mirror of
https://github.com/espressif/openthread.git
synced 2026-08-11 05:07:47 +00:00
[thread] simplify ThreadNetworkDataTlv definition (#12770)
This commit simplifies the definition of `ThreadNetworkDataTlv`. Previously, `ThreadNetworkDataTlv` included a 255-byte array to store the Network Data TLVs. The code now relies on standard TLV parsing methods like `Tlv::FindTlvValueOffsetRange()` and `Message::ReadBytes()` to access the Network Data directly from the message payload.
This commit is contained in:
@@ -221,8 +221,8 @@ void Leader::RemoveBorderRouter(uint16_t aRloc16, MatchMode aMatchMode)
|
||||
|
||||
template <> void Leader::HandleTmf<kUriServerData>(Coap::Msg &aMsg)
|
||||
{
|
||||
ThreadNetworkDataTlv networkDataTlv;
|
||||
uint16_t rloc16;
|
||||
uint16_t rloc16;
|
||||
OffsetRange offsetRange;
|
||||
|
||||
VerifyOrExit(Get<Mle::Mle>().IsLeader() && !mWaitingForNetDataSync);
|
||||
|
||||
@@ -241,12 +241,16 @@ template <> void Leader::HandleTmf<kUriServerData>(Coap::Msg &aMsg)
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
if (Tlv::FindTlv(aMsg.mMessage, networkDataTlv) == kErrorNone)
|
||||
if (Tlv::FindTlvValueOffsetRange(aMsg.mMessage, ThreadNetworkDataTlv::kType, offsetRange) == kErrorNone)
|
||||
{
|
||||
VerifyOrExit(networkDataTlv.IsValid());
|
||||
uint8_t bytes[kMaxSize];
|
||||
|
||||
VerifyOrExit(offsetRange.GetLength() <= kMaxSize);
|
||||
|
||||
aMsg.mMessage.ReadBytes(offsetRange, bytes);
|
||||
|
||||
{
|
||||
NetworkData networkData(GetInstance(), networkDataTlv.GetTlvs(), networkDataTlv.GetLength());
|
||||
NetworkData networkData(GetInstance(), bytes, static_cast<uint8_t>(offsetRange.GetLength()));
|
||||
|
||||
RegisterNetworkData(aMsg.mMessageInfo.GetPeerAddr().GetIid().GetLocator(), networkData);
|
||||
}
|
||||
|
||||
@@ -191,8 +191,8 @@ Error Notifier::SendServerDataNotification(uint16_t aOldRloc16, const NetworkDat
|
||||
|
||||
if (aNetworkData != nullptr)
|
||||
{
|
||||
SuccessOrExit(error = Tlv::AppendTlv(*message, ThreadTlv::kThreadNetworkData, aNetworkData->GetBytes(),
|
||||
aNetworkData->GetLength()));
|
||||
SuccessOrExit(
|
||||
error = Tlv::Append<ThreadNetworkDataTlv>(*message, aNetworkData->GetBytes(), aNetworkData->GetLength()));
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BORDER_ROUTER_SIGNAL_NETWORK_DATA_FULL
|
||||
Get<Leader>().CheckForNetDataGettingFull(*aNetworkData, aOldRloc16);
|
||||
|
||||
@@ -202,40 +202,9 @@ private:
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
/**
|
||||
* Implements Thread Network Data TLV generation and parsing.
|
||||
* Defines Thread Network Data TLV constants and types.
|
||||
*/
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
class ThreadNetworkDataTlv : public ThreadTlv, public TlvInfo<ThreadTlv::kThreadNetworkData>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Initializes the TLV.
|
||||
*/
|
||||
void Init(void)
|
||||
{
|
||||
SetType(kThreadNetworkData);
|
||||
SetLength(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides same method of the base class
|
||||
*
|
||||
* @retval TRUE the TLV appears to be well-formed.
|
||||
*/
|
||||
bool IsValid(void) const { return true; }
|
||||
|
||||
/**
|
||||
* Returns a pointer to the Network Data TLVs.
|
||||
*
|
||||
* @returns A pointer to the Network Data TLVs.
|
||||
*/
|
||||
uint8_t *GetTlvs(void) { return mTlvs; }
|
||||
|
||||
private:
|
||||
static constexpr uint8_t kMaxSize = 255;
|
||||
|
||||
uint8_t mTlvs[kMaxSize];
|
||||
} OT_TOOL_PACKED_END;
|
||||
typedef TlvInfo<ThreadTlv::kThreadNetworkData> ThreadNetworkDataTlv;
|
||||
|
||||
#if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2
|
||||
|
||||
|
||||
Reference in New Issue
Block a user