mirror of
https://github.com/espressif/openthread.git
synced 2026-09-01 23:09:53 +00:00
[dataset] implement ChannelMaskTlv::IsValid() (#5906)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user