mirror of
https://github.com/espressif/openthread.git
synced 2026-10-02 05:47:40 +00:00
[debug] adding SuccessOrAssert() helper macro (#7083)
This commit adds a new macro `SuccessOrAssert()` which checks a given status value against zero (zero status indicates success or no error) and `OT_ASSERT()` if it is not. This helper macro is then used by other modules where we want to assert that some method/function is not returning an error.
This commit is contained in:
@@ -100,17 +100,11 @@ Error CoapSecure::Connect(const Ip6::SockAddr &aSockAddr, ConnectedCallback aCal
|
|||||||
|
|
||||||
void CoapSecure::SetPsk(const MeshCoP::JoinerPskd &aPskd)
|
void CoapSecure::SetPsk(const MeshCoP::JoinerPskd &aPskd)
|
||||||
{
|
{
|
||||||
Error error;
|
|
||||||
|
|
||||||
OT_UNUSED_VARIABLE(error);
|
|
||||||
|
|
||||||
static_assert(static_cast<uint16_t>(MeshCoP::JoinerPskd::kMaxLength) <=
|
static_assert(static_cast<uint16_t>(MeshCoP::JoinerPskd::kMaxLength) <=
|
||||||
static_cast<uint16_t>(MeshCoP::Dtls::kPskMaxLength),
|
static_cast<uint16_t>(MeshCoP::Dtls::kPskMaxLength),
|
||||||
"The maximum length of DTLS PSK is smaller than joiner PSKd");
|
"The maximum length of DTLS PSK is smaller than joiner PSKd");
|
||||||
|
|
||||||
error = mDtls.SetPsk(reinterpret_cast<const uint8_t *>(aPskd.GetAsCString()), aPskd.GetLength());
|
SuccessOrAssert(mDtls.SetPsk(reinterpret_cast<const uint8_t *>(aPskd.GetAsCString()), aPskd.GetLength()));
|
||||||
|
|
||||||
OT_ASSERT(error == kErrorNone);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||||
|
|||||||
@@ -92,4 +92,20 @@
|
|||||||
|
|
||||||
#endif // OPENTHREAD_CONFIG_ASSERT_ENABLE
|
#endif // OPENTHREAD_CONFIG_ASSERT_ENABLE
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This macro checks a given status (which is expected to be successful) against zero (0) which indicates success,
|
||||||
|
* and `OT_ASSERT()` if it is not.
|
||||||
|
*
|
||||||
|
* @param[in] aStatus A scalar status to be evaluated against zero (0).
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define SuccessOrAssert(aStatus) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
if ((aStatus) != 0) \
|
||||||
|
{ \
|
||||||
|
OT_ASSERT(false); \
|
||||||
|
} \
|
||||||
|
} while (false)
|
||||||
|
|
||||||
#endif // DEBUG_HPP_
|
#endif // DEBUG_HPP_
|
||||||
|
|||||||
@@ -54,9 +54,6 @@ RandomManager::CryptoCtrDrbg RandomManager::sCtrDrbg;
|
|||||||
RandomManager::RandomManager(void)
|
RandomManager::RandomManager(void)
|
||||||
{
|
{
|
||||||
uint32_t seed;
|
uint32_t seed;
|
||||||
Error error;
|
|
||||||
|
|
||||||
OT_UNUSED_VARIABLE(error);
|
|
||||||
|
|
||||||
OT_ASSERT(sInitCount < 0xffff);
|
OT_ASSERT(sInitCount < 0xffff);
|
||||||
|
|
||||||
@@ -66,11 +63,9 @@ RandomManager::RandomManager(void)
|
|||||||
sEntropy.Init();
|
sEntropy.Init();
|
||||||
sCtrDrbg.Init();
|
sCtrDrbg.Init();
|
||||||
|
|
||||||
error = Random::Crypto::FillBuffer(reinterpret_cast<uint8_t *>(&seed), sizeof(seed));
|
SuccessOrAssert(Random::Crypto::FillBuffer(reinterpret_cast<uint8_t *>(&seed), sizeof(seed)));
|
||||||
OT_ASSERT(error == kErrorNone);
|
|
||||||
#else
|
#else
|
||||||
error = otPlatEntropyGet(reinterpret_cast<uint8_t *>(&seed), sizeof(seed));
|
SuccessOrAssert(otPlatEntropyGet(reinterpret_cast<uint8_t *>(&seed), sizeof(seed)));
|
||||||
OT_ASSERT(error == kErrorNone);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sPrng.Init(seed);
|
sPrng.Init(seed);
|
||||||
|
|||||||
@@ -40,35 +40,24 @@ namespace Crypto {
|
|||||||
|
|
||||||
AesEcb::AesEcb(void)
|
AesEcb::AesEcb(void)
|
||||||
{
|
{
|
||||||
Error err = kErrorNone;
|
|
||||||
|
|
||||||
mContext.mContext = mContextStorage;
|
mContext.mContext = mContextStorage;
|
||||||
mContext.mContextSize = sizeof(mContextStorage);
|
mContext.mContextSize = sizeof(mContextStorage);
|
||||||
err = otPlatCryptoAesInit(&mContext);
|
SuccessOrAssert(otPlatCryptoAesInit(&mContext));
|
||||||
|
|
||||||
OT_ASSERT(err == kErrorNone);
|
|
||||||
OT_UNUSED_VARIABLE(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AesEcb::SetKey(const Key &aKey)
|
void AesEcb::SetKey(const Key &aKey)
|
||||||
{
|
{
|
||||||
Error err = otPlatCryptoAesSetKey(&mContext, &aKey);
|
SuccessOrAssert(otPlatCryptoAesSetKey(&mContext, &aKey));
|
||||||
OT_ASSERT(err == kErrorNone);
|
|
||||||
OT_UNUSED_VARIABLE(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AesEcb::Encrypt(const uint8_t aInput[kBlockSize], uint8_t aOutput[kBlockSize])
|
void AesEcb::Encrypt(const uint8_t aInput[kBlockSize], uint8_t aOutput[kBlockSize])
|
||||||
{
|
{
|
||||||
Error err = otPlatCryptoAesEncrypt(&mContext, aInput, aOutput);
|
SuccessOrAssert(otPlatCryptoAesEncrypt(&mContext, aInput, aOutput));
|
||||||
OT_ASSERT(err == kErrorNone);
|
|
||||||
OT_UNUSED_VARIABLE(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AesEcb::~AesEcb(void)
|
AesEcb::~AesEcb(void)
|
||||||
{
|
{
|
||||||
Error err = otPlatCryptoAesFree(&mContext);
|
SuccessOrAssert(otPlatCryptoAesFree(&mContext));
|
||||||
OT_ASSERT(err == kErrorNone);
|
|
||||||
OT_UNUSED_VARIABLE(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Crypto
|
} // namespace Crypto
|
||||||
|
|||||||
@@ -45,36 +45,24 @@ namespace Crypto {
|
|||||||
|
|
||||||
HkdfSha256::HkdfSha256(void)
|
HkdfSha256::HkdfSha256(void)
|
||||||
{
|
{
|
||||||
Error err = kErrorNone;
|
|
||||||
|
|
||||||
mContext.mContext = mContextStorage;
|
mContext.mContext = mContextStorage;
|
||||||
mContext.mContextSize = sizeof(mContextStorage);
|
mContext.mContextSize = sizeof(mContextStorage);
|
||||||
err = otPlatCryptoHkdfInit(&mContext);
|
SuccessOrAssert(otPlatCryptoHkdfInit(&mContext));
|
||||||
|
|
||||||
OT_ASSERT(err == kErrorNone);
|
|
||||||
OT_UNUSED_VARIABLE(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HkdfSha256::~HkdfSha256(void)
|
HkdfSha256::~HkdfSha256(void)
|
||||||
{
|
{
|
||||||
Error err = otPlatCryptoHkdfDeinit(&mContext);
|
SuccessOrAssert(otPlatCryptoHkdfDeinit(&mContext));
|
||||||
|
|
||||||
OT_ASSERT(err == kErrorNone);
|
|
||||||
OT_UNUSED_VARIABLE(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HkdfSha256::Extract(const uint8_t *aSalt, uint16_t aSaltLength, const Key &aInputKey)
|
void HkdfSha256::Extract(const uint8_t *aSalt, uint16_t aSaltLength, const Key &aInputKey)
|
||||||
{
|
{
|
||||||
Error err = otPlatCryptoHkdfExtract(&mContext, aSalt, aSaltLength, &aInputKey);
|
SuccessOrAssert(otPlatCryptoHkdfExtract(&mContext, aSalt, aSaltLength, &aInputKey));
|
||||||
OT_ASSERT(err == kErrorNone);
|
|
||||||
OT_UNUSED_VARIABLE(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HkdfSha256::Expand(const uint8_t *aInfo, uint16_t aInfoLength, uint8_t *aOutputKey, uint16_t aOutputKeyLength)
|
void HkdfSha256::Expand(const uint8_t *aInfo, uint16_t aInfoLength, uint8_t *aOutputKey, uint16_t aOutputKeyLength)
|
||||||
{
|
{
|
||||||
Error err = otPlatCryptoHkdfExpand(&mContext, aInfo, aInfoLength, aOutputKey, aOutputKeyLength);
|
SuccessOrAssert(otPlatCryptoHkdfExpand(&mContext, aInfo, aInfoLength, aOutputKey, aOutputKeyLength));
|
||||||
OT_ASSERT(err == kErrorNone);
|
|
||||||
OT_UNUSED_VARIABLE(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Crypto
|
} // namespace Crypto
|
||||||
|
|||||||
@@ -41,42 +41,30 @@ namespace Crypto {
|
|||||||
|
|
||||||
HmacSha256::HmacSha256(void)
|
HmacSha256::HmacSha256(void)
|
||||||
{
|
{
|
||||||
Error err = kErrorNone;
|
|
||||||
|
|
||||||
mContext.mContext = mContextStorage;
|
mContext.mContext = mContextStorage;
|
||||||
mContext.mContextSize = sizeof(mContextStorage);
|
mContext.mContextSize = sizeof(mContextStorage);
|
||||||
|
|
||||||
err = otPlatCryptoHmacSha256Init(&mContext);
|
SuccessOrAssert(otPlatCryptoHmacSha256Init(&mContext));
|
||||||
OT_ASSERT(err == kErrorNone);
|
|
||||||
OT_UNUSED_VARIABLE(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HmacSha256::~HmacSha256(void)
|
HmacSha256::~HmacSha256(void)
|
||||||
{
|
{
|
||||||
Error err = otPlatCryptoHmacSha256Deinit(&mContext);
|
SuccessOrAssert(otPlatCryptoHmacSha256Deinit(&mContext));
|
||||||
OT_ASSERT(err == kErrorNone);
|
|
||||||
OT_UNUSED_VARIABLE(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HmacSha256::Start(const Key &aKey)
|
void HmacSha256::Start(const Key &aKey)
|
||||||
{
|
{
|
||||||
Error err = otPlatCryptoHmacSha256Start(&mContext, &aKey);
|
SuccessOrAssert(otPlatCryptoHmacSha256Start(&mContext, &aKey));
|
||||||
OT_ASSERT(err == kErrorNone);
|
|
||||||
OT_UNUSED_VARIABLE(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HmacSha256::Update(const void *aBuf, uint16_t aBufLength)
|
void HmacSha256::Update(const void *aBuf, uint16_t aBufLength)
|
||||||
{
|
{
|
||||||
Error err = otPlatCryptoHmacSha256Update(&mContext, aBuf, aBufLength);
|
SuccessOrAssert(otPlatCryptoHmacSha256Update(&mContext, aBuf, aBufLength));
|
||||||
OT_ASSERT(err == kErrorNone);
|
|
||||||
OT_UNUSED_VARIABLE(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HmacSha256::Finish(Hash &aHash)
|
void HmacSha256::Finish(Hash &aHash)
|
||||||
{
|
{
|
||||||
Error err = otPlatCryptoHmacSha256Finish(&mContext, aHash.m8, Hash::kSize);
|
SuccessOrAssert(otPlatCryptoHmacSha256Finish(&mContext, aHash.m8, Hash::kSize));
|
||||||
OT_ASSERT(err == kErrorNone);
|
|
||||||
OT_UNUSED_VARIABLE(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HmacSha256::Update(const Message &aMessage, uint16_t aOffset, uint16_t aLength)
|
void HmacSha256::Update(const Message &aMessage, uint16_t aOffset, uint16_t aLength)
|
||||||
|
|||||||
@@ -42,35 +42,24 @@ namespace Crypto {
|
|||||||
|
|
||||||
Sha256::Sha256(void)
|
Sha256::Sha256(void)
|
||||||
{
|
{
|
||||||
Error err = kErrorNone;
|
|
||||||
|
|
||||||
mContext.mContext = mContextStorage;
|
mContext.mContext = mContextStorage;
|
||||||
mContext.mContextSize = sizeof(mContextStorage);
|
mContext.mContextSize = sizeof(mContextStorage);
|
||||||
err = otPlatCryptoSha256Init(&mContext);
|
SuccessOrAssert(otPlatCryptoSha256Init(&mContext));
|
||||||
|
|
||||||
OT_ASSERT(err == kErrorNone);
|
|
||||||
OT_UNUSED_VARIABLE(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Sha256::~Sha256(void)
|
Sha256::~Sha256(void)
|
||||||
{
|
{
|
||||||
Error err = otPlatCryptoSha256Deinit(&mContext);
|
SuccessOrAssert(otPlatCryptoSha256Deinit(&mContext));
|
||||||
OT_ASSERT(err == kErrorNone);
|
|
||||||
OT_UNUSED_VARIABLE(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sha256::Start(void)
|
void Sha256::Start(void)
|
||||||
{
|
{
|
||||||
Error err = otPlatCryptoSha256Start(&mContext);
|
SuccessOrAssert(otPlatCryptoSha256Start(&mContext));
|
||||||
OT_ASSERT(err == kErrorNone);
|
|
||||||
OT_UNUSED_VARIABLE(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sha256::Update(const void *aBuf, uint16_t aBufLength)
|
void Sha256::Update(const void *aBuf, uint16_t aBufLength)
|
||||||
{
|
{
|
||||||
Error err = otPlatCryptoSha256Update(&mContext, aBuf, aBufLength);
|
SuccessOrAssert(otPlatCryptoSha256Update(&mContext, aBuf, aBufLength));
|
||||||
OT_ASSERT(err == kErrorNone);
|
|
||||||
OT_UNUSED_VARIABLE(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sha256::Update(const Message &aMessage, uint16_t aOffset, uint16_t aLength)
|
void Sha256::Update(const Message &aMessage, uint16_t aOffset, uint16_t aLength)
|
||||||
@@ -88,9 +77,8 @@ void Sha256::Update(const Message &aMessage, uint16_t aOffset, uint16_t aLength)
|
|||||||
|
|
||||||
void Sha256::Finish(Hash &aHash)
|
void Sha256::Finish(Hash &aHash)
|
||||||
{
|
{
|
||||||
Error err = otPlatCryptoSha256Finish(&mContext, aHash.m8, Hash::kSize);
|
SuccessOrAssert(otPlatCryptoSha256Finish(&mContext, aHash.m8, Hash::kSize));
|
||||||
OT_ASSERT(err == kErrorNone);
|
|
||||||
OT_UNUSED_VARIABLE(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Crypto
|
} // namespace Crypto
|
||||||
} // namespace ot
|
} // namespace ot
|
||||||
|
|||||||
@@ -46,9 +46,8 @@ Error Key::ExtractKey(uint8_t *aKeyBuffer, uint16_t &aKeyLength) const
|
|||||||
|
|
||||||
OT_ASSERT(IsKeyRef());
|
OT_ASSERT(IsKeyRef());
|
||||||
|
|
||||||
error = Crypto::Storage::ExportKey(GetKeyRef(), aKeyBuffer, aKeyLength, readKeyLength);
|
SuccessOrAssert(Crypto::Storage::ExportKey(GetKeyRef(), aKeyBuffer, aKeyLength, readKeyLength));
|
||||||
|
|
||||||
OT_ASSERT(error == kErrorNone);
|
|
||||||
VerifyOrExit(readKeyLength <= aKeyLength, error = kErrorNoBufs);
|
VerifyOrExit(readKeyLength <= aKeyLength, error = kErrorNoBufs);
|
||||||
|
|
||||||
aKeyLength = static_cast<uint16_t>(readKeyLength);
|
aKeyLength = static_cast<uint16_t>(readKeyLength);
|
||||||
@@ -65,14 +64,9 @@ LiteralKey::LiteralKey(const Key &aKey)
|
|||||||
#if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
|
#if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
|
||||||
if (aKey.IsKeyRef())
|
if (aKey.IsKeyRef())
|
||||||
{
|
{
|
||||||
Error error;
|
|
||||||
|
|
||||||
mKey = mBuffer;
|
mKey = mBuffer;
|
||||||
mLength = sizeof(mBuffer);
|
mLength = sizeof(mBuffer);
|
||||||
error = aKey.ExtractKey(mBuffer, mLength);
|
SuccessOrAssert(aKey.ExtractKey(mBuffer, mLength));
|
||||||
|
|
||||||
OT_ASSERT(error == kErrorNone);
|
|
||||||
OT_UNUSED_VARIABLE(error);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -273,17 +273,12 @@ void DataPollHandler::HandleSentFrame(const Mac::TxFrame &aFrame, Error aError,
|
|||||||
{
|
{
|
||||||
uint32_t frameCounter;
|
uint32_t frameCounter;
|
||||||
uint8_t keyId;
|
uint8_t keyId;
|
||||||
Error error;
|
|
||||||
|
|
||||||
error = aFrame.GetFrameCounter(frameCounter);
|
SuccessOrAssert(aFrame.GetFrameCounter(frameCounter));
|
||||||
OT_ASSERT(error == kErrorNone);
|
|
||||||
aChild.SetIndirectFrameCounter(frameCounter);
|
aChild.SetIndirectFrameCounter(frameCounter);
|
||||||
|
|
||||||
error = aFrame.GetKeyId(keyId);
|
SuccessOrAssert(aFrame.GetKeyId(keyId));
|
||||||
OT_ASSERT(error == kErrorNone);
|
|
||||||
aChild.SetIndirectKeyId(keyId);
|
aChild.SetIndirectKeyId(keyId);
|
||||||
|
|
||||||
OT_UNUSED_VARIABLE(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ExitNow();
|
ExitNow();
|
||||||
|
|||||||
@@ -156,10 +156,7 @@ 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))
|
||||||
{
|
{
|
||||||
Error error = mSubMac.Send();
|
SuccessOrAssert(mSubMac.Send());
|
||||||
|
|
||||||
OT_ASSERT(error == kErrorNone);
|
|
||||||
OT_UNUSED_VARIABLE(error);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
|
#if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
|
||||||
|
|||||||
@@ -511,11 +511,7 @@ public:
|
|||||||
void Send(void)
|
void Send(void)
|
||||||
{
|
{
|
||||||
#if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
|
#if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
|
||||||
{
|
SuccessOrAssert(mSubMac.Send());
|
||||||
Error error = mSubMac.Send();
|
|
||||||
OT_ASSERT(error == kErrorNone);
|
|
||||||
OT_UNUSED_VARIABLE(error);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
#if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
|
#if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
|
||||||
mTrel.Send();
|
mTrel.Send();
|
||||||
|
|||||||
@@ -355,18 +355,15 @@ void KeyMaterial::SetFrom(const Key &aKey, bool aIsExportable)
|
|||||||
{
|
{
|
||||||
#if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
|
#if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
|
||||||
{
|
{
|
||||||
Error error;
|
|
||||||
KeyRef keyRef = 0;
|
KeyRef keyRef = 0;
|
||||||
|
|
||||||
DestroyKey();
|
DestroyKey();
|
||||||
|
|
||||||
error = Crypto::Storage::ImportKey(keyRef, Crypto::Storage::kKeyTypeAes, Crypto::Storage::kKeyAlgorithmAesEcb,
|
SuccessOrAssert(Crypto::Storage::ImportKey(keyRef, Crypto::Storage::kKeyTypeAes,
|
||||||
(aIsExportable ? Crypto::Storage::kUsageExport : 0) |
|
Crypto::Storage::kKeyAlgorithmAesEcb,
|
||||||
Crypto::Storage::kUsageEncrypt | Crypto::Storage::kUsageDecrypt,
|
(aIsExportable ? Crypto::Storage::kUsageExport : 0) |
|
||||||
Crypto::Storage::kTypeVolatile, aKey.GetBytes(), Key::kSize);
|
Crypto::Storage::kUsageEncrypt | Crypto::Storage::kUsageDecrypt,
|
||||||
|
Crypto::Storage::kTypeVolatile, aKey.GetBytes(), Key::kSize));
|
||||||
OT_ASSERT(error == kErrorNone);
|
|
||||||
OT_UNUSED_VARIABLE(error);
|
|
||||||
|
|
||||||
SetKeyRef(keyRef);
|
SetKeyRef(keyRef);
|
||||||
}
|
}
|
||||||
@@ -383,12 +380,9 @@ void KeyMaterial::ExtractKey(Key &aKey)
|
|||||||
|
|
||||||
if (Crypto::Storage::IsKeyRefValid(GetKeyRef()))
|
if (Crypto::Storage::IsKeyRefValid(GetKeyRef()))
|
||||||
{
|
{
|
||||||
Error error;
|
|
||||||
size_t keySize;
|
size_t keySize;
|
||||||
|
|
||||||
error = Crypto::Storage::ExportKey(GetKeyRef(), aKey.m8, Key::kSize, keySize);
|
SuccessOrAssert(Crypto::Storage::ExportKey(GetKeyRef(), aKey.m8, Key::kSize, keySize));
|
||||||
OT_ASSERT(error == kErrorNone);
|
|
||||||
OT_UNUSED_VARIABLE(error);
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
aKey = GetKey();
|
aKey = GetKey();
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ Error SubMac::Enable(void)
|
|||||||
SetState(kStateSleep);
|
SetState(kStateSleep);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
OT_ASSERT(error == kErrorNone);
|
SuccessOrAssert(error);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -455,8 +455,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());
|
SuccessOrAssert(Get<Radio>().Receive(mTransmitFrame.GetChannel()));
|
||||||
OT_ASSERT(error == kErrorNone);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SetState(kStateTransmit);
|
SetState(kStateTransmit);
|
||||||
@@ -474,7 +473,8 @@ void SubMac::BeginTransmit(void)
|
|||||||
mTransmitFrame.mInfo.mTxInfo.mTxDelayBaseTime = 0;
|
mTransmitFrame.mInfo.mTxInfo.mTxDelayBaseTime = 0;
|
||||||
error = Get<Radio>().Transmit(mTransmitFrame);
|
error = Get<Radio>().Transmit(mTransmitFrame);
|
||||||
}
|
}
|
||||||
OT_ASSERT(error == kErrorNone);
|
|
||||||
|
SuccessOrAssert(error);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return;
|
return;
|
||||||
@@ -644,8 +644,7 @@ Error SubMac::EnergyScan(uint8_t aScanChannel, uint16_t aScanDuration)
|
|||||||
}
|
}
|
||||||
else if (ShouldHandleEnergyScan())
|
else if (ShouldHandleEnergyScan())
|
||||||
{
|
{
|
||||||
error = Get<Radio>().Receive(aScanChannel);
|
SuccessOrAssert(Get<Radio>().Receive(aScanChannel));
|
||||||
OT_ASSERT(error == kErrorNone);
|
|
||||||
|
|
||||||
SetState(kStateEnergyScan);
|
SetState(kStateEnergyScan);
|
||||||
mEnergyScanMaxRssi = kInvalidRssiValue;
|
mEnergyScanMaxRssi = kInvalidRssiValue;
|
||||||
|
|||||||
@@ -187,13 +187,7 @@ bool InterfaceIdentifier::IsReservedSubnetAnycast(void) const
|
|||||||
|
|
||||||
void InterfaceIdentifier::GenerateRandom(void)
|
void InterfaceIdentifier::GenerateRandom(void)
|
||||||
{
|
{
|
||||||
Error error;
|
SuccessOrAssert(Random::Crypto::FillBuffer(mFields.m8, kSize));
|
||||||
|
|
||||||
OT_UNUSED_VARIABLE(error);
|
|
||||||
|
|
||||||
error = Random::Crypto::FillBuffer(mFields.m8, kSize);
|
|
||||||
|
|
||||||
OT_ASSERT(error == kErrorNone);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InterfaceIdentifier::SetBytes(const uint8_t *aBuffer)
|
void InterfaceIdentifier::SetBytes(const uint8_t *aBuffer)
|
||||||
|
|||||||
@@ -427,10 +427,7 @@ void Mpl::Metadata::ReadFrom(const Message &aMessage)
|
|||||||
|
|
||||||
void Mpl::Metadata::RemoveFrom(Message &aMessage) const
|
void Mpl::Metadata::RemoveFrom(Message &aMessage) const
|
||||||
{
|
{
|
||||||
Error error = aMessage.SetLength(aMessage.GetLength() - sizeof(*this));
|
SuccessOrAssert(aMessage.SetLength(aMessage.GetLength() - sizeof(*this)));
|
||||||
|
|
||||||
OT_ASSERT(error == kErrorNone);
|
|
||||||
OT_UNUSED_VARIABLE(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mpl::Metadata::UpdateIn(Message &aMessage) const
|
void Mpl::Metadata::UpdateIn(Message &aMessage) const
|
||||||
|
|||||||
@@ -226,8 +226,7 @@ exit:
|
|||||||
|
|
||||||
void Netif::SubscribeAllRoutersMulticast(void)
|
void Netif::SubscribeAllRoutersMulticast(void)
|
||||||
{
|
{
|
||||||
Error error = kErrorNone;
|
MulticastAddress *prev = nullptr;
|
||||||
MulticastAddress *prev = nullptr;
|
|
||||||
MulticastAddress &linkLocalAllRoutersAddress =
|
MulticastAddress &linkLocalAllRoutersAddress =
|
||||||
static_cast<MulticastAddress &>(AsNonConst(kLinkLocalAllRoutersMulticastAddress));
|
static_cast<MulticastAddress &>(AsNonConst(kLinkLocalAllRoutersMulticastAddress));
|
||||||
MulticastAddress &linkLocalAllNodesAddress =
|
MulticastAddress &linkLocalAllNodesAddress =
|
||||||
@@ -235,13 +234,10 @@ void Netif::SubscribeAllRoutersMulticast(void)
|
|||||||
MulticastAddress &realmLocalAllRoutersAddress =
|
MulticastAddress &realmLocalAllRoutersAddress =
|
||||||
static_cast<MulticastAddress &>(AsNonConst(kRealmLocalAllRoutersMulticastAddress));
|
static_cast<MulticastAddress &>(AsNonConst(kRealmLocalAllRoutersMulticastAddress));
|
||||||
|
|
||||||
error = mMulticastAddresses.Find(linkLocalAllNodesAddress, prev);
|
|
||||||
|
|
||||||
// This method MUST be called after `SubscribeAllNodesMulticast()`
|
// This method MUST be called after `SubscribeAllNodesMulticast()`
|
||||||
// Ensure that the `LinkLocalAll` was found on the list.
|
// Ensure that the `LinkLocalAll` was found on the list.
|
||||||
|
|
||||||
OT_ASSERT(error == kErrorNone);
|
SuccessOrAssert(mMulticastAddresses.Find(linkLocalAllNodesAddress, prev));
|
||||||
OT_UNUSED_VARIABLE(error);
|
|
||||||
|
|
||||||
// The tail of multicast address linked list contains the
|
// The tail of multicast address linked list contains the
|
||||||
// fixed addresses. We either have a chain of five addresses
|
// fixed addresses. We either have a chain of five addresses
|
||||||
|
|||||||
@@ -426,10 +426,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
void ReadFrom(const Message &aMessage)
|
void ReadFrom(const Message &aMessage)
|
||||||
{
|
{
|
||||||
Error error = aMessage.Read(aMessage.GetLength() - sizeof(*this), *this);
|
SuccessOrAssert(aMessage.Read(aMessage.GetLength() - sizeof(*this), *this));
|
||||||
|
|
||||||
OT_ASSERT(error == kErrorNone);
|
|
||||||
OT_UNUSED_VARIABLE(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -37,13 +37,8 @@ namespace ot {
|
|||||||
void Radio::Init(void)
|
void Radio::Init(void)
|
||||||
{
|
{
|
||||||
#if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
|
#if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
|
||||||
Error error = OT_ERROR_NONE;
|
|
||||||
|
|
||||||
OT_UNUSED_VARIABLE(error);
|
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
|
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
|
||||||
error = EnableCsl(0, Mac::kShortAddrInvalid, nullptr);
|
SuccessOrAssert(EnableCsl(0, Mac::kShortAddrInvalid, nullptr));
|
||||||
OT_ASSERT(error == OT_ERROR_NONE);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
EnableSrcMatch(false);
|
EnableSrcMatch(false);
|
||||||
@@ -52,11 +47,8 @@ void Radio::Init(void)
|
|||||||
|
|
||||||
if (IsEnabled())
|
if (IsEnabled())
|
||||||
{
|
{
|
||||||
error = Sleep();
|
SuccessOrAssert(Sleep());
|
||||||
OT_ASSERT(error == OT_ERROR_NONE);
|
SuccessOrAssert(Disable());
|
||||||
|
|
||||||
error = Disable();
|
|
||||||
OT_ASSERT(error == OT_ERROR_NONE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SetPanId(Mac::kPanIdBroadcast);
|
SetPanId(Mac::kPanIdBroadcast);
|
||||||
|
|||||||
@@ -523,13 +523,10 @@ void KeyManager::GetNetworkKey(NetworkKey &aNetworkKey) const
|
|||||||
#if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
|
#if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
|
||||||
if (Crypto::Storage::IsKeyRefValid(mNetworkKeyRef))
|
if (Crypto::Storage::IsKeyRefValid(mNetworkKeyRef))
|
||||||
{
|
{
|
||||||
Error error = kErrorNone;
|
|
||||||
size_t keyLen;
|
size_t keyLen;
|
||||||
|
|
||||||
error = Crypto::Storage::ExportKey(mNetworkKeyRef, aNetworkKey.m8, NetworkKey::kSize, keyLen);
|
SuccessOrAssert(Crypto::Storage::ExportKey(mNetworkKeyRef, aNetworkKey.m8, NetworkKey::kSize, keyLen));
|
||||||
OT_ASSERT(error == kErrorNone);
|
|
||||||
OT_ASSERT(keyLen == NetworkKey::kSize);
|
OT_ASSERT(keyLen == NetworkKey::kSize);
|
||||||
OT_UNUSED_VARIABLE(error);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -545,13 +542,10 @@ void KeyManager::GetPskc(Pskc &aPskc) const
|
|||||||
#if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
|
#if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
|
||||||
if (Crypto::Storage::IsKeyRefValid(mPskcRef))
|
if (Crypto::Storage::IsKeyRefValid(mPskcRef))
|
||||||
{
|
{
|
||||||
Error error = kErrorNone;
|
|
||||||
size_t keyLen;
|
size_t keyLen;
|
||||||
|
|
||||||
error = Crypto::Storage::ExportKey(mPskcRef, aPskc.m8, Pskc::kSize, keyLen);
|
SuccessOrAssert(Crypto::Storage::ExportKey(mPskcRef, aPskc.m8, Pskc::kSize, keyLen));
|
||||||
OT_ASSERT(error == kErrorNone);
|
|
||||||
OT_ASSERT(keyLen == Pskc::kSize);
|
OT_ASSERT(keyLen == Pskc::kSize);
|
||||||
OT_UNUSED_VARIABLE(error);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -566,7 +560,6 @@ void KeyManager::GetPskc(Pskc &aPskc) const
|
|||||||
|
|
||||||
void KeyManager::StoreNetworkKey(const NetworkKey &aNetworkKey, bool aOverWriteExisting)
|
void KeyManager::StoreNetworkKey(const NetworkKey &aNetworkKey, bool aOverWriteExisting)
|
||||||
{
|
{
|
||||||
Error error;
|
|
||||||
NetworkKeyRef keyRef;
|
NetworkKeyRef keyRef;
|
||||||
|
|
||||||
keyRef = kNetworkKeyPsaItsOffset;
|
keyRef = kNetworkKeyPsaItsOffset;
|
||||||
@@ -584,10 +577,10 @@ void KeyManager::StoreNetworkKey(const NetworkKey &aNetworkKey, bool aOverWriteE
|
|||||||
|
|
||||||
Crypto::Storage::DestroyKey(keyRef);
|
Crypto::Storage::DestroyKey(keyRef);
|
||||||
|
|
||||||
error = Crypto::Storage::ImportKey(keyRef, Crypto::Storage::kKeyTypeHmac, Crypto::Storage::kKeyAlgorithmHmacSha256,
|
SuccessOrAssert(Crypto::Storage::ImportKey(keyRef, Crypto::Storage::kKeyTypeHmac,
|
||||||
Crypto::Storage::kUsageSignHash | Crypto::Storage::kUsageExport,
|
Crypto::Storage::kKeyAlgorithmHmacSha256,
|
||||||
Crypto::Storage::kTypePersistent, aNetworkKey.m8, NetworkKey::kSize);
|
Crypto::Storage::kUsageSignHash | Crypto::Storage::kUsageExport,
|
||||||
OT_ASSERT(error == kErrorNone);
|
Crypto::Storage::kTypePersistent, aNetworkKey.m8, NetworkKey::kSize));
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if (mNetworkKeyRef != keyRef)
|
if (mNetworkKeyRef != keyRef)
|
||||||
@@ -601,15 +594,12 @@ exit:
|
|||||||
void KeyManager::StorePskc(const Pskc &aPskc)
|
void KeyManager::StorePskc(const Pskc &aPskc)
|
||||||
{
|
{
|
||||||
PskcRef keyRef = kPskcPsaItsOffset;
|
PskcRef keyRef = kPskcPsaItsOffset;
|
||||||
Error error = kErrorNone;
|
|
||||||
|
|
||||||
Crypto::Storage::DestroyKey(keyRef);
|
Crypto::Storage::DestroyKey(keyRef);
|
||||||
|
|
||||||
error = Crypto::Storage::ImportKey(keyRef, Crypto::Storage::kKeyTypeRaw, Crypto::Storage::kKeyAlgorithmVendor,
|
SuccessOrAssert(Crypto::Storage::ImportKey(keyRef, Crypto::Storage::kKeyTypeRaw,
|
||||||
Crypto::Storage::kUsageExport, Crypto::Storage::kTypePersistent, aPskc.m8,
|
Crypto::Storage::kKeyAlgorithmVendor, Crypto::Storage::kUsageExport,
|
||||||
Pskc::kSize);
|
Crypto::Storage::kTypePersistent, aPskc.m8, Pskc::kSize));
|
||||||
OT_ASSERT(error == kErrorNone);
|
|
||||||
OT_UNUSED_VARIABLE(error);
|
|
||||||
|
|
||||||
if (mPskcRef != keyRef)
|
if (mPskcRef != keyRef)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -775,9 +775,6 @@ start:
|
|||||||
maxPayloadLength - headerLength - Lowpan::FragmentHeader::kFirstFragmentHeaderSize);
|
maxPayloadLength - headerLength - Lowpan::FragmentHeader::kFirstFragmentHeaderSize);
|
||||||
uint8_t hcLength;
|
uint8_t hcLength;
|
||||||
Mac::Address meshSource, meshDest;
|
Mac::Address meshSource, meshDest;
|
||||||
Error error;
|
|
||||||
|
|
||||||
OT_UNUSED_VARIABLE(error);
|
|
||||||
|
|
||||||
if (aAddMeshHeader)
|
if (aAddMeshHeader)
|
||||||
{
|
{
|
||||||
@@ -790,8 +787,7 @@ start:
|
|||||||
meshDest = aMacDest;
|
meshDest = aMacDest;
|
||||||
}
|
}
|
||||||
|
|
||||||
error = Get<Lowpan::Lowpan>().Compress(aMessage, meshSource, meshDest, buffer);
|
SuccessOrAssert(Get<Lowpan::Lowpan>().Compress(aMessage, meshSource, meshDest, buffer));
|
||||||
OT_ASSERT(error == kErrorNone);
|
|
||||||
|
|
||||||
hcLength = static_cast<uint8_t>(buffer.GetWritePointer() - payload);
|
hcLength = static_cast<uint8_t>(buffer.GetWritePointer() - payload);
|
||||||
headerLength += hcLength;
|
headerLength += hcLength;
|
||||||
|
|||||||
@@ -1307,9 +1307,7 @@ Error Mle::AppendAddressRegistration(Message &aMessage, AddressRegistrationMode
|
|||||||
|
|
||||||
if (Get<ThreadNetif>().HasUnicastAddress(domainUnicastAddress))
|
if (Get<ThreadNetif>().HasUnicastAddress(domainUnicastAddress))
|
||||||
{
|
{
|
||||||
error = Get<NetworkData::Leader>().GetContext(domainUnicastAddress, context);
|
SuccessOrAssert(Get<NetworkData::Leader>().GetContext(domainUnicastAddress, context));
|
||||||
|
|
||||||
OT_ASSERT(error == kErrorNone);
|
|
||||||
|
|
||||||
// Prioritize DUA, compressed entry
|
// Prioritize DUA, compressed entry
|
||||||
entry.SetContextId(context.mContextId);
|
entry.SetContextId(context.mContextId);
|
||||||
@@ -4611,9 +4609,7 @@ void Mle::DelayedResponseMetadata::ReadFrom(const Message &aMessage)
|
|||||||
|
|
||||||
void Mle::DelayedResponseMetadata::RemoveFrom(Message &aMessage) const
|
void Mle::DelayedResponseMetadata::RemoveFrom(Message &aMessage) const
|
||||||
{
|
{
|
||||||
Error error = aMessage.SetLength(aMessage.GetLength() - sizeof(*this));
|
SuccessOrAssert(aMessage.SetLength(aMessage.GetLength() - sizeof(*this)));
|
||||||
OT_ASSERT(error == kErrorNone);
|
|
||||||
OT_UNUSED_VARIABLE(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Mle
|
} // namespace Mle
|
||||||
|
|||||||
@@ -1219,8 +1219,7 @@ otError NcpBase::CommandHandler_RESET(uint8_t aHeader)
|
|||||||
|
|
||||||
if (mDecoder.GetRemainingLengthInStruct() > 0)
|
if (mDecoder.GetRemainingLengthInStruct() > 0)
|
||||||
{
|
{
|
||||||
error = mDecoder.ReadUint8(reset_type);
|
SuccessOrAssert(error = mDecoder.ReadUint8(reset_type));
|
||||||
OT_ASSERT(error == OT_ERROR_NONE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if OPENTHREAD_RADIO
|
#if OPENTHREAD_RADIO
|
||||||
@@ -1235,8 +1234,8 @@ otError NcpBase::CommandHandler_RESET(uint8_t aHeader)
|
|||||||
|
|
||||||
ResetCounters();
|
ResetCounters();
|
||||||
|
|
||||||
error = WriteLastStatusFrame(SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, SPINEL_STATUS_RESET_POWER_ON);
|
SuccessOrAssert(
|
||||||
OT_ASSERT(error == OT_ERROR_NONE);
|
error = WriteLastStatusFrame(SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, SPINEL_STATUS_RESET_POWER_ON));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -3771,8 +3771,7 @@ template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_SRP_CLIENT_HOST_NAME>
|
|||||||
SuccessOrExit(error = otSrpClientSetHostName(mInstance, name));
|
SuccessOrExit(error = otSrpClientSetHostName(mInstance, name));
|
||||||
|
|
||||||
strcpy(hostNameBuffer, name);
|
strcpy(hostNameBuffer, name);
|
||||||
error = otSrpClientSetHostName(mInstance, hostNameBuffer);
|
SuccessOrAssert(error = otSrpClientSetHostName(mInstance, hostNameBuffer));
|
||||||
OT_ASSERT(error == OT_ERROR_NONE);
|
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return error;
|
return error;
|
||||||
@@ -3820,8 +3819,7 @@ template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_SRP_CLIENT_HOST_ADDRE
|
|||||||
|
|
||||||
memcpy(hostAddressArray, addresses, sizeof(addresses));
|
memcpy(hostAddressArray, addresses, sizeof(addresses));
|
||||||
|
|
||||||
error = otSrpClientSetHostAddresses(mInstance, hostAddressArray, numAddresses);
|
SuccessOrAssert(error = otSrpClientSetHostAddresses(mInstance, hostAddressArray, numAddresses));
|
||||||
OT_ASSERT(error == OT_ERROR_NONE);
|
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return error;
|
return error;
|
||||||
|
|||||||
Reference in New Issue
Block a user