diff --git a/src/core/meshcop/commissioner.cpp b/src/core/meshcop/commissioner.cpp index 0024b549c..2b725f19b 100644 --- a/src/core/meshcop/commissioner.cpp +++ b/src/core/meshcop/commissioner.cpp @@ -508,6 +508,7 @@ ThreadError Commissioner::SendPetition(void) mNetif.GetMle().GetLeaderAloc(*static_cast(&messageInfo.mPeerAddr)); messageInfo.SetPeerPort(kCoapUdpPort); + messageInfo.SetSockAddr(mNetif.GetMle().GetMeshLocal16()); SuccessOrExit(error = mNetif.GetCoapClient().SendMessage(*message, messageInfo, Commissioner::HandleLeaderPetitionResponse, this)); diff --git a/src/core/thread/network_data_leader_ftd.cpp b/src/core/thread/network_data_leader_ftd.cpp index 479f6fbb7..45cb01a60 100644 --- a/src/core/thread/network_data_leader_ftd.cpp +++ b/src/core/thread/network_data_leader_ftd.cpp @@ -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(mTlvs + sizeof(CommissioningDataTlv)); - cur < reinterpret_cast(mTlvs + mLength); - cur = cur->GetNext()) + // Find Commissioning Data TLV + for (NetworkDataTlv *netDataTlv = reinterpret_cast(mTlvs); + netDataTlv < reinterpret_cast(mTlvs + mLength); + netDataTlv = netDataTlv->GetNext()) { - if (cur->GetType() == MeshCoP::Tlv::kCommissionerSessionId) + if (netDataTlv->GetType() == NetworkDataTlv::kTypeCommissioningData) { - VerifyOrExit(sessionId == - static_cast(cur)->GetCommissionerSessionId(), - state = MeshCoP::StateTlv::kReject); - } - else if (cur->GetType() == MeshCoP::Tlv::kBorderAgentLocator) - { - memcpy(tlvs + length, reinterpret_cast(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(netDataTlv->GetValue()); + cur < reinterpret_cast(netDataTlv->GetValue() + netDataTlv->GetLength()); + cur = cur->GetNext()) + { + if (cur->GetType() == MeshCoP::Tlv::kCommissionerSessionId) + { + VerifyOrExit(sessionId == + static_cast(cur)->GetCommissionerSessionId(), + state = MeshCoP::StateTlv::kReject); + } + else if (cur->GetType() == MeshCoP::Tlv::kBorderAgentLocator) + { + memcpy(tlvs + length, reinterpret_cast(cur), cur->GetLength() + sizeof(MeshCoP::Tlv)); + length += (cur->GetLength() + sizeof(MeshCoP::Tlv)); + } + } } }