mirror of
https://github.com/espressif/openthread.git
synced 2026-08-26 04:09:52 +00:00
[tlvs] rename helper methods to FindTlv (FindUint8Tlv, etc) (#5008)
This commit renames the helper `static` methods in `Tlv` class. It harmonizes the naming model to use `FindTlv()` for different flavors of methods that search within a given `Message` (or buffer) to find a TLV with a given type. This commit also removes the re-definition of same `static` methods in sub-classes of `Tlv` class. This helps simplify the use of such methods and avoids the shadowing of some flavors of methods due to their re-definition in the sub-class (the sub-class re-definition allows a more specific TLV `Type` enumeration parameter to be used, however the base case version will continue to work due to implicit conversion of `enum` value to an integer).
This commit is contained in:
committed by
Jonathan Hui
parent
578b29fa60
commit
8b387c5fb4
+11
-11
@@ -64,7 +64,7 @@ otError Tlv::AppendTo(Message &aMessage) const
|
||||
return aMessage.Append(this, static_cast<uint16_t>(size));
|
||||
}
|
||||
|
||||
otError Tlv::Get(const Message &aMessage, uint8_t aType, uint16_t aMaxSize, Tlv &aTlv)
|
||||
otError Tlv::FindTlv(const Message &aMessage, uint8_t aType, uint16_t aMaxSize, Tlv &aTlv)
|
||||
{
|
||||
otError error;
|
||||
uint16_t offset;
|
||||
@@ -83,12 +83,12 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Tlv::GetOffset(const Message &aMessage, uint8_t aType, uint16_t &aOffset)
|
||||
otError Tlv::FindTlvOffset(const Message &aMessage, uint8_t aType, uint16_t &aOffset)
|
||||
{
|
||||
return Find(aMessage, aType, &aOffset, NULL, NULL);
|
||||
}
|
||||
|
||||
otError Tlv::GetValueOffset(const Message &aMessage, uint8_t aType, uint16_t &aValueOffset, uint16_t &aLength)
|
||||
otError Tlv::FindTlvValueOffset(const Message &aMessage, uint8_t aType, uint16_t &aValueOffset, uint16_t &aLength)
|
||||
{
|
||||
otError error;
|
||||
uint16_t offset;
|
||||
@@ -174,12 +174,12 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Tlv::ReadUint8Tlv(const Message &aMessage, uint8_t aType, uint8_t &aValue)
|
||||
otError Tlv::FindUint8Tlv(const Message &aMessage, uint8_t aType, uint8_t &aValue)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
TlvUint8 tlv8;
|
||||
|
||||
SuccessOrExit(error = Get(aMessage, aType, sizeof(tlv8), tlv8));
|
||||
SuccessOrExit(error = FindTlv(aMessage, aType, sizeof(tlv8), tlv8));
|
||||
VerifyOrExit(tlv8.IsValid(), error = OT_ERROR_PARSE);
|
||||
aValue = tlv8.GetUint8Value();
|
||||
|
||||
@@ -187,12 +187,12 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Tlv::ReadUint16Tlv(const Message &aMessage, uint8_t aType, uint16_t &aValue)
|
||||
otError Tlv::FindUint16Tlv(const Message &aMessage, uint8_t aType, uint16_t &aValue)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
TlvUint16 tlv16;
|
||||
|
||||
SuccessOrExit(error = Get(aMessage, aType, sizeof(tlv16), tlv16));
|
||||
SuccessOrExit(error = FindTlv(aMessage, aType, sizeof(tlv16), tlv16));
|
||||
VerifyOrExit(tlv16.IsValid(), error = OT_ERROR_PARSE);
|
||||
aValue = tlv16.GetUint16Value();
|
||||
|
||||
@@ -200,12 +200,12 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Tlv::ReadUint32Tlv(const Message &aMessage, uint8_t aType, uint32_t &aValue)
|
||||
otError Tlv::FindUint32Tlv(const Message &aMessage, uint8_t aType, uint32_t &aValue)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
TlvUint32 tlv32;
|
||||
|
||||
SuccessOrExit(error = Get(aMessage, aType, sizeof(tlv32), tlv32));
|
||||
SuccessOrExit(error = FindTlv(aMessage, aType, sizeof(tlv32), tlv32));
|
||||
VerifyOrExit(tlv32.IsValid(), error = OT_ERROR_PARSE);
|
||||
aValue = tlv32.GetUint32Value();
|
||||
|
||||
@@ -213,13 +213,13 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Tlv::ReadTlv(const Message &aMessage, uint8_t aType, void *aValue, uint8_t aLength)
|
||||
otError Tlv::FindTlv(const Message &aMessage, uint8_t aType, void *aValue, uint8_t aLength)
|
||||
{
|
||||
otError error;
|
||||
uint16_t offset;
|
||||
uint16_t length;
|
||||
|
||||
SuccessOrExit(error = GetValueOffset(aMessage, aType, offset, length));
|
||||
SuccessOrExit(error = FindTlvValueOffset(aMessage, aType, offset, length));
|
||||
VerifyOrExit(length >= aLength, error = OT_ERROR_PARSE);
|
||||
aMessage.Read(offset, aLength, static_cast<uint8_t *>(aValue));
|
||||
|
||||
|
||||
@@ -191,7 +191,7 @@ public:
|
||||
* @retval OT_ERROR_NOT_FOUND Could not find the TLV with Type @p aType.
|
||||
*
|
||||
*/
|
||||
static otError Get(const Message &aMessage, uint8_t aType, uint16_t aMaxSize, Tlv &aTlv);
|
||||
static otError FindTlv(const Message &aMessage, uint8_t aType, uint16_t aMaxSize, Tlv &aTlv);
|
||||
|
||||
/**
|
||||
* This static method obtains the offset of a TLV within @p aMessage.
|
||||
@@ -206,7 +206,7 @@ public:
|
||||
* @retval OT_ERROR_NOT_FOUND Could not find the TLV with Type @p aType.
|
||||
*
|
||||
*/
|
||||
static otError GetOffset(const Message &aMessage, uint8_t aType, uint16_t &aOffset);
|
||||
static otError FindTlvOffset(const Message &aMessage, uint8_t aType, uint16_t &aOffset);
|
||||
|
||||
/**
|
||||
* This static method finds the offset and length of a given TLV type.
|
||||
@@ -222,7 +222,7 @@ public:
|
||||
* @retval OT_ERROR_NOT_FOUND Could not find the TLV with Type @p aType.
|
||||
*
|
||||
*/
|
||||
static otError GetValueOffset(const Message &aMessage, uint8_t aType, uint16_t &aOffset, uint16_t &aLength);
|
||||
static otError FindTlvValueOffset(const Message &aMessage, uint8_t aType, uint16_t &aOffset, uint16_t &aLength);
|
||||
|
||||
/**
|
||||
* This static method searches for a TLV with a given type in a message and reads its value as an `uint8_t`.
|
||||
@@ -236,7 +236,7 @@ public:
|
||||
* @retval OT_ERROR_PARSE TLV was found but it was not well-formed and could not be parsed.
|
||||
*
|
||||
*/
|
||||
static otError ReadUint8Tlv(const Message &aMessage, uint8_t aType, uint8_t &aValue);
|
||||
static otError FindUint8Tlv(const Message &aMessage, uint8_t aType, uint8_t &aValue);
|
||||
|
||||
/**
|
||||
* This static method searches for a TLV with a given type in a message and reads its value as an `uint16_t`.
|
||||
@@ -250,7 +250,7 @@ public:
|
||||
* @retval OT_ERROR_PARSE TLV was found but it was not well-formed and could not be parsed.
|
||||
*
|
||||
*/
|
||||
static otError ReadUint16Tlv(const Message &aMessage, uint8_t aType, uint16_t &aValue);
|
||||
static otError FindUint16Tlv(const Message &aMessage, uint8_t aType, uint16_t &aValue);
|
||||
|
||||
/**
|
||||
* This static method searches for a TLV with a given type in a message and reads its value as an `uint32_t`.
|
||||
@@ -264,7 +264,7 @@ public:
|
||||
* @retval OT_ERROR_PARSE TLV was found but it was not well-formed and could not be parsed.
|
||||
*
|
||||
*/
|
||||
static otError ReadUint32Tlv(const Message &aMessage, uint8_t aType, uint32_t &aValue);
|
||||
static otError FindUint32Tlv(const Message &aMessage, uint8_t aType, uint32_t &aValue);
|
||||
|
||||
/**
|
||||
* This static method searches for a TLV with a given type in a message, ensures its length is same or larger than
|
||||
@@ -273,7 +273,7 @@ public:
|
||||
* If the TLV length is smaller than the minimum length @p aLength, the TLV is considered invalid. In this case,
|
||||
* this method returns `OT_ERROR_PARSE` and the @p aValue buffer is not updated.
|
||||
*
|
||||
* If the TLV is length is larger than @p aLength, the TLV is considered valid, but only the @aLength first bytes
|
||||
* If the TLV length is larger than @p aLength, the TLV is considered valid, but only the first @p aLength bytes
|
||||
* of the value are read and copied into the @p aValue buffer.
|
||||
*
|
||||
* @param[in] aMessage A reference to the message.
|
||||
@@ -281,12 +281,12 @@ public:
|
||||
* @param[out] aValue A buffer to output the value (must contain at least @p aLength bytes).
|
||||
* @param[in] aLength The expected (minimum) length of the TLV value.
|
||||
*
|
||||
* @retval OT_ERROR_NONE The TLV was found and read successfully. @p @aValue is updated.
|
||||
* @retval OT_ERROR_NONE The TLV was found and read successfully. @p aValue is updated.
|
||||
* @retval OT_ERROR_NOT_FOUND Could not find the TLV with Type @p aType.
|
||||
* @retval OT_ERROR_PARSE TLV was found but it was not well-formed and could not be parsed.
|
||||
*
|
||||
*/
|
||||
static otError ReadTlv(const Message &aMessage, uint8_t aType, void *aValue, uint8_t aLength);
|
||||
static otError FindTlv(const Message &aMessage, uint8_t aType, void *aValue, uint8_t aLength);
|
||||
|
||||
/**
|
||||
* This static method appends a simple TLV with a given type and an `uint8_t` value to a message.
|
||||
|
||||
@@ -244,13 +244,13 @@ void BorderAgent::HandleCoapResponse(void * aContext,
|
||||
{
|
||||
uint8_t state;
|
||||
|
||||
SuccessOrExit(error = Tlv::ReadUint8Tlv(*response, Tlv::kState, state));
|
||||
SuccessOrExit(error = Tlv::FindUint8Tlv(*response, Tlv::kState, state));
|
||||
|
||||
if (state == StateTlv::kAccept)
|
||||
{
|
||||
uint16_t sessionId;
|
||||
|
||||
SuccessOrExit(error = Tlv::ReadUint16Tlv(*response, Tlv::kCommissionerSessionId, sessionId));
|
||||
SuccessOrExit(error = Tlv::FindUint16Tlv(*response, Tlv::kCommissionerSessionId, sessionId));
|
||||
|
||||
IgnoreError(instance.Get<Mle::MleRouter>().GetCommissionerAloc(borderAgent.mCommissionerAloc.GetAddress(),
|
||||
sessionId));
|
||||
@@ -397,7 +397,7 @@ void BorderAgent::HandleProxyTransmit(const Coap::Message &aMessage)
|
||||
{
|
||||
UdpEncapsulationTlv tlv;
|
||||
|
||||
SuccessOrExit(error = Tlv::GetOffset(aMessage, Tlv::kUdpEncapsulation, offset));
|
||||
SuccessOrExit(error = Tlv::FindTlvOffset(aMessage, Tlv::kUdpEncapsulation, offset));
|
||||
VerifyOrExit(aMessage.Read(offset, sizeof(tlv), &tlv) == sizeof(tlv), error = OT_ERROR_PARSE);
|
||||
|
||||
VerifyOrExit((message = Get<Ip6::Udp>().NewMessage(0)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
@@ -410,7 +410,7 @@ void BorderAgent::HandleProxyTransmit(const Coap::Message &aMessage)
|
||||
}
|
||||
|
||||
SuccessOrExit(
|
||||
error = Tlv::ReadTlv(aMessage, Tlv::kIPv6Address, messageInfo.GetPeerAddr().mFields.m8, sizeof(Ip6::Address)));
|
||||
error = Tlv::FindTlv(aMessage, Tlv::kIPv6Address, messageInfo.GetPeerAddr().mFields.m8, sizeof(Ip6::Address)));
|
||||
|
||||
SuccessOrExit(error = Get<Ip6::Udp>().SendDatagram(*message, messageInfo, Ip6::kProtoUdp));
|
||||
otLogInfoMeshCoP("Proxy transmit sent");
|
||||
@@ -547,7 +547,7 @@ void BorderAgent::HandleRelayTransmit(const Coap::Message &aMessage)
|
||||
|
||||
VerifyOrExit(aMessage.IsNonConfirmable() && aMessage.GetCode() == OT_COAP_CODE_POST, OT_NOOP);
|
||||
|
||||
SuccessOrExit(error = Tlv::ReadUint16Tlv(aMessage, Tlv::kJoinerRouterLocator, joinerRouterRloc));
|
||||
SuccessOrExit(error = Tlv::FindUint16Tlv(aMessage, Tlv::kJoinerRouterLocator, joinerRouterRloc));
|
||||
|
||||
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::Coap>())) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
|
||||
@@ -739,10 +739,10 @@ void Commissioner::HandleLeaderPetitionResponse(Coap::Message * aMessage
|
||||
|
||||
otLogInfoMeshCoP("received Leader Petition response");
|
||||
|
||||
SuccessOrExit(Tlv::ReadUint8Tlv(*aMessage, Tlv::kState, state));
|
||||
SuccessOrExit(Tlv::FindUint8Tlv(*aMessage, Tlv::kState, state));
|
||||
VerifyOrExit(state == StateTlv::kAccept, IgnoreError(Stop(/* aResign */ false)));
|
||||
|
||||
SuccessOrExit(Tlv::ReadUint16Tlv(*aMessage, Tlv::kCommissionerSessionId, mSessionId));
|
||||
SuccessOrExit(Tlv::FindUint16Tlv(*aMessage, Tlv::kCommissionerSessionId, mSessionId));
|
||||
|
||||
// reject this session by sending KeepAlive reject if commissioner is in disabled state
|
||||
// this could happen if commissioner is stopped by API during petitioning
|
||||
@@ -842,7 +842,7 @@ void Commissioner::HandleLeaderKeepAliveResponse(Coap::Message * aMessag
|
||||
|
||||
otLogInfoMeshCoP("received Leader keep-alive response");
|
||||
|
||||
SuccessOrExit(Tlv::ReadUint8Tlv(*aMessage, Tlv::kState, state));
|
||||
SuccessOrExit(Tlv::FindUint8Tlv(*aMessage, Tlv::kState, state));
|
||||
VerifyOrExit(state == StateTlv::kAccept, IgnoreError(Stop(/* aResign */ false)));
|
||||
|
||||
mTimer.Start(Time::SecToMsec(kKeepAliveTimeout) / 2);
|
||||
@@ -876,11 +876,11 @@ void Commissioner::HandleRelayReceive(Coap::Message &aMessage, const Ip6::Messag
|
||||
|
||||
VerifyOrExit(aMessage.IsNonConfirmable() && aMessage.GetCode() == OT_COAP_CODE_POST, OT_NOOP);
|
||||
|
||||
SuccessOrExit(error = Tlv::ReadUint16Tlv(aMessage, Tlv::kJoinerUdpPort, joinerPort));
|
||||
SuccessOrExit(error = Tlv::ReadTlv(aMessage, Tlv::kJoinerIid, joinerIid, sizeof(joinerIid)));
|
||||
SuccessOrExit(error = Tlv::ReadUint16Tlv(aMessage, Tlv::kJoinerRouterLocator, joinerRloc));
|
||||
SuccessOrExit(error = Tlv::FindUint16Tlv(aMessage, Tlv::kJoinerUdpPort, joinerPort));
|
||||
SuccessOrExit(error = Tlv::FindTlv(aMessage, Tlv::kJoinerIid, joinerIid, sizeof(joinerIid)));
|
||||
SuccessOrExit(error = Tlv::FindUint16Tlv(aMessage, Tlv::kJoinerRouterLocator, joinerRloc));
|
||||
|
||||
SuccessOrExit(error = Tlv::GetValueOffset(aMessage, Tlv::kJoinerDtlsEncapsulation, offset, length));
|
||||
SuccessOrExit(error = Tlv::FindTlvValueOffset(aMessage, Tlv::kJoinerDtlsEncapsulation, offset, length));
|
||||
VerifyOrExit(length <= aMessage.GetLength() - offset, error = OT_ERROR_PARSE);
|
||||
|
||||
if (!Get<Coap::CoapSecure>().IsConnectionActive())
|
||||
@@ -976,7 +976,7 @@ void Commissioner::HandleJoinerFinalize(Coap::Message &aMessage, const Ip6::Mess
|
||||
|
||||
otLogInfoMeshCoP("received joiner finalize");
|
||||
|
||||
if (Tlv::GetTlv(aMessage, Tlv::kProvisioningUrl, sizeof(provisioningUrl), provisioningUrl) == OT_ERROR_NONE)
|
||||
if (Tlv::FindTlv(aMessage, Tlv::kProvisioningUrl, sizeof(provisioningUrl), provisioningUrl) == OT_ERROR_NONE)
|
||||
{
|
||||
uint8_t len = static_cast<uint8_t>(StringLength(mProvisioningUrl, sizeof(mProvisioningUrl)));
|
||||
|
||||
|
||||
@@ -107,14 +107,14 @@ otError DatasetManager::HandleSet(Coap::Message &aMessage, const Ip6::MessageInf
|
||||
|
||||
type = (strcmp(mUriSet, OT_URI_PATH_ACTIVE_SET) == 0 ? Tlv::kActiveTimestamp : Tlv::kPendingTimestamp);
|
||||
|
||||
if (Tlv::GetTlv(aMessage, Tlv::kActiveTimestamp, sizeof(activeTimestamp), activeTimestamp) != OT_ERROR_NONE)
|
||||
if (Tlv::FindTlv(aMessage, Tlv::kActiveTimestamp, sizeof(activeTimestamp), activeTimestamp) != OT_ERROR_NONE)
|
||||
{
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
VerifyOrExit(activeTimestamp.IsValid(), OT_NOOP);
|
||||
|
||||
if (Tlv::GetTlv(aMessage, Tlv::kPendingTimestamp, sizeof(pendingTimestamp), pendingTimestamp) == OT_ERROR_NONE)
|
||||
if (Tlv::FindTlv(aMessage, Tlv::kPendingTimestamp, sizeof(pendingTimestamp), pendingTimestamp) == OT_ERROR_NONE)
|
||||
{
|
||||
VerifyOrExit(pendingTimestamp.IsValid(), OT_NOOP);
|
||||
}
|
||||
@@ -126,7 +126,7 @@ otError DatasetManager::HandleSet(Coap::Message &aMessage, const Ip6::MessageInf
|
||||
VerifyOrExit(mLocal.Compare(timestamp) > 0, OT_NOOP);
|
||||
|
||||
// check channel
|
||||
if (Tlv::GetTlv(aMessage, Tlv::kChannel, sizeof(channel), channel) == OT_ERROR_NONE)
|
||||
if (Tlv::FindTlv(aMessage, Tlv::kChannel, sizeof(channel), channel) == OT_ERROR_NONE)
|
||||
{
|
||||
VerifyOrExit(channel.IsValid(), OT_NOOP);
|
||||
|
||||
@@ -137,20 +137,20 @@ otError DatasetManager::HandleSet(Coap::Message &aMessage, const Ip6::MessageInf
|
||||
}
|
||||
|
||||
// check PAN ID
|
||||
if (Tlv::ReadUint16Tlv(aMessage, Tlv::kPanId, panId) == OT_ERROR_NONE && panId != Get<Mac::Mac>().GetPanId())
|
||||
if (Tlv::FindUint16Tlv(aMessage, Tlv::kPanId, panId) == OT_ERROR_NONE && panId != Get<Mac::Mac>().GetPanId())
|
||||
{
|
||||
doesAffectConnectivity = true;
|
||||
}
|
||||
|
||||
// check mesh local prefix
|
||||
if (Tlv::ReadTlv(aMessage, Tlv::kMeshLocalPrefix, &meshLocalPrefix, sizeof(meshLocalPrefix)) == OT_ERROR_NONE &&
|
||||
if (Tlv::FindTlv(aMessage, Tlv::kMeshLocalPrefix, &meshLocalPrefix, sizeof(meshLocalPrefix)) == OT_ERROR_NONE &&
|
||||
meshLocalPrefix != Get<Mle::MleRouter>().GetMeshLocalPrefix())
|
||||
{
|
||||
doesAffectConnectivity = true;
|
||||
}
|
||||
|
||||
// check network master key
|
||||
if (Tlv::ReadTlv(aMessage, Tlv::kNetworkMasterKey, &masterKey, sizeof(masterKey)) == OT_ERROR_NONE)
|
||||
if (Tlv::FindTlv(aMessage, Tlv::kNetworkMasterKey, &masterKey, sizeof(masterKey)) == OT_ERROR_NONE)
|
||||
{
|
||||
hasMasterKey = true;
|
||||
|
||||
@@ -171,7 +171,7 @@ otError DatasetManager::HandleSet(Coap::Message &aMessage, const Ip6::MessageInf
|
||||
}
|
||||
|
||||
// check commissioner session id
|
||||
if (Tlv::ReadUint16Tlv(aMessage, Tlv::kCommissionerSessionId, sessionId) == OT_ERROR_NONE)
|
||||
if (Tlv::FindUint16Tlv(aMessage, Tlv::kCommissionerSessionId, sessionId) == OT_ERROR_NONE)
|
||||
{
|
||||
const CommissionerSessionIdTlv *localId;
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ void EnergyScanClient::HandleReport(Coap::Message &aMessage, const Ip6::MessageI
|
||||
|
||||
VerifyOrExit((mask = MeshCoP::ChannelMaskTlv::GetChannelMask(aMessage)) != 0, OT_NOOP);
|
||||
|
||||
SuccessOrExit(MeshCoP::Tlv::GetTlv(aMessage, MeshCoP::Tlv::kEnergyList, sizeof(energyList), energyList.tlv));
|
||||
SuccessOrExit(MeshCoP::Tlv::FindTlv(aMessage, MeshCoP::Tlv::kEnergyList, sizeof(energyList), energyList.tlv));
|
||||
VerifyOrExit(energyList.tlv.IsValid(), OT_NOOP);
|
||||
|
||||
if (mCallback != NULL)
|
||||
|
||||
@@ -529,7 +529,7 @@ void Joiner::HandleJoinerFinalizeResponse(Coap::Message & aMessage,
|
||||
aMessage.GetCode() == OT_COAP_CODE_CHANGED,
|
||||
OT_NOOP);
|
||||
|
||||
SuccessOrExit(Tlv::ReadUint8Tlv(aMessage, Tlv::kState, state));
|
||||
SuccessOrExit(Tlv::FindUint8Tlv(aMessage, Tlv::kState, state));
|
||||
|
||||
SetState(OT_JOINER_STATE_ENTRUST);
|
||||
mTimer.Start(kReponseTimeout);
|
||||
@@ -565,7 +565,7 @@ void Joiner::HandleJoinerEntrust(Coap::Message &aMessage, const Ip6::MessageInfo
|
||||
|
||||
memset(&dataset, 0, sizeof(dataset));
|
||||
|
||||
SuccessOrExit(error = Tlv::ReadTlv(aMessage, Tlv::kNetworkMasterKey, &dataset.mMasterKey, sizeof(MasterKey)));
|
||||
SuccessOrExit(error = Tlv::FindTlv(aMessage, Tlv::kNetworkMasterKey, &dataset.mMasterKey, sizeof(MasterKey)));
|
||||
dataset.mComponents.mIsMasterKeyPresent = true;
|
||||
|
||||
dataset.mChannel = Get<Mac::Mac>().GetPanChannel();
|
||||
|
||||
@@ -203,10 +203,10 @@ void JoinerRouter::HandleRelayTransmit(Coap::Message &aMessage, const Ip6::Messa
|
||||
|
||||
otLogInfoMeshCoP("Received relay transmit");
|
||||
|
||||
SuccessOrExit(error = Tlv::ReadUint16Tlv(aMessage, Tlv::kJoinerUdpPort, joinerPort));
|
||||
SuccessOrExit(error = Tlv::ReadTlv(aMessage, Tlv::kJoinerIid, joinerIid, sizeof(joinerIid)));
|
||||
SuccessOrExit(error = Tlv::FindUint16Tlv(aMessage, Tlv::kJoinerUdpPort, joinerPort));
|
||||
SuccessOrExit(error = Tlv::FindTlv(aMessage, Tlv::kJoinerIid, joinerIid, sizeof(joinerIid)));
|
||||
|
||||
SuccessOrExit(error = Tlv::GetValueOffset(aMessage, Tlv::kJoinerDtlsEncapsulation, offset, length));
|
||||
SuccessOrExit(error = Tlv::FindTlvValueOffset(aMessage, Tlv::kJoinerDtlsEncapsulation, offset, length));
|
||||
|
||||
VerifyOrExit((message = mSocket.NewMessage(0, settings)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
@@ -218,7 +218,7 @@ void JoinerRouter::HandleRelayTransmit(Coap::Message &aMessage, const Ip6::Messa
|
||||
|
||||
SuccessOrExit(error = mSocket.SendTo(*message, messageInfo));
|
||||
|
||||
if (Tlv::ReadTlv(aMessage, Tlv::kJoinerRouterKek, &kek, sizeof(kek)) == OT_ERROR_NONE)
|
||||
if (Tlv::FindTlv(aMessage, Tlv::kJoinerRouterKek, &kek, sizeof(kek)) == OT_ERROR_NONE)
|
||||
{
|
||||
otLogInfoMeshCoP("Received kek");
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ void Leader::HandlePetition(Coap::Message &aMessage, const Ip6::MessageInfo &aMe
|
||||
otLogInfoMeshCoP("received petition");
|
||||
|
||||
VerifyOrExit(Get<Mle::MleRouter>().IsRoutingLocator(aMessageInfo.GetPeerAddr()), OT_NOOP);
|
||||
SuccessOrExit(Tlv::GetTlv(aMessage, Tlv::kCommissionerId, sizeof(commissionerId), commissionerId));
|
||||
SuccessOrExit(Tlv::FindTlv(aMessage, Tlv::kCommissionerId, sizeof(commissionerId), commissionerId));
|
||||
|
||||
if (mTimer.IsRunning())
|
||||
{
|
||||
@@ -176,9 +176,9 @@ void Leader::HandleKeepAlive(Coap::Message &aMessage, const Ip6::MessageInfo &aM
|
||||
|
||||
otLogInfoMeshCoP("received keep alive");
|
||||
|
||||
SuccessOrExit(Tlv::ReadUint8Tlv(aMessage, Tlv::kState, state));
|
||||
SuccessOrExit(Tlv::FindUint8Tlv(aMessage, Tlv::kState, state));
|
||||
|
||||
SuccessOrExit(Tlv::ReadUint16Tlv(aMessage, Tlv::kCommissionerSessionId, sessionId));
|
||||
SuccessOrExit(Tlv::FindUint16Tlv(aMessage, Tlv::kCommissionerSessionId, sessionId));
|
||||
|
||||
borderAgentLocator = static_cast<BorderAgentLocatorTlv *>(
|
||||
Get<NetworkData::Leader>().GetCommissioningDataSubTlv(Tlv::kBorderAgentLocator));
|
||||
|
||||
@@ -285,7 +285,7 @@ uint32_t ChannelMaskTlv::GetChannelMask(const Message &aMessage)
|
||||
uint16_t offset;
|
||||
uint16_t end;
|
||||
|
||||
SuccessOrExit(GetValueOffset(aMessage, kChannelMask, offset, end));
|
||||
SuccessOrExit(FindTlvValueOffset(aMessage, kChannelMask, offset, end));
|
||||
end += offset;
|
||||
|
||||
while (offset + sizeof(ChannelMaskEntryBase) <= end)
|
||||
|
||||
@@ -158,26 +158,34 @@ public:
|
||||
* @retval OT_ERROR_NOT_FOUND Could not find the TLV with Type @p aType.
|
||||
*
|
||||
*/
|
||||
static otError GetTlv(const Message &aMessage, Type aType, uint16_t aMaxLength, Tlv &aTlv)
|
||||
static otError FindTlv(const Message &aMessage, Type aType, uint16_t aMaxLength, Tlv &aTlv)
|
||||
{
|
||||
return ot::Tlv::Get(aMessage, static_cast<uint8_t>(aType), aMaxLength, aTlv);
|
||||
return ot::Tlv::FindTlv(aMessage, static_cast<uint8_t>(aType), aMaxLength, aTlv);
|
||||
}
|
||||
|
||||
/**
|
||||
* This static method finds the offset and length of a given TLV type.
|
||||
* This static method searches for a TLV with a given type in a message, ensures its length is same or larger than
|
||||
* an expected minimum value, and then reads its value into a given buffer.
|
||||
*
|
||||
* @param[in] aMessage A reference to the message.
|
||||
* @param[in] aType The Type value to search for.
|
||||
* @param[out] aOffset The offset where the value starts.
|
||||
* @param[out] aLength The length of the value.
|
||||
* If the TLV length is smaller than the minimum length @p aLength, the TLV is considered invalid. In this case,
|
||||
* this method returns `OT_ERROR_PARSE` and the @p aValue buffer is not updated.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully found the TLV.
|
||||
* If the TLV length is larger than @p aLength, the TLV is considered valid, but only the first @p aLength bytes
|
||||
* of the value are read and copied into the @p aValue buffer.
|
||||
*
|
||||
* @param[in] aMessage A reference to the message.
|
||||
* @param[in] aType The TLV type to search for.
|
||||
* @param[out] aValue A buffer to output the value (must contain at least @p aLength bytes).
|
||||
* @param[in] aLength The expected (minimum) length of the TLV value.
|
||||
*
|
||||
* @retval OT_ERROR_NONE The TLV was found and read successfully. @p aValue is updated.
|
||||
* @retval OT_ERROR_NOT_FOUND Could not find the TLV with Type @p aType.
|
||||
* @retval OT_ERROR_PARSE TLV was found but it was not well-formed and could not be parsed.
|
||||
*
|
||||
*/
|
||||
static otError GetValueOffset(const Message &aMessage, Type aType, uint16_t &aOffset, uint16_t &aLength)
|
||||
static otError FindTlv(const Message &aMessage, Type aType, void *aValue, uint8_t aLength)
|
||||
{
|
||||
return ot::Tlv::GetValueOffset(aMessage, static_cast<uint8_t>(aType), aOffset, aLength);
|
||||
return ot::Tlv::FindTlv(aMessage, aType, aValue, aLength);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -121,7 +121,7 @@ void PanIdQueryClient::HandleConflict(Coap::Message &aMessage, const Ip6::Messag
|
||||
|
||||
otLogInfoMeshCoP("received panid conflict");
|
||||
|
||||
SuccessOrExit(Tlv::ReadUint16Tlv(aMessage, MeshCoP::Tlv::kPanId, panId));
|
||||
SuccessOrExit(Tlv::FindUint16Tlv(aMessage, MeshCoP::Tlv::kPanId, panId));
|
||||
|
||||
VerifyOrExit((mask = MeshCoP::ChannelMaskTlv::GetChannelMask(aMessage)) != 0, OT_NOOP);
|
||||
|
||||
|
||||
@@ -603,11 +603,11 @@ void AddressResolver::HandleAddressNotification(Coap::Message &aMessage, const I
|
||||
|
||||
VerifyOrExit(aMessage.IsConfirmable() && aMessage.GetCode() == OT_COAP_CODE_POST, OT_NOOP);
|
||||
|
||||
SuccessOrExit(Tlv::ReadTlv(aMessage, ThreadTlv::kTarget, &target, sizeof(target)));
|
||||
SuccessOrExit(Tlv::ReadTlv(aMessage, ThreadTlv::kMeshLocalEid, meshLocalIid, sizeof(meshLocalIid)));
|
||||
SuccessOrExit(Tlv::ReadUint16Tlv(aMessage, ThreadTlv::kRloc16, rloc16));
|
||||
SuccessOrExit(Tlv::FindTlv(aMessage, ThreadTlv::kTarget, &target, sizeof(target)));
|
||||
SuccessOrExit(Tlv::FindTlv(aMessage, ThreadTlv::kMeshLocalEid, meshLocalIid, sizeof(meshLocalIid)));
|
||||
SuccessOrExit(Tlv::FindUint16Tlv(aMessage, ThreadTlv::kRloc16, rloc16));
|
||||
|
||||
switch (Tlv::ReadUint32Tlv(aMessage, ThreadTlv::kLastTransactionTime, lastTransactionTime))
|
||||
switch (Tlv::FindUint32Tlv(aMessage, ThreadTlv::kLastTransactionTime, lastTransactionTime))
|
||||
{
|
||||
case OT_ERROR_NONE:
|
||||
break;
|
||||
@@ -732,8 +732,8 @@ void AddressResolver::HandleAddressError(Coap::Message &aMessage, const Ip6::Mes
|
||||
}
|
||||
}
|
||||
|
||||
SuccessOrExit(error = Tlv::ReadTlv(aMessage, ThreadTlv::kTarget, &target, sizeof(target)));
|
||||
SuccessOrExit(error = Tlv::ReadTlv(aMessage, ThreadTlv::kMeshLocalEid, meshLocalIid, sizeof(meshLocalIid)));
|
||||
SuccessOrExit(error = Tlv::FindTlv(aMessage, ThreadTlv::kTarget, &target, sizeof(target)));
|
||||
SuccessOrExit(error = Tlv::FindTlv(aMessage, ThreadTlv::kMeshLocalEid, meshLocalIid, sizeof(meshLocalIid)));
|
||||
|
||||
for (const Ip6::NetifUnicastAddress *address = Get<ThreadNetif>().GetUnicastAddresses(); address;
|
||||
address = address->GetNext())
|
||||
@@ -795,7 +795,7 @@ void AddressResolver::HandleAddressQuery(Coap::Message &aMessage, const Ip6::Mes
|
||||
|
||||
VerifyOrExit(aMessage.IsNonConfirmable() && aMessage.GetCode() == OT_COAP_CODE_POST, OT_NOOP);
|
||||
|
||||
SuccessOrExit(Tlv::ReadTlv(aMessage, ThreadTlv::kTarget, &target, sizeof(target)));
|
||||
SuccessOrExit(Tlv::FindTlv(aMessage, ThreadTlv::kTarget, &target, sizeof(target)));
|
||||
|
||||
otLogInfoArp("Received address query from 0x%04x for target %s", aMessageInfo.GetPeerAddr().GetLocator(),
|
||||
target.ToString().AsCString());
|
||||
|
||||
@@ -75,8 +75,8 @@ void AnnounceBeginServer::HandleRequest(Coap::Message &aMessage, const Ip6::Mess
|
||||
VerifyOrExit(aMessage.GetCode() == OT_COAP_CODE_POST, OT_NOOP);
|
||||
VerifyOrExit((mask = MeshCoP::ChannelMaskTlv::GetChannelMask(aMessage)) != 0, OT_NOOP);
|
||||
|
||||
SuccessOrExit(Tlv::ReadUint8Tlv(aMessage, MeshCoP::Tlv::kCount, count));
|
||||
SuccessOrExit(Tlv::ReadUint16Tlv(aMessage, MeshCoP::Tlv::kPeriod, period));
|
||||
SuccessOrExit(Tlv::FindUint8Tlv(aMessage, MeshCoP::Tlv::kCount, count));
|
||||
SuccessOrExit(Tlv::FindUint16Tlv(aMessage, MeshCoP::Tlv::kPeriod, period));
|
||||
|
||||
SendAnnounce(mask, count, period);
|
||||
|
||||
|
||||
@@ -78,9 +78,9 @@ void EnergyScanServer::HandleRequest(Coap::Message &aMessage, const Ip6::Message
|
||||
|
||||
VerifyOrExit(aMessage.GetCode() == OT_COAP_CODE_POST, OT_NOOP);
|
||||
|
||||
SuccessOrExit(Tlv::ReadUint8Tlv(aMessage, MeshCoP::Tlv::kCount, count));
|
||||
SuccessOrExit(Tlv::ReadUint16Tlv(aMessage, MeshCoP::Tlv::kPeriod, period));
|
||||
SuccessOrExit(Tlv::ReadUint16Tlv(aMessage, MeshCoP::Tlv::kScanDuration, scanDuration));
|
||||
SuccessOrExit(Tlv::FindUint8Tlv(aMessage, MeshCoP::Tlv::kCount, count));
|
||||
SuccessOrExit(Tlv::FindUint16Tlv(aMessage, MeshCoP::Tlv::kPeriod, period));
|
||||
SuccessOrExit(Tlv::FindUint16Tlv(aMessage, MeshCoP::Tlv::kScanDuration, scanDuration));
|
||||
|
||||
VerifyOrExit((mask = MeshCoP::ChannelMaskTlv::GetChannelMask(aMessage)) != 0, OT_NOOP);
|
||||
|
||||
|
||||
+39
-39
@@ -1168,7 +1168,7 @@ otError Mle::ReadChallengeOrResponse(const Message &aMessage, uint8_t aTlvType,
|
||||
uint16_t offset;
|
||||
uint16_t length;
|
||||
|
||||
SuccessOrExit(error = Tlv::GetValueOffset(aMessage, aTlvType, offset, length));
|
||||
SuccessOrExit(error = Tlv::FindTlvValueOffset(aMessage, aTlvType, offset, length));
|
||||
VerifyOrExit(length >= kMinChallengeSize, error = OT_ERROR_PARSE);
|
||||
|
||||
if (length > kMaxChallengeSize)
|
||||
@@ -1226,7 +1226,7 @@ otError Mle::ReadLeaderData(const Message &aMessage, LeaderData &aLeaderData)
|
||||
otError error;
|
||||
LeaderDataTlv leaderDataTlv;
|
||||
|
||||
SuccessOrExit(error = Tlv::GetTlv(aMessage, Tlv::kLeaderData, sizeof(leaderDataTlv), leaderDataTlv));
|
||||
SuccessOrExit(error = Tlv::FindTlv(aMessage, Tlv::kLeaderData, sizeof(leaderDataTlv), leaderDataTlv));
|
||||
VerifyOrExit(leaderDataTlv.IsValid(), error = OT_ERROR_PARSE);
|
||||
leaderDataTlv.Get(aLeaderData);
|
||||
|
||||
@@ -1256,13 +1256,13 @@ otError Mle::AppendTlvRequest(Message &aMessage, const uint8_t *aTlvs, uint8_t a
|
||||
return Tlv::AppendTlv(aMessage, Tlv::kTlvRequest, aTlvs, aTlvsLength);
|
||||
}
|
||||
|
||||
otError Mle::ReadTlvRequest(const Message &aMessage, RequestedTlvs &aRequestedTlvs)
|
||||
otError Mle::FindTlvRequest(const Message &aMessage, RequestedTlvs &aRequestedTlvs)
|
||||
{
|
||||
otError error;
|
||||
uint16_t offset;
|
||||
uint16_t length;
|
||||
|
||||
SuccessOrExit(error = Tlv::GetValueOffset(aMessage, Tlv::kTlvRequest, offset, length));
|
||||
SuccessOrExit(error = Tlv::FindTlvValueOffset(aMessage, Tlv::kTlvRequest, offset, length));
|
||||
|
||||
if (length > sizeof(aRequestedTlvs.mTlvs))
|
||||
{
|
||||
@@ -2860,7 +2860,7 @@ void Mle::HandleAdvertisement(const Message &aMessage, const Ip6::MessageInfo &a
|
||||
uint16_t delay;
|
||||
|
||||
// Source Address
|
||||
SuccessOrExit(error = Tlv::ReadUint16Tlv(aMessage, Tlv::kSourceAddress, sourceAddress));
|
||||
SuccessOrExit(error = Tlv::FindUint16Tlv(aMessage, Tlv::kSourceAddress, sourceAddress));
|
||||
|
||||
LogMleMessage("Receive Advertisement", aMessageInfo.GetPeerAddr(), sourceAddress);
|
||||
|
||||
@@ -2904,7 +2904,7 @@ void Mle::HandleAdvertisement(const Message &aMessage, const Ip6::MessageInfo &a
|
||||
{
|
||||
RouteTlv route;
|
||||
|
||||
if ((Tlv::GetTlv(aMessage, Tlv::kRoute, sizeof(route), route) == OT_ERROR_NONE) && route.IsValid())
|
||||
if ((Tlv::FindTlv(aMessage, Tlv::kRoute, sizeof(route), route) == OT_ERROR_NONE) && route.IsValid())
|
||||
{
|
||||
// Overwrite Route Data
|
||||
IgnoreError(Get<MleRouter>().ProcessRouteTlv(route));
|
||||
@@ -3022,7 +3022,7 @@ otError Mle::HandleLeaderData(const Message &aMessage, const Ip6::MessageInfo &a
|
||||
}
|
||||
|
||||
// Active Timestamp
|
||||
if (Tlv::GetTlv(aMessage, Tlv::kActiveTimestamp, sizeof(activeTimestamp), activeTimestamp) == OT_ERROR_NONE)
|
||||
if (Tlv::FindTlv(aMessage, Tlv::kActiveTimestamp, sizeof(activeTimestamp), activeTimestamp) == OT_ERROR_NONE)
|
||||
{
|
||||
const MeshCoP::Timestamp *timestamp;
|
||||
|
||||
@@ -3032,7 +3032,7 @@ otError Mle::HandleLeaderData(const Message &aMessage, const Ip6::MessageInfo &a
|
||||
// if received timestamp does not match the local value and message does not contain the dataset,
|
||||
// send MLE Data Request
|
||||
if ((timestamp == NULL || timestamp->Compare(activeTimestamp) != 0) &&
|
||||
(Tlv::GetOffset(aMessage, Tlv::kActiveDataset, activeDatasetOffset) != OT_ERROR_NONE))
|
||||
(Tlv::FindTlvOffset(aMessage, Tlv::kActiveDataset, activeDatasetOffset) != OT_ERROR_NONE))
|
||||
{
|
||||
ExitNow(dataRequest = true);
|
||||
}
|
||||
@@ -3043,7 +3043,7 @@ otError Mle::HandleLeaderData(const Message &aMessage, const Ip6::MessageInfo &a
|
||||
}
|
||||
|
||||
// Pending Timestamp
|
||||
if (Tlv::GetTlv(aMessage, Tlv::kPendingTimestamp, sizeof(pendingTimestamp), pendingTimestamp) == OT_ERROR_NONE)
|
||||
if (Tlv::FindTlv(aMessage, Tlv::kPendingTimestamp, sizeof(pendingTimestamp), pendingTimestamp) == OT_ERROR_NONE)
|
||||
{
|
||||
const MeshCoP::Timestamp *timestamp;
|
||||
|
||||
@@ -3053,7 +3053,7 @@ otError Mle::HandleLeaderData(const Message &aMessage, const Ip6::MessageInfo &a
|
||||
// if received timestamp does not match the local value and message does not contain the dataset,
|
||||
// send MLE Data Request
|
||||
if ((timestamp == NULL || timestamp->Compare(pendingTimestamp) != 0) &&
|
||||
(Tlv::GetOffset(aMessage, Tlv::kPendingDataset, pendingDatasetOffset) != OT_ERROR_NONE))
|
||||
(Tlv::FindTlvOffset(aMessage, Tlv::kPendingDataset, pendingDatasetOffset) != OT_ERROR_NONE))
|
||||
{
|
||||
ExitNow(dataRequest = true);
|
||||
}
|
||||
@@ -3063,7 +3063,7 @@ otError Mle::HandleLeaderData(const Message &aMessage, const Ip6::MessageInfo &a
|
||||
pendingTimestamp.SetLength(0);
|
||||
}
|
||||
|
||||
if (Tlv::GetOffset(aMessage, Tlv::kNetworkData, networkDataOffset) == OT_ERROR_NONE)
|
||||
if (Tlv::FindTlvOffset(aMessage, Tlv::kNetworkData, networkDataOffset) == OT_ERROR_NONE)
|
||||
{
|
||||
error =
|
||||
Get<NetworkData::Leader>().SetNetworkData(leaderData.GetDataVersion(), leaderData.GetStableDataVersion(),
|
||||
@@ -3224,12 +3224,12 @@ void Mle::HandleParentResponse(const Message &aMessage, const Ip6::MessageInfo &
|
||||
#endif
|
||||
|
||||
// Source Address
|
||||
SuccessOrExit(error = Tlv::ReadUint16Tlv(aMessage, Tlv::kSourceAddress, sourceAddress));
|
||||
SuccessOrExit(error = Tlv::FindUint16Tlv(aMessage, Tlv::kSourceAddress, sourceAddress));
|
||||
|
||||
LogMleMessage("Receive Parent Response", aMessageInfo.GetPeerAddr(), sourceAddress);
|
||||
|
||||
// Version
|
||||
SuccessOrExit(error = Tlv::ReadUint16Tlv(aMessage, Tlv::kVersion, version));
|
||||
SuccessOrExit(error = Tlv::FindUint16Tlv(aMessage, Tlv::kVersion, version));
|
||||
VerifyOrExit(version >= OT_THREAD_VERSION_1_1, error = OT_ERROR_PARSE);
|
||||
|
||||
// Response
|
||||
@@ -3247,7 +3247,7 @@ void Mle::HandleParentResponse(const Message &aMessage, const Ip6::MessageInfo &
|
||||
SuccessOrExit(error = ReadLeaderData(aMessage, leaderData));
|
||||
|
||||
// Link Margin
|
||||
SuccessOrExit(error = Tlv::ReadUint8Tlv(aMessage, Tlv::kLinkMargin, linkMarginFromTlv));
|
||||
SuccessOrExit(error = Tlv::FindUint8Tlv(aMessage, Tlv::kLinkMargin, linkMarginFromTlv));
|
||||
|
||||
linkMargin = LinkQualityInfo::ConvertRssToLinkMargin(Get<Mac::Mac>().GetNoiseFloor(), linkInfo->mRss);
|
||||
|
||||
@@ -3259,7 +3259,7 @@ void Mle::HandleParentResponse(const Message &aMessage, const Ip6::MessageInfo &
|
||||
linkQuality = LinkQualityInfo::ConvertLinkMarginToLinkQuality(linkMargin);
|
||||
|
||||
// Connectivity
|
||||
SuccessOrExit(error = Tlv::GetTlv(aMessage, Tlv::kConnectivity, sizeof(connectivity), connectivity));
|
||||
SuccessOrExit(error = Tlv::FindTlv(aMessage, Tlv::kConnectivity, sizeof(connectivity), connectivity));
|
||||
VerifyOrExit(connectivity.IsValid(), error = OT_ERROR_PARSE);
|
||||
|
||||
// Share data with application, if requested.
|
||||
@@ -3339,10 +3339,10 @@ void Mle::HandleParentResponse(const Message &aMessage, const Ip6::MessageInfo &
|
||||
}
|
||||
|
||||
// Link Frame Counter
|
||||
SuccessOrExit(error = Tlv::ReadUint32Tlv(aMessage, Tlv::kLinkFrameCounter, linkFrameCounter));
|
||||
SuccessOrExit(error = Tlv::FindUint32Tlv(aMessage, Tlv::kLinkFrameCounter, linkFrameCounter));
|
||||
|
||||
// Mle Frame Counter
|
||||
switch (Tlv::ReadUint32Tlv(aMessage, Tlv::kMleFrameCounter, mleFrameCounter))
|
||||
switch (Tlv::FindUint32Tlv(aMessage, Tlv::kMleFrameCounter, mleFrameCounter))
|
||||
{
|
||||
case OT_ERROR_NONE:
|
||||
break;
|
||||
@@ -3356,7 +3356,7 @@ void Mle::HandleParentResponse(const Message &aMessage, const Ip6::MessageInfo &
|
||||
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
|
||||
|
||||
// Time Parameter
|
||||
if (Tlv::GetTlv(aMessage, Tlv::kTimeParameter, sizeof(timeParameter), timeParameter) == OT_ERROR_NONE)
|
||||
if (Tlv::FindTlv(aMessage, Tlv::kTimeParameter, sizeof(timeParameter), timeParameter) == OT_ERROR_NONE)
|
||||
{
|
||||
VerifyOrExit(timeParameter.IsValid(), OT_NOOP);
|
||||
|
||||
@@ -3427,7 +3427,7 @@ void Mle::HandleChildIdResponse(const Message & aMessage,
|
||||
uint16_t offset;
|
||||
|
||||
// Source Address
|
||||
SuccessOrExit(error = Tlv::ReadUint16Tlv(aMessage, Tlv::kSourceAddress, sourceAddress));
|
||||
SuccessOrExit(error = Tlv::FindUint16Tlv(aMessage, Tlv::kSourceAddress, sourceAddress));
|
||||
|
||||
LogMleMessage("Receive Child ID Response", aMessageInfo.GetPeerAddr(), sourceAddress);
|
||||
|
||||
@@ -3439,19 +3439,19 @@ void Mle::HandleChildIdResponse(const Message & aMessage,
|
||||
SuccessOrExit(error = ReadLeaderData(aMessage, leaderData));
|
||||
|
||||
// ShortAddress
|
||||
SuccessOrExit(error = Tlv::ReadUint16Tlv(aMessage, Tlv::kAddress16, shortAddress));
|
||||
SuccessOrExit(error = Tlv::FindUint16Tlv(aMessage, Tlv::kAddress16, shortAddress));
|
||||
|
||||
// Network Data
|
||||
error = Tlv::GetOffset(aMessage, Tlv::kNetworkData, networkDataOffset);
|
||||
error = Tlv::FindTlvOffset(aMessage, Tlv::kNetworkData, networkDataOffset);
|
||||
SuccessOrExit(error);
|
||||
|
||||
// Active Timestamp
|
||||
if (Tlv::GetTlv(aMessage, Tlv::kActiveTimestamp, sizeof(activeTimestamp), activeTimestamp) == OT_ERROR_NONE)
|
||||
if (Tlv::FindTlv(aMessage, Tlv::kActiveTimestamp, sizeof(activeTimestamp), activeTimestamp) == OT_ERROR_NONE)
|
||||
{
|
||||
VerifyOrExit(activeTimestamp.IsValid(), error = OT_ERROR_PARSE);
|
||||
|
||||
// Active Dataset
|
||||
if (Tlv::GetOffset(aMessage, Tlv::kActiveDataset, offset) == OT_ERROR_NONE)
|
||||
if (Tlv::FindTlvOffset(aMessage, Tlv::kActiveDataset, offset) == OT_ERROR_NONE)
|
||||
{
|
||||
aMessage.Read(offset, sizeof(tlv), &tlv);
|
||||
IgnoreError(
|
||||
@@ -3466,12 +3466,12 @@ void Mle::HandleChildIdResponse(const Message & aMessage,
|
||||
}
|
||||
|
||||
// Pending Timestamp
|
||||
if (Tlv::GetTlv(aMessage, Tlv::kPendingTimestamp, sizeof(pendingTimestamp), pendingTimestamp) == OT_ERROR_NONE)
|
||||
if (Tlv::FindTlv(aMessage, Tlv::kPendingTimestamp, sizeof(pendingTimestamp), pendingTimestamp) == OT_ERROR_NONE)
|
||||
{
|
||||
VerifyOrExit(pendingTimestamp.IsValid(), error = OT_ERROR_PARSE);
|
||||
|
||||
// Pending Dataset
|
||||
if (Tlv::GetOffset(aMessage, Tlv::kPendingDataset, offset) == OT_ERROR_NONE)
|
||||
if (Tlv::FindTlvOffset(aMessage, Tlv::kPendingDataset, offset) == OT_ERROR_NONE)
|
||||
{
|
||||
aMessage.Read(offset, sizeof(tlv), &tlv);
|
||||
IgnoreError(
|
||||
@@ -3512,7 +3512,7 @@ void Mle::HandleChildIdResponse(const Message & aMessage,
|
||||
{
|
||||
RouteTlv route;
|
||||
|
||||
if (Tlv::GetTlv(aMessage, Tlv::kRoute, sizeof(route), route) == OT_ERROR_NONE)
|
||||
if (Tlv::FindTlv(aMessage, Tlv::kRoute, sizeof(route), route) == OT_ERROR_NONE)
|
||||
{
|
||||
SuccessOrExit(error = Get<MleRouter>().ProcessRouteTlv(route));
|
||||
}
|
||||
@@ -3550,7 +3550,7 @@ void Mle::HandleChildUpdateRequest(const Message &aMessage, const Ip6::MessageIn
|
||||
uint8_t numTlvs = 0;
|
||||
|
||||
// Source Address
|
||||
SuccessOrExit(error = Tlv::ReadUint16Tlv(aMessage, Tlv::kSourceAddress, sourceAddress));
|
||||
SuccessOrExit(error = Tlv::FindUint16Tlv(aMessage, Tlv::kSourceAddress, sourceAddress));
|
||||
|
||||
LogMleMessage("Receive Child Update Request from parent", aMessageInfo.GetPeerAddr(), sourceAddress);
|
||||
|
||||
@@ -3572,7 +3572,7 @@ void Mle::HandleChildUpdateRequest(const Message &aMessage, const Ip6::MessageIn
|
||||
{
|
||||
uint8_t status;
|
||||
|
||||
switch (Tlv::ReadUint8Tlv(aMessage, Tlv::kStatus, status))
|
||||
switch (Tlv::FindUint8Tlv(aMessage, Tlv::kStatus, status))
|
||||
{
|
||||
case OT_ERROR_NONE:
|
||||
VerifyOrExit(status != StatusTlv::kError, IgnoreError(BecomeDetached()));
|
||||
@@ -3599,7 +3599,7 @@ void Mle::HandleChildUpdateRequest(const Message &aMessage, const Ip6::MessageIn
|
||||
}
|
||||
|
||||
// TLV Request
|
||||
switch (ReadTlvRequest(aMessage, requestedTlvs))
|
||||
switch (FindTlvRequest(aMessage, requestedTlvs))
|
||||
{
|
||||
case OT_ERROR_NONE:
|
||||
for (uint8_t i = 0; i < requestedTlvs.mNumTlvs; i++)
|
||||
@@ -3661,22 +3661,22 @@ void Mle::HandleChildUpdateResponse(const Message & aMessage,
|
||||
}
|
||||
|
||||
// Status
|
||||
if (Tlv::ReadUint8Tlv(aMessage, Tlv::kStatus, status) == OT_ERROR_NONE)
|
||||
if (Tlv::FindUint8Tlv(aMessage, Tlv::kStatus, status) == OT_ERROR_NONE)
|
||||
{
|
||||
IgnoreError(BecomeDetached());
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
// Mode
|
||||
SuccessOrExit(error = Tlv::ReadUint8Tlv(aMessage, Tlv::kMode, mode));
|
||||
SuccessOrExit(error = Tlv::FindUint8Tlv(aMessage, Tlv::kMode, mode));
|
||||
VerifyOrExit(DeviceMode(mode) == mDeviceMode, error = OT_ERROR_DROP);
|
||||
|
||||
switch (mRole)
|
||||
{
|
||||
case kRoleDetached:
|
||||
SuccessOrExit(error = Tlv::ReadUint32Tlv(aMessage, Tlv::kLinkFrameCounter, linkFrameCounter));
|
||||
SuccessOrExit(error = Tlv::FindUint32Tlv(aMessage, Tlv::kLinkFrameCounter, linkFrameCounter));
|
||||
|
||||
switch (Tlv::ReadUint32Tlv(aMessage, Tlv::kMleFrameCounter, mleFrameCounter))
|
||||
switch (Tlv::FindUint32Tlv(aMessage, Tlv::kMleFrameCounter, mleFrameCounter))
|
||||
{
|
||||
case OT_ERROR_NONE:
|
||||
break;
|
||||
@@ -3699,7 +3699,7 @@ void Mle::HandleChildUpdateResponse(const Message & aMessage,
|
||||
|
||||
case kRoleChild:
|
||||
// Source Address
|
||||
SuccessOrExit(error = Tlv::ReadUint16Tlv(aMessage, Tlv::kSourceAddress, sourceAddress));
|
||||
SuccessOrExit(error = Tlv::FindUint16Tlv(aMessage, Tlv::kSourceAddress, sourceAddress));
|
||||
|
||||
if (RouterIdFromRloc16(sourceAddress) != RouterIdFromRloc16(GetRloc16()))
|
||||
{
|
||||
@@ -3711,7 +3711,7 @@ void Mle::HandleChildUpdateResponse(const Message & aMessage,
|
||||
SuccessOrExit(error = HandleLeaderData(aMessage, aMessageInfo));
|
||||
|
||||
// Timeout optional
|
||||
switch (Tlv::ReadUint32Tlv(aMessage, Tlv::kTimeout, timeout))
|
||||
switch (Tlv::FindUint32Tlv(aMessage, Tlv::kTimeout, timeout))
|
||||
{
|
||||
case OT_ERROR_NONE:
|
||||
mTimeout = timeout;
|
||||
@@ -3769,15 +3769,15 @@ void Mle::HandleAnnounce(const Message &aMessage, const Ip6::MessageInfo &aMessa
|
||||
|
||||
LogMleMessage("Receive Announce", aMessageInfo.GetPeerAddr());
|
||||
|
||||
SuccessOrExit(error = Tlv::GetTlv(aMessage, Tlv::kChannel, sizeof(channelTlv), channelTlv));
|
||||
SuccessOrExit(error = Tlv::FindTlv(aMessage, Tlv::kChannel, sizeof(channelTlv), channelTlv));
|
||||
VerifyOrExit(channelTlv.IsValid(), error = OT_ERROR_PARSE);
|
||||
|
||||
channel = static_cast<uint8_t>(channelTlv.GetChannel());
|
||||
|
||||
SuccessOrExit(error = Tlv::GetTlv(aMessage, Tlv::kActiveTimestamp, sizeof(timestamp), timestamp));
|
||||
SuccessOrExit(error = Tlv::FindTlv(aMessage, Tlv::kActiveTimestamp, sizeof(timestamp), timestamp));
|
||||
VerifyOrExit(timestamp.IsValid(), error = OT_ERROR_PARSE);
|
||||
|
||||
SuccessOrExit(error = Tlv::ReadUint16Tlv(aMessage, Tlv::kPanId, panId));
|
||||
SuccessOrExit(error = Tlv::FindUint16Tlv(aMessage, Tlv::kPanId, panId));
|
||||
|
||||
localTimestamp = Get<MeshCoP::ActiveDataset>().GetTimestamp();
|
||||
|
||||
@@ -3871,7 +3871,7 @@ void Mle::HandleDiscoveryResponse(const Message &aMessage, const Ip6::MessageInf
|
||||
VerifyOrExit(mDiscoverInProgress, error = OT_ERROR_DROP);
|
||||
|
||||
// find MLE Discovery TLV
|
||||
VerifyOrExit(Tlv::GetOffset(aMessage, Tlv::kDiscovery, offset) == OT_ERROR_NONE, error = OT_ERROR_PARSE);
|
||||
VerifyOrExit(Tlv::FindTlvOffset(aMessage, Tlv::kDiscovery, offset) == OT_ERROR_NONE, error = OT_ERROR_PARSE);
|
||||
aMessage.Read(offset, sizeof(tlv), &tlv);
|
||||
|
||||
offset += sizeof(tlv);
|
||||
|
||||
@@ -1259,7 +1259,7 @@ protected:
|
||||
* @retval OT_ERROR_PARSE TLV was found but could not be parsed.
|
||||
*
|
||||
*/
|
||||
otError ReadTlvRequest(const Message &aMessage, RequestedTlvs &aRequestedTlvs);
|
||||
otError FindTlvRequest(const Message &aMessage, RequestedTlvs &aRequestedTlvs);
|
||||
|
||||
/**
|
||||
* This method appends a Leader Data TLV to a message.
|
||||
|
||||
@@ -584,7 +584,7 @@ void MleRouter::HandleLinkRequest(const Message &aMessage, const Ip6::MessageInf
|
||||
SuccessOrExit(error = ReadChallenge(aMessage, challenge));
|
||||
|
||||
// Version
|
||||
SuccessOrExit(error = Tlv::ReadUint16Tlv(aMessage, Tlv::kVersion, version));
|
||||
SuccessOrExit(error = Tlv::FindUint16Tlv(aMessage, Tlv::kVersion, version));
|
||||
VerifyOrExit(version >= OT_THREAD_VERSION_1_1, error = OT_ERROR_PARSE);
|
||||
|
||||
// Leader Data
|
||||
@@ -600,7 +600,7 @@ void MleRouter::HandleLinkRequest(const Message &aMessage, const Ip6::MessageInf
|
||||
}
|
||||
|
||||
// Source Address
|
||||
switch (Tlv::ReadUint16Tlv(aMessage, Tlv::kSourceAddress, sourceAddress))
|
||||
switch (Tlv::FindUint16Tlv(aMessage, Tlv::kSourceAddress, sourceAddress))
|
||||
{
|
||||
case OT_ERROR_NONE:
|
||||
if (IsActiveRouter(sourceAddress))
|
||||
@@ -644,7 +644,7 @@ void MleRouter::HandleLinkRequest(const Message &aMessage, const Ip6::MessageInf
|
||||
}
|
||||
|
||||
// TLV Request
|
||||
switch (ReadTlvRequest(aMessage, requestedTlvs))
|
||||
switch (FindTlvRequest(aMessage, requestedTlvs))
|
||||
{
|
||||
case OT_ERROR_NONE:
|
||||
break;
|
||||
@@ -658,7 +658,7 @@ void MleRouter::HandleLinkRequest(const Message &aMessage, const Ip6::MessageInf
|
||||
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
|
||||
if (neighbor != NULL)
|
||||
{
|
||||
if (Tlv::GetTlv(aMessage, Tlv::kTimeRequest, sizeof(timeRequest), timeRequest) == OT_ERROR_NONE)
|
||||
if (Tlv::FindTlv(aMessage, Tlv::kTimeRequest, sizeof(timeRequest), timeRequest) == OT_ERROR_NONE)
|
||||
{
|
||||
neighbor->SetTimeSyncEnabled(true);
|
||||
}
|
||||
@@ -825,7 +825,7 @@ otError MleRouter::HandleLinkAccept(const Message & aMessage,
|
||||
uint8_t linkMargin;
|
||||
|
||||
// Source Address
|
||||
SuccessOrExit(error = Tlv::ReadUint16Tlv(aMessage, Tlv::kSourceAddress, sourceAddress));
|
||||
SuccessOrExit(error = Tlv::FindUint16Tlv(aMessage, Tlv::kSourceAddress, sourceAddress));
|
||||
|
||||
if (aRequest)
|
||||
{
|
||||
@@ -869,14 +869,14 @@ otError MleRouter::HandleLinkAccept(const Message & aMessage,
|
||||
}
|
||||
|
||||
// Version
|
||||
SuccessOrExit(error = Tlv::ReadUint16Tlv(aMessage, Tlv::kVersion, version));
|
||||
SuccessOrExit(error = Tlv::FindUint16Tlv(aMessage, Tlv::kVersion, version));
|
||||
VerifyOrExit(version >= OT_THREAD_VERSION_1_1, error = OT_ERROR_PARSE);
|
||||
|
||||
// Link-Layer Frame Counter
|
||||
SuccessOrExit(error = Tlv::ReadUint32Tlv(aMessage, Tlv::kLinkFrameCounter, linkFrameCounter));
|
||||
SuccessOrExit(error = Tlv::FindUint32Tlv(aMessage, Tlv::kLinkFrameCounter, linkFrameCounter));
|
||||
|
||||
// MLE Frame Counter
|
||||
switch (Tlv::ReadUint32Tlv(aMessage, Tlv::kMleFrameCounter, mleFrameCounter))
|
||||
switch (Tlv::FindUint32Tlv(aMessage, Tlv::kMleFrameCounter, mleFrameCounter))
|
||||
{
|
||||
case OT_ERROR_NONE:
|
||||
break;
|
||||
@@ -888,7 +888,7 @@ otError MleRouter::HandleLinkAccept(const Message & aMessage,
|
||||
}
|
||||
|
||||
// Link Margin
|
||||
switch (Tlv::ReadUint8Tlv(aMessage, Tlv::kLinkMargin, linkMargin))
|
||||
switch (Tlv::FindUint8Tlv(aMessage, Tlv::kLinkMargin, linkMargin))
|
||||
{
|
||||
case OT_ERROR_NONE:
|
||||
break;
|
||||
@@ -910,7 +910,7 @@ otError MleRouter::HandleLinkAccept(const Message & aMessage,
|
||||
|
||||
case kRoleDetached:
|
||||
// Address16
|
||||
SuccessOrExit(error = Tlv::ReadUint16Tlv(aMessage, Tlv::kAddress16, address16));
|
||||
SuccessOrExit(error = Tlv::FindUint16Tlv(aMessage, Tlv::kAddress16, address16));
|
||||
VerifyOrExit(GetRloc16() == address16, error = OT_ERROR_DROP);
|
||||
|
||||
// Leader Data
|
||||
@@ -918,7 +918,7 @@ otError MleRouter::HandleLinkAccept(const Message & aMessage,
|
||||
SetLeaderData(leaderData.GetPartitionId(), leaderData.GetWeighting(), leaderData.GetLeaderRouterId());
|
||||
|
||||
// Route
|
||||
SuccessOrExit(error = Tlv::GetTlv(aMessage, Tlv::kRoute, sizeof(route), route));
|
||||
SuccessOrExit(error = Tlv::FindTlv(aMessage, Tlv::kRoute, sizeof(route), route));
|
||||
VerifyOrExit(route.IsValid(), error = OT_ERROR_PARSE);
|
||||
mRouterTable.Clear();
|
||||
SuccessOrExit(error = ProcessRouteTlv(route));
|
||||
@@ -961,7 +961,7 @@ otError MleRouter::HandleLinkAccept(const Message & aMessage,
|
||||
}
|
||||
|
||||
// Route (optional)
|
||||
if (Tlv::GetTlv(aMessage, Tlv::kRoute, sizeof(route), route) == OT_ERROR_NONE)
|
||||
if (Tlv::FindTlv(aMessage, Tlv::kRoute, sizeof(route), route) == OT_ERROR_NONE)
|
||||
{
|
||||
VerifyOrExit(route.IsValid(), error = OT_ERROR_PARSE);
|
||||
SuccessOrExit(error = ProcessRouteTlv(route));
|
||||
@@ -1004,7 +1004,7 @@ otError MleRouter::HandleLinkAccept(const Message & aMessage,
|
||||
SuccessOrExit(error = ReadChallenge(aMessage, challenge));
|
||||
|
||||
// TLV Request
|
||||
switch (ReadTlvRequest(aMessage, requestedTlvs))
|
||||
switch (FindTlvRequest(aMessage, requestedTlvs))
|
||||
{
|
||||
case OT_ERROR_NONE:
|
||||
break;
|
||||
@@ -1177,13 +1177,13 @@ otError MleRouter::HandleAdvertisement(const Message & aMessage,
|
||||
aMessageInfo.GetPeerAddr().ToExtAddress(macAddr);
|
||||
|
||||
// Source Address
|
||||
SuccessOrExit(error = Tlv::ReadUint16Tlv(aMessage, Tlv::kSourceAddress, sourceAddress));
|
||||
SuccessOrExit(error = Tlv::FindUint16Tlv(aMessage, Tlv::kSourceAddress, sourceAddress));
|
||||
|
||||
// Leader Data
|
||||
SuccessOrExit(error = ReadLeaderData(aMessage, leaderData));
|
||||
|
||||
// Route Data (optional)
|
||||
if (Tlv::GetTlv(aMessage, Tlv::kRoute, sizeof(route), route) == OT_ERROR_NONE)
|
||||
if (Tlv::FindTlv(aMessage, Tlv::kRoute, sizeof(route), route) == OT_ERROR_NONE)
|
||||
{
|
||||
VerifyOrExit(route.IsValid(), error = OT_ERROR_PARSE);
|
||||
}
|
||||
@@ -1632,11 +1632,11 @@ void MleRouter::HandleParentRequest(const Message &aMessage, const Ip6::MessageI
|
||||
aMessageInfo.GetPeerAddr().ToExtAddress(macAddr);
|
||||
|
||||
// Version
|
||||
SuccessOrExit(error = Tlv::ReadUint16Tlv(aMessage, Tlv::kVersion, version));
|
||||
SuccessOrExit(error = Tlv::FindUint16Tlv(aMessage, Tlv::kVersion, version));
|
||||
VerifyOrExit(version >= OT_THREAD_VERSION_1_1, error = OT_ERROR_PARSE);
|
||||
|
||||
// Scan Mask
|
||||
SuccessOrExit(error = Tlv::ReadUint8Tlv(aMessage, Tlv::kScanMask, scanMask));
|
||||
SuccessOrExit(error = Tlv::FindUint8Tlv(aMessage, Tlv::kScanMask, scanMask));
|
||||
|
||||
switch (mRole)
|
||||
{
|
||||
@@ -1670,7 +1670,7 @@ void MleRouter::HandleParentRequest(const Message &aMessage, const Ip6::MessageI
|
||||
child->ResetLinkFailures();
|
||||
child->SetState(Neighbor::kStateParentRequest);
|
||||
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
|
||||
if (Tlv::GetTlv(aMessage, Tlv::kTimeRequest, sizeof(timeRequest), timeRequest) == OT_ERROR_NONE)
|
||||
if (Tlv::FindTlv(aMessage, Tlv::kTimeRequest, sizeof(timeRequest), timeRequest) == OT_ERROR_NONE)
|
||||
{
|
||||
child->SetTimeSyncEnabled(true);
|
||||
}
|
||||
@@ -2176,7 +2176,7 @@ void MleRouter::HandleChildIdRequest(const Message & aMessage,
|
||||
VerifyOrExit(child != NULL, error = OT_ERROR_ALREADY);
|
||||
|
||||
// Version
|
||||
SuccessOrExit(error = Tlv::ReadUint16Tlv(aMessage, Tlv::kVersion, version));
|
||||
SuccessOrExit(error = Tlv::FindUint16Tlv(aMessage, Tlv::kVersion, version));
|
||||
VerifyOrExit(version >= OT_THREAD_VERSION_1_1, error = OT_ERROR_PARSE);
|
||||
|
||||
// Response
|
||||
@@ -2190,10 +2190,10 @@ void MleRouter::HandleChildIdRequest(const Message & aMessage,
|
||||
Get<MeshForwarder>().RemoveMessages(*child, Message::kSubTypeMleDataResponse);
|
||||
|
||||
// Link-Layer Frame Counter
|
||||
SuccessOrExit(error = Tlv::ReadUint32Tlv(aMessage, Tlv::kLinkFrameCounter, linkFrameCounter));
|
||||
SuccessOrExit(error = Tlv::FindUint32Tlv(aMessage, Tlv::kLinkFrameCounter, linkFrameCounter));
|
||||
|
||||
// MLE Frame Counter
|
||||
switch (Tlv::ReadUint32Tlv(aMessage, Tlv::kMleFrameCounter, mleFrameCounter))
|
||||
switch (Tlv::FindUint32Tlv(aMessage, Tlv::kMleFrameCounter, mleFrameCounter))
|
||||
{
|
||||
case OT_ERROR_NONE:
|
||||
break;
|
||||
@@ -2205,20 +2205,20 @@ void MleRouter::HandleChildIdRequest(const Message & aMessage,
|
||||
}
|
||||
|
||||
// Mode
|
||||
SuccessOrExit(error = Tlv::ReadUint8Tlv(aMessage, Tlv::kMode, modeBitmask));
|
||||
SuccessOrExit(error = Tlv::FindUint8Tlv(aMessage, Tlv::kMode, modeBitmask));
|
||||
mode.Set(modeBitmask);
|
||||
|
||||
// Timeout
|
||||
SuccessOrExit(error = Tlv::ReadUint32Tlv(aMessage, Tlv::kTimeout, timeout));
|
||||
SuccessOrExit(error = Tlv::FindUint32Tlv(aMessage, Tlv::kTimeout, timeout));
|
||||
|
||||
// TLV Request
|
||||
SuccessOrExit(error = ReadTlvRequest(aMessage, requestedTlvs));
|
||||
SuccessOrExit(error = FindTlvRequest(aMessage, requestedTlvs));
|
||||
VerifyOrExit(requestedTlvs.mNumTlvs <= Child::kMaxRequestTlvs, error = OT_ERROR_PARSE);
|
||||
|
||||
// Active Timestamp
|
||||
activeTimestamp.SetLength(0);
|
||||
|
||||
if (Tlv::GetTlv(aMessage, Tlv::kActiveTimestamp, sizeof(activeTimestamp), activeTimestamp) == OT_ERROR_NONE)
|
||||
if (Tlv::FindTlv(aMessage, Tlv::kActiveTimestamp, sizeof(activeTimestamp), activeTimestamp) == OT_ERROR_NONE)
|
||||
{
|
||||
VerifyOrExit(activeTimestamp.IsValid(), error = OT_ERROR_PARSE);
|
||||
}
|
||||
@@ -2226,14 +2226,14 @@ void MleRouter::HandleChildIdRequest(const Message & aMessage,
|
||||
// Pending Timestamp
|
||||
pendingTimestamp.SetLength(0);
|
||||
|
||||
if (Tlv::GetTlv(aMessage, Tlv::kPendingTimestamp, sizeof(pendingTimestamp), pendingTimestamp) == OT_ERROR_NONE)
|
||||
if (Tlv::FindTlv(aMessage, Tlv::kPendingTimestamp, sizeof(pendingTimestamp), pendingTimestamp) == OT_ERROR_NONE)
|
||||
{
|
||||
VerifyOrExit(pendingTimestamp.IsValid(), error = OT_ERROR_PARSE);
|
||||
}
|
||||
|
||||
if (!mode.IsFullThreadDevice())
|
||||
{
|
||||
SuccessOrExit(error = Tlv::GetOffset(aMessage, Tlv::kAddressRegistration, addressRegistrationOffset));
|
||||
SuccessOrExit(error = Tlv::FindTlvOffset(aMessage, Tlv::kAddressRegistration, addressRegistrationOffset));
|
||||
SuccessOrExit(error = UpdateChildAddresses(aMessage, addressRegistrationOffset, *child));
|
||||
}
|
||||
|
||||
@@ -2339,7 +2339,7 @@ void MleRouter::HandleChildUpdateRequest(const Message & aMessage,
|
||||
LogMleMessage("Receive Child Update Request from child", aMessageInfo.GetPeerAddr());
|
||||
|
||||
// Mode
|
||||
SuccessOrExit(error = Tlv::ReadUint8Tlv(aMessage, Tlv::kMode, modeBitmask));
|
||||
SuccessOrExit(error = Tlv::FindUint8Tlv(aMessage, Tlv::kMode, modeBitmask));
|
||||
mode.Set(modeBitmask);
|
||||
|
||||
// Challenge
|
||||
@@ -2390,7 +2390,7 @@ void MleRouter::HandleChildUpdateRequest(const Message & aMessage,
|
||||
}
|
||||
|
||||
// Ip6 Address TLV
|
||||
if (Tlv::GetOffset(aMessage, Tlv::kAddressRegistration, addressRegistrationOffset) == OT_ERROR_NONE)
|
||||
if (Tlv::FindTlvOffset(aMessage, Tlv::kAddressRegistration, addressRegistrationOffset) == OT_ERROR_NONE)
|
||||
{
|
||||
SuccessOrExit(error = UpdateChildAddresses(aMessage, addressRegistrationOffset, *child));
|
||||
tlvs[tlvslength++] = Tlv::kAddressRegistration;
|
||||
@@ -2407,7 +2407,7 @@ void MleRouter::HandleChildUpdateRequest(const Message & aMessage,
|
||||
}
|
||||
|
||||
// Timeout
|
||||
switch (Tlv::ReadUint32Tlv(aMessage, Tlv::kTimeout, timeout))
|
||||
switch (Tlv::FindUint32Tlv(aMessage, Tlv::kTimeout, timeout))
|
||||
{
|
||||
case OT_ERROR_NONE:
|
||||
if (child->GetTimeout() != timeout)
|
||||
@@ -2427,7 +2427,7 @@ void MleRouter::HandleChildUpdateRequest(const Message & aMessage,
|
||||
}
|
||||
|
||||
// TLV Request
|
||||
switch (ReadTlvRequest(aMessage, requestedTlvs))
|
||||
switch (FindTlvRequest(aMessage, requestedTlvs))
|
||||
{
|
||||
case OT_ERROR_NONE:
|
||||
VerifyOrExit(requestedTlvs.mNumTlvs <= (kMaxResponseTlvs - tlvslength), error = OT_ERROR_PARSE);
|
||||
@@ -2527,7 +2527,7 @@ void MleRouter::HandleChildUpdateResponse(const Message & aMessage,
|
||||
LogMleMessage("Receive Child Update Response from child", aMessageInfo.GetPeerAddr(), child->GetRloc16());
|
||||
|
||||
// Source Address
|
||||
switch (Tlv::ReadUint16Tlv(aMessage, Tlv::kSourceAddress, sourceAddress))
|
||||
switch (Tlv::FindUint16Tlv(aMessage, Tlv::kSourceAddress, sourceAddress))
|
||||
{
|
||||
case OT_ERROR_NONE:
|
||||
if (child->GetRloc16() != sourceAddress)
|
||||
@@ -2546,7 +2546,7 @@ void MleRouter::HandleChildUpdateResponse(const Message & aMessage,
|
||||
}
|
||||
|
||||
// Status
|
||||
switch (Tlv::ReadUint8Tlv(aMessage, Tlv::kStatus, status))
|
||||
switch (Tlv::FindUint8Tlv(aMessage, Tlv::kStatus, status))
|
||||
{
|
||||
case OT_ERROR_NONE:
|
||||
VerifyOrExit(status != StatusTlv::kError, RemoveNeighbor(*child));
|
||||
@@ -2559,7 +2559,7 @@ void MleRouter::HandleChildUpdateResponse(const Message & aMessage,
|
||||
|
||||
// Link-Layer Frame Counter
|
||||
|
||||
switch (Tlv::ReadUint32Tlv(aMessage, Tlv::kLinkFrameCounter, linkFrameCounter))
|
||||
switch (Tlv::FindUint32Tlv(aMessage, Tlv::kLinkFrameCounter, linkFrameCounter))
|
||||
{
|
||||
case OT_ERROR_NONE:
|
||||
child->SetLinkFrameCounter(linkFrameCounter);
|
||||
@@ -2571,7 +2571,7 @@ void MleRouter::HandleChildUpdateResponse(const Message & aMessage,
|
||||
}
|
||||
|
||||
// MLE Frame Counter
|
||||
switch (Tlv::ReadUint32Tlv(aMessage, Tlv::kMleFrameCounter, mleFrameCounter))
|
||||
switch (Tlv::FindUint32Tlv(aMessage, Tlv::kMleFrameCounter, mleFrameCounter))
|
||||
{
|
||||
case OT_ERROR_NONE:
|
||||
child->SetMleFrameCounter(mleFrameCounter);
|
||||
@@ -2583,7 +2583,7 @@ void MleRouter::HandleChildUpdateResponse(const Message & aMessage,
|
||||
}
|
||||
|
||||
// Timeout
|
||||
switch (Tlv::ReadUint32Tlv(aMessage, Tlv::kTimeout, timeout))
|
||||
switch (Tlv::FindUint32Tlv(aMessage, Tlv::kTimeout, timeout))
|
||||
{
|
||||
case OT_ERROR_NONE:
|
||||
child->SetTimeout(timeout);
|
||||
@@ -2595,7 +2595,7 @@ void MleRouter::HandleChildUpdateResponse(const Message & aMessage,
|
||||
}
|
||||
|
||||
// Ip6 Address
|
||||
if (Tlv::GetOffset(aMessage, Tlv::kAddressRegistration, addressRegistrationOffset) == OT_ERROR_NONE)
|
||||
if (Tlv::FindTlvOffset(aMessage, Tlv::kAddressRegistration, addressRegistrationOffset) == OT_ERROR_NONE)
|
||||
{
|
||||
SuccessOrExit(error = UpdateChildAddresses(aMessage, addressRegistrationOffset, *child));
|
||||
}
|
||||
@@ -2648,13 +2648,13 @@ void MleRouter::HandleDataRequest(const Message & aMessage,
|
||||
VerifyOrExit(aNeighbor && aNeighbor->IsStateValid(), error = OT_ERROR_SECURITY);
|
||||
|
||||
// TLV Request
|
||||
SuccessOrExit(error = ReadTlvRequest(aMessage, requestedTlvs));
|
||||
SuccessOrExit(error = FindTlvRequest(aMessage, requestedTlvs));
|
||||
VerifyOrExit(requestedTlvs.mNumTlvs <= sizeof(tlvs), error = OT_ERROR_PARSE);
|
||||
|
||||
// Active Timestamp
|
||||
activeTimestamp.SetLength(0);
|
||||
|
||||
if (Tlv::GetTlv(aMessage, Tlv::kActiveTimestamp, sizeof(activeTimestamp), activeTimestamp) == OT_ERROR_NONE)
|
||||
if (Tlv::FindTlv(aMessage, Tlv::kActiveTimestamp, sizeof(activeTimestamp), activeTimestamp) == OT_ERROR_NONE)
|
||||
{
|
||||
VerifyOrExit(activeTimestamp.IsValid(), error = OT_ERROR_PARSE);
|
||||
}
|
||||
@@ -2662,7 +2662,7 @@ void MleRouter::HandleDataRequest(const Message & aMessage,
|
||||
// Pending Timestamp
|
||||
pendingTimestamp.SetLength(0);
|
||||
|
||||
if (Tlv::GetTlv(aMessage, Tlv::kPendingTimestamp, sizeof(pendingTimestamp), pendingTimestamp) == OT_ERROR_NONE)
|
||||
if (Tlv::FindTlv(aMessage, Tlv::kPendingTimestamp, sizeof(pendingTimestamp), pendingTimestamp) == OT_ERROR_NONE)
|
||||
{
|
||||
VerifyOrExit(pendingTimestamp.IsValid(), error = OT_ERROR_PARSE);
|
||||
}
|
||||
@@ -2795,7 +2795,7 @@ void MleRouter::HandleDiscoveryRequest(const Message &aMessage, const Ip6::Messa
|
||||
VerifyOrExit(IsRouterEligible(), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
// find MLE Discovery TLV
|
||||
VerifyOrExit(Tlv::GetOffset(aMessage, Tlv::kDiscovery, offset) == OT_ERROR_NONE, error = OT_ERROR_PARSE);
|
||||
VerifyOrExit(Tlv::FindTlvOffset(aMessage, Tlv::kDiscovery, offset) == OT_ERROR_NONE, error = OT_ERROR_PARSE);
|
||||
aMessage.Read(offset, sizeof(tlv), &tlv);
|
||||
|
||||
offset += sizeof(tlv);
|
||||
@@ -4043,7 +4043,7 @@ void MleRouter::HandleAddressSolicitResponse(Coap::Message * aMessage,
|
||||
|
||||
LogMleMessage("Receive Address Reply", aMessageInfo->GetPeerAddr());
|
||||
|
||||
SuccessOrExit(Tlv::ReadUint8Tlv(*aMessage, ThreadTlv::kStatus, status));
|
||||
SuccessOrExit(Tlv::FindUint8Tlv(*aMessage, ThreadTlv::kStatus, status));
|
||||
|
||||
if (status != ThreadStatusTlv::kSuccess)
|
||||
{
|
||||
@@ -4062,10 +4062,10 @@ void MleRouter::HandleAddressSolicitResponse(Coap::Message * aMessage,
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
SuccessOrExit(Tlv::ReadUint16Tlv(*aMessage, ThreadTlv::kRloc16, rloc16));
|
||||
SuccessOrExit(Tlv::FindUint16Tlv(*aMessage, ThreadTlv::kRloc16, rloc16));
|
||||
routerId = RouterIdFromRloc16(rloc16);
|
||||
|
||||
SuccessOrExit(ThreadTlv::GetTlv(*aMessage, ThreadTlv::kRouterMask, sizeof(routerMaskTlv), routerMaskTlv));
|
||||
SuccessOrExit(ThreadTlv::FindTlv(*aMessage, ThreadTlv::kRouterMask, sizeof(routerMaskTlv), routerMaskTlv));
|
||||
VerifyOrExit(routerMaskTlv.IsValid(), OT_NOOP);
|
||||
|
||||
// assign short address
|
||||
@@ -4142,13 +4142,13 @@ void MleRouter::HandleAddressSolicit(Coap::Message &aMessage, const Ip6::Message
|
||||
|
||||
LogMleMessage("Receive Address Solicit", aMessageInfo.GetPeerAddr());
|
||||
|
||||
SuccessOrExit(error = Tlv::ReadTlv(aMessage, ThreadTlv::kExtMacAddress, &extAddress, sizeof(extAddress)));
|
||||
SuccessOrExit(error = ThreadTlv::FindTlv(aMessage, ThreadTlv::kExtMacAddress, &extAddress, sizeof(extAddress)));
|
||||
|
||||
SuccessOrExit(error = Tlv::ReadUint8Tlv(aMessage, ThreadTlv::kStatus, status));
|
||||
SuccessOrExit(error = Tlv::FindUint8Tlv(aMessage, ThreadTlv::kStatus, status));
|
||||
|
||||
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
|
||||
// In a time sync enabled network, all routers' xtal accuracy must be less than the threshold.
|
||||
SuccessOrExit(Tlv::ReadUint16Tlv(aMessage, Tlv::kXtalAccuracy, xtalAccuracy));
|
||||
SuccessOrExit(Tlv::FindUint16Tlv(aMessage, Tlv::kXtalAccuracy, xtalAccuracy));
|
||||
VerifyOrExit(xtalAccuracy <= Get<TimeSync>().GetXtalThreshold(), OT_NOOP);
|
||||
#endif
|
||||
|
||||
@@ -4176,7 +4176,7 @@ void MleRouter::HandleAddressSolicit(Coap::Message &aMessage, const Ip6::Message
|
||||
OT_UNREACHABLE_CODE(break);
|
||||
}
|
||||
|
||||
switch (Tlv::ReadUint16Tlv(aMessage, ThreadTlv::kRloc16, rloc16))
|
||||
switch (Tlv::FindUint16Tlv(aMessage, ThreadTlv::kRloc16, rloc16))
|
||||
{
|
||||
case OT_ERROR_NONE:
|
||||
router = mRouterTable.Allocate(RouterIdFromRloc16(rloc16));
|
||||
@@ -4271,9 +4271,9 @@ void MleRouter::HandleAddressRelease(Coap::Message &aMessage, const Ip6::Message
|
||||
|
||||
LogMleMessage("Receive Address Release", aMessageInfo.GetPeerAddr());
|
||||
|
||||
SuccessOrExit(Tlv::ReadUint16Tlv(aMessage, ThreadTlv::kRloc16, rloc16));
|
||||
SuccessOrExit(Tlv::FindUint16Tlv(aMessage, ThreadTlv::kRloc16, rloc16));
|
||||
|
||||
SuccessOrExit(Tlv::ReadTlv(aMessage, ThreadTlv::kExtMacAddress, &extAddress, sizeof(extAddress)));
|
||||
SuccessOrExit(Tlv::FindTlv(aMessage, ThreadTlv::kExtMacAddress, &extAddress, sizeof(extAddress)));
|
||||
|
||||
routerId = RouterIdFromRloc16(rloc16);
|
||||
router = mRouterTable.GetRouter(routerId);
|
||||
|
||||
@@ -134,39 +134,6 @@ public:
|
||||
*/
|
||||
void SetType(Type aType) { ot::Tlv::SetType(static_cast<uint8_t>(aType)); }
|
||||
|
||||
/**
|
||||
* This static method reads the requested TLV out of @p aMessage.
|
||||
*
|
||||
* @param[in] aMessage A reference to the message.
|
||||
* @param[in] aType The Type value to search for.
|
||||
* @param[in] aMaxLength Maximum number of bytes to read.
|
||||
* @param[out] aTlv A reference to the TLV that will be copied to.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully copied the TLV.
|
||||
* @retval OT_ERROR_NOT_FOUND Could not find the TLV with Type @p aType.
|
||||
*
|
||||
*/
|
||||
static otError GetTlv(const Message &aMessage, Type aType, uint16_t aMaxLength, Tlv &aTlv)
|
||||
{
|
||||
return ot::Tlv::Get(aMessage, static_cast<uint8_t>(aType), aMaxLength, aTlv);
|
||||
}
|
||||
|
||||
/**
|
||||
* This static method obtains the offset of a TLV within @p aMessage.
|
||||
*
|
||||
* @param[in] aMessage A reference to the message.
|
||||
* @param[in] aType The Type value to search for.
|
||||
* @param[out] aOffset A reference to the offset of the TLV.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully copied the TLV.
|
||||
* @retval OT_ERROR_NOT_FOUND Could not find the TLV with Type @p aType.
|
||||
*
|
||||
*/
|
||||
static otError GetOffset(const Message &aMessage, Type aType, uint16_t &aOffset)
|
||||
{
|
||||
return ot::Tlv::GetOffset(aMessage, static_cast<uint8_t>(aType), aOffset);
|
||||
}
|
||||
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
#if !OPENTHREAD_CONFIG_MLE_LONG_ROUTES_ENABLE
|
||||
|
||||
@@ -146,7 +146,7 @@ void Leader::HandleServerData(Coap::Message &aMessage, const Ip6::MessageInfo &a
|
||||
|
||||
VerifyOrExit(aMessageInfo.GetPeerAddr().IsIidRoutingLocator(), OT_NOOP);
|
||||
|
||||
switch (Tlv::ReadUint16Tlv(aMessage, ThreadTlv::kRloc16, rloc16))
|
||||
switch (Tlv::FindUint16Tlv(aMessage, ThreadTlv::kRloc16, rloc16))
|
||||
{
|
||||
case OT_ERROR_NONE:
|
||||
RemoveBorderRouter(rloc16, kMatchModeRloc16);
|
||||
@@ -157,7 +157,7 @@ void Leader::HandleServerData(Coap::Message &aMessage, const Ip6::MessageInfo &a
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
if (ThreadTlv::GetTlv(aMessage, ThreadTlv::kThreadNetworkData, sizeof(networkData), networkData) == OT_ERROR_NONE)
|
||||
if (ThreadTlv::FindTlv(aMessage, ThreadTlv::kThreadNetworkData, sizeof(networkData), networkData) == OT_ERROR_NONE)
|
||||
{
|
||||
VerifyOrExit(networkData.IsValid(), OT_NOOP);
|
||||
RegisterNetworkData(aMessageInfo.GetPeerAddr().GetLocator(), networkData.GetTlvs(), networkData.GetLength());
|
||||
@@ -287,7 +287,7 @@ void Leader::HandleCommissioningGet(Coap::Message &aMessage, const Ip6::MessageI
|
||||
uint16_t length = 0;
|
||||
uint16_t offset;
|
||||
|
||||
SuccessOrExit(Tlv::GetValueOffset(aMessage, MeshCoP::Tlv::kGet, offset, length));
|
||||
SuccessOrExit(Tlv::FindTlvValueOffset(aMessage, MeshCoP::Tlv::kGet, offset, length));
|
||||
aMessage.SetOffset(offset);
|
||||
|
||||
exit:
|
||||
|
||||
@@ -116,39 +116,6 @@ public:
|
||||
*/
|
||||
void SetType(Type aType) { ot::Tlv::SetType(static_cast<uint8_t>(aType)); }
|
||||
|
||||
/**
|
||||
* This static method reads the requested TLV out of @p aMessage.
|
||||
*
|
||||
* @param[in] aMessage A reference to the message.
|
||||
* @param[in] aType The Type value to search for.
|
||||
* @param[in] aMaxLength Maximum number of bytes to read.
|
||||
* @param[out] aTlv A reference to the TLV that will be copied to.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully copied the TLV.
|
||||
* @retval OT_ERROR_NOT_FOUND Could not find the TLV with Type @p aType.
|
||||
*
|
||||
*/
|
||||
static otError GetTlv(const Message &aMessage, Type aType, uint16_t aMaxLength, Tlv &aTlv)
|
||||
{
|
||||
return ot::Tlv::Get(aMessage, static_cast<uint8_t>(aType), aMaxLength, aTlv);
|
||||
}
|
||||
|
||||
/**
|
||||
* This static method obtains the offset of a TLV within @p aMessage.
|
||||
*
|
||||
* @param[in] aMessage A reference to the message.
|
||||
* @param[in] aType The Type value to search for.
|
||||
* @param[out] aOffset A reference to the offset of the TLV.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully copied the TLV.
|
||||
* @retval OT_ERROR_NOT_FOUND Could not find the TLV with Type @p aType.
|
||||
*
|
||||
*/
|
||||
static otError GetOffset(const Message &aMessage, Type aType, uint16_t &aOffset)
|
||||
{
|
||||
return ot::Tlv::GetOffset(aMessage, static_cast<uint8_t>(aType), aOffset);
|
||||
}
|
||||
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
/**
|
||||
|
||||
@@ -71,7 +71,7 @@ void PanIdQueryServer::HandleQuery(Coap::Message &aMessage, const Ip6::MessageIn
|
||||
VerifyOrExit(aMessage.GetCode() == OT_COAP_CODE_POST, OT_NOOP);
|
||||
VerifyOrExit((mask = MeshCoP::ChannelMaskTlv::GetChannelMask(aMessage)) != 0, OT_NOOP);
|
||||
|
||||
SuccessOrExit(Tlv::ReadUint16Tlv(aMessage, MeshCoP::Tlv::kPanId, panId));
|
||||
SuccessOrExit(Tlv::FindUint16Tlv(aMessage, MeshCoP::Tlv::kPanId, panId));
|
||||
|
||||
mChannelMask = mask;
|
||||
mCommissioner = aMessageInfo.GetPeerAddr();
|
||||
|
||||
@@ -95,23 +95,6 @@ public:
|
||||
*/
|
||||
void SetType(Type aType) { ot::Tlv::SetType(static_cast<uint8_t>(aType)); }
|
||||
|
||||
/**
|
||||
* This static method reads the requested TLV out of @p aMessage.
|
||||
*
|
||||
* @param[in] aMessage A reference to the message.
|
||||
* @param[in] aType The Type value to search for.
|
||||
* @param[in] aMaxLength Maximum number of bytes to read.
|
||||
* @param[out] aTlv A reference to the TLV that will be copied to.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully copied the TLV.
|
||||
* @retval OT_ERROR_NOT_FOUND Could not find the TLV with Type @p aType.
|
||||
*
|
||||
*/
|
||||
static otError GetTlv(const Message &aMessage, Type aType, uint16_t aMaxLength, Tlv &aTlv)
|
||||
{
|
||||
return ot::Tlv::Get(aMessage, static_cast<uint8_t>(aType), aMaxLength, aTlv);
|
||||
}
|
||||
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user