otError PanIdQueryClient::SendQuery(uint16_t aPanId, uint32_t aChannelMask, const Ip6::Address &aAddress, otCommissionerPanIdConflictCallback aCallback, void *aContext) { ThreadNetif &netif = GetNetif(); otError error = OT_ERROR_NONE; Coap::Header header; MeshCoP::CommissionerSessionIdTlv sessionId; MeshCoP::ChannelMask0Tlv channelMask; MeshCoP::PanIdTlv panId; Ip6::MessageInfo messageInfo; Message *message = NULL; VerifyOrExit(netif.GetCommissioner().IsActive(), error = OT_ERROR_INVALID_STATE); header.Init(aAddress.IsMulticast() ? OT_COAP_TYPE_NON_CONFIRMABLE : OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST); header.SetToken(Coap::Header::kDefaultTokenLength); header.AppendUriPathOptions(OT_URI_PATH_PANID_QUERY); header.SetPayloadMarker(); VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(netif.GetCoap(), header)) != NULL, error = OT_ERROR_NO_BUFS); sessionId.Init(); sessionId.SetCommissionerSessionId(netif.GetCommissioner().GetSessionId()); SuccessOrExit(error = message->Append(&sessionId, sizeof(sessionId))); channelMask.Init(); channelMask.SetMask(aChannelMask); SuccessOrExit(error = message->Append(&channelMask, sizeof(channelMask))); panId.Init(); panId.SetPanId(aPanId); SuccessOrExit(error = message->Append(&panId, sizeof(panId))); messageInfo.SetSockAddr(netif.GetMle().GetMeshLocal16()); messageInfo.SetPeerAddr(aAddress); messageInfo.SetPeerPort(kCoapUdpPort); messageInfo.SetInterfaceId(netif.GetInterfaceId()); SuccessOrExit(error = netif.GetCoap().SendMessage(*message, messageInfo)); otLogInfoMeshCoP(GetInstance(), "sent panid query"); mCallback = aCallback; mContext = aContext; exit: if (error != OT_ERROR_NONE && message != NULL) { message->Free(); } return error; }
ThreadError Dataset::Set(const otOperationalDataset &aDataset) { ThreadError error = kThreadError_None; MeshCoP::ActiveTimestampTlv activeTimestampTlv; VerifyOrExit(aDataset.mIsActiveTimestampSet, error = kThreadError_InvalidArgs); activeTimestampTlv.Init(); activeTimestampTlv.SetSeconds(aDataset.mActiveTimestamp); activeTimestampTlv.SetTicks(0); Set(activeTimestampTlv); if (mType == Tlv::kPendingTimestamp) { MeshCoP::PendingTimestampTlv pendingTimestampTlv; VerifyOrExit(aDataset.mIsPendingTimestampSet, error = kThreadError_InvalidArgs); pendingTimestampTlv.Init(); pendingTimestampTlv.SetSeconds(aDataset.mPendingTimestamp); pendingTimestampTlv.SetTicks(0); Set(pendingTimestampTlv); if (aDataset.mIsDelaySet) { MeshCoP::DelayTimerTlv tlv; tlv.Init(); tlv.SetDelayTimer(aDataset.mDelay); Set(tlv); } } if (aDataset.mIsChannelSet) { MeshCoP::ChannelTlv tlv; tlv.Init(); tlv.SetChannelPage(0); tlv.SetChannel(aDataset.mChannel); Set(tlv); } if (aDataset.mIsChannelMaskPage0Set) { MeshCoP::ChannelMask0Tlv tlv; tlv.Init(); tlv.SetMask(aDataset.mChannelMaskPage0); Set(tlv); } if (aDataset.mIsExtendedPanIdSet) { MeshCoP::ExtendedPanIdTlv tlv; tlv.Init(); tlv.SetExtendedPanId(aDataset.mExtendedPanId.m8); Set(tlv); } if (aDataset.mIsMeshLocalPrefixSet) { MeshCoP::MeshLocalPrefixTlv tlv; tlv.Init(); tlv.SetMeshLocalPrefix(aDataset.mMeshLocalPrefix.m8); Set(tlv); } if (aDataset.mIsMasterKeySet) { MeshCoP::NetworkMasterKeyTlv tlv; tlv.Init(); tlv.SetNetworkMasterKey(aDataset.mMasterKey.m8); Set(tlv); } if (aDataset.mIsNetworkNameSet) { MeshCoP::NetworkNameTlv tlv; tlv.Init(); tlv.SetNetworkName(aDataset.mNetworkName.m8); Set(tlv); } if (aDataset.mIsPanIdSet) { MeshCoP::PanIdTlv tlv; tlv.Init(); tlv.SetPanId(aDataset.mPanId); Set(tlv); } if (aDataset.mIsPSKcSet) { MeshCoP::PSKcTlv tlv; tlv.Init(); tlv.SetPSKc(aDataset.mPSKc.m8); Set(tlv); } if (aDataset.mIsSecurityPolicySet) { MeshCoP::SecurityPolicyTlv tlv; tlv.Init(); tlv.SetRotationTime(aDataset.mSecurityPolicy.mRotationTime); tlv.SetFlags(aDataset.mSecurityPolicy.mFlags); Set(tlv); } exit: return error; }
otError Dataset::Set(const otOperationalDataset &aDataset) { otError error = OT_ERROR_NONE; MeshCoP::ActiveTimestampTlv activeTimestampTlv; VerifyOrExit(aDataset.mComponents.mIsActiveTimestampPresent, error = OT_ERROR_INVALID_ARGS); activeTimestampTlv.Init(); activeTimestampTlv.SetSeconds(aDataset.mActiveTimestamp); activeTimestampTlv.SetTicks(0); Set(activeTimestampTlv); if (mType == Tlv::kPendingTimestamp) { MeshCoP::PendingTimestampTlv pendingTimestampTlv; VerifyOrExit(aDataset.mComponents.mIsPendingTimestampPresent, error = OT_ERROR_INVALID_ARGS); pendingTimestampTlv.Init(); pendingTimestampTlv.SetSeconds(aDataset.mPendingTimestamp); pendingTimestampTlv.SetTicks(0); Set(pendingTimestampTlv); if (aDataset.mComponents.mIsDelayPresent) { MeshCoP::DelayTimerTlv tlv; tlv.Init(); tlv.SetDelayTimer(aDataset.mDelay); Set(tlv); } } if (aDataset.mComponents.mIsChannelPresent) { MeshCoP::ChannelTlv tlv; tlv.Init(); tlv.SetChannelPage(0); tlv.SetChannel(aDataset.mChannel); Set(tlv); } if (aDataset.mComponents.mIsChannelMaskPage0Present) { MeshCoP::ChannelMask0Tlv tlv; tlv.Init(); tlv.SetMask(aDataset.mChannelMaskPage0); Set(tlv); } if (aDataset.mComponents.mIsExtendedPanIdPresent) { MeshCoP::ExtendedPanIdTlv tlv; tlv.Init(); tlv.SetExtendedPanId(aDataset.mExtendedPanId); Set(tlv); } if (aDataset.mComponents.mIsMeshLocalPrefixPresent) { MeshCoP::MeshLocalPrefixTlv tlv; tlv.Init(); tlv.SetMeshLocalPrefix(aDataset.mMeshLocalPrefix.m8); Set(tlv); } if (aDataset.mComponents.mIsMasterKeyPresent) { MeshCoP::NetworkMasterKeyTlv tlv; tlv.Init(); tlv.SetNetworkMasterKey(aDataset.mMasterKey); Set(tlv); } if (aDataset.mComponents.mIsNetworkNamePresent) { MeshCoP::NetworkNameTlv tlv; tlv.Init(); tlv.SetNetworkName(aDataset.mNetworkName.m8); Set(tlv); } if (aDataset.mComponents.mIsPanIdPresent) { MeshCoP::PanIdTlv tlv; tlv.Init(); tlv.SetPanId(aDataset.mPanId); Set(tlv); } if (aDataset.mComponents.mIsPSKcPresent) { MeshCoP::PSKcTlv tlv; tlv.Init(); tlv.SetPSKc(aDataset.mPSKc.m8); Set(tlv); } if (aDataset.mComponents.mIsSecurityPolicyPresent) { MeshCoP::SecurityPolicyTlv tlv; tlv.Init(); tlv.SetRotationTime(aDataset.mSecurityPolicy.mRotationTime); tlv.SetFlags(aDataset.mSecurityPolicy.mFlags); Set(tlv); } mUpdateTime = TimerMilli::GetNow(); exit: return error; }