Fix Commissioning dataset update. (#1363)

This commit is contained in:
Robert Lubos
2017-02-22 08:16:57 +01:00
committed by Jonathan Hui
parent bd161d5750
commit 40ee47b516
2 changed files with 23 additions and 12 deletions
+1
View File
@@ -508,6 +508,7 @@ ThreadError Commissioner::SendPetition(void)
mNetif.GetMle().GetLeaderAloc(*static_cast<Ip6::Address *>(&messageInfo.mPeerAddr));
messageInfo.SetPeerPort(kCoapUdpPort);
messageInfo.SetSockAddr(mNetif.GetMle().GetMeshLocal16());
SuccessOrExit(error = mNetif.GetCoapClient().SendMessage(*message, messageInfo,
Commissioner::HandleLeaderPetitionResponse, this));
+22 -12
View File
@@ -229,20 +229,30 @@ void Leader::HandleCommissioningSet(Coap::Header &aHeader, Message &aMessage, co
// verify whether or not MGMT_COMM_SET.req includes at least one valid TLV
VerifyOrExit(hasValidTlv, state = MeshCoP::StateTlv::kReject);
for (MeshCoP::Tlv *cur = reinterpret_cast<MeshCoP::Tlv *>(mTlvs + sizeof(CommissioningDataTlv));
cur < reinterpret_cast<MeshCoP::Tlv *>(mTlvs + mLength);
cur = cur->GetNext())
// Find Commissioning Data TLV
for (NetworkDataTlv *netDataTlv = reinterpret_cast<NetworkDataTlv *>(mTlvs);
netDataTlv < reinterpret_cast<NetworkDataTlv *>(mTlvs + mLength);
netDataTlv = netDataTlv->GetNext())
{
if (cur->GetType() == MeshCoP::Tlv::kCommissionerSessionId)
if (netDataTlv->GetType() == NetworkDataTlv::kTypeCommissioningData)
{
VerifyOrExit(sessionId ==
static_cast<MeshCoP::CommissionerSessionIdTlv *>(cur)->GetCommissionerSessionId(),
state = MeshCoP::StateTlv::kReject);
}
else if (cur->GetType() == MeshCoP::Tlv::kBorderAgentLocator)
{
memcpy(tlvs + length, reinterpret_cast<uint8_t *>(cur), cur->GetLength() + sizeof(MeshCoP::Tlv));
length += (cur->GetLength() + sizeof(MeshCoP::Tlv));
// Iterate over MeshCoP TLVs and extract desired data
for (MeshCoP::Tlv *cur = reinterpret_cast<MeshCoP::Tlv *>(netDataTlv->GetValue());
cur < reinterpret_cast<MeshCoP::Tlv *>(netDataTlv->GetValue() + netDataTlv->GetLength());
cur = cur->GetNext())
{
if (cur->GetType() == MeshCoP::Tlv::kCommissionerSessionId)
{
VerifyOrExit(sessionId ==
static_cast<MeshCoP::CommissionerSessionIdTlv *>(cur)->GetCommissionerSessionId(),
state = MeshCoP::StateTlv::kReject);
}
else if (cur->GetType() == MeshCoP::Tlv::kBorderAgentLocator)
{
memcpy(tlvs + length, reinterpret_cast<uint8_t *>(cur), cur->GetLength() + sizeof(MeshCoP::Tlv));
length += (cur->GetLength() + sizeof(MeshCoP::Tlv));
}
}
}
}