mirror of
https://github.com/espressif/openthread.git
synced 2026-09-14 13:10:08 +00:00
[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:
@@ -172,6 +172,7 @@ LOCAL_SRC_FILES := \
|
|||||||
src/core/api/diags_api.cpp \
|
src/core/api/diags_api.cpp \
|
||||||
src/core/api/dns_api.cpp \
|
src/core/api/dns_api.cpp \
|
||||||
src/core/api/entropy_api.cpp \
|
src/core/api/entropy_api.cpp \
|
||||||
|
src/core/api/error_api.cpp \
|
||||||
src/core/api/heap_api.cpp \
|
src/core/api/heap_api.cpp \
|
||||||
src/core/api/icmp6_api.cpp \
|
src/core/api/icmp6_api.cpp \
|
||||||
src/core/api/instance_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_message.cpp \
|
||||||
src/core/coap/coap_secure.cpp \
|
src/core/coap/coap_secure.cpp \
|
||||||
src/core/common/crc16.cpp \
|
src/core/common/crc16.cpp \
|
||||||
|
src/core/common/error.cpp \
|
||||||
src/core/common/instance.cpp \
|
src/core/common/instance.cpp \
|
||||||
src/core/common/logging.cpp \
|
src/core/common/logging.cpp \
|
||||||
src/core/common/message.cpp \
|
src/core/common/message.cpp \
|
||||||
|
|||||||
@@ -300,6 +300,7 @@ openthread_core_files = [
|
|||||||
"api/diags_api.cpp",
|
"api/diags_api.cpp",
|
||||||
"api/dns_api.cpp",
|
"api/dns_api.cpp",
|
||||||
"api/entropy_api.cpp",
|
"api/entropy_api.cpp",
|
||||||
|
"api/error_api.cpp",
|
||||||
"api/heap_api.cpp",
|
"api/heap_api.cpp",
|
||||||
"api/icmp6_api.cpp",
|
"api/icmp6_api.cpp",
|
||||||
"api/instance_api.cpp",
|
"api/instance_api.cpp",
|
||||||
@@ -357,6 +358,8 @@ openthread_core_files = [
|
|||||||
"common/debug.hpp",
|
"common/debug.hpp",
|
||||||
"common/encoding.hpp",
|
"common/encoding.hpp",
|
||||||
"common/equatable.hpp",
|
"common/equatable.hpp",
|
||||||
|
"common/error.cpp",
|
||||||
|
"common/error.hpp",
|
||||||
"common/extension.hpp",
|
"common/extension.hpp",
|
||||||
"common/instance.cpp",
|
"common/instance.cpp",
|
||||||
"common/instance.hpp",
|
"common/instance.hpp",
|
||||||
@@ -618,11 +621,13 @@ openthread_core_files = [
|
|||||||
|
|
||||||
openthread_radio_sources = [
|
openthread_radio_sources = [
|
||||||
"api/diags_api.cpp",
|
"api/diags_api.cpp",
|
||||||
|
"api/error_api.cpp",
|
||||||
"api/instance_api.cpp",
|
"api/instance_api.cpp",
|
||||||
"api/link_raw_api.cpp",
|
"api/link_raw_api.cpp",
|
||||||
"api/logging_api.cpp",
|
"api/logging_api.cpp",
|
||||||
"api/random_noncrypto_api.cpp",
|
"api/random_noncrypto_api.cpp",
|
||||||
"api/tasklet_api.cpp",
|
"api/tasklet_api.cpp",
|
||||||
|
"common/error.hpp",
|
||||||
"common/instance.cpp",
|
"common/instance.cpp",
|
||||||
"common/logging.cpp",
|
"common/logging.cpp",
|
||||||
"common/random_manager.cpp",
|
"common/random_manager.cpp",
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ set(COMMON_SOURCES
|
|||||||
api/diags_api.cpp
|
api/diags_api.cpp
|
||||||
api/dns_api.cpp
|
api/dns_api.cpp
|
||||||
api/entropy_api.cpp
|
api/entropy_api.cpp
|
||||||
|
api/error_api.cpp
|
||||||
api/heap_api.cpp
|
api/heap_api.cpp
|
||||||
api/icmp6_api.cpp
|
api/icmp6_api.cpp
|
||||||
api/instance_api.cpp
|
api/instance_api.cpp
|
||||||
@@ -86,6 +87,7 @@ set(COMMON_SOURCES
|
|||||||
coap/coap_message.cpp
|
coap/coap_message.cpp
|
||||||
coap/coap_secure.cpp
|
coap/coap_secure.cpp
|
||||||
common/crc16.cpp
|
common/crc16.cpp
|
||||||
|
common/error.cpp
|
||||||
common/instance.cpp
|
common/instance.cpp
|
||||||
common/logging.cpp
|
common/logging.cpp
|
||||||
common/message.cpp
|
common/message.cpp
|
||||||
|
|||||||
@@ -125,6 +125,7 @@ SOURCES_COMMON = \
|
|||||||
api/diags_api.cpp \
|
api/diags_api.cpp \
|
||||||
api/dns_api.cpp \
|
api/dns_api.cpp \
|
||||||
api/entropy_api.cpp \
|
api/entropy_api.cpp \
|
||||||
|
api/error_api.cpp \
|
||||||
api/heap_api.cpp \
|
api/heap_api.cpp \
|
||||||
api/icmp6_api.cpp \
|
api/icmp6_api.cpp \
|
||||||
api/instance_api.cpp \
|
api/instance_api.cpp \
|
||||||
@@ -163,6 +164,7 @@ SOURCES_COMMON = \
|
|||||||
coap/coap_message.cpp \
|
coap/coap_message.cpp \
|
||||||
coap/coap_secure.cpp \
|
coap/coap_secure.cpp \
|
||||||
common/crc16.cpp \
|
common/crc16.cpp \
|
||||||
|
common/error.cpp \
|
||||||
common/instance.cpp \
|
common/instance.cpp \
|
||||||
common/logging.cpp \
|
common/logging.cpp \
|
||||||
common/message.cpp \
|
common/message.cpp \
|
||||||
@@ -291,12 +293,14 @@ EXTRA_DIST = \
|
|||||||
|
|
||||||
libopenthread_radio_a_SOURCES = \
|
libopenthread_radio_a_SOURCES = \
|
||||||
api/diags_api.cpp \
|
api/diags_api.cpp \
|
||||||
|
api/error_api.cpp \
|
||||||
api/heap_api.cpp \
|
api/heap_api.cpp \
|
||||||
api/instance_api.cpp \
|
api/instance_api.cpp \
|
||||||
api/link_raw_api.cpp \
|
api/link_raw_api.cpp \
|
||||||
api/logging_api.cpp \
|
api/logging_api.cpp \
|
||||||
api/random_noncrypto_api.cpp \
|
api/random_noncrypto_api.cpp \
|
||||||
api/tasklet_api.cpp \
|
api/tasklet_api.cpp \
|
||||||
|
common/error.cpp \
|
||||||
common/instance.cpp \
|
common/instance.cpp \
|
||||||
common/logging.cpp \
|
common/logging.cpp \
|
||||||
common/random_manager.cpp \
|
common/random_manager.cpp \
|
||||||
@@ -369,6 +373,7 @@ HEADERS_COMMON = \
|
|||||||
common/debug.hpp \
|
common/debug.hpp \
|
||||||
common/encoding.hpp \
|
common/encoding.hpp \
|
||||||
common/equatable.hpp \
|
common/equatable.hpp \
|
||||||
|
common/error.hpp \
|
||||||
common/extension.hpp \
|
common/extension.hpp \
|
||||||
common/instance.hpp \
|
common/instance.hpp \
|
||||||
common/iterator_utils.hpp \
|
common/iterator_utils.hpp \
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ otError otBorderRouterGetNetData(otInstance *aInstance, bool aStable, uint8_t *a
|
|||||||
|
|
||||||
otError otBorderRouterAddOnMeshPrefix(otInstance *aInstance, const otBorderRouterConfig *aConfig)
|
otError otBorderRouterAddOnMeshPrefix(otInstance *aInstance, const otBorderRouterConfig *aConfig)
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
Instance & instance = *static_cast<Instance *>(aInstance);
|
Instance & instance = *static_cast<Instance *>(aInstance);
|
||||||
const NetworkData::OnMeshPrefixConfig *config = static_cast<const NetworkData::OnMeshPrefixConfig *>(aConfig);
|
const NetworkData::OnMeshPrefixConfig *config = static_cast<const NetworkData::OnMeshPrefixConfig *>(aConfig);
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ exit:
|
|||||||
|
|
||||||
otError otBorderRouterRemoveOnMeshPrefix(otInstance *aInstance, const otIp6Prefix *aPrefix)
|
otError otBorderRouterRemoveOnMeshPrefix(otInstance *aInstance, const otIp6Prefix *aPrefix)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance & instance = *static_cast<Instance *>(aInstance);
|
Instance & instance = *static_cast<Instance *>(aInstance);
|
||||||
const Ip6::Prefix *prefix = static_cast<const Ip6::Prefix *>(aPrefix);
|
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
|
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||||
error = instance.Get<BackboneRouter::Local>().RemoveDomainPrefix(*prefix);
|
error = instance.Get<BackboneRouter::Local>().RemoveDomainPrefix(*prefix);
|
||||||
|
|
||||||
if (error == OT_ERROR_NOT_FOUND)
|
if (error == kErrorNotFound)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
error = instance.Get<NetworkData::Local>().RemoveOnMeshPrefix(*prefix);
|
error = instance.Get<NetworkData::Local>().RemoveOnMeshPrefix(*prefix);
|
||||||
@@ -166,7 +166,7 @@ otError otBorderRouterRegister(otInstance *aInstance)
|
|||||||
|
|
||||||
instance.Get<NetworkData::Notifier>().HandleServerDataUpdated();
|
instance.Get<NetworkData::Notifier>().HandleServerDataUpdated();
|
||||||
|
|
||||||
return OT_ERROR_NONE;
|
return kErrorNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE
|
#endif // OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE
|
||||||
|
|||||||
@@ -224,13 +224,13 @@ otError otCoapSendRequestBlockWiseWithParameters(otInstance * aIn
|
|||||||
otCoapBlockwiseTransmitHook aTransmitHook,
|
otCoapBlockwiseTransmitHook aTransmitHook,
|
||||||
otCoapBlockwiseReceiveHook aReceiveHook)
|
otCoapBlockwiseReceiveHook aReceiveHook)
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
Instance & instance = *static_cast<Instance *>(aInstance);
|
Instance & instance = *static_cast<Instance *>(aInstance);
|
||||||
const Coap::TxParameters &txParameters = Coap::TxParameters::From(aTxParameters);
|
const Coap::TxParameters &txParameters = Coap::TxParameters::From(aTxParameters);
|
||||||
|
|
||||||
if (aTxParameters != nullptr)
|
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),
|
error = instance.GetApplicationCoap().SendMessage(*static_cast<Coap::Message *>(aMessage),
|
||||||
@@ -249,13 +249,13 @@ otError otCoapSendRequestWithParameters(otInstance * aInstance,
|
|||||||
void * aContext,
|
void * aContext,
|
||||||
const otCoapTxParameters *aTxParameters)
|
const otCoapTxParameters *aTxParameters)
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
Instance & instance = *static_cast<Instance *>(aInstance);
|
Instance & instance = *static_cast<Instance *>(aInstance);
|
||||||
const Coap::TxParameters &txParameters = Coap::TxParameters::From(aTxParameters);
|
const Coap::TxParameters &txParameters = Coap::TxParameters::From(aTxParameters);
|
||||||
|
|
||||||
if (aTxParameters != nullptr)
|
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),
|
error = instance.GetApplicationCoap().SendMessage(*static_cast<Coap::Message *>(aMessage),
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ otError otCommissionerStop(otInstance *aInstance)
|
|||||||
|
|
||||||
otError otCommissionerAddJoiner(otInstance *aInstance, const otExtAddress *aEui64, const char *aPskd, uint32_t aTimeout)
|
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>();
|
MeshCoP::Commissioner &commissioner = static_cast<Instance *>(aInstance)->Get<MeshCoP::Commissioner>();
|
||||||
|
|
||||||
if (aEui64 == nullptr)
|
if (aEui64 == nullptr)
|
||||||
@@ -95,7 +95,7 @@ otError otCommissionerGetNextJoinerInfo(otInstance *aInstance, uint16_t *aIterat
|
|||||||
|
|
||||||
otError otCommissionerRemoveJoiner(otInstance *aInstance, const otExtAddress *aEui64)
|
otError otCommissionerRemoveJoiner(otInstance *aInstance, const otExtAddress *aEui64)
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
MeshCoP::Commissioner &commissioner = static_cast<Instance *>(aInstance)->Get<MeshCoP::Commissioner>();
|
MeshCoP::Commissioner &commissioner = static_cast<Instance *>(aInstance)->Get<MeshCoP::Commissioner>();
|
||||||
|
|
||||||
if (aEui64 == nullptr)
|
if (aEui64 == nullptr)
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -46,11 +46,11 @@ using namespace ot;
|
|||||||
|
|
||||||
otError otIp6SetEnabled(otInstance *aInstance, bool aEnabled)
|
otError otIp6SetEnabled(otInstance *aInstance, bool aEnabled)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_LINK_RAW_ENABLE
|
#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
|
#endif
|
||||||
|
|
||||||
if (aEnabled)
|
if (aEnabled)
|
||||||
@@ -246,12 +246,12 @@ bool otIp6IsAddressUnspecified(const otIp6Address *aAddress)
|
|||||||
|
|
||||||
otError otIp6SelectSourceAddress(otInstance *aInstance, otMessageInfo *aMessageInfo)
|
otError otIp6SelectSourceAddress(otInstance *aInstance, otMessageInfo *aMessageInfo)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance & instance = *static_cast<Instance *>(aInstance);
|
Instance & instance = *static_cast<Instance *>(aInstance);
|
||||||
const Ip6::NetifUnicastAddress *netifAddr;
|
const Ip6::NetifUnicastAddress *netifAddr;
|
||||||
|
|
||||||
netifAddr = instance.Get<Ip6::Ip6>().SelectSourceAddress(*static_cast<Ip6::MessageInfo *>(aMessageInfo));
|
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();
|
aMessageInfo->mSockAddr = netifAddr->GetAddress();
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ otError otJamDetectionSetRssiThreshold(otInstance *aInstance, int8_t aRssiThresh
|
|||||||
|
|
||||||
instance.Get<Utils::JamDetector>().SetRssiThreshold(aRssiThreshold);
|
instance.Get<Utils::JamDetector>().SetRssiThreshold(aRssiThreshold);
|
||||||
|
|
||||||
return OT_ERROR_NONE;
|
return kErrorNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t otJamDetectionGetRssiThreshold(otInstance *aInstance)
|
int8_t otJamDetectionGetRssiThreshold(otInstance *aInstance)
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ const otExtAddress *otJoinerGetId(otInstance *aInstance)
|
|||||||
|
|
||||||
otError otJoinerSetDiscerner(otInstance *aInstance, otJoinerDiscerner *aDiscerner)
|
otError otJoinerSetDiscerner(otInstance *aInstance, otJoinerDiscerner *aDiscerner)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
MeshCoP::Joiner &joiner = static_cast<Instance *>(aInstance)->Get<MeshCoP::Joiner>();
|
MeshCoP::Joiner &joiner = static_cast<Instance *>(aInstance)->Get<MeshCoP::Joiner>();
|
||||||
|
|
||||||
if (aDiscerner != nullptr)
|
if (aDiscerner != nullptr)
|
||||||
|
|||||||
+18
-18
@@ -63,7 +63,7 @@ uint8_t otLinkGetChannel(otInstance *aInstance)
|
|||||||
|
|
||||||
otError otLinkSetChannel(otInstance *aInstance, uint8_t aChannel)
|
otError otLinkSetChannel(otInstance *aInstance, uint8_t aChannel)
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_LINK_RAW_ENABLE
|
#if OPENTHREAD_CONFIG_LINK_RAW_ENABLE
|
||||||
@@ -74,7 +74,7 @@ otError otLinkSetChannel(otInstance *aInstance, uint8_t aChannel)
|
|||||||
}
|
}
|
||||||
#endif
|
#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));
|
SuccessOrExit(error = instance.Get<Mac::Mac>().SetPanChannel(aChannel));
|
||||||
instance.Get<MeshCoP::ActiveDataset>().Clear();
|
instance.Get<MeshCoP::ActiveDataset>().Clear();
|
||||||
@@ -93,10 +93,10 @@ uint32_t otLinkGetSupportedChannelMask(otInstance *aInstance)
|
|||||||
|
|
||||||
otError otLinkSetSupportedChannelMask(otInstance *aInstance, uint32_t aChannelMask)
|
otError otLinkSetSupportedChannelMask(otInstance *aInstance, uint32_t aChannelMask)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
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));
|
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 otLinkSetExtendedAddress(otInstance *aInstance, const otExtAddress *aExtAddress)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||||
|
|
||||||
OT_ASSERT(aExtAddress != nullptr);
|
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));
|
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 otLinkSetPanId(otInstance *aInstance, otPanId aPanId)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
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<Mac::Mac>().SetPanId(aPanId);
|
||||||
instance.Get<MeshCoP::ActiveDataset>().Clear();
|
instance.Get<MeshCoP::ActiveDataset>().Clear();
|
||||||
@@ -378,11 +378,11 @@ bool otLinkIsPromiscuous(otInstance *aInstance)
|
|||||||
|
|
||||||
otError otLinkSetPromiscuous(otInstance *aInstance, bool aPromiscuous)
|
otError otLinkSetPromiscuous(otInstance *aInstance, bool aPromiscuous)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||||
|
|
||||||
// cannot enable IEEE 802.15.4 promiscuous mode if the Thread interface is enabled
|
// 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);
|
instance.Get<Mac::Mac>().SetPromiscuous(aPromiscuous);
|
||||||
|
|
||||||
@@ -392,11 +392,11 @@ exit:
|
|||||||
|
|
||||||
otError otLinkSetEnabled(otInstance *aInstance, bool aEnable)
|
otError otLinkSetEnabled(otInstance *aInstance, bool aEnable)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||||
|
|
||||||
// cannot disable the link layer if the Thread interface is enabled
|
// 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);
|
instance.Get<Mac::Mac>().SetEnabled(aEnable);
|
||||||
|
|
||||||
@@ -490,10 +490,10 @@ uint8_t otLinkCslGetChannel(otInstance *aInstance)
|
|||||||
|
|
||||||
otError otLinkCslSetChannel(otInstance *aInstance, uint8_t aChannel)
|
otError otLinkCslSetChannel(otInstance *aInstance, uint8_t aChannel)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
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);
|
instance.Get<Mac::Mac>().SetCslChannel(aChannel);
|
||||||
|
|
||||||
@@ -508,10 +508,10 @@ uint16_t otLinkCslGetPeriod(otInstance *aInstance)
|
|||||||
|
|
||||||
otError otLinkCslSetPeriod(otInstance *aInstance, uint16_t aPeriod)
|
otError otLinkCslSetPeriod(otInstance *aInstance, uint16_t aPeriod)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
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);
|
instance.Get<Mac::Mac>().SetCslPeriod(aPeriod);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
@@ -525,10 +525,10 @@ uint32_t otLinkCslGetTimeout(otInstance *aInstance)
|
|||||||
|
|
||||||
otError otLinkCslSetTimeout(otInstance *aInstance, uint32_t aTimeout)
|
otError otLinkCslSetTimeout(otInstance *aInstance, uint32_t aTimeout)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
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);
|
instance.Get<Mac::Mac>().SetCslTimeout(aTimeout);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
|||||||
@@ -71,10 +71,10 @@ bool otLinkRawGetPromiscuous(otInstance *aInstance)
|
|||||||
|
|
||||||
otError otLinkRawSetPromiscuous(otInstance *aInstance, bool aEnable)
|
otError otLinkRawSetPromiscuous(otInstance *aInstance, bool aEnable)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
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);
|
instance.Get<Radio>().SetPromiscuous(aEnable);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
@@ -83,10 +83,10 @@ exit:
|
|||||||
|
|
||||||
otError otLinkRawSleep(otInstance *aInstance)
|
otError otLinkRawSleep(otInstance *aInstance)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
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();
|
error = instance.Get<Radio>().Sleep();
|
||||||
|
|
||||||
@@ -129,10 +129,10 @@ otError otLinkRawEnergyScan(otInstance * aInstance,
|
|||||||
|
|
||||||
otError otLinkRawSrcMatchEnable(otInstance *aInstance, bool aEnable)
|
otError otLinkRawSrcMatchEnable(otInstance *aInstance, bool aEnable)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
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);
|
instance.Get<Radio>().EnableSrcMatch(aEnable);
|
||||||
|
|
||||||
@@ -142,10 +142,10 @@ exit:
|
|||||||
|
|
||||||
otError otLinkRawSrcMatchAddShortEntry(otInstance *aInstance, uint16_t aShortAddress)
|
otError otLinkRawSrcMatchAddShortEntry(otInstance *aInstance, uint16_t aShortAddress)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
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);
|
error = instance.Get<Radio>().AddSrcMatchShortEntry(aShortAddress);
|
||||||
|
|
||||||
@@ -156,10 +156,10 @@ exit:
|
|||||||
otError otLinkRawSrcMatchAddExtEntry(otInstance *aInstance, const otExtAddress *aExtAddress)
|
otError otLinkRawSrcMatchAddExtEntry(otInstance *aInstance, const otExtAddress *aExtAddress)
|
||||||
{
|
{
|
||||||
Mac::ExtAddress address;
|
Mac::ExtAddress address;
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance & instance = *static_cast<Instance *>(aInstance);
|
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);
|
address.Set(aExtAddress->m8, Mac::ExtAddress::kReverseByteOrder);
|
||||||
error = instance.Get<Radio>().AddSrcMatchExtEntry(address);
|
error = instance.Get<Radio>().AddSrcMatchExtEntry(address);
|
||||||
@@ -170,10 +170,10 @@ exit:
|
|||||||
|
|
||||||
otError otLinkRawSrcMatchClearShortEntry(otInstance *aInstance, uint16_t aShortAddress)
|
otError otLinkRawSrcMatchClearShortEntry(otInstance *aInstance, uint16_t aShortAddress)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
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);
|
error = instance.Get<Radio>().ClearSrcMatchShortEntry(aShortAddress);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
@@ -183,10 +183,10 @@ exit:
|
|||||||
otError otLinkRawSrcMatchClearExtEntry(otInstance *aInstance, const otExtAddress *aExtAddress)
|
otError otLinkRawSrcMatchClearExtEntry(otInstance *aInstance, const otExtAddress *aExtAddress)
|
||||||
{
|
{
|
||||||
Mac::ExtAddress address;
|
Mac::ExtAddress address;
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance & instance = *static_cast<Instance *>(aInstance);
|
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);
|
address.Set(aExtAddress->m8, Mac::ExtAddress::kReverseByteOrder);
|
||||||
error = instance.Get<Radio>().ClearSrcMatchExtEntry(address);
|
error = instance.Get<Radio>().ClearSrcMatchExtEntry(address);
|
||||||
@@ -197,10 +197,10 @@ exit:
|
|||||||
|
|
||||||
otError otLinkRawSrcMatchClearShortEntries(otInstance *aInstance)
|
otError otLinkRawSrcMatchClearShortEntries(otInstance *aInstance)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
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();
|
instance.Get<Radio>().ClearSrcMatchShortEntries();
|
||||||
|
|
||||||
@@ -210,10 +210,10 @@ exit:
|
|||||||
|
|
||||||
otError otLinkRawSrcMatchClearExtEntries(otInstance *aInstance)
|
otError otLinkRawSrcMatchClearExtEntries(otInstance *aInstance)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
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();
|
instance.Get<Radio>().ClearSrcMatchExtEntries();
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ otLogLevel otLoggingGetLevel(void)
|
|||||||
#if OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE
|
#if OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE
|
||||||
otError otLoggingSetLevel(otLogLevel aLogLevel)
|
otError otLoggingSetLevel(otLogLevel aLogLevel)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
|
|
||||||
if (aLogLevel <= OT_LOG_LEVEL_DEBG && aLogLevel >= OT_LOG_LEVEL_NONE)
|
if (aLogLevel <= OT_LOG_LEVEL_DEBG && aLogLevel >= OT_LOG_LEVEL_NONE)
|
||||||
{
|
{
|
||||||
@@ -59,7 +59,7 @@ otError otLoggingSetLevel(otLogLevel aLogLevel)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
error = OT_ERROR_INVALID_ARGS;
|
error = kErrorInvalidArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
|
|||||||
@@ -49,13 +49,13 @@ otError otMultiRadioGetNeighborInfo(otInstance * aInstance,
|
|||||||
const otExtAddress * aExtAddress,
|
const otExtAddress * aExtAddress,
|
||||||
otMultiRadioNeighborInfo *aInfo)
|
otMultiRadioNeighborInfo *aInfo)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||||
Neighbor *neighbor;
|
Neighbor *neighbor;
|
||||||
|
|
||||||
neighbor = instance.Get<NeighborTable>().FindNeighbor(*static_cast<const Mac::ExtAddress *>(aExtAddress),
|
neighbor = instance.Get<NeighborTable>().FindNeighbor(*static_cast<const Mac::ExtAddress *>(aExtAddress),
|
||||||
Neighbor::kInStateAnyExceptInvalid);
|
Neighbor::kInStateAnyExceptInvalid);
|
||||||
VerifyOrExit(neighbor != NULL, error = OT_ERROR_NOT_FOUND);
|
VerifyOrExit(neighbor != NULL, error = kErrorNotFound);
|
||||||
|
|
||||||
neighbor->PopulateMultiRadioInfo(*aInfo);
|
neighbor->PopulateMultiRadioInfo(*aInfo);
|
||||||
|
|
||||||
|
|||||||
@@ -53,11 +53,11 @@ otError otNetDataGetNextOnMeshPrefix(otInstance * aInstance,
|
|||||||
otNetworkDataIterator *aIterator,
|
otNetworkDataIterator *aIterator,
|
||||||
otBorderRouterConfig * aConfig)
|
otBorderRouterConfig * aConfig)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance & instance = *static_cast<Instance *>(aInstance);
|
Instance & instance = *static_cast<Instance *>(aInstance);
|
||||||
NetworkData::OnMeshPrefixConfig *config = static_cast<NetworkData::OnMeshPrefixConfig *>(aConfig);
|
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);
|
error = instance.Get<NetworkData::Leader>().GetNextOnMeshPrefix(*aIterator, *config);
|
||||||
|
|
||||||
@@ -67,10 +67,10 @@ exit:
|
|||||||
|
|
||||||
otError otNetDataGetNextRoute(otInstance *aInstance, otNetworkDataIterator *aIterator, otExternalRouteConfig *aConfig)
|
otError otNetDataGetNextRoute(otInstance *aInstance, otNetworkDataIterator *aIterator, otExternalRouteConfig *aConfig)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
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(
|
error = instance.Get<NetworkData::Leader>().GetNextExternalRoute(
|
||||||
*aIterator, *static_cast<NetworkData::ExternalRouteConfig *>(aConfig));
|
*aIterator, *static_cast<NetworkData::ExternalRouteConfig *>(aConfig));
|
||||||
@@ -81,10 +81,10 @@ exit:
|
|||||||
|
|
||||||
otError otNetDataGetNextService(otInstance *aInstance, otNetworkDataIterator *aIterator, otServiceConfig *aConfig)
|
otError otNetDataGetNextService(otInstance *aInstance, otNetworkDataIterator *aIterator, otServiceConfig *aConfig)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
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,
|
error = instance.Get<NetworkData::Leader>().GetNextService(*aIterator,
|
||||||
*static_cast<NetworkData::ServiceConfig *>(aConfig));
|
*static_cast<NetworkData::ServiceConfig *>(aConfig));
|
||||||
|
|||||||
@@ -51,10 +51,10 @@ otNetworkTimeStatus otNetworkTimeGet(otInstance *aInstance, uint64_t *aNetworkTi
|
|||||||
|
|
||||||
otError otNetworkTimeSetSyncPeriod(otInstance *aInstance, uint16_t aTimeSyncPeriod)
|
otError otNetworkTimeSetSyncPeriod(otInstance *aInstance, uint16_t aTimeSyncPeriod)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
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);
|
instance.Get<TimeSync>().SetTimeSyncPeriod(aTimeSyncPeriod);
|
||||||
|
|
||||||
@@ -71,10 +71,10 @@ uint16_t otNetworkTimeGetSyncPeriod(otInstance *aInstance)
|
|||||||
|
|
||||||
otError otNetworkTimeSetXtalThreshold(otInstance *aInstance, uint16_t aXtalThreshold)
|
otError otNetworkTimeSetXtalThreshold(otInstance *aInstance, uint16_t aXtalThreshold)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
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);
|
instance.Get<TimeSync>().SetXtalThreshold(aXtalThreshold);
|
||||||
|
|
||||||
|
|||||||
@@ -73,10 +73,10 @@ otError otServerRemoveService(otInstance * aInstance,
|
|||||||
|
|
||||||
otError otServerGetNextService(otInstance *aInstance, otNetworkDataIterator *aIterator, otServiceConfig *aConfig)
|
otError otServerGetNextService(otInstance *aInstance, otNetworkDataIterator *aIterator, otServiceConfig *aConfig)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
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,
|
error = instance.Get<NetworkData::Local>().GetNextService(*aIterator,
|
||||||
*static_cast<NetworkData::ServiceConfig *>(aConfig));
|
*static_cast<NetworkData::ServiceConfig *>(aConfig));
|
||||||
@@ -91,7 +91,7 @@ otError otServerRegister(otInstance *aInstance)
|
|||||||
|
|
||||||
instance.Get<NetworkData::Notifier>().HandleServerDataUpdated();
|
instance.Get<NetworkData::Notifier>().HandleServerDataUpdated();
|
||||||
|
|
||||||
return OT_ERROR_NONE;
|
return kErrorNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
#endif // OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
||||||
|
|||||||
+20
-20
@@ -66,12 +66,12 @@ const otExtendedPanId *otThreadGetExtendedPanId(otInstance *aInstance)
|
|||||||
|
|
||||||
otError otThreadSetExtendedPanId(otInstance *aInstance, const otExtendedPanId *aExtendedPanId)
|
otError otThreadSetExtendedPanId(otInstance *aInstance, const otExtendedPanId *aExtendedPanId)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance & instance = *static_cast<Instance *>(aInstance);
|
Instance & instance = *static_cast<Instance *>(aInstance);
|
||||||
const Mac::ExtendedPanId &extPanId = *static_cast<const Mac::ExtendedPanId *>(aExtendedPanId);
|
const Mac::ExtendedPanId &extPanId = *static_cast<const Mac::ExtendedPanId *>(aExtendedPanId);
|
||||||
Mle::MeshLocalPrefix prefix;
|
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);
|
instance.Get<Mac::Mac>().SetExtendedPanId(extPanId);
|
||||||
|
|
||||||
@@ -120,12 +120,12 @@ const otMasterKey *otThreadGetMasterKey(otInstance *aInstance)
|
|||||||
|
|
||||||
otError otThreadSetMasterKey(otInstance *aInstance, const otMasterKey *aKey)
|
otError otThreadSetMasterKey(otInstance *aInstance, const otMasterKey *aKey)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||||
|
|
||||||
OT_ASSERT(aKey != nullptr);
|
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));
|
error = instance.Get<KeyManager>().SetMasterKey(*static_cast<const MasterKey *>(aKey));
|
||||||
instance.Get<MeshCoP::ActiveDataset>().Clear();
|
instance.Get<MeshCoP::ActiveDataset>().Clear();
|
||||||
@@ -158,10 +158,10 @@ const otMeshLocalPrefix *otThreadGetMeshLocalPrefix(otInstance *aInstance)
|
|||||||
|
|
||||||
otError otThreadSetMeshLocalPrefix(otInstance *aInstance, const otMeshLocalPrefix *aMeshLocalPrefix)
|
otError otThreadSetMeshLocalPrefix(otInstance *aInstance, const otMeshLocalPrefix *aMeshLocalPrefix)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
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<Mle::MleRouter>().SetMeshLocalPrefix(*static_cast<const Mle::MeshLocalPrefix *>(aMeshLocalPrefix));
|
||||||
instance.Get<MeshCoP::ActiveDataset>().Clear();
|
instance.Get<MeshCoP::ActiveDataset>().Clear();
|
||||||
@@ -187,10 +187,10 @@ const char *otThreadGetNetworkName(otInstance *aInstance)
|
|||||||
|
|
||||||
otError otThreadSetNetworkName(otInstance *aInstance, const char *aNetworkName)
|
otError otThreadSetNetworkName(otInstance *aInstance, const char *aNetworkName)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
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);
|
error = instance.Get<Mac::Mac>().SetNetworkName(aNetworkName);
|
||||||
instance.Get<MeshCoP::ActiveDataset>().Clear();
|
instance.Get<MeshCoP::ActiveDataset>().Clear();
|
||||||
@@ -210,10 +210,10 @@ const char *otThreadGetDomainName(otInstance *aInstance)
|
|||||||
|
|
||||||
otError otThreadSetDomainName(otInstance *aInstance, const char *aDomainName)
|
otError otThreadSetDomainName(otInstance *aInstance, const char *aDomainName)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
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);
|
error = instance.Get<Mac::Mac>().SetDomainName(aDomainName);
|
||||||
|
|
||||||
@@ -225,7 +225,7 @@ exit:
|
|||||||
otError otThreadSetFixedDuaInterfaceIdentifier(otInstance *aInstance, const otIp6InterfaceIdentifier *aIid)
|
otError otThreadSetFixedDuaInterfaceIdentifier(otInstance *aInstance, const otIp6InterfaceIdentifier *aIid)
|
||||||
{
|
{
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
|
|
||||||
if (aIid)
|
if (aIid)
|
||||||
{
|
{
|
||||||
@@ -317,11 +317,11 @@ otDeviceRole otThreadGetDeviceRole(otInstance *aInstance)
|
|||||||
otError otThreadGetLeaderData(otInstance *aInstance, otLeaderData *aLeaderData)
|
otError otThreadGetLeaderData(otInstance *aInstance, otLeaderData *aLeaderData)
|
||||||
{
|
{
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
|
|
||||||
OT_ASSERT(aLeaderData != nullptr);
|
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();
|
*aLeaderData = instance.Get<Mle::MleRouter>().GetLeaderData();
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
@@ -359,14 +359,14 @@ uint16_t otThreadGetRloc16(otInstance *aInstance)
|
|||||||
otError otThreadGetParentInfo(otInstance *aInstance, otRouterInfo *aParentInfo)
|
otError otThreadGetParentInfo(otInstance *aInstance, otRouterInfo *aParentInfo)
|
||||||
{
|
{
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Router * parent;
|
Router * parent;
|
||||||
|
|
||||||
OT_ASSERT(aParentInfo != nullptr);
|
OT_ASSERT(aParentInfo != nullptr);
|
||||||
|
|
||||||
// Reference device needs get the original parent's info even after the node state changed.
|
// Reference device needs get the original parent's info even after the node state changed.
|
||||||
#if !OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
#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
|
#endif
|
||||||
|
|
||||||
parent = &instance.Get<Mle::MleRouter>().GetParent();
|
parent = &instance.Get<Mle::MleRouter>().GetParent();
|
||||||
@@ -390,14 +390,14 @@ exit:
|
|||||||
|
|
||||||
otError otThreadGetParentAverageRssi(otInstance *aInstance, int8_t *aParentRssi)
|
otError otThreadGetParentAverageRssi(otInstance *aInstance, int8_t *aParentRssi)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||||
|
|
||||||
OT_ASSERT(aParentRssi != nullptr);
|
OT_ASSERT(aParentRssi != nullptr);
|
||||||
|
|
||||||
*aParentRssi = instance.Get<Mle::MleRouter>().GetParent().GetLinkInfo().GetAverageRss();
|
*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:
|
exit:
|
||||||
return error;
|
return error;
|
||||||
@@ -405,14 +405,14 @@ exit:
|
|||||||
|
|
||||||
otError otThreadGetParentLastRssi(otInstance *aInstance, int8_t *aLastRssi)
|
otError otThreadGetParentLastRssi(otInstance *aInstance, int8_t *aLastRssi)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||||
|
|
||||||
OT_ASSERT(aLastRssi != nullptr);
|
OT_ASSERT(aLastRssi != nullptr);
|
||||||
|
|
||||||
*aLastRssi = instance.Get<Mle::MleRouter>().GetParent().GetLinkInfo().GetLastRss();
|
*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:
|
exit:
|
||||||
return error;
|
return error;
|
||||||
@@ -420,7 +420,7 @@ exit:
|
|||||||
|
|
||||||
otError otThreadSetEnabled(otInstance *aInstance, bool aEnabled)
|
otError otThreadSetEnabled(otInstance *aInstance, bool aEnabled)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||||
|
|
||||||
if (aEnabled)
|
if (aEnabled)
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ otError otThreadSetJoinerUdpPort(otInstance *aInstance, uint16_t aJoinerUdpPort)
|
|||||||
|
|
||||||
instance.Get<MeshCoP::JoinerRouter>().SetJoinerUdpPort(aJoinerUdpPort);
|
instance.Get<MeshCoP::JoinerRouter>().SetJoinerUdpPort(aJoinerUdpPort);
|
||||||
|
|
||||||
return OT_ERROR_NONE;
|
return kErrorNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t otThreadGetContextIdReuseDelay(otInstance *aInstance)
|
uint32_t otThreadGetContextIdReuseDelay(otInstance *aInstance)
|
||||||
@@ -186,10 +186,10 @@ void otThreadSetRouterUpgradeThreshold(otInstance *aInstance, uint8_t aThreshold
|
|||||||
|
|
||||||
otError otThreadReleaseRouterId(otInstance *aInstance, uint8_t aRouterId)
|
otError otThreadReleaseRouterId(otInstance *aInstance, uint8_t aRouterId)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
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);
|
error = instance.Get<RouterTable>().Release(aRouterId);
|
||||||
|
|
||||||
@@ -199,7 +199,7 @@ exit:
|
|||||||
|
|
||||||
otError otThreadBecomeRouter(otInstance *aInstance)
|
otError otThreadBecomeRouter(otInstance *aInstance)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_INVALID_STATE;
|
Error error = kErrorInvalidState;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||||
|
|
||||||
switch (instance.Get<Mle::MleRouter>().GetRole())
|
switch (instance.Get<Mle::MleRouter>().GetRole())
|
||||||
@@ -214,7 +214,7 @@ otError otThreadBecomeRouter(otInstance *aInstance)
|
|||||||
|
|
||||||
case Mle::kRoleRouter:
|
case Mle::kRoleRouter:
|
||||||
case Mle::kRoleLeader:
|
case Mle::kRoleLeader:
|
||||||
error = OT_ERROR_NONE;
|
error = kErrorNone;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,20 +279,20 @@ otError otThreadGetChildNextIp6Address(otInstance * aInstance,
|
|||||||
otChildIp6AddressIterator *aIterator,
|
otChildIp6AddressIterator *aIterator,
|
||||||
otIp6Address * aAddress)
|
otIp6Address * aAddress)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance & instance = *static_cast<Instance *>(aInstance);
|
Instance & instance = *static_cast<Instance *>(aInstance);
|
||||||
const Child *child;
|
const Child *child;
|
||||||
|
|
||||||
OT_ASSERT(aIterator != nullptr && aAddress != nullptr);
|
OT_ASSERT(aIterator != nullptr && aAddress != nullptr);
|
||||||
|
|
||||||
child = instance.Get<ChildTable>().GetChildAtIndex(aChildIndex);
|
child = instance.Get<ChildTable>().GetChildAtIndex(aChildIndex);
|
||||||
VerifyOrExit(child != nullptr, error = OT_ERROR_INVALID_ARGS);
|
VerifyOrExit(child != nullptr, error = kErrorInvalidArgs);
|
||||||
VerifyOrExit(child->IsStateValidOrRestoring(), error = OT_ERROR_INVALID_ARGS);
|
VerifyOrExit(child->IsStateValidOrRestoring(), error = kErrorInvalidArgs);
|
||||||
|
|
||||||
{
|
{
|
||||||
Child::AddressIterator iter(*child, *aIterator);
|
Child::AddressIterator iter(*child, *aIterator);
|
||||||
|
|
||||||
VerifyOrExit(!iter.IsDone(), error = OT_ERROR_NOT_FOUND);
|
VerifyOrExit(!iter.IsDone(), error = kErrorNotFound);
|
||||||
*aAddress = *iter.GetAddress();
|
*aAddress = *iter.GetAddress();
|
||||||
|
|
||||||
iter++;
|
iter++;
|
||||||
@@ -352,10 +352,10 @@ const otPskc *otThreadGetPskc(otInstance *aInstance)
|
|||||||
|
|
||||||
otError otThreadSetPskc(otInstance *aInstance, const otPskc *aPskc)
|
otError otThreadSetPskc(otInstance *aInstance, const otPskc *aPskc)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
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<KeyManager>().SetPskc(*static_cast<const Pskc *>(aPskc));
|
||||||
instance.Get<MeshCoP::ActiveDataset>().Clear();
|
instance.Get<MeshCoP::ActiveDataset>().Clear();
|
||||||
|
|||||||
@@ -41,9 +41,9 @@
|
|||||||
namespace ot {
|
namespace ot {
|
||||||
namespace BackboneRouter {
|
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));
|
SuccessOrExit(error = Coap::Start(kBackboneUdpPort, OT_NETIF_BACKBONE));
|
||||||
SubscribeMulticast(Get<Local>().GetAllNetworkBackboneRoutersAddress());
|
SubscribeMulticast(Get<Local>().GetAllNetworkBackboneRoutersAddress());
|
||||||
@@ -52,14 +52,11 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError BackboneTmfAgent::Filter(const ot::Coap::Message &aMessage,
|
Error BackboneTmfAgent::Filter(const ot::Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo, void *aContext)
|
||||||
const Ip6::MessageInfo & aMessageInfo,
|
|
||||||
void * aContext)
|
|
||||||
{
|
{
|
||||||
OT_UNUSED_VARIABLE(aMessage);
|
OT_UNUSED_VARIABLE(aMessage);
|
||||||
|
|
||||||
return static_cast<BackboneTmfAgent *>(aContext)->IsBackboneTmfMessage(aMessageInfo) ? OT_ERROR_NONE
|
return static_cast<BackboneTmfAgent *>(aContext)->IsBackboneTmfMessage(aMessageInfo) ? kErrorNone : kErrorNotTmf;
|
||||||
: OT_ERROR_NOT_TMF;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BackboneTmfAgent::IsBackboneTmfMessage(const Ip6::MessageInfo &aMessageInfo) const
|
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)
|
void BackboneTmfAgent::SubscribeMulticast(const Ip6::Address &aAddress)
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
error = mSocket.JoinNetifMulticastGroup(OT_NETIF_BACKBONE, aAddress);
|
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)
|
void BackboneTmfAgent::UnsubscribeMulticast(const Ip6::Address &aAddress)
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
error = mSocket.LeaveNetifMulticastGroup(OT_NETIF_BACKBONE, aAddress);
|
error = mSocket.LeaveNetifMulticastGroup(OT_NETIF_BACKBONE, aAddress);
|
||||||
|
|
||||||
|
|||||||
@@ -66,11 +66,11 @@ public:
|
|||||||
/**
|
/**
|
||||||
* This method starts the Backbone TMF agent.
|
* This method starts the Backbone TMF agent.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully started the CoAP service.
|
* @retval kErrorNone Successfully started the CoAP service.
|
||||||
* @retval OT_ERROR_FAILED Failed to start the Backbone TMF agent.
|
* @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.
|
* This method returns whether @p aMessageInfo meets Backbone Thread Management Framework Addressing Rules.
|
||||||
@@ -98,7 +98,7 @@ public:
|
|||||||
void UnsubscribeMulticast(const Ip6::Address &aAddress);
|
void UnsubscribeMulticast(const Ip6::Address &aAddress);
|
||||||
|
|
||||||
private:
|
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
|
} // namespace BackboneRouter
|
||||||
|
|||||||
@@ -57,11 +57,11 @@ void Leader::Reset(void)
|
|||||||
mDomainPrefix.SetLength(0);
|
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;
|
aConfig = mConfig;
|
||||||
|
|
||||||
@@ -69,11 +69,11 @@ exit:
|
|||||||
return error;
|
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>(
|
error = Get<NetworkData::Service::Manager>().GetServiceId<NetworkData::Service::BackboneRouter>(
|
||||||
/* aServerStable */ true, aServiceId);
|
/* aServerStable */ true, aServiceId);
|
||||||
|
|
||||||
@@ -256,7 +256,7 @@ void Leader::UpdateDomainPrefixConfig(void)
|
|||||||
DomainPrefixState state;
|
DomainPrefixState state;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
while (Get<NetworkData::Leader>().GetNextOnMeshPrefix(iterator, config) == OT_ERROR_NONE)
|
while (Get<NetworkData::Leader>().GetNextOnMeshPrefix(iterator, config) == kErrorNone)
|
||||||
{
|
{
|
||||||
if (config.mDp)
|
if (config.mDp)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -106,22 +106,22 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[out] aConfig The Primary Backbone Router information.
|
* @param[out] aConfig The Primary Backbone Router information.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully got the Primary Backbone Router information.
|
* @retval kErrorNone Successfully got the Primary Backbone Router information.
|
||||||
* @retval OT_ERROR_NOT_FOUND No Backbone Router in the Thread Network.
|
* @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.
|
* This method gets the Backbone Router Service ID.
|
||||||
*
|
*
|
||||||
* @param[out] aServiceId The reference whether to put 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 kErrorNone Successfully got the Backbone Router Service ID.
|
||||||
* @retval OT_ERROR_NOT_FOUND Backbone Router service doesn't exist.
|
* @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.
|
* This method gets the short address of the Primary Backbone Router.
|
||||||
|
|||||||
@@ -125,19 +125,19 @@ void Local::GetConfig(BackboneRouterConfig &aConfig) const
|
|||||||
aConfig.mMlrTimeout = mMlrTimeout;
|
aConfig.mMlrTimeout = mMlrTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Local::SetConfig(const BackboneRouterConfig &aConfig)
|
Error Local::SetConfig(const BackboneRouterConfig &aConfig)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
bool update = false;
|
bool update = false;
|
||||||
|
|
||||||
VerifyOrExit(aConfig.mMlrTimeout >= Mle::kMlrTimeoutMin && aConfig.mMlrTimeout <= Mle::kMlrTimeoutMax,
|
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:
|
// 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."
|
// "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),
|
static_assert(sizeof(aConfig.mReregistrationDelay) < sizeof(aConfig.mMlrTimeout),
|
||||||
"the calculation below might overflow");
|
"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)
|
if (aConfig.mReregistrationDelay != mReregistrationDelay)
|
||||||
{
|
{
|
||||||
@@ -169,9 +169,9 @@ exit:
|
|||||||
return error;
|
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;
|
NetworkData::Service::BackboneRouter::ServerData serverData;
|
||||||
|
|
||||||
VerifyOrExit(mState != OT_BACKBONE_ROUTER_STATE_DISABLED && Get<Mle::Mle>().IsAttached());
|
VerifyOrExit(mState != OT_BACKBONE_ROUTER_STATE_DISABLED && Get<Mle::Mle>().IsAttached());
|
||||||
@@ -196,7 +196,7 @@ exit:
|
|||||||
|
|
||||||
void Local::RemoveService(void)
|
void Local::RemoveService(void)
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
SuccessOrExit(error = Get<NetworkData::Service::Manager>().Remove<NetworkData::Service::BackboneRouter>());
|
SuccessOrExit(error = Get<NetworkData::Service::Manager>().Remove<NetworkData::Service::BackboneRouter>());
|
||||||
mIsServiceAdded = false;
|
mIsServiceAdded = false;
|
||||||
@@ -266,7 +266,7 @@ void Local::HandleBackboneRouterPrimaryUpdate(Leader::State aState, const Backbo
|
|||||||
mReregistrationDelay = aConfig.mReregistrationDelay;
|
mReregistrationDelay = aConfig.mReregistrationDelay;
|
||||||
mMlrTimeout = aConfig.mMlrTimeout;
|
mMlrTimeout = aConfig.mMlrTimeout;
|
||||||
Get<Notifier>().Signal(kEventThreadBackboneRouterLocalChanged);
|
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();
|
Get<NetworkData::Notifier>().HandleServerDataUpdated();
|
||||||
}
|
}
|
||||||
@@ -280,11 +280,11 @@ exit:
|
|||||||
return;
|
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;
|
aConfig = mDomainPrefixConfig;
|
||||||
|
|
||||||
@@ -292,12 +292,12 @@ exit:
|
|||||||
return error;
|
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(aPrefix.GetLength() > 0, error = kErrorInvalidArgs);
|
||||||
VerifyOrExit(mDomainPrefixConfig.GetPrefix() == aPrefix, error = OT_ERROR_NOT_FOUND);
|
VerifyOrExit(mDomainPrefixConfig.GetPrefix() == aPrefix, error = kErrorNotFound);
|
||||||
|
|
||||||
if (IsEnabled())
|
if (IsEnabled())
|
||||||
{
|
{
|
||||||
@@ -318,7 +318,7 @@ void Local::SetDomainPrefix(const NetworkData::OnMeshPrefixConfig &aConfig)
|
|||||||
}
|
}
|
||||||
|
|
||||||
mDomainPrefixConfig = aConfig;
|
mDomainPrefixConfig = aConfig;
|
||||||
LogDomainPrefix("Set", OT_ERROR_NONE);
|
LogDomainPrefix("Set", kErrorNone);
|
||||||
|
|
||||||
if (IsEnabled())
|
if (IsEnabled())
|
||||||
{
|
{
|
||||||
@@ -390,7 +390,7 @@ exit:
|
|||||||
|
|
||||||
void Local::RemoveDomainPrefixFromNetworkData(void)
|
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)
|
if (mDomainPrefixConfig.mPrefix.mLength > 0)
|
||||||
{
|
{
|
||||||
@@ -402,7 +402,7 @@ void Local::RemoveDomainPrefixFromNetworkData(void)
|
|||||||
|
|
||||||
void Local::AddDomainPrefixToNetworkData(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)
|
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)
|
#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(),
|
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,
|
otLogInfoBbr("%s BBR Service: seqno (%d), delay (%ds), timeout (%ds), %s", aAction, mSequenceNumber,
|
||||||
mReregistrationDelay, mMlrTimeout, otThreadErrorToString(aError));
|
mReregistrationDelay, mMlrTimeout, ErrorToString(aError));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -114,11 +114,11 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[in] aConfig The configuration to set.
|
* @param[in] aConfig The configuration to set.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully updated configuration.
|
* @retval kErrorNone Successfully updated configuration.
|
||||||
* @retval OT_ERROR_INVALID_ARGS The configuration in @p aConfig is invalid.
|
* @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.
|
* This method registers Backbone Router Dataset to Leader.
|
||||||
@@ -127,12 +127,12 @@ public:
|
|||||||
* False to decide based on current BackboneRouterState.
|
* False to decide based on current BackboneRouterState.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully added the Service entry.
|
* @retval kErrorNone Successfully added the Service entry.
|
||||||
* @retval OT_ERROR_INVALID_STATE Not in the ready state to register.
|
* @retval kErrorInvalidState Not in the ready state to register.
|
||||||
* @retval OT_ERROR_NO_BUFS Insufficient space to add the Service entry.
|
* @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.
|
* 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.
|
* @param[out] aConfig A reference to the Domain Prefix configuration.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully got the Domain Prefix configuration.
|
* @retval kErrorNone Successfully got the Domain Prefix configuration.
|
||||||
* @retval OT_ERROR_NOT_FOUND No Domain Prefix was configured.
|
* @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.
|
* This method removes the local Domain Prefix configuration.
|
||||||
*
|
*
|
||||||
* @param[in] aPrefix A reference to the IPv6 Domain Prefix.
|
* @param[in] aPrefix A reference to the IPv6 Domain Prefix.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully removed the Domain Prefix.
|
* @retval kErrorNone Successfully removed the Domain Prefix.
|
||||||
* @retval OT_ERROR_INVALID_ARGS @p aPrefix is invalid.
|
* @retval kErrorInvalidArgs @p aPrefix is invalid.
|
||||||
* @retval OT_ERROR_NOT_FOUND No Domain Prefix was configured or @p aPrefix doesn't match.
|
* @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.
|
* This method sets the local Domain Prefix configuration.
|
||||||
@@ -253,11 +253,11 @@ private:
|
|||||||
void AddDomainPrefixToNetworkData(void);
|
void AddDomainPrefixToNetworkData(void);
|
||||||
void RemoveDomainPrefixFromNetworkData(void);
|
void RemoveDomainPrefixFromNetworkData(void);
|
||||||
#if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_BBR == 1)
|
#if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_BBR == 1)
|
||||||
void LogBackboneRouterService(const char *aAction, otError aError);
|
void LogBackboneRouterService(const char *aAction, Error aError);
|
||||||
void LogDomainPrefix(const char *aAction, otError aError);
|
void LogDomainPrefix(const char *aAction, Error aError);
|
||||||
#else
|
#else
|
||||||
void LogBackboneRouterService(const char *, otError) {}
|
void LogBackboneRouterService(const char *, Error) {}
|
||||||
void LogDomainPrefix(const char *, otError) {}
|
void LogDomainPrefix(const char *, Error) {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
BackboneRouterState mState;
|
BackboneRouterState mState;
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ Manager::Manager(Instance &aInstance)
|
|||||||
|
|
||||||
void Manager::HandleNotifierEvents(Events aEvents)
|
void Manager::HandleNotifierEvents(Events aEvents)
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
if (aEvents.Contains(kEventThreadBackboneRouterStateChanged))
|
if (aEvents.Contains(kEventThreadBackboneRouterStateChanged))
|
||||||
{
|
{
|
||||||
@@ -105,13 +105,13 @@ void Manager::HandleNotifierEvents(Events aEvents)
|
|||||||
|
|
||||||
error = mBackboneTmfAgent.Stop();
|
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
|
else
|
||||||
{
|
{
|
||||||
otLogInfoBbr("Stop Backbone TMF agent: %s", otThreadErrorToString(error));
|
otLogInfoBbr("Stop Backbone TMF agent: %s", ErrorToString(error));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -155,7 +155,7 @@ void Manager::HandleTimer(void)
|
|||||||
#if OPENTHREAD_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE
|
#if OPENTHREAD_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE
|
||||||
void Manager::HandleMulticastListenerRegistration(const Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
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();
|
bool isPrimary = Get<BackboneRouter::Local>().IsPrimary();
|
||||||
ThreadStatusTlv::MlrStatus status = ThreadStatusTlv::kMlrSuccess;
|
ThreadStatusTlv::MlrStatus status = ThreadStatusTlv::kMlrSuccess;
|
||||||
BackboneRouterConfig config;
|
BackboneRouterConfig config;
|
||||||
@@ -171,7 +171,7 @@ void Manager::HandleMulticastListenerRegistration(const Coap::Message &aMessage,
|
|||||||
bool hasCommissionerSessionIdTlv = false;
|
bool hasCommissionerSessionIdTlv = false;
|
||||||
bool processTimeoutTlv = false;
|
bool processTimeoutTlv = false;
|
||||||
|
|
||||||
VerifyOrExit(aMessage.IsConfirmablePostRequest(), error = OT_ERROR_PARSE);
|
VerifyOrExit(aMessage.IsConfirmablePostRequest(), error = kErrorParse);
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||||
// Required by Test Specification 5.10.22 DUA-TC-26, only for certification purpose
|
// 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
|
// 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 =
|
const MeshCoP::CommissionerSessionIdTlv *commissionerSessionIdTlv =
|
||||||
static_cast<const MeshCoP::CommissionerSessionIdTlv *>(
|
static_cast<const MeshCoP::CommissionerSessionIdTlv *>(
|
||||||
@@ -199,12 +199,11 @@ void Manager::HandleMulticastListenerRegistration(const Coap::Message &aMessage,
|
|||||||
hasCommissionerSessionIdTlv = true;
|
hasCommissionerSessionIdTlv = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
processTimeoutTlv =
|
processTimeoutTlv = hasCommissionerSessionIdTlv && (Tlv::Find<ThreadTimeoutTlv>(aMessage, timeout) == kErrorNone);
|
||||||
hasCommissionerSessionIdTlv && (Tlv::Find<ThreadTimeoutTlv>(aMessage, timeout) == OT_ERROR_NONE);
|
|
||||||
|
|
||||||
VerifyOrExit(Tlv::FindTlvValueOffset(aMessage, IPv6AddressesTlv::kIPv6Addresses, addressesOffset,
|
VerifyOrExit(Tlv::FindTlvValueOffset(aMessage, IPv6AddressesTlv::kIPv6Addresses, addressesOffset,
|
||||||
addressesLength) == OT_ERROR_NONE,
|
addressesLength) == kErrorNone,
|
||||||
error = OT_ERROR_PARSE);
|
error = kErrorParse);
|
||||||
VerifyOrExit(addressesLength % sizeof(Ip6::Address) == 0, status = ThreadStatusTlv::kMlrGeneralFailure);
|
VerifyOrExit(addressesLength % sizeof(Ip6::Address) == 0, status = ThreadStatusTlv::kMlrGeneralFailure);
|
||||||
VerifyOrExit(addressesLength / sizeof(Ip6::Address) <= kIPv6AddressesNumMax,
|
VerifyOrExit(addressesLength / sizeof(Ip6::Address) <= kIPv6AddressesNumMax,
|
||||||
status = ThreadStatusTlv::kMlrGeneralFailure);
|
status = ThreadStatusTlv::kMlrGeneralFailure);
|
||||||
@@ -249,16 +248,16 @@ void Manager::HandleMulticastListenerRegistration(const Coap::Message &aMessage,
|
|||||||
|
|
||||||
switch (mMulticastListenersTable.Add(address, expireTime))
|
switch (mMulticastListenersTable.Add(address, expireTime))
|
||||||
{
|
{
|
||||||
case OT_ERROR_NONE:
|
case kErrorNone:
|
||||||
failed = false;
|
failed = false;
|
||||||
break;
|
break;
|
||||||
case OT_ERROR_INVALID_ARGS:
|
case kErrorInvalidArgs:
|
||||||
if (status == ThreadStatusTlv::kMlrSuccess)
|
if (status == ThreadStatusTlv::kMlrSuccess)
|
||||||
{
|
{
|
||||||
status = ThreadStatusTlv::kMlrInvalid;
|
status = ThreadStatusTlv::kMlrInvalid;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case OT_ERROR_NO_BUFS:
|
case kErrorNoBufs:
|
||||||
if (status == ThreadStatusTlv::kMlrSuccess)
|
if (status == ThreadStatusTlv::kMlrSuccess)
|
||||||
{
|
{
|
||||||
status = ThreadStatusTlv::kMlrNoResources;
|
status = ThreadStatusTlv::kMlrNoResources;
|
||||||
@@ -281,7 +280,7 @@ void Manager::HandleMulticastListenerRegistration(const Coap::Message &aMessage,
|
|||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if (error == OT_ERROR_NONE)
|
if (error == kErrorNone)
|
||||||
{
|
{
|
||||||
SendMulticastListenerRegistrationResponse(aMessage, aMessageInfo, status, addresses, failedAddressNum);
|
SendMulticastListenerRegistrationResponse(aMessage, aMessageInfo, status, addresses, failedAddressNum);
|
||||||
}
|
}
|
||||||
@@ -299,10 +298,10 @@ void Manager::SendMulticastListenerRegistrationResponse(const Coap::Message &
|
|||||||
Ip6::Address * aFailedAddresses,
|
Ip6::Address * aFailedAddresses,
|
||||||
uint8_t aFailedAddressNum)
|
uint8_t aFailedAddressNum)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Coap::Message *message = nullptr;
|
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->SetDefaultResponseHeader(aMessage));
|
||||||
SuccessOrExit(message->SetPayloadMarker());
|
SuccessOrExit(message->SetPayloadMarker());
|
||||||
@@ -327,14 +326,14 @@ void Manager::SendMulticastListenerRegistrationResponse(const Coap::Message &
|
|||||||
|
|
||||||
exit:
|
exit:
|
||||||
FreeMessageOnError(message, error);
|
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,
|
void Manager::SendBackboneMulticastListenerRegistration(const Ip6::Address *aAddresses,
|
||||||
uint8_t aAddressNum,
|
uint8_t aAddressNum,
|
||||||
uint32_t aTimeout)
|
uint32_t aTimeout)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Coap::Message * message = nullptr;
|
Coap::Message * message = nullptr;
|
||||||
Ip6::MessageInfo messageInfo;
|
Ip6::MessageInfo messageInfo;
|
||||||
IPv6AddressesTlv addressesTlv;
|
IPv6AddressesTlv addressesTlv;
|
||||||
@@ -342,7 +341,7 @@ void Manager::SendBackboneMulticastListenerRegistration(const Ip6::Address *aAdd
|
|||||||
|
|
||||||
OT_ASSERT(aAddressNum >= kIPv6AddressesNumMin && aAddressNum <= kIPv6AddressesNumMax);
|
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->InitAsNonConfirmablePost(UriPath::kBackboneMlr));
|
||||||
SuccessOrExit(error = message->SetPayloadMarker());
|
SuccessOrExit(error = message->SetPayloadMarker());
|
||||||
@@ -364,14 +363,14 @@ void Manager::SendBackboneMulticastListenerRegistration(const Ip6::Address *aAdd
|
|||||||
|
|
||||||
exit:
|
exit:
|
||||||
FreeMessageOnError(message, error);
|
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
|
#endif // OPENTHREAD_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_BACKBONE_ROUTER_DUA_NDPROXYING_ENABLE
|
#if OPENTHREAD_CONFIG_BACKBONE_ROUTER_DUA_NDPROXYING_ENABLE
|
||||||
void Manager::HandleDuaRegistration(const Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
void Manager::HandleDuaRegistration(const Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
ThreadStatusTlv::DuaStatus status = ThreadStatusTlv::kDuaSuccess;
|
ThreadStatusTlv::DuaStatus status = ThreadStatusTlv::kDuaSuccess;
|
||||||
bool isPrimary = Get<BackboneRouter::Local>().IsPrimary();
|
bool isPrimary = Get<BackboneRouter::Local>().IsPrimary();
|
||||||
uint32_t lastTransactionTime;
|
uint32_t lastTransactionTime;
|
||||||
@@ -382,8 +381,8 @@ void Manager::HandleDuaRegistration(const Coap::Message &aMessage, const Ip6::Me
|
|||||||
Coap::Code duaRespCoapCode = Coap::kCodeEmpty;
|
Coap::Code duaRespCoapCode = Coap::kCodeEmpty;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
VerifyOrExit(aMessageInfo.GetPeerAddr().GetIid().IsRoutingLocator(), error = OT_ERROR_DROP);
|
VerifyOrExit(aMessageInfo.GetPeerAddr().GetIid().IsRoutingLocator(), error = kErrorDrop);
|
||||||
VerifyOrExit(aMessage.IsConfirmablePostRequest(), error = OT_ERROR_PARSE);
|
VerifyOrExit(aMessage.IsConfirmablePostRequest(), error = kErrorParse);
|
||||||
|
|
||||||
SuccessOrExit(error = Tlv::Find<ThreadTargetTlv>(aMessage, target));
|
SuccessOrExit(error = Tlv::Find<ThreadTargetTlv>(aMessage, target));
|
||||||
SuccessOrExit(error = Tlv::Find<ThreadMeshLocalEidTlv>(aMessage, meshLocalIid));
|
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>().HasDomainPrefix(), status = ThreadStatusTlv::kDuaGeneralFailure);
|
||||||
VerifyOrExit(Get<BackboneRouter::Leader>().IsDomainUnicast(target), status = ThreadStatusTlv::kDuaInvalid);
|
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(),
|
switch (mNdProxyTable.Register(target.GetIid(), meshLocalIid, aMessageInfo.GetPeerAddr().GetIid().GetLocator(),
|
||||||
hasLastTransactionTime ? &lastTransactionTime : nullptr))
|
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
|
// 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
|
// DUA.req packet according to Thread Spec. 5.23.3.6.2
|
||||||
break;
|
break;
|
||||||
case OT_ERROR_DUPLICATED:
|
case kErrorDuplicated:
|
||||||
status = ThreadStatusTlv::kDuaDuplicate;
|
status = ThreadStatusTlv::kDuaDuplicate;
|
||||||
break;
|
break;
|
||||||
case OT_ERROR_NO_BUFS:
|
case kErrorNoBufs:
|
||||||
status = ThreadStatusTlv::kDuaNoResources;
|
status = ThreadStatusTlv::kDuaNoResources;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -429,9 +428,9 @@ void Manager::HandleDuaRegistration(const Coap::Message &aMessage, const Ip6::Me
|
|||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
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 OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||||
if (duaRespCoapCode != Coap::kCodeEmpty)
|
if (duaRespCoapCode != Coap::kCodeEmpty)
|
||||||
@@ -451,10 +450,10 @@ void Manager::SendDuaRegistrationResponse(const Coap::Message & aMessage,
|
|||||||
const Ip6::Address & aTarget,
|
const Ip6::Address & aTarget,
|
||||||
ThreadStatusTlv::DuaStatus aStatus)
|
ThreadStatusTlv::DuaStatus aStatus)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Coap::Message *message = nullptr;
|
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->SetDefaultResponseHeader(aMessage));
|
||||||
SuccessOrExit(message->SetPayloadMarker());
|
SuccessOrExit(message->SetPayloadMarker());
|
||||||
@@ -467,7 +466,7 @@ void Manager::SendDuaRegistrationResponse(const Coap::Message & aMessage,
|
|||||||
exit:
|
exit:
|
||||||
FreeMessageOnError(message, error);
|
FreeMessageOnError(message, error);
|
||||||
otLogInfoBbr("Sent DUA.rsp for DUA %s, status %d %s", aTarget.ToString().AsCString(), aStatus,
|
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
|
#endif // OPENTHREAD_CONFIG_BACKBONE_ROUTER_DUA_NDPROXYING_ENABLE
|
||||||
|
|
||||||
@@ -509,7 +508,7 @@ bool Manager::ShouldForwardDuaToBackbone(const Ip6::Address &aAddress)
|
|||||||
{
|
{
|
||||||
bool forwardToBackbone = false;
|
bool forwardToBackbone = false;
|
||||||
Mac::ShortAddress rloc16;
|
Mac::ShortAddress rloc16;
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
VerifyOrExit(Get<Local>().IsPrimary());
|
VerifyOrExit(Get<Local>().IsPrimary());
|
||||||
VerifyOrExit(Get<Leader>().IsDomainUnicast(aAddress));
|
VerifyOrExit(Get<Leader>().IsDomainUnicast(aAddress));
|
||||||
@@ -517,7 +516,7 @@ bool Manager::ShouldForwardDuaToBackbone(const Ip6::Address &aAddress)
|
|||||||
VerifyOrExit(!mNdProxyTable.IsRegistered(aAddress.GetIid()));
|
VerifyOrExit(!mNdProxyTable.IsRegistered(aAddress.GetIid()));
|
||||||
|
|
||||||
error = Get<AddressResolver>().Resolve(aAddress, rloc16, /* aAllowAddressQuery */ false);
|
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?
|
// TODO: check if the DUA is an address of any Child?
|
||||||
forwardToBackbone = true;
|
forwardToBackbone = true;
|
||||||
@@ -526,15 +525,15 @@ exit:
|
|||||||
return forwardToBackbone;
|
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;
|
Coap::Message * message = nullptr;
|
||||||
Ip6::MessageInfo messageInfo;
|
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->InitAsNonConfirmablePost(UriPath::kBackboneQuery));
|
||||||
SuccessOrExit(error = message->SetPayloadMarker());
|
SuccessOrExit(error = message->SetPayloadMarker());
|
||||||
@@ -556,7 +555,7 @@ otError Manager::SendBackboneQuery(const Ip6::Address &aDua, uint16_t aRloc16)
|
|||||||
|
|
||||||
exit:
|
exit:
|
||||||
otLogInfoBbr("SendBackboneQuery for %s (rloc16=%04x): %s", aDua.ToString().AsCString(), aRloc16,
|
otLogInfoBbr("SendBackboneQuery for %s (rloc16=%04x): %s", aDua.ToString().AsCString(), aRloc16,
|
||||||
otThreadErrorToString(error));
|
ErrorToString(error));
|
||||||
FreeMessageOnError(message, error);
|
FreeMessageOnError(message, error);
|
||||||
return 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)
|
void Manager::HandleBackboneQuery(const Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Ip6::Address dua;
|
Ip6::Address dua;
|
||||||
uint16_t rloc16 = Mac::kShortAddrInvalid;
|
uint16_t rloc16 = Mac::kShortAddrInvalid;
|
||||||
NdProxyTable::NdProxy *ndProxy;
|
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(Get<Local>().IsPrimary(), error = kErrorInvalidState);
|
||||||
VerifyOrExit(aMessage.IsNonConfirmablePostRequest(), error = OT_ERROR_PARSE);
|
VerifyOrExit(aMessage.IsNonConfirmablePostRequest(), error = kErrorParse);
|
||||||
|
|
||||||
SuccessOrExit(error = Tlv::Find<ThreadTargetTlv>(aMessage, dua));
|
SuccessOrExit(error = Tlv::Find<ThreadTargetTlv>(aMessage, dua));
|
||||||
|
|
||||||
error = Tlv::Find<ThreadRloc16Tlv>(aMessage, rloc16);
|
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(),
|
otLogInfoBbr("Received BB.qry from %s for %s (rloc16=%04x)", aMessageInfo.GetPeerAddr().ToString().AsCString(),
|
||||||
dua.ToString().AsCString(), rloc16);
|
dua.ToString().AsCString(), rloc16);
|
||||||
|
|
||||||
ndProxy = mNdProxyTable.ResolveDua(dua);
|
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);
|
error = SendBackboneAnswer(aMessageInfo, dua, rloc16, *ndProxy);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
otLogInfoBbr("HandleBackboneQuery: %s", otThreadErrorToString(error));
|
otLogInfoBbr("HandleBackboneQuery: %s", ErrorToString(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::HandleBackboneAnswer(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo)
|
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)
|
void Manager::HandleBackboneAnswer(const Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
bool proactive;
|
bool proactive;
|
||||||
Ip6::Address dua;
|
Ip6::Address dua;
|
||||||
Ip6::InterfaceIdentifier meshLocalIid;
|
Ip6::InterfaceIdentifier meshLocalIid;
|
||||||
@@ -612,10 +611,10 @@ void Manager::HandleBackboneAnswer(const Coap::Message &aMessage, const Ip6::Mes
|
|||||||
uint32_t timeSinceLastTransaction;
|
uint32_t timeSinceLastTransaction;
|
||||||
uint16_t srcRloc16 = Mac::kShortAddrInvalid;
|
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(Get<Local>().IsPrimary(), error = kErrorInvalidState);
|
||||||
VerifyOrExit(aMessage.IsPostRequest(), error = OT_ERROR_PARSE);
|
VerifyOrExit(aMessage.IsPostRequest(), error = kErrorParse);
|
||||||
|
|
||||||
proactive = !aMessage.IsConfirmable();
|
proactive = !aMessage.IsConfirmable();
|
||||||
|
|
||||||
@@ -627,7 +626,7 @@ void Manager::HandleBackboneAnswer(const Coap::Message &aMessage, const Ip6::Mes
|
|||||||
Tlv::FindTlvValueOffset(aMessage, ThreadTlv::kNetworkName, networkNameOffset, networkNameLength));
|
Tlv::FindTlvValueOffset(aMessage, ThreadTlv::kNetworkName, networkNameOffset, networkNameLength));
|
||||||
|
|
||||||
error = Tlv::Find<ThreadRloc16Tlv>(aMessage, srcRloc16);
|
error = Tlv::Find<ThreadRloc16Tlv>(aMessage, srcRloc16);
|
||||||
VerifyOrExit(error == OT_ERROR_NONE || error == OT_ERROR_NOT_FOUND);
|
VerifyOrExit(error == kErrorNone || error == kErrorNotFound);
|
||||||
|
|
||||||
if (proactive)
|
if (proactive)
|
||||||
{
|
{
|
||||||
@@ -645,40 +644,40 @@ void Manager::HandleBackboneAnswer(const Coap::Message &aMessage, const Ip6::Mes
|
|||||||
SuccessOrExit(error = mBackboneTmfAgent.SendEmptyAck(aMessage, aMessageInfo));
|
SuccessOrExit(error = mBackboneTmfAgent.SendEmptyAck(aMessage, aMessageInfo));
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
otLogInfoBbr("HandleBackboneAnswer: %s", otThreadErrorToString(error));
|
otLogInfoBbr("HandleBackboneAnswer: %s", ErrorToString(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Manager::SendProactiveBackboneNotification(const Ip6::Address & aDua,
|
Error Manager::SendProactiveBackboneNotification(const Ip6::Address & aDua,
|
||||||
const Ip6::InterfaceIdentifier &aMeshLocalIid,
|
const Ip6::InterfaceIdentifier &aMeshLocalIid,
|
||||||
uint32_t aTimeSinceLastTransaction)
|
uint32_t aTimeSinceLastTransaction)
|
||||||
{
|
{
|
||||||
return SendBackboneAnswer(Get<BackboneRouter::Local>().GetAllDomainBackboneRoutersAddress(),
|
return SendBackboneAnswer(Get<BackboneRouter::Local>().GetAllDomainBackboneRoutersAddress(),
|
||||||
BackboneRouter::kBackboneUdpPort, aDua, aMeshLocalIid, aTimeSinceLastTransaction,
|
BackboneRouter::kBackboneUdpPort, aDua, aMeshLocalIid, aTimeSinceLastTransaction,
|
||||||
Mac::kShortAddrInvalid);
|
Mac::kShortAddrInvalid);
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Manager::SendBackboneAnswer(const Ip6::MessageInfo & aQueryMessageInfo,
|
Error Manager::SendBackboneAnswer(const Ip6::MessageInfo & aQueryMessageInfo,
|
||||||
const Ip6::Address & aDua,
|
const Ip6::Address & aDua,
|
||||||
uint16_t aSrcRloc16,
|
uint16_t aSrcRloc16,
|
||||||
const NdProxyTable::NdProxy &aNdProxy)
|
const NdProxyTable::NdProxy &aNdProxy)
|
||||||
{
|
{
|
||||||
return SendBackboneAnswer(aQueryMessageInfo.GetPeerAddr(), aQueryMessageInfo.GetPeerPort(), aDua,
|
return SendBackboneAnswer(aQueryMessageInfo.GetPeerAddr(), aQueryMessageInfo.GetPeerPort(), aDua,
|
||||||
aNdProxy.GetMeshLocalIid(), aNdProxy.GetTimeSinceLastTransaction(), aSrcRloc16);
|
aNdProxy.GetMeshLocalIid(), aNdProxy.GetTimeSinceLastTransaction(), aSrcRloc16);
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Manager::SendBackboneAnswer(const Ip6::Address & aDstAddr,
|
Error Manager::SendBackboneAnswer(const Ip6::Address & aDstAddr,
|
||||||
uint16_t aDstPort,
|
uint16_t aDstPort,
|
||||||
const Ip6::Address & aDua,
|
const Ip6::Address & aDua,
|
||||||
const Ip6::InterfaceIdentifier &aMeshLocalIid,
|
const Ip6::InterfaceIdentifier &aMeshLocalIid,
|
||||||
uint32_t aTimeSinceLastTransaction,
|
uint32_t aTimeSinceLastTransaction,
|
||||||
uint16_t aSrcRloc16)
|
uint16_t aSrcRloc16)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Coap::Message * message = nullptr;
|
Coap::Message * message = nullptr;
|
||||||
Ip6::MessageInfo messageInfo;
|
Ip6::MessageInfo messageInfo;
|
||||||
bool proactive = aDstAddr.IsMulticast();
|
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,
|
SuccessOrExit(error = message->Init(proactive ? Coap::kTypeNonConfirmable : Coap::kTypeConfirmable, Coap::kCodePost,
|
||||||
UriPath::kBackboneAnswer));
|
UriPath::kBackboneAnswer));
|
||||||
@@ -711,7 +710,7 @@ otError Manager::SendBackboneAnswer(const Ip6::Address & aDstAddr,
|
|||||||
|
|
||||||
exit:
|
exit:
|
||||||
otLogInfoBbr("Send %s for %s (rloc16=%04x): %s", proactive ? "PRO_BB.ntf" : "BB.ans", aDua.ToString().AsCString(),
|
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);
|
FreeMessageOnError(message, error);
|
||||||
return error;
|
return error;
|
||||||
@@ -719,13 +718,13 @@ exit:
|
|||||||
|
|
||||||
void Manager::HandleDadBackboneAnswer(const Ip6::Address &aDua, const Ip6::InterfaceIdentifier &aMeshLocalIid)
|
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);
|
NdProxyTable::NdProxy *ndProxy = mNdProxyTable.ResolveDua(aDua);
|
||||||
bool duplicate = false;
|
bool duplicate = false;
|
||||||
|
|
||||||
OT_UNUSED_VARIABLE(error);
|
OT_UNUSED_VARIABLE(error);
|
||||||
|
|
||||||
VerifyOrExit(ndProxy != nullptr, error = OT_ERROR_NOT_FOUND);
|
VerifyOrExit(ndProxy != nullptr, error = kErrorNotFound);
|
||||||
|
|
||||||
duplicate = ndProxy->GetMeshLocalIid() != aMeshLocalIid;
|
duplicate = ndProxy->GetMeshLocalIid() != aMeshLocalIid;
|
||||||
|
|
||||||
@@ -740,7 +739,7 @@ void Manager::HandleDadBackboneAnswer(const Ip6::Address &aDua, const Ip6::Inter
|
|||||||
ot::BackboneRouter::NdProxyTable::NotifyDadComplete(*ndProxy, duplicate);
|
ot::BackboneRouter::NdProxyTable::NotifyDadComplete(*ndProxy, duplicate);
|
||||||
|
|
||||||
exit:
|
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");
|
aDua.ToString().AsCString(), aMeshLocalIid.ToString().AsCString(), duplicate ? "Y" : "N");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -763,12 +762,12 @@ void Manager::HandleProactiveBackboneNotification(const Ip6::Address &
|
|||||||
const Ip6::InterfaceIdentifier &aMeshLocalIid,
|
const Ip6::InterfaceIdentifier &aMeshLocalIid,
|
||||||
uint32_t aTimeSinceLastTransaction)
|
uint32_t aTimeSinceLastTransaction)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
NdProxyTable::NdProxy *ndProxy = mNdProxyTable.ResolveDua(aDua);
|
NdProxyTable::NdProxy *ndProxy = mNdProxyTable.ResolveDua(aDua);
|
||||||
|
|
||||||
OT_UNUSED_VARIABLE(error);
|
OT_UNUSED_VARIABLE(error);
|
||||||
|
|
||||||
VerifyOrExit(ndProxy != nullptr, error = OT_ERROR_NOT_FOUND);
|
VerifyOrExit(ndProxy != nullptr, error = kErrorNotFound);
|
||||||
|
|
||||||
if (ndProxy->GetMeshLocalIid() == aMeshLocalIid)
|
if (ndProxy->GetMeshLocalIid() == aMeshLocalIid)
|
||||||
{
|
{
|
||||||
@@ -792,7 +791,7 @@ void Manager::HandleProactiveBackboneNotification(const Ip6::Address &
|
|||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
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);
|
aDua.ToString().AsCString(), aMeshLocalIid.ToString().AsCString(), aTimeSinceLastTransaction);
|
||||||
}
|
}
|
||||||
#endif // OPENTHREAD_CONFIG_BACKBONE_ROUTER_DUA_NDPROXYING_ENABLE
|
#endif // OPENTHREAD_CONFIG_BACKBONE_ROUTER_DUA_NDPROXYING_ENABLE
|
||||||
|
|||||||
@@ -145,12 +145,12 @@ public:
|
|||||||
* @param[in] aRloc16 The short address of the address resolution initiator or `Mac::kShortAddrInvalid` for
|
* @param[in] aRloc16 The short address of the address resolution initiator or `Mac::kShortAddrInvalid` for
|
||||||
* DUA DAD.
|
* DUA DAD.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully sent BB.qry on backbone link.
|
* @retval kErrorNone Successfully sent BB.qry on backbone link.
|
||||||
* @retval OT_ERROR_INVALID_STATE If the Backbone Router is not primary, or not enabled.
|
* @retval kErrorInvalidState If the Backbone Router is not primary, or not enabled.
|
||||||
* @retval OT_ERROR_NO_BUFS If insufficient message buffers available.
|
* @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.
|
* 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] aMeshLocalIid The Mesh-Local IID to notify.
|
||||||
* @param[in] aTimeSinceLastTransaction Time since last transaction (in seconds).
|
* @param[in] aTimeSinceLastTransaction Time since last transaction (in seconds).
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully sent PRO_BB.ntf on backbone link.
|
* @retval kErrorNone Successfully sent PRO_BB.ntf on backbone link.
|
||||||
* @retval OT_ERROR_NO_BUFS If insufficient message buffers available.
|
* @retval kErrorNoBufs If insufficient message buffers available.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError SendProactiveBackboneNotification(const Ip6::Address & aDua,
|
Error SendProactiveBackboneNotification(const Ip6::Address & aDua,
|
||||||
const Ip6::InterfaceIdentifier &aMeshLocalIid,
|
const Ip6::InterfaceIdentifier &aMeshLocalIid,
|
||||||
uint32_t aTimeSinceLastTransaction);
|
uint32_t aTimeSinceLastTransaction);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum
|
enum
|
||||||
@@ -204,11 +204,11 @@ private:
|
|||||||
void HandleBackboneQuery(const Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
void HandleBackboneQuery(const Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||||
static void HandleBackboneAnswer(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo);
|
static void HandleBackboneAnswer(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo);
|
||||||
void HandleBackboneAnswer(const Coap::Message &aMessage, const Ip6::MessageInfo &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,
|
const Ip6::Address & aDua,
|
||||||
uint16_t aSrcRloc16,
|
uint16_t aSrcRloc16,
|
||||||
const NdProxyTable::NdProxy &aNdProxy);
|
const NdProxyTable::NdProxy &aNdProxy);
|
||||||
otError SendBackboneAnswer(const Ip6::Address & aDstAddr,
|
Error SendBackboneAnswer(const Ip6::Address & aDstAddr,
|
||||||
uint16_t aDstPort,
|
uint16_t aDstPort,
|
||||||
const Ip6::Address & aDua,
|
const Ip6::Address & aDua,
|
||||||
const Ip6::InterfaceIdentifier &aMeshLocalIid,
|
const Ip6::InterfaceIdentifier &aMeshLocalIid,
|
||||||
|
|||||||
@@ -48,11 +48,11 @@ namespace ot {
|
|||||||
|
|
||||||
namespace BackboneRouter {
|
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++)
|
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].SetAddress(aAddress);
|
||||||
mListeners[mNumValidListeners].SetExpireTime(aExpireTime);
|
mListeners[mNumValidListeners].SetExpireTime(aExpireTime);
|
||||||
@@ -87,7 +87,7 @@ exit:
|
|||||||
|
|
||||||
void MulticastListenersTable::Remove(const Ip6::Address &aAddress)
|
void MulticastListenersTable::Remove(const Ip6::Address &aAddress)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NOT_FOUND;
|
Error error = kErrorNotFound;
|
||||||
|
|
||||||
for (uint16_t i = 0; i < mNumValidListeners; i++)
|
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);
|
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())
|
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();
|
address = mListeners[0].GetAddress();
|
||||||
|
|
||||||
mNumValidListeners--;
|
mNumValidListeners--;
|
||||||
@@ -147,7 +147,7 @@ void MulticastListenersTable::Expire(void)
|
|||||||
void MulticastListenersTable::LogMulticastListenersTable(const char * aAction,
|
void MulticastListenersTable::LogMulticastListenersTable(const char * aAction,
|
||||||
const Ip6::Address &aAddress,
|
const Ip6::Address &aAddress,
|
||||||
TimeMilli aExpireTime,
|
TimeMilli aExpireTime,
|
||||||
otError aError)
|
Error aError)
|
||||||
{
|
{
|
||||||
OT_UNUSED_VARIABLE(aAction);
|
OT_UNUSED_VARIABLE(aAction);
|
||||||
OT_UNUSED_VARIABLE(aAddress);
|
OT_UNUSED_VARIABLE(aAddress);
|
||||||
@@ -155,7 +155,7 @@ void MulticastListenersTable::LogMulticastListenersTable(const char * aAc
|
|||||||
OT_UNUSED_VARIABLE(aError);
|
OT_UNUSED_VARIABLE(aError);
|
||||||
|
|
||||||
otLogDebgBbr("MulticastListenersTable: %s %s expire %u: %s", aAction, aAddress.ToString().AsCString(),
|
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)
|
void MulticastListenersTable::FixHeap(uint16_t aIndex)
|
||||||
@@ -287,13 +287,13 @@ void MulticastListenersTable::SetCallback(otBackboneRouterMulticastListenerCallb
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
otError MulticastListenersTable::GetNext(otBackboneRouterMulticastListenerIterator &aIterator,
|
Error MulticastListenersTable::GetNext(otBackboneRouterMulticastListenerIterator &aIterator,
|
||||||
otBackboneRouterMulticastListenerInfo & aListenerInfo)
|
otBackboneRouterMulticastListenerInfo & aListenerInfo)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
TimeMilli now;
|
TimeMilli now;
|
||||||
|
|
||||||
VerifyOrExit(aIterator < mNumValidListeners, error = OT_ERROR_NOT_FOUND);
|
VerifyOrExit(aIterator < mNumValidListeners, error = kErrorNotFound);
|
||||||
|
|
||||||
now = TimerMilli::GetNow();
|
now = TimerMilli::GetNow();
|
||||||
|
|
||||||
|
|||||||
@@ -119,12 +119,12 @@ public:
|
|||||||
* @param[in] aAddress The Multicast Listener address.
|
* @param[in] aAddress The Multicast Listener address.
|
||||||
* @param[in] aExpireTime The Multicast Listener expire time.
|
* @param[in] aExpireTime The Multicast Listener expire time.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE If the Multicast Listener was successfully added.
|
* @retval kErrorNone If the Multicast Listener was successfully added.
|
||||||
* @retval OT_ERROR_INVALID_ARGS If the Multicast Listener address was invalid.
|
* @retval kErrorInvalidArgs If the Multicast Listener address was invalid.
|
||||||
* @retval OT_ERROR_NO_BUFS No space available to save the Multicast Listener.
|
* @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.
|
* This method removes a given Multicast Listener.
|
||||||
@@ -181,12 +181,12 @@ public:
|
|||||||
* @param[in] aIterator A pointer to the Multicast Listener Iterator.
|
* @param[in] aIterator A pointer to the Multicast Listener Iterator.
|
||||||
* @param[out] aListenerInfo A pointer to where the Multicast Listener info is placed.
|
* @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 kErrorNone Successfully found the next Multicast Listener info.
|
||||||
* @retval OT_ERROR_NOT_FOUND No subsequent Multicast Listener was found.
|
* @retval kErrorNotFound No subsequent Multicast Listener was found.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError GetNext(otBackboneRouterMulticastListenerIterator &aIterator,
|
Error GetNext(otBackboneRouterMulticastListenerIterator &aIterator,
|
||||||
otBackboneRouterMulticastListenerInfo & aListenerInfo);
|
otBackboneRouterMulticastListenerInfo & aListenerInfo);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum
|
enum
|
||||||
@@ -213,7 +213,7 @@ private:
|
|||||||
void LogMulticastListenersTable(const char * aAction,
|
void LogMulticastListenersTable(const char * aAction,
|
||||||
const Ip6::Address &aAddress,
|
const Ip6::Address &aAddress,
|
||||||
TimeMilli aExpireTime,
|
TimeMilli aExpireTime,
|
||||||
otError aError);
|
Error aError);
|
||||||
|
|
||||||
void FixHeap(uint16_t aIndex);
|
void FixHeap(uint16_t aIndex);
|
||||||
bool SiftHeapElemDown(uint16_t aIndex);
|
bool SiftHeapElemDown(uint16_t aIndex);
|
||||||
|
|||||||
@@ -149,18 +149,18 @@ void NdProxyTable::Clear(void)
|
|||||||
otLogNoteBbr("NdProxyTable::Clear!");
|
otLogNoteBbr("NdProxyTable::Clear!");
|
||||||
}
|
}
|
||||||
|
|
||||||
otError NdProxyTable::Register(const Ip6::InterfaceIdentifier &aAddressIid,
|
Error NdProxyTable::Register(const Ip6::InterfaceIdentifier &aAddressIid,
|
||||||
const Ip6::InterfaceIdentifier &aMeshLocalIid,
|
const Ip6::InterfaceIdentifier &aMeshLocalIid,
|
||||||
uint16_t aRloc16,
|
uint16_t aRloc16,
|
||||||
const uint32_t * aTimeSinceLastTransaction)
|
const uint32_t * aTimeSinceLastTransaction)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
NdProxy *proxy = FindByAddressIid(aAddressIid);
|
NdProxy *proxy = FindByAddressIid(aAddressIid);
|
||||||
uint32_t timeSinceLastTransaction = aTimeSinceLastTransaction == nullptr ? 0 : *aTimeSinceLastTransaction;
|
uint32_t timeSinceLastTransaction = aTimeSinceLastTransaction == nullptr ? 0 : *aTimeSinceLastTransaction;
|
||||||
|
|
||||||
if (proxy != nullptr)
|
if (proxy != nullptr)
|
||||||
{
|
{
|
||||||
VerifyOrExit(proxy->mMeshLocalIid == aMeshLocalIid, error = OT_ERROR_DUPLICATED);
|
VerifyOrExit(proxy->mMeshLocalIid == aMeshLocalIid, error = kErrorDuplicated);
|
||||||
|
|
||||||
proxy->Update(aRloc16, timeSinceLastTransaction);
|
proxy->Update(aRloc16, timeSinceLastTransaction);
|
||||||
NotifyDuaRegistrationOnBackboneLink(*proxy, /* aIsRenew */ true);
|
NotifyDuaRegistrationOnBackboneLink(*proxy, /* aIsRenew */ true);
|
||||||
@@ -178,7 +178,7 @@ otError NdProxyTable::Register(const Ip6::InterfaceIdentifier &aAddressIid,
|
|||||||
proxy = FindInvalid();
|
proxy = FindInvalid();
|
||||||
|
|
||||||
// TODO: evict stale DUA entries to have room for this new DUA.
|
// 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);
|
proxy->Init(aAddressIid, aMeshLocalIid, aRloc16, timeSinceLastTransaction);
|
||||||
@@ -186,7 +186,7 @@ otError NdProxyTable::Register(const Ip6::InterfaceIdentifier &aAddressIid,
|
|||||||
|
|
||||||
exit:
|
exit:
|
||||||
otLogInfoBbr("NdProxyTable::Register %s MLIID %s RLOC16 %04x LTT %u => %s", aAddressIid.ToString().AsCString(),
|
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;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,7 +257,7 @@ void NdProxyTable::HandleTimer(void)
|
|||||||
{
|
{
|
||||||
mIsAnyDadInProcess = true;
|
mIsAnyDadInProcess = true;
|
||||||
|
|
||||||
if (Get<BackboneRouter::Manager>().SendBackboneQuery(GetDua(proxy)) == OT_ERROR_NONE)
|
if (Get<BackboneRouter::Manager>().SendBackboneQuery(GetDua(proxy)) == kErrorNone)
|
||||||
{
|
{
|
||||||
proxy.IncreaseDadAttampts();
|
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))
|
for (NdProxy &proxy : Iterate(kFilterValid))
|
||||||
{
|
{
|
||||||
@@ -349,7 +349,7 @@ otError NdProxyTable::GetInfo(const Ip6::Address &aDua, otBackboneRouterNdProxyI
|
|||||||
aNdProxyInfo.mTimeSinceLastTransaction = proxy.GetTimeSinceLastTransaction();
|
aNdProxyInfo.mTimeSinceLastTransaction = proxy.GetTimeSinceLastTransaction();
|
||||||
aNdProxyInfo.mRloc16 = proxy.mRloc16;
|
aNdProxyInfo.mRloc16 = proxy.mRloc16;
|
||||||
|
|
||||||
ExitNow(error = OT_ERROR_NONE);
|
ExitNow(error = kErrorNone);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -147,15 +147,15 @@ public:
|
|||||||
* @param[in] aRloc16 The RLOC16.
|
* @param[in] aRloc16 The RLOC16.
|
||||||
* @param[in] aTimeSinceLastTransaction Time since last transaction (in seconds).
|
* @param[in] aTimeSinceLastTransaction Time since last transaction (in seconds).
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE If registered successfully.
|
* @retval kErrorNone If registered successfully.
|
||||||
* @retval OT_ERROR_DUPLICATED If the Ip6 address IID is a duplicate.
|
* @retval kErrorDuplicated If the Ip6 address IID is a duplicate.
|
||||||
* @retval OT_ERROR_NO_BUFS Insufficient buffer space available to register.
|
* @retval kErrorNoBufs Insufficient buffer space available to register.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError Register(const Ip6::InterfaceIdentifier &aAddressIid,
|
Error Register(const Ip6::InterfaceIdentifier &aAddressIid,
|
||||||
const Ip6::InterfaceIdentifier &aMeshLocalIid,
|
const Ip6::InterfaceIdentifier &aMeshLocalIid,
|
||||||
uint16_t aRloc16,
|
uint16_t aRloc16,
|
||||||
const uint32_t * aTimeSinceLastTransaction);
|
const uint32_t * aTimeSinceLastTransaction);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method checks if a given Ip6 address IID was registered.
|
* 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] aDua The Domain Unicast Address to get info.
|
||||||
* @param[in] aNdProxyInfo A pointer to the ND Proxy info.
|
* @param[in] aNdProxyInfo A pointer to the ND Proxy info.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully retrieve the ND Proxy info.
|
* @retval kErrorNone Successfully retrieve the ND Proxy info.
|
||||||
* @retval OT_ERROR_NOT_FOUND Failed to find the Domain Unicast Address in the ND Proxy table.
|
* @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:
|
private:
|
||||||
enum
|
enum
|
||||||
|
|||||||
@@ -82,14 +82,12 @@ RoutingManager::RoutingManager(Instance &aInstance)
|
|||||||
memset(mDiscoveredPrefixes, 0, sizeof(mDiscoveredPrefixes));
|
memset(mDiscoveredPrefixes, 0, sizeof(mDiscoveredPrefixes));
|
||||||
}
|
}
|
||||||
|
|
||||||
otError RoutingManager::Init(uint32_t aInfraIfIndex,
|
Error RoutingManager::Init(uint32_t aInfraIfIndex, bool aInfraIfIsRunning, const Ip6::Address *aInfraIfLinkLocalAddress)
|
||||||
bool aInfraIfIsRunning,
|
|
||||||
const Ip6::Address *aInfraIfLinkLocalAddress)
|
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
VerifyOrExit(!IsInitialized(), error = OT_ERROR_INVALID_STATE);
|
VerifyOrExit(!IsInitialized(), error = kErrorInvalidState);
|
||||||
VerifyOrExit(aInfraIfIndex > 0, error = OT_ERROR_INVALID_ARGS);
|
VerifyOrExit(aInfraIfIndex > 0, error = kErrorInvalidArgs);
|
||||||
|
|
||||||
SuccessOrExit(error = LoadOrGenerateRandomOmrPrefix());
|
SuccessOrExit(error = LoadOrGenerateRandomOmrPrefix());
|
||||||
SuccessOrExit(error = LoadOrGenerateRandomOnLinkPrefix());
|
SuccessOrExit(error = LoadOrGenerateRandomOnLinkPrefix());
|
||||||
@@ -100,18 +98,18 @@ otError RoutingManager::Init(uint32_t aInfraIfIndex,
|
|||||||
SuccessOrExit(error = HandleInfraIfStateChanged(mInfraIfIndex, aInfraIfIsRunning, aInfraIfLinkLocalAddress));
|
SuccessOrExit(error = HandleInfraIfStateChanged(mInfraIfIndex, aInfraIfIsRunning, aInfraIfLinkLocalAddress));
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if (error != OT_ERROR_NONE)
|
if (error != kErrorNone)
|
||||||
{
|
{
|
||||||
mInfraIfIndex = 0;
|
mInfraIfIndex = 0;
|
||||||
}
|
}
|
||||||
return error;
|
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);
|
VerifyOrExit(aEnabled != mIsEnabled);
|
||||||
|
|
||||||
@@ -122,18 +120,18 @@ exit:
|
|||||||
return error;
|
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;
|
Ip6::NetworkPrefix randomOmrPrefix;
|
||||||
|
|
||||||
otLogNoteBr("no valid OMR prefix found in settings, generating new one");
|
otLogNoteBr("no valid OMR prefix found in settings, generating new one");
|
||||||
|
|
||||||
error = randomOmrPrefix.GenerateRandomUla();
|
error = randomOmrPrefix.GenerateRandomUla();
|
||||||
if (error != OT_ERROR_NONE)
|
if (error != kErrorNone)
|
||||||
{
|
{
|
||||||
otLogCritBr("failed to generate random OMR prefix");
|
otLogCritBr("failed to generate random OMR prefix");
|
||||||
ExitNow();
|
ExitNow();
|
||||||
@@ -147,19 +145,18 @@ exit:
|
|||||||
return error;
|
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 ||
|
if (Get<Settings>().ReadOnLinkPrefix(mLocalOnLinkPrefix) != kErrorNone || !IsValidOnLinkPrefix(mLocalOnLinkPrefix))
|
||||||
!IsValidOnLinkPrefix(mLocalOnLinkPrefix))
|
|
||||||
{
|
{
|
||||||
Ip6::NetworkPrefix randomOnLinkPrefix;
|
Ip6::NetworkPrefix randomOnLinkPrefix;
|
||||||
|
|
||||||
otLogNoteBr("no valid on-link prefix found in settings, generating new one");
|
otLogNoteBr("no valid on-link prefix found in settings, generating new one");
|
||||||
|
|
||||||
error = randomOnLinkPrefix.GenerateRandomUla();
|
error = randomOnLinkPrefix.GenerateRandomUla();
|
||||||
if (error != OT_ERROR_NONE)
|
if (error != kErrorNone)
|
||||||
{
|
{
|
||||||
otLogCritBr("failed to generate random on-link prefix");
|
otLogCritBr("failed to generate random on-link prefix");
|
||||||
ExitNow();
|
ExitNow();
|
||||||
@@ -241,19 +238,19 @@ void RoutingManager::RecvIcmp6Message(uint32_t aInfraIfIndex,
|
|||||||
const uint8_t * aBuffer,
|
const uint8_t * aBuffer,
|
||||||
uint16_t aBufferLength)
|
uint16_t aBufferLength)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
const Ip6::Icmp::Header *icmp6Header;
|
const Ip6::Icmp::Header *icmp6Header;
|
||||||
const Ip6::Address * infraLinkLocalAddr;
|
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);
|
infraLinkLocalAddr = static_cast<const Ip6::Address *>(&mInfraIfLinkLocalAddress);
|
||||||
|
|
||||||
// Drop any ICMPv6 messages sent from myself.
|
// 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);
|
icmp6Header = reinterpret_cast<const Ip6::Icmp::Header *>(aBuffer);
|
||||||
|
|
||||||
@@ -270,21 +267,21 @@ void RoutingManager::RecvIcmp6Message(uint32_t aInfraIfIndex,
|
|||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
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,
|
Error RoutingManager::HandleInfraIfStateChanged(uint32_t aInfraIfIndex,
|
||||||
bool aIsRunning,
|
bool aIsRunning,
|
||||||
const Ip6::Address *aLinkLocalAddress)
|
const Ip6::Address *aLinkLocalAddress)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
|
|
||||||
VerifyOrExit(IsInitialized(), error = OT_ERROR_INVALID_STATE);
|
VerifyOrExit(IsInitialized(), error = kErrorInvalidState);
|
||||||
VerifyOrExit(aInfraIfIndex == mInfraIfIndex, error = OT_ERROR_INVALID_ARGS);
|
VerifyOrExit(aInfraIfIndex == mInfraIfIndex, error = kErrorInvalidArgs);
|
||||||
VerifyOrExit(aLinkLocalAddress == nullptr || aLinkLocalAddress->IsLinkLocal(), error = OT_ERROR_INVALID_ARGS);
|
VerifyOrExit(aLinkLocalAddress == nullptr || aLinkLocalAddress->IsLinkLocal(), error = kErrorInvalidArgs);
|
||||||
|
|
||||||
otLogInfoBr("infra interface state changed: %s, link-local-addr=%s", aIsRunning ? "RUNNING" : "NOT RUNNING",
|
otLogInfoBr("infra interface state changed: %s, link-local-addr=%s", aIsRunning ? "RUNNING" : "NOT RUNNING",
|
||||||
(aLinkLocalAddress != nullptr) ? aLinkLocalAddress->ToString().AsCString() : "(null)");
|
(aLinkLocalAddress != nullptr) ? aLinkLocalAddress->ToString().AsCString() : "(null)");
|
||||||
@@ -333,7 +330,7 @@ uint8_t RoutingManager::EvaluateOmrPrefix(Ip6::Prefix *aNewOmrPrefixes, uint8_t
|
|||||||
|
|
||||||
OT_ASSERT(mIsRunning);
|
OT_ASSERT(mIsRunning);
|
||||||
|
|
||||||
while (Get<NetworkData::Leader>().GetNextOnMeshPrefix(iterator, onMeshPrefixConfig) == OT_ERROR_NONE)
|
while (Get<NetworkData::Leader>().GetNextOnMeshPrefix(iterator, onMeshPrefixConfig) == kErrorNone)
|
||||||
{
|
{
|
||||||
uint8_t newPrefixIndex;
|
uint8_t newPrefixIndex;
|
||||||
|
|
||||||
@@ -377,7 +374,7 @@ uint8_t RoutingManager::EvaluateOmrPrefix(Ip6::Prefix *aNewOmrPrefixes, uint8_t
|
|||||||
if (newOmrPrefixNum == 0)
|
if (newOmrPrefixNum == 0)
|
||||||
{
|
{
|
||||||
otLogInfoBr("EvaluateOmrPrefix: no valid OMR prefixes found in Thread network");
|
otLogInfoBr("EvaluateOmrPrefix: no valid OMR prefixes found in Thread network");
|
||||||
if (PublishLocalOmrPrefix() == OT_ERROR_NONE)
|
if (PublishLocalOmrPrefix() == kErrorNone)
|
||||||
{
|
{
|
||||||
aNewOmrPrefixes[newOmrPrefixNum++] = mLocalOmrPrefix;
|
aNewOmrPrefixes[newOmrPrefixNum++] = mLocalOmrPrefix;
|
||||||
}
|
}
|
||||||
@@ -397,9 +394,9 @@ uint8_t RoutingManager::EvaluateOmrPrefix(Ip6::Prefix *aNewOmrPrefixes, uint8_t
|
|||||||
return newOmrPrefixNum;
|
return newOmrPrefixNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError RoutingManager::PublishLocalOmrPrefix(void)
|
Error RoutingManager::PublishLocalOmrPrefix(void)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
NetworkData::OnMeshPrefixConfig omrPrefixConfig;
|
NetworkData::OnMeshPrefixConfig omrPrefixConfig;
|
||||||
|
|
||||||
OT_ASSERT(mIsRunning);
|
OT_ASSERT(mIsRunning);
|
||||||
@@ -414,10 +411,10 @@ otError RoutingManager::PublishLocalOmrPrefix(void)
|
|||||||
omrPrefixConfig.mPreference = OT_ROUTE_PREFERENCE_MED;
|
omrPrefixConfig.mPreference = OT_ROUTE_PREFERENCE_MED;
|
||||||
|
|
||||||
error = Get<NetworkData::Local>().AddOnMeshPrefix(omrPrefixConfig);
|
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",
|
otLogWarnBr("failed to publish local OMR prefix %s in Thread network: %s",
|
||||||
mLocalOmrPrefix.ToString().AsCString(), otThreadErrorToString(error));
|
mLocalOmrPrefix.ToString().AsCString(), ErrorToString(error));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -430,7 +427,7 @@ otError RoutingManager::PublishLocalOmrPrefix(void)
|
|||||||
|
|
||||||
void RoutingManager::UnpublishLocalOmrPrefix(void)
|
void RoutingManager::UnpublishLocalOmrPrefix(void)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
|
|
||||||
VerifyOrExit(mIsRunning);
|
VerifyOrExit(mIsRunning);
|
||||||
|
|
||||||
@@ -440,16 +437,16 @@ void RoutingManager::UnpublishLocalOmrPrefix(void)
|
|||||||
otLogInfoBr("unpublished local OMR prefix %s from Thread network", mLocalOmrPrefix.ToString().AsCString());
|
otLogInfoBr("unpublished local OMR prefix %s from Thread network", mLocalOmrPrefix.ToString().AsCString());
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if (error != OT_ERROR_NONE)
|
if (error != kErrorNone)
|
||||||
{
|
{
|
||||||
otLogWarnBr("failed to unpublish local OMR prefix %s from Thread network: %s",
|
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;
|
NetworkData::ExternalRouteConfig routeConfig;
|
||||||
|
|
||||||
OT_ASSERT(mIsRunning);
|
OT_ASSERT(mIsRunning);
|
||||||
@@ -460,10 +457,9 @@ otError RoutingManager::AddExternalRoute(const Ip6::Prefix &aPrefix, otRoutePref
|
|||||||
routeConfig.mPreference = aRoutePreference;
|
routeConfig.mPreference = aRoutePreference;
|
||||||
|
|
||||||
error = Get<NetworkData::Local>().AddHasRoutePrefix(routeConfig);
|
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(),
|
otLogWarnBr("failed to add external route %s: %s", aPrefix.ToString().AsCString(), ErrorToString(error));
|
||||||
otThreadErrorToString(error));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -476,7 +472,7 @@ otError RoutingManager::AddExternalRoute(const Ip6::Prefix &aPrefix, otRoutePref
|
|||||||
|
|
||||||
void RoutingManager::RemoveExternalRoute(const Ip6::Prefix &aPrefix)
|
void RoutingManager::RemoveExternalRoute(const Ip6::Prefix &aPrefix)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
|
|
||||||
VerifyOrExit(mIsRunning);
|
VerifyOrExit(mIsRunning);
|
||||||
|
|
||||||
@@ -486,10 +482,9 @@ void RoutingManager::RemoveExternalRoute(const Ip6::Prefix &aPrefix)
|
|||||||
otLogInfoBr("removed external route %s", aPrefix.ToString().AsCString());
|
otLogInfoBr("removed external route %s", aPrefix.ToString().AsCString());
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if (error != OT_ERROR_NONE)
|
if (error != kErrorNone)
|
||||||
{
|
{
|
||||||
otLogWarnBr("failed to remove external route %s: %s", aPrefix.ToString().AsCString(),
|
otLogWarnBr("failed to remove external route %s: %s", aPrefix.ToString().AsCString(), ErrorToString(error));
|
||||||
otThreadErrorToString(error));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -539,7 +534,7 @@ const Ip6::Prefix *RoutingManager::EvaluateOnLinkPrefix(void)
|
|||||||
{
|
{
|
||||||
newOnLinkPrefix = mAdvertisedOnLinkPrefix;
|
newOnLinkPrefix = mAdvertisedOnLinkPrefix;
|
||||||
}
|
}
|
||||||
else if (AddExternalRoute(mLocalOnLinkPrefix, OT_ROUTE_PREFERENCE_MED) == OT_ERROR_NONE)
|
else if (AddExternalRoute(mLocalOnLinkPrefix, OT_ROUTE_PREFERENCE_MED) == kErrorNone)
|
||||||
{
|
{
|
||||||
newOnLinkPrefix = &mLocalOnLinkPrefix;
|
newOnLinkPrefix = &mLocalOnLinkPrefix;
|
||||||
}
|
}
|
||||||
@@ -641,7 +636,7 @@ void RoutingManager::StartRouterSolicitation(void)
|
|||||||
mRouterSolicitTimer.Start(randomDelay);
|
mRouterSolicitTimer.Start(randomDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
otError RoutingManager::SendRouterSolicitation(void)
|
Error RoutingManager::SendRouterSolicitation(void)
|
||||||
{
|
{
|
||||||
Ip6::Address destAddress;
|
Ip6::Address destAddress;
|
||||||
RouterAdv::RouterSolicitMessage routerSolicit;
|
RouterAdv::RouterSolicitMessage routerSolicit;
|
||||||
@@ -761,7 +756,7 @@ void RoutingManager::SendRouterAdvertisement(const Ip6::Prefix *aNewOmrPrefixes,
|
|||||||
// Send the message only when there are options.
|
// Send the message only when there are options.
|
||||||
if (bufferLength > sizeof(routerAdv))
|
if (bufferLength > sizeof(routerAdv))
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
Ip6::Address destAddress;
|
Ip6::Address destAddress;
|
||||||
|
|
||||||
++mRouterAdvertisementCount;
|
++mRouterAdvertisementCount;
|
||||||
@@ -769,14 +764,13 @@ void RoutingManager::SendRouterAdvertisement(const Ip6::Prefix *aNewOmrPrefixes,
|
|||||||
destAddress.SetToLinkLocalAllNodesMulticast();
|
destAddress.SetToLinkLocalAllNodesMulticast();
|
||||||
error = otPlatInfraIfSendIcmp6Nd(mInfraIfIndex, &destAddress, buffer, bufferLength);
|
error = otPlatInfraIfSendIcmp6Nd(mInfraIfIndex, &destAddress, buffer, bufferLength);
|
||||||
|
|
||||||
if (error == OT_ERROR_NONE)
|
if (error == kErrorNone)
|
||||||
{
|
{
|
||||||
otLogInfoBr("sent Router Advertisement on interface %u", mInfraIfIndex);
|
otLogInfoBr("sent Router Advertisement on interface %u", mInfraIfIndex);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
otLogWarnBr("failed to send Router Advertisement on interface %u: %s", mInfraIfIndex,
|
otLogWarnBr("failed to send Router Advertisement on interface %u: %s", mInfraIfIndex, ErrorToString(error));
|
||||||
otThreadErrorToString(error));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -832,19 +826,18 @@ void RoutingManager::HandleRouterSolicitTimer(void)
|
|||||||
if (mRouterSolicitCount < kMaxRtrSolicitations)
|
if (mRouterSolicitCount < kMaxRtrSolicitations)
|
||||||
{
|
{
|
||||||
uint32_t nextSolicitationDelay;
|
uint32_t nextSolicitationDelay;
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
error = SendRouterSolicitation();
|
error = SendRouterSolicitation();
|
||||||
++mRouterSolicitCount;
|
++mRouterSolicitCount;
|
||||||
|
|
||||||
if (error == OT_ERROR_NONE)
|
if (error == kErrorNone)
|
||||||
{
|
{
|
||||||
otLogDebgBr("successfully sent %uth Router Solicitation", mRouterSolicitCount);
|
otLogDebgBr("successfully sent %uth Router Solicitation", mRouterSolicitCount);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
otLogCritBr("failed to send %uth Router Solicitation: %s", mRouterSolicitCount,
|
otLogCritBr("failed to send %uth Router Solicitation: %s", mRouterSolicitCount, ErrorToString(error));
|
||||||
otThreadErrorToString(error));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nextSolicitationDelay =
|
nextSolicitationDelay =
|
||||||
|
|||||||
@@ -47,11 +47,11 @@
|
|||||||
#error "OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE is required for OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE."
|
#error "OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE is required for OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <openthread/error.h>
|
|
||||||
#include <openthread/netdata.h>
|
#include <openthread/netdata.h>
|
||||||
#include <openthread/platform/infra_if.h>
|
#include <openthread/platform/infra_if.h>
|
||||||
|
|
||||||
#include "border_router/router_advertisement.hpp"
|
#include "border_router/router_advertisement.hpp"
|
||||||
|
#include "common/error.hpp"
|
||||||
#include "common/locator.hpp"
|
#include "common/locator.hpp"
|
||||||
#include "common/notifier.hpp"
|
#include "common/notifier.hpp"
|
||||||
#include "common/timer.hpp"
|
#include "common/timer.hpp"
|
||||||
@@ -92,11 +92,11 @@ public:
|
|||||||
* @param[in] aInfraIfLinkLocalAddress A pointer to the IPv6 link-local address of the infrastructure
|
* @param[in] aInfraIfLinkLocalAddress A pointer to the IPv6 link-local address of the infrastructure
|
||||||
* interface. NULL if the IPv6 link-local address is missing.
|
* interface. NULL if the IPv6 link-local address is missing.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully started the routing manager.
|
* @retval kErrorNone Successfully started the routing manager.
|
||||||
* @retval OT_ERROR_INVALID_ARGS The index of the infra interface is not valid.
|
* @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.
|
* 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.
|
* @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 kErrorInvalidState The Border Routing Manager is not initialized yet.
|
||||||
* @retval OT_ERROR_NONE Successfully enabled/disabled the Border Routing Manager.
|
* @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.
|
* 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
|
* @param[in] aLinkLocalAddress A pointer to the IPv6 link local address of the infrastructure
|
||||||
* interface. NULL if the IPv6 link local address is lost.
|
* interface. NULL if the IPv6 link local address is lost.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully updated the infra interface status.
|
* @retval kErrorNone Successfully updated the infra interface status.
|
||||||
* @retval OT_ERROR_INVALID_STATE The Routing Manager is not initialized.
|
* @retval kErrorInvalidState The Routing Manager is not initialized.
|
||||||
* @retval OT_ERROR_INVALID_ARGS The @p aInfraIfIndex doesn't match the infra interface the
|
* @retval kErrorInvalidArgs The @p aInfraIfIndex doesn't match the infra interface the Routing Manager are
|
||||||
* Routing Manager are initialized with, or the @p aLinkLocalAddress
|
* initialized with, or the @p aLinkLocalAddress is not a valid IPv6 link-local
|
||||||
* is not a valid IPv6 link-local address.
|
* address.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError HandleInfraIfStateChanged(uint32_t aInfraIfIndex, bool aIsRunning, const Ip6::Address *aLinkLocalAddress);
|
Error HandleInfraIfStateChanged(uint32_t aInfraIfIndex, bool aIsRunning, const Ip6::Address *aLinkLocalAddress);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum : uint16_t
|
enum : uint16_t
|
||||||
@@ -191,25 +191,25 @@ private:
|
|||||||
bool mIsOnLinkPrefix;
|
bool mIsOnLinkPrefix;
|
||||||
};
|
};
|
||||||
|
|
||||||
void EvaluateState(void);
|
void EvaluateState(void);
|
||||||
void Start(void);
|
void Start(void);
|
||||||
void Stop(void);
|
void Stop(void);
|
||||||
void HandleNotifierEvents(Events aEvents);
|
void HandleNotifierEvents(Events aEvents);
|
||||||
bool IsInitialized(void) const { return mInfraIfIndex != 0; }
|
bool IsInitialized(void) const { return mInfraIfIndex != 0; }
|
||||||
bool IsEnabled(void) const { return mIsEnabled; }
|
bool IsEnabled(void) const { return mIsEnabled; }
|
||||||
otError LoadOrGenerateRandomOmrPrefix(void);
|
Error LoadOrGenerateRandomOmrPrefix(void);
|
||||||
otError LoadOrGenerateRandomOnLinkPrefix(void);
|
Error LoadOrGenerateRandomOnLinkPrefix(void);
|
||||||
|
|
||||||
const Ip6::Prefix *EvaluateOnLinkPrefix(void);
|
const Ip6::Prefix *EvaluateOnLinkPrefix(void);
|
||||||
|
|
||||||
void EvaluateRoutingPolicy(void);
|
void EvaluateRoutingPolicy(void);
|
||||||
uint8_t EvaluateOmrPrefix(Ip6::Prefix *aNewOmrPrefixes, uint8_t aMaxOmrPrefixNum);
|
uint8_t EvaluateOmrPrefix(Ip6::Prefix *aNewOmrPrefixes, uint8_t aMaxOmrPrefixNum);
|
||||||
otError PublishLocalOmrPrefix(void);
|
Error PublishLocalOmrPrefix(void);
|
||||||
void UnpublishLocalOmrPrefix(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 RemoveExternalRoute(const Ip6::Prefix &aPrefix);
|
||||||
void StartRouterSolicitation(void);
|
void StartRouterSolicitation(void);
|
||||||
otError SendRouterSolicitation(void);
|
Error SendRouterSolicitation(void);
|
||||||
void SendRouterAdvertisement(const Ip6::Prefix *aNewOmrPrefixes,
|
void SendRouterAdvertisement(const Ip6::Prefix *aNewOmrPrefixes,
|
||||||
uint8_t aNewOmrPrefixNum,
|
uint8_t aNewOmrPrefixNum,
|
||||||
const Ip6::Prefix *aNewOnLinkPrefix);
|
const Ip6::Prefix *aNewOnLinkPrefix);
|
||||||
|
|||||||
+150
-152
@@ -86,7 +86,7 @@ void CoapBase::ClearRequests(const Ip6::Address *aAddress)
|
|||||||
|
|
||||||
if ((aAddress == nullptr) || (metadata.mSourceAddress == *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;
|
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
|
#if OPENTHREAD_CONFIG_OTNS_ENABLE
|
||||||
Get<Utils::Otns>().EmitCoapSend(static_cast<Message &>(aMessage), aMessageInfo);
|
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);
|
error = mSender(*this, aMessage, aMessageInfo);
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_OTNS_ENABLE
|
#if OPENTHREAD_CONFIG_OTNS_ENABLE
|
||||||
if (error != OT_ERROR_NONE)
|
if (error != kErrorNone)
|
||||||
{
|
{
|
||||||
Get<Utils::Otns>().EmitCoapSendFailure(error, static_cast<Message &>(aMessage), aMessageInfo);
|
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
|
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||||
otError CoapBase::SendMessage(Message & aMessage,
|
Error CoapBase::SendMessage(Message & aMessage,
|
||||||
const Ip6::MessageInfo & aMessageInfo,
|
const Ip6::MessageInfo & aMessageInfo,
|
||||||
const TxParameters & aTxParameters,
|
const TxParameters & aTxParameters,
|
||||||
ResponseHandler aHandler,
|
ResponseHandler aHandler,
|
||||||
void * aContext,
|
void * aContext,
|
||||||
otCoapBlockwiseTransmitHook aTransmitHook,
|
otCoapBlockwiseTransmitHook aTransmitHook,
|
||||||
otCoapBlockwiseReceiveHook aReceiveHook)
|
otCoapBlockwiseReceiveHook aReceiveHook)
|
||||||
#else
|
#else
|
||||||
otError CoapBase::SendMessage(Message & aMessage,
|
Error CoapBase::SendMessage(Message & aMessage,
|
||||||
const Ip6::MessageInfo &aMessageInfo,
|
const Ip6::MessageInfo &aMessageInfo,
|
||||||
const TxParameters & aTxParameters,
|
const TxParameters & aTxParameters,
|
||||||
ResponseHandler aHandler,
|
ResponseHandler aHandler,
|
||||||
void * aContext)
|
void * aContext)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
Message *storedCopy = nullptr;
|
Message *storedCopy = nullptr;
|
||||||
uint16_t copyLength = 0;
|
uint16_t copyLength = 0;
|
||||||
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||||
@@ -187,12 +187,12 @@ otError CoapBase::SendMessage(Message & aMessage,
|
|||||||
case kTypeAck:
|
case kTypeAck:
|
||||||
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||||
// Check for block-wise transfer
|
// Check for block-wise transfer
|
||||||
if ((aTransmitHook != nullptr) && (aMessage.ReadBlockOptionValues(kOptionBlock2) == OT_ERROR_NONE) &&
|
if ((aTransmitHook != nullptr) && (aMessage.ReadBlockOptionValues(kOptionBlock2) == kErrorNone) &&
|
||||||
(aMessage.GetBlockWiseBlockNumber() == 0))
|
(aMessage.GetBlockWiseBlockNumber() == 0))
|
||||||
{
|
{
|
||||||
// Set payload for first block of the transfer
|
// Set payload for first block of the transfer
|
||||||
VerifyOrExit((bufLen = otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize())) <= kMaxBlockLength,
|
VerifyOrExit((bufLen = otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize())) <= kMaxBlockLength,
|
||||||
error = OT_ERROR_NO_BUFS);
|
error = kErrorNoBufs);
|
||||||
SuccessOrExit(error = aTransmitHook(aContext, buf, aMessage.GetBlockWiseBlockNumber() * bufLen, &bufLen,
|
SuccessOrExit(error = aTransmitHook(aContext, buf, aMessage.GetBlockWiseBlockNumber() * bufLen, &bufLen,
|
||||||
&moreBlocks));
|
&moreBlocks));
|
||||||
SuccessOrExit(error = aMessage.AppendBytes(buf, bufLen));
|
SuccessOrExit(error = aMessage.AppendBytes(buf, bufLen));
|
||||||
@@ -209,12 +209,12 @@ otError CoapBase::SendMessage(Message & aMessage,
|
|||||||
default:
|
default:
|
||||||
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||||
// Check for block-wise transfer
|
// Check for block-wise transfer
|
||||||
if ((aTransmitHook != nullptr) && (aMessage.ReadBlockOptionValues(kOptionBlock1) == OT_ERROR_NONE) &&
|
if ((aTransmitHook != nullptr) && (aMessage.ReadBlockOptionValues(kOptionBlock1) == kErrorNone) &&
|
||||||
(aMessage.GetBlockWiseBlockNumber() == 0))
|
(aMessage.GetBlockWiseBlockNumber() == 0))
|
||||||
{
|
{
|
||||||
// Set payload for first block of the transfer
|
// Set payload for first block of the transfer
|
||||||
VerifyOrExit((bufLen = otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize())) <= kMaxBlockLength,
|
VerifyOrExit((bufLen = otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize())) <= kMaxBlockLength,
|
||||||
error = OT_ERROR_NO_BUFS);
|
error = kErrorNoBufs);
|
||||||
SuccessOrExit(error = aTransmitHook(aContext, buf, aMessage.GetBlockWiseBlockNumber() * bufLen, &bufLen,
|
SuccessOrExit(error = aTransmitHook(aContext, buf, aMessage.GetBlockWiseBlockNumber() * bufLen, &bufLen,
|
||||||
&moreBlocks));
|
&moreBlocks));
|
||||||
SuccessOrExit(error = aMessage.AppendBytes(buf, bufLen));
|
SuccessOrExit(error = aMessage.AppendBytes(buf, bufLen));
|
||||||
@@ -275,7 +275,7 @@ otError CoapBase::SendMessage(Message & aMessage,
|
|||||||
Message *origRequest = FindRelatedRequest(aMessage, aMessageInfo, handlerMetadata);
|
Message *origRequest = FindRelatedRequest(aMessage, aMessageInfo, handlerMetadata);
|
||||||
if (origRequest != nullptr)
|
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());
|
(metadata.mConfirmable ? metadata.mRetransmissionTimeout : aTxParameters.CalculateMaxTransmitWait());
|
||||||
|
|
||||||
storedCopy = CopyAndEnqueueMessage(aMessage, copyLength, metadata);
|
storedCopy = CopyAndEnqueueMessage(aMessage, copyLength, metadata);
|
||||||
VerifyOrExit(storedCopy != nullptr, error = OT_ERROR_NO_BUFS);
|
VerifyOrExit(storedCopy != nullptr, error = kErrorNoBufs);
|
||||||
}
|
}
|
||||||
|
|
||||||
SuccessOrExit(error = Send(aMessage, aMessageInfo));
|
SuccessOrExit(error = Send(aMessage, aMessageInfo));
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
|
||||||
if (error != OT_ERROR_NONE && storedCopy != nullptr)
|
if (error != kErrorNone && storedCopy != nullptr)
|
||||||
{
|
{
|
||||||
DequeueMessage(*storedCopy);
|
DequeueMessage(*storedCopy);
|
||||||
}
|
}
|
||||||
@@ -322,10 +322,10 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError CoapBase::SendMessage(Message & aMessage,
|
Error CoapBase::SendMessage(Message & aMessage,
|
||||||
const Ip6::MessageInfo &aMessageInfo,
|
const Ip6::MessageInfo &aMessageInfo,
|
||||||
ResponseHandler aHandler,
|
ResponseHandler aHandler,
|
||||||
void * aContext)
|
void * aContext)
|
||||||
{
|
{
|
||||||
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||||
return SendMessage(aMessage, aMessageInfo, TxParameters::GetDefault(), aHandler, aContext, nullptr, nullptr);
|
return SendMessage(aMessage, aMessageInfo, TxParameters::GetDefault(), aHandler, aContext, nullptr, nullptr);
|
||||||
@@ -334,34 +334,34 @@ otError CoapBase::SendMessage(Message & aMessage,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
otError CoapBase::SendReset(Message &aRequest, const Ip6::MessageInfo &aMessageInfo)
|
Error CoapBase::SendReset(Message &aRequest, const Ip6::MessageInfo &aMessageInfo)
|
||||||
{
|
{
|
||||||
return SendEmptyMessage(kTypeReset, aRequest, 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);
|
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);
|
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;
|
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->Init(aType, kCodeEmpty);
|
||||||
message->SetMessageId(aRequest.GetMessageId());
|
message->SetMessageId(aRequest.GetMessageId());
|
||||||
@@ -374,13 +374,13 @@ exit:
|
|||||||
return error;
|
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;
|
Message *message = nullptr;
|
||||||
|
|
||||||
VerifyOrExit(aRequest.IsRequest(), error = OT_ERROR_INVALID_ARGS);
|
VerifyOrExit(aRequest.IsRequest(), error = kErrorInvalidArgs);
|
||||||
VerifyOrExit((message = NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
|
VerifyOrExit((message = NewMessage()) != nullptr, error = kErrorNoBufs);
|
||||||
|
|
||||||
switch (aRequest.GetType())
|
switch (aRequest.GetType())
|
||||||
{
|
{
|
||||||
@@ -394,7 +394,7 @@ otError CoapBase::SendHeaderResponse(Message::Code aCode, const Message &aReques
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ExitNow(error = OT_ERROR_INVALID_ARGS);
|
ExitNow(error = kErrorInvalidArgs);
|
||||||
OT_UNREACHABLE_CODE(break);
|
OT_UNREACHABLE_CODE(break);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -439,7 +439,7 @@ void CoapBase::HandleRetransmissionTimer(void)
|
|||||||
if (!metadata.mConfirmable || (metadata.mRetransmissionsRemaining == 0))
|
if (!metadata.mConfirmable || (metadata.mRetransmissionsRemaining == 0))
|
||||||
{
|
{
|
||||||
// No expected response or acknowledgment.
|
// No expected response or acknowledgment.
|
||||||
FinalizeCoapTransaction(*message, metadata, nullptr, nullptr, OT_ERROR_RESPONSE_TIMEOUT);
|
FinalizeCoapTransaction(*message, metadata, nullptr, nullptr, kErrorResponseTimeout);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -481,7 +481,7 @@ void CoapBase::FinalizeCoapTransaction(Message & aRequest,
|
|||||||
const Metadata & aMetadata,
|
const Metadata & aMetadata,
|
||||||
Message * aResponse,
|
Message * aResponse,
|
||||||
const Ip6::MessageInfo *aMessageInfo,
|
const Ip6::MessageInfo *aMessageInfo,
|
||||||
otError aResult)
|
Error aResult)
|
||||||
{
|
{
|
||||||
DequeueMessage(aRequest);
|
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;
|
Message *nextMessage;
|
||||||
Metadata metadata;
|
Metadata metadata;
|
||||||
|
|
||||||
@@ -504,8 +504,8 @@ otError CoapBase::AbortTransaction(ResponseHandler aHandler, void *aContext)
|
|||||||
|
|
||||||
if (metadata.mResponseHandler == aHandler && metadata.mResponseContext == aContext)
|
if (metadata.mResponseHandler == aHandler && metadata.mResponseContext == aContext)
|
||||||
{
|
{
|
||||||
FinalizeCoapTransaction(*message, metadata, nullptr, nullptr, OT_ERROR_ABORT);
|
FinalizeCoapTransaction(*message, metadata, nullptr, nullptr, kErrorAbort);
|
||||||
error = OT_ERROR_NONE;
|
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)
|
Message *CoapBase::CopyAndEnqueueMessage(const Message &aMessage, uint16_t aCopyLength, const Metadata &aMetadata)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Message *messageCopy = nullptr;
|
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));
|
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
|
// Save last response for block-wise transfer
|
||||||
FreeLastBlockResponse();
|
FreeLastBlockResponse();
|
||||||
|
|
||||||
if ((mLastResponse = aResponse->Clone()) == nullptr)
|
if ((mLastResponse = aResponse->Clone()) == nullptr)
|
||||||
{
|
{
|
||||||
error = OT_ERROR_NO_BUFS;
|
error = kErrorNoBufs;
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError CoapBase::PrepareNextBlockRequest(Message::BlockType aType,
|
Error CoapBase::PrepareNextBlockRequest(Message::BlockType aType,
|
||||||
bool aMoreBlocks,
|
bool aMoreBlocks,
|
||||||
Message & aRequestOld,
|
Message & aRequestOld,
|
||||||
Message & aRequest,
|
Message & aRequest,
|
||||||
Message & aMessage)
|
Message & aMessage)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
bool isOptionSet = false;
|
bool isOptionSet = false;
|
||||||
uint64_t optionBuf = 0;
|
uint64_t optionBuf = 0;
|
||||||
uint16_t blockOption = 0;
|
uint16_t blockOption = 0;
|
||||||
@@ -633,12 +633,12 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError CoapBase::SendNextBlock1Request(Message & aRequest,
|
Error CoapBase::SendNextBlock1Request(Message & aRequest,
|
||||||
Message & aMessage,
|
Message & aMessage,
|
||||||
const Ip6::MessageInfo &aMessageInfo,
|
const Ip6::MessageInfo &aMessageInfo,
|
||||||
const Metadata & aCoapMetadata)
|
const Metadata & aCoapMetadata)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Message *request = nullptr;
|
Message *request = nullptr;
|
||||||
bool moreBlocks = false;
|
bool moreBlocks = false;
|
||||||
uint8_t buf[kMaxBlockLength] = {0};
|
uint8_t buf[kMaxBlockLength] = {0};
|
||||||
@@ -650,13 +650,13 @@ otError CoapBase::SendNextBlock1Request(Message & aRequest,
|
|||||||
// Conclude block-wise transfer if last block has been received
|
// Conclude block-wise transfer if last block has been received
|
||||||
if (!aRequest.IsMoreBlocksFlagSet())
|
if (!aRequest.IsMoreBlocksFlagSet())
|
||||||
{
|
{
|
||||||
FinalizeCoapTransaction(aRequest, aCoapMetadata, &aMessage, &aMessageInfo, OT_ERROR_NONE);
|
FinalizeCoapTransaction(aRequest, aCoapMetadata, &aMessage, &aMessageInfo, kErrorNone);
|
||||||
ExitNow();
|
ExitNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get next block
|
// Get next block
|
||||||
VerifyOrExit((bufLen = otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize())) <= kMaxBlockLength,
|
VerifyOrExit((bufLen = otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize())) <= kMaxBlockLength,
|
||||||
error = OT_ERROR_NO_BUFS);
|
error = kErrorNoBufs);
|
||||||
|
|
||||||
SuccessOrExit(
|
SuccessOrExit(
|
||||||
error = aCoapMetadata.mBlockwiseTransmitHook(aCoapMetadata.mResponseContext, buf,
|
error = aCoapMetadata.mBlockwiseTransmitHook(aCoapMetadata.mResponseContext, buf,
|
||||||
@@ -665,11 +665,10 @@ otError CoapBase::SendNextBlock1Request(Message & aRequest,
|
|||||||
&bufLen, &moreBlocks));
|
&bufLen, &moreBlocks));
|
||||||
|
|
||||||
// Check if block length is valid
|
// Check if block length is valid
|
||||||
VerifyOrExit(bufLen <= otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize()),
|
VerifyOrExit(bufLen <= otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize()), error = kErrorInvalidArgs);
|
||||||
error = OT_ERROR_INVALID_ARGS);
|
|
||||||
|
|
||||||
// Init request for next block
|
// 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 = PrepareNextBlockRequest(Message::kBlockType1, moreBlocks, aRequest, *request, aMessage));
|
||||||
|
|
||||||
SuccessOrExit(error = request->SetPayloadMarker());
|
SuccessOrExit(error = request->SetPayloadMarker());
|
||||||
@@ -691,14 +690,14 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError CoapBase::SendNextBlock2Request(Message & aRequest,
|
Error CoapBase::SendNextBlock2Request(Message & aRequest,
|
||||||
Message & aMessage,
|
Message & aMessage,
|
||||||
const Ip6::MessageInfo &aMessageInfo,
|
const Ip6::MessageInfo &aMessageInfo,
|
||||||
const Metadata & aCoapMetadata,
|
const Metadata & aCoapMetadata,
|
||||||
uint32_t aTotalLength,
|
uint32_t aTotalLength,
|
||||||
bool aBeginBlock1Transfer)
|
bool aBeginBlock1Transfer)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Message *request = nullptr;
|
Message *request = nullptr;
|
||||||
uint8_t buf[kMaxBlockLength] = {0};
|
uint8_t buf[kMaxBlockLength] = {0};
|
||||||
uint16_t bufLen = kMaxBlockLength;
|
uint16_t bufLen = kMaxBlockLength;
|
||||||
@@ -709,7 +708,7 @@ otError CoapBase::SendNextBlock2Request(Message & aRequest,
|
|||||||
VerifyOrExit((aMessage.GetLength() - aMessage.GetOffset()) <=
|
VerifyOrExit((aMessage.GetLength() - aMessage.GetOffset()) <=
|
||||||
otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize()) &&
|
otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize()) &&
|
||||||
(aMessage.GetLength() - aMessage.GetOffset()) <= kMaxBlockLength,
|
(aMessage.GetLength() - aMessage.GetOffset()) <= kMaxBlockLength,
|
||||||
error = OT_ERROR_NO_BUFS);
|
error = kErrorNoBufs);
|
||||||
|
|
||||||
// Read and then forward payload to receive hook function
|
// Read and then forward payload to receive hook function
|
||||||
bufLen = aMessage.ReadBytes(aMessage.GetOffset(), buf, aMessage.GetLength() - aMessage.GetOffset());
|
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
|
// Conclude block-wise transfer if last block has been received
|
||||||
if (!aMessage.IsMoreBlocksFlagSet())
|
if (!aMessage.IsMoreBlocksFlagSet())
|
||||||
{
|
{
|
||||||
FinalizeCoapTransaction(aRequest, aCoapMetadata, &aMessage, &aMessageInfo, OT_ERROR_NONE);
|
FinalizeCoapTransaction(aRequest, aCoapMetadata, &aMessage, &aMessageInfo, kErrorNone);
|
||||||
ExitNow();
|
ExitNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init request for next block
|
// 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,
|
SuccessOrExit(error = PrepareNextBlockRequest(Message::kBlockType2, aMessage.IsMoreBlocksFlagSet(), aRequest,
|
||||||
*request, aMessage));
|
*request, aMessage));
|
||||||
|
|
||||||
@@ -753,12 +752,12 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError CoapBase::ProcessBlock1Request(Message & aMessage,
|
Error CoapBase::ProcessBlock1Request(Message & aMessage,
|
||||||
const Ip6::MessageInfo & aMessageInfo,
|
const Ip6::MessageInfo & aMessageInfo,
|
||||||
const ResourceBlockWise &aResource,
|
const ResourceBlockWise &aResource,
|
||||||
uint32_t aTotalLength)
|
uint32_t aTotalLength)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Message *response = nullptr;
|
Message *response = nullptr;
|
||||||
uint8_t buf[kMaxBlockLength] = {0};
|
uint8_t buf[kMaxBlockLength] = {0};
|
||||||
uint16_t bufLen = kMaxBlockLength;
|
uint16_t bufLen = kMaxBlockLength;
|
||||||
@@ -766,7 +765,7 @@ otError CoapBase::ProcessBlock1Request(Message & aMessage,
|
|||||||
SuccessOrExit(error = aMessage.ReadBlockOptionValues(kOptionBlock1));
|
SuccessOrExit(error = aMessage.ReadBlockOptionValues(kOptionBlock1));
|
||||||
|
|
||||||
// Read and then forward payload to receive hook function
|
// 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());
|
bufLen = aMessage.ReadBytes(aMessage.GetOffset(), buf, aMessage.GetLength() - aMessage.GetOffset());
|
||||||
SuccessOrExit(error = aResource.HandleBlockReceive(buf,
|
SuccessOrExit(error = aResource.HandleBlockReceive(buf,
|
||||||
otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize()) *
|
otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize()) *
|
||||||
@@ -776,7 +775,7 @@ otError CoapBase::ProcessBlock1Request(Message & aMessage,
|
|||||||
if (aMessage.IsMoreBlocksFlagSet())
|
if (aMessage.IsMoreBlocksFlagSet())
|
||||||
{
|
{
|
||||||
// Set up next response
|
// Set up next response
|
||||||
VerifyOrExit((response = NewMessage()) != nullptr, error = OT_ERROR_FAILED);
|
VerifyOrExit((response = NewMessage()) != nullptr, error = kErrorFailed);
|
||||||
response->Init(kTypeAck, kCodeContinue);
|
response->Init(kTypeAck, kCodeContinue);
|
||||||
response->SetMessageId(aMessage.GetMessageId());
|
response->SetMessageId(aMessage.GetMessageId());
|
||||||
IgnoreReturnValue(
|
IgnoreReturnValue(
|
||||||
@@ -797,17 +796,17 @@ otError CoapBase::ProcessBlock1Request(Message & aMessage,
|
|||||||
|
|
||||||
SuccessOrExit(error = SendMessage(*response, aMessageInfo));
|
SuccessOrExit(error = SendMessage(*response, aMessageInfo));
|
||||||
|
|
||||||
error = OT_ERROR_BUSY;
|
error = kErrorBusy;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Conclude block-wise transfer if last block has been received
|
// Conclude block-wise transfer if last block has been received
|
||||||
FreeLastBlockResponse();
|
FreeLastBlockResponse();
|
||||||
error = OT_ERROR_NONE;
|
error = kErrorNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if (error != OT_ERROR_NONE && error != OT_ERROR_BUSY && response != nullptr)
|
if (error != kErrorNone && error != kErrorBusy && response != nullptr)
|
||||||
{
|
{
|
||||||
response->Free();
|
response->Free();
|
||||||
}
|
}
|
||||||
@@ -815,11 +814,11 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError CoapBase::ProcessBlock2Request(Message & aMessage,
|
Error CoapBase::ProcessBlock2Request(Message & aMessage,
|
||||||
const Ip6::MessageInfo & aMessageInfo,
|
const Ip6::MessageInfo & aMessageInfo,
|
||||||
const ResourceBlockWise &aResource)
|
const ResourceBlockWise &aResource)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Message * response = nullptr;
|
Message * response = nullptr;
|
||||||
uint8_t buf[kMaxBlockLength] = {0};
|
uint8_t buf[kMaxBlockLength] = {0};
|
||||||
uint16_t bufLen = kMaxBlockLength;
|
uint16_t bufLen = kMaxBlockLength;
|
||||||
@@ -839,12 +838,12 @@ otError CoapBase::ProcessBlock2Request(Message & aMessage,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set up next response
|
// Set up next response
|
||||||
VerifyOrExit((response = NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
|
VerifyOrExit((response = NewMessage()) != nullptr, error = kErrorNoBufs);
|
||||||
response->Init(kTypeAck, kCodeContent);
|
response->Init(kTypeAck, kCodeContent);
|
||||||
response->SetMessageId(aMessage.GetMessageId());
|
response->SetMessageId(aMessage.GetMessageId());
|
||||||
|
|
||||||
VerifyOrExit((bufLen = otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize())) <= kMaxBlockLength,
|
VerifyOrExit((bufLen = otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize())) <= kMaxBlockLength,
|
||||||
error = OT_ERROR_NO_BUFS);
|
error = kErrorNoBufs);
|
||||||
SuccessOrExit(error = aResource.HandleBlockTransmit(buf,
|
SuccessOrExit(error = aResource.HandleBlockTransmit(buf,
|
||||||
otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize()) *
|
otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize()) *
|
||||||
aMessage.GetBlockWiseBlockNumber(),
|
aMessage.GetBlockWiseBlockNumber(),
|
||||||
@@ -877,7 +876,7 @@ otError CoapBase::ProcessBlock2Request(Message & aMessage,
|
|||||||
response->SetBlockWiseBlockSize(OT_COAP_OPTION_BLOCK_SZX_16);
|
response->SetBlockWiseBlockSize(OT_COAP_OPTION_BLOCK_SZX_16);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error = OT_ERROR_INVALID_ARGS;
|
error = kErrorInvalidArgs;
|
||||||
ExitNow();
|
ExitNow();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -886,7 +885,7 @@ otError CoapBase::ProcessBlock2Request(Message & aMessage,
|
|||||||
{
|
{
|
||||||
// Verify that buffer length is not larger than requested block size
|
// Verify that buffer length is not larger than requested block size
|
||||||
VerifyOrExit(bufLen <= otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize()),
|
VerifyOrExit(bufLen <= otCoapBlockSizeFromExponent(aMessage.GetBlockWiseBlockSize()),
|
||||||
error = OT_ERROR_INVALID_ARGS);
|
error = kErrorInvalidArgs);
|
||||||
response->SetBlockWiseBlockSize(aMessage.GetBlockWiseBlockSize());
|
response->SetBlockWiseBlockSize(aMessage.GetBlockWiseBlockSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -943,20 +942,20 @@ exit:
|
|||||||
|
|
||||||
void CoapBase::SendCopy(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
void CoapBase::SendCopy(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
Message *messageCopy = nullptr;
|
Message *messageCopy = nullptr;
|
||||||
|
|
||||||
// Create a message copy for lower layers.
|
// Create a message copy for lower layers.
|
||||||
messageCopy = aMessage.Clone(aMessage.GetLength() - sizeof(Metadata));
|
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));
|
SuccessOrExit(error = Send(*messageCopy, aMessageInfo));
|
||||||
|
|
||||||
exit:
|
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);
|
FreeMessage(messageCopy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1007,7 +1006,7 @@ void CoapBase::Receive(ot::Message &aMessage, const Ip6::MessageInfo &aMessageIn
|
|||||||
{
|
{
|
||||||
Message &message = static_cast<Message &>(aMessage);
|
Message &message = static_cast<Message &>(aMessage);
|
||||||
|
|
||||||
if (message.ParseHeader() != OT_ERROR_NONE)
|
if (message.ParseHeader() != kErrorNone)
|
||||||
{
|
{
|
||||||
otLogDebgCoap("Failed to parse CoAP header");
|
otLogDebgCoap("Failed to parse CoAP header");
|
||||||
|
|
||||||
@@ -1034,7 +1033,7 @@ void CoapBase::ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo
|
|||||||
{
|
{
|
||||||
Metadata metadata;
|
Metadata metadata;
|
||||||
Message *request = nullptr;
|
Message *request = nullptr;
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
|
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
|
||||||
bool responseObserve = false;
|
bool responseObserve = false;
|
||||||
#endif
|
#endif
|
||||||
@@ -1062,7 +1061,7 @@ void CoapBase::ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo
|
|||||||
case kTypeReset:
|
case kTypeReset:
|
||||||
if (aMessage.IsEmpty())
|
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).
|
// 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
|
// 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
|
// "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.
|
// 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
|
else
|
||||||
#endif
|
#endif
|
||||||
@@ -1109,7 +1108,7 @@ void CoapBase::ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo
|
|||||||
if (metadata.mObserve && responseObserve && (metadata.mResponseHandler != nullptr))
|
if (metadata.mObserve && responseObserve && (metadata.mResponseHandler != nullptr))
|
||||||
{
|
{
|
||||||
// This is a RFC7641 notification. The request is *not* done!
|
// 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.
|
// Consider the message acknowledged at this point.
|
||||||
metadata.mAcknowledged = true;
|
metadata.mAcknowledged = true;
|
||||||
@@ -1153,7 +1152,7 @@ void CoapBase::ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo
|
|||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
// Piggybacked response.
|
// Piggybacked response.
|
||||||
FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, OT_ERROR_NONE);
|
FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, kErrorNone);
|
||||||
break;
|
break;
|
||||||
case 1: // Block1 option
|
case 1: // Block1 option
|
||||||
if (aMessage.GetCode() == kCodeContinue && metadata.mBlockwiseTransmitHook != nullptr)
|
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 ||
|
if (aMessage.GetCode() != kCodeContinue || metadata.mBlockwiseTransmitHook == nullptr ||
|
||||||
error != OT_ERROR_NONE)
|
error != kErrorNone)
|
||||||
{
|
{
|
||||||
FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, error);
|
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 ||
|
if (aMessage.GetCode() >= kCodeBadRequest || metadata.mBlockwiseReceiveHook == nullptr ||
|
||||||
error != OT_ERROR_NONE)
|
error != kErrorNone)
|
||||||
{
|
{
|
||||||
FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, error);
|
FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, error);
|
||||||
}
|
}
|
||||||
@@ -1190,14 +1189,14 @@ void CoapBase::ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo
|
|||||||
FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, error);
|
FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, error);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error = OT_ERROR_ABORT;
|
error = kErrorAbort;
|
||||||
FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, error);
|
FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, error);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else // OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
#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
|
#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
|
// 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
|
else
|
||||||
{
|
{
|
||||||
FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, OT_ERROR_NONE);
|
FinalizeCoapTransaction(*request, metadata, &aMessage, &aMessageInfo, kErrorNone);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -1235,7 +1234,7 @@ void CoapBase::ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo
|
|||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
|
||||||
if (error == OT_ERROR_NONE && request == nullptr)
|
if (error == kErrorNone && request == nullptr)
|
||||||
{
|
{
|
||||||
if (aMessage.IsConfirmable() || aMessage.IsNonConfirmable())
|
if (aMessage.IsConfirmable() || aMessage.IsNonConfirmable())
|
||||||
{
|
{
|
||||||
@@ -1250,7 +1249,7 @@ void CoapBase::ProcessReceivedRequest(Message &aMessage, const Ip6::MessageInfo
|
|||||||
{
|
{
|
||||||
char uriPath[Message::kMaxReceivedUriPath + 1];
|
char uriPath[Message::kMaxReceivedUriPath + 1];
|
||||||
Message *cachedResponse = nullptr;
|
Message *cachedResponse = nullptr;
|
||||||
otError error = OT_ERROR_NOT_FOUND;
|
Error error = kErrorNotFound;
|
||||||
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||||
Option::Iterator iterator;
|
Option::Iterator iterator;
|
||||||
char * curUriPath = uriPath;
|
char * curUriPath = uriPath;
|
||||||
@@ -1265,16 +1264,16 @@ void CoapBase::ProcessReceivedRequest(Message &aMessage, const Ip6::MessageInfo
|
|||||||
|
|
||||||
switch (mResponsesQueue.GetMatchedResponseCopy(aMessage, aMessageInfo, &cachedResponse))
|
switch (mResponsesQueue.GetMatchedResponseCopy(aMessage, aMessageInfo, &cachedResponse))
|
||||||
{
|
{
|
||||||
case OT_ERROR_NONE:
|
case kErrorNone:
|
||||||
cachedResponse->Finish();
|
cachedResponse->Finish();
|
||||||
error = Send(*cachedResponse, aMessageInfo);
|
error = Send(*cachedResponse, aMessageInfo);
|
||||||
|
|
||||||
OT_FALL_THROUGH;
|
OT_FALL_THROUGH;
|
||||||
|
|
||||||
case OT_ERROR_NO_BUFS:
|
case kErrorNoBufs:
|
||||||
ExitNow();
|
ExitNow();
|
||||||
|
|
||||||
case OT_ERROR_NOT_FOUND:
|
case kErrorNotFound:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1292,8 +1291,7 @@ void CoapBase::ProcessReceivedRequest(Message &aMessage, const Ip6::MessageInfo
|
|||||||
*curUriPath++ = '/';
|
*curUriPath++ = '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
VerifyOrExit(curUriPath + iterator.GetOption()->GetLength() < OT_ARRAY_END(uriPath),
|
VerifyOrExit(curUriPath + iterator.GetOption()->GetLength() < OT_ARRAY_END(uriPath), error = kErrorParse);
|
||||||
error = OT_ERROR_PARSE);
|
|
||||||
|
|
||||||
IgnoreError(iterator.ReadOptionValue(curUriPath));
|
IgnoreError(iterator.ReadOptionValue(curUriPath));
|
||||||
curUriPath += iterator.GetOption()->GetLength();
|
curUriPath += iterator.GetOption()->GetLength();
|
||||||
@@ -1337,23 +1335,23 @@ void CoapBase::ProcessReceivedRequest(Message &aMessage, const Ip6::MessageInfo
|
|||||||
{
|
{
|
||||||
switch (ProcessBlock1Request(aMessage, aMessageInfo, *resource, totalTransfereSize))
|
switch (ProcessBlock1Request(aMessage, aMessageInfo, *resource, totalTransfereSize))
|
||||||
{
|
{
|
||||||
case OT_ERROR_NONE:
|
case kErrorNone:
|
||||||
resource->HandleRequest(aMessage, aMessageInfo);
|
resource->HandleRequest(aMessage, aMessageInfo);
|
||||||
// Fall through
|
// Fall through
|
||||||
case OT_ERROR_BUSY:
|
case kErrorBusy:
|
||||||
error = OT_ERROR_NONE;
|
error = kErrorNone;
|
||||||
break;
|
break;
|
||||||
case OT_ERROR_NO_BUFS:
|
case kErrorNoBufs:
|
||||||
IgnoreReturnValue(SendHeaderResponse(kCodeRequestTooLarge, aMessage, aMessageInfo));
|
IgnoreReturnValue(SendHeaderResponse(kCodeRequestTooLarge, aMessage, aMessageInfo));
|
||||||
error = OT_ERROR_DROP;
|
error = kErrorDrop;
|
||||||
break;
|
break;
|
||||||
case OT_ERROR_NO_FRAME_RECEIVED:
|
case kErrorNoFrameReceived:
|
||||||
IgnoreReturnValue(SendHeaderResponse(kCodeRequestIncomplete, aMessage, aMessageInfo));
|
IgnoreReturnValue(SendHeaderResponse(kCodeRequestIncomplete, aMessage, aMessageInfo));
|
||||||
error = OT_ERROR_DROP;
|
error = kErrorDrop;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
IgnoreReturnValue(SendHeaderResponse(kCodeInternalError, aMessage, aMessageInfo));
|
IgnoreReturnValue(SendHeaderResponse(kCodeInternalError, aMessage, aMessageInfo));
|
||||||
error = OT_ERROR_DROP;
|
error = kErrorDrop;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1361,10 +1359,10 @@ void CoapBase::ProcessReceivedRequest(Message &aMessage, const Ip6::MessageInfo
|
|||||||
case 2:
|
case 2:
|
||||||
if (resource->mTransmitHook != nullptr)
|
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));
|
IgnoreReturnValue(SendHeaderResponse(kCodeInternalError, aMessage, aMessageInfo));
|
||||||
error = OT_ERROR_DROP;
|
error = kErrorDrop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -1374,7 +1372,7 @@ void CoapBase::ProcessReceivedRequest(Message &aMessage, const Ip6::MessageInfo
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
resource->HandleRequest(aMessage, aMessageInfo);
|
resource->HandleRequest(aMessage, aMessageInfo);
|
||||||
error = OT_ERROR_NONE;
|
error = kErrorNone;
|
||||||
ExitNow();
|
ExitNow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1387,7 +1385,7 @@ void CoapBase::ProcessReceivedRequest(Message &aMessage, const Ip6::MessageInfo
|
|||||||
if (strcmp(resource->mUriPath, uriPath) == 0)
|
if (strcmp(resource->mUriPath, uriPath) == 0)
|
||||||
{
|
{
|
||||||
resource->HandleRequest(aMessage, aMessageInfo);
|
resource->HandleRequest(aMessage, aMessageInfo);
|
||||||
error = OT_ERROR_NONE;
|
error = kErrorNone;
|
||||||
ExitNow();
|
ExitNow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1395,16 +1393,16 @@ void CoapBase::ProcessReceivedRequest(Message &aMessage, const Ip6::MessageInfo
|
|||||||
if (mDefaultHandler)
|
if (mDefaultHandler)
|
||||||
{
|
{
|
||||||
mDefaultHandler(mDefaultHandlerContext, &aMessage, &aMessageInfo);
|
mDefaultHandler(mDefaultHandlerContext, &aMessage, &aMessageInfo);
|
||||||
error = OT_ERROR_NONE;
|
error = kErrorNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
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));
|
IgnoreError(SendNotFound(aMessage, aMessageInfo));
|
||||||
}
|
}
|
||||||
@@ -1431,18 +1429,18 @@ ResponsesQueue::ResponsesQueue(Instance &aInstance)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
otError ResponsesQueue::GetMatchedResponseCopy(const Message & aRequest,
|
Error ResponsesQueue::GetMatchedResponseCopy(const Message & aRequest,
|
||||||
const Ip6::MessageInfo &aMessageInfo,
|
const Ip6::MessageInfo &aMessageInfo,
|
||||||
Message ** aResponse)
|
Message ** aResponse)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
const Message *cacheResponse;
|
const Message *cacheResponse;
|
||||||
|
|
||||||
cacheResponse = FindMatchedResponse(aRequest, aMessageInfo);
|
cacheResponse = FindMatchedResponse(aRequest, aMessageInfo);
|
||||||
VerifyOrExit(cacheResponse != nullptr, error = OT_ERROR_NOT_FOUND);
|
VerifyOrExit(cacheResponse != nullptr, error = kErrorNotFound);
|
||||||
|
|
||||||
*aResponse = cacheResponse->Clone(cacheResponse->GetLength() - sizeof(ResponseMetadata));
|
*aResponse = cacheResponse->Clone(cacheResponse->GetLength() - sizeof(ResponseMetadata));
|
||||||
VerifyOrExit(*aResponse != nullptr, error = OT_ERROR_NO_BUFS);
|
VerifyOrExit(*aResponse != nullptr, error = kErrorNoBufs);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return error;
|
return error;
|
||||||
@@ -1487,7 +1485,7 @@ void ResponsesQueue::EnqueueResponse(Message & aMessage,
|
|||||||
|
|
||||||
VerifyOrExit((responseCopy = aMessage.Clone()) != nullptr);
|
VerifyOrExit((responseCopy = aMessage.Clone()) != nullptr);
|
||||||
|
|
||||||
VerifyOrExit(metadata.AppendTo(*responseCopy) == OT_ERROR_NONE, responseCopy->Free());
|
VerifyOrExit(metadata.AppendTo(*responseCopy) == kErrorNone, responseCopy->Free());
|
||||||
|
|
||||||
mQueue.Enqueue(*responseCopy);
|
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;
|
Error error = kErrorNone;
|
||||||
bool socketOpened = false;
|
bool socketOpened = false;
|
||||||
|
|
||||||
VerifyOrExit(!mSocket.IsBound());
|
VerifyOrExit(!mSocket.IsBound());
|
||||||
|
|
||||||
@@ -1672,7 +1670,7 @@ otError Coap::Start(uint16_t aPort, otNetifIdentifier aNetifIdentifier)
|
|||||||
SuccessOrExit(error = mSocket.Bind(aPort));
|
SuccessOrExit(error = mSocket.Bind(aPort));
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if (error != OT_ERROR_NONE && socketOpened)
|
if (error != kErrorNone && socketOpened)
|
||||||
{
|
{
|
||||||
IgnoreError(mSocket.Close());
|
IgnoreError(mSocket.Close());
|
||||||
}
|
}
|
||||||
@@ -1680,9 +1678,9 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Coap::Stop(void)
|
Error Coap::Stop(void)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
|
|
||||||
VerifyOrExit(mSocket.IsBound());
|
VerifyOrExit(mSocket.IsBound());
|
||||||
|
|
||||||
@@ -1699,14 +1697,14 @@ void Coap::HandleUdpReceive(void *aContext, otMessage *aMessage, const otMessage
|
|||||||
*static_cast<const Ip6::MessageInfo *>(aMessageInfo));
|
*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);
|
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
|
} // namespace Coap
|
||||||
|
|||||||
+109
-110
@@ -211,16 +211,16 @@ public:
|
|||||||
mNext = nullptr;
|
mNext = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError HandleBlockReceive(const uint8_t *aBlock,
|
Error HandleBlockReceive(const uint8_t *aBlock,
|
||||||
uint32_t aPosition,
|
uint32_t aPosition,
|
||||||
uint16_t aBlockLength,
|
uint16_t aBlockLength,
|
||||||
bool aMore,
|
bool aMore,
|
||||||
uint32_t aTotalLength) const
|
uint32_t aTotalLength) const
|
||||||
{
|
{
|
||||||
return mReceiveHook(otCoapBlockwiseResource::mContext, aBlock, aPosition, aBlockLength, aMore, aTotalLength);
|
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);
|
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[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.
|
* @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 kErrorNone 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 kErrorNoBufs Matching response found but there is not sufficient buffer to create a copy.
|
||||||
* @retval OT_ERROR_NOT_FOUND Matching response not found.
|
* @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.
|
* This method gets a reference to the cached CoAP responses queue.
|
||||||
@@ -337,8 +337,8 @@ private:
|
|||||||
|
|
||||||
struct ResponseMetadata
|
struct ResponseMetadata
|
||||||
{
|
{
|
||||||
otError AppendTo(Message &aMessage) const { return aMessage.Append(*this); }
|
Error AppendTo(Message &aMessage) const { return aMessage.Append(*this); }
|
||||||
void ReadFrom(const Message &aMessage);
|
void ReadFrom(const Message &aMessage);
|
||||||
|
|
||||||
TimeMilli mDequeueTime;
|
TimeMilli mDequeueTime;
|
||||||
Ip6::MessageInfo mMessageInfo;
|
Ip6::MessageInfo mMessageInfo;
|
||||||
@@ -377,13 +377,12 @@ public:
|
|||||||
@ @param[in] aMessageInfo A reference to the message info associated with @p aMessage.
|
@ @param[in] aMessageInfo A reference to the message info associated with @p aMessage.
|
||||||
* @param[in] aContext A pointer to arbitrary context information.
|
* @param[in] aContext A pointer to arbitrary context information.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Server should continue processing this message, other
|
* @retval kErrorNone Server should continue processing this message, other return values indicates the
|
||||||
* return values indicates the server should stop processing
|
* server should stop processing this message.
|
||||||
* this message.
|
* @retval kErrorNotTmf The message is not a TMF message.
|
||||||
* @retval OT_ERROR_NOT_TMF 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.
|
* 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] 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.
|
* @param[in] aReceiveHook A pointer to a hook function for incoming block-wise transfer.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully sent CoAP message.
|
* @retval kErrorNone Successfully sent CoAP message.
|
||||||
* @retval OT_ERROR_NO_BUFS Failed to allocate retransmission data.
|
* @retval kErrorNoBufs Failed to allocate retransmission data.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError SendMessage(Message & aMessage,
|
Error SendMessage(Message & aMessage,
|
||||||
const Ip6::MessageInfo & aMessageInfo,
|
const Ip6::MessageInfo & aMessageInfo,
|
||||||
const TxParameters & aTxParameters,
|
const TxParameters & aTxParameters,
|
||||||
otCoapResponseHandler aHandler = nullptr,
|
otCoapResponseHandler aHandler = nullptr,
|
||||||
void * aContext = nullptr,
|
void * aContext = nullptr,
|
||||||
otCoapBlockwiseTransmitHook aTransmitHook = nullptr,
|
otCoapBlockwiseTransmitHook aTransmitHook = nullptr,
|
||||||
otCoapBlockwiseReceiveHook aReceiveHook = nullptr);
|
otCoapBlockwiseReceiveHook aReceiveHook = nullptr);
|
||||||
#else // OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
#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] aHandler A function pointer that shall be called on response reception or time-out.
|
||||||
* @param[in] aContext A pointer to arbitrary context information.
|
* @param[in] aContext A pointer to arbitrary context information.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully sent CoAP message.
|
* @retval kErrorNone Successfully sent CoAP message.
|
||||||
* @retval OT_ERROR_NO_BUFS Insufficient buffers available to send the CoAP message.
|
* @retval kErrorNoBufs Insufficient buffers available to send the CoAP message.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError SendMessage(Message & aMessage,
|
Error SendMessage(Message & aMessage,
|
||||||
const Ip6::MessageInfo &aMessageInfo,
|
const Ip6::MessageInfo &aMessageInfo,
|
||||||
const TxParameters & aTxParameters,
|
const TxParameters & aTxParameters,
|
||||||
ResponseHandler aHandler = nullptr,
|
ResponseHandler aHandler = nullptr,
|
||||||
void * aContext = nullptr);
|
void * aContext = nullptr);
|
||||||
#endif // OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
#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] aHandler A function pointer that shall be called on response reception or time-out.
|
||||||
* @param[in] aContext A pointer to arbitrary context information.
|
* @param[in] aContext A pointer to arbitrary context information.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully sent CoAP message.
|
* @retval kErrorNone Successfully sent CoAP message.
|
||||||
* @retval OT_ERROR_NO_BUFS Insufficient buffers available to send the CoAP response.
|
* @retval kErrorNoBufs Insufficient buffers available to send the CoAP response.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError SendMessage(Message & aMessage,
|
Error SendMessage(Message & aMessage,
|
||||||
const Ip6::MessageInfo &aMessageInfo,
|
const Ip6::MessageInfo &aMessageInfo,
|
||||||
ResponseHandler aHandler = nullptr,
|
ResponseHandler aHandler = nullptr,
|
||||||
void * aContext = nullptr);
|
void * aContext = nullptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method sends a CoAP reset message.
|
* 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] 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 kErrorNone Successfully enqueued the CoAP response message.
|
||||||
* @retval OT_ERROR_NO_BUFS Insufficient buffers available to send the CoAP response.
|
* @retval kErrorNoBufs Insufficient buffers available to send the CoAP response.
|
||||||
* @retval OT_ERROR_INVALID_ARGS The @p aRequest is not of confirmable type.
|
* @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.
|
* 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] 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 kErrorNone Successfully enqueued the CoAP response message.
|
||||||
* @retval OT_ERROR_NO_BUFS Insufficient buffers available to send the CoAP response.
|
* @retval kErrorNoBufs Insufficient buffers available to send the CoAP response.
|
||||||
* @retval OT_ERROR_INVALID_ARGS The @p aRequest header is not of confirmable type.
|
* @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.
|
* 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] 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 kErrorNone Successfully enqueued the CoAP response message.
|
||||||
* @retval OT_ERROR_NO_BUFS Insufficient buffers available to send the CoAP response.
|
* @retval kErrorNoBufs Insufficient buffers available to send the CoAP response.
|
||||||
* @retval OT_ERROR_INVALID_ARGS The @p aRequest header is not of confirmable type.
|
* @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.
|
* 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] aMessageInfo The message info corresponding to the CoAP request.
|
||||||
* @param[in] aCode The CoAP code of the dummy CoAP response.
|
* @param[in] aCode The CoAP code of the dummy CoAP response.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully enqueued the CoAP response message.
|
* @retval kErrorNone Successfully enqueued the CoAP response message.
|
||||||
* @retval OT_ERROR_NO_BUFS Insufficient buffers available to send the CoAP response.
|
* @retval kErrorNoBufs Insufficient buffers available to send the CoAP response.
|
||||||
* @retval OT_ERROR_INVALID_ARGS The @p aRequest header is not of confirmable type.
|
* @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.
|
* 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] 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 kErrorNone Successfully enqueued the CoAP response message.
|
||||||
* @retval OT_ERROR_NO_BUFS Insufficient buffers available to send the CoAP response.
|
* @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
|
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||||
/**
|
/**
|
||||||
@@ -609,13 +608,13 @@ public:
|
|||||||
* were sent out of order.
|
* were sent out of order.
|
||||||
*
|
*
|
||||||
* @param[in] aRequest A reference to the CoAP Message that was used in CoAP 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 kErrorNone Successfully enqueued the CoAP response message.
|
||||||
* @retval OT_ERROR_NO_BUFS Insufficient buffers available to send the CoAP response.
|
* @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);
|
return SendHeaderResponse(kCodeRequestIncomplete, aRequest, aMessageInfo);
|
||||||
}
|
}
|
||||||
@@ -624,16 +623,16 @@ public:
|
|||||||
/**
|
/**
|
||||||
* This method aborts CoAP transactions associated with given handler and context.
|
* 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] aHandler A function pointer that should be called when the transaction ends.
|
||||||
* @param[in] aContext A pointer to arbitrary context information.
|
* @param[in] aContext A pointer to arbitrary context information.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully aborted CoAP transactions.
|
* @retval kErrorNone Successfully aborted CoAP transactions.
|
||||||
* @retval OT_ERROR_NOT_FOUND CoAP transaction associated with given handler was not found.
|
* @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.
|
* 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] aMessage A reference to the message to send.
|
||||||
* @param[in] aMessageInfo A reference to the message info associated with @p aMessage.
|
* @param[in] aMessageInfo A reference to the message info associated with @p aMessage.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully sent CoAP message.
|
* @retval kErrorNone Successfully sent CoAP message.
|
||||||
* @retval OT_ERROR_NO_BUFS Failed to allocate retransmission data.
|
* @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.
|
* This constructor initializes the object.
|
||||||
@@ -696,9 +695,9 @@ protected:
|
|||||||
private:
|
private:
|
||||||
struct Metadata
|
struct Metadata
|
||||||
{
|
{
|
||||||
otError AppendTo(Message &aMessage) const { return aMessage.Append(*this); }
|
Error AppendTo(Message &aMessage) const { return aMessage.Append(*this); }
|
||||||
void ReadFrom(const Message &aMessage);
|
void ReadFrom(const Message &aMessage);
|
||||||
void UpdateIn(Message &aMessage) const;
|
void UpdateIn(Message &aMessage) const;
|
||||||
|
|
||||||
Ip6::Address mSourceAddress; // IPv6 address of the message source.
|
Ip6::Address mSourceAddress; // IPv6 address of the message source.
|
||||||
Ip6::Address mDestinationAddress; // IPv6 address of the message destination.
|
Ip6::Address mDestinationAddress; // IPv6 address of the message destination.
|
||||||
@@ -739,44 +738,44 @@ private:
|
|||||||
const Metadata & aMetadata,
|
const Metadata & aMetadata,
|
||||||
Message * aResponse,
|
Message * aResponse,
|
||||||
const Ip6::MessageInfo *aMessageInfo,
|
const Ip6::MessageInfo *aMessageInfo,
|
||||||
otError aResult);
|
Error aResult);
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||||
void FreeLastBlockResponse(void);
|
void FreeLastBlockResponse(void);
|
||||||
otError CacheLastBlockResponse(Message *aResponse);
|
Error CacheLastBlockResponse(Message *aResponse);
|
||||||
|
|
||||||
otError PrepareNextBlockRequest(Message::BlockType aType,
|
Error PrepareNextBlockRequest(Message::BlockType aType,
|
||||||
bool aMoreBlocks,
|
bool aMoreBlocks,
|
||||||
Message & aRequestOld,
|
Message & aRequestOld,
|
||||||
Message & aRequest,
|
Message & aRequest,
|
||||||
Message & aMessage);
|
Message & aMessage);
|
||||||
otError ProcessBlock1Request(Message & aMessage,
|
Error ProcessBlock1Request(Message & aMessage,
|
||||||
const Ip6::MessageInfo & aMessageInfo,
|
const Ip6::MessageInfo & aMessageInfo,
|
||||||
const ResourceBlockWise &aResource,
|
const ResourceBlockWise &aResource,
|
||||||
uint32_t aTotalLength);
|
uint32_t aTotalLength);
|
||||||
otError ProcessBlock2Request(Message & aMessage,
|
Error ProcessBlock2Request(Message & aMessage,
|
||||||
const Ip6::MessageInfo & aMessageInfo,
|
const Ip6::MessageInfo & aMessageInfo,
|
||||||
const ResourceBlockWise &aResource);
|
const ResourceBlockWise &aResource);
|
||||||
#endif
|
#endif
|
||||||
void ProcessReceivedRequest(Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
void ProcessReceivedRequest(Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||||
void ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
void ProcessReceivedResponse(Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||||
otError SendNextBlock1Request(Message & aRequest,
|
Error SendNextBlock1Request(Message & aRequest,
|
||||||
Message & aMessage,
|
Message & aMessage,
|
||||||
const Ip6::MessageInfo &aMessageInfo,
|
const Ip6::MessageInfo &aMessageInfo,
|
||||||
const Metadata & aCoapMetadata);
|
const Metadata & aCoapMetadata);
|
||||||
otError SendNextBlock2Request(Message & aRequest,
|
Error SendNextBlock2Request(Message & aRequest,
|
||||||
Message & aMessage,
|
Message & aMessage,
|
||||||
const Ip6::MessageInfo &aMessageInfo,
|
const Ip6::MessageInfo &aMessageInfo,
|
||||||
const Metadata & aCoapMetadata,
|
const Metadata & aCoapMetadata,
|
||||||
uint32_t aTotalLength,
|
uint32_t aTotalLength,
|
||||||
bool aBeginBlock1Transfer);
|
bool aBeginBlock1Transfer);
|
||||||
#endif
|
#endif
|
||||||
void SendCopy(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
void SendCopy(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||||
otError SendEmptyMessage(Type aType, const Message &aRequest, 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;
|
MessageQueue mPendingRequests;
|
||||||
uint16_t mMessageId;
|
uint16_t mMessageId;
|
||||||
@@ -820,28 +819,28 @@ public:
|
|||||||
* @param[in] aPort The local UDP port to bind to.
|
* @param[in] aPort The local UDP port to bind to.
|
||||||
* @param[in] aNetifIdentifier The network interface identifier to bind.
|
* @param[in] aNetifIdentifier The network interface identifier to bind.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully started the CoAP service.
|
* @retval kErrorNone Successfully started the CoAP service.
|
||||||
* @retval OT_ERROR_FAILED Failed to start CoAP agent.
|
* @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.
|
* This method stops the CoAP service.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully stopped the CoAP service.
|
* @retval kErrorNone Successfully stopped the CoAP service.
|
||||||
* @retval OT_ERROR_FAILED Failed to stop CoAP agent.
|
* @retval kErrorFailed Failed to stop CoAP agent.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError Stop(void);
|
Error Stop(void);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Ip6::Udp::Socket mSocket;
|
Ip6::Udp::Socket mSocket;
|
||||||
|
|
||||||
private:
|
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);
|
||||||
static void HandleUdpReceive(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo);
|
static void HandleUdpReceive(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo);
|
||||||
otError Send(ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
Error Send(ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Coap
|
} // namespace Coap
|
||||||
|
|||||||
@@ -65,9 +65,9 @@ void Message::Init(Type aType, Code aCode)
|
|||||||
SetCode(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);
|
Init(aType, aCode);
|
||||||
SuccessOrExit(error = GenerateRandomToken(kDefaultTokenLength));
|
SuccessOrExit(error = GenerateRandomToken(kDefaultTokenLength));
|
||||||
@@ -87,17 +87,17 @@ void Message::InitAsNonConfirmablePost(void)
|
|||||||
Init(kTypeNonConfirmable, kCodePost);
|
Init(kTypeNonConfirmable, kCodePost);
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Message::InitAsConfirmablePost(const char *aUriPath)
|
Error Message::InitAsConfirmablePost(const char *aUriPath)
|
||||||
{
|
{
|
||||||
return Init(kTypeConfirmable, kCodePost, aUriPath);
|
return Init(kTypeConfirmable, kCodePost, aUriPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Message::InitAsNonConfirmablePost(const char *aUriPath)
|
Error Message::InitAsNonConfirmablePost(const char *aUriPath)
|
||||||
{
|
{
|
||||||
return Init(kTypeNonConfirmable, kCodePost, 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);
|
return Init(aDestination.IsMulticast() ? kTypeNonConfirmable : kTypeConfirmable, kCodePost, aUriPath);
|
||||||
}
|
}
|
||||||
@@ -160,15 +160,15 @@ uint8_t Message::WriteExtendedOptionField(uint16_t aValue, uint8_t *&aBuffer)
|
|||||||
return rval;
|
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;
|
uint16_t delta;
|
||||||
uint8_t header[kMaxOptionHeaderSize];
|
uint8_t header[kMaxOptionHeaderSize];
|
||||||
uint16_t headerLength;
|
uint16_t headerLength;
|
||||||
uint8_t *cur;
|
uint8_t *cur;
|
||||||
|
|
||||||
VerifyOrExit(aNumber >= GetHelpData().mOptionLast, error = OT_ERROR_INVALID_ARGS);
|
VerifyOrExit(aNumber >= GetHelpData().mOptionLast, error = kErrorInvalidArgs);
|
||||||
delta = aNumber - GetHelpData().mOptionLast;
|
delta = aNumber - GetHelpData().mOptionLast;
|
||||||
|
|
||||||
cur = &header[1];
|
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);
|
headerLength = static_cast<uint16_t>(cur - header);
|
||||||
|
|
||||||
VerifyOrExit(static_cast<uint32_t>(GetLength()) + headerLength + aLength < kMaxHeaderLength,
|
VerifyOrExit(static_cast<uint32_t>(GetLength()) + headerLength + aLength < kMaxHeaderLength, error = kErrorNoBufs);
|
||||||
error = OT_ERROR_NO_BUFS);
|
|
||||||
|
|
||||||
SuccessOrExit(error = AppendBytes(header, headerLength));
|
SuccessOrExit(error = AppendBytes(header, headerLength));
|
||||||
SuccessOrExit(error = AppendBytes(aValue, aLength));
|
SuccessOrExit(error = AppendBytes(aValue, aLength));
|
||||||
@@ -192,7 +191,7 @@ exit:
|
|||||||
return error;
|
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)];
|
uint8_t buffer[sizeof(uint32_t)];
|
||||||
const uint8_t *value = &buffer[0];
|
const uint8_t *value = &buffer[0];
|
||||||
@@ -209,14 +208,14 @@ otError Message::AppendUintOption(uint16_t aNumber, uint32_t aValue)
|
|||||||
return AppendOption(aNumber, length, value);
|
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);
|
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 *cur = aUriPath;
|
||||||
const char *end;
|
const char *end;
|
||||||
|
|
||||||
@@ -232,10 +231,10 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Message::ReadUriPathOptions(char (&aUriPath)[kMaxReceivedUriPath + 1]) const
|
Error Message::ReadUriPathOptions(char (&aUriPath)[kMaxReceivedUriPath + 1]) const
|
||||||
{
|
{
|
||||||
char * curUriPath = aUriPath;
|
char * curUriPath = aUriPath;
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Option::Iterator iterator;
|
Option::Iterator iterator;
|
||||||
|
|
||||||
SuccessOrExit(error = iterator.Init(*this, kOptionUriPath));
|
SuccessOrExit(error = iterator.Init(*this, kOptionUriPath));
|
||||||
@@ -249,7 +248,7 @@ otError Message::ReadUriPathOptions(char (&aUriPath)[kMaxReceivedUriPath + 1]) c
|
|||||||
*curUriPath++ = '/';
|
*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));
|
IgnoreError(iterator.ReadOptionValue(curUriPath));
|
||||||
curUriPath += optionLength;
|
curUriPath += optionLength;
|
||||||
@@ -263,14 +262,14 @@ exit:
|
|||||||
return error;
|
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;
|
uint32_t encoded = aSize;
|
||||||
|
|
||||||
VerifyOrExit(aType == kBlockType1 || aType == kBlockType2, error = OT_ERROR_INVALID_ARGS);
|
VerifyOrExit(aType == kBlockType1 || aType == kBlockType2, error = kErrorInvalidArgs);
|
||||||
VerifyOrExit(aSize <= OT_COAP_OPTION_BLOCK_SZX_1024, error = OT_ERROR_INVALID_ARGS);
|
VerifyOrExit(aSize <= OT_COAP_OPTION_BLOCK_SZX_1024, error = kErrorInvalidArgs);
|
||||||
VerifyOrExit(aNum < kBlockNumMax, error = OT_ERROR_INVALID_ARGS);
|
VerifyOrExit(aNum < kBlockNumMax, error = kErrorInvalidArgs);
|
||||||
|
|
||||||
encoded |= static_cast<uint32_t>(aMore << kBlockMOffset);
|
encoded |= static_cast<uint32_t>(aMore << kBlockMOffset);
|
||||||
encoded |= aNum << kBlockNumOffset;
|
encoded |= aNum << kBlockNumOffset;
|
||||||
@@ -282,13 +281,13 @@ exit:
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
#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};
|
uint8_t buf[kMaxOptionHeaderSize] = {0};
|
||||||
Option::Iterator iterator;
|
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.Init(*this, aBlockType));
|
||||||
SuccessOrExit(error = iterator.ReadOptionValue(buf));
|
SuccessOrExit(error = iterator.ReadOptionValue(buf));
|
||||||
@@ -315,7 +314,7 @@ otError Message::ReadBlockOptionValues(uint16_t aBlockType)
|
|||||||
SetBlockWiseBlockSize(static_cast<otCoapBlockSzx>(buf[2] & 0x07));
|
SetBlockWiseBlockSize(static_cast<otCoapBlockSzx>(buf[2] & 0x07));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error = OT_ERROR_INVALID_ARGS;
|
error = kErrorInvalidArgs;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,12 +323,12 @@ exit:
|
|||||||
}
|
}
|
||||||
#endif // OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
#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;
|
uint8_t marker = kPayloadMarker;
|
||||||
|
|
||||||
VerifyOrExit(GetLength() < kMaxHeaderLength, error = OT_ERROR_NO_BUFS);
|
VerifyOrExit(GetLength() < kMaxHeaderLength, error = kErrorNoBufs);
|
||||||
SuccessOrExit(error = Append(marker));
|
SuccessOrExit(error = Append(marker));
|
||||||
GetHelpData().mHeaderLength = GetLength();
|
GetHelpData().mHeaderLength = GetLength();
|
||||||
|
|
||||||
@@ -340,9 +339,9 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Message::ParseHeader(void)
|
Error Message::ParseHeader(void)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Option::Iterator iterator;
|
Option::Iterator iterator;
|
||||||
|
|
||||||
OT_ASSERT(mBuffer.mHead.mMetadata.mReserved >=
|
OT_ASSERT(mBuffer.mHead.mMetadata.mReserved >=
|
||||||
@@ -354,7 +353,7 @@ otError Message::ParseHeader(void)
|
|||||||
GetHelpData().mHeaderOffset = GetOffset();
|
GetHelpData().mHeaderOffset = GetOffset();
|
||||||
IgnoreError(Read(GetHelpData().mHeaderOffset, GetHelpData().mHeader));
|
IgnoreError(Read(GetHelpData().mHeaderOffset, GetHelpData().mHeader));
|
||||||
|
|
||||||
VerifyOrExit(GetTokenLength() <= kMaxTokenLength, error = OT_ERROR_PARSE);
|
VerifyOrExit(GetTokenLength() <= kMaxTokenLength, error = kErrorParse);
|
||||||
|
|
||||||
SuccessOrExit(error = iterator.Init(*this));
|
SuccessOrExit(error = iterator.Init(*this));
|
||||||
|
|
||||||
@@ -370,7 +369,7 @@ exit:
|
|||||||
return error;
|
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);
|
OT_ASSERT(aTokenLength <= kMaxTokenLength);
|
||||||
|
|
||||||
@@ -381,7 +380,7 @@ otError Message::SetToken(const uint8_t *aToken, uint8_t aTokenLength)
|
|||||||
return SetLength(GetHelpData().mHeaderLength);
|
return SetLength(GetHelpData().mHeaderLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Message::GenerateRandomToken(uint8_t aTokenLength)
|
Error Message::GenerateRandomToken(uint8_t aTokenLength)
|
||||||
{
|
{
|
||||||
uint8_t token[kMaxTokenLength];
|
uint8_t token[kMaxTokenLength];
|
||||||
|
|
||||||
@@ -392,7 +391,7 @@ otError Message::GenerateRandomToken(uint8_t aTokenLength)
|
|||||||
return SetToken(token, aTokenLength);
|
return SetToken(token, aTokenLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Message::SetTokenFromMessage(const Message &aMessage)
|
Error Message::SetTokenFromMessage(const Message &aMessage)
|
||||||
{
|
{
|
||||||
return SetToken(aMessage.GetToken(), aMessage.GetTokenLength());
|
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));
|
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);
|
Init(kTypeAck, kCodeChanged);
|
||||||
|
|
||||||
@@ -525,9 +524,9 @@ const char *Message::CodeToString(void) const
|
|||||||
}
|
}
|
||||||
#endif // OPENTHREAD_CONFIG_COAP_API_ENABLE
|
#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();
|
uint32_t offset = static_cast<uint32_t>(aMessage.GetHelpData().mHeaderOffset) + aMessage.GetOptionStart();
|
||||||
|
|
||||||
// Note that the case where `offset == aMessage.GetLength())` is
|
// Note that the case where `offset == aMessage.GetLength())` is
|
||||||
@@ -547,9 +546,9 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Option::Iterator::Advance(void)
|
Error Option::Iterator::Advance(void)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
uint8_t headerByte;
|
uint8_t headerByte;
|
||||||
uint16_t optionDelta;
|
uint16_t optionDelta;
|
||||||
uint16_t optionLength;
|
uint16_t optionLength;
|
||||||
@@ -558,22 +557,22 @@ otError Option::Iterator::Advance(void)
|
|||||||
|
|
||||||
error = Read(sizeof(uint8_t), &headerByte);
|
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.
|
// Payload Marker indicates end of options and start of payload.
|
||||||
// Absence of a Payload Marker indicates a zero-length payload.
|
// Absence of a Payload Marker indicates a zero-length payload.
|
||||||
|
|
||||||
MarkAsDone();
|
MarkAsDone();
|
||||||
|
|
||||||
if (error == OT_ERROR_NONE)
|
if (error == kErrorNone)
|
||||||
{
|
{
|
||||||
// The presence of a marker followed by a zero-length payload
|
// The presence of a marker followed by a zero-length payload
|
||||||
// MUST be processed as a message format error.
|
// 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;
|
optionDelta = (headerByte & Message::kOptionDeltaMask) >> Message::kOptionDeltaOffset;
|
||||||
@@ -582,14 +581,14 @@ otError Option::Iterator::Advance(void)
|
|||||||
optionLength = (headerByte & Message::kOptionLengthMask) >> Message::kOptionLengthOffset;
|
optionLength = (headerByte & Message::kOptionLengthMask) >> Message::kOptionLengthOffset;
|
||||||
SuccessOrExit(error = ReadExtendedOptionField(optionLength));
|
SuccessOrExit(error = ReadExtendedOptionField(optionLength));
|
||||||
|
|
||||||
VerifyOrExit(optionLength <= GetMessage().GetLength() - mNextOptionOffset, error = OT_ERROR_PARSE);
|
VerifyOrExit(optionLength <= GetMessage().GetLength() - mNextOptionOffset, error = kErrorParse);
|
||||||
mNextOptionOffset += optionLength;
|
mNextOptionOffset += optionLength;
|
||||||
|
|
||||||
mOption.mNumber += optionDelta;
|
mOption.mNumber += optionDelta;
|
||||||
mOption.mLength = optionLength;
|
mOption.mLength = optionLength;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if (error != OT_ERROR_NONE)
|
if (error != kErrorNone)
|
||||||
{
|
{
|
||||||
MarkAsParseErrored();
|
MarkAsParseErrored();
|
||||||
}
|
}
|
||||||
@@ -597,25 +596,25 @@ exit:
|
|||||||
return error;
|
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);
|
GetMessage().ReadBytes(mNextOptionOffset - mOption.mLength, aValue, mOption.mLength);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return error;
|
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)];
|
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));
|
IgnoreError(ReadOptionValue(buffer));
|
||||||
|
|
||||||
aUintValue = 0;
|
aUintValue = 0;
|
||||||
@@ -630,13 +629,13 @@ exit:
|
|||||||
return error;
|
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
|
// Reads `aLength` bytes from the message into `aBuffer` at
|
||||||
// `mNextOptionOffset` and updates the `mNextOptionOffset` on a
|
// `mNextOptionOffset` and updates the `mNextOptionOffset` on a
|
||||||
// successful read (i.e., when entire `aLength` bytes can be read).
|
// 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));
|
SuccessOrExit(error = GetMessage().Read(mNextOptionOffset, aBuffer, aLength));
|
||||||
mNextOptionOffset += aLength;
|
mNextOptionOffset += aLength;
|
||||||
@@ -645,9 +644,9 @@ exit:
|
|||||||
return error;
|
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);
|
VerifyOrExit(aValue >= Message::kOption1ByteExtension);
|
||||||
|
|
||||||
@@ -668,18 +667,18 @@ otError Option::Iterator::ReadExtendedOptionField(uint16_t &aValue)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
error = OT_ERROR_PARSE;
|
error = kErrorParse;
|
||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return error;
|
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();
|
error = Advance();
|
||||||
}
|
}
|
||||||
|
|||||||
+102
-102
@@ -223,33 +223,33 @@ public:
|
|||||||
* @param[in] aCode The Code value.
|
* @param[in] aCode The Code value.
|
||||||
* @param[in] aUriPath A pointer to a null-terminated string.
|
* @param[in] aUriPath A pointer to a null-terminated string.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully appended the option.
|
* @retval kErrorNone Successfully appended the option.
|
||||||
* @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
|
* @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.
|
* 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.
|
* @param[in] aUriPath A pointer to a null-terminated string.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully appended the option.
|
* @retval kErrorNone Successfully appended the option.
|
||||||
* @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
|
* @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.
|
* 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.
|
* @param[in] aUriPath A pointer to a null-terminated string.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully appended the option.
|
* @retval kErrorNone Successfully appended the option.
|
||||||
* @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
|
* @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
|
* 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.
|
* `kTypeNonConfirmable` if multicast address, `kTypeConfirmable` otherwise.
|
||||||
* @param[in] aUriPath A pointer to a null-terminated string.
|
* @param[in] aUriPath A pointer to a null-terminated string.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully appended the option.
|
* @retval kErrorNone Successfully appended the option.
|
||||||
* @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
|
* @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.
|
* 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] aToken A pointer to the Token value.
|
||||||
* @param[in] aTokenLength The Length of @p aToken.
|
* @param[in] aTokenLength The Length of @p aToken.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully set the token value.
|
* @retval kErrorNone Successfully set the token value.
|
||||||
* @retval OT_ERROR_NO_BUFS Insufficient message buffers available to 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.
|
* 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.
|
* @param[in] aMessage The message to copy the Token from.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully set the token value.
|
* @retval kErrorNone Successfully set the token value.
|
||||||
* @retval OT_ERROR_NO_BUFS Insufficient message buffers available to 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.
|
* This method sets the Token length and randomizes its value.
|
||||||
*
|
*
|
||||||
* @param[in] aTokenLength The Length of a Token to set.
|
* @param[in] aTokenLength The Length of a Token to set.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully set the token value.
|
* @retval kErrorNone Successfully set the token value.
|
||||||
* @retval OT_ERROR_NO_BUFS Insufficient message buffers available to 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.
|
* 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] aLength The CoAP Option length.
|
||||||
* @param[in] aValue A pointer to the CoAP Option value (@p aLength bytes are used as Option value).
|
* @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 kErrorNone Successfully appended the option.
|
||||||
* @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
|
* @retval kErrorInvalidArgs 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 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
|
* 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] aNumber The CoAP Option number.
|
||||||
* @param[in] aValue The CoAP Option unsigned integer value.
|
* @param[in] aValue The CoAP Option unsigned integer value.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully appended the option.
|
* @retval kErrorNone Successfully appended the option.
|
||||||
* @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
|
* @retval kErrorInvalidArgs 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 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.
|
* This method appends a string CoAP option.
|
||||||
@@ -453,35 +453,35 @@ public:
|
|||||||
* @param[in] aNumber The CoAP Option number.
|
* @param[in] aNumber The CoAP Option number.
|
||||||
* @param[in] aValue The CoAP Option string value.
|
* @param[in] aValue The CoAP Option string value.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully appended the option.
|
* @retval kErrorNone Successfully appended the option.
|
||||||
* @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
|
* @retval kErrorInvalidArgs 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 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.
|
* This method appends an Observe option.
|
||||||
*
|
*
|
||||||
* @param[in] aObserve Observe field value.
|
* @param[in] aObserve Observe field value.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully appended the option.
|
* @retval kErrorNone Successfully appended the option.
|
||||||
* @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
|
* @retval kErrorInvalidArgs 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 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.
|
* This method appends a Uri-Path option.
|
||||||
*
|
*
|
||||||
* @param[in] aUriPath A pointer to a null-terminated string.
|
* @param[in] aUriPath A pointer to a null-terminated string.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully appended the option.
|
* @retval kErrorNone Successfully appended the option.
|
||||||
* @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
|
* @retval kErrorInvalidArgs 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 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`.
|
* 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.
|
* @param[in] aUriPath A reference to the buffer for storing URI path.
|
||||||
* NOTE: The buffer size must be `kMaxReceivedUriPath + 1`.
|
* NOTE: The buffer size must be `kMaxReceivedUriPath + 1`.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully read the Uri-Path options.
|
* @retval kErrorNone Successfully read the Uri-Path options.
|
||||||
* @retval OT_ERROR_PARSE CoAP Option header not well-formed.
|
* @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
|
* 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] aMore Boolean to indicate more blocks are to be sent.
|
||||||
* @param[in] aSize Maximum block size.
|
* @param[in] aSize Maximum block size.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully appended the option.
|
* @retval kErrorNone Successfully appended the option.
|
||||||
* @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
|
* @retval kErrorInvalidArgs 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 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.
|
* This method appends a Proxy-Uri option.
|
||||||
*
|
*
|
||||||
* @param[in] aProxyUri A pointer to a null-terminated string.
|
* @param[in] aProxyUri A pointer to a null-terminated string.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully appended the option.
|
* @retval kErrorNone Successfully appended the option.
|
||||||
* @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
|
* @retval kErrorInvalidArgs 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 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.
|
* This method appends a Content-Format option.
|
||||||
*
|
*
|
||||||
* @param[in] aContentFormat The Content Format value.
|
* @param[in] aContentFormat The Content Format value.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully appended the option.
|
* @retval kErrorNone Successfully appended the option.
|
||||||
* @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
|
* @retval kErrorInvalidArgs 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 kErrorNoBufs The option length exceeds the buffer size.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError AppendContentFormatOption(otCoapOptionContentFormat aContentFormat)
|
Error AppendContentFormatOption(otCoapOptionContentFormat aContentFormat)
|
||||||
{
|
{
|
||||||
return AppendUintOption(kOptionContentFormat, static_cast<uint32_t>(aContentFormat));
|
return AppendUintOption(kOptionContentFormat, static_cast<uint32_t>(aContentFormat));
|
||||||
}
|
}
|
||||||
@@ -542,22 +542,22 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[in] aMaxAge The Max-Age value.
|
* @param[in] aMaxAge The Max-Age value.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully appended the option.
|
* @retval kErrorNone Successfully appended the option.
|
||||||
* @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
|
* @retval kErrorInvalidArgs 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 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.
|
* 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.
|
* @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 kErrorNone Successfully appended the option.
|
||||||
* @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
|
* @retval kErrorInvalidArgs 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 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
|
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||||
/**
|
/**
|
||||||
@@ -566,11 +566,11 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[in] aBlockType Block1 or Block2 option value.
|
* @param[in] aBlockType Block1 or Block2 option value.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE The option has been found and is valid.
|
* @retval kErrorNone The option has been found and is valid.
|
||||||
* @retval OT_ERROR_NOT_FOUND The option has not been found.
|
* @retval kErrorNotFound The option has not been found.
|
||||||
* @retval OT_ERROR_INVALID_ARGS The option is invalid.
|
* @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.
|
* 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.
|
* 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 kErrorNone URI path string has been reassembled.
|
||||||
* @retval OT_ERROR_NO_BUFS URI path string is too long.
|
* @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.
|
* This method adds Payload Marker indicating beginning of the payload to the CoAP header.
|
||||||
*
|
*
|
||||||
* It also set offset to the start of payload.
|
* It also set offset to the start of payload.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Payload Marker successfully added.
|
* @retval kErrorNone Payload Marker successfully added.
|
||||||
* @retval OT_ERROR_NO_BUFS Message Payload Marker exceeds the buffer size.
|
* @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.
|
* 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.
|
* This method parses CoAP header and moves offset end of CoAP header.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully parsed CoAP header from the message.
|
* @retval kErrorNone Successfully parsed CoAP header from the message.
|
||||||
* @retval OT_ERROR_PARSE Failed to parse the CoAP header.
|
* @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.
|
* This method sets a default response header based on request header.
|
||||||
*
|
*
|
||||||
* @param[in] aRequest The request message.
|
* @param[in] aRequest The request message.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully set the default response header.
|
* @retval kErrorNone Successfully set the default response header.
|
||||||
* @retval OT_ERROR_NO_BUFS Insufficient message buffers available to 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
|
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||||
|
|
||||||
@@ -1058,11 +1058,11 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[in] aMessage The CoAP message.
|
* @param[in] aMessage The CoAP message.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully initialized. Iterator is either at the first option or done.
|
* @retval kErrorNone 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 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
|
* 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] aMessage The CoAP message.
|
||||||
* @param[in] aNumber The CoAP Option Number.
|
* @param[in] aNumber The CoAP Option Number.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully initialized. Iterator is either at the first matching option or done.
|
* @retval kErrorNone 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 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).
|
* 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.
|
* 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 kErrorNone Successfully advanced the iterator.
|
||||||
* @retval OT_ERROR_PARSE CoAP Option header is not well-formed.
|
* @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.
|
* 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.
|
* @param[in] aNumber The CoAP Option Number.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully advanced the iterator.
|
* @retval kErrorNone Successfully advanced the iterator.
|
||||||
* @retval OT_ERROR_PARSE CoAP Option header is not well-formed.
|
* @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.
|
* 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
|
* @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).
|
* sufficiently large (i.e. at least `GetOption()->GetLength()` bytes).
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully read and copied the Option Value into given buffer.
|
* @retval kErrorNone Successfully read and copied the Option Value into given buffer.
|
||||||
* @retval OT_ERROR_NOT_FOUND Iterator is done (not pointing to any option).
|
* @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.
|
* 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.
|
* @param[out] aUintValue A reference to `uint64_t` to output the read Option Value.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully read the Option value.
|
* @retval kErrorNone Successfully read the Option value.
|
||||||
* @retval OT_ERROR_NO_BUFS Value is too long to fit in an `uint64_t`.
|
* @retval kErrorNoBufs Value is too long to fit in an `uint64_t`.
|
||||||
* @retval OT_ERROR_NOT_FOUND Iterator is done (not pointing to any option).
|
* @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).
|
* 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 MarkAsDone(void) { mOption.mLength = kIteratorDoneLength; }
|
||||||
void MarkAsParseErrored(void) { MarkAsDone(), mNextOptionOffset = kNextOptionOffsetParseError; }
|
void MarkAsParseErrored(void) { MarkAsDone(), mNextOptionOffset = kNextOptionOffsetParseError; }
|
||||||
|
|
||||||
otError Read(uint16_t aLength, void *aBuffer);
|
Error Read(uint16_t aLength, void *aBuffer);
|
||||||
otError ReadExtendedOptionField(uint16_t &aValue);
|
Error ReadExtendedOptionField(uint16_t &aValue);
|
||||||
otError InitOrAdvance(const Message *aMessage, uint16_t aNumber);
|
Error InitOrAdvance(const Message *aMessage, uint16_t aNumber);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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;
|
mConnectedCallback = nullptr;
|
||||||
mConnectedContext = nullptr;
|
mConnectedContext = nullptr;
|
||||||
@@ -68,9 +68,9 @@ exit:
|
|||||||
return error;
|
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;
|
mConnectedCallback = nullptr;
|
||||||
mConnectedContext = nullptr;
|
mConnectedContext = nullptr;
|
||||||
@@ -95,7 +95,7 @@ void CoapSecure::Stop(void)
|
|||||||
ClearRequestsAndResponses();
|
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;
|
mConnectedCallback = aCallback;
|
||||||
mConnectedContext = aContext;
|
mConnectedContext = aContext;
|
||||||
@@ -105,7 +105,7 @@ otError CoapSecure::Connect(const Ip6::SockAddr &aSockAddr, ConnectedCallback aC
|
|||||||
|
|
||||||
void CoapSecure::SetPsk(const MeshCoP::JoinerPskd &aPskd)
|
void CoapSecure::SetPsk(const MeshCoP::JoinerPskd &aPskd)
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
OT_UNUSED_VARIABLE(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());
|
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
|
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||||
otError CoapSecure::SendMessage(Message & aMessage,
|
Error CoapSecure::SendMessage(Message & aMessage,
|
||||||
ResponseHandler aHandler,
|
ResponseHandler aHandler,
|
||||||
void * aContext,
|
void * aContext,
|
||||||
otCoapBlockwiseTransmitHook aTransmitHook,
|
otCoapBlockwiseTransmitHook aTransmitHook,
|
||||||
otCoapBlockwiseReceiveHook aReceiveHook)
|
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,
|
error = CoapBase::SendMessage(aMessage, mDtls.GetMessageInfo(), TxParameters::GetDefault(), aHandler, aContext,
|
||||||
aTransmitHook, aReceiveHook);
|
aTransmitHook, aReceiveHook);
|
||||||
@@ -136,22 +136,22 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError CoapSecure::SendMessage(Message & aMessage,
|
Error CoapSecure::SendMessage(Message & aMessage,
|
||||||
const Ip6::MessageInfo & aMessageInfo,
|
const Ip6::MessageInfo & aMessageInfo,
|
||||||
ResponseHandler aHandler,
|
ResponseHandler aHandler,
|
||||||
void * aContext,
|
void * aContext,
|
||||||
otCoapBlockwiseTransmitHook aTransmitHook,
|
otCoapBlockwiseTransmitHook aTransmitHook,
|
||||||
otCoapBlockwiseReceiveHook aReceiveHook)
|
otCoapBlockwiseReceiveHook aReceiveHook)
|
||||||
{
|
{
|
||||||
return CoapBase::SendMessage(aMessage, aMessageInfo, TxParameters::GetDefault(), aHandler, aContext, aTransmitHook,
|
return CoapBase::SendMessage(aMessage, aMessageInfo, TxParameters::GetDefault(), aHandler, aContext, aTransmitHook,
|
||||||
aReceiveHook);
|
aReceiveHook);
|
||||||
}
|
}
|
||||||
#else // OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
#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);
|
error = CoapBase::SendMessage(aMessage, mDtls.GetMessageInfo(), aHandler, aContext);
|
||||||
|
|
||||||
@@ -159,23 +159,23 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError CoapSecure::SendMessage(Message & aMessage,
|
Error CoapSecure::SendMessage(Message & aMessage,
|
||||||
const Ip6::MessageInfo &aMessageInfo,
|
const Ip6::MessageInfo &aMessageInfo,
|
||||||
ResponseHandler aHandler,
|
ResponseHandler aHandler,
|
||||||
void * aContext)
|
void * aContext)
|
||||||
{
|
{
|
||||||
return CoapBase::SendMessage(aMessage, aMessageInfo, aHandler, aContext);
|
return CoapBase::SendMessage(aMessage, aMessageInfo, aHandler, aContext);
|
||||||
}
|
}
|
||||||
#endif // OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
#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);
|
OT_UNUSED_VARIABLE(aMessageInfo);
|
||||||
|
|
||||||
mTransmitQueue.Enqueue(aMessage);
|
mTransmitQueue.Enqueue(aMessage);
|
||||||
mTransmitTask.Post();
|
mTransmitTask.Post();
|
||||||
|
|
||||||
return OT_ERROR_NONE;
|
return kErrorNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoapSecure::HandleDtlsConnected(void *aContext, bool aConnected)
|
void CoapSecure::HandleDtlsConnected(void *aContext, bool aConnected)
|
||||||
@@ -216,7 +216,7 @@ void CoapSecure::HandleTransmit(Tasklet &aTasklet)
|
|||||||
|
|
||||||
void CoapSecure::HandleTransmit(void)
|
void CoapSecure::HandleTransmit(void)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
ot::Message *message = mTransmitQueue.GetHead();
|
ot::Message *message = mTransmitQueue.GetHead();
|
||||||
|
|
||||||
VerifyOrExit(message != nullptr);
|
VerifyOrExit(message != nullptr);
|
||||||
@@ -230,14 +230,14 @@ void CoapSecure::HandleTransmit(void)
|
|||||||
SuccessOrExit(error = mDtls.Send(*message, message->GetLength()));
|
SuccessOrExit(error = mDtls.Send(*message, message->GetLength()));
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if (error != OT_ERROR_NONE)
|
if (error != kErrorNone)
|
||||||
{
|
{
|
||||||
otLogNoteMeshCoP("CoapSecure Transmit: %s", otThreadErrorToString(error));
|
otLogNoteMeshCoP("CoapSecure Transmit: %s", ErrorToString(error));
|
||||||
message->Free();
|
message->Free();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
otLogDebgMeshCoP("CoapSecure Transmit: %s", otThreadErrorToString(error));
|
otLogDebgMeshCoP("CoapSecure Transmit: %s", ErrorToString(error));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,11 +72,11 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[in] aPort The local UDP port to bind to.
|
* @param[in] aPort The local UDP port to bind to.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully started the CoAP agent.
|
* @retval kErrorNone Successfully started the CoAP agent.
|
||||||
* @retval OT_ERROR_ALREADY Already started.
|
* @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.
|
* 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] aCallback A pointer to a function for sending messages.
|
||||||
* @param[in] aContext A pointer to arbitrary context information.
|
* @param[in] aContext A pointer to arbitrary context information.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully started the CoAP agent.
|
* @retval kErrorNone Successfully started the CoAP agent.
|
||||||
* @retval OT_ERROR_ALREADY Already started.
|
* @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.
|
* 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
|
* @param[in] aCallback A pointer to a function that will be called once DTLS connection is
|
||||||
* established.
|
* 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.
|
* 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] aPsk A pointer to the PSK.
|
||||||
* @param[in] aPskLength The PSK length.
|
* @param[in] aPskLength The PSK length.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully set the PSK.
|
* @retval kErrorNone Successfully set the PSK.
|
||||||
* @retval OT_ERROR_INVALID_ARGS The PSK is invalid.
|
* @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.
|
* This method sets the PSK.
|
||||||
@@ -238,11 +238,11 @@ public:
|
|||||||
* @param[out] aCertLength The length of the base64 encoded peer certificate.
|
* @param[out] aCertLength The length of the base64 encoded peer certificate.
|
||||||
* @param[in] aCertBufferSize The buffer size of aPeerCert.
|
* @param[in] aCertBufferSize The buffer size of aPeerCert.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully get the peer certificate.
|
* @retval kErrorNone Successfully get the peer certificate.
|
||||||
* @retval OT_ERROR_NO_BUFS Can't allocate memory for 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);
|
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] 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.
|
* @param[in] aReceiveHook A pointer to a hook function for incoming block-wise transfer.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully sent CoAP message.
|
* @retval kErrorNone Successfully sent CoAP message.
|
||||||
* @retval OT_ERROR_NO_BUFS Failed to allocate retransmission data.
|
* @retval kErrorNoBufs Failed to allocate retransmission data.
|
||||||
* @retval OT_ERROR_INVALID_STATE DTLS connection was not initialized.
|
* @retval kErrorInvalidState DTLS connection was not initialized.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError SendMessage(Message & aMessage,
|
Error SendMessage(Message & aMessage,
|
||||||
ResponseHandler aHandler = nullptr,
|
ResponseHandler aHandler = nullptr,
|
||||||
void * aContext = nullptr,
|
void * aContext = nullptr,
|
||||||
otCoapBlockwiseTransmitHook aTransmitHook = nullptr,
|
otCoapBlockwiseTransmitHook aTransmitHook = nullptr,
|
||||||
otCoapBlockwiseReceiveHook aReceiveHook = nullptr);
|
otCoapBlockwiseReceiveHook aReceiveHook = nullptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method sends a CoAP message over secure DTLS connection.
|
* 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] 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.
|
* @param[in] aReceiveHook A pointer to a hook function for incoming block-wise transfer.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully sent CoAP message.
|
* @retval kErrorNone Successfully sent CoAP message.
|
||||||
* @retval OT_ERROR_NO_BUFS Failed to allocate retransmission data.
|
* @retval kErrorNoBufs Failed to allocate retransmission data.
|
||||||
* @retval OT_ERROR_INVALID_STATE DTLS connection was not initialized.
|
* @retval kErrorInvalidState DTLS connection was not initialized.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError SendMessage(Message & aMessage,
|
Error SendMessage(Message & aMessage,
|
||||||
const Ip6::MessageInfo & aMessageInfo,
|
const Ip6::MessageInfo & aMessageInfo,
|
||||||
ResponseHandler aHandler = nullptr,
|
ResponseHandler aHandler = nullptr,
|
||||||
void * aContext = nullptr,
|
void * aContext = nullptr,
|
||||||
otCoapBlockwiseTransmitHook aTransmitHook = nullptr,
|
otCoapBlockwiseTransmitHook aTransmitHook = nullptr,
|
||||||
otCoapBlockwiseReceiveHook aReceiveHook = nullptr);
|
otCoapBlockwiseReceiveHook aReceiveHook = nullptr);
|
||||||
#else // OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
#else // OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||||
/**
|
/**
|
||||||
* This method sends a CoAP message over secure DTLS connection.
|
* 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] aHandler A function pointer that shall be called on response reception or time-out.
|
||||||
* @param[in] aContext A pointer to arbitrary context information.
|
* @param[in] aContext A pointer to arbitrary context information.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully sent CoAP message.
|
* @retval kErrorNone Successfully sent CoAP message.
|
||||||
* @retval OT_ERROR_NO_BUFS Failed to allocate retransmission data.
|
* @retval kErrorNoBufs Failed to allocate retransmission data.
|
||||||
* @retval OT_ERROR_INVALID_STATE DTLS connection was not initialized.
|
* @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.
|
* 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] aHandler A function pointer that shall be called on response reception or time-out.
|
||||||
* @param[in] aContext A pointer to arbitrary context information.
|
* @param[in] aContext A pointer to arbitrary context information.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully sent CoAP message.
|
* @retval kErrorNone Successfully sent CoAP message.
|
||||||
* @retval OT_ERROR_NO_BUFS Failed to allocate retransmission data.
|
* @retval kErrorNoBufs Failed to allocate retransmission data.
|
||||||
* @retval OT_ERROR_INVALID_STATE DTLS connection was not initialized.
|
* @retval kErrorInvalidState DTLS connection was not initialized.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError SendMessage(Message & aMessage,
|
Error SendMessage(Message & aMessage,
|
||||||
const Ip6::MessageInfo &aMessageInfo,
|
const Ip6::MessageInfo &aMessageInfo,
|
||||||
ResponseHandler aHandler = nullptr,
|
ResponseHandler aHandler = nullptr,
|
||||||
void * aContext = nullptr);
|
void * aContext = nullptr);
|
||||||
#endif // OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
#endif // OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -385,11 +385,11 @@ public:
|
|||||||
const Ip6::MessageInfo &GetMessageInfo(void) const { return mDtls.GetMessageInfo(); }
|
const Ip6::MessageInfo &GetMessageInfo(void) const { return mDtls.GetMessageInfo(); }
|
||||||
|
|
||||||
private:
|
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);
|
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);
|
static void HandleDtlsConnected(void *aContext, bool aConnected);
|
||||||
void HandleDtlsConnected(bool aConnected);
|
void HandleDtlsConnected(bool aConnected);
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -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_
|
||||||
@@ -214,11 +214,11 @@ void Instance::FactoryReset(void)
|
|||||||
otPlatReset(this);
|
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();
|
Get<Settings>().Wipe();
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
|||||||
@@ -39,13 +39,13 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <openthread/error.h>
|
|
||||||
#include <openthread/heap.h>
|
#include <openthread/heap.h>
|
||||||
#include <openthread/platform/logging.h>
|
#include <openthread/platform/logging.h>
|
||||||
#if OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
|
#if OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
|
||||||
#include <openthread/platform/memory.h>
|
#include <openthread/platform/memory.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "common/error.hpp"
|
||||||
#include "common/non_copyable.hpp"
|
#include "common/non_copyable.hpp"
|
||||||
#include "common/random_manager.hpp"
|
#include "common/random_manager.hpp"
|
||||||
#include "common/tasklet.hpp"
|
#include "common/tasklet.hpp"
|
||||||
@@ -238,11 +238,11 @@ public:
|
|||||||
*
|
*
|
||||||
* Erase is successful/allowed only if the device is in `disabled` state/role.
|
* 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 kErrorNone All persistent info/state was erased successfully.
|
||||||
* @retval OT_ERROR_INVALID_STATE Device is not in `disabled` state/role.
|
* @retval kErrorInvalidState Device is not in `disabled` state/role.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError ErasePersistentInfo(void);
|
Error ErasePersistentInfo(void);
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
|
#if OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
|
||||||
static void HeapFree(void *aPointer) { otPlatFree(aPointer); }
|
static void HeapFree(void *aPointer) { otPlatFree(aPointer); }
|
||||||
|
|||||||
@@ -37,7 +37,8 @@
|
|||||||
#include "openthread-core-config.h"
|
#include "openthread-core-config.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <openthread/error.h>
|
|
||||||
|
#include "common/error.hpp"
|
||||||
|
|
||||||
namespace ot {
|
namespace ot {
|
||||||
|
|
||||||
@@ -239,7 +240,7 @@ public:
|
|||||||
{
|
{
|
||||||
const Type *prev;
|
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.
|
* @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 kErrorNone The entry was successfully added at the head of the list.
|
||||||
* @retval OT_ERROR_ALREADY The entry is already in 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))
|
if (Contains(aEntry))
|
||||||
{
|
{
|
||||||
error = OT_ERROR_ALREADY;
|
error = kErrorAlready;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -295,16 +296,16 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[in] aEntry A reference to an entry to remove.
|
* @param[in] aEntry A reference to an entry to remove.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE The entry was successfully removed from the list.
|
* @retval kErrorNone The entry was successfully removed from the list.
|
||||||
* @retval OT_ERROR_NOT_FOUND Could not find the entry in the list.
|
* @retval kErrorNotFound Could not find the entry in the list.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError Remove(const Type &aEntry)
|
Error Remove(const Type &aEntry)
|
||||||
{
|
{
|
||||||
Type * prev;
|
Type *prev;
|
||||||
otError error = Find(aEntry, prev);
|
Error error = Find(aEntry, prev);
|
||||||
|
|
||||||
if (error == OT_ERROR_NONE)
|
if (error == kErrorNone)
|
||||||
{
|
{
|
||||||
PopAfter(prev);
|
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
|
* @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.
|
* 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 kErrorNone 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 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;
|
aPrevEntry = nullptr;
|
||||||
|
|
||||||
@@ -365,7 +366,7 @@ public:
|
|||||||
{
|
{
|
||||||
if (entry == &aEntry)
|
if (entry == &aEntry)
|
||||||
{
|
{
|
||||||
error = OT_ERROR_NONE;
|
error = kErrorNone;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -381,11 +382,11 @@ public:
|
|||||||
* @p aPrevEntry is set to nullptr if @p aEntry is the head of the list. Otherwise it is
|
* @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.
|
* 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 kErrorNone 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 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));
|
return const_cast<const LinkedList *>(this)->Find(aEntry, const_cast<const Type *&>(aPrevEntry));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ static void Log(otLogLevel aLogLevel,
|
|||||||
#endif // OPENTHREAD_CONFIG_LOG_PREPEND_LEVEL
|
#endif // OPENTHREAD_CONFIG_LOG_PREPEND_LEVEL
|
||||||
|
|
||||||
IgnoreError(logString.Append("%s", aRegionPrefix));
|
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());
|
otPlatLog(aLogLevel, aLogRegion, "%s" OPENTHREAD_CONFIG_LOG_SUFFIX, logString.AsCString());
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
@@ -318,51 +318,6 @@ void otDump(otLogLevel, otLogRegion, const char *, const void *, const size_t)
|
|||||||
}
|
}
|
||||||
#endif // OPENTHREAD_CONFIG_LOG_PKT_DUMP
|
#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
|
#if OPENTHREAD_CONFIG_LOG_DEFINE_AS_MACRO_ONLY
|
||||||
|
|
||||||
const char *otLogLevelToPrefixString(otLogLevel aLogLevel)
|
const char *otLogLevelToPrefixString(otLogLevel aLogLevel)
|
||||||
|
|||||||
@@ -2558,7 +2558,7 @@ const char *otLogLevelToPrefixString(otLogLevel aLogLevel);
|
|||||||
/**
|
/**
|
||||||
* @def otLogResultPlat
|
* @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.
|
* log level is info. Otherwise the log level is warn.
|
||||||
*
|
*
|
||||||
* @param[in] aError The error result.
|
* @param[in] aError The error result.
|
||||||
|
|||||||
+21
-21
@@ -66,7 +66,7 @@ MessagePool::MessagePool(Instance &aInstance)
|
|||||||
|
|
||||||
Message *MessagePool::New(Message::Type aType, uint16_t aReserveHeader, Message::Priority aPriority)
|
Message *MessagePool::New(Message::Type aType, uint16_t aReserveHeader, Message::Priority aPriority)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Message *message;
|
Message *message;
|
||||||
|
|
||||||
VerifyOrExit((message = static_cast<Message *>(NewBuffer(aPriority))) != nullptr);
|
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));
|
SuccessOrExit(error = message->SetLength(0));
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if (error != OT_ERROR_NONE)
|
if (error != kErrorNone)
|
||||||
{
|
{
|
||||||
Free(message);
|
Free(message);
|
||||||
message = nullptr;
|
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);
|
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
|
// add buffers
|
||||||
Buffer * curBuffer = this;
|
Buffer * curBuffer = this;
|
||||||
@@ -215,7 +215,7 @@ otError Message::ResizeMessage(uint16_t aLength)
|
|||||||
if (curBuffer->GetNextBuffer() == nullptr)
|
if (curBuffer->GetNextBuffer() == nullptr)
|
||||||
{
|
{
|
||||||
curBuffer->SetNextBuffer(GetMessagePool()->NewBuffer(GetPriority()));
|
curBuffer->SetNextBuffer(GetMessagePool()->NewBuffer(GetPriority()));
|
||||||
VerifyOrExit(curBuffer->GetNextBuffer() != nullptr, error = OT_ERROR_NO_BUFS);
|
VerifyOrExit(curBuffer->GetNextBuffer() != nullptr, error = kErrorNoBufs);
|
||||||
}
|
}
|
||||||
|
|
||||||
curBuffer = curBuffer->GetNextBuffer();
|
curBuffer = curBuffer->GetNextBuffer();
|
||||||
@@ -262,12 +262,12 @@ exit:
|
|||||||
return next;
|
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;
|
uint16_t totalLengthRequest = GetReserved() + aLength;
|
||||||
|
|
||||||
VerifyOrExit(totalLengthRequest >= GetReserved(), error = OT_ERROR_INVALID_ARGS);
|
VerifyOrExit(totalLengthRequest >= GetReserved(), error = kErrorInvalidArgs);
|
||||||
|
|
||||||
SuccessOrExit(error = ResizeMessage(totalLengthRequest));
|
SuccessOrExit(error = ResizeMessage(totalLengthRequest));
|
||||||
GetMetadata().mLength = aLength;
|
GetMetadata().mLength = aLength;
|
||||||
@@ -331,13 +331,13 @@ bool Message::IsSubTypeMle(void) const
|
|||||||
return rval;
|
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);
|
uint8_t priority = static_cast<uint8_t>(aPriority);
|
||||||
PriorityQueue *priorityQueue = nullptr;
|
PriorityQueue *priorityQueue = nullptr;
|
||||||
|
|
||||||
VerifyOrExit(priority < kNumPriorities, error = OT_ERROR_INVALID_ARGS);
|
VerifyOrExit(priority < kNumPriorities, error = kErrorInvalidArgs);
|
||||||
|
|
||||||
VerifyOrExit(IsInAQueue(), GetMetadata().mPriority = priority);
|
VerifyOrExit(IsInAQueue(), GetMetadata().mPriority = priority);
|
||||||
VerifyOrExit(GetMetadata().mPriority != priority);
|
VerifyOrExit(GetMetadata().mPriority != priority);
|
||||||
@@ -376,9 +376,9 @@ const char *Message::PriorityToString(Priority aPriority)
|
|||||||
return kPriorityStrings[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();
|
uint16_t oldLength = GetLength();
|
||||||
|
|
||||||
SuccessOrExit(error = SetLength(GetLength() + aLength));
|
SuccessOrExit(error = SetLength(GetLength() + aLength));
|
||||||
@@ -388,14 +388,14 @@ exit:
|
|||||||
return error;
|
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;
|
Buffer *newBuffer = nullptr;
|
||||||
|
|
||||||
while (aLength > GetReserved())
|
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());
|
newBuffer->SetNextBuffer(GetNextBuffer());
|
||||||
SetNextBuffer(newBuffer);
|
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));
|
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
|
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
|
Message *Message::Clone(uint16_t aLength) const
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Message *messageCopy;
|
Message *messageCopy;
|
||||||
uint16_t offset;
|
uint16_t offset;
|
||||||
|
|
||||||
VerifyOrExit((messageCopy = GetMessagePool()->New(GetType(), GetReserved(), GetPriority())) != nullptr,
|
VerifyOrExit((messageCopy = GetMessagePool()->New(GetType(), GetReserved(), GetPriority())) != nullptr,
|
||||||
error = OT_ERROR_NO_BUFS);
|
error = kErrorNoBufs);
|
||||||
SuccessOrExit(error = messageCopy->SetLength(aLength));
|
SuccessOrExit(error = messageCopy->SetLength(aLength));
|
||||||
CopyTo(0, 0, aLength, *messageCopy);
|
CopyTo(0, 0, aLength, *messageCopy);
|
||||||
|
|
||||||
|
|||||||
+49
-49
@@ -100,38 +100,38 @@ class HmacSha256;
|
|||||||
} while (false)
|
} 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.
|
* 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] 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) \
|
#define FreeMessageOnError(aMessage, aError) \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
if (((aError) != OT_ERROR_NONE) && ((aMessage) != nullptr)) \
|
if (((aError) != kErrorNone) && ((aMessage) != nullptr)) \
|
||||||
{ \
|
{ \
|
||||||
(aMessage)->Free(); \
|
(aMessage)->Free(); \
|
||||||
} \
|
} \
|
||||||
} while (false)
|
} 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] 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) \
|
#define FreeAndNullMessageOnError(aMessage, aError) \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
if (((aError) != OT_ERROR_NONE) && ((aMessage) != nullptr)) \
|
if (((aError) != kErrorNone) && ((aMessage) != nullptr)) \
|
||||||
{ \
|
{ \
|
||||||
(aMessage)->Free(); \
|
(aMessage)->Free(); \
|
||||||
(aMessage) = nullptr; \
|
(aMessage) = nullptr; \
|
||||||
} \
|
} \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
|
||||||
enum
|
enum
|
||||||
@@ -477,11 +477,11 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[in] aLength Requested number of bytes in the message.
|
* @param[in] aLength Requested number of bytes in the message.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully set the length of the message.
|
* @retval kErrorNone 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 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.
|
* This method returns the number of buffers in the message.
|
||||||
@@ -586,11 +586,11 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[in] aPriority The message priority level.
|
* @param[in] aPriority The message priority level.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully set the priority for the message.
|
* @retval kErrorNone Successfully set the priority for the message.
|
||||||
* @retval OT_ERROR_INVALID_ARGS Priority level is not invalid.
|
* @retval kErrorInvalidArgs Priority level is not invalid.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError SetPriority(Priority aPriority);
|
Error SetPriority(Priority aPriority);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This static method convert a `Priority` to a string.
|
* 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] 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.
|
* @param[in] aLength The number of bytes to prepend.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully prepended the bytes.
|
* @retval kErrorNone Successfully prepended the bytes.
|
||||||
* @retval OT_ERROR_NO_BUFS Not enough reserved bytes in the message.
|
* @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.
|
* 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.
|
* @param[in] aObject A reference to the object to prepend to the message.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully prepended the object.
|
* @retval kErrorNone Successfully prepended the object.
|
||||||
* @retval OT_ERROR_NO_BUFS Not enough reserved bytes in the message.
|
* @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");
|
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] aBuf A pointer to a data buffer (MUST not be `nullptr`).
|
||||||
* @param[in] aLength The number of bytes to append.
|
* @param[in] aLength The number of bytes to append.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully appended the bytes.
|
* @retval kErrorNone Successfully appended the bytes.
|
||||||
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to grow the message.
|
* @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.
|
* 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.
|
* @param[in] aObject A reference to the object to append to the message.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully appended the object.
|
* @retval kErrorNone Successfully appended the object.
|
||||||
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to grow the message.
|
* @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");
|
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.
|
* 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
|
* 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[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[out] aBuf A pointer to a data buffer to copy the read bytes into.
|
||||||
* @param[in] aLength Number of bytes to read.
|
* @param[in] aLength Number of bytes to read.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE @p aLength bytes were successfully read from message.
|
* @retval kErrorNone @p aLength bytes were successfully read from message.
|
||||||
* @retval OT_ERROR_PARSE Not enough bytes remaining in message to read the entire object.
|
* @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.
|
* 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
|
* 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.
|
* be returned.
|
||||||
*
|
*
|
||||||
* @tparam ObjectType The object type to read from the message.
|
* @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[in] aOffset Byte offset within the message to begin reading.
|
||||||
* @param[out] aObject A reference to the object to read into.
|
* @param[out] aObject A reference to the object to read into.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Object @p aObject was successfully read from message.
|
* @retval kErrorNone Object @p aObject was successfully read from message.
|
||||||
* @retval OT_ERROR_PARSE Not enough bytes remaining in message to read the entire object.
|
* @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");
|
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.
|
* @param[in] aLength The number of bytes that the message buffer needs to handle.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully resized the message.
|
* @retval kErrorNone Successfully resized the message.
|
||||||
* @retval OT_ERROR_NO_BUFS Could not grow the message due to insufficient available message buffers.
|
* @retval kErrorNoBufs Could not grow the message due to insufficient available message buffers.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError ResizeMessage(uint16_t aLength);
|
Error ResizeMessage(uint16_t aLength);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Chunk
|
struct Chunk
|
||||||
@@ -1627,7 +1627,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
Buffer *NewBuffer(Message::Priority aPriority);
|
Buffer *NewBuffer(Message::Priority aPriority);
|
||||||
void FreeBuffers(Buffer *aBuffer);
|
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
|
#if !OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT && !OPENTHREAD_CONFIG_MESSAGE_USE_HEAP_ENABLE
|
||||||
uint16_t mNumFreeBuffers;
|
uint16_t mNumFreeBuffers;
|
||||||
|
|||||||
@@ -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;
|
ExternalCallback *unusedCallback = nullptr;
|
||||||
|
|
||||||
VerifyOrExit(aCallback != nullptr);
|
VerifyOrExit(aCallback != nullptr);
|
||||||
@@ -71,10 +71,10 @@ otError Notifier::RegisterCallback(otStateChangedCallback aCallback, void *aCont
|
|||||||
continue;
|
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->mHandler = aCallback;
|
||||||
unusedCallback->mContext = aContext;
|
unusedCallback->mContext = aContext;
|
||||||
|
|||||||
@@ -42,6 +42,7 @@
|
|||||||
#include <openthread/instance.h>
|
#include <openthread/instance.h>
|
||||||
#include <openthread/platform/toolchain.h>
|
#include <openthread/platform/toolchain.h>
|
||||||
|
|
||||||
|
#include "common/error.hpp"
|
||||||
#include "common/locator.hpp"
|
#include "common/locator.hpp"
|
||||||
#include "common/non_copyable.hpp"
|
#include "common/non_copyable.hpp"
|
||||||
#include "common/tasklet.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] aCallback A pointer to the handler function that is called to notify of the changes.
|
||||||
* @param[in] aContext A pointer to arbitrary context information.
|
* @param[in] aContext A pointer to arbitrary context information.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully registered the callback.
|
* @retval kErrorNone Successfully registered the callback.
|
||||||
* @retval OT_ERROR_ALREADY The callback was already registered.
|
* @retval kErrorAlready The callback was already registered.
|
||||||
* @retval OT_ERROR_NO_BUFS Could not add the callback due to resource constraints.
|
* @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.
|
* 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.
|
* 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).
|
* 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 `=`.
|
* The template `Type` should support comparison operator `==` and assignment operator `=`.
|
||||||
@@ -273,18 +274,18 @@ public:
|
|||||||
* @param[in] aNewValue The new value.
|
* @param[in] aNewValue The new value.
|
||||||
* @param[in] aEvent The event to signal.
|
* @param[in] aEvent The event to signal.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE The variable was update successfully and @p aEvent was signaled.
|
* @retval kErrorNone The variable was update successfully and @p aEvent was signaled.
|
||||||
* @retval OT_ERROR_ALREADY The variable was already set to the same value.
|
* @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)
|
if (aVariable == aNewValue)
|
||||||
{
|
{
|
||||||
SignalIfFirst(aEvent);
|
SignalIfFirst(aEvent);
|
||||||
error = OT_ERROR_ALREADY;
|
error = kErrorAlready;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -38,9 +38,8 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <openthread/error.h>
|
|
||||||
|
|
||||||
#include "common/debug.hpp"
|
#include "common/debug.hpp"
|
||||||
|
#include "common/error.hpp"
|
||||||
#include "common/random_manager.hpp"
|
#include "common/random_manager.hpp"
|
||||||
|
|
||||||
namespace ot {
|
namespace ot {
|
||||||
@@ -170,10 +169,10 @@ namespace Crypto {
|
|||||||
* @param[out] aBuffer A pointer to a buffer to fill with the random bytes.
|
* @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).
|
* @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);
|
return RandomManager::CryptoFillBuffer(aBuffer, aSize);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ RandomManager::CryptoCtrDrbg RandomManager::sCtrDrbg;
|
|||||||
RandomManager::RandomManager(void)
|
RandomManager::RandomManager(void)
|
||||||
{
|
{
|
||||||
uint32_t seed;
|
uint32_t seed;
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
OT_UNUSED_VARIABLE(error);
|
OT_UNUSED_VARIABLE(error);
|
||||||
|
|
||||||
@@ -71,10 +71,10 @@ RandomManager::RandomManager(void)
|
|||||||
sCtrDrbg.Init();
|
sCtrDrbg.Init();
|
||||||
|
|
||||||
error = Random::Crypto::FillBuffer(reinterpret_cast<uint8_t *>(&seed), sizeof(seed));
|
error = Random::Crypto::FillBuffer(reinterpret_cast<uint8_t *>(&seed), sizeof(seed));
|
||||||
OT_ASSERT(error == OT_ERROR_NONE);
|
OT_ASSERT(error == kErrorNone);
|
||||||
#else
|
#else
|
||||||
error = otPlatEntropyGet(reinterpret_cast<uint8_t *>(&seed), sizeof(seed));
|
error = otPlatEntropyGet(reinterpret_cast<uint8_t *>(&seed), sizeof(seed));
|
||||||
OT_ASSERT(error == OT_ERROR_NONE);
|
OT_ASSERT(error == kErrorNone);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sPrng.Init(seed);
|
sPrng.Init(seed);
|
||||||
@@ -211,7 +211,7 @@ void RandomManager::CryptoCtrDrbg::Deinit(void)
|
|||||||
mbedtls_ctr_drbg_free(&mCtrDrbg);
|
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(
|
return ot::Crypto::MbedTls::MapError(
|
||||||
mbedtls_ctr_drbg_random(&mCtrDrbg, static_cast<unsigned char *>(aBuffer), static_cast<size_t>(aSize)));
|
mbedtls_ctr_drbg_random(&mCtrDrbg, static_cast<unsigned char *>(aBuffer), static_cast<size_t>(aSize)));
|
||||||
|
|||||||
@@ -37,13 +37,13 @@
|
|||||||
#include "openthread-core-config.h"
|
#include "openthread-core-config.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <openthread/error.h>
|
|
||||||
|
|
||||||
#if !OPENTHREAD_RADIO
|
#if !OPENTHREAD_RADIO
|
||||||
#include <mbedtls/ctr_drbg.h>
|
#include <mbedtls/ctr_drbg.h>
|
||||||
#include <mbedtls/entropy.h>
|
#include <mbedtls/entropy.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "common/error.hpp"
|
||||||
#include "common/non_copyable.hpp"
|
#include "common/non_copyable.hpp"
|
||||||
|
|
||||||
#if (!defined(MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES) && \
|
#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[out] aBuffer A pointer to a buffer to fill with the random bytes.
|
||||||
* @param[in] aSize Size of buffer (number of bytes to fill).
|
* @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.
|
* This static method returns the initialized mbedtls_ctr_drbg_context.
|
||||||
@@ -139,9 +139,9 @@ private:
|
|||||||
class CryptoCtrDrbg
|
class CryptoCtrDrbg
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void Init(void);
|
void Init(void);
|
||||||
void Deinit(void);
|
void Deinit(void);
|
||||||
otError FillBuffer(uint8_t *aBuffer, uint16_t aSize);
|
Error FillBuffer(uint8_t *aBuffer, uint16_t aSize);
|
||||||
|
|
||||||
mbedtls_ctr_drbg_context *GetContext(void) { return &mCtrDrbg; }
|
mbedtls_ctr_drbg_context *GetContext(void) { return &mCtrDrbg; }
|
||||||
|
|
||||||
|
|||||||
@@ -95,11 +95,11 @@ void SettingsBase::LogPrefix(const char *aAction, const char *aPrefixName, const
|
|||||||
|
|
||||||
#if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_WARN)
|
#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);
|
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);
|
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);
|
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);
|
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);
|
return otPlatSettingsSet(&GetInstance(), aKey, aValue, aValueLength);
|
||||||
}
|
}
|
||||||
@@ -178,22 +178,22 @@ void SettingsDriver::SetCriticalKeys(const uint16_t *aKeys, uint16_t aKeysLength
|
|||||||
OT_UNUSED_VARIABLE(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);
|
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);
|
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);
|
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);
|
return mFlash.Set(aKey, aValue, aValueLength);
|
||||||
}
|
}
|
||||||
@@ -222,21 +222,21 @@ void Settings::Wipe(void)
|
|||||||
otLogInfoCore("Non-volatile: Wiped all info");
|
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);
|
LogFailure(error, "saving OperationalDataset", false);
|
||||||
return error;
|
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;
|
uint16_t length = MeshCoP::Dataset::kMaxSize;
|
||||||
|
|
||||||
SuccessOrExit(error = Read(aIsActive ? kKeyActiveDataset : kKeyPendingDataset, aDataset.GetBytes(), length));
|
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);
|
aDataset.SetSize(length);
|
||||||
|
|
||||||
@@ -244,18 +244,18 @@ exit:
|
|||||||
return error;
|
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);
|
LogFailure(error, "deleting OperationalDataset", true);
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Settings::ReadNetworkInfo(NetworkInfo &aNetworkInfo) const
|
Error Settings::ReadNetworkInfo(NetworkInfo &aNetworkInfo) const
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
uint16_t length = sizeof(NetworkInfo);
|
uint16_t length = sizeof(NetworkInfo);
|
||||||
|
|
||||||
aNetworkInfo.Init();
|
aNetworkInfo.Init();
|
||||||
@@ -266,13 +266,13 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Settings::SaveNetworkInfo(const NetworkInfo &aNetworkInfo)
|
Error Settings::SaveNetworkInfo(const NetworkInfo &aNetworkInfo)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
NetworkInfo prevNetworkInfo;
|
NetworkInfo prevNetworkInfo;
|
||||||
uint16_t length = sizeof(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))
|
(prevNetworkInfo == aNetworkInfo))
|
||||||
{
|
{
|
||||||
LogNetworkInfo("Re-saved", aNetworkInfo);
|
LogNetworkInfo("Re-saved", aNetworkInfo);
|
||||||
@@ -287,9 +287,9 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Settings::DeleteNetworkInfo(void)
|
Error Settings::DeleteNetworkInfo(void)
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
SuccessOrExit(error = Delete(kKeyNetworkInfo));
|
SuccessOrExit(error = Delete(kKeyNetworkInfo));
|
||||||
otLogInfoCore("Non-volatile: Deleted NetworkInfo");
|
otLogInfoCore("Non-volatile: Deleted NetworkInfo");
|
||||||
@@ -299,9 +299,9 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Settings::ReadParentInfo(ParentInfo &aParentInfo) const
|
Error Settings::ReadParentInfo(ParentInfo &aParentInfo) const
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
uint16_t length = sizeof(ParentInfo);
|
uint16_t length = sizeof(ParentInfo);
|
||||||
|
|
||||||
aParentInfo.Init();
|
aParentInfo.Init();
|
||||||
@@ -312,13 +312,13 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Settings::SaveParentInfo(const ParentInfo &aParentInfo)
|
Error Settings::SaveParentInfo(const ParentInfo &aParentInfo)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
ParentInfo prevParentInfo;
|
ParentInfo prevParentInfo;
|
||||||
uint16_t length = sizeof(ParentInfo);
|
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))
|
(prevParentInfo == aParentInfo))
|
||||||
{
|
{
|
||||||
LogParentInfo("Re-saved", aParentInfo);
|
LogParentInfo("Re-saved", aParentInfo);
|
||||||
@@ -333,9 +333,9 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Settings::DeleteParentInfo(void)
|
Error Settings::DeleteParentInfo(void)
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
SuccessOrExit(error = Delete(kKeyParentInfo));
|
SuccessOrExit(error = Delete(kKeyParentInfo));
|
||||||
otLogInfoCore("Non-volatile: Deleted ParentInfo");
|
otLogInfoCore("Non-volatile: Deleted ParentInfo");
|
||||||
@@ -345,9 +345,9 @@ exit:
|
|||||||
return error;
|
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)));
|
SuccessOrExit(error = Add(kKeyChildInfo, &aChildInfo, sizeof(aChildInfo)));
|
||||||
LogChildInfo("Added", aChildInfo);
|
LogChildInfo("Added", aChildInfo);
|
||||||
@@ -357,9 +357,9 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Settings::DeleteAllChildInfo(void)
|
Error Settings::DeleteAllChildInfo(void)
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
SuccessOrExit(error = Delete(kKeyChildInfo));
|
SuccessOrExit(error = Delete(kKeyChildInfo));
|
||||||
otLogInfoCore("Non-volatile: Deleted all ChildInfo");
|
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));
|
SuccessOrExit(error = Get<SettingsDriver>().Delete(kKeyChildInfo, mIndex));
|
||||||
LogChildInfo("Removed", mChildInfo);
|
LogChildInfo("Removed", mChildInfo);
|
||||||
|
|
||||||
@@ -402,7 +402,7 @@ exit:
|
|||||||
void Settings::ChildInfoIterator::Read(void)
|
void Settings::ChildInfoIterator::Read(void)
|
||||||
{
|
{
|
||||||
uint16_t length = sizeof(ChildInfo);
|
uint16_t length = sizeof(ChildInfo);
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
mChildInfo.Init();
|
mChildInfo.Init();
|
||||||
SuccessOrExit(
|
SuccessOrExit(
|
||||||
@@ -410,13 +410,13 @@ void Settings::ChildInfoIterator::Read(void)
|
|||||||
LogChildInfo("Read", mChildInfo);
|
LogChildInfo("Read", mChildInfo);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
mIsDone = (error != OT_ERROR_NONE);
|
mIsDone = (error != kErrorNone);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_DUA_ENABLE
|
#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);
|
uint16_t length = sizeof(DadInfo);
|
||||||
|
|
||||||
aDadInfo.Init();
|
aDadInfo.Init();
|
||||||
@@ -427,13 +427,13 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Settings::SaveDadInfo(const DadInfo &aDadInfo)
|
Error Settings::SaveDadInfo(const DadInfo &aDadInfo)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
DadInfo prevDadInfo;
|
DadInfo prevDadInfo;
|
||||||
uint16_t length = sizeof(DadInfo);
|
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))
|
(prevDadInfo == aDadInfo))
|
||||||
{
|
{
|
||||||
LogDadInfo("Re-saved", aDadInfo);
|
LogDadInfo("Re-saved", aDadInfo);
|
||||||
@@ -448,9 +448,9 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Settings::DeleteDadInfo(void)
|
Error Settings::DeleteDadInfo(void)
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
SuccessOrExit(error = Delete(kKeyDadInfo));
|
SuccessOrExit(error = Delete(kKeyDadInfo));
|
||||||
otLogInfoCore("Non-volatile: Deleted DadInfo");
|
otLogInfoCore("Non-volatile: Deleted DadInfo");
|
||||||
@@ -462,13 +462,13 @@ exit:
|
|||||||
#endif // OPENTHREAD_CONFIG_DUA_ENABLE
|
#endif // OPENTHREAD_CONFIG_DUA_ENABLE
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_BORDER_ROUTING_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;
|
Ip6::Prefix prevOmrPrefix;
|
||||||
uint16_t length = sizeof(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))
|
(prevOmrPrefix == aOmrPrefix))
|
||||||
{
|
{
|
||||||
LogPrefix("Re-saved", "OMR prefix", aOmrPrefix);
|
LogPrefix("Re-saved", "OMR prefix", aOmrPrefix);
|
||||||
@@ -483,9 +483,9 @@ exit:
|
|||||||
return error;
|
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);
|
uint16_t length = sizeof(aOmrPrefix);
|
||||||
|
|
||||||
aOmrPrefix.Clear();
|
aOmrPrefix.Clear();
|
||||||
@@ -496,13 +496,13 @@ exit:
|
|||||||
return error;
|
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;
|
Ip6::Prefix prevOnLinkPrefix;
|
||||||
uint16_t length = sizeof(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))
|
(prevOnLinkPrefix == aOnLinkPrefix))
|
||||||
{
|
{
|
||||||
LogPrefix("Re-saved", "on-link prefix", aOnLinkPrefix);
|
LogPrefix("Re-saved", "on-link prefix", aOnLinkPrefix);
|
||||||
@@ -517,9 +517,9 @@ exit:
|
|||||||
return error;
|
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);
|
uint16_t length = sizeof(aOnLinkPrefix);
|
||||||
|
|
||||||
aOnLinkPrefix.Clear();
|
aOnLinkPrefix.Clear();
|
||||||
@@ -533,9 +533,9 @@ exit:
|
|||||||
|
|
||||||
#if OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE
|
#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()));
|
SuccessOrExit(error = Save(kKeySrpEcdsaKey, aKeyPair.GetDerBytes(), aKeyPair.GetDerLength()));
|
||||||
otLogInfoCore("Non-volatile: Saved SRP key");
|
otLogInfoCore("Non-volatile: Saved SRP key");
|
||||||
@@ -545,13 +545,13 @@ exit:
|
|||||||
return error;
|
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;
|
uint16_t length = Crypto::Ecdsa::P256::KeyPair::kMaxDerSize;
|
||||||
|
|
||||||
SuccessOrExit(error = Read(kKeySrpEcdsaKey, aKeyPair.GetDerBytes(), length));
|
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));
|
aKeyPair.SetDerLength(static_cast<uint8_t>(length));
|
||||||
otLogInfoCore("Non-volatile: Read SRP key");
|
otLogInfoCore("Non-volatile: Read SRP key");
|
||||||
|
|
||||||
@@ -559,9 +559,9 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Settings::DeleteSrpKey(void)
|
Error Settings::DeleteSrpKey(void)
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
SuccessOrExit(error = Delete(kKeySrpEcdsaKey));
|
SuccessOrExit(error = Delete(kKeySrpEcdsaKey));
|
||||||
otLogInfoCore("Non-volatile: Deleted SRP key");
|
otLogInfoCore("Non-volatile: Deleted SRP key");
|
||||||
@@ -573,22 +573,22 @@ exit:
|
|||||||
|
|
||||||
#endif // OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE
|
#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);
|
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);
|
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);
|
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);
|
return Get<SettingsDriver>().Delete(aKey, -1);
|
||||||
}
|
}
|
||||||
|
|||||||
+102
-102
@@ -96,11 +96,11 @@ public:
|
|||||||
* MUST NOT be nullptr if @p aValueLength is non-zero.
|
* 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.
|
* @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 kErrorNone The value was added.
|
||||||
* @retval OT_ERROR_NO_BUFS Not enough space to store the value.
|
* @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.
|
* This method removes a value from @p aKey.
|
||||||
@@ -109,11 +109,11 @@ public:
|
|||||||
* @param[in] aIndex The index of the value to be removed.
|
* @param[in] aIndex The index of the value to be removed.
|
||||||
* If set to -1, all values for @p aKey will 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 kErrorNone The given key and index was found and removed successfully.
|
||||||
* @retval OT_ERROR_NOT_FOUND The given key or index was not found.
|
* @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.
|
* This method fetches the value identified by @p aKey.
|
||||||
@@ -128,11 +128,11 @@ public:
|
|||||||
* At return, the actual length of the setting is written.
|
* At return, the actual length of the setting is written.
|
||||||
* May be nullptr if performing a presence check.
|
* May be nullptr if performing a presence check.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE The value was fetched successfully.
|
* @retval kErrorNone The value was fetched successfully.
|
||||||
* @retval OT_ERROR_NOT_FOUND The key was not found.
|
* @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.
|
* 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.
|
* 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.
|
* @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 kErrorNone The value was changed.
|
||||||
* @retval OT_ERROR_NO_BUFS Not enough space to store the value.
|
* @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.
|
* This method remves all values.
|
||||||
@@ -637,9 +637,9 @@ protected:
|
|||||||
#endif // (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_UTIL != 0)
|
#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)
|
#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
|
#else
|
||||||
void LogFailure(otError, const char *, bool) const {}
|
void LogFailure(Error, const char *, bool) const {}
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -691,11 +691,11 @@ public:
|
|||||||
* @param[in] aIsActive Indicates whether Dataset is active or pending.
|
* @param[in] aIsActive Indicates whether Dataset is active or pending.
|
||||||
* @param[in] aDataset A reference to a `Dataset` object to be saved.
|
* @param[in] aDataset A reference to a `Dataset` object to be saved.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully saved the Dataset.
|
* @retval kErrorNone Successfully saved the Dataset.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @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).
|
* 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[in] aIsActive Indicates whether Dataset is active or pending.
|
||||||
* @param[out] aDataset A reference to a `Dataset` object to output the read content.
|
* @param[out] aDataset A reference to a `Dataset` object to output the read content.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully read the Dataset.
|
* @retval kErrorNone Successfully read the Dataset.
|
||||||
* @retval OT_ERROR_NOT_FOUND No corresponding value in the setting store.
|
* @retval kErrorNotFound No corresponding value in the setting store.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @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.
|
* This method deletes the Operational Dataset (active/pending) from settings.
|
||||||
*
|
*
|
||||||
* @param[in] aIsActive Indicates whether Dataset is active or pending.
|
* @param[in] aIsActive Indicates whether Dataset is active or pending.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully deleted the Dataset.
|
* @retval kErrorNone Successfully deleted the Dataset.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @retval kErrorNotImplemented The platform does not implement settings functionality.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError DeleteOperationalDataset(bool aIsActive);
|
Error DeleteOperationalDataset(bool aIsActive);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method saves Network Info.
|
* This method saves Network Info.
|
||||||
*
|
*
|
||||||
* @param[in] aNetworkInfo A reference to a `NetworkInfo` structure to be saved.
|
* @param[in] aNetworkInfo A reference to a `NetworkInfo` structure to be saved.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully saved Network Info in settings.
|
* @retval kErrorNone Successfully saved Network Info in settings.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @retval kErrorNotImplemented The platform does not implement settings functionality.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError SaveNetworkInfo(const NetworkInfo &aNetworkInfo);
|
Error SaveNetworkInfo(const NetworkInfo &aNetworkInfo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method reads Network Info.
|
* This method reads Network Info.
|
||||||
*
|
*
|
||||||
* @param[out] aNetworkInfo A reference to a `NetworkInfo` structure to output the read content.
|
* @param[out] aNetworkInfo A reference to a `NetworkInfo` structure to output the read content.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully read the Network Info.
|
* @retval kErrorNone Successfully read the Network Info.
|
||||||
* @retval OT_ERROR_NOT_FOUND No corresponding value in the setting store.
|
* @retval kErrorNotFound No corresponding value in the setting store.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @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.
|
* This method deletes Network Info from settings.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully deleted the value.
|
* @retval kErrorNone Successfully deleted the value.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @retval kErrorNotImplemented The platform does not implement settings functionality.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError DeleteNetworkInfo(void);
|
Error DeleteNetworkInfo(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method saves Parent Info.
|
* This method saves Parent Info.
|
||||||
*
|
*
|
||||||
* @param[in] aParentInfo A reference to a `ParentInfo` structure to be saved.
|
* @param[in] aParentInfo A reference to a `ParentInfo` structure to be saved.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully saved Parent Info in settings.
|
* @retval kErrorNone Successfully saved Parent Info in settings.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @retval kErrorNotImplemented The platform does not implement settings functionality.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError SaveParentInfo(const ParentInfo &aParentInfo);
|
Error SaveParentInfo(const ParentInfo &aParentInfo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method reads Parent Info.
|
* This method reads Parent Info.
|
||||||
*
|
*
|
||||||
* @param[out] aParentInfo A reference to a `ParentInfo` structure to output the read content.
|
* @param[out] aParentInfo A reference to a `ParentInfo` structure to output the read content.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully read the Parent Info.
|
* @retval kErrorNone Successfully read the Parent Info.
|
||||||
* @retval OT_ERROR_NOT_FOUND No corresponding value in the setting store.
|
* @retval kErrorNotFound No corresponding value in the setting store.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @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.
|
* This method deletes Parent Info from settings.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully deleted the value.
|
* @retval kErrorNone Successfully deleted the value.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @retval kErrorNotImplemented The platform does not implement settings functionality.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError DeleteParentInfo(void);
|
Error DeleteParentInfo(void);
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE
|
#if OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE
|
||||||
|
|
||||||
@@ -792,11 +792,11 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[in] aKey The SLAAC IID secret key.
|
* @param[in] aKey The SLAAC IID secret key.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully saved the value.
|
* @retval kErrorNone Successfully saved the value.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @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));
|
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.
|
* @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 kErrorNone Successfully read the value.
|
||||||
* @retval OT_ERROR_NOT_FOUND No corresponding value in the setting store.
|
* @retval kErrorNotFound No corresponding value in the setting store.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @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);
|
uint16_t length = sizeof(aKey);
|
||||||
|
|
||||||
@@ -821,11 +821,11 @@ public:
|
|||||||
/**
|
/**
|
||||||
* This method deletes the SLAAC IID secret key value from settings.
|
* This method deletes the SLAAC IID secret key value from settings.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully deleted the value.
|
* @retval kErrorNone Successfully deleted the value.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @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
|
#endif // OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE
|
||||||
|
|
||||||
@@ -836,22 +836,22 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[in] aChildInfo A reference to a `ChildInfo` structure to be saved/added.
|
* @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 kErrorNone Successfully saved the Child Info in settings.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @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.
|
* This method deletes all Child Info entries from the settings.
|
||||||
*
|
*
|
||||||
* @note Child Info is a list-based settings property and can contain multiple entries.
|
* @note Child Info is a list-based settings property and can contain multiple entries.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully deleted the value.
|
* @retval kErrorNone Successfully deleted the value.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @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`.
|
* 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.
|
* This method deletes the current Child Info entry.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE The entry was deleted successfully.
|
* @retval kErrorNone The entry was deleted successfully.
|
||||||
* @retval OT_ERROR_INVALID_STATE The entry is not valid (iterator has reached end of list).
|
* @retval kErrorInvalidState The entry is not valid (iterator has reached end of list).
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @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
|
* 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.
|
* @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 kErrorNone Successfully saved duplicate address detection information in settings.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @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.
|
* This method reads duplicate address detection information.
|
||||||
*
|
*
|
||||||
* @param[out] aDadInfo A reference to a `DadInfo` structure to output the read content.
|
* @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 kErrorNone Successfully read the duplicate address detection information.
|
||||||
* @retval OT_ERROR_NOT_FOUND No corresponding value in the setting store.
|
* @retval kErrorNotFound No corresponding value in the setting store.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @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.
|
* This method deletes duplicate address detection information from settings.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully deleted the value.
|
* @retval kErrorNone Successfully deleted the value.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @retval kErrorNotImplemented The platform does not implement settings functionality.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError DeleteDadInfo(void);
|
Error DeleteDadInfo(void);
|
||||||
|
|
||||||
#endif // OPENTHREAD_CONFIG_DUA_ENABLE
|
#endif // OPENTHREAD_CONFIG_DUA_ENABLE
|
||||||
|
|
||||||
@@ -1029,46 +1029,46 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[in] aOmrPrefix An OMR prefix to be saved.
|
* @param[in] aOmrPrefix An OMR prefix to be saved.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully saved the OMR prefix in settings.
|
* @retval kErrorNone Successfully saved the OMR prefix in settings.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @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.
|
* This method reads OMR prefix.
|
||||||
*
|
*
|
||||||
* @param[out] aOmrPrefix A reference to a `Ip6::Prefix` structure to output the 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 kErrorNone Successfully read the OMR prefix.
|
||||||
* @retval OT_ERROR_NOT_FOUND No corresponding value in the setting store.
|
* @retval kErrorNotFound No corresponding value in the setting store.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @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.
|
* This method saves on-link prefix.
|
||||||
*
|
*
|
||||||
* @param[in] aOnLinkPrefix An on-link prefix to be saved.
|
* @param[in] aOnLinkPrefix An on-link prefix to be saved.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully saved the on-link prefix in settings.
|
* @retval kErrorNone Successfully saved the on-link prefix in settings.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @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.
|
* This method reads on-link prefix.
|
||||||
*
|
*
|
||||||
* @param[out] aOnLinkPrefix A reference to a `Ip6::Prefix` structure to output the 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 kErrorNone Successfully read the on-link prefix.
|
||||||
* @retval OT_ERROR_NOT_FOUND No corresponding value in the setting store.
|
* @retval kErrorNotFound No corresponding value in the setting store.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @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
|
#endif // OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_SRP_CLIENT_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.
|
* @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 kErrorNone Successfully saved key-pair information in settings.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @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.
|
* This method reads SRP client ECDSA key pair.
|
||||||
*
|
*
|
||||||
* @param[out] aKeyPair A reference to a ECDA `KeyPair` to output the read content.
|
* @param[out] aKeyPair A reference to a ECDA `KeyPair` to output the read content.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully read key-pair information.
|
* @retval kErrorNone Successfully read key-pair information.
|
||||||
* @retval OT_ERROR_NOT_FOUND No corresponding value in the setting store.
|
* @retval kErrorNotFound No corresponding value in the setting store.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @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.
|
* This method deletes SRP client ECDSA key pair from settings.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully deleted the value.
|
* @retval kErrorNone Successfully deleted the value.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @retval kErrorNotImplemented The platform does not implement settings functionality.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError DeleteSrpKey(void);
|
Error DeleteSrpKey(void);
|
||||||
#endif // OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE
|
#endif // OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -1118,10 +1118,10 @@ private:
|
|||||||
ChildInfoIterator end(void) { return ChildInfoIterator(GetInstance(), ChildInfoIterator::kEndIterator); }
|
ChildInfoIterator end(void) { return ChildInfoIterator(GetInstance(), ChildInfoIterator::kEndIterator); }
|
||||||
};
|
};
|
||||||
|
|
||||||
otError Read(Key aKey, void *aBuffer, uint16_t &aSize) const;
|
Error Read(Key aKey, void *aBuffer, uint16_t &aSize) const;
|
||||||
otError Save(Key aKey, const void *aValue, uint16_t aSize);
|
Error Save(Key aKey, const void *aValue, uint16_t aSize);
|
||||||
otError Add(Key aKey, const void *aValue, uint16_t aSize);
|
Error Add(Key aKey, const void *aValue, uint16_t aSize);
|
||||||
otError Delete(Key aKey);
|
Error Delete(Key aKey);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ot
|
} // namespace ot
|
||||||
|
|||||||
@@ -65,10 +65,10 @@ const char *StringFind(const char *aString, char aChar)
|
|||||||
return ret;
|
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;
|
Error error = kErrorNone;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
len = vsnprintf(aBuffer + aLength, aSize - aLength, aFormat, aArgs);
|
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;
|
aLength = 0;
|
||||||
aBuffer[0] = 0;
|
aBuffer[0] = 0;
|
||||||
error = OT_ERROR_INVALID_ARGS;
|
error = kErrorInvalidArgs;
|
||||||
}
|
}
|
||||||
else if (len >= aSize - aLength)
|
else if (len >= aSize - aLength)
|
||||||
{
|
{
|
||||||
aLength = aSize - 1;
|
aLength = aSize - 1;
|
||||||
error = OT_ERROR_NO_BUFS;
|
error = kErrorNoBufs;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
+23
-24
@@ -40,9 +40,8 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <openthread/error.h>
|
|
||||||
|
|
||||||
#include "common/code_utils.hpp"
|
#include "common/code_utils.hpp"
|
||||||
|
#include "common/error.hpp"
|
||||||
|
|
||||||
namespace ot {
|
namespace ot {
|
||||||
|
|
||||||
@@ -95,11 +94,11 @@ protected:
|
|||||||
* @param[in] aFormat A pointer to the format string.
|
* @param[in] aFormat A pointer to the format string.
|
||||||
* @param[in] aArgs Arguments for the format specification.
|
* @param[in] aArgs Arguments for the format specification.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Updated the string successfully.
|
* @retval kErrorNone Updated the string successfully.
|
||||||
* @retval OT_ERROR_NO_BUFS String could not fit in the storage.
|
* @retval kErrorNoBufs String could not fit in the storage.
|
||||||
* @retval OT_ERROR_INVALID_ARGS Arguments do not match the format string.
|
* @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] aFormat A pointer to the format string.
|
||||||
* @param[in] ... Arguments for the format specification.
|
* @param[in] ... Arguments for the format specification.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Updated the string successfully.
|
* @retval kErrorNone Updated the string successfully.
|
||||||
* @retval OT_ERROR_NO_BUFS String could not fit in the storage.
|
* @retval kErrorNoBufs String could not fit in the storage.
|
||||||
* @retval OT_ERROR_INVALID_ARGS Arguments do not match the format string.
|
* @retval kErrorInvalidArgs Arguments do not match the format string.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError Set(const char *aFormat, ...)
|
Error Set(const char *aFormat, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
va_start(args, aFormat);
|
va_start(args, aFormat);
|
||||||
mLength = 0;
|
mLength = 0;
|
||||||
@@ -206,15 +205,15 @@ public:
|
|||||||
* @param[in] aFormat A pointer to the format string.
|
* @param[in] aFormat A pointer to the format string.
|
||||||
* @param[in] ... Arguments for the format specification.
|
* @param[in] ... Arguments for the format specification.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Updated the string successfully.
|
* @retval kErrorNone Updated the string successfully.
|
||||||
* @retval OT_ERROR_NO_BUFS String could not fit in the storage.
|
* @retval kErrorNoBufs String could not fit in the storage.
|
||||||
* @retval OT_ERROR_INVALID_ARGS Arguments do not match the format string.
|
* @retval kErrorInvalidArgs Arguments do not match the format string.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError Append(const char *aFormat, ...)
|
Error Append(const char *aFormat, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
va_start(args, aFormat);
|
va_start(args, aFormat);
|
||||||
error = Write(mBuffer, kSize, mLength, aFormat, args);
|
error = Write(mBuffer, kSize, mLength, aFormat, args);
|
||||||
@@ -229,12 +228,12 @@ public:
|
|||||||
* @param[in] aFormat A pointer to the format string.
|
* @param[in] aFormat A pointer to the format string.
|
||||||
* @param[in] aArgs Arguments for the format specification (as `va_list`).
|
* @param[in] aArgs Arguments for the format specification (as `va_list`).
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Updated the string successfully.
|
* @retval kErrorNone Updated the string successfully.
|
||||||
* @retval OT_ERROR_NO_BUFS String could not fit in the storage.
|
* @retval kErrorNoBufs String could not fit in the storage.
|
||||||
* @retval OT_ERROR_INVALID_ARGS Arguments do not match the format string.
|
* @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.
|
* 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] aBytes A pointer to buffer containing the bytes to append.
|
||||||
* @param[in] aLength The length of @p aBytes buffer (in bytes).
|
* @param[in] aLength The length of @p aBytes buffer (in bytes).
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Updated the string successfully.
|
* @retval kErrorNone Updated the string successfully.
|
||||||
* @retval OT_ERROR_NO_BUFS String could not fit in the storage.
|
* @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--)
|
while (aLength--)
|
||||||
{
|
{
|
||||||
|
|||||||
+34
-34
@@ -55,14 +55,14 @@ const uint8_t *Tlv::GetValue(void) const
|
|||||||
return reinterpret_cast<const uint8_t *>(this) + (IsExtended() ? sizeof(ExtendedTlv) : sizeof(Tlv));
|
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()));
|
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 offset;
|
||||||
uint16_t size;
|
uint16_t size;
|
||||||
|
|
||||||
@@ -79,14 +79,14 @@ exit:
|
|||||||
return error;
|
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);
|
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 offset;
|
||||||
uint16_t size;
|
uint16_t size;
|
||||||
bool isExtendedTlv;
|
bool isExtendedTlv;
|
||||||
@@ -108,9 +108,9 @@ exit:
|
|||||||
return error;
|
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 offset = aMessage.GetOffset();
|
||||||
uint16_t remainingLen = aMessage.GetLength();
|
uint16_t remainingLen = aMessage.GetLength();
|
||||||
Tlv tlv;
|
Tlv tlv;
|
||||||
@@ -156,7 +156,7 @@ otError Tlv::Find(const Message &aMessage, uint8_t aType, uint16_t *aOffset, uin
|
|||||||
*aIsExtendedTlv = (tlv.mLength == kExtendedLength);
|
*aIsExtendedTlv = (tlv.mLength == kExtendedLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
error = OT_ERROR_NONE;
|
error = kErrorNone;
|
||||||
ExitNow();
|
ExitNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,9 +168,9 @@ exit:
|
|||||||
return error;
|
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)));
|
SuccessOrExit(error = ReadTlv(aMessage, aOffset, &aValue, sizeof(aValue)));
|
||||||
aValue = Encoding::BigEndian::HostSwap<UintType>(aValue);
|
aValue = Encoding::BigEndian::HostSwap<UintType>(aValue);
|
||||||
@@ -180,18 +180,18 @@ exit:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Explicit instantiations of `ReadUintTlv<>()`
|
// Explicit instantiations of `ReadUintTlv<>()`
|
||||||
template otError Tlv::ReadUintTlv<uint8_t>(const Message &aMessage, uint16_t aOffset, uint8_t &aValue);
|
template Error 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 Error 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<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;
|
Error error = kErrorNone;
|
||||||
Tlv tlv;
|
Tlv tlv;
|
||||||
|
|
||||||
SuccessOrExit(error = aMessage.Read(aOffset, tlv));
|
SuccessOrExit(error = aMessage.Read(aOffset, tlv));
|
||||||
VerifyOrExit(!tlv.IsExtended() && (tlv.GetLength() >= aMinLength), error = OT_ERROR_PARSE);
|
VerifyOrExit(!tlv.IsExtended() && (tlv.GetLength() >= aMinLength), error = kErrorParse);
|
||||||
VerifyOrExit(tlv.GetSize() + aOffset <= aMessage.GetLength(), error = OT_ERROR_PARSE);
|
VerifyOrExit(tlv.GetSize() + aOffset <= aMessage.GetLength(), error = kErrorParse);
|
||||||
|
|
||||||
aMessage.ReadBytes(aOffset + sizeof(Tlv), aValue, aMinLength);
|
aMessage.ReadBytes(aOffset + sizeof(Tlv), aValue, aMinLength);
|
||||||
|
|
||||||
@@ -199,9 +199,9 @@ exit:
|
|||||||
return error;
|
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;
|
uint16_t offset;
|
||||||
|
|
||||||
SuccessOrExit(error = FindTlvOffset(aMessage, aType, offset));
|
SuccessOrExit(error = FindTlvOffset(aMessage, aType, offset));
|
||||||
@@ -212,25 +212,25 @@ exit:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Explicit instantiations of `FindUintTlv<>()`
|
// Explicit instantiations of `FindUintTlv<>()`
|
||||||
template otError Tlv::FindUintTlv<uint8_t>(const Message &aMessage, uint8_t aType, uint8_t &aValue);
|
template Error 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 Error 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<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 offset;
|
||||||
uint16_t length;
|
uint16_t length;
|
||||||
|
|
||||||
SuccessOrExit(error = FindTlvValueOffset(aMessage, aType, offset, 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);
|
aMessage.ReadBytes(offset, aValue, aLength);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return error;
|
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);
|
UintType value = Encoding::BigEndian::HostSwap<UintType>(aValue);
|
||||||
|
|
||||||
@@ -238,14 +238,14 @@ template <typename UintType> otError Tlv::AppendUintTlv(Message &aMessage, uint8
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Explicit instantiations of `AppendUintTlv<>()`
|
// Explicit instantiations of `AppendUintTlv<>()`
|
||||||
template otError Tlv::AppendUintTlv<uint8_t>(Message &aMessage, uint8_t aType, uint8_t aValue);
|
template Error 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 Error 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<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;
|
Error error = kErrorNone;
|
||||||
Tlv tlv;
|
Tlv tlv;
|
||||||
|
|
||||||
OT_ASSERT(aLength <= Tlv::kBaseTlvMaxLength);
|
OT_ASSERT(aLength <= Tlv::kBaseTlvMaxLength);
|
||||||
|
|
||||||
|
|||||||
+57
-65
@@ -36,11 +36,11 @@
|
|||||||
|
|
||||||
#include "openthread-core-config.h"
|
#include "openthread-core-config.h"
|
||||||
|
|
||||||
#include <openthread/error.h>
|
|
||||||
#include <openthread/thread.h>
|
#include <openthread/thread.h>
|
||||||
#include <openthread/platform/toolchain.h>
|
#include <openthread/platform/toolchain.h>
|
||||||
|
|
||||||
#include "common/encoding.hpp"
|
#include "common/encoding.hpp"
|
||||||
|
#include "common/error.hpp"
|
||||||
#include "common/type_traits.hpp"
|
#include "common/type_traits.hpp"
|
||||||
|
|
||||||
namespace ot {
|
namespace ot {
|
||||||
@@ -171,11 +171,11 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[in] aMessage A reference to the message to append to.
|
* @param[in] aMessage A reference to the message to append to.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully appended the TLV to the message.
|
* @retval kErrorNone Successfully appended the TLV to the message.
|
||||||
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to grow 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.
|
* 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[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.
|
* @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 kErrorNone 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 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.
|
* 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[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.
|
* @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 kErrorNone 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 kErrorParse The TLV was not well-formed and could not be parsed.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
template <typename SimpleTlvType>
|
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));
|
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[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.
|
* @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 kErrorNone 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 kErrorParse The TLV was not well-formed and could not be parsed.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
template <typename UintTlvType>
|
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);
|
return ReadUintTlv(aMessage, aOffset, aValue);
|
||||||
}
|
}
|
||||||
@@ -239,11 +239,11 @@ public:
|
|||||||
* @param[in] aMaxSize Maximum number of bytes to read.
|
* @param[in] aMaxSize Maximum number of bytes to read.
|
||||||
* @param[out] aTlv A reference to the TLV that will be copied to.
|
* @param[out] aTlv A reference to the TLV that will be copied to.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully copied the TLV.
|
* @retval kErrorNone Successfully copied the TLV.
|
||||||
* @retval OT_ERROR_NOT_FOUND Could not find the TLV with Type @p aType.
|
* @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.
|
* 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[in] aMessage A reference to the message.
|
||||||
* @param[out] aTlv A reference to the TLV that will be copied to.
|
* @param[out] aTlv A reference to the TLV that will be copied to.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully copied the TLV.
|
* @retval kErrorNone Successfully copied the TLV.
|
||||||
* @retval OT_ERROR_NOT_FOUND Could not find the TLV with Type @p aType.
|
* @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);
|
return FindTlv(aMessage, TlvType::kType, sizeof(TlvType), aTlv);
|
||||||
}
|
}
|
||||||
@@ -273,11 +273,11 @@ public:
|
|||||||
* @param[in] aType The Type value to search for.
|
* @param[in] aType The Type value to search for.
|
||||||
* @param[out] aOffset A reference to the offset of the TLV.
|
* @param[out] aOffset A reference to the offset of the TLV.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully copied the TLV.
|
* @retval kErrorNone Successfully copied the TLV.
|
||||||
* @retval OT_ERROR_NOT_FOUND Could not find the TLV with Type @p aType.
|
* @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.
|
* 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] aValueOffset The offset where the value starts.
|
||||||
* @param[out] aLength The length of the value.
|
* @param[out] aLength The length of the value.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully found the TLV.
|
* @retval kErrorNone Successfully found the TLV.
|
||||||
* @retval OT_ERROR_NOT_FOUND Could not find the TLV with Type @p aType.
|
* @retval kErrorNotFound Could not find the TLV with Type @p aType.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static otError FindTlvValueOffset(const Message &aMessage,
|
static Error FindTlvValueOffset(const Message &aMessage, uint8_t aType, uint16_t &aValueOffset, uint16_t &aLength);
|
||||||
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
|
* 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.
|
* 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,
|
* 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
|
* 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.
|
* 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[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.
|
* @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 kErrorNone 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 kErrorNotFound 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 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);
|
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.
|
* 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
|
* 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
|
* 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.
|
* `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[in] aType The TLV type to search for.
|
||||||
* @param[out] aValue A reference to the value object to output the read value.
|
* @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 kErrorNone 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 kErrorNotFound 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 kErrorParse TLV was found but it was not well-formed and could not be parsed.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
template <typename SimpleTlvType>
|
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));
|
return FindTlv(aMessage, SimpleTlvType::kType, &aValue, sizeof(aValue));
|
||||||
}
|
}
|
||||||
@@ -357,20 +354,20 @@ public:
|
|||||||
* into a given `uint` reference variable.
|
* 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
|
* 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`)
|
* @tparam UintTlvType The simple TLV type to find (must be a sub-class of `UintTlvInfo`)
|
||||||
*
|
*
|
||||||
* @param[in] aMessage A reference to the message.
|
* @param[in] aMessage A reference to the message.
|
||||||
* @param[out] aValue A reference to an unsigned int value to output the TLV's value.
|
* @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 kErrorNone 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 kErrorNotFound 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 kErrorParse TLV was found but it was not well-formed and could not be parsed.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
template <typename UintTlvType>
|
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);
|
return FindUintTlv(aMessage, UintTlvType::kType, aValue);
|
||||||
}
|
}
|
||||||
@@ -386,11 +383,11 @@ public:
|
|||||||
* @param[in] aValue A buffer containing the TLV value.
|
* @param[in] aValue A buffer containing the TLV value.
|
||||||
* @param[in] aLength The value length (in bytes).
|
* @param[in] aLength The value length (in bytes).
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully appended the TLV to the message.
|
* @retval kErrorNone Successfully appended the TLV to the message.
|
||||||
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to grow 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);
|
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] aMessage A reference to the message to append to.
|
||||||
* @param[in] aValue A reference to the object containing TLV's value.
|
* @param[in] aValue A reference to the object containing TLV's value.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully appended the TLV to the message.
|
* @retval kErrorNone Successfully appended the TLV to the message.
|
||||||
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to grow the message.
|
* @retval kErrorNoBufs Insufficient available buffers to grow the message.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
template <typename SimpleTlvType>
|
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));
|
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] aMessage A reference to the message to append to.
|
||||||
* @param[in] aValue An unsigned int value to use as TLV's value.
|
* @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 kErrorNone Successfully appended the TLV to the message.
|
||||||
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to grow 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);
|
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] 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.
|
* @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 kErrorNone Successfully found the TLV.
|
||||||
* @retval OT_ERROR_NOT_FOUND Could not find the TLV with Type @p aType.
|
* @retval kErrorNotFound Could not find the TLV with Type @p aType.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static otError Find(const Message &aMessage,
|
static Error Find(const Message &aMessage, uint8_t aType, uint16_t *aOffset, uint16_t *aSize, bool *aIsExtendedTlv);
|
||||||
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 Error 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);
|
static Error AppendTlv(Message &aMessage, uint8_t aType, const void *aValue, uint8_t aLength);
|
||||||
template <typename UintType>
|
template <typename UintType> static Error ReadUintTlv(const Message &aMessage, uint16_t aOffset, UintType &aValue);
|
||||||
static otError 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 otError FindUintTlv(const Message &aMessage, uint8_t aType, UintType &aValue);
|
template <typename UintType> static Error AppendUintTlv(Message &aMessage, uint8_t aType, UintType aValue);
|
||||||
template <typename UintType> static otError AppendUintTlv(Message &aMessage, uint8_t aType, UintType aValue);
|
|
||||||
|
|
||||||
uint8_t mType;
|
uint8_t mType;
|
||||||
uint8_t mLength;
|
uint8_t mLength;
|
||||||
|
|||||||
@@ -38,8 +38,7 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <openthread/error.h>
|
#include "common/error.hpp"
|
||||||
|
|
||||||
#include "crypto/aes_ecb.hpp"
|
#include "crypto/aes_ecb.hpp"
|
||||||
#include "mac/mac_types.hpp"
|
#include "mac/mac_types.hpp"
|
||||||
|
|
||||||
|
|||||||
+27
-27
@@ -50,7 +50,7 @@ namespace Ecdsa {
|
|||||||
|
|
||||||
#if OPENTHREAD_CONFIG_ECDSA_ENABLE
|
#if OPENTHREAD_CONFIG_ECDSA_ENABLE
|
||||||
|
|
||||||
otError P256::KeyPair::Generate(void)
|
Error P256::KeyPair::Generate(void)
|
||||||
{
|
{
|
||||||
mbedtls_pk_context pk;
|
mbedtls_pk_context pk;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -74,26 +74,26 @@ otError P256::KeyPair::Generate(void)
|
|||||||
exit:
|
exit:
|
||||||
mbedtls_pk_free(&pk);
|
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_context *pk = reinterpret_cast<mbedtls_pk_context *>(aContext);
|
||||||
|
|
||||||
mbedtls_pk_init(pk);
|
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_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 = OT_ERROR_PARSE);
|
VerifyOrExit(mbedtls_pk_parse_key(pk, mDerBytes, mDerLength, nullptr, 0) == 0, error = kErrorParse);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return error;
|
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_pk_context pk;
|
||||||
mbedtls_ecp_keypair *keyPair;
|
mbedtls_ecp_keypair *keyPair;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -113,9 +113,9 @@ exit:
|
|||||||
return error;
|
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_pk_context pk;
|
||||||
mbedtls_ecp_keypair * keypair;
|
mbedtls_ecp_keypair * keypair;
|
||||||
mbedtls_ecdsa_context ecdsa;
|
mbedtls_ecdsa_context ecdsa;
|
||||||
@@ -155,9 +155,9 @@ exit:
|
|||||||
return error;
|
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_ecdsa_context ecdsa;
|
||||||
mbedtls_mpi r;
|
mbedtls_mpi r;
|
||||||
mbedtls_mpi s;
|
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));
|
VerifyOrExit(ret == 0, error = MbedTls::MapError(ret));
|
||||||
|
|
||||||
ret = mbedtls_ecdsa_verify(&ecdsa.grp, aHash.GetBytes(), Sha256::Hash::kSize, &ecdsa.Q, &r, &s);
|
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:
|
exit:
|
||||||
mbedtls_mpi_free(&s);
|
mbedtls_mpi_free(&s);
|
||||||
@@ -194,14 +194,14 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Sign(uint8_t * aOutput,
|
Error Sign(uint8_t * aOutput,
|
||||||
uint16_t & aOutputLength,
|
uint16_t & aOutputLength,
|
||||||
const uint8_t *aInputHash,
|
const uint8_t *aInputHash,
|
||||||
uint16_t aInputHashLength,
|
uint16_t aInputHashLength,
|
||||||
const uint8_t *aPrivateKey,
|
const uint8_t *aPrivateKey,
|
||||||
uint16_t aPrivateKeyLength)
|
uint16_t aPrivateKeyLength)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
mbedtls_ecdsa_context ctx;
|
mbedtls_ecdsa_context ctx;
|
||||||
mbedtls_pk_context pkCtx;
|
mbedtls_pk_context pkCtx;
|
||||||
mbedtls_ecp_keypair * keypair;
|
mbedtls_ecp_keypair * keypair;
|
||||||
@@ -215,26 +215,26 @@ otError Sign(uint8_t * aOutput,
|
|||||||
|
|
||||||
// Parse a private key in PEM format.
|
// Parse a private key in PEM format.
|
||||||
VerifyOrExit(mbedtls_pk_parse_key(&pkCtx, aPrivateKey, aPrivateKeyLength, nullptr, 0) == 0,
|
VerifyOrExit(mbedtls_pk_parse_key(&pkCtx, aPrivateKey, aPrivateKeyLength, nullptr, 0) == 0,
|
||||||
error = OT_ERROR_INVALID_ARGS);
|
error = kErrorInvalidArgs);
|
||||||
VerifyOrExit(mbedtls_pk_get_type(&pkCtx) == MBEDTLS_PK_ECKEY, error = OT_ERROR_INVALID_ARGS);
|
VerifyOrExit(mbedtls_pk_get_type(&pkCtx) == MBEDTLS_PK_ECKEY, error = kErrorInvalidArgs);
|
||||||
|
|
||||||
keypair = mbedtls_pk_ec(pkCtx);
|
keypair = mbedtls_pk_ec(pkCtx);
|
||||||
OT_ASSERT(keypair != nullptr);
|
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.
|
// Sign using ECDSA.
|
||||||
VerifyOrExit(mbedtls_ecdsa_sign(&ctx.grp, &rMpi, &sMpi, &ctx.d, aInputHash, aInputHashLength,
|
VerifyOrExit(mbedtls_ecdsa_sign(&ctx.grp, &rMpi, &sMpi, &ctx.d, aInputHash, aInputHashLength,
|
||||||
mbedtls_ctr_drbg_random, Random::Crypto::MbedTlsContextGet()) == 0,
|
mbedtls_ctr_drbg_random, Random::Crypto::MbedTlsContextGet()) == 0,
|
||||||
error = OT_ERROR_FAILED);
|
error = kErrorFailed);
|
||||||
VerifyOrExit(mbedtls_mpi_size(&rMpi) + mbedtls_mpi_size(&sMpi) <= aOutputLength, error = OT_ERROR_NO_BUFS);
|
VerifyOrExit(mbedtls_mpi_size(&rMpi) + mbedtls_mpi_size(&sMpi) <= aOutputLength, error = kErrorNoBufs);
|
||||||
|
|
||||||
// Concatenate the two octet sequences in the order R and then S.
|
// 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));
|
aOutputLength = static_cast<uint16_t>(mbedtls_mpi_size(&rMpi));
|
||||||
|
|
||||||
VerifyOrExit(mbedtls_mpi_write_binary(&sMpi, aOutput + aOutputLength, mbedtls_mpi_size(&sMpi)) == 0,
|
VerifyOrExit(mbedtls_mpi_write_binary(&sMpi, aOutput + aOutputLength, mbedtls_mpi_size(&sMpi)) == 0,
|
||||||
error = OT_ERROR_FAILED);
|
error = kErrorFailed);
|
||||||
aOutputLength += mbedtls_mpi_size(&sMpi);
|
aOutputLength += mbedtls_mpi_size(&sMpi);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
|||||||
+30
-31
@@ -39,8 +39,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <openthread/error.h>
|
#include "common/error.hpp"
|
||||||
|
|
||||||
#include "crypto/sha256.hpp"
|
#include "crypto/sha256.hpp"
|
||||||
|
|
||||||
namespace ot {
|
namespace ot {
|
||||||
@@ -146,24 +145,24 @@ public:
|
|||||||
/**
|
/**
|
||||||
* This method generates and populates the `KeyPair` with a new public/private keys.
|
* 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 kErrorNone A new key pair was generated successfully.
|
||||||
* @retval OT_ERROR_NO_BUFS Failed to allocate buffer for key generation.
|
* @retval kErrorNoBufs Failed to allocate buffer for key generation.
|
||||||
* @retval OT_ERROR_NOT_CAPABLE Feature not supported.
|
* @retval kErrorNotCapable Feature not supported.
|
||||||
* @retval OT_ERROR_FAILED Failed to generate key.
|
* @retval kErrorFailed Failed to generate key.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError Generate(void);
|
Error Generate(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method gets the associated public key from the `KeyPair`.
|
* This method gets the associated public key from the `KeyPair`.
|
||||||
*
|
*
|
||||||
* @param[out] aPublicKey A reference to a `PublicKey` to output the value.
|
* @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 kErrorNone 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 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.
|
* 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[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.
|
* @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 kErrorNone 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 kErrorParse The key-pair DER format could not be parsed (invalid format).
|
||||||
* @retval OT_ERROR_INVALID_ARGS The @p aHash is invalid.
|
* @retval kErrorInvalidArgs The @p aHash is invalid.
|
||||||
* @retval OT_ERROR_NO_BUFS Failed to allocate buffer for signature calculation.
|
* @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:
|
private:
|
||||||
otError Parse(void *aContext) const;
|
Error Parse(void *aContext) const;
|
||||||
|
|
||||||
uint8_t mDerBytes[kMaxDerSize];
|
uint8_t mDerBytes[kMaxDerSize];
|
||||||
uint8_t mDerLength;
|
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] aHash The SHA-256 hash value of a message to use for signature verification.
|
||||||
* @param[in] aSignature The signature value to verify.
|
* @param[in] aSignature The signature value to verify.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE The signature was verified successfully.
|
* @retval kErrorNone The signature was verified successfully.
|
||||||
* @retval OT_ERROR_SECURITY The signature is invalid.
|
* @retval kErrorSecurity The signature is invalid.
|
||||||
* @retval OT_ERROR_INVALID_ARGS The key or has is invalid.
|
* @retval kErrorInvalidArgs The key or has is invalid.
|
||||||
* @retval OT_ERROR_NO_BUFS Failed to allocate buffer for signature verification
|
* @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:
|
private:
|
||||||
uint8_t mData[kSize];
|
uint8_t mData[kSize];
|
||||||
@@ -280,18 +279,18 @@ public:
|
|||||||
* @param[in] aPrivateKey A private key in PEM format.
|
* @param[in] aPrivateKey A private key in PEM format.
|
||||||
* @param[in] aPrivateKeyLength The length of the @p aPrivateKey buffer.
|
* @param[in] aPrivateKeyLength The length of the @p aPrivateKey buffer.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE ECDSA sign has been created successfully.
|
* @retval kErrorNone ECDSA sign has been created successfully.
|
||||||
* @retval OT_ERROR_NO_BUFS Output buffer is too small.
|
* @retval kErrorNoBufs Output buffer is too small.
|
||||||
* @retval OT_ERROR_INVALID_ARGS Private key is not valid EC Private Key.
|
* @retval kErrorInvalidArgs Private key is not valid EC Private Key.
|
||||||
* @retval OT_ERROR_FAILED Error during signing.
|
* @retval kErrorFailed Error during signing.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError Sign(uint8_t * aOutput,
|
Error Sign(uint8_t * aOutput,
|
||||||
uint16_t & aOutputLength,
|
uint16_t & aOutputLength,
|
||||||
const uint8_t *aInputHash,
|
const uint8_t *aInputHash,
|
||||||
uint16_t aInputHashLength,
|
uint16_t aInputHashLength,
|
||||||
const uint8_t *aPrivateKey,
|
const uint8_t *aPrivateKey,
|
||||||
uint16_t aPrivateKeyLength);
|
uint16_t aPrivateKeyLength);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
+10
-10
@@ -36,7 +36,6 @@
|
|||||||
#include <mbedtls/ctr_drbg.h>
|
#include <mbedtls/ctr_drbg.h>
|
||||||
#include <mbedtls/debug.h>
|
#include <mbedtls/debug.h>
|
||||||
#include <mbedtls/entropy.h>
|
#include <mbedtls/entropy.h>
|
||||||
#include <mbedtls/error.h>
|
|
||||||
#include <mbedtls/platform.h>
|
#include <mbedtls/platform.h>
|
||||||
#include <mbedtls/threading.h>
|
#include <mbedtls/threading.h>
|
||||||
|
|
||||||
@@ -44,6 +43,7 @@
|
|||||||
#include <mbedtls/pem.h>
|
#include <mbedtls/pem.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "common/error.hpp"
|
||||||
#include "common/instance.hpp"
|
#include "common/instance.hpp"
|
||||||
|
|
||||||
namespace ot {
|
namespace ot {
|
||||||
@@ -60,9 +60,9 @@ MbedTls::MbedTls(void)
|
|||||||
#endif // OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT
|
#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)
|
switch (aMbedTlsError)
|
||||||
{
|
{
|
||||||
@@ -102,7 +102,7 @@ otError MbedTls::MapError(int aMbedTlsError)
|
|||||||
case MBEDTLS_ERR_SSL_BAD_INPUT_DATA:
|
case MBEDTLS_ERR_SSL_BAD_INPUT_DATA:
|
||||||
case MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG:
|
case MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG:
|
||||||
case MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG:
|
case MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG:
|
||||||
error = OT_ERROR_INVALID_ARGS;
|
error = kErrorInvalidArgs;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_ECDSA_ENABLE
|
#if OPENTHREAD_CONFIG_ECDSA_ENABLE
|
||||||
@@ -119,7 +119,7 @@ otError MbedTls::MapError(int aMbedTlsError)
|
|||||||
case MBEDTLS_ERR_SSL_ALLOC_FAILED:
|
case MBEDTLS_ERR_SSL_ALLOC_FAILED:
|
||||||
case MBEDTLS_ERR_SSL_WANT_WRITE:
|
case MBEDTLS_ERR_SSL_WANT_WRITE:
|
||||||
case MBEDTLS_ERR_ENTROPY_MAX_SOURCES:
|
case MBEDTLS_ERR_ENTROPY_MAX_SOURCES:
|
||||||
error = OT_ERROR_NO_BUFS;
|
error = kErrorNoBufs;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
|
#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_SSL_PEER_VERIFY_FAILED:
|
||||||
case MBEDTLS_ERR_THREADING_BAD_INPUT_DATA:
|
case MBEDTLS_ERR_THREADING_BAD_INPUT_DATA:
|
||||||
case MBEDTLS_ERR_THREADING_MUTEX_ERROR:
|
case MBEDTLS_ERR_THREADING_MUTEX_ERROR:
|
||||||
error = OT_ERROR_SECURITY;
|
error = kErrorSecurity;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
|
#ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
|
||||||
case MBEDTLS_ERR_X509_FATAL_ERROR:
|
case MBEDTLS_ERR_X509_FATAL_ERROR:
|
||||||
error = OT_ERROR_FAILED;
|
error = kErrorFailed;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case MBEDTLS_ERR_SSL_TIMEOUT:
|
case MBEDTLS_ERR_SSL_TIMEOUT:
|
||||||
case MBEDTLS_ERR_SSL_WANT_READ:
|
case MBEDTLS_ERR_SSL_WANT_READ:
|
||||||
error = OT_ERROR_BUSY;
|
error = kErrorBusy;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_ECDSA_ENABLE
|
#if OPENTHREAD_CONFIG_ECDSA_ENABLE
|
||||||
case MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE:
|
case MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE:
|
||||||
error = OT_ERROR_NOT_CAPABLE;
|
error = kErrorNotCapable;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (aMbedTlsError < 0)
|
if (aMbedTlsError < 0)
|
||||||
{
|
{
|
||||||
error = OT_ERROR_FAILED;
|
error = kErrorFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
|
|
||||||
#include <openthread/instance.h>
|
#include <openthread/instance.h>
|
||||||
|
|
||||||
|
#include "common/error.hpp"
|
||||||
#include "common/non_copyable.hpp"
|
#include "common/non_copyable.hpp"
|
||||||
|
|
||||||
namespace ot {
|
namespace ot {
|
||||||
@@ -68,10 +69,10 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[in] aMbedTlsError The mbed TLS error.
|
* @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);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ otError otPlatDiagProcess(otInstance *aInstance,
|
|||||||
OT_UNUSED_VARIABLE(aOutput);
|
OT_UNUSED_VARIABLE(aOutput);
|
||||||
OT_UNUSED_VARIABLE(aOutputMaxLen);
|
OT_UNUSED_VARIABLE(aOutputMaxLen);
|
||||||
|
|
||||||
return OT_ERROR_INVALID_COMMAND;
|
return ot::kErrorInvalidCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ot {
|
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;
|
Error error = kErrorNone;
|
||||||
long value;
|
long value;
|
||||||
|
|
||||||
VerifyOrExit(aArgsLength == 1, error = OT_ERROR_INVALID_ARGS);
|
VerifyOrExit(aArgsLength == 1, error = kErrorInvalidArgs);
|
||||||
|
|
||||||
SuccessOrExit(error = ParseLong(aArgs[0], 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);
|
||||||
|
|
||||||
otPlatDiagChannelSet(static_cast<uint8_t>(value));
|
otPlatDiagChannelSet(static_cast<uint8_t>(value));
|
||||||
|
|
||||||
@@ -96,12 +96,12 @@ exit:
|
|||||||
return error;
|
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;
|
||||||
long value;
|
long value;
|
||||||
|
|
||||||
VerifyOrExit(aArgsLength == 1, error = OT_ERROR_INVALID_ARGS);
|
VerifyOrExit(aArgsLength == 1, error = kErrorInvalidArgs);
|
||||||
|
|
||||||
SuccessOrExit(error = ParseLong(aArgs[0], value));
|
SuccessOrExit(error = ParseLong(aArgs[0], value));
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ exit:
|
|||||||
return error;
|
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(aArgsLength);
|
||||||
OT_UNUSED_VARIABLE(aArgs);
|
OT_UNUSED_VARIABLE(aArgs);
|
||||||
@@ -121,10 +121,10 @@ otError Diags::ProcessStart(uint8_t aArgsLength, char *aArgs[], char *aOutput, s
|
|||||||
|
|
||||||
otPlatDiagModeSet(true);
|
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(aArgsLength);
|
||||||
OT_UNUSED_VARIABLE(aArgs);
|
OT_UNUSED_VARIABLE(aArgs);
|
||||||
@@ -133,7 +133,7 @@ otError Diags::ProcessStop(uint8_t aArgsLength, char *aArgs[], char *aOutput, si
|
|||||||
|
|
||||||
otPlatDiagModeSet(false);
|
otPlatDiagModeSet(false);
|
||||||
|
|
||||||
return OT_ERROR_NONE;
|
return kErrorNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void otPlatDiagAlarmFired(otInstance *aInstance)
|
extern "C" void otPlatDiagAlarmFired(otInstance *aInstance)
|
||||||
@@ -162,11 +162,11 @@ Diags::Diags(Instance &aInstance)
|
|||||||
mStats.Clear();
|
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)
|
if (aArgsLength == 0)
|
||||||
{
|
{
|
||||||
@@ -177,7 +177,7 @@ otError Diags::ProcessChannel(uint8_t aArgsLength, char *aArgs[], char *aOutput,
|
|||||||
long value;
|
long value;
|
||||||
|
|
||||||
SuccessOrExit(error = ParseLong(aArgs[0], 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);
|
mChannel = static_cast<uint8_t>(value);
|
||||||
IgnoreError(Get<Radio>().Receive(mChannel));
|
IgnoreError(Get<Radio>().Receive(mChannel));
|
||||||
@@ -191,11 +191,11 @@ exit:
|
|||||||
return error;
|
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)
|
if (aArgsLength == 0)
|
||||||
{
|
{
|
||||||
@@ -219,12 +219,12 @@ exit:
|
|||||||
return error;
|
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(otPlatDiagModeGet(), error = kErrorInvalidState);
|
||||||
VerifyOrExit(aArgsLength > 0, error = OT_ERROR_INVALID_ARGS);
|
VerifyOrExit(aArgsLength > 0, error = kErrorInvalidArgs);
|
||||||
|
|
||||||
if (strcmp(aArgs[0], "stop") == 0)
|
if (strcmp(aArgs[0], "stop") == 0)
|
||||||
{
|
{
|
||||||
@@ -236,13 +236,13 @@ otError Diags::ProcessRepeat(uint8_t aArgsLength, char *aArgs[], char *aOutput,
|
|||||||
{
|
{
|
||||||
long value;
|
long value;
|
||||||
|
|
||||||
VerifyOrExit(aArgsLength == 2, error = OT_ERROR_INVALID_ARGS);
|
VerifyOrExit(aArgsLength == 2, error = kErrorInvalidArgs);
|
||||||
|
|
||||||
SuccessOrExit(error = ParseLong(aArgs[0], value));
|
SuccessOrExit(error = ParseLong(aArgs[0], value));
|
||||||
mTxPeriod = static_cast<uint32_t>(value);
|
mTxPeriod = static_cast<uint32_t>(value);
|
||||||
|
|
||||||
SuccessOrExit(error = ParseLong(aArgs[1], 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);
|
mTxLen = static_cast<uint8_t>(value);
|
||||||
|
|
||||||
mRepeatActive = true;
|
mRepeatActive = true;
|
||||||
@@ -257,19 +257,19 @@ exit:
|
|||||||
return error;
|
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;
|
Error error = kErrorNone;
|
||||||
long value;
|
long value;
|
||||||
|
|
||||||
VerifyOrExit(otPlatDiagModeGet(), error = OT_ERROR_INVALID_STATE);
|
VerifyOrExit(otPlatDiagModeGet(), error = kErrorInvalidState);
|
||||||
VerifyOrExit(aArgsLength == 2, error = OT_ERROR_INVALID_ARGS);
|
VerifyOrExit(aArgsLength == 2, error = kErrorInvalidArgs);
|
||||||
|
|
||||||
SuccessOrExit(error = ParseLong(aArgs[0], value));
|
SuccessOrExit(error = ParseLong(aArgs[0], value));
|
||||||
mTxPackets = static_cast<uint32_t>(value);
|
mTxPackets = static_cast<uint32_t>(value);
|
||||||
|
|
||||||
SuccessOrExit(error = ParseLong(aArgs[1], 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);
|
mTxLen = static_cast<uint8_t>(value);
|
||||||
|
|
||||||
snprintf(aOutput, aOutputMaxLen, "sending %#x packet(s), length %#x\r\nstatus 0x%02x\r\n",
|
snprintf(aOutput, aOutputMaxLen, "sending %#x packet(s), length %#x\r\nstatus 0x%02x\r\n",
|
||||||
@@ -281,14 +281,14 @@ exit:
|
|||||||
return error;
|
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(aArgsLength);
|
||||||
OT_UNUSED_VARIABLE(aArgs);
|
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);
|
otPlatDiagChannelSet(mChannel);
|
||||||
otPlatDiagTxPowerSet(mTxPower);
|
otPlatDiagTxPowerSet(mTxPower);
|
||||||
@@ -307,11 +307,11 @@ exit:
|
|||||||
return error;
|
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))
|
if ((aArgsLength == 1) && (strcmp(aArgs[0], "clear") == 0))
|
||||||
{
|
{
|
||||||
@@ -320,7 +320,7 @@ otError Diags::ProcessStats(uint8_t aArgsLength, char *aArgs[], char *aOutput, s
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
VerifyOrExit(aArgsLength == 0, error = OT_ERROR_INVALID_ARGS);
|
VerifyOrExit(aArgsLength == 0, error = kErrorInvalidArgs);
|
||||||
snprintf(aOutput, aOutputMaxLen,
|
snprintf(aOutput, aOutputMaxLen,
|
||||||
"received packets: %d\r\nsent packets: %d\r\n"
|
"received packets: %d\r\nsent packets: %d\r\n"
|
||||||
"first received packet: rssi=%d, lqi=%d\r\n"
|
"first received packet: rssi=%d, lqi=%d\r\n"
|
||||||
@@ -335,14 +335,14 @@ exit:
|
|||||||
return error;
|
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(aArgsLength);
|
||||||
OT_UNUSED_VARIABLE(aArgs);
|
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());
|
otPlatAlarmMilliStop(&GetInstance());
|
||||||
otPlatDiagModeSet(false);
|
otPlatDiagModeSet(false);
|
||||||
@@ -375,12 +375,12 @@ void Diags::TransmitPacket(void)
|
|||||||
IgnoreError(Get<Radio>().Transmit(*static_cast<Mac::TxFrame *>(mTxPacket)));
|
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(otPlatDiagModeGet(), error = kErrorInvalidState);
|
||||||
VerifyOrExit(aArgsLength > 0, error = OT_ERROR_INVALID_ARGS);
|
VerifyOrExit(aArgsLength > 0, error = kErrorInvalidArgs);
|
||||||
|
|
||||||
if (strcmp(aArgs[0], "sleep") == 0)
|
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();
|
otRadioState state = Get<Radio>().GetState();
|
||||||
|
|
||||||
error = OT_ERROR_NONE;
|
error = kErrorNone;
|
||||||
|
|
||||||
switch (state)
|
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
|
// for sensitivity test, only record the rssi and lqi for the first and last packet
|
||||||
if (mStats.mReceivedPackets == 0)
|
if (mStats.mReceivedPackets == 0)
|
||||||
@@ -474,9 +474,9 @@ void Diags::ReceiveDone(otRadioFrame *aFrame, otError aError)
|
|||||||
otPlatDiagRadioReceived(&GetInstance(), aFrame, 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++;
|
mStats.mSentPackets++;
|
||||||
|
|
||||||
@@ -499,19 +499,19 @@ exit:
|
|||||||
|
|
||||||
#endif // OPENTHREAD_RADIO
|
#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);
|
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;
|
char *endptr;
|
||||||
aLong = strtol(aString, &endptr, 0);
|
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)
|
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,
|
kMaxCommandBuffer = OPENTHREAD_CONFIG_DIAG_CMD_LINE_BUFFER_SIZE,
|
||||||
};
|
};
|
||||||
|
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
char buffer[kMaxCommandBuffer];
|
char buffer[kMaxCommandBuffer];
|
||||||
char * aArgsector[kMaxArgs];
|
char * aArgsector[kMaxArgs];
|
||||||
uint8_t argCount = 0;
|
uint8_t argCount = 0;
|
||||||
|
|
||||||
VerifyOrExit(StringLength(aString, kMaxCommandBuffer) < kMaxCommandBuffer, error = OT_ERROR_NO_BUFS);
|
VerifyOrExit(StringLength(aString, kMaxCommandBuffer) < kMaxCommandBuffer, error = kErrorNoBufs);
|
||||||
|
|
||||||
strcpy(buffer, aString);
|
strcpy(buffer, aString);
|
||||||
error = ot::Utils::CmdLineParser::ParseCmd(buffer, argCount, aArgsector, kMaxArgs);
|
error = ot::Utils::CmdLineParser::ParseCmd(buffer, argCount, aArgsector, kMaxArgs);
|
||||||
@@ -536,16 +536,16 @@ exit:
|
|||||||
|
|
||||||
switch (error)
|
switch (error)
|
||||||
{
|
{
|
||||||
case OT_ERROR_NONE:
|
case kErrorNone:
|
||||||
aOutput[0] = '\0'; // In case there is no output.
|
aOutput[0] = '\0'; // In case there is no output.
|
||||||
IgnoreError(ProcessCmd(argCount, &aArgsector[0], aOutput, aOutputMaxLen));
|
IgnoreError(ProcessCmd(argCount, &aArgsector[0], aOutput, aOutputMaxLen));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OT_ERROR_NO_BUFS:
|
case kErrorNoBufs:
|
||||||
snprintf(aOutput, aOutputMaxLen, "failed: command string too long\r\n");
|
snprintf(aOutput, aOutputMaxLen, "failed: command string too long\r\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OT_ERROR_INVALID_ARGS:
|
case kErrorInvalidArgs:
|
||||||
snprintf(aOutput, aOutputMaxLen, "failed: command string contains too many arguments\r\n");
|
snprintf(aOutput, aOutputMaxLen, "failed: command string contains too many arguments\r\n");
|
||||||
break;
|
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
|
// 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.
|
// 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:
|
exit:
|
||||||
// Add more platform specific diagnostics features here.
|
// 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]);
|
snprintf(aOutput, aOutputMaxLen, "diag feature '%s' is not supported\r\n", aArgs[0]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
|
|
||||||
#include <openthread/platform/radio.h>
|
#include <openthread/platform/radio.h>
|
||||||
|
|
||||||
|
#include "common/error.hpp"
|
||||||
#include "common/locator.hpp"
|
#include "common/locator.hpp"
|
||||||
#include "common/non_copyable.hpp"
|
#include "common/non_copyable.hpp"
|
||||||
|
|
||||||
@@ -77,12 +78,12 @@ public:
|
|||||||
* @param[out] aOutput The diagnostics execution result.
|
* @param[out] aOutput The diagnostics execution result.
|
||||||
* @param[in] aOutputMaxLen The output buffer size.
|
* @param[in] aOutputMaxLen The output buffer size.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_INVALID_ARGS The command is supported but invalid arguments provided.
|
* @retval kErrorInvalidArgs The command is supported but invalid arguments provided.
|
||||||
* @retval OT_ERROR_NONE The command is successfully process.
|
* @retval kErrorNone The command is successfully process.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The command is not supported.
|
* @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.
|
* 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.
|
* 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] 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,
|
* @param[in] aError kErrorNone when successfully received a frame,
|
||||||
* OT_ERROR_ABORT when reception was aborted and a frame was not received,
|
* kErrorAbort 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.
|
* 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.
|
* 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,
|
* @param[in] aError kErrorNone when the frame was transmitted,
|
||||||
* OT_ERROR_CHANNEL_ACCESS_FAILURE tx could not take place due to activity on channel,
|
* kErrorChannelAccessFailure tx could not take place due to activity on channel,
|
||||||
* OT_ERROR_ABORT when transmission was aborted for other reasons.
|
* kErrorAbort when transmission was aborted for other reasons.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void TransmitDone(otError aError);
|
void TransmitDone(Error aError);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Command
|
struct Command
|
||||||
{
|
{
|
||||||
const char *mName;
|
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
|
struct Stats
|
||||||
@@ -139,19 +140,19 @@ private:
|
|||||||
uint8_t mLastLqi;
|
uint8_t mLastLqi;
|
||||||
};
|
};
|
||||||
|
|
||||||
otError ProcessChannel(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
|
Error ProcessChannel(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
|
||||||
otError ProcessPower(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
|
Error ProcessPower(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
|
||||||
otError ProcessRadio(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
|
Error ProcessRadio(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
|
||||||
otError ProcessRepeat(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
|
Error ProcessRepeat(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
|
||||||
otError ProcessSend(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
|
Error ProcessSend(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
|
||||||
otError ProcessStart(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
|
Error ProcessStart(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
|
||||||
otError ProcessStats(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
|
Error ProcessStats(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen);
|
||||||
otError ProcessStop(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);
|
void TransmitPacket(void);
|
||||||
|
|
||||||
static void AppendErrorResult(otError aError, char *aOutput, size_t aOutputMaxLen);
|
static void AppendErrorResult(Error aError, char *aOutput, size_t aOutputMaxLen);
|
||||||
static otError ParseLong(char *aString, long &aLong);
|
static Error ParseLong(char *aString, long &aLong);
|
||||||
|
|
||||||
static const struct Command sCommands[];
|
static const struct Command sCommands[];
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ uint8_t ChannelMask::GetNumberOfChannels(void) const
|
|||||||
uint8_t num = 0;
|
uint8_t num = 0;
|
||||||
uint8_t channel = kChannelIteratorFirst;
|
uint8_t channel = kChannelIteratorFirst;
|
||||||
|
|
||||||
while (GetNextChannel(channel) == OT_ERROR_NONE)
|
while (GetNextChannel(channel) == kErrorNone)
|
||||||
{
|
{
|
||||||
num++;
|
num++;
|
||||||
}
|
}
|
||||||
@@ -52,9 +52,9 @@ uint8_t ChannelMask::GetNumberOfChannels(void) const
|
|||||||
return num;
|
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)
|
if (aChannel == kChannelIteratorFirst)
|
||||||
{
|
{
|
||||||
@@ -65,7 +65,7 @@ otError ChannelMask::GetNextChannel(uint8_t &aChannel) const
|
|||||||
{
|
{
|
||||||
if (ContainsChannel(aChannel))
|
if (ContainsChannel(aChannel))
|
||||||
{
|
{
|
||||||
ExitNow(error = OT_ERROR_NONE);
|
ExitNow(error = kErrorNone);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,18 +98,18 @@ ChannelMask::InfoString ChannelMask::ToString(void) const
|
|||||||
InfoString string;
|
InfoString string;
|
||||||
uint8_t channel = kChannelIteratorFirst;
|
uint8_t channel = kChannelIteratorFirst;
|
||||||
bool addComma = false;
|
bool addComma = false;
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
IgnoreError(string.Append("{"));
|
IgnoreError(string.Append("{"));
|
||||||
|
|
||||||
error = GetNextChannel(channel);
|
error = GetNextChannel(channel);
|
||||||
|
|
||||||
while (error == OT_ERROR_NONE)
|
while (error == kErrorNone)
|
||||||
{
|
{
|
||||||
uint8_t rangeStart = channel;
|
uint8_t rangeStart = channel;
|
||||||
uint8_t rangeEnd = channel;
|
uint8_t rangeEnd = channel;
|
||||||
|
|
||||||
while ((error = GetNextChannel(channel)) == OT_ERROR_NONE)
|
while ((error = GetNextChannel(channel)) == kErrorNone)
|
||||||
{
|
{
|
||||||
if (channel != rangeEnd + 1)
|
if (channel != rangeEnd + 1)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -201,11 +201,11 @@ public:
|
|||||||
* On entry it should contain the previous channel or `kChannelIteratorFirst`.
|
* On entry it should contain the previous channel or `kChannelIteratorFirst`.
|
||||||
* On exit it contains the next channel.
|
* On exit it contains the next channel.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Got the next channel, @p aChannel updated successfully.
|
* @retval kErrorNone 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 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.
|
* This method randomly chooses a channel from the channel mask.
|
||||||
|
|||||||
@@ -47,16 +47,16 @@ DataPollHandler::Callbacks::Callbacks(Instance &aInstance)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
inline otError DataPollHandler::Callbacks::PrepareFrameForChild(Mac::TxFrame &aFrame,
|
inline Error DataPollHandler::Callbacks::PrepareFrameForChild(Mac::TxFrame &aFrame,
|
||||||
FrameContext &aContext,
|
FrameContext &aContext,
|
||||||
Child & aChild)
|
Child & aChild)
|
||||||
{
|
{
|
||||||
return Get<IndirectSender>().PrepareFrameForChild(aFrame, aContext, aChild);
|
return Get<IndirectSender>().PrepareFrameForChild(aFrame, aContext, aChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void DataPollHandler::Callbacks::HandleSentFrameToChild(const Mac::TxFrame &aFrame,
|
inline void DataPollHandler::Callbacks::HandleSentFrameToChild(const Mac::TxFrame &aFrame,
|
||||||
const FrameContext &aContext,
|
const FrameContext &aContext,
|
||||||
otError aError,
|
Error aError,
|
||||||
Child & aChild)
|
Child & aChild)
|
||||||
{
|
{
|
||||||
Get<IndirectSender>().HandleSentFrameToChild(aFrame, aContext, aError, aChild);
|
Get<IndirectSender>().HandleSentFrameToChild(aFrame, aContext, aError, aChild);
|
||||||
@@ -183,7 +183,7 @@ Mac::TxFrame *DataPollHandler::HandleFrameRequest(Mac::TxFrames &aTxFrames)
|
|||||||
frame = &aTxFrames.GetTxFrame();
|
frame = &aTxFrames.GetTxFrame();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
VerifyOrExit(mCallbacks.PrepareFrameForChild(*frame, mFrameContext, *mIndirectTxChild) == OT_ERROR_NONE,
|
VerifyOrExit(mCallbacks.PrepareFrameForChild(*frame, mFrameContext, *mIndirectTxChild) == kErrorNone,
|
||||||
frame = nullptr);
|
frame = nullptr);
|
||||||
|
|
||||||
if (mIndirectTxChild->GetIndirectTxAttempts() > 0)
|
if (mIndirectTxChild->GetIndirectTxAttempts() > 0)
|
||||||
@@ -210,7 +210,7 @@ exit:
|
|||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataPollHandler::HandleSentFrame(const Mac::TxFrame &aFrame, otError aError)
|
void DataPollHandler::HandleSentFrame(const Mac::TxFrame &aFrame, Error aError)
|
||||||
{
|
{
|
||||||
Child *child = mIndirectTxChild;
|
Child *child = mIndirectTxChild;
|
||||||
|
|
||||||
@@ -223,7 +223,7 @@ exit:
|
|||||||
ProcessPendingPolls();
|
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())
|
if (aChild.IsFramePurgePending())
|
||||||
{
|
{
|
||||||
@@ -236,12 +236,12 @@ void DataPollHandler::HandleSentFrame(const Mac::TxFrame &aFrame, otError aError
|
|||||||
|
|
||||||
switch (aError)
|
switch (aError)
|
||||||
{
|
{
|
||||||
case OT_ERROR_NONE:
|
case kErrorNone:
|
||||||
aChild.ResetIndirectTxAttempts();
|
aChild.ResetIndirectTxAttempts();
|
||||||
aChild.SetFrameReplacePending(false);
|
aChild.SetFrameReplacePending(false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OT_ERROR_NO_ACK:
|
case kErrorNoAck:
|
||||||
aChild.IncrementIndirectTxAttempts();
|
aChild.IncrementIndirectTxAttempts();
|
||||||
|
|
||||||
otLogInfoMac("Indirect tx to child %04x failed, attempt %d/%d", aChild.GetRloc16(),
|
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;
|
OT_FALL_THROUGH;
|
||||||
|
|
||||||
case OT_ERROR_CHANNEL_ACCESS_FAILURE:
|
case kErrorChannelAccessFailure:
|
||||||
case OT_ERROR_ABORT:
|
case kErrorAbort:
|
||||||
|
|
||||||
if (aChild.IsFrameReplacePending())
|
if (aChild.IsFrameReplacePending())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -171,27 +171,27 @@ public:
|
|||||||
* @param[out] aContext A reference to a `FrameContext` where the context for the new frame would be placed.
|
* @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.
|
* @param[in] aChild The child for which to prepare the frame.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Frame was prepared successfully.
|
* @retval kErrorNone Frame was prepared successfully.
|
||||||
* @retval OT_ERROR_ABORT Indirect transmission to child should be aborted (no frame for the child).
|
* @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.
|
* This callback method notifies the end of indirect frame transmission to a child.
|
||||||
*
|
*
|
||||||
* @param[in] aFrame The transmitted frame.
|
* @param[in] aFrame The transmitted frame.
|
||||||
* @param[in] aContext The context associated with the frame when it was prepared.
|
* @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,
|
* @param[in] aError kErrorNone when the frame was transmitted successfully,
|
||||||
* OT_ERROR_NO_ACK when the frame was transmitted but no ACK was received,
|
* kErrorNoAck when the frame was transmitted but no ACK was received,
|
||||||
* OT_ERROR_CHANNEL_ACCESS_FAILURE tx failed due to activity on the channel,
|
* kErrorChannelAccessFailure tx failed due to activity on the channel,
|
||||||
* OT_ERROR_ABORT when transmission was aborted for other reasons.
|
* kErrorAbort when transmission was aborted for other reasons.
|
||||||
* @param[in] aChild The child to which the frame was transmitted.
|
* @param[in] aChild The child to which the frame was transmitted.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void HandleSentFrameToChild(const Mac::TxFrame &aFrame,
|
void HandleSentFrameToChild(const Mac::TxFrame &aFrame,
|
||||||
const FrameContext &aContext,
|
const FrameContext &aContext,
|
||||||
otError aError,
|
Error aError,
|
||||||
Child & aChild);
|
Child & aChild);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -272,9 +272,9 @@ private:
|
|||||||
// Callbacks from MAC
|
// Callbacks from MAC
|
||||||
void HandleDataPoll(Mac::RxFrame &aFrame);
|
void HandleDataPoll(Mac::RxFrame &aFrame);
|
||||||
Mac::TxFrame *HandleFrameRequest(Mac::TxFrames &aTxFrames);
|
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);
|
void ProcessPendingPolls(void);
|
||||||
|
|
||||||
// In the current implementation of `DataPollHandler`, we can have a
|
// In the current implementation of `DataPollHandler`, we can have a
|
||||||
|
|||||||
@@ -94,14 +94,14 @@ void DataPollSender::StopPolling(void)
|
|||||||
mEnabled = false;
|
mEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError DataPollSender::SendDataPoll(void)
|
Error DataPollSender::SendDataPoll(void)
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
VerifyOrExit(mEnabled, error = OT_ERROR_INVALID_STATE);
|
VerifyOrExit(mEnabled, error = kErrorInvalidState);
|
||||||
VerifyOrExit(!Get<Mac::Mac>().GetRxOnWhenIdle(), error = OT_ERROR_INVALID_STATE);
|
VerifyOrExit(!Get<Mac::Mac>().GetRxOnWhenIdle(), error = kErrorInvalidState);
|
||||||
|
|
||||||
VerifyOrExit(GetParent().IsStateValidOrRestoring(), error = OT_ERROR_INVALID_STATE);
|
VerifyOrExit(GetParent().IsStateValidOrRestoring(), error = kErrorInvalidState);
|
||||||
|
|
||||||
mTimer.Stop();
|
mTimer.Stop();
|
||||||
|
|
||||||
@@ -111,23 +111,23 @@ exit:
|
|||||||
|
|
||||||
switch (error)
|
switch (error)
|
||||||
{
|
{
|
||||||
case OT_ERROR_NONE:
|
case kErrorNone:
|
||||||
otLogDebgMac("Sending data poll");
|
otLogDebgMac("Sending data poll");
|
||||||
ScheduleNextPoll(kUsePreviousPollPeriod);
|
ScheduleNextPoll(kUsePreviousPollPeriod);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OT_ERROR_INVALID_STATE:
|
case kErrorInvalidState:
|
||||||
otLogWarnMac("Data poll tx requested while data polling was not enabled!");
|
otLogWarnMac("Data poll tx requested while data polling was not enabled!");
|
||||||
StopPolling();
|
StopPolling();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OT_ERROR_ALREADY:
|
case kErrorAlready:
|
||||||
otLogDebgMac("Data poll tx requested when a previous data request still in send queue.");
|
otLogDebgMac("Data poll tx requested when a previous data request still in send queue.");
|
||||||
ScheduleNextPoll(kUsePreviousPollPeriod);
|
ScheduleNextPoll(kUsePreviousPollPeriod);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
otLogWarnMac("Unexpected error %s requesting data poll", otThreadErrorToString(error));
|
otLogWarnMac("Unexpected error %s requesting data poll", ErrorToString(error));
|
||||||
ScheduleNextPoll(kRecalculatePollPeriod);
|
ScheduleNextPoll(kRecalculatePollPeriod);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -136,15 +136,15 @@ exit:
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_MULTI_RADIO
|
#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
|
#else
|
||||||
otError DataPollSender::GetPollDestinationAddress(Mac::Address &aDest) const
|
Error DataPollSender::GetPollDestinationAddress(Mac::Address &aDest) const
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
const Neighbor &parent = GetParent();
|
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).
|
// Use extended address attaching to a new parent (i.e. parent is the parent candidate).
|
||||||
if ((Get<Mac::Mac>().GetShortAddress() == Mac::kShortAddrInvalid) ||
|
if ((Get<Mac::Mac>().GetShortAddress() == Mac::kShortAddrInvalid) ||
|
||||||
@@ -165,13 +165,13 @@ exit:
|
|||||||
return error;
|
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)
|
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.
|
// Clipped by the maximal value.
|
||||||
if (aPeriod > kMaxExternalPeriod)
|
if (aPeriod > kMaxExternalPeriod)
|
||||||
@@ -206,7 +206,7 @@ uint32_t DataPollSender::GetKeepAlivePollPeriod(void) const
|
|||||||
return period;
|
return period;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataPollSender::HandlePollSent(Mac::TxFrame &aFrame, otError aError)
|
void DataPollSender::HandlePollSent(Mac::TxFrame &aFrame, Error aError)
|
||||||
{
|
{
|
||||||
Mac::Address macDest;
|
Mac::Address macDest;
|
||||||
bool shouldRecalculatePollPeriod = false;
|
bool shouldRecalculatePollPeriod = false;
|
||||||
@@ -228,7 +228,7 @@ void DataPollSender::HandlePollSent(Mac::TxFrame &aFrame, otError aError)
|
|||||||
|
|
||||||
switch (aError)
|
switch (aError)
|
||||||
{
|
{
|
||||||
case OT_ERROR_NONE:
|
case kErrorNone:
|
||||||
|
|
||||||
if (mRemainingFastPolls != 0)
|
if (mRemainingFastPolls != 0)
|
||||||
{
|
{
|
||||||
@@ -250,8 +250,8 @@ void DataPollSender::HandlePollSent(Mac::TxFrame &aFrame, otError aError)
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OT_ERROR_CHANNEL_ACCESS_FAILURE:
|
case kErrorChannelAccessFailure:
|
||||||
case OT_ERROR_ABORT:
|
case kErrorAbort:
|
||||||
mRetxMode = true;
|
mRetxMode = true;
|
||||||
shouldRecalculatePollPeriod = true;
|
shouldRecalculatePollPeriod = true;
|
||||||
break;
|
break;
|
||||||
@@ -259,8 +259,8 @@ void DataPollSender::HandlePollSent(Mac::TxFrame &aFrame, otError aError)
|
|||||||
default:
|
default:
|
||||||
mPollTxFailureCounter++;
|
mPollTxFailureCounter++;
|
||||||
|
|
||||||
otLogInfoMac("Failed to send data poll, error:%s, retx:%d/%d", otThreadErrorToString(aError),
|
otLogInfoMac("Failed to send data poll, error:%s, retx:%d/%d", ErrorToString(aError), mPollTxFailureCounter,
|
||||||
mPollTxFailureCounter, kMaxPollRetxAttempts);
|
kMaxPollRetxAttempts);
|
||||||
|
|
||||||
if (mPollTxFailureCounter < kMaxPollRetxAttempts)
|
if (mPollTxFailureCounter < kMaxPollRetxAttempts)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -92,13 +92,13 @@ public:
|
|||||||
/**
|
/**
|
||||||
* This method enqueues a data poll (an IEEE 802.15.4 Data Request) message.
|
* 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 kErrorNone Successfully enqueued a data poll message
|
||||||
* @retval OT_ERROR_ALREADY A data poll message is already enqueued.
|
* @retval kErrorAlready A data poll message is already enqueued.
|
||||||
* @retval OT_ERROR_INVALID_STATE Device is not in rx-off-when-idle mode.
|
* @retval kErrorInvalidState Device is not in rx-off-when-idle mode.
|
||||||
* @retval OT_ERROR_NO_BUFS Insufficient message buffers available.
|
* @retval kErrorNoBufs Insufficient message buffers available.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError SendDataPoll(void);
|
Error SendDataPoll(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method sets/clears a user-specified/external data poll period.
|
* This method sets/clears a user-specified/external data poll period.
|
||||||
@@ -111,16 +111,16 @@ public:
|
|||||||
* value is larger than the child timeout.
|
* 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
|
* 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.
|
* `0x3FFFFFF ((1 << 26) - 1)`, it would be clipped to this value.
|
||||||
*
|
*
|
||||||
* @param[in] aPeriod The data poll period in milliseconds.
|
* @param[in] aPeriod The data poll period in milliseconds.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully set/cleared user-specified poll period.
|
* @retval kErrorNone Successfully set/cleared user-specified poll period.
|
||||||
* @retval OT_ERROR_INVALID_ARGS If aPeriod is invalid.
|
* @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.
|
* 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] 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).
|
* @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 kErrorNone @p aDest and @p aRadioType were updated successfully.
|
||||||
* @retval OT_ERROR_ABORT Abort the data poll transmission (not currently attached to any parent).
|
* @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
|
#else
|
||||||
/**
|
/**
|
||||||
* This method gets the destination MAC address for a data poll frame.
|
* 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).
|
* @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 kErrorNone @p aDest was updated successfully.
|
||||||
* @retval OT_ERROR_ABORT Abort the data poll transmission (not currently attached to any parent).
|
* @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
|
#endif // #if OPENTHREAD_CONFIG_MULTI_RADIO
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -166,7 +166,7 @@ public:
|
|||||||
* @param[in] aError Error status of a data poll message transmission.
|
* @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
|
* This method informs the data poll sender that a data poll timeout happened, i.e., when the ack in response to
|
||||||
|
|||||||
+44
-44
@@ -64,15 +64,15 @@ LinkRaw::LinkRaw(Instance &aInstance)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
otError LinkRaw::SetReceiveDone(otLinkRawReceiveDone aCallback)
|
Error LinkRaw::SetReceiveDone(otLinkRawReceiveDone aCallback)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
bool enable = aCallback != nullptr;
|
bool enable = aCallback != nullptr;
|
||||||
|
|
||||||
otLogDebgMac("LinkRaw::Enabled(%s)", (enable ? "true" : "false"));
|
otLogDebgMac("LinkRaw::Enabled(%s)", (enable ? "true" : "false"));
|
||||||
|
|
||||||
#if OPENTHREAD_MTD || OPENTHREAD_FTD
|
#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
|
// 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
|
// 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
|
// When disabling link-raw, make sure there is no ongoing
|
||||||
// transmit or scan operation. Otherwise Mac will attempt to
|
// transmit or scan operation. Otherwise Mac will attempt to
|
||||||
// handle an unexpected "done" callback.
|
// handle an unexpected "done" callback.
|
||||||
VerifyOrExit(!mSubMac.IsTransmittingOrScanning(), error = OT_ERROR_BUSY);
|
VerifyOrExit(!mSubMac.IsTransmittingOrScanning(), error = kErrorBusy);
|
||||||
}
|
}
|
||||||
|
|
||||||
Get<Mac>().SetEnabled(!enable);
|
Get<Mac>().SetEnabled(!enable);
|
||||||
@@ -105,11 +105,11 @@ exit:
|
|||||||
return error;
|
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);
|
mSubMac.SetPanId(aPanId);
|
||||||
mPanId = aPanId;
|
mPanId = aPanId;
|
||||||
|
|
||||||
@@ -117,44 +117,44 @@ exit:
|
|||||||
return error;
|
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;
|
mReceiveChannel = aChannel;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return error;
|
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);
|
mSubMac.SetExtAddress(aExtAddress);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return error;
|
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);
|
mSubMac.SetShortAddress(aShortAddress);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return error;
|
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));
|
SuccessOrExit(error = mSubMac.Receive(mReceiveChannel));
|
||||||
|
|
||||||
@@ -162,22 +162,22 @@ exit:
|
|||||||
return error;
|
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,
|
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);
|
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());
|
SuccessOrExit(error = mSubMac.Send());
|
||||||
mTransmitDoneCallback = aCallback;
|
mTransmitDoneCallback = aCallback;
|
||||||
@@ -186,9 +186,9 @@ exit:
|
|||||||
return error;
|
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)
|
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));
|
SuccessOrExit(error = mSubMac.EnergyScan(aScanChannel, aScanDuration));
|
||||||
mEnergyScanDoneCallback = aCallback;
|
mEnergyScanDoneCallback = aCallback;
|
||||||
@@ -219,26 +219,26 @@ void LinkRaw::InvokeEnergyScanDone(int8_t aEnergyScanMaxRssi)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
otError LinkRaw::SetMacKey(uint8_t aKeyIdMode,
|
Error LinkRaw::SetMacKey(uint8_t aKeyIdMode,
|
||||||
uint8_t aKeyId,
|
uint8_t aKeyId,
|
||||||
const Key &aPrevKey,
|
const Key &aPrevKey,
|
||||||
const Key &aCurrKey,
|
const Key &aCurrKey,
|
||||||
const Key &aNextKey)
|
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);
|
mSubMac.SetMacKey(aKeyIdMode, aKeyId, aPrevKey, aCurrKey, aNextKey);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return error;
|
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);
|
mSubMac.SetFrameCounter(aMacFrameCounter);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
@@ -251,16 +251,16 @@ exit:
|
|||||||
|
|
||||||
void LinkRaw::RecordFrameTransmitStatus(const TxFrame &aFrame,
|
void LinkRaw::RecordFrameTransmitStatus(const TxFrame &aFrame,
|
||||||
const RxFrame *aAckFrame,
|
const RxFrame *aAckFrame,
|
||||||
otError aError,
|
Error aError,
|
||||||
uint8_t aRetryCount,
|
uint8_t aRetryCount,
|
||||||
bool aWillRetx)
|
bool aWillRetx)
|
||||||
{
|
{
|
||||||
OT_UNUSED_VARIABLE(aAckFrame);
|
OT_UNUSED_VARIABLE(aAckFrame);
|
||||||
OT_UNUSED_VARIABLE(aWillRetx);
|
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());
|
aFrame.GetMaxFrameRetries(), aFrame.ToInfoString().AsCString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+46
-50
@@ -80,12 +80,12 @@ public:
|
|||||||
* raw link-layer.
|
* raw link-layer.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_INVALID_STATE Thread stack is enabled.
|
* @retval kErrorInvalidState Thread stack is enabled.
|
||||||
* @retval OT_ERROR_FAILED The radio could not be enabled/disabled.
|
* @retval kErrorFailed The radio could not be enabled/disabled.
|
||||||
* @retval OT_ERROR_NONE Successfully enabled/disabled raw link.
|
* @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.
|
* 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.
|
* This method starts a (recurring) Receive on the link-layer.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully transitioned to Receive.
|
* @retval kErrorNone Successfully transitioned to Receive.
|
||||||
* @retval OT_ERROR_INVALID_STATE The radio was disabled or transmitting.
|
* @retval kErrorInvalidState The radio was disabled or transmitting.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError Receive(void);
|
Error Receive(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method invokes the mReceiveDoneCallback, if set.
|
* 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] 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,
|
* @param[in] aError kErrorNone when successfully received a frame,
|
||||||
* OT_ERROR_ABORT when reception was aborted and a frame was not received,
|
* kErrorAbort 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.
|
* 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.
|
* This method gets the radio transmit frame.
|
||||||
@@ -126,28 +126,28 @@ public:
|
|||||||
/**
|
/**
|
||||||
* This method starts a (single) Transmit on the link-layer.
|
* 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.
|
* @param[in] aCallback A pointer to a function called on completion of the transmission.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully transitioned to Transmit.
|
* @retval kErrorNone Successfully transitioned to Transmit.
|
||||||
* @retval OT_ERROR_INVALID_STATE The radio was not in the Receive state.
|
* @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.
|
* This method invokes the mTransmitDoneCallback, if set.
|
||||||
*
|
*
|
||||||
* @param[in] aFrame The transmitted frame.
|
* @param[in] aFrame The transmitted frame.
|
||||||
* @param[in] aAckFrame A pointer to the ACK frame, nullptr if no ACK was received.
|
* @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,
|
* @param[in] aError kErrorNone when the frame was transmitted,
|
||||||
* OT_ERROR_NO_ACK when the frame was transmitted but no ACK was received,
|
* kErrorNoAck when the frame was transmitted but no ACK was received,
|
||||||
* OT_ERROR_CHANNEL_ACCESS_FAILURE tx failed due to activity on the channel,
|
* kErrorChannelAccessFailure tx failed due to activity on the channel,
|
||||||
* OT_ERROR_ABORT when transmission was aborted for other reasons.
|
* 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.
|
* 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] 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.
|
* @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 kErrorNone Successfully started scanning the channel.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The radio doesn't support energy scanning.
|
* @retval kErrorNotImplemented The radio doesn't support energy scanning.
|
||||||
* @retval OT_ERROR_INVALID_STATE If the raw link-layer isn't enabled.
|
* @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.
|
* This method invokes the mEnergyScanDoneCallback, if set.
|
||||||
@@ -184,11 +184,11 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[in] aShortAddress The short address.
|
* @param[in] aShortAddress The short address.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE If successful.
|
* @retval kErrorNone If successful.
|
||||||
* @retval OT_ERROR_INVALID_STATE If the raw link-layer isn't enabled.
|
* @retval kErrorInvalidState If the raw link-layer isn't enabled.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError SetShortAddress(ShortAddress aShortAddress);
|
Error SetShortAddress(ShortAddress aShortAddress);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function returns PANID.
|
* This function returns PANID.
|
||||||
@@ -203,11 +203,11 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[in] aPanId The PANID.
|
* @param[in] aPanId The PANID.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE If successful.
|
* @retval kErrorNone If successful.
|
||||||
* @retval OT_ERROR_INVALID_STATE If the raw link-layer isn't enabled.
|
* @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.
|
* This method gets the current receiving channel.
|
||||||
@@ -223,7 +223,7 @@ public:
|
|||||||
* @param[in] aChannel The channel to use for receiving.
|
* @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.
|
* This function returns the extended address.
|
||||||
@@ -238,11 +238,11 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[in] aExtAddress The extended address.
|
* @param[in] aExtAddress The extended address.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE If successful.
|
* @retval kErrorNone If successful.
|
||||||
* @retval OT_ERROR_INVALID_STATE If the raw link-layer isn't enabled.
|
* @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.
|
* This method updates MAC keys and key index.
|
||||||
@@ -253,26 +253,22 @@ public:
|
|||||||
* @param[in] aCurrKey The current MAC key.
|
* @param[in] aCurrKey The current MAC key.
|
||||||
* @param[in] aNextKey The next MAC key.
|
* @param[in] aNextKey The next MAC key.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE If successful.
|
* @retval kErrorNone If successful.
|
||||||
* @retval OT_ERROR_INVALID_STATE If the raw link-layer isn't enabled.
|
* @retval kErrorInvalidState If the raw link-layer isn't enabled.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError SetMacKey(uint8_t aKeyIdMode,
|
Error SetMacKey(uint8_t aKeyIdMode, uint8_t aKeyId, const Key &aPrevKey, const Key &aCurrKey, const Key &aNextKey);
|
||||||
uint8_t aKeyId,
|
|
||||||
const Key &aPrevKey,
|
|
||||||
const Key &aCurrKey,
|
|
||||||
const Key &aNextKey);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method sets the current MAC frame counter value.
|
* This method sets the current MAC frame counter value.
|
||||||
*
|
*
|
||||||
* @param[in] aMacFrameCounter The MAC frame counter value.
|
* @param[in] aMacFrameCounter The MAC frame counter value.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE If successful.
|
* @retval kErrorNone If successful.
|
||||||
* @retval OT_ERROR_INVALID_STATE If the raw link-layer isn't enabled.
|
* @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.
|
* 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] aFrame The transmitted frame.
|
||||||
* @param[in] aAckFrame A pointer to the ACK frame, or nullptr if no ACK was received.
|
* @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,
|
* @param[in] aError kErrorNone when the frame was transmitted successfully,
|
||||||
* OT_ERROR_NO_ACK when the frame was transmitted but no ACK was received,
|
* kErrorNoAck when the frame was transmitted but no ACK was received,
|
||||||
* OT_ERROR_CHANNEL_ACCESS_FAILURE tx failed due to activity on the channel,
|
* kErrorChannelAccessFailure tx failed due to activity on the channel,
|
||||||
* OT_ERROR_ABORT when transmission was aborted for other reasons.
|
* kErrorAbort when transmission was aborted for other reasons.
|
||||||
* @param[in] aRetryCount Indicates number of transmission retries for this frame.
|
* @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
|
* @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).
|
* 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)
|
#if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_MAC == 1)
|
||||||
void RecordFrameTransmitStatus(const TxFrame &aFrame,
|
void RecordFrameTransmitStatus(const TxFrame &aFrame,
|
||||||
const RxFrame *aAckFrame,
|
const RxFrame *aAckFrame,
|
||||||
otError aError,
|
Error aError,
|
||||||
uint8_t aRetryCount,
|
uint8_t aRetryCount,
|
||||||
bool aWillRetx);
|
bool aWillRetx);
|
||||||
#else
|
#else
|
||||||
void RecordFrameTransmitStatus(const TxFrame &, const RxFrame *, otError, uint8_t, bool) {}
|
void RecordFrameTransmitStatus(const TxFrame &, const RxFrame *, Error, uint8_t, bool) {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
+126
-128
@@ -124,7 +124,7 @@ Mac::Mac(Instance &aInstance)
|
|||||||
, mKeyIdMode2FrameCounter(0)
|
, mKeyIdMode2FrameCounter(0)
|
||||||
, mCcaSampleCount(0)
|
, mCcaSampleCount(0)
|
||||||
#if OPENTHREAD_CONFIG_MULTI_RADIO
|
#if OPENTHREAD_CONFIG_MULTI_RADIO
|
||||||
, mTxError(OT_ERROR_NONE)
|
, mTxError(kErrorNone)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
ExtAddress randomExtAddress;
|
ExtAddress randomExtAddress;
|
||||||
@@ -149,12 +149,12 @@ Mac::Mac(Instance &aInstance)
|
|||||||
SetShortAddress(GetShortAddress());
|
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(IsEnabled(), error = kErrorInvalidState);
|
||||||
VerifyOrExit(!IsActiveScanInProgress() && !IsEnergyScanInProgress(), error = OT_ERROR_BUSY);
|
VerifyOrExit(!IsActiveScanInProgress() && !IsEnergyScanInProgress(), error = kErrorBusy);
|
||||||
|
|
||||||
mActiveScanHandler = aHandler;
|
mActiveScanHandler = aHandler;
|
||||||
mScanHandlerContext = aContext;
|
mScanHandlerContext = aContext;
|
||||||
@@ -170,12 +170,12 @@ exit:
|
|||||||
return error;
|
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(IsEnabled(), error = kErrorInvalidState);
|
||||||
VerifyOrExit(!IsActiveScanInProgress() && !IsEnergyScanInProgress(), error = OT_ERROR_BUSY);
|
VerifyOrExit(!IsActiveScanInProgress() && !IsEnergyScanInProgress(), error = kErrorBusy);
|
||||||
|
|
||||||
mEnergyScanHandler = aHandler;
|
mEnergyScanHandler = aHandler;
|
||||||
mScanHandlerContext = aContext;
|
mScanHandlerContext = aContext;
|
||||||
@@ -231,9 +231,9 @@ bool Mac::IsInTransmitState(void) const
|
|||||||
return retval;
|
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;
|
Address address;
|
||||||
const Beacon * beacon = nullptr;
|
const Beacon * beacon = nullptr;
|
||||||
const BeaconPayload *beaconPayload = nullptr;
|
const BeaconPayload *beaconPayload = nullptr;
|
||||||
@@ -241,14 +241,14 @@ otError Mac::ConvertBeaconToActiveScanResult(const RxFrame *aBeaconFrame, Active
|
|||||||
|
|
||||||
memset(&aResult, 0, sizeof(ActiveScanResult));
|
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));
|
SuccessOrExit(error = aBeaconFrame->GetSrcAddr(address));
|
||||||
VerifyOrExit(address.IsExtended(), error = OT_ERROR_PARSE);
|
VerifyOrExit(address.IsExtended(), error = kErrorParse);
|
||||||
aResult.mExtAddress = address.GetExtended();
|
aResult.mExtAddress = address.GetExtended();
|
||||||
|
|
||||||
if (OT_ERROR_NONE != aBeaconFrame->GetSrcPanId(aResult.mPanId))
|
if (kErrorNone != aBeaconFrame->GetSrcPanId(aResult.mPanId))
|
||||||
{
|
{
|
||||||
IgnoreError(aBeaconFrame->GetDstPanId(aResult.mPanId));
|
IgnoreError(aBeaconFrame->GetDstPanId(aResult.mPanId));
|
||||||
}
|
}
|
||||||
@@ -268,7 +268,7 @@ otError Mac::ConvertBeaconToActiveScanResult(const RxFrame *aBeaconFrame, Active
|
|||||||
aResult.mIsJoinable = beaconPayload->IsJoiningPermitted();
|
aResult.mIsJoinable = beaconPayload->IsJoiningPermitted();
|
||||||
aResult.mIsNative = beaconPayload->IsNative();
|
aResult.mIsNative = beaconPayload->IsNative();
|
||||||
IgnoreError(static_cast<NetworkName &>(aResult.mNetworkName).Set(beaconPayload->GetNetworkName()));
|
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();
|
aResult.mExtendedPanId = beaconPayload->GetExtendedPanId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,11 +278,11 @@ exit:
|
|||||||
return error;
|
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);
|
error = mScanChannelMask.GetNextChannel(mScanChannel);
|
||||||
|
|
||||||
@@ -292,7 +292,7 @@ exit:
|
|||||||
|
|
||||||
void Mac::PerformActiveScan(void)
|
void Mac::PerformActiveScan(void)
|
||||||
{
|
{
|
||||||
if (UpdateScanChannel() == OT_ERROR_NONE)
|
if (UpdateScanChannel() == kErrorNone)
|
||||||
{
|
{
|
||||||
// If there are more channels to scan, send the beacon request.
|
// If there are more channels to scan, send the beacon request.
|
||||||
BeginTransmit();
|
BeginTransmit();
|
||||||
@@ -328,7 +328,7 @@ exit:
|
|||||||
|
|
||||||
void Mac::PerformEnergyScan(void)
|
void Mac::PerformEnergyScan(void)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
|
|
||||||
SuccessOrExit(error = UpdateScanChannel());
|
SuccessOrExit(error = UpdateScanChannel());
|
||||||
|
|
||||||
@@ -348,7 +348,7 @@ void Mac::PerformEnergyScan(void)
|
|||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
|
||||||
if (error != OT_ERROR_NONE)
|
if (error != kErrorNone)
|
||||||
{
|
{
|
||||||
FinishOperation();
|
FinishOperation();
|
||||||
|
|
||||||
@@ -420,11 +420,11 @@ exit:
|
|||||||
return;
|
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));
|
SuccessOrExit(Get<Notifier>().Update(mPanChannel, aChannel, kEventThreadChannelChanged));
|
||||||
|
|
||||||
@@ -440,11 +440,11 @@ exit:
|
|||||||
return error;
|
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;
|
mUsingTemporaryChannel = true;
|
||||||
mRadioChannel = aChannel;
|
mRadioChannel = aChannel;
|
||||||
@@ -473,7 +473,7 @@ void Mac::SetSupportedChannelMask(const ChannelMask &aMask)
|
|||||||
IgnoreError(Get<Notifier>().Update(mSupportedChannelMask, newMask, kEventSupportedChannelMaskChanged));
|
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`
|
// When setting Network Name from a string, we treat it as `NameData`
|
||||||
// with `kMaxSize + 1` chars. `NetworkName::Set(data)` will look
|
// 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`
|
// the name's length and ensure that the name fits in `kMaxSize`
|
||||||
// chars. The `+ 1` ensures that a `aNameString` with length
|
// chars. The `+ 1` ensures that a `aNameString` with length
|
||||||
// longer than `kMaxSize` is correctly rejected (returning error
|
// longer than `kMaxSize` is correctly rejected (returning error
|
||||||
// `OT_ERROR_INVALID_ARGS`).
|
// `kErrorInvalidArgs`).
|
||||||
|
|
||||||
otError error;
|
Error error;
|
||||||
NameData data(aNameString, NetworkName::kMaxSize + 1);
|
NameData data(aNameString, NetworkName::kMaxSize + 1);
|
||||||
|
|
||||||
VerifyOrExit(IsValidUtf8String(aNameString), error = OT_ERROR_INVALID_ARGS);
|
VerifyOrExit(IsValidUtf8String(aNameString), error = kErrorInvalidArgs);
|
||||||
|
|
||||||
error = SetNetworkName(data);
|
error = SetNetworkName(data);
|
||||||
|
|
||||||
@@ -494,14 +494,14 @@ exit:
|
|||||||
return error;
|
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);
|
Get<Notifier>().SignalIfFirst(kEventThreadNetworkNameChanged);
|
||||||
error = OT_ERROR_NONE;
|
error = kErrorNone;
|
||||||
ExitNow();
|
ExitNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -513,7 +513,7 @@ exit:
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
|
#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`
|
// When setting Domain Name from a string, we treat it as `NameData`
|
||||||
// with `kMaxSize + 1` chars. `DomainName::Set(data)` will look
|
// 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`
|
// the name's length and ensure that the name fits in `kMaxSize`
|
||||||
// chars. The `+ 1` ensures that a `aNameString` with length
|
// chars. The `+ 1` ensures that a `aNameString` with length
|
||||||
// longer than `kMaxSize` is correctly rejected (returning error
|
// longer than `kMaxSize` is correctly rejected (returning error
|
||||||
// `OT_ERROR_INVALID_ARGS`).
|
// `kErrorInvalidArgs`).
|
||||||
|
|
||||||
otError error;
|
Error error;
|
||||||
NameData data(aNameString, DomainName::kMaxSize + 1);
|
NameData data(aNameString, DomainName::kMaxSize + 1);
|
||||||
|
|
||||||
VerifyOrExit(IsValidUtf8String(aNameString), error = OT_ERROR_INVALID_ARGS);
|
VerifyOrExit(IsValidUtf8String(aNameString), error = kErrorInvalidArgs);
|
||||||
|
|
||||||
error = SetDomainName(data);
|
error = SetDomainName(data);
|
||||||
|
|
||||||
@@ -534,13 +534,13 @@ exit:
|
|||||||
return error;
|
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;
|
return error;
|
||||||
@@ -599,14 +599,13 @@ exit:
|
|||||||
#endif
|
#endif
|
||||||
#endif // OPENTHREAD_FTD
|
#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(aOobFrame != nullptr, error = kErrorInvalidArgs);
|
||||||
VerifyOrExit(IsEnabled(), error = OT_ERROR_INVALID_STATE);
|
VerifyOrExit(IsEnabled(), error = kErrorInvalidState);
|
||||||
VerifyOrExit(!mPendingTransmitOobFrame && (mOperation != kOperationTransmitOutOfBandFrame),
|
VerifyOrExit(!mPendingTransmitOobFrame && (mOperation != kOperationTransmitOutOfBandFrame), error = kErrorAlready);
|
||||||
error = OT_ERROR_ALREADY);
|
|
||||||
|
|
||||||
mOobFrame = static_cast<TxFrame *>(aOobFrame);
|
mOobFrame = static_cast<TxFrame *>(aOobFrame);
|
||||||
|
|
||||||
@@ -616,12 +615,12 @@ exit:
|
|||||||
return error;
|
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(IsEnabled(), error = kErrorInvalidState);
|
||||||
VerifyOrExit(!mPendingTransmitPoll && (mOperation != kOperationTransmitPoll), error = OT_ERROR_ALREADY);
|
VerifyOrExit(!mPendingTransmitPoll && (mOperation != kOperationTransmitPoll), error = kErrorAlready);
|
||||||
|
|
||||||
// We ensure data frame and data poll tx requests are handled in the
|
// 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
|
// 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
|
#if OPENTHREAD_CONFIG_MULTI_RADIO
|
||||||
mTxPendingRadioLinks.Clear();
|
mTxPendingRadioLinks.Clear();
|
||||||
mTxError = OT_ERROR_ABORT;
|
mTxError = kErrorAbort;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
VerifyOrExit(IsEnabled());
|
VerifyOrExit(IsEnabled());
|
||||||
@@ -1300,15 +1299,15 @@ void Mac::BeginTransmit(void)
|
|||||||
mTxPendingRadioLinks = txFrames.GetSelectedRadioTypes();
|
mTxPendingRadioLinks = txFrames.GetSelectedRadioTypes();
|
||||||
|
|
||||||
// If the "required radio type set" is empty,`mTxError` starts as
|
// 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.
|
// link is sufficient for overall tx to be considered successful.
|
||||||
// When the "required radio type set" is not empty, `mTxError`
|
// 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.
|
// in the required set fails.
|
||||||
|
|
||||||
if (!txFrames.GetRequiredRadioTypes().IsEmpty())
|
if (!txFrames.GetRequiredRadioTypes().IsEmpty())
|
||||||
{
|
{
|
||||||
mTxError = OT_ERROR_NONE;
|
mTxError = kErrorNone;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1338,7 +1337,7 @@ exit:
|
|||||||
|
|
||||||
frame = &txFrames.GetBroadcastTxFrame();
|
frame = &txFrames.GetBroadcastTxFrame();
|
||||||
frame->SetLength(0);
|
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,
|
void Mac::RecordFrameTransmitStatus(const TxFrame &aFrame,
|
||||||
const RxFrame *aAckFrame,
|
const RxFrame *aAckFrame,
|
||||||
otError aError,
|
Error aError,
|
||||||
uint8_t aRetryCount,
|
uint8_t aRetryCount,
|
||||||
bool aWillRetx)
|
bool aWillRetx)
|
||||||
{
|
{
|
||||||
@@ -1390,12 +1389,12 @@ void Mac::RecordFrameTransmitStatus(const TxFrame &aFrame,
|
|||||||
|
|
||||||
switch (aError)
|
switch (aError)
|
||||||
{
|
{
|
||||||
case OT_ERROR_NO_ACK:
|
case kErrorNoAck:
|
||||||
frameTxSuccess = false;
|
frameTxSuccess = false;
|
||||||
|
|
||||||
OT_FALL_THROUGH;
|
OT_FALL_THROUGH;
|
||||||
|
|
||||||
case OT_ERROR_NONE:
|
case kErrorNone:
|
||||||
neighbor->GetLinkInfo().AddFrameTxStatus(frameTxSuccess);
|
neighbor->GetLinkInfo().AddFrameTxStatus(frameTxSuccess);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -1406,7 +1405,7 @@ void Mac::RecordFrameTransmitStatus(const TxFrame &aFrame,
|
|||||||
|
|
||||||
// Log frame transmission failure.
|
// Log frame transmission failure.
|
||||||
|
|
||||||
if (aError != OT_ERROR_NONE)
|
if (aError != kErrorNone)
|
||||||
{
|
{
|
||||||
LogFrameTxFailure(aFrame, aError, aRetryCount, aWillRetx);
|
LogFrameTxFailure(aFrame, aError, aRetryCount, aWillRetx);
|
||||||
otDumpDebgMac("TX ERR", aFrame.GetHeader(), 16);
|
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.
|
// 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());
|
neighbor->GetLinkInfo().AddRss(aAckFrame->GetRssi());
|
||||||
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_ENABLE
|
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_ENABLE
|
||||||
@@ -1447,12 +1446,12 @@ void Mac::RecordFrameTransmitStatus(const TxFrame &aFrame,
|
|||||||
|
|
||||||
mCounters.mTxTotal++;
|
mCounters.mTxTotal++;
|
||||||
|
|
||||||
if (aError == OT_ERROR_ABORT)
|
if (aError == kErrorAbort)
|
||||||
{
|
{
|
||||||
mCounters.mTxErrAbort++;
|
mCounters.mTxErrAbort++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aError == OT_ERROR_CHANNEL_ACCESS_FAILURE)
|
if (aError == kErrorChannelAccessFailure)
|
||||||
{
|
{
|
||||||
mCounters.mTxErrBusyChannel++;
|
mCounters.mTxErrBusyChannel++;
|
||||||
}
|
}
|
||||||
@@ -1461,7 +1460,7 @@ void Mac::RecordFrameTransmitStatus(const TxFrame &aFrame,
|
|||||||
{
|
{
|
||||||
mCounters.mTxAckRequested++;
|
mCounters.mTxAckRequested++;
|
||||||
|
|
||||||
if (aError == OT_ERROR_NONE)
|
if (aError == kErrorNone)
|
||||||
{
|
{
|
||||||
mCounters.mTxAcked++;
|
mCounters.mTxAcked++;
|
||||||
}
|
}
|
||||||
@@ -1484,7 +1483,7 @@ exit:
|
|||||||
return;
|
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 OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
|
||||||
if (!aFrame.IsEmpty()
|
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
|
#if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2
|
||||||
// Verify Enh-ACK integrity by checking its MIC
|
// Verify Enh-ACK integrity by checking its MIC
|
||||||
if ((aError == OT_ERROR_NONE) && (aAckFrame != nullptr) &&
|
if ((aError == kErrorNone) && (aAckFrame != nullptr) &&
|
||||||
(ProcessEnhAckSecurity(aFrame, *aAckFrame) != OT_ERROR_NONE))
|
(ProcessEnhAckSecurity(aFrame, *aAckFrame) != kErrorNone))
|
||||||
{
|
{
|
||||||
aError = OT_ERROR_NO_ACK;
|
aError = kErrorNoAck;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -1544,10 +1543,10 @@ void Mac::HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aError
|
|||||||
// If the "required radio type set" is empty, successful
|
// If the "required radio type set" is empty, successful
|
||||||
// tx over any radio link is sufficient for overall tx to
|
// tx over any radio link is sufficient for overall tx to
|
||||||
// be considered successful. In this case `mTxError`
|
// be considered successful. In this case `mTxError`
|
||||||
// starts as `OT_ERROR_ABORT` and we update it only when
|
// starts as `kErrorAbort` and we update it only when
|
||||||
// it is not already `OT_ERROR_NONE`.
|
// it is not already `kErrorNone`.
|
||||||
|
|
||||||
if (mTxError != OT_ERROR_NONE)
|
if (mTxError != kErrorNone)
|
||||||
{
|
{
|
||||||
mTxError = aError;
|
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
|
// When the "required radio type set" is not empty we
|
||||||
// expect the successful frame tx on all links in this set
|
// expect the successful frame tx on all links in this set
|
||||||
// to consider the overall tx successful. In this case,
|
// 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 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),
|
otLogDebgMac("Frame tx failed on required radio link %s with error %s", RadioTypeToString(radio),
|
||||||
otThreadErrorToString(aError));
|
ErrorToString(aError));
|
||||||
|
|
||||||
mTxError = aError;
|
mTxError = aError;
|
||||||
}
|
}
|
||||||
@@ -1597,7 +1596,7 @@ void Mac::HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aError
|
|||||||
case kOperationTransmitPoll:
|
case kOperationTransmitPoll:
|
||||||
OT_ASSERT(aFrame.IsEmpty() || aFrame.GetAckRequest());
|
OT_ASSERT(aFrame.IsEmpty() || aFrame.GetAckRequest());
|
||||||
|
|
||||||
if ((aError == OT_ERROR_NONE) && (aAckFrame != nullptr))
|
if ((aError == kErrorNone) && (aAckFrame != nullptr))
|
||||||
{
|
{
|
||||||
bool framePending = aAckFrame->GetFramePending();
|
bool framePending = aAckFrame->GetFramePending();
|
||||||
|
|
||||||
@@ -1618,7 +1617,7 @@ void Mac::HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aError
|
|||||||
case kOperationTransmitDataDirect:
|
case kOperationTransmitDataDirect:
|
||||||
mCounters.mTxData++;
|
mCounters.mTxData++;
|
||||||
|
|
||||||
if (aError != OT_ERROR_NONE)
|
if (aError != kErrorNone)
|
||||||
{
|
{
|
||||||
mCounters.mTxDirectMaxRetryExpiry++;
|
mCounters.mTxDirectMaxRetryExpiry++;
|
||||||
}
|
}
|
||||||
@@ -1633,7 +1632,7 @@ void Mac::HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aError
|
|||||||
FinishOperation();
|
FinishOperation();
|
||||||
Get<MeshForwarder>().HandleSentFrame(aFrame, aError);
|
Get<MeshForwarder>().HandleSentFrame(aFrame, aError);
|
||||||
#if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2
|
#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)
|
aFrame.GetSecurityEnabled() && aAckFrame != nullptr)
|
||||||
{
|
{
|
||||||
Get<DataPollSender>().ProcessFrame(*aAckFrame);
|
Get<DataPollSender>().ProcessFrame(*aAckFrame);
|
||||||
@@ -1657,7 +1656,7 @@ void Mac::HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aError
|
|||||||
case kOperationTransmitDataIndirect:
|
case kOperationTransmitDataIndirect:
|
||||||
mCounters.mTxData++;
|
mCounters.mTxData++;
|
||||||
|
|
||||||
if (aError != OT_ERROR_NONE)
|
if (aError != kErrorNone)
|
||||||
{
|
{
|
||||||
mCounters.mTxIndirectMaxRetryExpiry++;
|
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>();
|
KeyManager & keyManager = Get<KeyManager>();
|
||||||
otError error = OT_ERROR_SECURITY;
|
Error error = kErrorSecurity;
|
||||||
uint8_t securityLevel;
|
uint8_t securityLevel;
|
||||||
uint8_t keyIdMode;
|
uint8_t keyIdMode;
|
||||||
uint32_t frameCounter;
|
uint32_t frameCounter;
|
||||||
@@ -1750,7 +1749,7 @@ otError Mac::ProcessReceiveSecurity(RxFrame &aFrame, const Address &aSrcAddr, Ne
|
|||||||
const Key * macKey;
|
const Key * macKey;
|
||||||
const ExtAddress *extAddress;
|
const ExtAddress *extAddress;
|
||||||
|
|
||||||
VerifyOrExit(aFrame.GetSecurityEnabled(), error = OT_ERROR_NONE);
|
VerifyOrExit(aFrame.GetSecurityEnabled(), error = kErrorNone);
|
||||||
|
|
||||||
IgnoreError(aFrame.GetSecurityLevel(securityLevel));
|
IgnoreError(aFrame.GetSecurityLevel(securityLevel));
|
||||||
VerifyOrExit(securityLevel == Frame::kSecEncMic32);
|
VerifyOrExit(securityLevel == Frame::kSecEncMic32);
|
||||||
@@ -1813,7 +1812,7 @@ otError Mac::ProcessReceiveSecurity(RxFrame &aFrame, const Address &aSrcAddr, Ne
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// If frame counter is one off, then frame is a duplicate.
|
// 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);
|
VerifyOrExit(frameCounter >= neighborFrameCounter);
|
||||||
}
|
}
|
||||||
@@ -1867,16 +1866,16 @@ otError Mac::ProcessReceiveSecurity(RxFrame &aFrame, const Address &aSrcAddr, Ne
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
error = OT_ERROR_NONE;
|
error = kErrorNone;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2
|
#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 securityLevel;
|
||||||
uint8_t txKeyId;
|
uint8_t txKeyId;
|
||||||
uint8_t ackKeyId;
|
uint8_t ackKeyId;
|
||||||
@@ -1888,14 +1887,14 @@ otError Mac::ProcessEnhAckSecurity(TxFrame &aTxFrame, RxFrame &aAckFrame)
|
|||||||
KeyManager &keyManager = Get<KeyManager>();
|
KeyManager &keyManager = Get<KeyManager>();
|
||||||
const Key * macKey;
|
const Key * macKey;
|
||||||
|
|
||||||
VerifyOrExit(aAckFrame.GetSecurityEnabled(), error = OT_ERROR_NONE);
|
VerifyOrExit(aAckFrame.GetSecurityEnabled(), error = kErrorNone);
|
||||||
VerifyOrExit(aAckFrame.IsVersion2015());
|
VerifyOrExit(aAckFrame.IsVersion2015());
|
||||||
|
|
||||||
IgnoreError(aAckFrame.GetSecurityLevel(securityLevel));
|
IgnoreError(aAckFrame.GetSecurityLevel(securityLevel));
|
||||||
VerifyOrExit(securityLevel == Frame::kSecEncMic32);
|
VerifyOrExit(securityLevel == Frame::kSecEncMic32);
|
||||||
|
|
||||||
IgnoreError(aAckFrame.GetKeyIdMode(keyIdMode));
|
IgnoreError(aAckFrame.GetKeyIdMode(keyIdMode));
|
||||||
VerifyOrExit(keyIdMode == Frame::kKeyIdMode1, error = OT_ERROR_NONE);
|
VerifyOrExit(keyIdMode == Frame::kKeyIdMode1, error = kErrorNone);
|
||||||
|
|
||||||
IgnoreError(aTxFrame.GetKeyId(txKeyId));
|
IgnoreError(aTxFrame.GetKeyId(txKeyId));
|
||||||
IgnoreError(aAckFrame.GetKeyId(ackKeyId));
|
IgnoreError(aAckFrame.GetKeyId(ackKeyId));
|
||||||
@@ -1962,7 +1961,7 @@ otError Mac::ProcessEnhAckSecurity(TxFrame &aTxFrame, RxFrame &aAckFrame)
|
|||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if (error != OT_ERROR_NONE)
|
if (error != kErrorNone)
|
||||||
{
|
{
|
||||||
otLogInfoMac("Frame tx attempt failed, error: Enh-ACK security check fail");
|
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
|
#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 srcaddr;
|
||||||
Address dstaddr;
|
Address dstaddr;
|
||||||
PanId panid;
|
PanId panid;
|
||||||
Neighbor *neighbor;
|
Neighbor *neighbor;
|
||||||
otError error = aError;
|
Error error = aError;
|
||||||
|
|
||||||
mCounters.mRxTotal++;
|
mCounters.mRxTotal++;
|
||||||
|
|
||||||
SuccessOrExit(error);
|
SuccessOrExit(error);
|
||||||
VerifyOrExit(aFrame != nullptr, error = OT_ERROR_NO_FRAME_RECEIVED);
|
VerifyOrExit(aFrame != nullptr, error = kErrorNoFrameReceived);
|
||||||
VerifyOrExit(IsEnabled(), error = OT_ERROR_INVALID_STATE);
|
VerifyOrExit(IsEnabled(), error = kErrorInvalidState);
|
||||||
|
|
||||||
// Ensure we have a valid frame before attempting to read any contents of
|
// Ensure we have a valid frame before attempting to read any contents of
|
||||||
// the buffer received from the radio.
|
// the buffer received from the radio.
|
||||||
@@ -2001,7 +2000,7 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, otError aError)
|
|||||||
|
|
||||||
case Address::kTypeShort:
|
case Address::kTypeShort:
|
||||||
VerifyOrExit((mRxOnWhenIdle && dstaddr.IsBroadcast()) || dstaddr.GetShort() == GetShortAddress(),
|
VerifyOrExit((mRxOnWhenIdle && dstaddr.IsBroadcast()) || dstaddr.GetShort() == GetShortAddress(),
|
||||||
error = OT_ERROR_DESTINATION_ADDRESS_FILTERED);
|
error = kErrorDestinationAddressFiltered);
|
||||||
|
|
||||||
#if OPENTHREAD_FTD
|
#if OPENTHREAD_FTD
|
||||||
// Allow multicasts from neighbor routers if FTD
|
// Allow multicasts from neighbor routers if FTD
|
||||||
@@ -2014,14 +2013,14 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, otError aError)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Address::kTypeExtended:
|
case Address::kTypeExtended:
|
||||||
VerifyOrExit(dstaddr.GetExtended() == GetExtAddress(), error = OT_ERROR_DESTINATION_ADDRESS_FILTERED);
|
VerifyOrExit(dstaddr.GetExtended() == GetExtAddress(), error = kErrorDestinationAddressFiltered);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify destination PAN ID if present
|
// 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
|
// Source Address Filtering
|
||||||
@@ -2033,7 +2032,7 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, otError aError)
|
|||||||
case Address::kTypeShort:
|
case Address::kTypeShort:
|
||||||
otLogDebgMac("Received frame from short address 0x%04x", srcaddr.GetShort());
|
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());
|
srcaddr.SetExtended(neighbor->GetExtAddress());
|
||||||
|
|
||||||
@@ -2042,7 +2041,7 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, otError aError)
|
|||||||
case Address::kTypeExtended:
|
case Address::kTypeExtended:
|
||||||
|
|
||||||
// Duplicate Address Protection
|
// 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
|
#if OPENTHREAD_CONFIG_MAC_FILTER_ENABLE
|
||||||
{
|
{
|
||||||
@@ -2080,7 +2079,7 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, otError aError)
|
|||||||
|
|
||||||
switch (error)
|
switch (error)
|
||||||
{
|
{
|
||||||
case OT_ERROR_DUPLICATED:
|
case kErrorDuplicated:
|
||||||
|
|
||||||
// Allow a duplicate received frame pass, only if the
|
// Allow a duplicate received frame pass, only if the
|
||||||
// current operation is `kOperationWaitingForData` (i.e.,
|
// current operation is `kOperationWaitingForData` (i.e.,
|
||||||
@@ -2099,7 +2098,7 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, otError aError)
|
|||||||
|
|
||||||
OT_FALL_THROUGH;
|
OT_FALL_THROUGH;
|
||||||
|
|
||||||
case OT_ERROR_NONE:
|
case kErrorNone:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -2139,11 +2138,11 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, otError aError)
|
|||||||
case Neighbor::kStateChildUpdateRequest:
|
case Neighbor::kStateChildUpdateRequest:
|
||||||
|
|
||||||
// Only accept a "MAC Data Request" frame from a child being restored.
|
// 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;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ExitNow(error = OT_ERROR_UNKNOWN_NEIGHBOR);
|
ExitNow(error = kErrorUnknownNeighbor);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2 && OPENTHREAD_FTD
|
#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:
|
case Frame::kFcfFrameMacCmd:
|
||||||
if (HandleMacCommand(*aFrame)) // returns `true` when handled
|
if (HandleMacCommand(*aFrame)) // returns `true` when handled
|
||||||
{
|
{
|
||||||
ExitNow(error = OT_ERROR_NONE);
|
ExitNow(error = kErrorNone);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -2239,41 +2238,41 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, otError aError)
|
|||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
|
||||||
if (error != OT_ERROR_NONE)
|
if (error != kErrorNone)
|
||||||
{
|
{
|
||||||
LogFrameRxFailure(aFrame, error);
|
LogFrameRxFailure(aFrame, error);
|
||||||
|
|
||||||
switch (error)
|
switch (error)
|
||||||
{
|
{
|
||||||
case OT_ERROR_SECURITY:
|
case kErrorSecurity:
|
||||||
mCounters.mRxErrSec++;
|
mCounters.mRxErrSec++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OT_ERROR_FCS:
|
case kErrorFcs:
|
||||||
mCounters.mRxErrFcs++;
|
mCounters.mRxErrFcs++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OT_ERROR_NO_FRAME_RECEIVED:
|
case kErrorNoFrameReceived:
|
||||||
mCounters.mRxErrNoFrame++;
|
mCounters.mRxErrNoFrame++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OT_ERROR_UNKNOWN_NEIGHBOR:
|
case kErrorUnknownNeighbor:
|
||||||
mCounters.mRxErrUnknownNeighbor++;
|
mCounters.mRxErrUnknownNeighbor++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OT_ERROR_INVALID_SOURCE_ADDRESS:
|
case kErrorInvalidSourceAddress:
|
||||||
mCounters.mRxErrInvalidSrcAddr++;
|
mCounters.mRxErrInvalidSrcAddr++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OT_ERROR_ADDRESS_FILTERED:
|
case kErrorAddressFiltered:
|
||||||
mCounters.mRxAddressFiltered++;
|
mCounters.mRxAddressFiltered++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OT_ERROR_DESTINATION_ADDRESS_FILTERED:
|
case kErrorDestinationAddressFiltered:
|
||||||
mCounters.mRxDestAddrFiltered++;
|
mCounters.mRxDestAddrFiltered++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OT_ERROR_DUPLICATED:
|
case kErrorDuplicated:
|
||||||
mCounters.mRxDuplicated++;
|
mCounters.mRxDuplicated++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -2412,15 +2411,15 @@ const char *Mac::OperationToString(Operation aOperation)
|
|||||||
return kOperationStrings[aOperation];
|
return kOperationStrings[aOperation];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mac::LogFrameRxFailure(const RxFrame *aFrame, otError aError) const
|
void Mac::LogFrameRxFailure(const RxFrame *aFrame, Error aError) const
|
||||||
{
|
{
|
||||||
otLogLevel logLevel;
|
otLogLevel logLevel;
|
||||||
|
|
||||||
switch (aError)
|
switch (aError)
|
||||||
{
|
{
|
||||||
case OT_ERROR_ABORT:
|
case kErrorAbort:
|
||||||
case OT_ERROR_NO_FRAME_RECEIVED:
|
case kErrorNoFrameReceived:
|
||||||
case OT_ERROR_DESTINATION_ADDRESS_FILTERED:
|
case kErrorDestinationAddressFiltered:
|
||||||
logLevel = OT_LOG_LEVEL_DEBG;
|
logLevel = OT_LOG_LEVEL_DEBG;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -2431,16 +2430,15 @@ void Mac::LogFrameRxFailure(const RxFrame *aFrame, otError aError) const
|
|||||||
|
|
||||||
if (aFrame == nullptr)
|
if (aFrame == nullptr)
|
||||||
{
|
{
|
||||||
otLogMac(logLevel, "Frame rx failed, error:%s", otThreadErrorToString(aError));
|
otLogMac(logLevel, "Frame rx failed, error:%s", ErrorToString(aError));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
otLogMac(logLevel, "Frame rx failed, error:%s, %s", otThreadErrorToString(aError),
|
otLogMac(logLevel, "Frame rx failed, error:%s, %s", ErrorToString(aError), aFrame->ToInfoString().AsCString());
|
||||||
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 OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE && OPENTHREAD_CONFIG_MULTI_RADIO
|
||||||
if (aFrame.GetRadioType() == kRadioTypeIeee802154)
|
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 maxAttempts = aFrame.GetMaxFrameRetries() + 1;
|
||||||
uint8_t curAttempt = aWillRetx ? (aRetryCount + 1) : maxAttempts;
|
uint8_t curAttempt = aWillRetx ? (aRetryCount + 1) : maxAttempts;
|
||||||
|
|
||||||
otLogInfoMac("Frame tx attempt %d/%d failed, error:%s, %s", curAttempt, maxAttempts,
|
otLogInfoMac("Frame tx attempt %d/%d failed, error:%s, %s", curAttempt, maxAttempts, ErrorToString(aError),
|
||||||
otThreadErrorToString(aError), aFrame.ToInfoString().AsCString());
|
aFrame.ToInfoString().AsCString());
|
||||||
}
|
}
|
||||||
else
|
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)
|
#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
@@ -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] 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).
|
* @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 kErrorNone Successfully scheduled the Active Scan request.
|
||||||
* @retval OT_ERROR_BUSY Could not schedule the scan (a scan is ongoing or scheduled).
|
* @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.
|
* 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] 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).
|
* @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 kErrorNone Accepted the Energy Scan request.
|
||||||
* @retval OT_ERROR_BUSY Could not start the energy scan.
|
* @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.
|
* 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.
|
* @param[in] aOobFrame A pointer to the frame.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully scheduled the frame transmission.
|
* @retval kErrorNone Successfully scheduled the frame transmission.
|
||||||
* @retval OT_ERROR_ALREADY MAC layer is busy sending a previously requested frame.
|
* @retval kErrorAlready MAC layer is busy sending a previously requested frame.
|
||||||
* @retval OT_ERROR_INVALID_STATE The MAC layer is not enabled.
|
* @retval kErrorInvalidState The MAC layer is not enabled.
|
||||||
* @retval OT_ERROR_INVALID_ARGS The argument @p aOobFrame is nullptr.
|
* @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.
|
* This method requests transmission of a data poll (MAC Data Request) frame.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Data poll transmission request is scheduled successfully.
|
* @retval kErrorNone Data poll transmission request is scheduled successfully.
|
||||||
* @retval OT_ERROR_ALREADY MAC is busy sending earlier poll transmission request.
|
* @retval kErrorAlready MAC is busy sending earlier poll transmission request.
|
||||||
* @retval OT_ERROR_INVALID_STATE The MAC layer is not enabled.
|
* @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.
|
* 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.
|
* @param[in] aChannel The IEEE 802.15.4 PAN Channel.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully set the IEEE 802.15.4 PAN Channel.
|
* @retval kErrorNone 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 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.
|
* 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.
|
* @param[in] aChannel A IEEE 802.15.4 channel.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully set the temporary channel
|
* @retval kErrorNone Successfully set the temporary channel
|
||||||
* @retval OT_ERROR_INVALID_ARGS The @p aChannel is not in the supported channel mask.
|
* @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.
|
* 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.
|
* @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 kErrorNone Successfully set the IEEE 802.15.4 Network Name.
|
||||||
* @retval OT_ERROR_INVALID_ARGS Given name is too long.
|
* @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.
|
* This method sets the IEEE 802.15.4 Network Name.
|
||||||
*
|
*
|
||||||
* @param[in] aNameData A name data (pointer to char buffer and length).
|
* @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 kErrorNone Successfully set the IEEE 802.15.4 Network Name.
|
||||||
* @retval OT_ERROR_INVALID_ARGS Given name is too long.
|
* @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)
|
#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.
|
* @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 kErrorNone Successfully set the Thread Domain Name.
|
||||||
* @retval OT_ERROR_INVALID_ARGS Given name is too long.
|
* @retval kErrorInvalidArgs Given name is too long.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError SetDomainName(const char *aNameString);
|
Error SetDomainName(const char *aNameString);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method sets the Thread Domain Name.
|
* This method sets the Thread Domain Name.
|
||||||
*
|
*
|
||||||
* @param[in] aNameData A name data (pointer to char buffer and length).
|
* @param[in] aNameData A name data (pointer to char buffer and length).
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully set the Thread Domain Name.
|
* @retval kErrorNone Successfully set the Thread Domain Name.
|
||||||
* @retval OT_ERROR_INVALID_ARGS Given name is too long.
|
* @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)
|
#endif // (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -482,11 +482,11 @@ public:
|
|||||||
* This method is called to handle a received frame.
|
* 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] 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,
|
* @param[in] aError kErrorNone when successfully received a frame,
|
||||||
* OT_ERROR_ABORT when reception was aborted and a frame was not received.
|
* 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.
|
* 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] aFrame The transmitted frame.
|
||||||
* @param[in] aAckFrame A pointer to the ACK frame, or nullptr if no ACK was received.
|
* @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,
|
* @param[in] aError kErrorNone when the frame was transmitted successfully,
|
||||||
* OT_ERROR_NO_ACK when the frame was transmitted but no ACK was received,
|
* kErrorNoAck when the frame was transmitted but no ACK was received,
|
||||||
* OT_ERROR_CHANNEL_ACCESS_FAILURE tx failed due to activity on the channel,
|
* kErrorChannelAccessFailure tx failed due to activity on the channel,
|
||||||
* OT_ERROR_ABORT when transmission was aborted for other reasons.
|
* kErrorAbort when transmission was aborted for other reasons.
|
||||||
* @param[in] aRetryCount Indicates number of transmission retries for this frame.
|
* @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
|
* @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).
|
* when there was an error in transmission (i.e., `aError` is not NONE).
|
||||||
@@ -516,7 +516,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
void RecordFrameTransmitStatus(const TxFrame &aFrame,
|
void RecordFrameTransmitStatus(const TxFrame &aFrame,
|
||||||
const RxFrame *aAckFrame,
|
const RxFrame *aAckFrame,
|
||||||
otError aError,
|
Error aError,
|
||||||
uint8_t aRetryCount,
|
uint8_t aRetryCount,
|
||||||
bool aWillRetx);
|
bool aWillRetx);
|
||||||
|
|
||||||
@@ -525,13 +525,13 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[in] aFrame The frame that was transmitted.
|
* @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] 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,
|
* @param[in] aError kErrorNone when the frame was transmitted successfully,
|
||||||
* OT_ERROR_NO_ACK when the frame was transmitted but no ACK was received,
|
* kErrorNoAck 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,
|
* kErrorChannelAccessFailure when the tx failed due to activity on the channel,
|
||||||
* OT_ERROR_ABORT when transmission was aborted for other reasons.
|
* 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.
|
* This method returns if an active scan is in progress.
|
||||||
@@ -795,10 +795,10 @@ private:
|
|||||||
};
|
};
|
||||||
#endif // OPENTHREAD_CONFIG_MAC_RETRY_SUCCESS_HISTOGRAM_ENABLE
|
#endif // OPENTHREAD_CONFIG_MAC_RETRY_SUCCESS_HISTOGRAM_ENABLE
|
||||||
|
|
||||||
otError ProcessReceiveSecurity(RxFrame &aFrame, const Address &aSrcAddr, Neighbor *aNeighbor);
|
Error ProcessReceiveSecurity(RxFrame &aFrame, const Address &aSrcAddr, Neighbor *aNeighbor);
|
||||||
void ProcessTransmitSecurity(TxFrame &aFrame);
|
void ProcessTransmitSecurity(TxFrame &aFrame);
|
||||||
#if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2
|
#if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2
|
||||||
otError ProcessEnhAckSecurity(TxFrame &aTxFrame, RxFrame &aAckFrame);
|
Error ProcessEnhAckSecurity(TxFrame &aTxFrame, RxFrame &aAckFrame);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void UpdateIdleMode(void);
|
void UpdateIdleMode(void);
|
||||||
@@ -817,16 +817,16 @@ private:
|
|||||||
void HandleTimer(void);
|
void HandleTimer(void);
|
||||||
static void HandleOperationTask(Tasklet &aTasklet);
|
static void HandleOperationTask(Tasklet &aTasklet);
|
||||||
|
|
||||||
void Scan(Operation aScanOperation, uint32_t aScanChannels, uint16_t aScanDuration);
|
void Scan(Operation aScanOperation, uint32_t aScanChannels, uint16_t aScanDuration);
|
||||||
otError UpdateScanChannel(void);
|
Error UpdateScanChannel(void);
|
||||||
void PerformActiveScan(void);
|
void PerformActiveScan(void);
|
||||||
void ReportActiveScanResult(const RxFrame *aBeaconFrame);
|
void ReportActiveScanResult(const RxFrame *aBeaconFrame);
|
||||||
otError ConvertBeaconToActiveScanResult(const RxFrame *aBeaconFrame, ActiveScanResult &aResult);
|
Error ConvertBeaconToActiveScanResult(const RxFrame *aBeaconFrame, ActiveScanResult &aResult);
|
||||||
void PerformEnergyScan(void);
|
void PerformEnergyScan(void);
|
||||||
void ReportEnergyScanResult(int8_t aRssi);
|
void ReportEnergyScanResult(int8_t aRssi);
|
||||||
|
|
||||||
void LogFrameRxFailure(const RxFrame *aFrame, otError aError) const;
|
void LogFrameRxFailure(const RxFrame *aFrame, Error aError) const;
|
||||||
void LogFrameTxFailure(const TxFrame &aFrame, otError aError, uint8_t aRetryCount, bool aWillRetx) const;
|
void LogFrameTxFailure(const TxFrame &aFrame, Error aError, uint8_t aRetryCount, bool aWillRetx) const;
|
||||||
void LogBeacon(const char *aActionText, const BeaconPayload &aBeaconPayload) const;
|
void LogBeacon(const char *aActionText, const BeaconPayload &aBeaconPayload) const;
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
|
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
|
||||||
@@ -917,7 +917,7 @@ private:
|
|||||||
|
|
||||||
#if OPENTHREAD_CONFIG_MULTI_RADIO
|
#if OPENTHREAD_CONFIG_MULTI_RADIO
|
||||||
RadioTypes mTxPendingRadioLinks;
|
RadioTypes mTxPendingRadioLinks;
|
||||||
otError mTxError;
|
Error mTxError;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_MAC_FILTER_ENABLE
|
#if OPENTHREAD_CONFIG_MAC_FILTER_ENABLE
|
||||||
|
|||||||
+17
-17
@@ -83,14 +83,14 @@ exit:
|
|||||||
return rval;
|
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);
|
FilterEntry *entry = FindEntry(aExtAddress);
|
||||||
|
|
||||||
if (entry == nullptr)
|
if (entry == nullptr)
|
||||||
{
|
{
|
||||||
VerifyOrExit((entry = FindAvailableEntry()) != nullptr, error = OT_ERROR_NO_BUFS);
|
VerifyOrExit((entry = FindAvailableEntry()) != nullptr, error = kErrorNoBufs);
|
||||||
entry->mExtAddress = aExtAddress;
|
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++)
|
for (; aIterator < OT_ARRAY_LENGTH(mFilterEntries); aIterator++)
|
||||||
{
|
{
|
||||||
@@ -130,7 +130,7 @@ otError Filter::GetNextAddress(Iterator &aIterator, Entry &aEntry) const
|
|||||||
{
|
{
|
||||||
aEntry.mExtAddress = entry.mExtAddress;
|
aEntry.mExtAddress = entry.mExtAddress;
|
||||||
aEntry.mRssIn = entry.mRssIn;
|
aEntry.mRssIn = entry.mRssIn;
|
||||||
error = OT_ERROR_NONE;
|
error = kErrorNone;
|
||||||
aIterator++;
|
aIterator++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -139,15 +139,15 @@ otError Filter::GetNextAddress(Iterator &aIterator, Entry &aEntry) const
|
|||||||
return error;
|
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);
|
FilterEntry *entry = FindEntry(aExtAddress);
|
||||||
|
|
||||||
if (entry == nullptr)
|
if (entry == nullptr)
|
||||||
{
|
{
|
||||||
entry = FindAvailableEntry();
|
entry = FindAvailableEntry();
|
||||||
VerifyOrExit(entry != nullptr, error = OT_ERROR_NO_BUFS);
|
VerifyOrExit(entry != nullptr, error = kErrorNoBufs);
|
||||||
|
|
||||||
entry->mExtAddress = aExtAddress;
|
entry->mExtAddress = aExtAddress;
|
||||||
}
|
}
|
||||||
@@ -180,9 +180,9 @@ void Filter::ClearAllRssIn(void)
|
|||||||
mDefaultRssIn = kFixedRssDisabled;
|
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++)
|
for (; aIterator < OT_ARRAY_LENGTH(mFilterEntries); aIterator++)
|
||||||
{
|
{
|
||||||
@@ -192,7 +192,7 @@ otError Filter::GetNextRssIn(Iterator &aIterator, Entry &aEntry)
|
|||||||
{
|
{
|
||||||
aEntry.mExtAddress = entry.mExtAddress;
|
aEntry.mExtAddress = entry.mExtAddress;
|
||||||
aEntry.mRssIn = entry.mRssIn;
|
aEntry.mRssIn = entry.mRssIn;
|
||||||
error = OT_ERROR_NONE;
|
error = kErrorNone;
|
||||||
aIterator++;
|
aIterator++;
|
||||||
ExitNow();
|
ExitNow();
|
||||||
}
|
}
|
||||||
@@ -203,7 +203,7 @@ otError Filter::GetNextRssIn(Iterator &aIterator, Entry &aEntry)
|
|||||||
{
|
{
|
||||||
static_cast<ExtAddress &>(aEntry.mExtAddress).Fill(0xff);
|
static_cast<ExtAddress &>(aEntry.mExtAddress).Fill(0xff);
|
||||||
aEntry.mRssIn = mDefaultRssIn;
|
aEntry.mRssIn = mDefaultRssIn;
|
||||||
error = OT_ERROR_NONE;
|
error = kErrorNone;
|
||||||
aIterator++;
|
aIterator++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,9 +211,9 @@ exit:
|
|||||||
return error;
|
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);
|
FilterEntry *entry = FindEntry(aExtAddress);
|
||||||
bool isInFilterList;
|
bool isInFilterList;
|
||||||
|
|
||||||
@@ -231,11 +231,11 @@ otError Filter::Apply(const ExtAddress &aExtAddress, int8_t &aRss)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case kModeAllowlist:
|
case kModeAllowlist:
|
||||||
VerifyOrExit(isInFilterList, error = OT_ERROR_ADDRESS_FILTERED);
|
VerifyOrExit(isInFilterList, error = kErrorAddressFiltered);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kModeDenylist:
|
case kModeDenylist:
|
||||||
VerifyOrExit(!isInFilterList, error = OT_ERROR_ADDRESS_FILTERED);
|
VerifyOrExit(!isInFilterList, error = kErrorAddressFiltered);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+15
-16
@@ -117,11 +117,11 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[in] aExtAddress A reference to the Extended Address.
|
* @param[in] aExtAddress A reference to the Extended Address.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully added @p aExtAddress to the filter.
|
* @retval kErrorNone Successfully added @p aExtAddress to the filter.
|
||||||
* @retval OT_ERROR_NO_BUFS No available entry exists.
|
* @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.
|
* 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.
|
* 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.
|
* @param[out] aEntry A reference to where the information is placed.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully retrieved the next address filter entry.
|
* @retval kErrorNone Successfully retrieved the next address filter entry.
|
||||||
* @retval OT_ERROR_NOT_FOUND No subsequent entry exists.
|
* @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.
|
* 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] aExtAddress An Extended Address
|
||||||
* @param[in] aRss The received signal strength to set.
|
* @param[in] aRss The received signal strength to set.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully set @p aRss for @p aExtAddress.
|
* @retval kErrorNone Successfully set @p aRss for @p aExtAddress.
|
||||||
* @retval OT_ERROR_NO_BUFS No available entry exists.
|
* @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.
|
* 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
|
* Extended Address as all 0xff to indicate the default received signal strength
|
||||||
* if it was set.
|
* if it was set.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully retrieved the next RssIn filter entry.
|
* @retval kErrorNone Successfully retrieved the next RssIn filter entry.
|
||||||
* @retval OT_ERROR_NOT_FOUND No subsequent entry exists.
|
* @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.
|
* 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[in] aExtAddress A reference to the Extended Address.
|
||||||
* @param[out] aRss A reference to where the received signal strength to be placed.
|
* @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 kErrorNone Successfully applied the filter rules on @p aExtAddress.
|
||||||
* @retval OT_ERROR_ADDRESS_FILTERED Address filter (allowlist or denylist) is enabled and @p aExtAddress is
|
* @retval kErrorAddressFiltered Address filter (allowlist or denylist) is enabled and @p aExtAddress is filtered.
|
||||||
* filtered.
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError Apply(const ExtAddress &aExtAddress, int8_t &aRss);
|
Error Apply(const ExtAddress &aExtAddress, int8_t &aRss);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum
|
enum
|
||||||
|
|||||||
+56
-56
@@ -86,13 +86,13 @@ uint16_t Frame::GetFrameControlField(void) const
|
|||||||
return ReadUint16(mPsdu);
|
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();
|
uint8_t index = FindPayloadIndex();
|
||||||
|
|
||||||
VerifyOrExit(index != kInvalidIndex, error = OT_ERROR_PARSE);
|
VerifyOrExit(index != kInvalidIndex, error = kErrorParse);
|
||||||
VerifyOrExit((index + GetFooterLength()) <= mLength, error = OT_ERROR_PARSE);
|
VerifyOrExit((index + GetFooterLength()) <= mLength, error = kErrorParse);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return error;
|
return error;
|
||||||
@@ -166,12 +166,12 @@ bool Frame::IsDstPanIdPresent(uint16_t aFcf)
|
|||||||
return present;
|
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();
|
uint8_t index = FindDstPanIdIndex();
|
||||||
|
|
||||||
VerifyOrExit(index != kInvalidIndex, error = OT_ERROR_PARSE);
|
VerifyOrExit(index != kInvalidIndex, error = kErrorParse);
|
||||||
aPanId = ReadUint16(&mPsdu[index]);
|
aPanId = ReadUint16(&mPsdu[index]);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
@@ -191,12 +191,12 @@ uint8_t Frame::FindDstAddrIndex(void) const
|
|||||||
return kFcfSize + kDsnSize + (IsDstPanIdPresent() ? sizeof(PanId) : 0);
|
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();
|
uint8_t index = FindDstAddrIndex();
|
||||||
|
|
||||||
VerifyOrExit(index != kInvalidIndex, error = OT_ERROR_PARSE);
|
VerifyOrExit(index != kInvalidIndex, error = kErrorParse);
|
||||||
|
|
||||||
switch (GetFrameControlField() & kFcfDstAddrMask)
|
switch (GetFrameControlField() & kFcfDstAddrMask)
|
||||||
{
|
{
|
||||||
@@ -304,24 +304,24 @@ bool Frame::IsSrcPanIdPresent(uint16_t aFcf)
|
|||||||
return srcPanIdPresent;
|
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();
|
uint8_t index = FindSrcPanIdIndex();
|
||||||
|
|
||||||
VerifyOrExit(index != kInvalidIndex, error = OT_ERROR_PARSE);
|
VerifyOrExit(index != kInvalidIndex, error = kErrorParse);
|
||||||
aPanId = ReadUint16(&mPsdu[index]);
|
aPanId = ReadUint16(&mPsdu[index]);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Frame::SetSrcPanId(PanId aPanId)
|
Error Frame::SetSrcPanId(PanId aPanId)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
uint8_t index = FindSrcPanIdIndex();
|
uint8_t index = FindSrcPanIdIndex();
|
||||||
|
|
||||||
VerifyOrExit(index != kInvalidIndex, error = OT_ERROR_PARSE);
|
VerifyOrExit(index != kInvalidIndex, error = kErrorParse);
|
||||||
WriteUint16(aPanId, &mPsdu[index]);
|
WriteUint16(aPanId, &mPsdu[index]);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
@@ -359,13 +359,13 @@ uint8_t Frame::FindSrcAddrIndex(void) const
|
|||||||
return index;
|
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();
|
uint8_t index = FindSrcAddrIndex();
|
||||||
uint16_t fcf = GetFrameControlField();
|
uint16_t fcf = GetFrameControlField();
|
||||||
|
|
||||||
VerifyOrExit(index != kInvalidIndex, error = OT_ERROR_PARSE);
|
VerifyOrExit(index != kInvalidIndex, error = kErrorParse);
|
||||||
|
|
||||||
switch (fcf & kFcfSrcAddrMask)
|
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();
|
uint8_t index = FindSecurityHeaderIndex();
|
||||||
|
|
||||||
VerifyOrExit(index != kInvalidIndex, error = OT_ERROR_PARSE);
|
VerifyOrExit(index != kInvalidIndex, error = kErrorParse);
|
||||||
|
|
||||||
aSecurityControlField = mPsdu[index];
|
aSecurityControlField = mPsdu[index];
|
||||||
|
|
||||||
@@ -457,12 +457,12 @@ exit:
|
|||||||
return index;
|
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();
|
uint8_t index = FindSecurityHeaderIndex();
|
||||||
|
|
||||||
VerifyOrExit(index != kInvalidIndex, error = OT_ERROR_PARSE);
|
VerifyOrExit(index != kInvalidIndex, error = kErrorParse);
|
||||||
|
|
||||||
aSecurityLevel = mPsdu[index] & kSecLevelMask;
|
aSecurityLevel = mPsdu[index] & kSecLevelMask;
|
||||||
|
|
||||||
@@ -470,12 +470,12 @@ exit:
|
|||||||
return error;
|
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();
|
uint8_t index = FindSecurityHeaderIndex();
|
||||||
|
|
||||||
VerifyOrExit(index != kInvalidIndex, error = OT_ERROR_PARSE);
|
VerifyOrExit(index != kInvalidIndex, error = kErrorParse);
|
||||||
|
|
||||||
aKeyIdMode = mPsdu[index] & kKeyIdModeMask;
|
aKeyIdMode = mPsdu[index] & kKeyIdModeMask;
|
||||||
|
|
||||||
@@ -483,12 +483,12 @@ exit:
|
|||||||
return error;
|
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();
|
uint8_t index = FindSecurityHeaderIndex();
|
||||||
|
|
||||||
VerifyOrExit(index != kInvalidIndex, error = OT_ERROR_PARSE);
|
VerifyOrExit(index != kInvalidIndex, error = kErrorParse);
|
||||||
|
|
||||||
// Security Control
|
// Security Control
|
||||||
index += kSecurityControlSize;
|
index += kSecurityControlSize;
|
||||||
@@ -558,9 +558,9 @@ void Frame::SetKeySource(const uint8_t *aKeySource)
|
|||||||
memcpy(&mPsdu[index + kSecurityControlSize + kFrameCounterSize], aKeySource, keySourceLength);
|
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 keySourceLength;
|
||||||
uint8_t index = FindSecurityHeaderIndex();
|
uint8_t index = FindSecurityHeaderIndex();
|
||||||
|
|
||||||
@@ -586,11 +586,11 @@ void Frame::SetKeyId(uint8_t aKeyId)
|
|||||||
mPsdu[index + kSecurityControlSize + kFrameCounterSize + keySourceLength] = 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();
|
uint8_t index = FindPayloadIndex();
|
||||||
VerifyOrExit(index != kInvalidIndex, error = OT_ERROR_PARSE);
|
VerifyOrExit(index != kInvalidIndex, error = kErrorParse);
|
||||||
|
|
||||||
aCommandId = mPsdu[IsVersion2015() ? index : (index - 1)];
|
aCommandId = mPsdu[IsVersion2015() ? index : (index - 1)];
|
||||||
|
|
||||||
@@ -598,12 +598,12 @@ exit:
|
|||||||
return error;
|
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();
|
uint8_t index = FindPayloadIndex();
|
||||||
|
|
||||||
VerifyOrExit(index != kInvalidIndex, error = OT_ERROR_PARSE);
|
VerifyOrExit(index != kInvalidIndex, error = kErrorParse);
|
||||||
|
|
||||||
mPsdu[IsVersion2015() ? index : (index - 1)] = aCommandId;
|
mPsdu[IsVersion2015() ? index : (index - 1)] = aCommandId;
|
||||||
|
|
||||||
@@ -894,9 +894,9 @@ exit:
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT
|
#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));
|
SuccessOrExit(error = InitIeHeaderAt(aIndex, IeType::kHeaderIeId, IeType::kIeContentSize));
|
||||||
|
|
||||||
@@ -906,16 +906,16 @@ exit:
|
|||||||
return error;
|
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)
|
if (aIndex == 0)
|
||||||
{
|
{
|
||||||
aIndex = FindHeaderIeIndex();
|
aIndex = FindHeaderIeIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
VerifyOrExit(aIndex != kInvalidIndex, error = OT_ERROR_NOT_FOUND);
|
VerifyOrExit(aIndex != kInvalidIndex, error = kErrorNotFound);
|
||||||
|
|
||||||
reinterpret_cast<HeaderIe *>(mPsdu + aIndex)->Init(ieId, ieContentSize);
|
reinterpret_cast<HeaderIe *>(mPsdu + aIndex)->Init(ieId, ieContentSize);
|
||||||
aIndex += sizeof(HeaderIe);
|
aIndex += sizeof(HeaderIe);
|
||||||
@@ -1123,12 +1123,12 @@ uint8_t Frame::GetFcsSize(void) const
|
|||||||
// Explicit instantiation
|
// Explicit instantiation
|
||||||
#if OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT
|
#if OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT
|
||||||
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
|
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
|
||||||
template otError Frame::AppendHeaderIeAt<TimeIe>(uint8_t &aIndex);
|
template Error Frame::AppendHeaderIeAt<TimeIe>(uint8_t &aIndex);
|
||||||
#endif
|
#endif
|
||||||
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
|
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
|
||||||
template otError Frame::AppendHeaderIeAt<CslIe>(uint8_t &aIndex);
|
template Error Frame::AppendHeaderIeAt<CslIe>(uint8_t &aIndex);
|
||||||
#endif
|
#endif
|
||||||
template otError Frame::AppendHeaderIeAt<Termination2Ie>(uint8_t &aIndex);
|
template Error Frame::AppendHeaderIeAt<Termination2Ie>(uint8_t &aIndex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void TxFrame::CopyFrom(const TxFrame &aFromFrame)
|
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
|
#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;
|
uint16_t fcf = kFcfFrameAck | kFcfFrameVersion2015 | kFcfSrcAddrNone;
|
||||||
Address address;
|
Address address;
|
||||||
@@ -1289,7 +1289,7 @@ otError TxFrame::GenerateEnhAck(const RxFrame &aFrame, bool aIsFramePending, con
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ExitNow(error = OT_ERROR_PARSE);
|
ExitNow(error = kErrorParse);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetDstPanId(panId);
|
SetDstPanId(panId);
|
||||||
@@ -1332,15 +1332,15 @@ exit:
|
|||||||
}
|
}
|
||||||
#endif // OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2
|
#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
|
#if OPENTHREAD_RADIO
|
||||||
OT_UNUSED_VARIABLE(aExtAddress);
|
OT_UNUSED_VARIABLE(aExtAddress);
|
||||||
OT_UNUSED_VARIABLE(aMacKey);
|
OT_UNUSED_VARIABLE(aMacKey);
|
||||||
|
|
||||||
return OT_ERROR_NONE;
|
return kErrorNone;
|
||||||
#else
|
#else
|
||||||
otError error = OT_ERROR_SECURITY;
|
Error error = kErrorSecurity;
|
||||||
uint32_t frameCounter = 0;
|
uint32_t frameCounter = 0;
|
||||||
uint8_t securityLevel;
|
uint8_t securityLevel;
|
||||||
uint8_t nonce[Crypto::AesCcm::kNonceSize];
|
uint8_t nonce[Crypto::AesCcm::kNonceSize];
|
||||||
@@ -1348,7 +1348,7 @@ otError RxFrame::ProcessReceiveAesCcm(const ExtAddress &aExtAddress, const Key &
|
|||||||
uint8_t tagLength;
|
uint8_t tagLength;
|
||||||
Crypto::AesCcm aesCcm;
|
Crypto::AesCcm aesCcm;
|
||||||
|
|
||||||
VerifyOrExit(GetSecurityEnabled(), error = OT_ERROR_NONE);
|
VerifyOrExit(GetSecurityEnabled(), error = kErrorNone);
|
||||||
|
|
||||||
SuccessOrExit(GetSecurityLevel(securityLevel));
|
SuccessOrExit(GetSecurityLevel(securityLevel));
|
||||||
SuccessOrExit(GetFrameCounter(frameCounter));
|
SuccessOrExit(GetFrameCounter(frameCounter));
|
||||||
@@ -1373,7 +1373,7 @@ otError RxFrame::ProcessReceiveAesCcm(const ExtAddress &aExtAddress, const Key &
|
|||||||
VerifyOrExit(memcmp(tag, GetFooter(), tagLength) == 0);
|
VerifyOrExit(memcmp(tag, GetFooter(), tagLength) == 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
error = OT_ERROR_NONE;
|
error = kErrorNone;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return error;
|
return error;
|
||||||
@@ -1409,7 +1409,7 @@ Frame::InfoString Frame::ToInfoString(void) const
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case kFcfFrameMacCmd:
|
case kFcfFrameMacCmd:
|
||||||
if (GetCommandId(commandId) != OT_ERROR_NONE)
|
if (GetCommandId(commandId) != kErrorNone)
|
||||||
{
|
{
|
||||||
commandId = 0xff;
|
commandId = 0xff;
|
||||||
}
|
}
|
||||||
|
|||||||
+39
-39
@@ -407,11 +407,11 @@ public:
|
|||||||
/**
|
/**
|
||||||
* This method validates the frame.
|
* This method validates the frame.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully parsed the MAC header.
|
* @retval kErrorNone Successfully parsed the MAC header.
|
||||||
* @retval OT_ERROR_PARSE Failed to parse through 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.
|
* This method returns the IEEE 802.15.4 Frame Type.
|
||||||
@@ -536,11 +536,11 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[out] aPanId The Destination PAN Identifier.
|
* @param[out] aPanId The Destination PAN Identifier.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully retrieved the Destination PAN Identifier.
|
* @retval kErrorNone Successfully retrieved the Destination PAN Identifier.
|
||||||
* @retval OT_ERROR_PARSE Failed to parse the 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.
|
* This method sets the Destination PAN Identifier.
|
||||||
@@ -563,10 +563,10 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[out] aAddress The Destination Address.
|
* @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.
|
* This method sets the Destination Address.
|
||||||
@@ -605,20 +605,20 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[out] aPanId The Source PAN Identifier.
|
* @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.
|
* This method sets the Source PAN Identifier.
|
||||||
*
|
*
|
||||||
* @param[in] aPanId 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.
|
* 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.
|
* @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.
|
* This method sets the Source Address.
|
||||||
@@ -667,11 +667,11 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[out] aSecurityControlField The Security Control Field.
|
* @param[out] aSecurityControlField The Security Control Field.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully retrieved the Security Level Identifier.
|
* @retval kErrorNone Successfully retrieved the Security Level Identifier.
|
||||||
* @retval OT_ERROR_PARSE Failed to find the security control field in the frame.
|
* @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.
|
* This method sets the Security Control Field.
|
||||||
@@ -686,30 +686,30 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[out] aSecurityLevel The Security Level Identifier.
|
* @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.
|
* This method gets the Key Identifier Mode.
|
||||||
*
|
*
|
||||||
* @param[out] aSecurityLevel 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.
|
* This method gets the Frame Counter.
|
||||||
*
|
*
|
||||||
* @param[out] aFrameCounter 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.
|
* This method sets the Frame Counter.
|
||||||
@@ -740,10 +740,10 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[out] aKeyId The Key Identifier.
|
* @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.
|
* This method sets the Key Identifier.
|
||||||
@@ -758,20 +758,20 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[out] aCommandId The Command ID.
|
* @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.
|
* This method sets the Command ID.
|
||||||
*
|
*
|
||||||
* @param[in] aCommandId 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).
|
* 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
|
* @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.
|
* and an enum `kIeContentSize` indicating the IE body's size.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully appended the Header IE.
|
* @retval kErrorNone Successfully appended the Header IE.
|
||||||
* @retval OT_ERROR_NOT_FOUND The position for first IE is not found.
|
* @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.
|
* This method returns a pointer to the Header IE.
|
||||||
@@ -1121,7 +1121,7 @@ protected:
|
|||||||
#if OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT
|
#if OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT
|
||||||
uint8_t FindHeaderIeIndex(void) const;
|
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);
|
template <typename IeType> void InitIeContentAt(uint8_t &aIndex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1203,11 +1203,11 @@ public:
|
|||||||
* for AES CCM computation.
|
* for AES CCM computation.
|
||||||
* @param[in] aMacKey A reference to the MAC key to decrypt the received frame.
|
* @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 kErrorNone Process of received frame AES CCM succeeded.
|
||||||
* @retval OT_ERROR_SECURITY Received frame MIC check failed.
|
* @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
|
#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] 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.
|
* @param[in] aIeLength The length of IE data portion of the ACK to be sent.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully generated Enh Ack.
|
* @retval kErrorNone Successfully generated Enh Ack.
|
||||||
* @retval OT_ERROR_PARSE @p aFrame has incorrect format.
|
* @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
|
#if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -159,9 +159,9 @@ void Links::Send(TxFrame &aFrame, RadioTypes aRadioTypes)
|
|||||||
#if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
|
#if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
|
||||||
if (aRadioTypes.Contains(kRadioTypeIeee802154))
|
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);
|
OT_UNUSED_VARIABLE(error);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -513,8 +513,8 @@ public:
|
|||||||
{
|
{
|
||||||
#if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
|
#if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
|
||||||
{
|
{
|
||||||
otError error = mSubMac.Send();
|
Error error = mSubMac.Send();
|
||||||
OT_ASSERT(error == OT_ERROR_NONE);
|
OT_ASSERT(error == kErrorNone);
|
||||||
OT_UNUSED_VARIABLE(error);
|
OT_UNUSED_VARIABLE(error);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -576,12 +576,12 @@ public:
|
|||||||
* @param[in] aScanChannel The channel to perform the energy scan on.
|
* @param[in] aScanChannel The channel to perform the energy scan on.
|
||||||
* @param[in] aScanDuration The duration, in milliseconds, for the channel to be scanned.
|
* @param[in] aScanDuration The duration, in milliseconds, for the channel to be scanned.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully started scanning the channel.
|
* @retval kErrorNone Successfully started scanning the channel.
|
||||||
* @retval OT_ERROR_INVALID_STATE The radio was disabled or transmitting.
|
* @retval kErrorInvalidState The radio was disabled or transmitting.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED Energy scan is not supported by radio link.
|
* @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(aScanChannel);
|
||||||
OT_UNUSED_VARIABLE(aScanDuration);
|
OT_UNUSED_VARIABLE(aScanDuration);
|
||||||
@@ -590,7 +590,7 @@ public:
|
|||||||
#if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
|
#if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
|
||||||
mSubMac.EnergyScan(aScanChannel, aScanDuration);
|
mSubMac.EnergyScan(aScanChannel, aScanDuration);
|
||||||
#else
|
#else
|
||||||
OT_ERROR_NOT_IMPLEMENTED;
|
kErrorNotImplemented;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -654,8 +654,8 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[in] TxFrame The `TxFrame` from which to get the counter value.
|
* @param[in] TxFrame The `TxFrame` from which to get the counter value.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE If successful.
|
* @retval kErrorNone If successful.
|
||||||
* @retval OT_ERROR_INVALID_STATE If the raw link-layer isn't enabled.
|
* @retval kErrorInvalidState If the raw link-layer isn't enabled.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void SetMacFrameCounter(TxFrame &aFrame);
|
void SetMacFrameCounter(TxFrame &aFrame);
|
||||||
|
|||||||
@@ -128,15 +128,15 @@ NameData NetworkName::GetAsData(void) const
|
|||||||
return NameData(m8, len);
|
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()));
|
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.
|
// 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);
|
memcpy(m8, aNameData.GetBuffer(), newLen);
|
||||||
m8[newLen] = '\0';
|
m8[newLen] = '\0';
|
||||||
@@ -162,15 +162,15 @@ NameData DomainName::GetAsData(void) const
|
|||||||
return NameData(m8, len);
|
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()));
|
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.
|
// 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);
|
memcpy(m8, aNameData.GetBuffer(), newLen);
|
||||||
m8[newLen] = '\0';
|
m8[newLen] = '\0';
|
||||||
|
|||||||
@@ -564,12 +564,12 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[in] aNameData A reference to name data.
|
* @param[in] aNameData A reference to name data.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully set the IEEE 802.15.4 Network Name.
|
* @retval kErrorNone Successfully set the IEEE 802.15.4 Network Name.
|
||||||
* @retval OT_ERROR_ALREADY The name is already set to the same string.
|
* @retval kErrorAlready The name is already set to the same string.
|
||||||
* @retval OT_ERROR_INVALID_ARGS Given name is too long.
|
* @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.
|
* 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.
|
* @param[in] aNameData A reference to name data.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully set the Thread Domain Name.
|
* @retval kErrorNone Successfully set the Thread Domain Name.
|
||||||
* @retval OT_ERROR_ALREADY The name is already set to the same string.
|
* @retval kErrorAlready The name is already set to the same string.
|
||||||
* @retval OT_ERROR_INVALID_ARGS Given name is too long.
|
* @retval kErrorInvalidArgs Given name is too long.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError Set(const NameData &aNameData);
|
Error Set(const NameData &aNameData);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char m8[kMaxSize + 1]; ///< Byte values.
|
char m8[kMaxSize + 1]; ///< Byte values.
|
||||||
|
|||||||
+42
-43
@@ -151,9 +151,9 @@ void SubMac::SetPcapCallback(otLinkPcapCallback aPcapCallback, void *aCallbackCo
|
|||||||
mPcapCallbackContext = aCallbackContext;
|
mPcapCallbackContext = aCallbackContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError SubMac::Enable(void)
|
Error SubMac::Enable(void)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
|
|
||||||
VerifyOrExit(mState == kStateDisabled);
|
VerifyOrExit(mState == kStateDisabled);
|
||||||
|
|
||||||
@@ -163,13 +163,13 @@ otError SubMac::Enable(void)
|
|||||||
SetState(kStateSleep);
|
SetState(kStateSleep);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
OT_ASSERT(error == OT_ERROR_NONE);
|
OT_ASSERT(error == kErrorNone);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError SubMac::Disable(void)
|
Error SubMac::Disable(void)
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
mTimer.Stop();
|
mTimer.Stop();
|
||||||
SuccessOrExit(error = Get<Radio>().Sleep());
|
SuccessOrExit(error = Get<Radio>().Sleep());
|
||||||
@@ -180,13 +180,13 @@ exit:
|
|||||||
return error;
|
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();
|
ExitNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,13 +196,13 @@ exit:
|
|||||||
return error;
|
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();
|
ExitNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,9 +213,9 @@ exit:
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
|
#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())
|
if (!IsCslChannelSpecified())
|
||||||
{
|
{
|
||||||
@@ -233,7 +233,7 @@ otError SubMac::CslSample(uint8_t aPanChannel)
|
|||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case kCslIdle:
|
case kCslIdle:
|
||||||
ExitNow(error = OT_ERROR_INVALID_STATE);
|
ExitNow(error = kErrorInvalidState);
|
||||||
default:
|
default:
|
||||||
OT_ASSERT(false);
|
OT_ASSERT(false);
|
||||||
}
|
}
|
||||||
@@ -241,17 +241,17 @@ otError SubMac::CslSample(uint8_t aPanChannel)
|
|||||||
SetState(kStateCslSample);
|
SetState(kStateCslSample);
|
||||||
|
|
||||||
exit:
|
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;
|
return error;
|
||||||
}
|
}
|
||||||
#endif
|
#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);
|
mPcapCallback(aFrame, false, mPcapCallbackContext);
|
||||||
}
|
}
|
||||||
@@ -262,7 +262,7 @@ void SubMac::HandleReceiveDone(RxFrame *aFrame, otError aError)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_MAC_CSL_DEBUG_ENABLE
|
#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
|
// Split the log into two lines for RTT to output
|
||||||
otLogDebgMac("Received frame in state (SubMac %s, CSL %s), timestamp %u", StateToString(mState),
|
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);
|
mCallbacks.ReceiveDone(aFrame, aError);
|
||||||
}
|
}
|
||||||
|
|
||||||
otError SubMac::Send(void)
|
Error SubMac::Send(void)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
|
|
||||||
switch (mState)
|
switch (mState)
|
||||||
{
|
{
|
||||||
@@ -288,7 +288,7 @@ otError SubMac::Send(void)
|
|||||||
#endif
|
#endif
|
||||||
case kStateTransmit:
|
case kStateTransmit:
|
||||||
case kStateEnergyScan:
|
case kStateEnergyScan:
|
||||||
ExitNow(error = OT_ERROR_INVALID_STATE);
|
ExitNow(error = kErrorInvalidState);
|
||||||
OT_UNREACHABLE_CODE(break);
|
OT_UNREACHABLE_CODE(break);
|
||||||
|
|
||||||
case kStateSleep:
|
case kStateSleep:
|
||||||
@@ -409,7 +409,7 @@ exit:
|
|||||||
|
|
||||||
void SubMac::BeginTransmit(void)
|
void SubMac::BeginTransmit(void)
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
OT_UNUSED_VARIABLE(error);
|
OT_UNUSED_VARIABLE(error);
|
||||||
|
|
||||||
@@ -422,7 +422,7 @@ void SubMac::BeginTransmit(void)
|
|||||||
if ((mRadioCaps & OT_RADIO_CAPS_SLEEP_TO_TX) == 0)
|
if ((mRadioCaps & OT_RADIO_CAPS_SLEEP_TO_TX) == 0)
|
||||||
{
|
{
|
||||||
error = Get<Radio>().Receive(mTransmitFrame.GetChannel());
|
error = Get<Radio>().Receive(mTransmitFrame.GetChannel());
|
||||||
OT_ASSERT(error == OT_ERROR_NONE);
|
OT_ASSERT(error == kErrorNone);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetState(kStateTransmit);
|
SetState(kStateTransmit);
|
||||||
@@ -433,14 +433,14 @@ void SubMac::BeginTransmit(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
error = Get<Radio>().Transmit(mTransmitFrame);
|
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.
|
// Platform `transmit_at` fails and we send the frame directly.
|
||||||
mTransmitFrame.mInfo.mTxInfo.mTxDelay = 0;
|
mTransmitFrame.mInfo.mTxInfo.mTxDelay = 0;
|
||||||
mTransmitFrame.mInfo.mTxInfo.mTxDelayBaseTime = 0;
|
mTransmitFrame.mInfo.mTxInfo.mTxDelayBaseTime = 0;
|
||||||
error = Get<Radio>().Transmit(mTransmitFrame);
|
error = Get<Radio>().Transmit(mTransmitFrame);
|
||||||
}
|
}
|
||||||
OT_ASSERT(error == OT_ERROR_NONE);
|
OT_ASSERT(error == kErrorNone);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return;
|
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 ccaSuccess = true;
|
||||||
bool shouldRetx;
|
bool shouldRetx;
|
||||||
@@ -471,18 +471,18 @@ void SubMac::HandleTransmitDone(TxFrame &aFrame, RxFrame *aAckFrame, otError aEr
|
|||||||
|
|
||||||
switch (aError)
|
switch (aError)
|
||||||
{
|
{
|
||||||
case OT_ERROR_ABORT:
|
case kErrorAbort:
|
||||||
// Do not record CCA status in case of `ABORT` error
|
// Do not record CCA status in case of `ABORT` error
|
||||||
// since there may be no CCA check performed by radio.
|
// since there may be no CCA check performed by radio.
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OT_ERROR_CHANNEL_ACCESS_FAILURE:
|
case kErrorChannelAccessFailure:
|
||||||
ccaSuccess = false;
|
ccaSuccess = false;
|
||||||
|
|
||||||
OT_FALL_THROUGH;
|
OT_FALL_THROUGH;
|
||||||
|
|
||||||
case OT_ERROR_NONE:
|
case kErrorNone:
|
||||||
case OT_ERROR_NO_ACK:
|
case kErrorNoAck:
|
||||||
if (aFrame.IsCsmaCaEnabled())
|
if (aFrame.IsCsmaCaEnabled())
|
||||||
{
|
{
|
||||||
mCallbacks.RecordCcaStatus(ccaSuccess, aFrame.GetChannel());
|
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.
|
// Determine whether to re-transmit the frame.
|
||||||
|
|
||||||
shouldRetx =
|
shouldRetx = ((aError != kErrorNone) && ShouldHandleRetries() && (mTransmitRetries < aFrame.GetMaxFrameRetries()));
|
||||||
((aError != OT_ERROR_NONE) && ShouldHandleRetries() && (mTransmitRetries < aFrame.GetMaxFrameRetries()));
|
|
||||||
|
|
||||||
mCallbacks.RecordFrameTransmitStatus(aFrame, aAckFrame, aError, mTransmitRetries, shouldRetx);
|
mCallbacks.RecordFrameTransmitStatus(aFrame, aAckFrame, aError, mTransmitRetries, shouldRetx);
|
||||||
|
|
||||||
@@ -554,10 +553,10 @@ void SubMac::UpdateFrameCounterOnTxDone(const TxFrame &aFrame)
|
|||||||
allowError = Get<LinkRaw>().IsEnabled();
|
allowError = Get<LinkRaw>().IsEnabled();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
VerifyOrExit(aFrame.GetKeyIdMode(keyIdMode) == OT_ERROR_NONE, OT_ASSERT(allowError));
|
VerifyOrExit(aFrame.GetKeyIdMode(keyIdMode) == kErrorNone, OT_ASSERT(allowError));
|
||||||
VerifyOrExit(keyIdMode == Frame::kKeyIdMode1);
|
VerifyOrExit(keyIdMode == Frame::kKeyIdMode1);
|
||||||
|
|
||||||
VerifyOrExit(aFrame.GetFrameCounter(frameCounter) == OT_ERROR_NONE, OT_ASSERT(allowError));
|
VerifyOrExit(aFrame.GetFrameCounter(frameCounter) == kErrorNone, OT_ASSERT(allowError));
|
||||||
UpdateFrameCounter(frameCounter);
|
UpdateFrameCounter(frameCounter);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
@@ -574,9 +573,9 @@ int8_t SubMac::GetNoiseFloor(void)
|
|||||||
return Get<Radio>().GetReceiveSensitivity();
|
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)
|
switch (mState)
|
||||||
{
|
{
|
||||||
@@ -587,7 +586,7 @@ otError SubMac::EnergyScan(uint8_t aScanChannel, uint16_t aScanDuration)
|
|||||||
case kStateCslTransmit:
|
case kStateCslTransmit:
|
||||||
#endif
|
#endif
|
||||||
case kStateEnergyScan:
|
case kStateEnergyScan:
|
||||||
ExitNow(error = OT_ERROR_INVALID_STATE);
|
ExitNow(error = kErrorInvalidState);
|
||||||
|
|
||||||
case kStateReceive:
|
case kStateReceive:
|
||||||
case kStateSleep:
|
case kStateSleep:
|
||||||
@@ -605,7 +604,7 @@ otError SubMac::EnergyScan(uint8_t aScanChannel, uint16_t aScanDuration)
|
|||||||
else if (ShouldHandleEnergyScan())
|
else if (ShouldHandleEnergyScan())
|
||||||
{
|
{
|
||||||
error = Get<Radio>().Receive(aScanChannel);
|
error = Get<Radio>().Receive(aScanChannel);
|
||||||
OT_ASSERT(error == OT_ERROR_NONE);
|
OT_ASSERT(error == kErrorNone);
|
||||||
|
|
||||||
SetState(kStateEnergyScan);
|
SetState(kStateEnergyScan);
|
||||||
mEnergyScanMaxRssi = kInvalidRssiValue;
|
mEnergyScanMaxRssi = kInvalidRssiValue;
|
||||||
@@ -614,7 +613,7 @@ otError SubMac::EnergyScan(uint8_t aScanChannel, uint16_t aScanDuration)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
error = OT_ERROR_NOT_IMPLEMENTED;
|
error = kErrorNotImplemented;
|
||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
@@ -676,7 +675,7 @@ void SubMac::HandleTimer(void)
|
|||||||
case kStateTransmit:
|
case kStateTransmit:
|
||||||
otLogDebgMac("Ack timer timed out");
|
otLogDebgMac("Ack timer timed out");
|
||||||
IgnoreError(Get<Radio>().Receive(mTransmitFrame.GetChannel()));
|
IgnoreError(Get<Radio>().Receive(mTransmitFrame.GetChannel()));
|
||||||
HandleTransmitDone(mTransmitFrame, nullptr, OT_ERROR_NO_ACK);
|
HandleTransmitDone(mTransmitFrame, nullptr, kErrorNoAck);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kStateEnergyScan:
|
case kStateEnergyScan:
|
||||||
|
|||||||
+39
-39
@@ -116,12 +116,12 @@ public:
|
|||||||
* This method notifies user of `SubMac` of a received frame.
|
* 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] 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,
|
* @param[in] aError kErrorNone when successfully received a frame,
|
||||||
* OT_ERROR_ABORT when reception was aborted and a frame was not received,
|
* kErrorAbort 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.
|
* 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.
|
* 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] aFrame The transmitted frame.
|
||||||
* @param[in] aAckFrame A pointer to the ACK frame, or nullptr if no ACK was received.
|
* @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,
|
* @param[in] aError kErrorNone when the frame was transmitted successfully,
|
||||||
* OT_ERROR_NO_ACK when the frame was transmitted but no ACK was received,
|
* kErrorNoAck when the frame was transmitted but no ACK was received,
|
||||||
* OT_ERROR_CHANNEL_ACCESS_FAILURE tx failed due to activity on the channel,
|
* kErrorChannelAccessFailure tx failed due to activity on the channel,
|
||||||
* OT_ERROR_ABORT when transmission was aborted for other reasons.
|
* 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] 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
|
* @param[in] aWillRetx Indicates whether frame will be retransmitted or not. This is applicable only
|
||||||
* when there was an error in current transmission attempt.
|
* when there was an error in current transmission attempt.
|
||||||
@@ -155,7 +155,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
void RecordFrameTransmitStatus(const TxFrame &aFrame,
|
void RecordFrameTransmitStatus(const TxFrame &aFrame,
|
||||||
const RxFrame *aAckFrame,
|
const RxFrame *aAckFrame,
|
||||||
otError aError,
|
Error aError,
|
||||||
uint8_t aRetryCount,
|
uint8_t aRetryCount,
|
||||||
bool aWillRetx);
|
bool aWillRetx);
|
||||||
|
|
||||||
@@ -165,13 +165,13 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[in] aFrame The transmitted frame.
|
* @param[in] aFrame The transmitted frame.
|
||||||
* @param[in] aAckFrame A pointer to the ACK frame, nullptr if no ACK was received.
|
* @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,
|
* @param[in] aError kErrorNone when the frame was transmitted,
|
||||||
* OT_ERROR_NO_ACK when the frame was transmitted but no ACK was received,
|
* kErrorNoAck when the frame was transmitted but no ACK was received,
|
||||||
* OT_ERROR_CHANNEL_ACCESS_FAILURE tx failed due to activity on the channel,
|
* kErrorChannelAccessFailure tx failed due to activity on the channel,
|
||||||
* OT_ERROR_ABORT when transmission was aborted for other reasons.
|
* 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.
|
* This method notifies user of `SubMac` that energy scan is complete.
|
||||||
@@ -275,29 +275,29 @@ public:
|
|||||||
/**
|
/**
|
||||||
* This method enables the radio.
|
* This method enables the radio.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully enabled.
|
* @retval kErrorNone Successfully enabled.
|
||||||
* @retval OT_ERROR_FAILED The radio could not be enabled.
|
* @retval kErrorFailed The radio could not be enabled.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError Enable(void);
|
Error Enable(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method disables the radio.
|
* 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.
|
* This method transitions the radio to Sleep.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully transitioned to Sleep.
|
* @retval kErrorNone Successfully transitioned to Sleep.
|
||||||
* @retval OT_ERROR_BUSY The radio was transmitting.
|
* @retval kErrorBusy The radio was transmitting.
|
||||||
* @retval OT_ERROR_INVALID_STATE The radio was disabled.
|
* @retval kErrorInvalidState The radio was disabled.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError Sleep(void);
|
Error Sleep(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method indicates whether the sub-mac is busy transmitting or scanning.
|
* 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.
|
* @param[in] aChannel The channel to use for receiving.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully transitioned to Receive.
|
* @retval kErrorNone Successfully transitioned to Receive.
|
||||||
* @retval OT_ERROR_INVALID_STATE The radio was disabled or transmitting.
|
* @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
|
#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
|
* @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.
|
* channel hasn't been explicitly specified.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully entered CSL operation (sleep or receive according to CSL timer).
|
* @retval kErrorNone Successfully entered CSL operation (sleep or receive according to CSL timer).
|
||||||
* @retval OT_ERROR_BUSY The radio was transmitting.
|
* @retval kErrorBusy The radio was transmitting.
|
||||||
* @retval OT_ERROR_INVALID_STATE The radio was disabled.
|
* @retval kErrorInvalidState The radio was disabled.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError CslSample(uint8_t aPanChannel);
|
Error CslSample(uint8_t aPanChannel);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -353,11 +353,11 @@ public:
|
|||||||
*
|
*
|
||||||
* The `SubMac` layer handles Ack timeout, CSMA backoff, and frame retransmission.
|
* The `SubMac` layer handles Ack timeout, CSMA backoff, and frame retransmission.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully started the frame transmission
|
* @retval kErrorNone Successfully started the frame transmission
|
||||||
* @retval OT_ERROR_INVALID_STATE The radio was disabled or transmitting.
|
* @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.
|
* 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] aScanChannel The channel to perform the energy scan on.
|
||||||
* @param[in] aScanDuration The duration, in milliseconds, for the channel to be scanned.
|
* @param[in] aScanDuration The duration, in milliseconds, for the channel to be scanned.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully started scanning the channel.
|
* @retval kErrorNone Successfully started scanning the channel.
|
||||||
* @retval OT_ERROR_INVALID_STATE The radio was disabled or transmitting.
|
* @retval kErrorInvalidState The radio was disabled or transmitting.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED Energy scan is not supported (applicable in link-raw/radio mode only).
|
* @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).
|
* This method returns the noise floor value (currently use the radio receive sensitivity value).
|
||||||
@@ -596,9 +596,9 @@ private:
|
|||||||
void BeginTransmit(void);
|
void BeginTransmit(void);
|
||||||
void SampleRssi(void);
|
void SampleRssi(void);
|
||||||
|
|
||||||
void HandleReceiveDone(RxFrame *aFrame, otError aError);
|
void HandleReceiveDone(RxFrame *aFrame, Error aError);
|
||||||
void HandleTransmitStarted(TxFrame &aFrame);
|
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 UpdateFrameCounterOnTxDone(const TxFrame &aFrame);
|
||||||
void HandleEnergyScanDone(int8_t aMaxRssi);
|
void HandleEnergyScanDone(int8_t aMaxRssi);
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ SubMac::Callbacks::Callbacks(Instance &aInstance)
|
|||||||
|
|
||||||
#if OPENTHREAD_FTD || OPENTHREAD_MTD
|
#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 OPENTHREAD_CONFIG_LINK_RAW_ENABLE
|
||||||
if (Get<LinkRaw>().IsEnabled())
|
if (Get<LinkRaw>().IsEnabled())
|
||||||
@@ -72,14 +72,14 @@ void SubMac::Callbacks::RecordCcaStatus(bool aCcaSuccess, uint8_t aChannel)
|
|||||||
|
|
||||||
void SubMac::Callbacks::RecordFrameTransmitStatus(const TxFrame &aFrame,
|
void SubMac::Callbacks::RecordFrameTransmitStatus(const TxFrame &aFrame,
|
||||||
const RxFrame *aAckFrame,
|
const RxFrame *aAckFrame,
|
||||||
otError aError,
|
Error aError,
|
||||||
uint8_t aRetryCount,
|
uint8_t aRetryCount,
|
||||||
bool aWillRetx)
|
bool aWillRetx)
|
||||||
{
|
{
|
||||||
Get<Mac>().RecordFrameTransmitStatus(aFrame, aAckFrame, aError, aRetryCount, 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 OPENTHREAD_CONFIG_LINK_RAW_ENABLE
|
||||||
if (Get<LinkRaw>().IsEnabled())
|
if (Get<LinkRaw>().IsEnabled())
|
||||||
@@ -114,7 +114,7 @@ void SubMac::Callbacks::FrameCounterUpdated(uint32_t aFrameCounter)
|
|||||||
|
|
||||||
#elif OPENTHREAD_RADIO
|
#elif OPENTHREAD_RADIO
|
||||||
|
|
||||||
void SubMac::Callbacks::ReceiveDone(RxFrame *aFrame, otError aError)
|
void SubMac::Callbacks::ReceiveDone(RxFrame *aFrame, Error aError)
|
||||||
{
|
{
|
||||||
Get<LinkRaw>().InvokeReceiveDone(aFrame, aError);
|
Get<LinkRaw>().InvokeReceiveDone(aFrame, aError);
|
||||||
}
|
}
|
||||||
@@ -125,14 +125,14 @@ void SubMac::Callbacks::RecordCcaStatus(bool, uint8_t)
|
|||||||
|
|
||||||
void SubMac::Callbacks::RecordFrameTransmitStatus(const TxFrame &aFrame,
|
void SubMac::Callbacks::RecordFrameTransmitStatus(const TxFrame &aFrame,
|
||||||
const RxFrame *aAckFrame,
|
const RxFrame *aAckFrame,
|
||||||
otError aError,
|
Error aError,
|
||||||
uint8_t aRetryCount,
|
uint8_t aRetryCount,
|
||||||
bool aWillRetx)
|
bool aWillRetx)
|
||||||
{
|
{
|
||||||
Get<LinkRaw>().RecordFrameTransmitStatus(aFrame, aAckFrame, aError, aRetryCount, 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);
|
Get<LinkRaw>().InvokeTransmitDone(aFrame, aAckFrame, aError);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,18 +53,18 @@ AnnounceBeginClient::AnnounceBeginClient(Instance &aInstance)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
otError AnnounceBeginClient::SendRequest(uint32_t aChannelMask,
|
Error AnnounceBeginClient::SendRequest(uint32_t aChannelMask,
|
||||||
uint8_t aCount,
|
uint8_t aCount,
|
||||||
uint16_t aPeriod,
|
uint16_t aPeriod,
|
||||||
const Ip6::Address &aAddress)
|
const Ip6::Address &aAddress)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
MeshCoP::ChannelMaskTlv channelMask;
|
MeshCoP::ChannelMaskTlv channelMask;
|
||||||
Ip6::MessageInfo messageInfo;
|
Ip6::MessageInfo messageInfo;
|
||||||
Coap::Message * message = nullptr;
|
Coap::Message * message = nullptr;
|
||||||
|
|
||||||
VerifyOrExit(Get<MeshCoP::Commissioner>().IsActive(), error = OT_ERROR_INVALID_STATE);
|
VerifyOrExit(Get<MeshCoP::Commissioner>().IsActive(), error = kErrorInvalidState);
|
||||||
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
|
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = kErrorNoBufs);
|
||||||
|
|
||||||
SuccessOrExit(error = message->InitAsPost(aAddress, UriPath::kAnnounceBegin));
|
SuccessOrExit(error = message->InitAsPost(aAddress, UriPath::kAnnounceBegin));
|
||||||
SuccessOrExit(error = message->SetPayloadMarker());
|
SuccessOrExit(error = message->SetPayloadMarker());
|
||||||
|
|||||||
@@ -64,11 +64,11 @@ public:
|
|||||||
* @param[in] aPeriod The time between two successive MLE Announce transmissions (in milliseconds).
|
* @param[in] aPeriod The time between two successive MLE Announce transmissions (in milliseconds).
|
||||||
* @param[in] aAddress The destination address.
|
* @param[in] aAddress The destination address.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully enqueued the Announce Begin message.
|
* @retval kErrorNone Successfully enqueued the Announce Begin message.
|
||||||
* @retval OT_ERROR_NO_BUFS Insufficient buffers to generate a 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);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ void BorderAgent::ForwardContext::Init(Instance & aInstance,
|
|||||||
memcpy(mToken, aMessage.GetToken(), mTokenLength);
|
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)
|
if ((mType == Coap::kTypeNonConfirmable) || mSeparate)
|
||||||
{
|
{
|
||||||
@@ -81,17 +81,17 @@ otError BorderAgent::ForwardContext::ToHeader(Coap::Message &aMessage, uint8_t a
|
|||||||
return aMessage.SetToken(mToken, mTokenLength);
|
return aMessage.SetToken(mToken, mTokenLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
Coap::Message::Code BorderAgent::CoapCodeFromError(otError aError)
|
Coap::Message::Code BorderAgent::CoapCodeFromError(Error aError)
|
||||||
{
|
{
|
||||||
Coap::Message::Code code;
|
Coap::Message::Code code;
|
||||||
|
|
||||||
switch (aError)
|
switch (aError)
|
||||||
{
|
{
|
||||||
case OT_ERROR_NONE:
|
case kErrorNone:
|
||||||
code = Coap::kCodeChanged;
|
code = Coap::kCodeChanged;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OT_ERROR_PARSE:
|
case kErrorParse:
|
||||||
code = Coap::kCodeBadRequest;
|
code = Coap::kCodeBadRequest;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -103,13 +103,13 @@ Coap::Message::Code BorderAgent::CoapCodeFromError(otError aError)
|
|||||||
return code;
|
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::CoapSecure &coaps = Get<Coap::CoapSecure>();
|
||||||
Coap::Message * message = nullptr;
|
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 = aForwardContext.ToHeader(*message, CoapCodeFromError(aError)));
|
||||||
SuccessOrExit(error = coaps.SendMessage(*message, coaps.GetMessageInfo()));
|
SuccessOrExit(error = coaps.SendMessage(*message, coaps.GetMessageInfo()));
|
||||||
|
|
||||||
@@ -118,13 +118,13 @@ exit:
|
|||||||
LogError("send error CoAP message", error);
|
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::CoapSecure &coaps = Get<Coap::CoapSecure>();
|
||||||
Coap::Message * message = nullptr;
|
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)
|
if (aRequest.IsNonConfirmable() || aSeparate)
|
||||||
{
|
{
|
||||||
@@ -152,7 +152,7 @@ exit:
|
|||||||
void BorderAgent::HandleCoapResponse(void * aContext,
|
void BorderAgent::HandleCoapResponse(void * aContext,
|
||||||
otMessage * aMessage,
|
otMessage * aMessage,
|
||||||
const otMessageInfo *aMessageInfo,
|
const otMessageInfo *aMessageInfo,
|
||||||
otError aResult)
|
Error aResult)
|
||||||
{
|
{
|
||||||
OT_UNUSED_VARIABLE(aMessageInfo);
|
OT_UNUSED_VARIABLE(aMessageInfo);
|
||||||
|
|
||||||
@@ -162,13 +162,13 @@ void BorderAgent::HandleCoapResponse(void * aContext,
|
|||||||
aResult);
|
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;
|
Coap::Message *message = nullptr;
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
SuccessOrExit(error = aResult);
|
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)
|
if (aForwardContext.IsPetition() && aResponse->GetCode() == Coap::kCodeChanged)
|
||||||
{
|
{
|
||||||
@@ -199,12 +199,11 @@ void BorderAgent::HandleCoapResponse(ForwardContext &aForwardContext, const Coap
|
|||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
|
||||||
if (error != OT_ERROR_NONE)
|
if (error != kErrorNone)
|
||||||
{
|
{
|
||||||
FreeMessage(message);
|
FreeMessage(message);
|
||||||
|
|
||||||
otLogWarnMeshCoP("Commissioner request[%hu] failed: %s", aForwardContext.GetMessageId(),
|
otLogWarnMeshCoP("Commissioner request[%hu] failed: %s", aForwardContext.GetMessageId(), ErrorToString(error));
|
||||||
otThreadErrorToString(error));
|
|
||||||
|
|
||||||
SendErrorMessage(aForwardContext, error);
|
SendErrorMessage(aForwardContext, error);
|
||||||
}
|
}
|
||||||
@@ -316,13 +315,13 @@ void BorderAgent::HandleProxyTransmit(const Coap::Message &aMessage)
|
|||||||
Message * message = nullptr;
|
Message * message = nullptr;
|
||||||
Ip6::MessageInfo messageInfo;
|
Ip6::MessageInfo messageInfo;
|
||||||
uint16_t offset;
|
uint16_t offset;
|
||||||
otError error;
|
Error error;
|
||||||
UdpEncapsulationTlv tlv;
|
UdpEncapsulationTlv tlv;
|
||||||
|
|
||||||
SuccessOrExit(error = Tlv::FindTlvOffset(aMessage, Tlv::kUdpEncapsulation, offset));
|
SuccessOrExit(error = Tlv::FindTlvOffset(aMessage, Tlv::kUdpEncapsulation, offset));
|
||||||
SuccessOrExit(error = aMessage.Read(offset, tlv));
|
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()));
|
SuccessOrExit(error = message->SetLength(tlv.GetUdpLength()));
|
||||||
aMessage.CopyTo(offset + sizeof(tlv), 0, tlv.GetUdpLength(), *message);
|
aMessage.CopyTo(offset + sizeof(tlv), 0, tlv.GetUdpLength(), *message);
|
||||||
|
|
||||||
@@ -342,15 +341,15 @@ exit:
|
|||||||
|
|
||||||
bool BorderAgent::HandleUdpReceive(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
bool BorderAgent::HandleUdpReceive(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
Coap::Message *message = nullptr;
|
Coap::Message *message = nullptr;
|
||||||
|
|
||||||
VerifyOrExit(aMessageInfo.GetSockAddr() == mCommissionerAloc.GetAddress(),
|
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();
|
message->InitAsNonConfirmablePost();
|
||||||
SuccessOrExit(error = message->AppendUriPathOptions(UriPath::kProxyRx));
|
SuccessOrExit(error = message->AppendUriPathOptions(UriPath::kProxyRx));
|
||||||
@@ -382,16 +381,16 @@ exit:
|
|||||||
FreeMessageOnError(message, error);
|
FreeMessageOnError(message, error);
|
||||||
LogError("notify commissioner on ProxyRx (c/ur)", 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)
|
void BorderAgent::HandleRelayReceive(const Coap::Message &aMessage)
|
||||||
{
|
{
|
||||||
Coap::Message *message = nullptr;
|
Coap::Message *message = nullptr;
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
VerifyOrExit(aMessage.IsNonConfirmablePostRequest(), error = OT_ERROR_DROP);
|
VerifyOrExit(aMessage.IsNonConfirmablePostRequest(), error = kErrorDrop);
|
||||||
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::CoapSecure>())) != nullptr, error = OT_ERROR_NO_BUFS);
|
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::CoapSecure>())) != nullptr, error = kErrorNoBufs);
|
||||||
|
|
||||||
message->InitAsNonConfirmablePost();
|
message->InitAsNonConfirmablePost();
|
||||||
SuccessOrExit(error = message->AppendUriPathOptions(UriPath::kRelayRx));
|
SuccessOrExit(error = message->AppendUriPathOptions(UriPath::kRelayRx));
|
||||||
@@ -408,9 +407,9 @@ exit:
|
|||||||
FreeMessageOnError(message, error);
|
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;
|
uint16_t offset = 0;
|
||||||
|
|
||||||
offset = aForwardMessage.GetLength();
|
offset = aForwardMessage.GetLength();
|
||||||
@@ -429,11 +428,11 @@ exit:
|
|||||||
|
|
||||||
void BorderAgent::HandleKeepAlive(const Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
void BorderAgent::HandleKeepAlive(const Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
error = ForwardToLeader(aMessage, aMessageInfo, UriPath::kLeaderKeepAlive, false, true);
|
error = ForwardToLeader(aMessage, aMessageInfo, UriPath::kLeaderKeepAlive, false, true);
|
||||||
|
|
||||||
if (error == OT_ERROR_NONE)
|
if (error == kErrorNone)
|
||||||
{
|
{
|
||||||
mTimer.Start(kKeepAliveTimeout);
|
mTimer.Start(kKeepAliveTimeout);
|
||||||
}
|
}
|
||||||
@@ -441,7 +440,7 @@ void BorderAgent::HandleKeepAlive(const Coap::Message &aMessage, const Ip6::Mess
|
|||||||
|
|
||||||
void BorderAgent::HandleRelayTransmit(const Coap::Message &aMessage)
|
void BorderAgent::HandleRelayTransmit(const Coap::Message &aMessage)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
uint16_t joinerRouterRloc;
|
uint16_t joinerRouterRloc;
|
||||||
Coap::Message * message = nullptr;
|
Coap::Message * message = nullptr;
|
||||||
Ip6::MessageInfo messageInfo;
|
Ip6::MessageInfo messageInfo;
|
||||||
@@ -451,7 +450,7 @@ void BorderAgent::HandleRelayTransmit(const Coap::Message &aMessage)
|
|||||||
|
|
||||||
SuccessOrExit(error = Tlv::Find<JoinerRouterLocatorTlv>(aMessage, joinerRouterRloc));
|
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->InitAsNonConfirmablePost(UriPath::kRelayTx));
|
||||||
SuccessOrExit(error = message->SetPayloadMarker());
|
SuccessOrExit(error = message->SetPayloadMarker());
|
||||||
@@ -475,19 +474,19 @@ exit:
|
|||||||
LogError("send to joiner router request RelayTx (c/tx)", error);
|
LogError("send to joiner router request RelayTx (c/tx)", error);
|
||||||
}
|
}
|
||||||
|
|
||||||
otError BorderAgent::ForwardToLeader(const Coap::Message & aMessage,
|
Error BorderAgent::ForwardToLeader(const Coap::Message & aMessage,
|
||||||
const Ip6::MessageInfo &aMessageInfo,
|
const Ip6::MessageInfo &aMessageInfo,
|
||||||
const char * aPath,
|
const char * aPath,
|
||||||
bool aPetition,
|
bool aPetition,
|
||||||
bool aSeparate)
|
bool aSeparate)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
ForwardContext * forwardContext = nullptr;
|
ForwardContext * forwardContext = nullptr;
|
||||||
Ip6::MessageInfo messageInfo;
|
Ip6::MessageInfo messageInfo;
|
||||||
Coap::Message * message = nullptr;
|
Coap::Message * message = nullptr;
|
||||||
uint16_t offset = 0;
|
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)
|
if (aSeparate)
|
||||||
{
|
{
|
||||||
@@ -495,7 +494,7 @@ otError BorderAgent::ForwardToLeader(const Coap::Message & aMessage,
|
|||||||
}
|
}
|
||||||
|
|
||||||
forwardContext = static_cast<ForwardContext *>(Instance::HeapCAlloc(1, sizeof(ForwardContext)));
|
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);
|
forwardContext->Init(GetInstance(), aMessage, aPetition, aSeparate);
|
||||||
|
|
||||||
@@ -526,7 +525,7 @@ otError BorderAgent::ForwardToLeader(const Coap::Message & aMessage,
|
|||||||
exit:
|
exit:
|
||||||
LogError("forward to leader", error);
|
LogError("forward to leader", error);
|
||||||
|
|
||||||
if (error != OT_ERROR_NONE)
|
if (error != kErrorNone)
|
||||||
{
|
{
|
||||||
if (forwardContext != nullptr)
|
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>();
|
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.Start(kBorderAgentUdpPort));
|
||||||
SuccessOrExit(error = coaps.SetPsk(Get<KeyManager>().GetPskc().m8, OT_PSKC_MAX_SIZE));
|
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>();
|
Coap::CoapSecure &coaps = Get<Coap::CoapSecure>();
|
||||||
|
|
||||||
VerifyOrExit(mState != kStateStopped, error = OT_ERROR_ALREADY);
|
VerifyOrExit(mState != kStateStopped, error = kErrorAlready);
|
||||||
|
|
||||||
mTimer.Stop();
|
mTimer.Stop();
|
||||||
|
|
||||||
|
|||||||
@@ -75,20 +75,20 @@ public:
|
|||||||
/**
|
/**
|
||||||
* This method starts the Border Agent service.
|
* This method starts the Border Agent service.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully started the Border Agent service.
|
* @retval kErrorNone Successfully started the Border Agent service.
|
||||||
* @retval OT_ERROR_ALREADY Border Agent is already started.
|
* @retval kErrorAlready Border Agent is already started.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError Start(void);
|
Error Start(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method stops the Border Agent service.
|
* This method stops the Border Agent service.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully stopped the Border Agent service.
|
* @retval kErrorNone Successfully stopped the Border Agent service.
|
||||||
* @retval OT_ERROR_ALREADY Border Agent is already stopped.
|
* @retval kErrorAlready Border Agent is already stopped.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError Stop(void);
|
Error Stop(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method gets the state of the Border Agent service.
|
* 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);
|
void Init(Instance &aInstance, const Coap::Message &aMessage, bool aPetition, bool aSeparate);
|
||||||
bool IsPetition(void) const { return mPetition; }
|
bool IsPetition(void) const { return mPetition; }
|
||||||
uint16_t GetMessageId(void) const { return mMessageId; }
|
uint16_t GetMessageId(void) const { return mMessageId; }
|
||||||
otError ToHeader(Coap::Message &aMessage, uint8_t aCode);
|
Error ToHeader(Coap::Message &aMessage, uint8_t aCode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint16_t mMessageId; // The CoAP Message ID of the original request.
|
uint16_t mMessageId; // The CoAP Message ID of the original request.
|
||||||
@@ -124,9 +124,9 @@ private:
|
|||||||
|
|
||||||
void HandleNotifierEvents(Events aEvents);
|
void HandleNotifierEvents(Events aEvents);
|
||||||
|
|
||||||
Coap::Message::Code CoapCodeFromError(otError aError);
|
Coap::Message::Code CoapCodeFromError(Error aError);
|
||||||
void SendErrorMessage(ForwardContext &aForwardContext, otError aError);
|
void SendErrorMessage(ForwardContext &aForwardContext, Error aError);
|
||||||
void SendErrorMessage(const Coap::Message &aRequest, bool aSeparate, otError aError);
|
void SendErrorMessage(const Coap::Message &aRequest, bool aSeparate, Error aError);
|
||||||
|
|
||||||
static void HandleConnected(bool aConnected, void *aContext);
|
static void HandleConnected(bool aConnected, void *aContext);
|
||||||
void HandleConnected(bool aConnected);
|
void HandleConnected(bool aConnected);
|
||||||
@@ -140,15 +140,15 @@ private:
|
|||||||
static void HandleCoapResponse(void * aContext,
|
static void HandleCoapResponse(void * aContext,
|
||||||
otMessage * aMessage,
|
otMessage * aMessage,
|
||||||
const otMessageInfo *aMessageInfo,
|
const otMessageInfo *aMessageInfo,
|
||||||
otError aResult);
|
Error aResult);
|
||||||
void HandleCoapResponse(ForwardContext &aForwardContext, const Coap::Message *aResponse, otError 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 Ip6::MessageInfo &aMessageInfo,
|
||||||
const char * aPath,
|
const char * aPath,
|
||||||
bool aPetition,
|
bool aPetition,
|
||||||
bool aSeparate);
|
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 HandleKeepAlive(const Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||||
void HandleRelayTransmit(const Coap::Message &aMessage);
|
void HandleRelayTransmit(const Coap::Message &aMessage);
|
||||||
void HandleRelayReceive(const Coap::Message &aMessage);
|
void HandleRelayReceive(const Coap::Message &aMessage);
|
||||||
|
|||||||
@@ -294,18 +294,18 @@ void Commissioner::RemoveJoinerEntry(Commissioner::Joiner &aJoiner)
|
|||||||
SignalJoinerEvent(kJoinerEventRemoved, &joinerCopy);
|
SignalJoinerEvent(kJoinerEventRemoved, &joinerCopy);
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Commissioner::Start(otCommissionerStateCallback aStateCallback,
|
Error Commissioner::Start(otCommissionerStateCallback aStateCallback,
|
||||||
otCommissionerJoinerCallback aJoinerCallback,
|
otCommissionerJoinerCallback aJoinerCallback,
|
||||||
void * aCallbackContext)
|
void * aCallbackContext)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
|
|
||||||
VerifyOrExit(Get<Mle::MleRouter>().IsAttached(), error = OT_ERROR_INVALID_STATE);
|
VerifyOrExit(Get<Mle::MleRouter>().IsAttached(), error = kErrorInvalidState);
|
||||||
VerifyOrExit(mState == kStateDisabled, error = OT_ERROR_ALREADY);
|
VerifyOrExit(mState == kStateDisabled, error = kErrorAlready);
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
|
#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
|
||||||
error = Get<MeshCoP::BorderAgent>().Stop();
|
error = Get<MeshCoP::BorderAgent>().Stop();
|
||||||
VerifyOrExit(error == OT_ERROR_NONE || error == OT_ERROR_ALREADY);
|
VerifyOrExit(error == kErrorNone || error == kErrorAlready);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SuccessOrExit(error = Get<Coap::CoapSecure>().Start(SendRelayTransmit, this));
|
SuccessOrExit(error = Get<Coap::CoapSecure>().Start(SendRelayTransmit, this));
|
||||||
@@ -320,7 +320,7 @@ otError Commissioner::Start(otCommissionerStateCallback aStateCallback,
|
|||||||
SetState(kStatePetition);
|
SetState(kStatePetition);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if ((error != OT_ERROR_NONE) && (error != OT_ERROR_ALREADY))
|
if ((error != kErrorNone) && (error != kErrorAlready))
|
||||||
{
|
{
|
||||||
Get<Coap::CoapSecure>().Stop();
|
Get<Coap::CoapSecure>().Stop();
|
||||||
}
|
}
|
||||||
@@ -329,12 +329,12 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Commissioner::Stop(bool aResign)
|
Error Commissioner::Stop(bool aResign)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
bool needResign = false;
|
bool needResign = false;
|
||||||
|
|
||||||
VerifyOrExit(mState != kStateDisabled, error = OT_ERROR_ALREADY);
|
VerifyOrExit(mState != kStateDisabled, error = kErrorAlready);
|
||||||
|
|
||||||
Get<Coap::CoapSecure>().Stop();
|
Get<Coap::CoapSecure>().Stop();
|
||||||
|
|
||||||
@@ -398,10 +398,10 @@ exit:
|
|||||||
|
|
||||||
void Commissioner::SendCommissionerSet(void)
|
void Commissioner::SendCommissionerSet(void)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
otCommissioningDataset dataset;
|
otCommissioningDataset dataset;
|
||||||
|
|
||||||
VerifyOrExit(mState == kStateActive, error = OT_ERROR_INVALID_STATE);
|
VerifyOrExit(mState == kStateActive, error = kErrorInvalidState);
|
||||||
|
|
||||||
memset(&dataset, 0, sizeof(dataset));
|
memset(&dataset, 0, sizeof(dataset));
|
||||||
|
|
||||||
@@ -427,19 +427,19 @@ void Commissioner::ClearJoiners(void)
|
|||||||
SendCommissionerSet();
|
SendCommissionerSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Commissioner::AddJoiner(const Mac::ExtAddress *aEui64,
|
Error Commissioner::AddJoiner(const Mac::ExtAddress *aEui64,
|
||||||
const JoinerDiscerner *aDiscerner,
|
const JoinerDiscerner *aDiscerner,
|
||||||
const char * aPskd,
|
const char * aPskd,
|
||||||
uint32_t aTimeout)
|
uint32_t aTimeout)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Joiner *joiner;
|
Joiner *joiner;
|
||||||
|
|
||||||
VerifyOrExit(mState == kStateActive, error = OT_ERROR_INVALID_STATE);
|
VerifyOrExit(mState == kStateActive, error = kErrorInvalidState);
|
||||||
|
|
||||||
if (aDiscerner != nullptr)
|
if (aDiscerner != nullptr)
|
||||||
{
|
{
|
||||||
VerifyOrExit(aDiscerner->IsValid(), error = OT_ERROR_INVALID_ARGS);
|
VerifyOrExit(aDiscerner->IsValid(), error = kErrorInvalidArgs);
|
||||||
joiner = FindJoinerEntry(*aDiscerner);
|
joiner = FindJoinerEntry(*aDiscerner);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -452,7 +452,7 @@ otError Commissioner::AddJoiner(const Mac::ExtAddress *aEui64,
|
|||||||
joiner = GetUnusedJoinerEntry();
|
joiner = GetUnusedJoinerEntry();
|
||||||
}
|
}
|
||||||
|
|
||||||
VerifyOrExit(joiner != nullptr, error = OT_ERROR_NO_BUFS);
|
VerifyOrExit(joiner != nullptr, error = kErrorNoBufs);
|
||||||
|
|
||||||
SuccessOrExit(error = joiner->mPskd.SetFrom(aPskd));
|
SuccessOrExit(error = joiner->mPskd.SetFrom(aPskd));
|
||||||
|
|
||||||
@@ -514,9 +514,9 @@ exit:
|
|||||||
return;
|
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))
|
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:
|
exit:
|
||||||
return error;
|
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;
|
Joiner *joiner;
|
||||||
|
|
||||||
VerifyOrExit(mState == kStateActive, error = OT_ERROR_INVALID_STATE);
|
VerifyOrExit(mState == kStateActive, error = kErrorInvalidState);
|
||||||
|
|
||||||
if (aDiscerner != nullptr)
|
if (aDiscerner != nullptr)
|
||||||
{
|
{
|
||||||
VerifyOrExit(aDiscerner->IsValid(), error = OT_ERROR_INVALID_ARGS);
|
VerifyOrExit(aDiscerner->IsValid(), error = kErrorInvalidArgs);
|
||||||
joiner = FindJoinerEntry(*aDiscerner);
|
joiner = FindJoinerEntry(*aDiscerner);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -552,7 +552,7 @@ otError Commissioner::RemoveJoiner(const Mac::ExtAddress *aEui64, const JoinerDi
|
|||||||
joiner = FindJoinerEntry(aEui64);
|
joiner = FindJoinerEntry(aEui64);
|
||||||
}
|
}
|
||||||
|
|
||||||
VerifyOrExit(joiner != nullptr, error = OT_ERROR_NOT_FOUND);
|
VerifyOrExit(joiner != nullptr, error = kErrorNotFound);
|
||||||
|
|
||||||
RemoveJoiner(*joiner, aDelay);
|
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;
|
uint8_t len;
|
||||||
|
|
||||||
if (aProvisioningUrl == nullptr)
|
if (aProvisioningUrl == nullptr)
|
||||||
@@ -589,11 +589,11 @@ otError Commissioner::SetProvisioningUrl(const char *aProvisioningUrl)
|
|||||||
ExitNow();
|
ExitNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
VerifyOrExit(IsValidUtf8String(aProvisioningUrl), error = OT_ERROR_INVALID_ARGS);
|
VerifyOrExit(IsValidUtf8String(aProvisioningUrl), error = kErrorInvalidArgs);
|
||||||
|
|
||||||
len = static_cast<uint8_t>(StringLength(aProvisioningUrl, sizeof(mProvisioningUrl)));
|
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);
|
memcpy(mProvisioningUrl, aProvisioningUrl, len);
|
||||||
mProvisioningUrl[len] = '\0';
|
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;
|
Coap::Message * message;
|
||||||
Ip6::MessageInfo messageInfo;
|
Ip6::MessageInfo messageInfo;
|
||||||
MeshCoP::Tlv tlv;
|
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));
|
SuccessOrExit(error = message->InitAsConfirmablePost(UriPath::kCommissionerGet));
|
||||||
|
|
||||||
@@ -722,7 +722,7 @@ exit:
|
|||||||
void Commissioner::HandleMgmtCommissionerGetResponse(void * aContext,
|
void Commissioner::HandleMgmtCommissionerGetResponse(void * aContext,
|
||||||
otMessage * aMessage,
|
otMessage * aMessage,
|
||||||
const otMessageInfo *aMessageInfo,
|
const otMessageInfo *aMessageInfo,
|
||||||
otError aResult)
|
Error aResult)
|
||||||
{
|
{
|
||||||
static_cast<Commissioner *>(aContext)->HandleMgmtCommissionerGetResponse(
|
static_cast<Commissioner *>(aContext)->HandleMgmtCommissionerGetResponse(
|
||||||
static_cast<Coap::Message *>(aMessage), static_cast<const Ip6::MessageInfo *>(aMessageInfo), aResult);
|
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,
|
void Commissioner::HandleMgmtCommissionerGetResponse(Coap::Message * aMessage,
|
||||||
const Ip6::MessageInfo *aMessageInfo,
|
const Ip6::MessageInfo *aMessageInfo,
|
||||||
otError aResult)
|
Error aResult)
|
||||||
{
|
{
|
||||||
OT_UNUSED_VARIABLE(aMessageInfo);
|
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");
|
otLogInfoMeshCoP("received MGMT_COMMISSIONER_GET response");
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Commissioner::SendMgmtCommissionerSetRequest(const otCommissioningDataset &aDataset,
|
Error Commissioner::SendMgmtCommissionerSetRequest(const otCommissioningDataset &aDataset,
|
||||||
const uint8_t * aTlvs,
|
const uint8_t * aTlvs,
|
||||||
uint8_t aLength)
|
uint8_t aLength)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Coap::Message * message;
|
Coap::Message * message;
|
||||||
Ip6::MessageInfo messageInfo;
|
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->InitAsConfirmablePost(UriPath::kCommissionerSet));
|
||||||
SuccessOrExit(error = message->SetPayloadMarker());
|
SuccessOrExit(error = message->SetPayloadMarker());
|
||||||
@@ -802,7 +802,7 @@ exit:
|
|||||||
void Commissioner::HandleMgmtCommissionerSetResponse(void * aContext,
|
void Commissioner::HandleMgmtCommissionerSetResponse(void * aContext,
|
||||||
otMessage * aMessage,
|
otMessage * aMessage,
|
||||||
const otMessageInfo *aMessageInfo,
|
const otMessageInfo *aMessageInfo,
|
||||||
otError aResult)
|
Error aResult)
|
||||||
{
|
{
|
||||||
static_cast<Commissioner *>(aContext)->HandleMgmtCommissionerSetResponse(
|
static_cast<Commissioner *>(aContext)->HandleMgmtCommissionerSetResponse(
|
||||||
static_cast<Coap::Message *>(aMessage), static_cast<const Ip6::MessageInfo *>(aMessageInfo), aResult);
|
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,
|
void Commissioner::HandleMgmtCommissionerSetResponse(Coap::Message * aMessage,
|
||||||
const Ip6::MessageInfo *aMessageInfo,
|
const Ip6::MessageInfo *aMessageInfo,
|
||||||
otError aResult)
|
Error aResult)
|
||||||
{
|
{
|
||||||
OT_UNUSED_VARIABLE(aMessageInfo);
|
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");
|
otLogInfoMeshCoP("received MGMT_COMMISSIONER_SET response");
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Commissioner::SendPetition(void)
|
Error Commissioner::SendPetition(void)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Coap::Message * message = nullptr;
|
Coap::Message * message = nullptr;
|
||||||
Ip6::MessageInfo messageInfo;
|
Ip6::MessageInfo messageInfo;
|
||||||
CommissionerIdTlv commissionerId;
|
CommissionerIdTlv commissionerId;
|
||||||
|
|
||||||
mTransmitAttempts++;
|
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->InitAsConfirmablePost(UriPath::kLeaderPetition));
|
||||||
SuccessOrExit(error = message->SetPayloadMarker());
|
SuccessOrExit(error = message->SetPayloadMarker());
|
||||||
@@ -856,7 +856,7 @@ exit:
|
|||||||
void Commissioner::HandleLeaderPetitionResponse(void * aContext,
|
void Commissioner::HandleLeaderPetitionResponse(void * aContext,
|
||||||
otMessage * aMessage,
|
otMessage * aMessage,
|
||||||
const otMessageInfo *aMessageInfo,
|
const otMessageInfo *aMessageInfo,
|
||||||
otError aResult)
|
Error aResult)
|
||||||
{
|
{
|
||||||
static_cast<Commissioner *>(aContext)->HandleLeaderPetitionResponse(
|
static_cast<Commissioner *>(aContext)->HandleLeaderPetitionResponse(
|
||||||
static_cast<Coap::Message *>(aMessage), static_cast<const Ip6::MessageInfo *>(aMessageInfo), aResult);
|
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,
|
void Commissioner::HandleLeaderPetitionResponse(Coap::Message * aMessage,
|
||||||
const Ip6::MessageInfo *aMessageInfo,
|
const Ip6::MessageInfo *aMessageInfo,
|
||||||
otError aResult)
|
Error aResult)
|
||||||
{
|
{
|
||||||
OT_UNUSED_VARIABLE(aMessageInfo);
|
OT_UNUSED_VARIABLE(aMessageInfo);
|
||||||
|
|
||||||
@@ -872,7 +872,7 @@ void Commissioner::HandleLeaderPetitionResponse(Coap::Message * aMessage
|
|||||||
bool retransmit = false;
|
bool retransmit = false;
|
||||||
|
|
||||||
VerifyOrExit(mState != kStateActive);
|
VerifyOrExit(mState != kStateActive);
|
||||||
VerifyOrExit(aResult == OT_ERROR_NONE && aMessage->GetCode() == Coap::kCodeChanged,
|
VerifyOrExit(aResult == kErrorNone && aMessage->GetCode() == Coap::kCodeChanged,
|
||||||
retransmit = (mState == kStatePetition));
|
retransmit = (mState == kStatePetition));
|
||||||
|
|
||||||
otLogInfoMeshCoP("received Leader Petition response");
|
otLogInfoMeshCoP("received Leader Petition response");
|
||||||
@@ -921,11 +921,11 @@ void Commissioner::SendKeepAlive(void)
|
|||||||
|
|
||||||
void Commissioner::SendKeepAlive(uint16_t aSessionId)
|
void Commissioner::SendKeepAlive(uint16_t aSessionId)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Coap::Message * message = nullptr;
|
Coap::Message * message = nullptr;
|
||||||
Ip6::MessageInfo messageInfo;
|
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->InitAsConfirmablePost(UriPath::kLeaderKeepAlive));
|
||||||
SuccessOrExit(error = message->SetPayloadMarker());
|
SuccessOrExit(error = message->SetPayloadMarker());
|
||||||
@@ -951,7 +951,7 @@ exit:
|
|||||||
void Commissioner::HandleLeaderKeepAliveResponse(void * aContext,
|
void Commissioner::HandleLeaderKeepAliveResponse(void * aContext,
|
||||||
otMessage * aMessage,
|
otMessage * aMessage,
|
||||||
const otMessageInfo *aMessageInfo,
|
const otMessageInfo *aMessageInfo,
|
||||||
otError aResult)
|
Error aResult)
|
||||||
{
|
{
|
||||||
static_cast<Commissioner *>(aContext)->HandleLeaderKeepAliveResponse(
|
static_cast<Commissioner *>(aContext)->HandleLeaderKeepAliveResponse(
|
||||||
static_cast<Coap::Message *>(aMessage), static_cast<const Ip6::MessageInfo *>(aMessageInfo), aResult);
|
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,
|
void Commissioner::HandleLeaderKeepAliveResponse(Coap::Message * aMessage,
|
||||||
const Ip6::MessageInfo *aMessageInfo,
|
const Ip6::MessageInfo *aMessageInfo,
|
||||||
otError aResult)
|
Error aResult)
|
||||||
{
|
{
|
||||||
OT_UNUSED_VARIABLE(aMessageInfo);
|
OT_UNUSED_VARIABLE(aMessageInfo);
|
||||||
|
|
||||||
uint8_t state;
|
uint8_t state;
|
||||||
|
|
||||||
VerifyOrExit(mState == kStateActive);
|
VerifyOrExit(mState == kStateActive);
|
||||||
VerifyOrExit(aResult == OT_ERROR_NONE && aMessage->GetCode() == Coap::kCodeChanged,
|
VerifyOrExit(aResult == kErrorNone && aMessage->GetCode() == Coap::kCodeChanged,
|
||||||
IgnoreError(Stop(/* aResign */ false)));
|
IgnoreError(Stop(/* aResign */ false)));
|
||||||
|
|
||||||
otLogInfoMeshCoP("received Leader keep-alive response");
|
otLogInfoMeshCoP("received Leader keep-alive response");
|
||||||
@@ -990,7 +990,7 @@ void Commissioner::HandleRelayReceive(Coap::Message &aMessage, const Ip6::Messag
|
|||||||
{
|
{
|
||||||
OT_UNUSED_VARIABLE(aMessageInfo);
|
OT_UNUSED_VARIABLE(aMessageInfo);
|
||||||
|
|
||||||
otError error;
|
Error error;
|
||||||
uint16_t joinerPort;
|
uint16_t joinerPort;
|
||||||
Ip6::InterfaceIdentifier joinerIid;
|
Ip6::InterfaceIdentifier joinerIid;
|
||||||
uint16_t joinerRloc;
|
uint16_t joinerRloc;
|
||||||
@@ -998,7 +998,7 @@ void Commissioner::HandleRelayReceive(Coap::Message &aMessage, const Ip6::Messag
|
|||||||
uint16_t offset;
|
uint16_t offset;
|
||||||
uint16_t length;
|
uint16_t length;
|
||||||
|
|
||||||
VerifyOrExit(mState == kStateActive, error = OT_ERROR_INVALID_STATE);
|
VerifyOrExit(mState == kStateActive, error = kErrorInvalidState);
|
||||||
|
|
||||||
VerifyOrExit(aMessage.IsNonConfirmablePostRequest());
|
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::Find<JoinerRouterLocatorTlv>(aMessage, joinerRloc));
|
||||||
|
|
||||||
SuccessOrExit(error = Tlv::FindTlvValueOffset(aMessage, Tlv::kJoinerDtlsEncapsulation, offset, length));
|
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())
|
if (!Get<Coap::CoapSecure>().IsConnectionActive())
|
||||||
{
|
{
|
||||||
@@ -1084,7 +1084,7 @@ void Commissioner::HandleJoinerFinalize(Coap::Message &aMessage, const Ip6::Mess
|
|||||||
|
|
||||||
otLogInfoMeshCoP("received joiner finalize");
|
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)));
|
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)
|
void Commissioner::SendJoinFinalizeResponse(const Coap::Message &aRequest, StateTlv::State aState)
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Ip6::MessageInfo joinerMessageInfo;
|
Ip6::MessageInfo joinerMessageInfo;
|
||||||
Coap::Message * message;
|
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->SetDefaultResponseHeader(aRequest));
|
||||||
SuccessOrExit(error = message->SetPayloadMarker());
|
SuccessOrExit(error = message->SetPayloadMarker());
|
||||||
@@ -1152,22 +1152,22 @@ exit:
|
|||||||
FreeMessageOnError(message, error);
|
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);
|
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);
|
OT_UNUSED_VARIABLE(aMessageInfo);
|
||||||
|
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
ExtendedTlv tlv;
|
ExtendedTlv tlv;
|
||||||
Coap::Message * message;
|
Coap::Message * message;
|
||||||
uint16_t offset;
|
uint16_t offset;
|
||||||
Ip6::MessageInfo messageInfo;
|
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();
|
message->InitAsNonConfirmablePost();
|
||||||
SuccessOrExit(error = message->AppendUriPathOptions(UriPath::kRelayTx));
|
SuccessOrExit(error = message->AppendUriPathOptions(UriPath::kRelayTx));
|
||||||
|
|||||||
@@ -86,25 +86,25 @@ public:
|
|||||||
* @param[in] aJoinerCallback A pointer to a function that is called when a joiner event occurs.
|
* @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.
|
* @param[in] aCallbackContext A pointer to application-specific context.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully started the Commissioner service.
|
* @retval kErrorNone Successfully started the Commissioner service.
|
||||||
* @retval OT_ERROR_ALREADY Commissioner is already started.
|
* @retval kErrorAlready Commissioner is already started.
|
||||||
* @retval OT_ERROR_INVALID_STATE Device is not currently attached to a network.
|
* @retval kErrorInvalidState Device is not currently attached to a network.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError Start(otCommissionerStateCallback aStateCallback,
|
Error Start(otCommissionerStateCallback aStateCallback,
|
||||||
otCommissionerJoinerCallback aJoinerCallback,
|
otCommissionerJoinerCallback aJoinerCallback,
|
||||||
void * aCallbackContext);
|
void * aCallbackContext);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method stops the Commissioner service.
|
* This method stops the Commissioner service.
|
||||||
*
|
*
|
||||||
* @param[in] aResign Whether send LEAD_KA.req to resign as Commissioner
|
* @param[in] aResign Whether send LEAD_KA.req to resign as Commissioner
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully stopped the Commissioner service.
|
* @retval kErrorNone Successfully stopped the Commissioner service.
|
||||||
* @retval OT_ERROR_ALREADY Commissioner is already stopped.
|
* @retval kErrorAlready Commissioner is already stopped.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError Stop(bool aResign);
|
Error Stop(bool aResign);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method clears all Joiner entries.
|
* This method clears all Joiner entries.
|
||||||
@@ -118,12 +118,12 @@ public:
|
|||||||
* @param[in] aPskd A pointer to the PSKd.
|
* @param[in] aPskd A pointer to the PSKd.
|
||||||
* @param[in] aTimeout A time after which a Joiner is automatically removed, in seconds.
|
* @param[in] aTimeout A time after which a Joiner is automatically removed, in seconds.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully added the Joiner.
|
* @retval kErrorNone Successfully added the Joiner.
|
||||||
* @retval OT_ERROR_NO_BUFS No buffers available to add the Joiner.
|
* @retval kErrorNoBufs No buffers available to add the Joiner.
|
||||||
* @retval OT_ERROR_INVALID_STATE Commissioner service is not started.
|
* @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.
|
* This method adds a Joiner entry.
|
||||||
@@ -132,12 +132,12 @@ public:
|
|||||||
* @param[in] aPskd A pointer to the PSKd.
|
* @param[in] aPskd A pointer to the PSKd.
|
||||||
* @param[in] aTimeout A time after which a Joiner is automatically removed, in seconds.
|
* @param[in] aTimeout A time after which a Joiner is automatically removed, in seconds.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully added the Joiner.
|
* @retval kErrorNone Successfully added the Joiner.
|
||||||
* @retval OT_ERROR_NO_BUFS No buffers available to add the Joiner.
|
* @retval kErrorNoBufs No buffers available to add the Joiner.
|
||||||
* @retval OT_ERROR_INVALID_STATE Commissioner service is not started.
|
* @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);
|
return AddJoiner(&aEui64, nullptr, aPskd, aTimeout);
|
||||||
}
|
}
|
||||||
@@ -149,12 +149,12 @@ public:
|
|||||||
* @param[in] aPskd A pointer to the PSKd.
|
* @param[in] aPskd A pointer to the PSKd.
|
||||||
* @param[in] aTimeout A time after which a Joiner is automatically removed, in seconds.
|
* @param[in] aTimeout A time after which a Joiner is automatically removed, in seconds.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully added the Joiner.
|
* @retval kErrorNone Successfully added the Joiner.
|
||||||
* @retval OT_ERROR_NO_BUFS No buffers available to add the Joiner.
|
* @retval kErrorNoBufs No buffers available to add the Joiner.
|
||||||
* @retval OT_ERROR_INVALID_STATE Commissioner service is not started.
|
* @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);
|
return AddJoiner(nullptr, &aDiscerner, aPskd, aTimeout);
|
||||||
}
|
}
|
||||||
@@ -165,23 +165,23 @@ public:
|
|||||||
* @param[inout] aIterator A iterator to the index of the joiner.
|
* @param[inout] aIterator A iterator to the index of the joiner.
|
||||||
* @param[out] aJoiner A reference to Joiner info.
|
* @param[out] aJoiner A reference to Joiner info.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully get the Joiner info.
|
* @retval kErrorNone Successfully get the Joiner info.
|
||||||
* @retval OT_ERROR_NOT_FOUND Not found next Joiner.
|
* @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.
|
* This method removes a Joiner entry accepting any Joiner.
|
||||||
*
|
*
|
||||||
* @param[in] aDelay The delay to remove Joiner (in seconds).
|
* @param[in] aDelay The delay to remove Joiner (in seconds).
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully added the Joiner.
|
* @retval kErrorNone Successfully added the Joiner.
|
||||||
* @retval OT_ERROR_NOT_FOUND The Joiner entry accepting any Joiner was not found.
|
* @retval kErrorNotFound The Joiner entry accepting any Joiner was not found.
|
||||||
* @retval OT_ERROR_INVALID_STATE Commissioner service is not started.
|
* @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.
|
* This method removes a Joiner entry.
|
||||||
@@ -189,12 +189,12 @@ public:
|
|||||||
* @param[in] aEui64 The Joiner's IEEE EUI-64.
|
* @param[in] aEui64 The Joiner's IEEE EUI-64.
|
||||||
* @param[in] aDelay The delay to remove Joiner (in seconds).
|
* @param[in] aDelay The delay to remove Joiner (in seconds).
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully added the Joiner.
|
* @retval kErrorNone Successfully added the Joiner.
|
||||||
* @retval OT_ERROR_NOT_FOUND The Joiner specified by @p aEui64 was not found.
|
* @retval kErrorNotFound The Joiner specified by @p aEui64 was not found.
|
||||||
* @retval OT_ERROR_INVALID_STATE Commissioner service is not started.
|
* @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);
|
return RemoveJoiner(&aEui64, nullptr, aDelay);
|
||||||
}
|
}
|
||||||
@@ -205,12 +205,12 @@ public:
|
|||||||
* @param[in] aDiscerner A Joiner Discerner.
|
* @param[in] aDiscerner A Joiner Discerner.
|
||||||
* @param[in] aDelay The delay to remove Joiner (in seconds).
|
* @param[in] aDelay The delay to remove Joiner (in seconds).
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully added the Joiner.
|
* @retval kErrorNone Successfully added the Joiner.
|
||||||
* @retval OT_ERROR_NOT_FOUND The Joiner specified by @p aEui64 was not found.
|
* @retval kErrorNotFound The Joiner specified by @p aEui64 was not found.
|
||||||
* @retval OT_ERROR_INVALID_STATE Commissioner service is not started.
|
* @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);
|
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).
|
* @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 kErrorNone Successfully set the Provisioning URL.
|
||||||
* @retval OT_ERROR_INVALID_ARGS @p aProvisioningUrl is invalid (too long).
|
* @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.
|
* This method returns the Commissioner Session ID.
|
||||||
@@ -272,12 +272,12 @@ public:
|
|||||||
* @param[in] aTlvs A pointer to Commissioning Data TLVs.
|
* @param[in] aTlvs A pointer to Commissioning Data TLVs.
|
||||||
* @param[in] aLength The length of requested TLVs in bytes.
|
* @param[in] aLength The length of requested TLVs in bytes.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Send MGMT_COMMISSIONER_GET successfully.
|
* @retval kErrorNone Send MGMT_COMMISSIONER_GET successfully.
|
||||||
* @retval OT_ERROR_NO_BUFS Insufficient buffer space to send.
|
* @retval kErrorNoBufs Insufficient buffer space to send.
|
||||||
* @retval OT_ERROR_INVALID_STATE Commissioner service is not started.
|
* @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.
|
* This method sends MGMT_COMMISSIONER_SET.
|
||||||
@@ -286,14 +286,12 @@ public:
|
|||||||
* @param[in] aTlvs A pointer to user specific Commissioning Data TLVs.
|
* @param[in] aTlvs A pointer to user specific Commissioning Data TLVs.
|
||||||
* @param[in] aLength The length of user specific TLVs in bytes.
|
* @param[in] aLength The length of user specific TLVs in bytes.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Send MGMT_COMMISSIONER_SET successfully.
|
* @retval kErrorNone Send MGMT_COMMISSIONER_SET successfully.
|
||||||
* @retval OT_ERROR_NO_BUFS Insufficient buffer space to send.
|
* @retval kErrorNoBufs Insufficient buffer space to send.
|
||||||
* @retval OT_ERROR_INVALID_STATE Commissioner service is not started.
|
* @retval kErrorInvalidState Commissioner service is not started.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError SendMgmtCommissionerSetRequest(const otCommissioningDataset &aDataset,
|
Error SendMgmtCommissionerSetRequest(const otCommissioningDataset &aDataset, const uint8_t *aTlvs, uint8_t aLength);
|
||||||
const uint8_t * aTlvs,
|
|
||||||
uint8_t aLength);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns a reference to the AnnounceBeginClient instance.
|
* This method returns a reference to the AnnounceBeginClient instance.
|
||||||
@@ -374,12 +372,12 @@ private:
|
|||||||
Joiner *FindBestMatchingJoinerEntry(const Mac::ExtAddress &aReceivedJoinerId);
|
Joiner *FindBestMatchingJoinerEntry(const Mac::ExtAddress &aReceivedJoinerId);
|
||||||
void RemoveJoinerEntry(Joiner &aJoiner);
|
void RemoveJoinerEntry(Joiner &aJoiner);
|
||||||
|
|
||||||
otError AddJoiner(const Mac::ExtAddress *aEui64,
|
Error AddJoiner(const Mac::ExtAddress *aEui64,
|
||||||
const JoinerDiscerner *aDiscerner,
|
const JoinerDiscerner *aDiscerner,
|
||||||
const char * aPskd,
|
const char * aPskd,
|
||||||
uint32_t aTimeout);
|
uint32_t aTimeout);
|
||||||
otError RemoveJoiner(const Mac::ExtAddress *aEui64, const JoinerDiscerner *aDiscerner, uint32_t aDelay);
|
Error RemoveJoiner(const Mac::ExtAddress *aEui64, const JoinerDiscerner *aDiscerner, uint32_t aDelay);
|
||||||
void RemoveJoiner(Joiner &aJoiner, uint32_t aDelay);
|
void RemoveJoiner(Joiner &aJoiner, uint32_t aDelay);
|
||||||
|
|
||||||
void AddCoapResources(void);
|
void AddCoapResources(void);
|
||||||
void RemoveCoapResources(void);
|
void RemoveCoapResources(void);
|
||||||
@@ -395,27 +393,27 @@ private:
|
|||||||
static void HandleMgmtCommissionerSetResponse(void * aContext,
|
static void HandleMgmtCommissionerSetResponse(void * aContext,
|
||||||
otMessage * aMessage,
|
otMessage * aMessage,
|
||||||
const otMessageInfo *aMessageInfo,
|
const otMessageInfo *aMessageInfo,
|
||||||
otError aResult);
|
Error aResult);
|
||||||
void HandleMgmtCommissionerSetResponse(Coap::Message * aMessage,
|
void HandleMgmtCommissionerSetResponse(Coap::Message * aMessage,
|
||||||
const Ip6::MessageInfo *aMessageInfo,
|
const Ip6::MessageInfo *aMessageInfo,
|
||||||
otError aResult);
|
Error aResult);
|
||||||
static void HandleMgmtCommissionerGetResponse(void * aContext,
|
static void HandleMgmtCommissionerGetResponse(void * aContext,
|
||||||
otMessage * aMessage,
|
otMessage * aMessage,
|
||||||
const otMessageInfo *aMessageInfo,
|
const otMessageInfo *aMessageInfo,
|
||||||
otError aResult);
|
Error aResult);
|
||||||
void HandleMgmtCommissionerGetResponse(Coap::Message * aMessage,
|
void HandleMgmtCommissionerGetResponse(Coap::Message * aMessage,
|
||||||
const Ip6::MessageInfo *aMessageInfo,
|
const Ip6::MessageInfo *aMessageInfo,
|
||||||
otError aResult);
|
Error aResult);
|
||||||
static void HandleLeaderPetitionResponse(void * aContext,
|
static void HandleLeaderPetitionResponse(void * aContext,
|
||||||
otMessage * aMessage,
|
otMessage * aMessage,
|
||||||
const otMessageInfo *aMessageInfo,
|
const otMessageInfo *aMessageInfo,
|
||||||
otError aResult);
|
Error aResult);
|
||||||
void HandleLeaderPetitionResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, otError aResult);
|
void HandleLeaderPetitionResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, Error aResult);
|
||||||
static void HandleLeaderKeepAliveResponse(void * aContext,
|
static void HandleLeaderKeepAliveResponse(void * aContext,
|
||||||
otMessage * aMessage,
|
otMessage * aMessage,
|
||||||
const otMessageInfo *aMessageInfo,
|
const otMessageInfo *aMessageInfo,
|
||||||
otError aResult);
|
Error aResult);
|
||||||
void HandleLeaderKeepAliveResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, otError aResult);
|
void HandleLeaderKeepAliveResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, Error aResult);
|
||||||
|
|
||||||
static void HandleCoapsConnected(bool aConnected, void *aContext);
|
static void HandleCoapsConnected(bool aConnected, void *aContext);
|
||||||
void HandleCoapsConnected(bool aConnected);
|
void HandleCoapsConnected(bool aConnected);
|
||||||
@@ -431,14 +429,14 @@ private:
|
|||||||
|
|
||||||
void SendJoinFinalizeResponse(const Coap::Message &aRequest, StateTlv::State aState);
|
void SendJoinFinalizeResponse(const Coap::Message &aRequest, StateTlv::State aState);
|
||||||
|
|
||||||
static otError SendRelayTransmit(void *aContext, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
static Error SendRelayTransmit(void *aContext, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||||
otError SendRelayTransmit(Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
Error SendRelayTransmit(Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||||
|
|
||||||
void ComputeBloomFilter(SteeringData &aSteeringData) const;
|
void ComputeBloomFilter(SteeringData &aSteeringData) const;
|
||||||
void SendCommissionerSet(void);
|
void SendCommissionerSet(void);
|
||||||
otError SendPetition(void);
|
Error SendPetition(void);
|
||||||
void SendKeepAlive(void);
|
void SendKeepAlive(void);
|
||||||
void SendKeepAlive(uint16_t aSessionId);
|
void SendKeepAlive(uint16_t aSessionId);
|
||||||
|
|
||||||
void SetState(State aState);
|
void SetState(State aState);
|
||||||
void SignalJoinerEvent(JoinerEvent aEvent, const Joiner *aJoiner) const;
|
void SignalJoinerEvent(JoinerEvent aEvent, const Joiner *aJoiner) const;
|
||||||
|
|||||||
@@ -48,9 +48,9 @@
|
|||||||
namespace ot {
|
namespace ot {
|
||||||
namespace MeshCoP {
|
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 supportedChannels = aInstance.Get<Mac::Mac>().GetSupportedChannelMask();
|
||||||
Mac::ChannelMask preferredChannels(aInstance.Get<Radio>().GetPreferredChannelMask());
|
Mac::ChannelMask preferredChannels(aInstance.Get<Radio>().GetPreferredChannelMask());
|
||||||
|
|
||||||
@@ -285,9 +285,9 @@ void Dataset::SetFrom(const otOperationalDatasetTlvs &aDataset)
|
|||||||
memcpy(mTlvs, aDataset.mTlvs, mLength);
|
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())
|
if (aDatasetInfo.IsActiveTimestampPresent())
|
||||||
{
|
{
|
||||||
@@ -400,9 +400,9 @@ void Dataset::SetTimestamp(const Timestamp &aTimestamp)
|
|||||||
IgnoreError(SetTlv((mType == kActive) ? Tlv::kActiveTimestamp : Tlv::kPendingTimestamp, 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;
|
uint16_t bytesAvailable = sizeof(mTlvs) - mLength;
|
||||||
Tlv * old = GetTlv(aType);
|
Tlv * old = GetTlv(aType);
|
||||||
Tlv tlv;
|
Tlv tlv;
|
||||||
@@ -412,7 +412,7 @@ otError Dataset::SetTlv(Tlv::Type aType, const void *aValue, uint8_t aLength)
|
|||||||
bytesAvailable += sizeof(Tlv) + old->GetLength();
|
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)
|
if (old != nullptr)
|
||||||
{
|
{
|
||||||
@@ -433,20 +433,20 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError Dataset::SetTlv(const Tlv &aTlv)
|
Error Dataset::SetTlv(const Tlv &aTlv)
|
||||||
{
|
{
|
||||||
return SetTlv(aTlv.GetType(), aTlv.GetValue(), aTlv.GetLength());
|
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));
|
SuccessOrExit(aMessage.Read(aOffset, mTlvs, aLength));
|
||||||
mLength = aLength;
|
mLength = aLength;
|
||||||
|
|
||||||
mUpdateTime = TimerMilli::GetNow();
|
mUpdateTime = TimerMilli::GetNow();
|
||||||
error = OT_ERROR_NONE;
|
error = kErrorNone;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return error;
|
return error;
|
||||||
@@ -463,9 +463,9 @@ exit:
|
|||||||
return;
|
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 tlv;
|
||||||
Mle::Tlv::Type type;
|
Mle::Tlv::Type type;
|
||||||
|
|
||||||
@@ -519,13 +519,13 @@ void Dataset::RemoveTlv(Tlv *aTlv)
|
|||||||
mLength -= length;
|
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>();
|
Mac::Mac & mac = aInstance.Get<Mac::Mac>();
|
||||||
KeyManager &keyManager = aInstance.Get<KeyManager>();
|
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)
|
if (aIsMasterKeyUpdated)
|
||||||
{
|
{
|
||||||
@@ -542,10 +542,10 @@ otError Dataset::ApplyConfiguration(Instance &aInstance, bool *aIsMasterKeyUpdat
|
|||||||
|
|
||||||
error = mac.SetPanChannel(channel);
|
error = mac.SetPanChannel(channel);
|
||||||
|
|
||||||
if (error != OT_ERROR_NONE)
|
if (error != kErrorNone)
|
||||||
{
|
{
|
||||||
otLogWarnMeshCoP("DatasetManager::ApplyConfiguration() Failed to set channel to %d (%s)", channel,
|
otLogWarnMeshCoP("DatasetManager::ApplyConfiguration() Failed to set channel to %d (%s)", channel,
|
||||||
otThreadErrorToString(error));
|
ErrorToString(error));
|
||||||
ExitNow();
|
ExitNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -603,10 +603,10 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[in] aInstance The OpenThread instance.
|
* @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
|
* 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.
|
* @param[in] aTlv A reference to the TLV.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully set the TLV.
|
* @retval kErrorNone Successfully set the TLV.
|
||||||
* @retval OT_ERROR_NO_BUFS Could not set the TLV due to insufficient buffer space.
|
* @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.
|
* 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] aValue A pointer to TLV Value.
|
||||||
* @param[in] aLength The TLV Length in bytes (length of @p aValue).
|
* @param[in] aLength The TLV Length in bytes (length of @p aValue).
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully set the TLV.
|
* @retval kErrorNone Successfully set the TLV.
|
||||||
* @retval OT_ERROR_NO_BUFS Could not set the TLV due to insufficient buffer space.
|
* @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.
|
* 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] aType The TLV Type.
|
||||||
* @param[in] aValue The TLV Value (of type `ValueType`).
|
* @param[in] aValue The TLV Value (of type `ValueType`).
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully set the TLV.
|
* @retval kErrorNone Successfully set the TLV.
|
||||||
* @retval OT_ERROR_NO_BUFS Could not set the TLV due to insufficient buffer space.
|
* @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");
|
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] aOffset The message buffer offset where the dataset starts.
|
||||||
* @param[in] aLength The TLVs length in the message buffer in bytes.
|
* @param[in] aLength The TLVs length in the message buffer in bytes.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully set the Dataset.
|
* @retval kErrorNone Successfully set the Dataset.
|
||||||
* @retval OT_ERROR_INVALID_ARGS The values of @p aOffset and @p aLength are not valid for @p aMessage.
|
* @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.
|
* This method sets the Dataset using an existing Dataset.
|
||||||
@@ -831,11 +831,11 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[in] aDatasetInfo The input Dataset as `Dataset::Info`.
|
* @param[in] aDatasetInfo The input Dataset as `Dataset::Info`.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully set the Dataset.
|
* @retval kErrorNone Successfully set the Dataset.
|
||||||
* @retval OT_ERROR_INVALID_ARGS Dataset is missing Active and/or Pending Timestamp.
|
* @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.
|
* This method sets the Dataset using @p aDataset.
|
||||||
@@ -858,11 +858,11 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[in] aMessage A message to append to.
|
* @param[in] aMessage A message to append to.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully append MLE Dataset TLV without MeshCoP Sub Timestamp TLV.
|
* @retval kErrorNone 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 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.
|
* 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[in] aInstance A reference to the OpenThread instance.
|
||||||
* @param[out] aIsMasterKeyUpdated A pointer to where to place whether master key was updated.
|
* @param[out] aIsMasterKeyUpdated A pointer to where to place whether master key was updated.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully applied configuration.
|
* @retval kErrorNone Successfully applied configuration.
|
||||||
* @retval OT_ERROR_PARSE The dataset has at least one TLV with invalid format.
|
* @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.
|
* This method converts a Pending Dataset to an Active Dataset.
|
||||||
@@ -943,11 +943,11 @@ private:
|
|||||||
* @param[in] aType The TLV Type.
|
* @param[in] aType The TLV Type.
|
||||||
* @param[in] aValue The TLV value (as `uint16_t`).
|
* @param[in] aValue The TLV value (as `uint16_t`).
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully set the TLV.
|
* @retval kErrorNone Successfully set the TLV.
|
||||||
* @retval OT_ERROR_NO_BUFS Could not set the TLV due to insufficient buffer space.
|
* @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);
|
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] aType The TLV Type.
|
||||||
* @param[in] aValue The TLV value (as `uint32_t`).
|
* @param[in] aValue The TLV value (as `uint32_t`).
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully set the TLV.
|
* @retval kErrorNone Successfully set the TLV.
|
||||||
* @retval OT_ERROR_NO_BUFS Could not set the TLV due to insufficient buffer space.
|
* @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);
|
uint32_t value = Encoding::BigEndian::HostSwap32(aValue);
|
||||||
|
|
||||||
|
|||||||
@@ -66,10 +66,10 @@ void DatasetLocal::Clear(void)
|
|||||||
mSaved = false;
|
mSaved = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError DatasetLocal::Restore(Dataset &aDataset)
|
Error DatasetLocal::Restore(Dataset &aDataset)
|
||||||
{
|
{
|
||||||
const Timestamp *timestamp;
|
const Timestamp *timestamp;
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
mTimestampPresent = false;
|
mTimestampPresent = false;
|
||||||
|
|
||||||
@@ -89,14 +89,14 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError DatasetLocal::Read(Dataset &aDataset) const
|
Error DatasetLocal::Read(Dataset &aDataset) const
|
||||||
{
|
{
|
||||||
DelayTimerTlv *delayTimer;
|
DelayTimerTlv *delayTimer;
|
||||||
uint32_t elapsed;
|
uint32_t elapsed;
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
error = Get<Settings>().ReadOperationalDataset(IsActive(), aDataset);
|
error = Get<Settings>().ReadOperationalDataset(IsActive(), aDataset);
|
||||||
VerifyOrExit(error == OT_ERROR_NONE, aDataset.mLength = 0);
|
VerifyOrExit(error == kErrorNone, aDataset.mLength = 0);
|
||||||
|
|
||||||
if (mType == Dataset::kActive)
|
if (mType == Dataset::kActive)
|
||||||
{
|
{
|
||||||
@@ -126,10 +126,10 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError DatasetLocal::Read(Dataset::Info &aDatasetInfo) const
|
Error DatasetLocal::Read(Dataset::Info &aDatasetInfo) const
|
||||||
{
|
{
|
||||||
Dataset dataset(mType);
|
Dataset dataset(mType);
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
aDatasetInfo.Clear();
|
aDatasetInfo.Clear();
|
||||||
|
|
||||||
@@ -140,10 +140,10 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError DatasetLocal::Read(otOperationalDatasetTlvs &aDataset) const
|
Error DatasetLocal::Read(otOperationalDatasetTlvs &aDataset) const
|
||||||
{
|
{
|
||||||
Dataset dataset(mType);
|
Dataset dataset(mType);
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
memset(&aDataset, 0, sizeof(aDataset));
|
memset(&aDataset, 0, sizeof(aDataset));
|
||||||
|
|
||||||
@@ -154,9 +154,9 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError DatasetLocal::Save(const Dataset::Info &aDatasetInfo)
|
Error DatasetLocal::Save(const Dataset::Info &aDatasetInfo)
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
Dataset dataset(mType);
|
Dataset dataset(mType);
|
||||||
|
|
||||||
SuccessOrExit(error = dataset.SetFrom(aDatasetInfo));
|
SuccessOrExit(error = dataset.SetFrom(aDatasetInfo));
|
||||||
@@ -166,7 +166,7 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError DatasetLocal::Save(const otOperationalDatasetTlvs &aDataset)
|
Error DatasetLocal::Save(const otOperationalDatasetTlvs &aDataset)
|
||||||
{
|
{
|
||||||
Dataset dataset(mType);
|
Dataset dataset(mType);
|
||||||
|
|
||||||
@@ -175,10 +175,10 @@ otError DatasetLocal::Save(const otOperationalDatasetTlvs &aDataset)
|
|||||||
return Save(dataset);
|
return Save(dataset);
|
||||||
}
|
}
|
||||||
|
|
||||||
otError DatasetLocal::Save(const Dataset &aDataset)
|
Error DatasetLocal::Save(const Dataset &aDataset)
|
||||||
{
|
{
|
||||||
const Timestamp *timestamp;
|
const Timestamp *timestamp;
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
|
|
||||||
if (aDataset.GetSize() == 0)
|
if (aDataset.GetSize() == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -95,44 +95,44 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[out] aDataset Where to place the dataset.
|
* @param[out] aDataset Where to place the dataset.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully retrieved the dataset.
|
* @retval kErrorNone Successfully retrieved the dataset.
|
||||||
* @retval OT_ERROR_NOT_FOUND There is no corresponding dataset stored in non-volatile memory.
|
* @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.
|
* This method retrieves the dataset from non-volatile memory.
|
||||||
*
|
*
|
||||||
* @param[out] aDataset Where to place the dataset.
|
* @param[out] aDataset Where to place the dataset.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully retrieved the dataset.
|
* @retval kErrorNone Successfully retrieved the dataset.
|
||||||
* @retval OT_ERROR_NOT_FOUND There is no corresponding dataset stored in non-volatile memory.
|
* @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.
|
* This method retrieves the dataset from non-volatile memory.
|
||||||
*
|
*
|
||||||
* @param[out] aDatasetInfo Where to place the dataset as `Dataset::Info`.
|
* @param[out] aDatasetInfo Where to place the dataset as `Dataset::Info`.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully retrieved the dataset.
|
* @retval kErrorNone Successfully retrieved the dataset.
|
||||||
* @retval OT_ERROR_NOT_FOUND There is no corresponding dataset stored in non-volatile memory.
|
* @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.
|
* This method retrieves the dataset from non-volatile memory.
|
||||||
*
|
*
|
||||||
* @param[out] aDataset Where to place the dataset.
|
* @param[out] aDataset Where to place the dataset.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully retrieved the dataset.
|
* @retval kErrorNone Successfully retrieved the dataset.
|
||||||
* @retval OT_ERROR_NOT_FOUND There is no corresponding dataset stored in non-volatile memory.
|
* @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.
|
* 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`.
|
* @param[in] aDatasetInfo The Dataset to save as `Dataset::Info`.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully saved the dataset.
|
* @retval kErrorNone Successfully saved the dataset.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @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.
|
* This method stores the dataset into non-volatile memory.
|
||||||
*
|
*
|
||||||
* @param[in] aDataset The Dataset to save as `otOperationalDatasetTlvs`.
|
* @param[in] aDataset The Dataset to save as `otOperationalDatasetTlvs`.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully saved the dataset.
|
* @retval kErrorNone Successfully saved the dataset.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @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.
|
* This method stores the dataset into non-volatile memory.
|
||||||
*
|
*
|
||||||
* @param[in] aDataset The Dataset to save.
|
* @param[in] aDataset The Dataset to save.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully saved the dataset.
|
* @retval kErrorNone Successfully saved the dataset.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @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.
|
* This method compares this dataset to another based on the timestamp.
|
||||||
|
|||||||
@@ -78,9 +78,9 @@ int DatasetManager::Compare(const Timestamp &aTimestamp) const
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError DatasetManager::Restore(void)
|
Error DatasetManager::Restore(void)
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
Dataset dataset(GetType());
|
Dataset dataset(GetType());
|
||||||
const Timestamp *timestamp;
|
const Timestamp *timestamp;
|
||||||
|
|
||||||
@@ -109,9 +109,9 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError DatasetManager::ApplyConfiguration(void) const
|
Error DatasetManager::ApplyConfiguration(void) const
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
Dataset dataset(GetType());
|
Dataset dataset(GetType());
|
||||||
|
|
||||||
SuccessOrExit(error = Read(dataset));
|
SuccessOrExit(error = Read(dataset));
|
||||||
@@ -135,9 +135,9 @@ void DatasetManager::HandleDetach(void)
|
|||||||
IgnoreError(Restore());
|
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;
|
const Timestamp *timestamp;
|
||||||
int compare;
|
int compare;
|
||||||
bool isMasterkeyUpdated = false;
|
bool isMasterkeyUpdated = false;
|
||||||
@@ -167,7 +167,7 @@ otError DatasetManager::Save(const Dataset &aDataset)
|
|||||||
}
|
}
|
||||||
else if (compare < 0)
|
else if (compare < 0)
|
||||||
{
|
{
|
||||||
VerifyOrExit(!Get<Mle::MleRouter>().IsLeader(), error = OT_ERROR_INVALID_STATE);
|
VerifyOrExit(!Get<Mle::MleRouter>().IsLeader(), error = kErrorInvalidState);
|
||||||
SendSet();
|
SendSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,9 +177,9 @@ exit:
|
|||||||
return error;
|
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));
|
SuccessOrExit(error = mLocal.Save(aDatasetInfo));
|
||||||
HandleDatasetUpdated();
|
HandleDatasetUpdated();
|
||||||
@@ -188,9 +188,9 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError DatasetManager::Save(const otOperationalDatasetTlvs &aDataset)
|
Error DatasetManager::Save(const otOperationalDatasetTlvs &aDataset)
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
SuccessOrExit(error = mLocal.Save(aDataset));
|
SuccessOrExit(error = mLocal.Save(aDataset));
|
||||||
HandleDatasetUpdated();
|
HandleDatasetUpdated();
|
||||||
@@ -199,9 +199,9 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError DatasetManager::SaveLocal(const Dataset &aDataset)
|
Error DatasetManager::SaveLocal(const Dataset &aDataset)
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
SuccessOrExit(error = mLocal.Save(aDataset));
|
SuccessOrExit(error = mLocal.Save(aDataset));
|
||||||
HandleDatasetUpdated();
|
HandleDatasetUpdated();
|
||||||
@@ -245,9 +245,9 @@ void DatasetManager::SignalDatasetChange(void) const
|
|||||||
: kEventPendingDatasetChanged);
|
: kEventPendingDatasetChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
otError DatasetManager::GetChannelMask(Mac::ChannelMask &aChannelMask) const
|
Error DatasetManager::GetChannelMask(Mac::ChannelMask &aChannelMask) const
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
const MeshCoP::ChannelMaskTlv *channelMaskTlv;
|
const MeshCoP::ChannelMaskTlv *channelMaskTlv;
|
||||||
uint32_t mask;
|
uint32_t mask;
|
||||||
Dataset dataset(GetType());
|
Dataset dataset(GetType());
|
||||||
@@ -255,12 +255,12 @@ otError DatasetManager::GetChannelMask(Mac::ChannelMask &aChannelMask) const
|
|||||||
SuccessOrExit(error = Read(dataset));
|
SuccessOrExit(error = Read(dataset));
|
||||||
|
|
||||||
channelMaskTlv = dataset.GetTlv<ChannelMaskTlv>();
|
channelMaskTlv = dataset.GetTlv<ChannelMaskTlv>();
|
||||||
VerifyOrExit(channelMaskTlv != nullptr, error = OT_ERROR_NOT_FOUND);
|
VerifyOrExit(channelMaskTlv != nullptr, error = kErrorNotFound);
|
||||||
VerifyOrExit((mask = channelMaskTlv->GetChannelMask()) != 0);
|
VerifyOrExit((mask = channelMaskTlv->GetChannelMask()) != 0);
|
||||||
|
|
||||||
aChannelMask.SetMask(mask & Get<Mac::Mac>().GetSupportedChannelMask().GetMask());
|
aChannelMask.SetMask(mask & Get<Mac::Mac>().GetSupportedChannelMask().GetMask());
|
||||||
|
|
||||||
VerifyOrExit(!aChannelMask.IsEmpty(), error = OT_ERROR_NOT_FOUND);
|
VerifyOrExit(!aChannelMask.IsEmpty(), error = kErrorNotFound);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return error;
|
return error;
|
||||||
@@ -273,14 +273,14 @@ void DatasetManager::HandleTimer(void)
|
|||||||
|
|
||||||
void DatasetManager::SendSet(void)
|
void DatasetManager::SendSet(void)
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
Coap::Message * message = nullptr;
|
Coap::Message * message = nullptr;
|
||||||
Ip6::MessageInfo messageInfo;
|
Ip6::MessageInfo messageInfo;
|
||||||
Dataset dataset(GetType());
|
Dataset dataset(GetType());
|
||||||
|
|
||||||
VerifyOrExit(!mCoapPending, error = OT_ERROR_BUSY);
|
VerifyOrExit(!mCoapPending, error = kErrorBusy);
|
||||||
VerifyOrExit(Get<Mle::MleRouter>().IsAttached(), error = OT_ERROR_INVALID_STATE);
|
VerifyOrExit(Get<Mle::MleRouter>().IsAttached(), error = kErrorInvalidState);
|
||||||
VerifyOrExit(mLocal.Compare(GetTimestamp()) < 0, error = OT_ERROR_INVALID_STATE);
|
VerifyOrExit(mLocal.Compare(GetTimestamp()) < 0, error = kErrorInvalidState);
|
||||||
|
|
||||||
if (IsActiveDataset())
|
if (IsActiveDataset())
|
||||||
{
|
{
|
||||||
@@ -293,11 +293,11 @@ void DatasetManager::SendSet(void)
|
|||||||
if (pendingActiveTimestamp != nullptr && mLocal.Compare(pendingActiveTimestamp) == 0)
|
if (pendingActiveTimestamp != nullptr && mLocal.Compare(pendingActiveTimestamp) == 0)
|
||||||
{
|
{
|
||||||
// stop registration attempts during dataset transition
|
// 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 =
|
SuccessOrExit(error =
|
||||||
message->InitAsConfirmablePost(IsActiveDataset() ? UriPath::kActiveSet : UriPath::kPendingSet));
|
message->InitAsConfirmablePost(IsActiveDataset() ? UriPath::kActiveSet : UriPath::kPendingSet));
|
||||||
@@ -318,11 +318,11 @@ exit:
|
|||||||
|
|
||||||
switch (error)
|
switch (error)
|
||||||
{
|
{
|
||||||
case OT_ERROR_NONE:
|
case kErrorNone:
|
||||||
mCoapPending = true;
|
mCoapPending = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OT_ERROR_NO_BUFS:
|
case kErrorNoBufs:
|
||||||
mTimer.Start(kDelayNoBufs);
|
mTimer.Start(kDelayNoBufs);
|
||||||
OT_FALL_THROUGH;
|
OT_FALL_THROUGH;
|
||||||
|
|
||||||
@@ -336,7 +336,7 @@ exit:
|
|||||||
void DatasetManager::HandleCoapResponse(void * aContext,
|
void DatasetManager::HandleCoapResponse(void * aContext,
|
||||||
otMessage * aMessage,
|
otMessage * aMessage,
|
||||||
const otMessageInfo *aMessageInfo,
|
const otMessageInfo *aMessageInfo,
|
||||||
otError aError)
|
Error aError)
|
||||||
{
|
{
|
||||||
OT_UNUSED_VARIABLE(aMessage);
|
OT_UNUSED_VARIABLE(aMessage);
|
||||||
OT_UNUSED_VARIABLE(aMessageInfo);
|
OT_UNUSED_VARIABLE(aMessageInfo);
|
||||||
@@ -401,13 +401,13 @@ void DatasetManager::SendGetResponse(const Coap::Message & aRequest,
|
|||||||
uint8_t * aTlvs,
|
uint8_t * aTlvs,
|
||||||
uint8_t aLength) const
|
uint8_t aLength) const
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Coap::Message *message;
|
Coap::Message *message;
|
||||||
Dataset dataset(GetType());
|
Dataset dataset(GetType());
|
||||||
|
|
||||||
IgnoreError(Read(dataset));
|
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->SetDefaultResponseHeader(aRequest));
|
||||||
SuccessOrExit(error = message->SetPayloadMarker());
|
SuccessOrExit(error = message->SetPayloadMarker());
|
||||||
@@ -454,9 +454,9 @@ exit:
|
|||||||
FreeMessageOnError(message, error);
|
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());
|
Dataset dataset(GetType());
|
||||||
|
|
||||||
SuccessOrExit(error = dataset.SetFrom(aDatasetInfo));
|
SuccessOrExit(error = dataset.SetFrom(aDatasetInfo));
|
||||||
@@ -466,13 +466,13 @@ exit:
|
|||||||
return error;
|
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;
|
Coap::Message * message;
|
||||||
Ip6::MessageInfo messageInfo;
|
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 =
|
SuccessOrExit(error =
|
||||||
message->InitAsConfirmablePost(IsActiveDataset() ? UriPath::kActiveSet : UriPath::kPendingSet));
|
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())
|
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)
|
if (cur->GetType() == Tlv::kCommissionerSessionId)
|
||||||
{
|
{
|
||||||
@@ -529,12 +529,12 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError DatasetManager::SendGetRequest(const Dataset::Components &aDatasetComponents,
|
Error DatasetManager::SendGetRequest(const Dataset::Components &aDatasetComponents,
|
||||||
const uint8_t * aTlvTypes,
|
const uint8_t * aTlvTypes,
|
||||||
uint8_t aLength,
|
uint8_t aLength,
|
||||||
const otIp6Address * aAddress) const
|
const otIp6Address * aAddress) const
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
Error error = kErrorNone;
|
||||||
Coap::Message * message;
|
Coap::Message * message;
|
||||||
Ip6::MessageInfo messageInfo;
|
Ip6::MessageInfo messageInfo;
|
||||||
Tlv tlv;
|
Tlv tlv;
|
||||||
@@ -603,7 +603,7 @@ otError DatasetManager::SendGetRequest(const Dataset::Components &aDatasetCompon
|
|||||||
datasetTlvs[length++] = Tlv::kChannelMask;
|
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 =
|
SuccessOrExit(error =
|
||||||
message->InitAsConfirmablePost(IsActiveDataset() ? UriPath::kActiveGet : UriPath::kPendingGet));
|
message->InitAsConfirmablePost(IsActiveDataset() ? UriPath::kActiveGet : UriPath::kPendingGet));
|
||||||
@@ -679,9 +679,9 @@ exit:
|
|||||||
return isValid;
|
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());
|
Dataset dataset(GetType());
|
||||||
|
|
||||||
SuccessOrExit(error = dataset.Set(aMessage, aOffset, aLength));
|
SuccessOrExit(error = dataset.Set(aMessage, aOffset, aLength));
|
||||||
@@ -734,9 +734,9 @@ void PendingDataset::ClearNetwork(void)
|
|||||||
IgnoreError(DatasetManager::Save(dataset));
|
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));
|
SuccessOrExit(error = DatasetManager::Save(aDatasetInfo));
|
||||||
StartDelayTimer();
|
StartDelayTimer();
|
||||||
@@ -745,9 +745,9 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError PendingDataset::Save(const otOperationalDatasetTlvs &aDataset)
|
Error PendingDataset::Save(const otOperationalDatasetTlvs &aDataset)
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
SuccessOrExit(error = DatasetManager::Save(aDataset));
|
SuccessOrExit(error = DatasetManager::Save(aDataset));
|
||||||
StartDelayTimer();
|
StartDelayTimer();
|
||||||
@@ -756,9 +756,9 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
otError PendingDataset::Save(const Dataset &aDataset)
|
Error PendingDataset::Save(const Dataset &aDataset)
|
||||||
{
|
{
|
||||||
otError error;
|
Error error;
|
||||||
|
|
||||||
SuccessOrExit(error = DatasetManager::SaveLocal(aDataset));
|
SuccessOrExit(error = DatasetManager::SaveLocal(aDataset));
|
||||||
StartDelayTimer();
|
StartDelayTimer();
|
||||||
@@ -767,9 +767,9 @@ exit:
|
|||||||
return error;
|
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());
|
Dataset dataset(GetType());
|
||||||
|
|
||||||
SuccessOrExit(error = dataset.Set(aMessage, aOffset, aLength));
|
SuccessOrExit(error = dataset.Set(aMessage, aOffset, aLength));
|
||||||
|
|||||||
@@ -64,11 +64,11 @@ public:
|
|||||||
/**
|
/**
|
||||||
* This method restores the Operational Dataset from non-volatile memory.
|
* This method restores the Operational Dataset from non-volatile memory.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully restore the dataset.
|
* @retval kErrorNone Successfully restore the dataset.
|
||||||
* @retval OT_ERROR_NOT_FOUND There is no corresponding dataset stored in non-volatile memory.
|
* @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.
|
* This method compares @p aTimestamp to the dataset's timestamp value.
|
||||||
@@ -87,53 +87,53 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[out] aDataset Where to place the dataset.
|
* @param[out] aDataset Where to place the dataset.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully retrieved the dataset.
|
* @retval kErrorNone Successfully retrieved the dataset.
|
||||||
* @retval OT_ERROR_NOT_FOUND There is no corresponding dataset stored in non-volatile memory.
|
* @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.
|
* This method retrieves the dataset from non-volatile memory.
|
||||||
*
|
*
|
||||||
* @param[out] aDatasetInfo Where to place the dataset (as `Dataset::Info`).
|
* @param[out] aDatasetInfo Where to place the dataset (as `Dataset::Info`).
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully retrieved the dataset.
|
* @retval kErrorNone Successfully retrieved the dataset.
|
||||||
* @retval OT_ERROR_NOT_FOUND There is no corresponding dataset stored in non-volatile memory.
|
* @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.
|
* This method retrieves the dataset from non-volatile memory.
|
||||||
*
|
*
|
||||||
* @param[out] aDataset Where to place the dataset.
|
* @param[out] aDataset Where to place the dataset.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully retrieved the dataset.
|
* @retval kErrorNone Successfully retrieved the dataset.
|
||||||
* @retval OT_ERROR_NOT_FOUND There is no corresponding dataset stored in non-volatile memory.
|
* @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.
|
* This method retrieves the channel mask from local dataset.
|
||||||
*
|
*
|
||||||
* @param[out] aChannelMask A reference to the channel mask.
|
* @param[out] aChannelMask A reference to the channel mask.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully retrieved the channel mask.
|
* @retval kErrorNone Successfully retrieved the channel mask.
|
||||||
* @retval OT_ERROR_NOT_FOUND There is no valid channel mask stored in local dataset.
|
* @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.
|
* This method applies the Active or Pending Dataset to the Thread interface.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully applied configuration.
|
* @retval kErrorNone Successfully applied configuration.
|
||||||
* @retval OT_ERROR_PARSE The dataset has at least one TLV with invalid format.
|
* @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.
|
* 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] aTlvs Any additional raw TLVs to include.
|
||||||
* @param[in] aLength Number of bytes in @p aTlvs.
|
* @param[in] aLength Number of bytes in @p aTlvs.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully send the meshcop dataset command.
|
* @retval kErrorNone Successfully send the meshcop dataset command.
|
||||||
* @retval OT_ERROR_NO_BUFS Insufficient buffer space to send.
|
* @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.
|
* This method sends a MGMT_GET request.
|
||||||
@@ -164,25 +164,25 @@ public:
|
|||||||
* @param[in] aLength Number of bytes in @p aTlvTypes.
|
* @param[in] aLength Number of bytes in @p aTlvTypes.
|
||||||
* @param[in] aAddress The IPv6 destination address for the MGMT_GET request.
|
* @param[in] aAddress The IPv6 destination address for the MGMT_GET request.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully send the meshcop dataset command.
|
* @retval kErrorNone Successfully send the meshcop dataset command.
|
||||||
* @retval OT_ERROR_NO_BUFS Insufficient buffer space to send.
|
* @retval kErrorNoBufs Insufficient buffer space to send.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError SendGetRequest(const Dataset::Components &aDatasetComponents,
|
Error SendGetRequest(const Dataset::Components &aDatasetComponents,
|
||||||
const uint8_t * aTlvTypes,
|
const uint8_t * aTlvTypes,
|
||||||
uint8_t aLength,
|
uint8_t aLength,
|
||||||
const otIp6Address * aAddress) const;
|
const otIp6Address * aAddress) const;
|
||||||
#if OPENTHREAD_FTD
|
#if OPENTHREAD_FTD
|
||||||
/**
|
/**
|
||||||
* This method appends the MLE Dataset TLV but excluding MeshCoP Sub Timestamp TLV.
|
* This method appends the MLE Dataset TLV but excluding MeshCoP Sub Timestamp TLV.
|
||||||
*
|
*
|
||||||
* @param[in] aMessage The message to append the TLV to.
|
* @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 kErrorNone 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 kErrorNoBufs Insufficient available buffers to append the message with MLE Dataset TLV.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError AppendMleDatasetTlv(Message &aMessage) const;
|
Error AppendMleDatasetTlv(Message &aMessage) const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -200,11 +200,11 @@ protected:
|
|||||||
* @param[in] aMessage A message to read the TLV from.
|
* @param[in] aMessage A message to read the TLV from.
|
||||||
* @param[in] aOffset An offset into the message to read from.
|
* @param[in] aOffset An offset into the message to read from.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE The TLV was read successfully.
|
* @retval kErrorNone The TLV was read successfully.
|
||||||
* @retval OT_ERROR_PARSE The TLV was not well-formed and could not be parsed.
|
* @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:
|
private:
|
||||||
enum
|
enum
|
||||||
@@ -244,33 +244,33 @@ protected:
|
|||||||
*
|
*
|
||||||
* @param[in] aDataset The Operational Dataset.
|
* @param[in] aDataset The Operational Dataset.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully applied configuration.
|
* @retval kErrorNone Successfully applied configuration.
|
||||||
* @retval OT_ERROR_PARSE The dataset has at least one TLV with invalid format.
|
* @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.
|
* This method saves the Operational Dataset in non-volatile memory.
|
||||||
*
|
*
|
||||||
* @param[in] aDatasetInfo The Operational Dataset as `Dataset::Info`.
|
* @param[in] aDatasetInfo The Operational Dataset as `Dataset::Info`.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully saved the dataset.
|
* @retval kErrorNone Successfully saved the dataset.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @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.
|
* This method saves the Operational Dataset in non-volatile memory.
|
||||||
*
|
*
|
||||||
* @param[in] aDataset The Operational Dataset.
|
* @param[in] aDataset The Operational Dataset.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully saved the dataset.
|
* @retval kErrorNone Successfully saved the dataset.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @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.
|
* This method sets the Operational Dataset for the partition.
|
||||||
@@ -283,18 +283,18 @@ protected:
|
|||||||
* @param[in] aLength The length of the Operational Dataset.
|
* @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.
|
* This method saves the Operational Dataset in non-volatile memory.
|
||||||
*
|
*
|
||||||
* @param[in] aDataset The Operational Dataset.
|
* @param[in] aDataset The Operational Dataset.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully applied configuration.
|
* @retval kErrorNone Successfully applied configuration.
|
||||||
* @retval OT_ERROR_PARSE The dataset has at least one TLV with invalid format.
|
* @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.
|
* This method handles a MGMT_GET request message.
|
||||||
@@ -327,11 +327,11 @@ protected:
|
|||||||
* @param[in] aMessage The CoAP message buffer.
|
* @param[in] aMessage The CoAP message buffer.
|
||||||
* @param[in] aMessageInfo The message info.
|
* @param[in] aMessageInfo The message info.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE The MGMT_SET request message was handled successfully.
|
* @retval kErrorNone The MGMT_SET request message was handled successfully.
|
||||||
* @retval OT_ERROR_DROP The MGMT_SET request message was dropped.
|
* @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
|
#endif
|
||||||
|
|
||||||
DatasetLocal mLocal;
|
DatasetLocal mLocal;
|
||||||
@@ -342,19 +342,19 @@ private:
|
|||||||
static void HandleCoapResponse(void * aContext,
|
static void HandleCoapResponse(void * aContext,
|
||||||
otMessage * aMessage,
|
otMessage * aMessage,
|
||||||
const otMessageInfo *aMessageInfo,
|
const otMessageInfo *aMessageInfo,
|
||||||
otError aError);
|
Error aError);
|
||||||
void HandleCoapResponse(void);
|
void HandleCoapResponse(void);
|
||||||
|
|
||||||
bool IsActiveDataset(void) const { return GetType() == Dataset::kActive; }
|
bool IsActiveDataset(void) const { return GetType() == Dataset::kActive; }
|
||||||
bool IsPendingDataset(void) const { return GetType() == Dataset::kPending; }
|
bool IsPendingDataset(void) const { return GetType() == Dataset::kPending; }
|
||||||
void SignalDatasetChange(void) const;
|
void SignalDatasetChange(void) const;
|
||||||
void HandleDatasetUpdated(void);
|
void HandleDatasetUpdated(void);
|
||||||
otError AppendDatasetToMessage(const Dataset::Info &aDatasetInfo, Message &aMessage) const;
|
Error AppendDatasetToMessage(const Dataset::Info &aDatasetInfo, Message &aMessage) const;
|
||||||
void SendSet(void);
|
void SendSet(void);
|
||||||
void SendGetResponse(const Coap::Message & aRequest,
|
void SendGetResponse(const Coap::Message & aRequest,
|
||||||
const Ip6::MessageInfo &aMessageInfo,
|
const Ip6::MessageInfo &aMessageInfo,
|
||||||
uint8_t * aTlvs,
|
uint8_t * aTlvs,
|
||||||
uint8_t aLength) const;
|
uint8_t aLength) const;
|
||||||
|
|
||||||
#if OPENTHREAD_FTD
|
#if OPENTHREAD_FTD
|
||||||
void SendSetResponse(const Coap::Message &aRequest, const Ip6::MessageInfo &aMessageInfo, StateTlv::State aState);
|
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.
|
* @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.
|
* This method sets the Operational Dataset in non-volatile memory.
|
||||||
*
|
*
|
||||||
* @param[in] aDatasetInfo The Operational Dataset as `Dataset::Info`.
|
* @param[in] aDatasetInfo The Operational Dataset as `Dataset::Info`.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully saved the dataset.
|
* @retval kErrorNone Successfully saved the dataset.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @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.
|
* This method sets the Operational Dataset in non-volatile memory.
|
||||||
*
|
*
|
||||||
* @param[in] aDataset The Operational Dataset.
|
* @param[in] aDataset The Operational Dataset.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully saved the dataset.
|
* @retval kErrorNone Successfully saved the dataset.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @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
|
#if OPENTHREAD_FTD
|
||||||
|
|
||||||
@@ -461,11 +461,11 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[out] aDatasetInfo The Operational Dataset as `Dataset::Info`.
|
* @param[out] aDatasetInfo The Operational Dataset as `Dataset::Info`.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully created a new Operational Dataset.
|
* @retval kErrorNone Successfully created a new Operational Dataset.
|
||||||
* @retval OT_ERROR_FAILED Failed to generate random values for new parameters.
|
* @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.
|
* 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.
|
* This method generate a default Active Operational Dataset.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully generated an Active Operational Dataset.
|
* @retval kErrorNone Successfully generated an Active Operational Dataset.
|
||||||
* @retval OT_ERROR_ALREADY A valid Active Operational Dataset already exists.
|
* @retval kErrorAlready A valid Active Operational Dataset already exists.
|
||||||
* @retval OT_ERROR_INVALID_STATE Device is not currently attached to a network.
|
* @retval kErrorInvalidState Device is not currently attached to a network.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
otError GenerateLocal(void);
|
Error GenerateLocal(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -543,11 +543,11 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[in] aDatasetInfo The Operational Dataset as `Dataset::Info`.
|
* @param[in] aDatasetInfo The Operational Dataset as `Dataset::Info`.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully saved the dataset.
|
* @retval kErrorNone Successfully saved the dataset.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @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.
|
* This method saves the Operational Dataset in non-volatile memory.
|
||||||
@@ -556,11 +556,11 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[in] aDataset The Operational Dataset.
|
* @param[in] aDataset The Operational Dataset.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully saved the dataset.
|
* @retval kErrorNone Successfully saved the dataset.
|
||||||
* @retval OT_ERROR_NOT_IMPLEMENTED The platform does not implement settings functionality.
|
* @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.
|
* This method sets the Operational Dataset for the partition.
|
||||||
@@ -575,18 +575,18 @@ public:
|
|||||||
* @param[in] aLength The length of the Operational Dataset.
|
* @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.
|
* This method saves the Operational Dataset in non-volatile memory.
|
||||||
*
|
*
|
||||||
* @param[in] aDataset The Operational Dataset.
|
* @param[in] aDataset The Operational Dataset.
|
||||||
*
|
*
|
||||||
* @retval OT_ERROR_NONE Successfully applied configuration.
|
* @retval kErrorNone Successfully applied configuration.
|
||||||
* @retval OT_ERROR_PARSE The dataset has at least one TLV with invalid format.
|
* @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
|
#if OPENTHREAD_FTD
|
||||||
/**
|
/**
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user