[mle] add field-specific length methods to Challenge/Response TLVs (#3937)

This commit is contained in:
Jonathan Hui
2019-06-21 08:34:52 -07:00
committed by GitHub
parent ea9a6d2b14
commit 8224b3c49f
3 changed files with 14 additions and 6 deletions
+2 -2
View File
@@ -2384,7 +2384,7 @@ otError Mle::SendChildUpdateResponse(const uint8_t *aTlvs, uint8_t aNumTlvs, con
break;
case Tlv::kResponse:
SuccessOrExit(error = AppendResponse(*message, aChallenge.GetChallenge(), aChallenge.GetLength()));
SuccessOrExit(error = AppendResponse(*message, aChallenge.GetChallenge(), aChallenge.GetChallengeLength()));
break;
case Tlv::kLinkFrameCounter:
@@ -3212,7 +3212,7 @@ otError Mle::HandleParentResponse(const Message &aMessage, const Ip6::MessageInf
// Response
SuccessOrExit(error = Tlv::GetTlv(aMessage, Tlv::kResponse, sizeof(response), response));
VerifyOrExit(response.IsValid() &&
memcmp(response.GetResponse(), mParentRequest.mChallenge, response.GetLength()) == 0,
memcmp(response.GetResponse(), mParentRequest.mChallenge, response.GetResponseLength()) == 0,
error = OT_ERROR_PARSE);
aMessageInfo.GetPeerAddr().ToExtAddress(extAddress);
+2 -2
View File
@@ -691,7 +691,7 @@ otError MleRouter::SendLinkAccept(const Ip6::MessageInfo &aMessageInfo,
SuccessOrExit(error = AppendHeader(*message, command));
SuccessOrExit(error = AppendVersion(*message));
SuccessOrExit(error = AppendSourceAddress(*message));
SuccessOrExit(error = AppendResponse(*message, aChallenge.GetChallenge(), aChallenge.GetLength()));
SuccessOrExit(error = AppendResponse(*message, aChallenge.GetChallenge(), aChallenge.GetChallengeLength()));
SuccessOrExit(error = AppendLinkFrameCounter(*message));
SuccessOrExit(error = AppendMleFrameCounter(*message));
@@ -1898,7 +1898,7 @@ void MleRouter::SendParentResponse(Child *aChild, const ChallengeTlv &aChallenge
SuccessOrExit(error = AppendLeaderData(*message));
SuccessOrExit(error = AppendLinkFrameCounter(*message));
SuccessOrExit(error = AppendMleFrameCounter(*message));
SuccessOrExit(error = AppendResponse(*message, aChallenge.GetChallenge(), aChallenge.GetLength()));
SuccessOrExit(error = AppendResponse(*message, aChallenge.GetChallenge(), aChallenge.GetChallengeLength()));
#if OPENTHREAD_CONFIG_ENABLE_TIME_SYNC
if (aChild->IsTimeSyncEnabled())
{
+10 -2
View File
@@ -411,7 +411,7 @@ public:
/**
* This method indicates whether or not the TLV appears to be well-formed.
*
* OpenThread only generates Challenge values with 8-byte length. As a result, a Response value lengths must also
* OpenThread only generates Challenge values with 8-byte length. As a result, Response value lengths must also
* have 8-byte length.
*
* @retval TRUE If the TLV appears to be well-formed.
@@ -420,6 +420,14 @@ public:
*/
bool IsValid(void) const { return GetLength() >= sizeof(*this) - sizeof(Tlv); }
/**
* This method returns the Response length.
*
* @returns The Response length.
*
*/
uint8_t GetResponseLength(void) const { return GetLength() <= sizeof(mResponse) ? GetLength() : sizeof(mResponse); }
/**
* This method returns a pointer to the Response value.
*
@@ -434,7 +442,7 @@ public:
* @param[in] aResponse A pointer to the Response value.
*
*/
void SetResponse(const uint8_t *aResponse) { memcpy(mResponse, aResponse, GetLength()); }
void SetResponse(const uint8_t *aResponse) { memcpy(mResponse, aResponse, GetResponseLength()); }
private:
uint8_t mResponse[kMaxSize];