diff --git a/include/openthread/channel_manager.h b/include/openthread/channel_manager.h index 56342c179..b4ef6a908 100644 --- a/include/openthread/channel_manager.h +++ b/include/openthread/channel_manager.h @@ -127,8 +127,6 @@ otError otChannelManagerSetDelay(otInstance *aInstance, uint16_t aDelay); * * @retval OT_ERROR_NONE Channel selection finished successfully. * @retval OT_ERROR_NOT_FOUND Supported channel mask is empty, therefore could not select a channel. - * @retval OT_ERROR_INVALID_STATE Thread is not enabled or not enough data to select a new channel. - * @retval OT_ERROR_DISABLED_FEATURE `ChannelMonitor` feature is disabled by build-time configuration options. * */ otError otChannelManagerRequestChannelSelect(otInstance *aInstance, bool aSkipQualityCheck); diff --git a/include/openthread/coap_secure.h b/include/openthread/coap_secure.h index ab1236202..e939fe58f 100644 --- a/include/openthread/coap_secure.h +++ b/include/openthread/coap_secure.h @@ -32,6 +32,9 @@ * This file defines the top-level functions for the OpenThread CoAP Secure implementation. * * @note + * The functions in this module require the build-time feature `OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE=1`. + * + * @note * To enable cipher suite DTLS_PSK_WITH_AES_128_CCM_8, MBEDTLS_KEY_EXCHANGE_PSK_ENABLED * must be enabled in mbedtls-config.h * To enable cipher suite DTLS_ECDHE_ECDSA_WITH_AES_128_CCM_8, @@ -96,34 +99,34 @@ void otCoapSecureStop(otInstance *aInstance); * This method sets the Pre-Shared Key (PSK) and cipher suite * DTLS_PSK_WITH_AES_128_CCM_8. * + * @note This function requires the build-time feature `MBEDTLS_KEY_EXCHANGE_PSK_ENABLED` to be enabled. + * * @param[in] aInstance A pointer to an OpenThread instance. * @param[in] aPsk A pointer to the PSK. * @param[in] aPskLength The PSK length. * @param[in] aPskIdentity The Identity Name for the PSK. * @param[in] aPskIdLength The PSK Identity Length. * - * @retval OT_ERROR_NONE Successfully set the PSK. - * @retval OT_ERROR_INVALID_ARGS The PSK is invalid. - * @retval OT_ERROR_DISABLED_FEATURE Mbedtls config not enabled - * MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED - * */ -otError otCoapSecureSetPsk(otInstance * aInstance, - const uint8_t *aPsk, - uint16_t aPskLength, - const uint8_t *aPskIdentity, - uint16_t aPskIdLength); +void otCoapSecureSetPsk(otInstance * aInstance, + const uint8_t *aPsk, + uint16_t aPskLength, + const uint8_t *aPskIdentity, + uint16_t aPskIdLength); /** * This method returns the peer x509 certificate base64 encoded. * + * @note This function requires the build-time feature `MBEDTLS_BASE64_C` to be enabled. + * * @param[in] aInstance A pointer to an OpenThread instance. * @param[out] aPeerCert A pointer to the base64 encoded certificate buffer. * @param[out] aCertLength The length of the base64 encoded peer certificate. * @param[in] aCertBufferSize The buffer size of aPeerCert. * - * @retval OT_ERROR_NONE Successfully get the peer certificate. - * @retval OT_ERROR_DISABLED_FEATURE Mbedtls config not enabled MBEDTLS_BASE64_C. + * @retval OT_ERROR_INVALID_STATE Not connected yet. + * @retval OT_ERROR_NONE Successfully get the peer certificate. + * @retval OT_ERROR_NO_BUFS Can't allocate memory for certificate. * */ otError otCoapSecureGetPeerCertificateBase64(otInstance * aInstance, @@ -147,23 +150,20 @@ void otCoapSecureSetSslAuthMode(otInstance *aInstance, bool aVerifyPeerCertifica * This method sets the local device's X509 certificate with corresponding private key for * DTLS session with DTLS_ECDHE_ECDSA_WITH_AES_128_CCM_8. * + * @note This function requires `MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED=1`. + * * @param[in] aInstance A pointer to an OpenThread instance. * @param[in] aX509Cert A pointer to the PEM formatted X509 certificate. * @param[in] aX509Length The length of certificate. * @param[in] aPrivateKey A pointer to the PEM formatted private key. * @param[in] aPrivateKeyLength The length of the private key. * - * @retval OT_ERROR_NONE Successfully set the x509 certificate - * with his private key. - * @retval OT_ERROR_DISABLED_FEATURE Mbedtls config not enabled - * MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED. - * */ -otError otCoapSecureSetCertificate(otInstance * aInstance, - const uint8_t *aX509Cert, - uint32_t aX509Length, - const uint8_t *aPrivateKey, - uint32_t aPrivateKeyLength); +void otCoapSecureSetCertificate(otInstance * aInstance, + const uint8_t *aX509Cert, + uint32_t aX509Length, + const uint8_t *aPrivateKey, + uint32_t aPrivateKeyLength); /** * This method sets the trusted top level CAs. It is needed for validating the @@ -171,16 +171,16 @@ otError otCoapSecureSetCertificate(otInstance * aInstance, * * DTLS mode "ECDHE ECDSA with AES 128 CCM 8" for Application CoAPS. * + * @note This function requires `MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED=1`. + * * @param[in] aInstance A pointer to an OpenThread instance. * @param[in] aX509CaCertificateChain A pointer to the PEM formatted X509 CA chain. * @param[in] aX509CaCertChainLength The length of chain. * - * @retval OT_ERROR_NONE Successfully set the trusted top level CAs. - * */ -otError otCoapSecureSetCaCertificateChain(otInstance * aInstance, - const uint8_t *aX509CaCertificateChain, - uint32_t aX509CaCertChainLength); +void otCoapSecureSetCaCertificateChain(otInstance * aInstance, + const uint8_t *aX509CaCertificateChain, + uint32_t aX509CaCertChainLength); /** * This method initializes DTLS session with a peer. diff --git a/include/openthread/error.h b/include/openthread/error.h index 7057a012f..3c4c2d52c 100644 --- a/include/openthread/error.h +++ b/include/openthread/error.h @@ -339,11 +339,6 @@ typedef enum otError */ OT_ERROR_NOT_LOWPAN_DATA_FRAME = 32, - /** - * A feature/functionality disabled by build-time configuration options. - */ - OT_ERROR_DISABLED_FEATURE = 33, - /** * The link margin was too low. */ diff --git a/include/openthread/joiner.h b/include/openthread/joiner.h index 9b287b670..93b3484cc 100644 --- a/include/openthread/joiner.h +++ b/include/openthread/joiner.h @@ -48,6 +48,9 @@ extern "C" { * @brief * This module includes functions for the Thread Joiner role. * + * @note + * The functions in this module require `OPENTHREAD_CONFIG_JOINER_ENABLE=1`. + * * @{ * */ @@ -93,7 +96,6 @@ typedef void (*otJoinerCallback)(otError aError, void *aContext); * * @retval OT_ERROR_NONE Successfully started the Commissioner role. * @retval OT_ERROR_INVALID_ARGS @p aPSKd or @p aProvisioningUrl is invalid. - * @retval OT_ERROR_DISABLED_FEATURE The Joiner feature is not enabled in this build. * */ otError otJoinerStart(otInstance * aInstance, @@ -111,11 +113,8 @@ otError otJoinerStart(otInstance * aInstance, * * @param[in] aInstance A pointer to an OpenThread instance. * - * @retval OT_ERROR_NONE Successfully disabled the Joiner role. - * @retval OT_ERROR_DISABLED_FEATURE The Joiner feature is not enabled in this build. - * */ -otError otJoinerStop(otInstance *aInstance); +void otJoinerStop(otInstance *aInstance); /** * This function returns the Joiner State. @@ -141,11 +140,8 @@ otJoinerState otJoinerGetState(otInstance *aInstance); * @param[in] aInstance A pointer to the OpenThread instance. * @param[out] aJoinerId A pointer to where the Joiner ID is placed. * - * @retval OT_ERROR_NONE Successfully retrieved the Joiner ID. - * @retval OT_ERROR_DISABLED_FEATURE The Joiner feature is not enabled in this build. - * */ -otError otJoinerGetId(otInstance *aInstance, otExtAddress *aJoinerId); +void otJoinerGetId(otInstance *aInstance, otExtAddress *aJoinerId); /** * @} diff --git a/include/openthread/logging.h b/include/openthread/logging.h index c4dc2c9e0..4f5ecd80d 100644 --- a/include/openthread/logging.h +++ b/include/openthread/logging.h @@ -66,14 +66,12 @@ otLogLevel otLoggingGetLevel(void); /** * This function sets the log level. * + * @note This function requires `OPENTHREAD_CONFIG_ENABLE_DYNAMIC_LOG_LEVEL=1`. + * * @param[in] aLogLevel The log level. * - * @retval OT_ERROR_NONE The log level was changed successfully. - * @retval OT_ERROR_DISABLED_FEATURE The dynamic log level feature is not supported. - * (see `OPENTHREAD_CONFIG_ENABLE_DYNAMIC_LOG_LEVEL` configuration option). - * */ -otError otLoggingSetLevel(otLogLevel aLogLevel); +void otLoggingSetLevel(otLogLevel aLogLevel); /** * @} diff --git a/include/openthread/ncp.h b/include/openthread/ncp.h index 98ef8b622..b5f07fe79 100644 --- a/include/openthread/ncp.h +++ b/include/openthread/ncp.h @@ -122,12 +122,9 @@ typedef bool (*otNcpDelegateAllowPeekPoke)(uint32_t aAddress, uint16_t aCount); * @param[in] aAllowPeekDelegate Delegate function pointer for peek operation. * @param[in] aAllowPokeDelegate Delegate function pointer for poke operation. * - * @retval OT_ERROR_NONE Successfully registered delegate functions. - * @retval OT_ERROR_DISABLED_FEATURE Peek/Poke feature is disabled (by a build-time configuration option). - * */ -otError otNcpRegisterPeekPokeDelagates(otNcpDelegateAllowPeekPoke aAllowPeekDelegate, - otNcpDelegateAllowPeekPoke aAllowPokeDelegate); +void otNcpRegisterPeekPokeDelagates(otNcpDelegateAllowPeekPoke aAllowPeekDelegate, + otNcpDelegateAllowPeekPoke aAllowPokeDelegate); //----------------------------------------------------------------------------------------- // Legacy network APIs diff --git a/include/openthread/thread.h b/include/openthread/thread.h index 68bc20af4..bd0a55abc 100644 --- a/include/openthread/thread.h +++ b/include/openthread/thread.h @@ -46,6 +46,9 @@ extern "C" { /** * @addtogroup api-thread-general * + * @note + * The functions in this module require `OPENTHREAD_FTD=1` or `OPENTHREAD_MTD=1`. + * * @{ * */ @@ -753,13 +756,10 @@ typedef void (*otThreadParentResponseCallback)(otThreadParentResponseInfo *aInfo * @param[in] aCallback A pointer to a function that is called upon receiving an MLE Parent Response message. * @param[in] aContext A pointer to callback client-specific context. * - * @retval OT_ERROR_NONE On successful registration - * @retval OT_ERROR_DISABLED_FEATURE If the feature is not supported - * */ -otError otThreadRegisterParentResponseCallback(otInstance * aInstance, - otThreadParentResponseCallback aCallback, - void * aContext); +void otThreadRegisterParentResponseCallback(otInstance * aInstance, + otThreadParentResponseCallback aCallback, + void * aContext); /** * @} diff --git a/include/openthread/thread_ftd.h b/include/openthread/thread_ftd.h index 5cdf4a02c..e7654f9dc 100644 --- a/include/openthread/thread_ftd.h +++ b/include/openthread/thread_ftd.h @@ -232,8 +232,7 @@ otError otThreadSetJoinerUdpPort(otInstance *aInstance, uint16_t aJoinerUdpPort) * Set Steering data out of band. * * Configuration option `OPENTHREAD_CONFIG_MLE_STEERING_DATA_SET_OOB_ENABLE` should be set to enable setting of steering - * data out of band. Otherwise calling this function does nothing and it returns `OT_ERROR_DISABLED_FEATURE` - * error. + * data out of band. * * @param[in] aInstance A pointer to an OpenThread instance. * @param[in] aExtAddress Address used to update the steering data. @@ -241,11 +240,8 @@ otError otThreadSetJoinerUdpPort(otInstance *aInstance, uint16_t aJoinerUdpPort) * All 0xFFs to set steering data/bloom filter to accept/allow all. * A specific EUI64 which is then added to current steering data/bloom filter. * - * @retval OT_ERROR_NONE Successfully set/updated the steering data. - * @retval OT_ERROR_DISABLED_FEATURE Feature is disabled, not capable of setting steering data out of band. - * */ -otError otThreadSetSteeringData(otInstance *aInstance, const otExtAddress *aExtAddress); +void otThreadSetSteeringData(otInstance *aInstance, const otExtAddress *aExtAddress); /** * Get the CONTEXT_ID_REUSE_DELAY parameter used in the Leader role. diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 7f71aefed..180a7f198 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -524,12 +524,14 @@ void Interpreter::ProcessChannel(int argc, char *argv[]) SuccessOrExit(error = ParseLong(argv[2], value)); otChannelManagerRequestChannelChange(mInstance, static_cast(value)); } +#if OPENTHREAD_CONFIG_CHANNEL_MONITOR_ENABLE else if (strcmp(argv[1], "select") == 0) { VerifyOrExit(argc > 2, error = OT_ERROR_INVALID_ARGS); SuccessOrExit(error = ParseLong(argv[2], value)); error = otChannelManagerRequestChannelSelect(mInstance, (value != 0) ? true : false); } +#endif else if (strcmp(argv[1], "auto") == 0) { VerifyOrExit(argc > 2, error = OT_ERROR_INVALID_ARGS); diff --git a/src/cli/cli_coap_secure.cpp b/src/cli/cli_coap_secure.cpp index d9ed1d5b5..7c0f9ad7d 100644 --- a/src/cli/cli_coap_secure.cpp +++ b/src/cli/cli_coap_secure.cpp @@ -52,7 +52,10 @@ const struct CoapSecure::Command CoapSecure::sCommands[] = { {"get", &CoapSecure::ProcessRequest}, {"post", &CoapSecure::ProcessRequest}, {"psk", &CoapSecure::ProcessPsk}, {"put", &CoapSecure::ProcessRequest}, {"resource", &CoapSecure::ProcessResource}, {"start", &CoapSecure::ProcessStart}, - {"stop", &CoapSecure::ProcessStop}, {"x509", &CoapSecure::ProcessX509}, + {"stop", &CoapSecure::ProcessStop}, +#ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED + {"x509", &CoapSecure::ProcessX509}, +#endif }; CoapSecure::CoapSecure(Interpreter &aInterpreter) @@ -340,7 +343,7 @@ otError CoapSecure::ProcessDisconnect(int argc, char *argv[]) otError CoapSecure::ProcessPsk(int argc, char *argv[]) { - otError error; + otError error = OT_ERROR_NONE; size_t length; VerifyOrExit(argc > 2, error = OT_ERROR_INVALID_ARGS); @@ -355,36 +358,30 @@ otError CoapSecure::ProcessPsk(int argc, char *argv[]) mPskIdLength = static_cast(length); memcpy(mPskId, argv[2], mPskIdLength); - SuccessOrExit(error = otCoapSecureSetPsk(mInterpreter.mInstance, mPsk, mPskLength, mPskId, mPskIdLength)); + otCoapSecureSetPsk(mInterpreter.mInstance, mPsk, mPskLength, mPskId, mPskIdLength); mUseCertificate = false; exit: return error; } +#ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED otError CoapSecure::ProcessX509(int argc, char *argv[]) { OT_UNUSED_VARIABLE(argc); OT_UNUSED_VARIABLE(argv); -#ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED - otError error; + otCoapSecureSetCertificate(mInterpreter.mInstance, (const uint8_t *)OT_CLI_COAPS_X509_CERT, + sizeof(OT_CLI_COAPS_X509_CERT), (const uint8_t *)OT_CLI_COAPS_PRIV_KEY, + sizeof(OT_CLI_COAPS_PRIV_KEY)); - SuccessOrExit(error = otCoapSecureSetCertificate( - mInterpreter.mInstance, (const uint8_t *)OT_CLI_COAPS_X509_CERT, sizeof(OT_CLI_COAPS_X509_CERT), - (const uint8_t *)OT_CLI_COAPS_PRIV_KEY, sizeof(OT_CLI_COAPS_PRIV_KEY))); - - SuccessOrExit(error = otCoapSecureSetCaCertificateChain(mInterpreter.mInstance, - (const uint8_t *)OT_CLI_COAPS_TRUSTED_ROOT_CERTIFICATE, - sizeof(OT_CLI_COAPS_TRUSTED_ROOT_CERTIFICATE))); + otCoapSecureSetCaCertificateChain(mInterpreter.mInstance, (const uint8_t *)OT_CLI_COAPS_TRUSTED_ROOT_CERTIFICATE, + sizeof(OT_CLI_COAPS_TRUSTED_ROOT_CERTIFICATE)); mUseCertificate = true; -exit: - return error; -#else - return OT_ERROR_DISABLED_FEATURE; -#endif + return OT_ERROR_NONE; } +#endif otError CoapSecure::Process(int argc, char *argv[]) { diff --git a/src/cli/cli_joiner.cpp b/src/cli/cli_joiner.cpp index 1facdb8e0..971555154 100644 --- a/src/cli/cli_joiner.cpp +++ b/src/cli/cli_joiner.cpp @@ -63,19 +63,17 @@ otError Joiner::ProcessHelp(int argc, char *argv[]) otError Joiner::ProcessId(int argc, char *argv[]) { - otError error; - otExtAddress joinerId; - OT_UNUSED_VARIABLE(argc); OT_UNUSED_VARIABLE(argv); - SuccessOrExit(error = otJoinerGetId(mInterpreter.mInstance, &joinerId)); + otExtAddress joinerId; + + otJoinerGetId(mInterpreter.mInstance, &joinerId); mInterpreter.OutputBytes(joinerId.m8, sizeof(joinerId)); mInterpreter.mServer->OutputFormat("\r\n"); -exit: - return error; + return OT_ERROR_NONE; } otError Joiner::ProcessStart(int argc, char *argv[]) @@ -102,7 +100,9 @@ otError Joiner::ProcessStop(int argc, char *argv[]) OT_UNUSED_VARIABLE(argc); OT_UNUSED_VARIABLE(argv); - return otJoinerStop(mInterpreter.mInstance); + otJoinerStop(mInterpreter.mInstance); + + return OT_ERROR_NONE; } otError Joiner::Process(int argc, char *argv[]) diff --git a/src/core/api/border_router_api.cpp b/src/core/api/border_router_api.cpp index dd8dd2f98..0388a3c7b 100644 --- a/src/core/api/border_router_api.cpp +++ b/src/core/api/border_router_api.cpp @@ -37,6 +37,7 @@ #include +#include "common/debug.hpp" #include "common/instance.hpp" #include "common/locator-getters.hpp" @@ -44,15 +45,11 @@ using namespace ot; otError otBorderRouterGetNetData(otInstance *aInstance, bool aStable, uint8_t *aData, uint8_t *aDataLength) { - otError error = OT_ERROR_NONE; Instance &instance = *static_cast(aInstance); - VerifyOrExit(aData != NULL && aDataLength != NULL, error = OT_ERROR_INVALID_ARGS); + assert(aData != NULL && aDataLength != NULL); - error = instance.Get().GetNetworkData(aStable, aData, *aDataLength); - -exit: - return error; + return instance.Get().GetNetworkData(aStable, aData, *aDataLength); } otError otBorderRouterAddOnMeshPrefix(otInstance *aInstance, const otBorderRouterConfig *aConfig) @@ -60,6 +57,8 @@ otError otBorderRouterAddOnMeshPrefix(otInstance *aInstance, const otBorderRoute uint8_t flags = 0; Instance &instance = *static_cast(aInstance); + assert(aConfig != NULL); + if (aConfig->mPreferred) { flags |= NetworkData::BorderRouterEntry::kPreferredFlag; @@ -98,6 +97,8 @@ otError otBorderRouterRemoveOnMeshPrefix(otInstance *aInstance, const otIp6Prefi { Instance &instance = *static_cast(aInstance); + assert(aPrefix != NULL); + return instance.Get().RemoveOnMeshPrefix(aPrefix->mPrefix.mFields.m8, aPrefix->mLength); } @@ -105,21 +106,19 @@ otError otBorderRouterGetNextOnMeshPrefix(otInstance * aInstance, otNetworkDataIterator *aIterator, otBorderRouterConfig * aConfig) { - otError error = OT_ERROR_NONE; Instance &instance = *static_cast(aInstance); - VerifyOrExit(aIterator && aConfig, error = OT_ERROR_INVALID_ARGS); + assert(aIterator != NULL && aConfig != NULL); - error = instance.Get().GetNextOnMeshPrefix(aIterator, aConfig); - -exit: - return error; + return instance.Get().GetNextOnMeshPrefix(aIterator, aConfig); } otError otBorderRouterAddRoute(otInstance *aInstance, const otExternalRouteConfig *aConfig) { Instance &instance = *static_cast(aInstance); + assert(aConfig != NULL); + return instance.Get().AddHasRoutePrefix( aConfig->mPrefix.mPrefix.mFields.m8, aConfig->mPrefix.mLength, aConfig->mPreference, aConfig->mStable); } @@ -128,6 +127,8 @@ otError otBorderRouterRemoveRoute(otInstance *aInstance, const otIp6Prefix *aPre { Instance &instance = *static_cast(aInstance); + assert(aPrefix != NULL); + return instance.Get().RemoveHasRoutePrefix(aPrefix->mPrefix.mFields.m8, aPrefix->mLength); } @@ -135,15 +136,11 @@ otError otBorderRouterGetNextRoute(otInstance * aInstance, otNetworkDataIterator *aIterator, otExternalRouteConfig *aConfig) { - otError error = OT_ERROR_NONE; Instance &instance = *static_cast(aInstance); - VerifyOrExit(aIterator && aConfig, error = OT_ERROR_INVALID_ARGS); + assert(aIterator != NULL && aConfig != NULL); - error = instance.Get().GetNextExternalRoute(aIterator, aConfig); - -exit: - return error; + return instance.Get().GetNextExternalRoute(aIterator, aConfig); } otError otBorderRouterRegister(otInstance *aInstance) diff --git a/src/core/api/channel_manager_api.cpp b/src/core/api/channel_manager_api.cpp index 5d2b503a4..5bb90ff23 100644 --- a/src/core/api/channel_manager_api.cpp +++ b/src/core/api/channel_manager_api.cpp @@ -70,12 +70,14 @@ otError otChannelManagerSetDelay(otInstance *aInstance, uint16_t aDelay) return instance.Get().SetDelay(aDelay); } +#if OPENTHREAD_CONFIG_CHANNEL_MONITOR_ENABLE otError otChannelManagerRequestChannelSelect(otInstance *aInstance, bool aSkipQualityCheck) { Instance &instance = *static_cast(aInstance); return instance.Get().RequestChannelSelect(aSkipQualityCheck); } +#endif void otChannelManagerSetAutoChannelSelectionEnabled(otInstance *aInstance, bool aEnabled) { diff --git a/src/core/api/coap_secure_api.cpp b/src/core/api/coap_secure_api.cpp index c1a5811ac..76e4be8c1 100644 --- a/src/core/api/coap_secure_api.cpp +++ b/src/core/api/coap_secure_api.cpp @@ -52,98 +52,58 @@ otError otCoapSecureStart(otInstance *aInstance, uint16_t aPort) return instance.GetApplicationCoapSecure().Start(aPort); } -otError otCoapSecureSetCertificate(otInstance * aInstance, - const uint8_t *aX509Cert, - uint32_t aX509Length, - const uint8_t *aPrivateKey, - uint32_t aPrivateKeyLength) -{ #ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED +void otCoapSecureSetCertificate(otInstance * aInstance, + const uint8_t *aX509Cert, + uint32_t aX509Length, + const uint8_t *aPrivateKey, + uint32_t aPrivateKeyLength) +{ Instance &instance = *static_cast(aInstance); - if (aX509Cert == NULL || aX509Length == 0 || aPrivateKey == NULL || aPrivateKeyLength == 0) - { - return OT_ERROR_INVALID_ARGS; - } + assert(aX509Cert != NULL && aX509Length != 0 && aPrivateKey != NULL && aPrivateKeyLength != 0); - return instance.GetApplicationCoapSecure().SetCertificate(aX509Cert, aX509Length, aPrivateKey, aPrivateKeyLength); -#else - OT_UNUSED_VARIABLE(aInstance); - OT_UNUSED_VARIABLE(aX509Cert); - OT_UNUSED_VARIABLE(aX509Length); - OT_UNUSED_VARIABLE(aPrivateKey); - OT_UNUSED_VARIABLE(aPrivateKeyLength); - - return OT_ERROR_DISABLED_FEATURE; -#endif // MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED + instance.GetApplicationCoapSecure().SetCertificate(aX509Cert, aX509Length, aPrivateKey, aPrivateKeyLength); } -otError otCoapSecureSetCaCertificateChain(otInstance * aInstance, - const uint8_t *aX509CaCertificateChain, - uint32_t aX509CaCertChainLength) +void otCoapSecureSetCaCertificateChain(otInstance * aInstance, + const uint8_t *aX509CaCertificateChain, + uint32_t aX509CaCertChainLength) { -#ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED Instance &instance = *static_cast(aInstance); - if (aX509CaCertificateChain == NULL || aX509CaCertChainLength == 0) - { - return OT_ERROR_INVALID_ARGS; - } + assert(aX509CaCertificateChain != NULL && aX509CaCertChainLength != 0); - return instance.GetApplicationCoapSecure().SetCaCertificateChain(aX509CaCertificateChain, aX509CaCertChainLength); -#else - OT_UNUSED_VARIABLE(aInstance); - OT_UNUSED_VARIABLE(aX509CaCertificateChain); - OT_UNUSED_VARIABLE(aX509CaCertChainLength); - - return OT_ERROR_DISABLED_FEATURE; -#endif // MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED + instance.GetApplicationCoapSecure().SetCaCertificateChain(aX509CaCertificateChain, aX509CaCertChainLength); } +#endif // MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED -otError otCoapSecureSetPsk(otInstance * aInstance, - const uint8_t *aPsk, - uint16_t aPskLength, - const uint8_t *aPskIdentity, - uint16_t aPskIdLength) -{ #ifdef MBEDTLS_KEY_EXCHANGE_PSK_ENABLED +void otCoapSecureSetPsk(otInstance * aInstance, + const uint8_t *aPsk, + uint16_t aPskLength, + const uint8_t *aPskIdentity, + uint16_t aPskIdLength) +{ Instance &instance = *static_cast(aInstance); - if (aPsk == NULL || aPskLength == 0 || aPskIdentity == NULL || aPskIdLength == 0) - { - return OT_ERROR_INVALID_ARGS; - } + assert(aPsk != NULL && aPskLength != 0 && aPskIdentity != NULL && aPskIdLength != 0); - return instance.GetApplicationCoapSecure().SetPreSharedKey(aPsk, aPskLength, aPskIdentity, aPskIdLength); -#else - OT_UNUSED_VARIABLE(aInstance); - OT_UNUSED_VARIABLE(aPsk); - OT_UNUSED_VARIABLE(aPskLength); - OT_UNUSED_VARIABLE(aPskIdentity); - OT_UNUSED_VARIABLE(aPskIdLength); - - return OT_ERROR_DISABLED_FEATURE; -#endif // MBEDTLS_KEY_EXCHANGE_PSK_ENABLED + instance.GetApplicationCoapSecure().SetPreSharedKey(aPsk, aPskLength, aPskIdentity, aPskIdLength); } +#endif // MBEDTLS_KEY_EXCHANGE_PSK_ENABLED +#ifdef MBEDTLS_BASE64_C otError otCoapSecureGetPeerCertificateBase64(otInstance * aInstance, unsigned char *aPeerCert, size_t * aCertLength, size_t aCertBufferSize) { -#ifdef MBEDTLS_BASE64_C Instance &instance = *static_cast(aInstance); return instance.GetApplicationCoapSecure().GetPeerCertificateBase64(aPeerCert, aCertLength, aCertBufferSize); -#else - OT_UNUSED_VARIABLE(aInstance); - OT_UNUSED_VARIABLE(aPeerCert); - OT_UNUSED_VARIABLE(aCertLength); - OT_UNUSED_VARIABLE(aCertBufferSize); - - return OT_ERROR_DISABLED_FEATURE; -#endif // MBEDTLS_BASE64_C } +#endif // MBEDTLS_BASE64_C void otCoapSecureSetSslAuthMode(otInstance *aInstance, bool aVerifyPeerCertificate) { @@ -193,8 +153,8 @@ void otCoapSecureStop(otInstance *aInstance) otError otCoapSecureSendRequest(otInstance * aInstance, otMessage * aMessage, - otCoapResponseHandler aHandler = NULL, - void * aContext = NULL) + otCoapResponseHandler aHandler, + void * aContext) { Instance &instance = *static_cast(aInstance); diff --git a/src/core/api/commissioner_api.cpp b/src/core/api/commissioner_api.cpp index 84daf66ac..b3417be9f 100644 --- a/src/core/api/commissioner_api.cpp +++ b/src/core/api/commissioner_api.cpp @@ -40,14 +40,14 @@ using namespace ot; +#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_COMMISSIONER_ENABLE otError otCommissionerStart(otInstance * aInstance, otCommissionerStateCallback aStateCallback, otCommissionerJoinerCallback aJoinerCallback, void * aCallbackContext) { - otError error = OT_ERROR_DISABLED_FEATURE; + otError error; -#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_COMMISSIONER_ENABLE Instance &instance = *static_cast(aInstance); #if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE @@ -56,100 +56,55 @@ otError otCommissionerStart(otInstance * aInstance, SuccessOrExit(error = instance.Get().Start(aStateCallback, aJoinerCallback, aCallbackContext)); exit: -#else - OT_UNUSED_VARIABLE(aInstance); - OT_UNUSED_VARIABLE(aStateCallback); - OT_UNUSED_VARIABLE(aJoinerCallback); - OT_UNUSED_VARIABLE(aCallbackContext); -#endif - return error; } otError otCommissionerStop(otInstance *aInstance) { - OT_UNUSED_VARIABLE(aInstance); - - otError error = OT_ERROR_DISABLED_FEATURE; - -#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_COMMISSIONER_ENABLE + otError error; Instance &instance = *static_cast(aInstance); SuccessOrExit(error = instance.Get().Stop()); #if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE SuccessOrExit(error = instance.Get().Start()); #endif + exit: -#endif return error; } otError otCommissionerAddJoiner(otInstance *aInstance, const otExtAddress *aEui64, const char *aPSKd, uint32_t aTimeout) { - otError error = OT_ERROR_DISABLED_FEATURE; - -#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_COMMISSIONER_ENABLE Instance &instance = *static_cast(aInstance); - error = - instance.Get().AddJoiner(static_cast(aEui64), aPSKd, aTimeout); -#else - OT_UNUSED_VARIABLE(aInstance); - OT_UNUSED_VARIABLE(aEui64); - OT_UNUSED_VARIABLE(aPSKd); - OT_UNUSED_VARIABLE(aTimeout); -#endif - - return error; + return instance.Get().AddJoiner(static_cast(aEui64), aPSKd, + aTimeout); } otError otCommissionerRemoveJoiner(otInstance *aInstance, const otExtAddress *aEui64) { - otError error = OT_ERROR_DISABLED_FEATURE; - -#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_COMMISSIONER_ENABLE Instance &instance = *static_cast(aInstance); - error = instance.Get().RemoveJoiner(static_cast(aEui64), 0); -#else - OT_UNUSED_VARIABLE(aInstance); - OT_UNUSED_VARIABLE(aEui64); -#endif - - return error; + return instance.Get().RemoveJoiner(static_cast(aEui64), 0); } otError otCommissionerSetProvisioningUrl(otInstance *aInstance, const char *aProvisioningUrl) { - otError error = OT_ERROR_DISABLED_FEATURE; - -#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_COMMISSIONER_ENABLE Instance &instance = *static_cast(aInstance); - error = instance.Get().SetProvisioningUrl(aProvisioningUrl); -#else - OT_UNUSED_VARIABLE(aInstance); - OT_UNUSED_VARIABLE(aProvisioningUrl); -#endif - - return error; + return instance.Get().SetProvisioningUrl(aProvisioningUrl); } const char *otCommissionerGetProvisioningUrl(otInstance *aInstance, uint16_t *aLength) { const char *url = NULL; -#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_COMMISSIONER_ENABLE Instance &instance = *static_cast(aInstance); if (aLength != NULL) { url = instance.Get().GetProvisioningUrl(*aLength); } -#else - OT_UNUSED_VARIABLE(aInstance); - OT_UNUSED_VARIABLE(aLength); -#endif return url; } @@ -160,22 +115,10 @@ otError otCommissionerAnnounceBegin(otInstance * aInstance, uint16_t aPeriod, const otIp6Address *aAddress) { - otError error = OT_ERROR_DISABLED_FEATURE; - -#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_COMMISSIONER_ENABLE Instance &instance = *static_cast(aInstance); - error = instance.Get().GetAnnounceBeginClient().SendRequest( + return instance.Get().GetAnnounceBeginClient().SendRequest( aChannelMask, aCount, aPeriod, *static_cast(aAddress)); -#else - OT_UNUSED_VARIABLE(aInstance); - OT_UNUSED_VARIABLE(aChannelMask); - OT_UNUSED_VARIABLE(aCount); - OT_UNUSED_VARIABLE(aPeriod); - OT_UNUSED_VARIABLE(aAddress); -#endif - - return error; } otError otCommissionerEnergyScan(otInstance * aInstance, @@ -187,26 +130,11 @@ otError otCommissionerEnergyScan(otInstance * aInstance, otCommissionerEnergyReportCallback aCallback, void * aContext) { - otError error = OT_ERROR_DISABLED_FEATURE; - -#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_COMMISSIONER_ENABLE Instance &instance = *static_cast(aInstance); - error = instance.Get().GetEnergyScanClient().SendQuery( + return instance.Get().GetEnergyScanClient().SendQuery( aChannelMask, aCount, aPeriod, aScanDuration, *static_cast(aAddress), aCallback, aContext); -#else - OT_UNUSED_VARIABLE(aInstance); - OT_UNUSED_VARIABLE(aChannelMask); - OT_UNUSED_VARIABLE(aCount); - OT_UNUSED_VARIABLE(aPeriod); - OT_UNUSED_VARIABLE(aScanDuration); - OT_UNUSED_VARIABLE(aAddress); - OT_UNUSED_VARIABLE(aCallback); - OT_UNUSED_VARIABLE(aContext); -#endif - - return error; } otError otCommissionerPanIdQuery(otInstance * aInstance, @@ -216,40 +144,17 @@ otError otCommissionerPanIdQuery(otInstance * aInstance, otCommissionerPanIdConflictCallback aCallback, void * aContext) { - otError error = OT_ERROR_DISABLED_FEATURE; - -#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_COMMISSIONER_ENABLE Instance &instance = *static_cast(aInstance); - error = instance.Get().GetPanIdQueryClient().SendQuery( + return instance.Get().GetPanIdQueryClient().SendQuery( aPanId, aChannelMask, *static_cast(aAddress), aCallback, aContext); -#else - OT_UNUSED_VARIABLE(aInstance); - OT_UNUSED_VARIABLE(aPanId); - OT_UNUSED_VARIABLE(aChannelMask); - OT_UNUSED_VARIABLE(aAddress); - OT_UNUSED_VARIABLE(aCallback); - OT_UNUSED_VARIABLE(aContext); -#endif - - return error; } otError otCommissionerSendMgmtGet(otInstance *aInstance, const uint8_t *aTlvs, uint8_t aLength) { - otError error = OT_ERROR_DISABLED_FEATURE; - -#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_COMMISSIONER_ENABLE Instance &instance = *static_cast(aInstance); - error = instance.Get().SendMgmtCommissionerGetRequest(aTlvs, aLength); -#else - OT_UNUSED_VARIABLE(aInstance); - OT_UNUSED_VARIABLE(aTlvs); - OT_UNUSED_VARIABLE(aLength); -#endif - - return error; + return instance.Get().SendMgmtCommissionerGetRequest(aTlvs, aLength); } otError otCommissionerSendMgmtSet(otInstance * aInstance, @@ -257,50 +162,23 @@ otError otCommissionerSendMgmtSet(otInstance * aInstance, const uint8_t * aTlvs, uint8_t aLength) { - otError error = OT_ERROR_DISABLED_FEATURE; - -#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_COMMISSIONER_ENABLE Instance &instance = *static_cast(aInstance); - error = instance.Get().SendMgmtCommissionerSetRequest(*aDataset, aTlvs, aLength); -#else - OT_UNUSED_VARIABLE(aInstance); - OT_UNUSED_VARIABLE(aDataset); - OT_UNUSED_VARIABLE(aTlvs); - OT_UNUSED_VARIABLE(aLength); -#endif - - return error; + return instance.Get().SendMgmtCommissionerSetRequest(*aDataset, aTlvs, aLength); } uint16_t otCommissionerGetSessionId(otInstance *aInstance) { - uint16_t sessionId = 0; - -#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_COMMISSIONER_ENABLE Instance &instance = *static_cast(aInstance); - sessionId = instance.Get().GetSessionId(); -#else - OT_UNUSED_VARIABLE(aInstance); -#endif - - return sessionId; + return instance.Get().GetSessionId(); } otCommissionerState otCommissionerGetState(otInstance *aInstance) { - otCommissionerState state = OT_COMMISSIONER_STATE_DISABLED; - -#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_COMMISSIONER_ENABLE Instance &instance = *static_cast(aInstance); - state = instance.Get().GetState(); -#else - OT_UNUSED_VARIABLE(aInstance); -#endif - - return state; + return instance.Get().GetState(); } otError otCommissionerGeneratePSKc(otInstance * aInstance, @@ -311,18 +189,7 @@ otError otCommissionerGeneratePSKc(otInstance * aInstance, { OT_UNUSED_VARIABLE(aInstance); - otError error = OT_ERROR_DISABLED_FEATURE; - -#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_COMMISSIONER_ENABLE - error = MeshCoP::Commissioner::GeneratePSKc(aPassPhrase, aNetworkName, - *static_cast(aExtPanId), aPSKc); -#else - OT_UNUSED_VARIABLE(aInstance); - OT_UNUSED_VARIABLE(aPassPhrase); - OT_UNUSED_VARIABLE(aNetworkName); - OT_UNUSED_VARIABLE(aExtPanId); - OT_UNUSED_VARIABLE(aPSKc); -#endif - - return error; + return MeshCoP::Commissioner::GeneratePSKc(aPassPhrase, aNetworkName, + *static_cast(aExtPanId), aPSKc); } +#endif // OPENTHREAD_FTD && OPENTHREAD_CONFIG_COMMISSIONER_ENABLE diff --git a/src/core/api/dataset_api.cpp b/src/core/api/dataset_api.cpp index 09bb304d5..7b95323ef 100644 --- a/src/core/api/dataset_api.cpp +++ b/src/core/api/dataset_api.cpp @@ -53,54 +53,38 @@ bool otDatasetIsCommissioned(otInstance *aInstance) otError otDatasetGetActive(otInstance *aInstance, otOperationalDataset *aDataset) { - otError error = OT_ERROR_NONE; Instance &instance = *static_cast(aInstance); - VerifyOrExit(aDataset != NULL, error = OT_ERROR_INVALID_ARGS); + assert(aDataset != NULL); - error = instance.Get().Read(*aDataset); - -exit: - return error; + return instance.Get().Read(*aDataset); } otError otDatasetSetActive(otInstance *aInstance, const otOperationalDataset *aDataset) { - otError error; Instance &instance = *static_cast(aInstance); - VerifyOrExit(aDataset != NULL, error = OT_ERROR_INVALID_ARGS); + assert(aDataset != NULL); - error = instance.Get().Save(*aDataset); - -exit: - return error; + return instance.Get().Save(*aDataset); } otError otDatasetGetPending(otInstance *aInstance, otOperationalDataset *aDataset) { - otError error = OT_ERROR_NONE; Instance &instance = *static_cast(aInstance); - VerifyOrExit(aDataset != NULL, error = OT_ERROR_INVALID_ARGS); + assert(aDataset != NULL); - error = instance.Get().Read(*aDataset); - -exit: - return error; + return instance.Get().Read(*aDataset); } otError otDatasetSetPending(otInstance *aInstance, const otOperationalDataset *aDataset) { - otError error; Instance &instance = *static_cast(aInstance); - VerifyOrExit(aDataset != NULL, error = OT_ERROR_INVALID_ARGS); + assert(aDataset != NULL); - error = instance.Get().Save(*aDataset); - -exit: - return error; + return instance.Get().Save(*aDataset); } otError otDatasetSendMgmtActiveGet(otInstance * aInstance, diff --git a/src/core/api/ip6_api.cpp b/src/core/api/ip6_api.cpp index 7219ae3a0..faa5088a7 100644 --- a/src/core/api/ip6_api.cpp +++ b/src/core/api/ip6_api.cpp @@ -237,14 +237,9 @@ otError otIp6AddressFromString(const char *aString, otIp6Address *aAddress) uint8_t otIp6PrefixMatch(const otIp6Address *aFirst, const otIp6Address *aSecond) { - uint8_t rval; + assert(aFirst != NULL && aSecond != NULL); - VerifyOrExit(aFirst != NULL && aSecond != NULL, rval = 0); - - rval = static_cast(aFirst)->PrefixMatch(*static_cast(aSecond)); - -exit: - return rval; + return static_cast(aFirst)->PrefixMatch(*static_cast(aSecond)); } bool otIp6IsAddressUnspecified(const otIp6Address *aAddress) diff --git a/src/core/api/joiner_api.cpp b/src/core/api/joiner_api.cpp index cf39a838a..8fb7b068e 100644 --- a/src/core/api/joiner_api.cpp +++ b/src/core/api/joiner_api.cpp @@ -40,6 +40,7 @@ using namespace ot; +#if OPENTHREAD_CONFIG_JOINER_ENABLE otError otJoinerStart(otInstance * aInstance, const char * aPSKd, const char * aProvisioningUrl, @@ -50,72 +51,30 @@ otError otJoinerStart(otInstance * aInstance, otJoinerCallback aCallback, void * aContext) { - otError error = OT_ERROR_DISABLED_FEATURE; -#if OPENTHREAD_CONFIG_JOINER_ENABLE Instance &instance = *static_cast(aInstance); - error = instance.Get().Start(aPSKd, aProvisioningUrl, aVendorName, aVendorModel, aVendorSwVersion, - aVendorData, aCallback, aContext); -#else - OT_UNUSED_VARIABLE(aInstance); - OT_UNUSED_VARIABLE(aPSKd); - OT_UNUSED_VARIABLE(aProvisioningUrl); - OT_UNUSED_VARIABLE(aVendorName); - OT_UNUSED_VARIABLE(aVendorModel); - OT_UNUSED_VARIABLE(aVendorSwVersion); - OT_UNUSED_VARIABLE(aVendorData); - OT_UNUSED_VARIABLE(aCallback); - OT_UNUSED_VARIABLE(aContext); -#endif - - return error; + return instance.Get().Start(aPSKd, aProvisioningUrl, aVendorName, aVendorModel, aVendorSwVersion, + aVendorData, aCallback, aContext); } -otError otJoinerStop(otInstance *aInstance) +void otJoinerStop(otInstance *aInstance) { - otError error; - -#if OPENTHREAD_CONFIG_JOINER_ENABLE Instance &instance = *static_cast(aInstance); instance.Get().Stop(); - error = OT_ERROR_NONE; -#else - OT_UNUSED_VARIABLE(aInstance); - error = OT_ERROR_DISABLED_FEATURE; -#endif - - return error; } otJoinerState otJoinerGetState(otInstance *aInstance) { - otJoinerState state = OT_JOINER_STATE_IDLE; - -#if OPENTHREAD_CONFIG_JOINER_ENABLE Instance &instance = *static_cast(aInstance); - state = instance.Get().GetState(); -#else - OT_UNUSED_VARIABLE(aInstance); -#endif - - return state; + return instance.Get().GetState(); } -otError otJoinerGetId(otInstance *aInstance, otExtAddress *aJoinerId) +void otJoinerGetId(otInstance *aInstance, otExtAddress *aJoinerId) { - otError error = OT_ERROR_DISABLED_FEATURE; - -#if OPENTHREAD_CONFIG_JOINER_ENABLE Instance &instance = *static_cast(aInstance); instance.Get().GetJoinerId(*static_cast(aJoinerId)); - error = OT_ERROR_NONE; -#else - OT_UNUSED_VARIABLE(aInstance); - OT_UNUSED_VARIABLE(aJoinerId); -#endif - - return error; } +#endif // OPENTHREAD_CONFIG_JOINER_ENABLE diff --git a/src/core/api/link_api.cpp b/src/core/api/link_api.cpp index b6783aa3b..bc0e4d169 100644 --- a/src/core/api/link_api.cpp +++ b/src/core/api/link_api.cpp @@ -119,7 +119,7 @@ otError otLinkSetExtendedAddress(otInstance *aInstance, const otExtAddress *aExt otError error = OT_ERROR_NONE; Instance &instance = *static_cast(aInstance); - VerifyOrExit(aExtAddress != NULL, error = OT_ERROR_INVALID_ARGS); + assert(aExtAddress != NULL); VerifyOrExit(instance.Get().GetRole() == OT_DEVICE_ROLE_DISABLED, error = OT_ERROR_INVALID_STATE); instance.Get().SetExtAddress(*static_cast(aExtAddress)); @@ -205,28 +205,20 @@ otError otLinkFilterSetAddressMode(otInstance *aInstance, otMacFilterAddressMode otError otLinkFilterAddAddress(otInstance *aInstance, const otExtAddress *aExtAddress) { - otError error = OT_ERROR_NONE; Instance &instance = *static_cast(aInstance); - VerifyOrExit(aExtAddress != NULL, error = OT_ERROR_INVALID_ARGS); + assert(aExtAddress != NULL); - error = instance.Get().AddAddress(*static_cast(aExtAddress)); - -exit: - return error; + return instance.Get().AddAddress(*static_cast(aExtAddress)); } otError otLinkFilterRemoveAddress(otInstance *aInstance, const otExtAddress *aExtAddress) { - otError error = OT_ERROR_NONE; Instance &instance = *static_cast(aInstance); - VerifyOrExit(aExtAddress != NULL, error = OT_ERROR_INVALID_ARGS); + assert(aExtAddress != NULL); - error = instance.Get().RemoveAddress(*static_cast(aExtAddress)); - -exit: - return error; + return instance.Get().RemoveAddress(*static_cast(aExtAddress)); } void otLinkFilterClearAddresses(otInstance *aInstance) @@ -238,15 +230,11 @@ void otLinkFilterClearAddresses(otInstance *aInstance) otError otLinkFilterGetNextAddress(otInstance *aInstance, otMacFilterIterator *aIterator, otMacFilterEntry *aEntry) { - otError error = OT_ERROR_NONE; Instance &instance = *static_cast(aInstance); - VerifyOrExit(aIterator != NULL && aEntry != NULL, error = OT_ERROR_INVALID_ARGS); + assert(aIterator != NULL && aEntry != NULL); - error = instance.Get().GetNextAddress(*aIterator, *aEntry); - -exit: - return error; + return instance.Get().GetNextAddress(*aIterator, *aEntry); } otError otLinkFilterAddRssIn(otInstance *aInstance, const otExtAddress *aExtAddress, int8_t aRss) @@ -272,15 +260,11 @@ void otLinkFilterClearRssIn(otInstance *aInstance) otError otLinkFilterGetNextRssIn(otInstance *aInstance, otMacFilterIterator *aIterator, otMacFilterEntry *aEntry) { - otError error = OT_ERROR_NONE; Instance &instance = *static_cast(aInstance); - VerifyOrExit(aIterator != NULL && aEntry != NULL, error = OT_ERROR_INVALID_ARGS); + assert(aIterator != NULL && aEntry != NULL); - error = instance.Get().GetNextRssIn(*aIterator, *aEntry); - -exit: - return error; + return instance.Get().GetNextRssIn(*aIterator, *aEntry); } uint8_t otLinkConvertRssToLinkQuality(otInstance *aInstance, int8_t aRss) diff --git a/src/core/api/logging_api.cpp b/src/core/api/logging_api.cpp index 31a88f545..a4cc02c02 100644 --- a/src/core/api/logging_api.cpp +++ b/src/core/api/logging_api.cpp @@ -40,30 +40,17 @@ using namespace ot; otLogLevel otLoggingGetLevel(void) +{ #if OPENTHREAD_CONFIG_ENABLE_DYNAMIC_LOG_LEVEL && !OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE -{ return Instance::Get().GetLogLevel(); -} #else -{ return static_cast(OPENTHREAD_CONFIG_LOG_LEVEL); -} #endif - -otError otLoggingSetLevel(otLogLevel aLogLevel) -{ - OT_UNUSED_VARIABLE(aLogLevel); - - otError error = OT_ERROR_DISABLED_FEATURE; +} #if OPENTHREAD_CONFIG_ENABLE_DYNAMIC_LOG_LEVEL -#if OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE -#warning "Dynamic log level is not supported along with multiple OT instance feature" -#else +void otLoggingSetLevel(otLogLevel aLogLevel) +{ Instance::Get().SetLogLevel(aLogLevel); - error = OT_ERROR_NONE; -#endif -#endif - - return error; } +#endif diff --git a/src/core/api/netdata_api.cpp b/src/core/api/netdata_api.cpp index fe30987d1..fa23366b3 100644 --- a/src/core/api/netdata_api.cpp +++ b/src/core/api/netdata_api.cpp @@ -42,15 +42,11 @@ using namespace ot; otError otNetDataGet(otInstance *aInstance, bool aStable, uint8_t *aData, uint8_t *aDataLength) { - otError error = OT_ERROR_NONE; Instance &instance = *static_cast(aInstance); - VerifyOrExit(aData != NULL && aDataLength != NULL, error = OT_ERROR_INVALID_ARGS); + assert(aData != NULL && aDataLength != NULL); - error = instance.Get().GetNetworkData(aStable, aData, *aDataLength); - -exit: - return error; + return instance.Get().GetNetworkData(aStable, aData, *aDataLength); } otError otNetDataGetNextOnMeshPrefix(otInstance * aInstance, diff --git a/src/core/api/server_api.cpp b/src/core/api/server_api.cpp index a10edc27a..33560a29f 100644 --- a/src/core/api/server_api.cpp +++ b/src/core/api/server_api.cpp @@ -44,15 +44,11 @@ using namespace ot; otError otServerGetNetDataLocal(otInstance *aInstance, bool aStable, uint8_t *aData, uint8_t *aDataLength) { - otError error = OT_ERROR_NONE; Instance &instance = *static_cast(aInstance); - VerifyOrExit(aData != NULL && aDataLength != NULL, error = OT_ERROR_INVALID_ARGS); + assert(aData != NULL && aDataLength != NULL); - error = instance.Get().GetNetworkData(aStable, aData, *aDataLength); - -exit: - return error; + return instance.Get().GetNetworkData(aStable, aData, *aDataLength); } otError otServerAddService(otInstance *aInstance, const otServiceConfig *aConfig) diff --git a/src/core/api/thread_api.cpp b/src/core/api/thread_api.cpp index e5301be4e..b2f830b23 100644 --- a/src/core/api/thread_api.cpp +++ b/src/core/api/thread_api.cpp @@ -35,6 +35,7 @@ #include +#include "common/debug.hpp" #include "common/instance.hpp" #include "common/locator-getters.hpp" #include "common/logging.hpp" @@ -42,6 +43,7 @@ using namespace ot; +#if OPENTHREAD_FTD || OPENTHREAD_MTD uint32_t otThreadGetChildTimeout(otInstance *aInstance) { Instance &instance = *static_cast(aInstance); @@ -88,15 +90,11 @@ exit: otError otThreadGetLeaderRloc(otInstance *aInstance, otIp6Address *aLeaderRloc) { - otError error; Instance &instance = *static_cast(aInstance); - VerifyOrExit(aLeaderRloc != NULL, error = OT_ERROR_INVALID_ARGS); + assert(aLeaderRloc != NULL); - error = instance.Get().GetLeaderAddress(*static_cast(aLeaderRloc)); - -exit: - return error; + return instance.Get().GetLeaderAddress(*static_cast(aLeaderRloc)); } otLinkModeConfig otThreadGetLinkMode(otInstance *aInstance) @@ -128,7 +126,8 @@ otError otThreadSetMasterKey(otInstance *aInstance, const otMasterKey *aKey) otError error = OT_ERROR_NONE; Instance &instance = *static_cast(aInstance); - VerifyOrExit(aKey != NULL, error = OT_ERROR_INVALID_ARGS); + assert(aKey != NULL); + VerifyOrExit(instance.Get().GetRole() == OT_DEVICE_ROLE_DISABLED, error = OT_ERROR_INVALID_STATE); error = instance.Get().SetMasterKey(*static_cast(aKey)); @@ -248,15 +247,11 @@ otError otThreadBecomeChild(otInstance *aInstance) otError otThreadGetNextNeighborInfo(otInstance *aInstance, otNeighborInfoIterator *aIterator, otNeighborInfo *aInfo) { - otError error = OT_ERROR_NONE; Instance &instance = *static_cast(aInstance); - VerifyOrExit((aInfo != NULL) && (aIterator != NULL), error = OT_ERROR_INVALID_ARGS); + assert((aInfo != NULL) && (aIterator != NULL)); - error = instance.Get().GetNextNeighborInfo(*aIterator, *aInfo); - -exit: - return error; + return instance.Get().GetNextNeighborInfo(*aIterator, *aInfo); } otDeviceRole otThreadGetDeviceRole(otInstance *aInstance) @@ -268,15 +263,11 @@ otDeviceRole otThreadGetDeviceRole(otInstance *aInstance) otError otThreadGetLeaderData(otInstance *aInstance, otLeaderData *aLeaderData) { - otError error; Instance &instance = *static_cast(aInstance); - VerifyOrExit(aLeaderData != NULL, error = OT_ERROR_INVALID_ARGS); + assert(aLeaderData != NULL); - error = instance.Get().GetLeaderData(*aLeaderData); - -exit: - return error; + return instance.Get().GetLeaderData(*aLeaderData); } uint8_t otThreadGetLeaderRouterId(otInstance *aInstance) @@ -309,13 +300,19 @@ uint16_t otThreadGetRloc16(otInstance *aInstance) otError otThreadGetParentInfo(otInstance *aInstance, otRouterInfo *aParentInfo) { - otError error = OT_ERROR_NONE; Instance &instance = *static_cast(aInstance); + otError error = OT_ERROR_NONE; Router * parent; - VerifyOrExit(aParentInfo != NULL, error = OT_ERROR_INVALID_ARGS); + assert(aParentInfo != NULL); + + // Reference device needs get the original parent's info even after the node state changed. +#if !OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE + VerifyOrExit(instance.Get().GetRole() == OT_DEVICE_ROLE_CHILD, error = OT_ERROR_INVALID_STATE); +#endif + + parent = instance.Get().GetParent(); - parent = instance.Get().GetParent(); aParentInfo->mExtAddress = parent->GetExtAddress(); aParentInfo->mRloc16 = parent->GetRloc16(); aParentInfo->mRouterId = Mle::Mle::GetRouterId(parent->GetRloc16()); @@ -327,7 +324,9 @@ otError otThreadGetParentInfo(otInstance *aInstance, otRouterInfo *aParentInfo) aParentInfo->mAllocated = true; aParentInfo->mLinkEstablished = parent->GetState() == Neighbor::kStateValid; +#if !OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE exit: +#endif return error; } @@ -337,7 +336,7 @@ otError otThreadGetParentAverageRssi(otInstance *aInstance, int8_t *aParentRssi) Instance &instance = *static_cast(aInstance); Router * parent; - VerifyOrExit(aParentRssi != NULL, error = OT_ERROR_INVALID_ARGS); + assert(aParentRssi != NULL); parent = instance.Get().GetParent(); *aParentRssi = parent->GetLinkInfo().GetAverageRss(); @@ -354,7 +353,7 @@ otError otThreadGetParentLastRssi(otInstance *aInstance, int8_t *aLastRssi) Instance &instance = *static_cast(aInstance); Router * parent; - VerifyOrExit(aLastRssi != NULL, error = OT_ERROR_INVALID_ARGS); + assert(aLastRssi != NULL); parent = instance.Get().GetParent(); *aLastRssi = parent->GetLinkInfo().GetLastRss(); @@ -464,21 +463,12 @@ void otThreadResetMleCounters(otInstance *aInstance) instance.Get().ResetCounters(); } -otError otThreadRegisterParentResponseCallback(otInstance * aInstance, - otThreadParentResponseCallback aCallback, - void * aContext) +void otThreadRegisterParentResponseCallback(otInstance * aInstance, + otThreadParentResponseCallback aCallback, + void * aContext) { -#if OPENTHREAD_FTD || OPENTHREAD_MTD Instance &instance = *static_cast(aInstance); instance.Get().RegisterParentResponseStatsCallback(aCallback, aContext); - - return OT_ERROR_NONE; -#else - OT_UNUSED_VARIABLE(aInstance); - OT_UNUSED_VARIABLE(aCallback); - OT_UNUSED_VARIABLE(aContext); - - return OT_ERROR_DISABLED_FEATURE; -#endif } +#endif // OPENTHREAD_FTD || OPENTHREAD_MTD diff --git a/src/core/api/thread_ftd_api.cpp b/src/core/api/thread_ftd_api.cpp index 130e64ddb..487db15d8 100644 --- a/src/core/api/thread_ftd_api.cpp +++ b/src/core/api/thread_ftd_api.cpp @@ -239,28 +239,20 @@ void otThreadSetRouterSelectionJitter(otInstance *aInstance, uint8_t aRouterJitt otError otThreadGetChildInfoById(otInstance *aInstance, uint16_t aChildId, otChildInfo *aChildInfo) { - otError error = OT_ERROR_NONE; Instance &instance = *static_cast(aInstance); - VerifyOrExit(aChildInfo != NULL, error = OT_ERROR_INVALID_ARGS); + assert(aChildInfo != NULL); - error = instance.Get().GetChildInfoById(aChildId, *aChildInfo); - -exit: - return error; + return instance.Get().GetChildInfoById(aChildId, *aChildInfo); } otError otThreadGetChildInfoByIndex(otInstance *aInstance, uint16_t aChildIndex, otChildInfo *aChildInfo) { - otError error = OT_ERROR_NONE; Instance &instance = *static_cast(aInstance); - VerifyOrExit(aChildInfo != NULL, error = OT_ERROR_INVALID_ARGS); + assert(aChildInfo != NULL); - error = instance.Get().GetChildInfoByIndex(aChildIndex, *aChildInfo); - -exit: - return error; + return instance.Get().GetChildInfoByIndex(aChildIndex, *aChildInfo); } otError otThreadGetChildNextIp6Address(otInstance * aInstance, @@ -273,7 +265,7 @@ otError otThreadGetChildNextIp6Address(otInstance * aInstance, Child::Ip6AddressIterator iterator; Ip6::Address * address; - VerifyOrExit(aIterator != NULL && aAddress != NULL, error = OT_ERROR_INVALID_ARGS); + assert(aIterator != NULL && aAddress != NULL); address = static_cast(aAddress); iterator.Set(*aIterator); @@ -301,46 +293,29 @@ uint8_t otThreadGetMaxRouterId(otInstance *aInstance) otError otThreadGetRouterInfo(otInstance *aInstance, uint16_t aRouterId, otRouterInfo *aRouterInfo) { - otError error = OT_ERROR_NONE; Instance &instance = *static_cast(aInstance); - VerifyOrExit(aRouterInfo != NULL, error = OT_ERROR_INVALID_ARGS); + assert(aRouterInfo != NULL); - error = instance.Get().GetRouterInfo(aRouterId, *aRouterInfo); - -exit: - return error; + return instance.Get().GetRouterInfo(aRouterId, *aRouterInfo); } otError otThreadGetEidCacheEntry(otInstance *aInstance, uint8_t aIndex, otEidCacheEntry *aEntry) { - otError error; Instance &instance = *static_cast(aInstance); - VerifyOrExit(aEntry != NULL, error = OT_ERROR_INVALID_ARGS); - error = instance.Get().GetEntry(aIndex, *aEntry); - -exit: - return error; + assert(aEntry != NULL); + return instance.Get().GetEntry(aIndex, *aEntry); } -otError otThreadSetSteeringData(otInstance *aInstance, const otExtAddress *aExtAddress) -{ - otError error; - #if OPENTHREAD_CONFIG_MLE_STEERING_DATA_SET_OOB_ENABLE +void otThreadSetSteeringData(otInstance *aInstance, const otExtAddress *aExtAddress) +{ Instance &instance = *static_cast(aInstance); - error = instance.Get().SetSteeringData(static_cast(aExtAddress)); -#else - OT_UNUSED_VARIABLE(aInstance); - OT_UNUSED_VARIABLE(aExtAddress); - - error = OT_ERROR_DISABLED_FEATURE; -#endif - - return error; + instance.Get().SetSteeringData(static_cast(aExtAddress)); } +#endif const otPSKc *otThreadGetPSKc(otInstance *aInstance) { diff --git a/src/core/coap/coap_secure.cpp b/src/core/coap/coap_secure.cpp index 9901dce6f..ffdec6c27 100644 --- a/src/core/coap/coap_secure.cpp +++ b/src/core/coap/coap_secure.cpp @@ -118,30 +118,20 @@ otError CoapSecure::SetPsk(const uint8_t *aPsk, uint8_t aPskLength) #if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE #ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED -otError CoapSecure::SetCertificate(const uint8_t *aX509Cert, - uint32_t aX509Length, - const uint8_t *aPrivateKey, - uint32_t aPrivateKeyLength) +void CoapSecure::SetCertificate(const uint8_t *aX509Cert, + uint32_t aX509Length, + const uint8_t *aPrivateKey, + uint32_t aPrivateKeyLength) { - return mDtls.SetCertificate(aX509Cert, aX509Length, aPrivateKey, aPrivateKeyLength); + mDtls.SetCertificate(aX509Cert, aX509Length, aPrivateKey, aPrivateKeyLength); } -otError CoapSecure::SetCaCertificateChain(const uint8_t *aX509CaCertificateChain, uint32_t aX509CaCertChainLength) +void CoapSecure::SetCaCertificateChain(const uint8_t *aX509CaCertificateChain, uint32_t aX509CaCertChainLength) { - return mDtls.SetCaCertificateChain(aX509CaCertificateChain, aX509CaCertChainLength); + mDtls.SetCaCertificateChain(aX509CaCertificateChain, aX509CaCertChainLength); } #endif // MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED -#ifdef MBEDTLS_KEY_EXCHANGE_PSK_ENABLED -otError CoapSecure::SetPreSharedKey(const uint8_t *aPsk, - uint16_t aPskLength, - const uint8_t *aPskIdentity, - uint16_t aPskIdLength) -{ - return mDtls.SetPreSharedKey(aPsk, aPskLength, aPskIdentity, aPskIdLength); -} -#endif // MBEDTLS_KEY_EXCHANGE_PSK_ENABLED - #ifdef MBEDTLS_BASE64_C otError CoapSecure::GetPeerCertificateBase64(unsigned char *aPeerCert, size_t *aCertLength, size_t aCertBufferSize) { diff --git a/src/core/coap/coap_secure.hpp b/src/core/coap/coap_secure.hpp index e32ea3cf7..79790846a 100644 --- a/src/core/coap/coap_secure.hpp +++ b/src/core/coap/coap_secure.hpp @@ -173,13 +173,11 @@ public: * @param[in] aPskIdentity The Identity Name for the PSK. * @param[in] aPskIdLength The PSK Identity Length. * - * @retval OT_ERROR_NONE Successfully set the PSK. - * */ - otError SetPreSharedKey(const uint8_t *aPsk, - uint16_t aPskLength, - const uint8_t *aPskIdentity, - uint16_t aPskIdLength); + void SetPreSharedKey(const uint8_t *aPsk, uint16_t aPskLength, const uint8_t *aPskIdentity, uint16_t aPskIdLength) + { + mDtls.SetPreSharedKey(aPsk, aPskLength, aPskIdentity, aPskIdLength); + } #endif // MBEDTLS_KEY_EXCHANGE_PSK_ENABLED #ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED @@ -193,13 +191,11 @@ public: * @param[in] aPrivateKey A pointer to the PEM formatted private key. * @param[in] aPrivateKeyLength The length of the private key. * - * @retval OT_ERROR_NONE Successfully set the x509 certificate with his private key. - * */ - otError SetCertificate(const uint8_t *aX509Cert, - uint32_t aX509Length, - const uint8_t *aPrivateKey, - uint32_t aPrivateKeyLength); + void SetCertificate(const uint8_t *aX509Cert, + uint32_t aX509Length, + const uint8_t *aPrivateKey, + uint32_t aPrivateKeyLength); /** * This method sets the trusted top level CAs. It is needed for validate the @@ -210,10 +206,8 @@ public: * @param[in] aX509CaCertificateChain A pointer to the PEM formatted X509 CA chain. * @param[in] aX509CaCertChainLength The length of chain. * - * @retval OT_ERROR_NONE Successfully set the trusted top level CAs. - * */ - otError SetCaCertificateChain(const uint8_t *aX509CaCertificateChain, uint32_t aX509CaCertChainLength); + void SetCaCertificateChain(const uint8_t *aX509CaCertificateChain, uint32_t aX509CaCertChainLength); #endif // MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED #ifdef MBEDTLS_BASE64_C diff --git a/src/core/common/logging.cpp b/src/core/common/logging.cpp index e91cbb487..259f987b2 100644 --- a/src/core/common/logging.cpp +++ b/src/core/common/logging.cpp @@ -290,10 +290,6 @@ const char *otThreadErrorToString(otError aError) retval = "NonLowpanDataFrame"; break; - case OT_ERROR_DISABLED_FEATURE: - retval = "DisabledFeature"; - break; - case OT_ERROR_GENERIC: retval = "GenericError"; break; diff --git a/src/core/config/openthread-core-config-check.h b/src/core/config/openthread-core-config-check.h index 86bb5bafc..5f2500386 100644 --- a/src/core/config/openthread-core-config-check.h +++ b/src/core/config/openthread-core-config-check.h @@ -42,6 +42,12 @@ #error "OPENTHREAD_ENABLE_DHCP6_MULTICAST_SOLICIT requires OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE to be also set." #endif +#if OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE +#if OPENTHREAD_CONFIG_ENABLE_DYNAMIC_LOG_LEVEL +#error "Dynamic log level is not supported along with multiple OT instance feature" +#endif +#endif + /* * Removed or replaced OPENTHREAD_CONFIG options. * diff --git a/src/core/meshcop/dtls.cpp b/src/core/meshcop/dtls.cpp index eb3a1d8d8..2364ae793 100644 --- a/src/core/meshcop/dtls.cpp +++ b/src/core/meshcop/dtls.cpp @@ -451,13 +451,11 @@ exit: #if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE #ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED -otError Dtls::SetCertificate(const uint8_t *aX509Certificate, - uint32_t aX509CertLength, - const uint8_t *aPrivateKey, - uint32_t aPrivateKeyLength) +void Dtls::SetCertificate(const uint8_t *aX509Certificate, + uint32_t aX509CertLength, + const uint8_t *aPrivateKey, + uint32_t aPrivateKeyLength) { - otError error = OT_ERROR_NONE; - assert(aX509CertLength > 0); assert(aX509Certificate != NULL); @@ -471,34 +469,23 @@ otError Dtls::SetCertificate(const uint8_t *aX509Certificate, mCipherSuites[0] = MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8; mCipherSuites[1] = 0; - - return error; } -otError Dtls::SetCaCertificateChain(const uint8_t *aX509CaCertificateChain, uint32_t aX509CaCertChainLength) +void Dtls::SetCaCertificateChain(const uint8_t *aX509CaCertificateChain, uint32_t aX509CaCertChainLength) { - otError error = OT_ERROR_NONE; - assert(aX509CaCertChainLength > 0); assert(aX509CaCertificateChain != NULL); mCaChainSrc = aX509CaCertificateChain; mCaChainLength = aX509CaCertChainLength; - - return error; } #endif // MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED #ifdef MBEDTLS_KEY_EXCHANGE_PSK_ENABLED -otError Dtls::SetPreSharedKey(const uint8_t *aPsk, - uint16_t aPskLength, - const uint8_t *aPskIdentity, - uint16_t aPskIdLength) +void Dtls::SetPreSharedKey(const uint8_t *aPsk, uint16_t aPskLength, const uint8_t *aPskIdentity, uint16_t aPskIdLength) { - otError error = OT_ERROR_NONE; - assert(aPsk != NULL); assert(aPskIdentity != NULL); assert(aPskLength > 0); @@ -511,8 +498,6 @@ otError Dtls::SetPreSharedKey(const uint8_t *aPsk, mCipherSuites[0] = MBEDTLS_TLS_PSK_WITH_AES_128_CCM_8; mCipherSuites[1] = 0; - - return error; } #endif // MBEDTLS_KEY_EXCHANGE_PSK_ENABLED diff --git a/src/core/meshcop/dtls.hpp b/src/core/meshcop/dtls.hpp index 764a3f28b..113dc27c7 100644 --- a/src/core/meshcop/dtls.hpp +++ b/src/core/meshcop/dtls.hpp @@ -263,15 +263,11 @@ public: * @retval OT_ERROR_NONE Successfully set the PSK. * */ - otError SetPreSharedKey(const uint8_t *aPsk, - uint16_t aPskLength, - const uint8_t *aPskIdentity, - uint16_t aPskIdLength); + void SetPreSharedKey(const uint8_t *aPsk, uint16_t aPskLength, const uint8_t *aPskIdentity, uint16_t aPskIdLength); #endif // MBEDTLS_KEY_EXCHANGE_PSK_ENABLED #ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED - /** * This method sets a reference to the own x509 certificate with corresponding private key. * @@ -282,13 +278,11 @@ public: * @param[in] aPrivateKey A pointer to the PEM formatted private key. * @param[in] aPrivateKeyLength The length of the private key. * - * @retval OT_ERROR_NONE Successfully set the x509 certificate with his private key. - * */ - otError SetCertificate(const uint8_t *aX509Certificate, - uint32_t aX509CertLength, - const uint8_t *aPrivateKey, - uint32_t aPrivateKeyLength); + void SetCertificate(const uint8_t *aX509Certificate, + uint32_t aX509CertLength, + const uint8_t *aPrivateKey, + uint32_t aPrivateKeyLength); /** * This method sets the trusted top level CAs. It is needed for validate the @@ -299,11 +293,8 @@ public: * @param[in] aX509CaCertificateChain A pointer to the PEM formatted X509 CA chain. * @param[in] aX509CaCertChainLength The length of chain. * - * @retval OT_ERROR_NONE Successfully set the trusted top level CAs. - * */ - otError SetCaCertificateChain(const uint8_t *aX509CaCertificateChain, uint32_t aX509CaCertChainLength); - + void SetCaCertificateChain(const uint8_t *aX509CaCertificateChain, uint32_t aX509CaCertChainLength); #endif // MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED #ifdef MBEDTLS_BASE64_C @@ -316,8 +307,9 @@ public: * @param[out] aCertLength The length of the base64 encoded peer certificate. * @param[in] aCertBufferSize The buffer size of aPeerCert. * - * @retval OT_ERROR_NONE Successfully get the peer certificate. - * @retval OT_ERROR_NO_BUFS Can't allocate memory for certificate. + * @retval OT_ERROR_INVALID_STATE Not connected yet. + * @retval OT_ERROR_NONE Successfully get the peer certificate. + * @retval OT_ERROR_NO_BUFS Can't allocate memory for certificate. * */ otError GetPeerCertificateBase64(unsigned char *aPeerCert, size_t *aCertLength, size_t aCertBufferSize); diff --git a/src/core/thread/key_manager.cpp b/src/core/thread/key_manager.cpp index 1474a886f..2c697db80 100644 --- a/src/core/thread/key_manager.cpp +++ b/src/core/thread/key_manager.cpp @@ -114,7 +114,7 @@ exit: otError KeyManager::SetMasterKey(const MasterKey &aKey) { otError error = OT_ERROR_NONE; - Router *routers; + Router *parent; VerifyOrExit(mMasterKey != aKey, Get().SignalIfFirst(OT_CHANGED_MASTER_KEY)); @@ -123,10 +123,10 @@ otError KeyManager::SetMasterKey(const MasterKey &aKey) ComputeKey(mKeySequence, mKey); // reset parent frame counters - routers = Get().GetParent(); - routers->SetKeySequence(0); - routers->SetLinkFrameCounter(0); - routers->SetMleFrameCounter(0); + parent = Get().GetParent(); + parent->SetKeySequence(0); + parent->SetLinkFrameCounter(0); + parent->SetMleFrameCounter(0); // reset router frame counters for (RouterTable::Iterator iter(GetInstance()); !iter.IsDone(); iter++) diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index 8927b9ed5..ecbc45bc5 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -2601,9 +2601,8 @@ exit: } #if OPENTHREAD_CONFIG_MLE_STEERING_DATA_SET_OOB_ENABLE -otError MleRouter::SetSteeringData(const Mac::ExtAddress *aExtAddress) +void MleRouter::SetSteeringData(const Mac::ExtAddress *aExtAddress) { - otError error = OT_ERROR_NONE; Mac::ExtAddress nullExtAddr; Mac::ExtAddress allowAnyExtAddr; @@ -2632,8 +2631,6 @@ otError MleRouter::SetSteeringData(const Mac::ExtAddress *aExtAddress) // compute Bloom Filter mSteeringData.ComputeBloomFilter(joinerId); } - - return error; } #endif // OPENTHREAD_CONFIG_MLE_STEERING_DATA_SET_OOB_ENABLE diff --git a/src/core/thread/mle_router_ftd.hpp b/src/core/thread/mle_router_ftd.hpp index 556e92944..7428b4b3e 100644 --- a/src/core/thread/mle_router_ftd.hpp +++ b/src/core/thread/mle_router_ftd.hpp @@ -548,10 +548,8 @@ public: * All 0xFFs sets steering data to 0xFF * Anything else is used to compute the bloom filter * - * @retval OT_ERROR_NONE Steering data was set - * */ - otError SetSteeringData(const Mac::ExtAddress *aExtAddress); + void SetSteeringData(const Mac::ExtAddress *aExtAddress); #endif // OPENTHREAD_CONFIG_MLE_STEERING_DATA_SET_OOB_ENABLE /** diff --git a/src/core/utils/channel_manager.cpp b/src/core/utils/channel_manager.cpp index 02270e90d..392d03a24 100644 --- a/src/core/utils/channel_manager.cpp +++ b/src/core/utils/channel_manager.cpp @@ -385,15 +385,6 @@ exit: return error; } - -#else // OPENTHREAD_CONFIG_CHANNEL_MONITOR_ENABLE - -otError ChannelManager::RequestChannelSelect(bool) -{ - otLogInfoUtil("ChannelManager: ChannelMonitor feature is disabled - cannot select channel"); - return OT_ERROR_DISABLED_FEATURE; -} - #endif // OPENTHREAD_CONFIG_CHANNEL_MONITOR_ENABLE void ChannelManager::StartAutoSelectTimer(void) diff --git a/src/core/utils/channel_manager.hpp b/src/core/utils/channel_manager.hpp index 28a84c8ac..534d485ef 100644 --- a/src/core/utils/channel_manager.hpp +++ b/src/core/utils/channel_manager.hpp @@ -155,7 +155,6 @@ public: * @retval OT_ERROR_NONE Channel selection finished successfully. * @retval OT_ERROR_NOT_FOUND Supported channels is empty, therefore could not select a channel. * @retval OT_ERROR_INVALID_STATE Thread is not enabled or not enough data to select new channel. - * @retval OT_ERROR_DISABLED_FEATURE `ChannelMonitor` feature is disabled by build-time configuration options. * */ otError RequestChannelSelect(bool aSkipQualityCheck); diff --git a/src/ncp/ncp_base.cpp b/src/ncp/ncp_base.cpp index 42bdd7d6e..ca53bfd7d 100644 --- a/src/ncp/ncp_base.cpp +++ b/src/ncp/ncp_base.cpp @@ -132,10 +132,6 @@ spinel_status_t NcpBase::ThreadErrorToSpinelStatus(otError aError) ret = SPINEL_STATUS_ITEM_NOT_FOUND; break; - case OT_ERROR_DISABLED_FEATURE: - ret = SPINEL_STATUS_INVALID_COMMAND_FOR_PROP; - break; - default: // Unknown error code. Wrap it as a Spinel status and return that. ret = static_cast(SPINEL_STATUS_STACK_NATIVE__BEGIN + static_cast(aError)); @@ -1939,11 +1935,6 @@ template <> otError NcpBase::HandlePropertyGet(void return mEncoder.WriteUint8(SPINEL_MCU_POWER_STATE_ON); } -template <> otError NcpBase::HandlePropertySet(void) -{ - return OT_ERROR_DISABLED_FEATURE; -} - #endif // OPENTHREAD_CONFIG_NCP_ENABLE_MCU_POWER_STATE_CONTROL template <> otError NcpBase::HandlePropertyGet(void) @@ -2139,11 +2130,12 @@ template <> otError NcpBase::HandlePropertyGet( return mEncoder.WriteUint8(ConvertLogLevel(otLoggingGetLevel())); } +#if OPENTHREAD_CONFIG_ENABLE_DYNAMIC_LOG_LEVEL template <> otError NcpBase::HandlePropertySet(void) { + otError error; uint8_t spinelNcpLogLevel = 0; otLogLevel logLevel; - otError error = OT_ERROR_NONE; SuccessOrExit(error = mDecoder.ReadUint8(spinelNcpLogLevel)); @@ -2180,11 +2172,12 @@ template <> otError NcpBase::HandlePropertySet( break; } - error = otLoggingSetLevel(logLevel); + otLoggingSetLevel(logLevel); exit: return error; } +#endif // OPENTHREAD_CONFIG_ENABLE_DYNAMIC_LOG_LEVEL template <> otError NcpBase::HandlePropertyGet(void) { @@ -2253,28 +2246,18 @@ exit: // MARK: Peek/Poke delegate API // ---------------------------------------------------------------------------- -otError otNcpRegisterPeekPokeDelagates(otNcpDelegateAllowPeekPoke aAllowPeekDelegate, - otNcpDelegateAllowPeekPoke aAllowPokeDelegate) -{ - OT_UNUSED_VARIABLE(aAllowPeekDelegate); - OT_UNUSED_VARIABLE(aAllowPokeDelegate); - - otError error = OT_ERROR_NONE; - #if OPENTHREAD_CONFIG_NCP_ENABLE_PEEK_POKE +void otNcpRegisterPeekPokeDelagates(otNcpDelegateAllowPeekPoke aAllowPeekDelegate, + otNcpDelegateAllowPeekPoke aAllowPokeDelegate) +{ ot::Ncp::NcpBase *ncp = ot::Ncp::NcpBase::GetNcpInstance(); if (ncp != NULL) { ncp->RegisterPeekPokeDelagates(aAllowPeekDelegate, aAllowPokeDelegate); } -#else - error = OT_ERROR_DISABLED_FEATURE; - -#endif // OPENTHREAD_CONFIG_NCP_ENABLE_PEEK_POKE - - return error; } +#endif // OPENTHREAD_CONFIG_NCP_ENABLE_PEEK_POKE // ---------------------------------------------------------------------------- // MARK: Virtual Datastream I/O (Public API) diff --git a/src/ncp/ncp_base.hpp b/src/ncp/ncp_base.hpp index f640c2130..d0439bdf4 100644 --- a/src/ncp/ncp_base.hpp +++ b/src/ncp/ncp_base.hpp @@ -121,9 +121,6 @@ public: * @param[in] aAllowPeekDelegate Delegate function pointer for peek operation. * @param[in] aAllowPokeDelegate Delegate function pointer for poke operation. * - * @retval OT_ERROR_NONE Successfully registered delegate functions. - * @retval OT_ERROR_DISABLED_FEATURE Peek/Poke feature is disabled (by a build-time configuration option). - * */ void RegisterPeekPokeDelagates(otNcpDelegateAllowPeekPoke aAllowPeekDelegate, otNcpDelegateAllowPeekPoke aAllowPokeDelegate); diff --git a/src/ncp/ncp_base_dispatcher.cpp b/src/ncp/ncp_base_dispatcher.cpp index 7eb7041b4..a6bb6f0c9 100644 --- a/src/ncp/ncp_base_dispatcher.cpp +++ b/src/ncp/ncp_base_dispatcher.cpp @@ -682,9 +682,11 @@ NcpBase::PropertyHandler NcpBase::FindSetPropertyHandler(spinel_prop_key_t aKey) case SPINEL_PROP_POWER_STATE: handler = &NcpBase::HandlePropertySet; break; +#if OPENTHREAD_CONFIG_NCP_ENABLE_MCU_POWER_STATE_CONTROL case SPINEL_PROP_MCU_POWER_STATE: handler = &NcpBase::HandlePropertySet; break; +#endif case SPINEL_PROP_UNSOL_UPDATE_FILTER: handler = &NcpBase::HandlePropertySet; break; @@ -805,9 +807,11 @@ NcpBase::PropertyHandler NcpBase::FindSetPropertyHandler(spinel_prop_key_t aKey) case SPINEL_PROP_NET_REQUIRE_JOIN_EXISTING: handler = &NcpBase::HandlePropertySet; break; +#if OPENTHREAD_CONFIG_ENABLE_DYNAMIC_LOG_LEVEL case SPINEL_PROP_DEBUG_NCP_LOG_LEVEL: handler = &NcpBase::HandlePropertySet; break; +#endif case SPINEL_PROP_THREAD_DISCOVERY_SCAN_JOINER_FLAG: handler = &NcpBase::HandlePropertySet; break; @@ -969,9 +973,11 @@ NcpBase::PropertyHandler NcpBase::FindSetPropertyHandler(spinel_prop_key_t aKey) case SPINEL_PROP_CHANNEL_MANAGER_FAVORED_CHANNELS: handler = &NcpBase::HandlePropertySet; break; +#if OPENTHREAD_CONFIG_CHANNEL_MONITOR_ENABLE case SPINEL_PROP_CHANNEL_MANAGER_CHANNEL_SELECT: handler = &NcpBase::HandlePropertySet; break; +#endif case SPINEL_PROP_CHANNEL_MANAGER_AUTO_SELECT_ENABLED: handler = &NcpBase::HandlePropertySet; break; diff --git a/src/ncp/ncp_base_ftd.cpp b/src/ncp/ncp_base_ftd.cpp index 152f763ed..a2f486112 100644 --- a/src/ncp/ncp_base_ftd.cpp +++ b/src/ncp/ncp_base_ftd.cpp @@ -833,7 +833,7 @@ template <> otError NcpBase::HandlePropertySet SuccessOrExit(error = mDecoder.ReadEui64(mSteeringDataAddress)); - SuccessOrExit(error = otThreadSetSteeringData(mInstance, &mSteeringDataAddress)); + otThreadSetSteeringData(mInstance, &mSteeringDataAddress); exit: return error; diff --git a/src/ncp/ncp_base_mtd.cpp b/src/ncp/ncp_base_mtd.cpp index 4926130cc..e7a00ed9d 100644 --- a/src/ncp/ncp_base_mtd.cpp +++ b/src/ncp/ncp_base_mtd.cpp @@ -1493,7 +1493,7 @@ template <> otError NcpBase::HandlePropertySet