[dataset] implement ChannelMaskTlv::IsValid() (#5906)

This commit is contained in:
Jonathan Hui
2020-12-03 08:30:16 -08:00
committed by GitHub
parent 4f10f593a4
commit 761f8304c1
2 changed files with 25 additions and 1 deletions
+24
View File
@@ -78,6 +78,10 @@ bool Tlv::IsValid(const Tlv &aTlv)
rval = static_cast<const SecurityPolicyTlv &>(aTlv).IsValid();
break;
case Tlv::kChannelMask:
rval = static_cast<const ChannelMaskTlv &>(aTlv).IsValid();
break;
default:
break;
}
@@ -177,6 +181,26 @@ void ChannelTlv::SetChannel(uint16_t aChannel)
mChannel = HostSwap16(aChannel);
}
bool ChannelMaskBaseTlv::IsValid(void) const
{
const ChannelMaskEntryBase *entry = GetFirstEntry();
const uint8_t * end = reinterpret_cast<const uint8_t *>(GetNext());
bool ret = false;
VerifyOrExit(entry != nullptr);
while (reinterpret_cast<const uint8_t *>(entry) < end)
{
entry = entry->GetNext();
VerifyOrExit(reinterpret_cast<const uint8_t *>(entry) <= end);
}
ret = true;
exit:
return ret;
}
const ChannelMaskEntryBase *ChannelMaskBaseTlv::GetFirstEntry(void) const
{
const ChannelMaskEntryBase *entry = nullptr;
+1 -1
View File
@@ -1432,7 +1432,7 @@ public:
* @retval FALSE If the TLV does not appear to be well-formed.
*
*/
bool IsValid(void) const { return true; }
bool IsValid(void) const;
/**
* This method gets the first Channel Mask Entry in the Channel Mask TLV.