void Joiner::HandleJoinerFinalizeResponse(Coap::Message & aMessage, const Ip6::MessageInfo *aMessageInfo, otError aResult) { OT_UNUSED_VARIABLE(aMessageInfo); StateTlv state; VerifyOrExit(mState == OT_JOINER_STATE_CONNECTED && aResult == OT_ERROR_NONE && aMessage.GetType() == OT_COAP_TYPE_ACKNOWLEDGMENT && aMessage.GetCode() == OT_COAP_CODE_CHANGED); SuccessOrExit(Tlv::GetTlv(aMessage, Tlv::kState, sizeof(state), state)); VerifyOrExit(state.IsValid()); mState = OT_JOINER_STATE_ENTRUST; mTimer.Start(kTimeout); otLogInfoMeshCoP("received joiner finalize response %d", static_cast<uint8_t>(state.GetState())); #if OPENTHREAD_ENABLE_CERT_LOG uint8_t buf[OPENTHREAD_CONFIG_MESSAGE_BUFFER_SIZE]; VerifyOrExit(aMessage.GetLength() <= sizeof(buf)); aMessage.Read(aMessage.GetOffset(), aMessage.GetLength() - aMessage.GetOffset(), buf); otDumpCertMeshCoP("[THCI] direction=recv | type=JOIN_FIN.rsp |", buf, aMessage.GetLength() - aMessage.GetOffset()); #endif exit: Close(); }
otError Leader::SendKeepAliveResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aMessageInfo, StateTlv::State aState) { ThreadNetif &netif = GetNetif(); otError error = OT_ERROR_NONE; Coap::Header responseHeader; StateTlv state; Message *message; responseHeader.SetDefaultResponseHeader(aRequestHeader); responseHeader.SetPayloadMarker(); VerifyOrExit((message = NewMeshCoPMessage(netif.GetCoap(), responseHeader)) != NULL, error = OT_ERROR_NO_BUFS); state.Init(); state.SetState(aState); SuccessOrExit(error = message->Append(&state, sizeof(state))); SuccessOrExit(error = netif.GetCoap().SendMessage(*message, aMessageInfo)); otLogInfoMeshCoP(GetInstance(), "sent keep alive response"); exit: if (error != OT_ERROR_NONE && message != NULL) { message->Free(); } return error; }
void Leader::HandleKeepAlive(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo) { StateTlv state; CommissionerSessionIdTlv sessionId; StateTlv::State responseState; otLogInfoMeshCoP(GetInstance(), "received keep alive"); SuccessOrExit(Tlv::GetTlv(aMessage, Tlv::kState, sizeof(state), state)); VerifyOrExit(state.IsValid()); SuccessOrExit(Tlv::GetTlv(aMessage, Tlv::kCommissionerSessionId, sizeof(sessionId), sessionId)); VerifyOrExit(sessionId.IsValid()); if (sessionId.GetCommissionerSessionId() != mSessionId) { responseState = StateTlv::kReject; } else if (state.GetState() != StateTlv::kAccept) { responseState = StateTlv::kReject; ResignCommissioner(); } else { responseState = StateTlv::kAccept; mTimer.Start(TimerMilli::SecToMsec(kTimeoutLeaderPetition)); } SendKeepAliveResponse(aHeader, aMessageInfo, responseState); exit: return; }
otError Leader::SendPetitionResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aMessageInfo, StateTlv::State aState) { ThreadNetif &netif = GetNetif(); otError error = OT_ERROR_NONE; Coap::Header responseHeader; StateTlv state; CommissionerSessionIdTlv sessionId; Message *message; responseHeader.SetDefaultResponseHeader(aRequestHeader); responseHeader.SetPayloadMarker(); VerifyOrExit((message = NewMeshCoPMessage(netif.GetCoap(), responseHeader)) != NULL, error = OT_ERROR_NO_BUFS); state.Init(); state.SetState(aState); SuccessOrExit(error = message->Append(&state, sizeof(state))); if (mTimer.IsRunning()) { uint16_t len = sizeof(Tlv) + mCommissionerId.GetLength(); SuccessOrExit(error = message->Append(&mCommissionerId, len)); } if (aState == StateTlv::kAccept) { sessionId.Init(); sessionId.SetCommissionerSessionId(mSessionId); SuccessOrExit(error = message->Append(&sessionId, sizeof(sessionId))); } SuccessOrExit(error = netif.GetCoap().SendMessage(*message, aMessageInfo)); otLogInfoMeshCoP(GetInstance(), "sent petition response"); exit: if (error != OT_ERROR_NONE && message != NULL) { message->Free(); } return error; }
void Joiner::SendJoinerFinalize(void) { Coap::Header header; StateTlv *stateTlv; uint8_t length; uint8_t buf[128]; uint8_t *cur = buf; otLogFuncEntry(); header.Init(kCoapTypeConfirmable, kCoapRequestPost); header.SetMessageId(0); header.SetToken(NULL, 0); header.AppendUriPathOptions(OPENTHREAD_URI_JOINER_FINALIZE); header.SetPayloadMarker(); memcpy(cur, header.GetBytes(), header.GetLength()); cur += header.GetLength(); stateTlv = reinterpret_cast<MeshCoP::StateTlv *>(cur); stateTlv->Init(); stateTlv->SetState(MeshCoP::StateTlv::kAccept); cur += sizeof(*stateTlv); length = mNetif.GetDtls().mProvisioningUrl.GetLength(); if (length > 0) { length += sizeof(Tlv); memcpy(cur, &mNetif.GetDtls().mProvisioningUrl, length); cur += length; } mNetif.GetDtls().Send(buf, static_cast<uint16_t>(cur - buf)); otLogInfoMeshCoP("Sent joiner finalize"); otDumpCertMeshCoP("[THCI] direction=send | type=JOIN_FIN.req |", buf + header.GetLength(), cur - buf - header.GetLength()); otLogFuncExit(); }
void Joiner::SendJoinerFinalize(void) { ThreadNetif & netif = GetNetif(); otError error = OT_ERROR_NONE; Coap::Message * message = NULL; StateTlv stateTlv; VendorNameTlv vendorNameTlv; VendorModelTlv vendorModelTlv; VendorSwVersionTlv vendorSwVersionTlv; VendorStackVersionTlv vendorStackVersionTlv; VerifyOrExit((message = NewMeshCoPMessage(netif.GetCoapSecure())) != NULL, error = OT_ERROR_NO_BUFS); message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST); message->AppendUriPathOptions(OT_URI_PATH_JOINER_FINALIZE); message->SetPayloadMarker(); message->SetOffset(message->GetLength()); stateTlv.Init(); stateTlv.SetState(MeshCoP::StateTlv::kAccept); SuccessOrExit(error = message->Append(&stateTlv, sizeof(stateTlv))); vendorNameTlv.Init(); vendorNameTlv.SetVendorName(mVendorName); SuccessOrExit(error = message->Append(&vendorNameTlv, vendorNameTlv.GetSize())); vendorModelTlv.Init(); vendorModelTlv.SetVendorModel(mVendorModel); SuccessOrExit(error = message->Append(&vendorModelTlv, vendorModelTlv.GetSize())); vendorSwVersionTlv.Init(); vendorSwVersionTlv.SetVendorSwVersion(mVendorSwVersion); SuccessOrExit(error = message->Append(&vendorSwVersionTlv, vendorSwVersionTlv.GetSize())); vendorStackVersionTlv.Init(); vendorStackVersionTlv.SetOui(OPENTHREAD_CONFIG_STACK_VENDOR_OUI); vendorStackVersionTlv.SetMajor(OPENTHREAD_CONFIG_STACK_VERSION_MAJOR); vendorStackVersionTlv.SetMinor(OPENTHREAD_CONFIG_STACK_VERSION_MINOR); vendorStackVersionTlv.SetRevision(OPENTHREAD_CONFIG_STACK_VERSION_REV); SuccessOrExit(error = message->Append(&vendorStackVersionTlv, vendorStackVersionTlv.GetSize())); if (mVendorData != NULL) { VendorDataTlv vendorDataTlv; vendorDataTlv.Init(); vendorDataTlv.SetVendorData(mVendorData); SuccessOrExit(error = message->Append(&vendorDataTlv, vendorDataTlv.GetSize())); } if (netif.GetCoapSecure().GetDtls().mProvisioningUrl.GetLength() > 0) { SuccessOrExit(error = message->Append(&netif.GetCoapSecure().GetDtls().mProvisioningUrl, netif.GetCoapSecure().GetDtls().mProvisioningUrl.GetSize())); } #if OPENTHREAD_ENABLE_CERT_LOG uint8_t buf[OPENTHREAD_CONFIG_MESSAGE_BUFFER_SIZE]; VerifyOrExit(message->GetLength() <= sizeof(buf)); message->Read(message->GetOffset(), message->GetLength() - message->GetOffset(), buf); otDumpCertMeshCoP("[THCI] direction=send | type=JOIN_FIN.req |", buf, message->GetLength() - message->GetOffset()); #endif SuccessOrExit(error = netif.GetCoapSecure().SendMessage(*message, Joiner::HandleJoinerFinalizeResponse, this)); otLogInfoMeshCoP("Sent joiner finalize"); exit: if (error != OT_ERROR_NONE && message != NULL) { message->Free(); } }