mirror of
https://github.com/espressif/openthread.git
synced 2026-07-30 07:37:46 +00:00
Refine API for creating CoAP message (#1584)
* merge two CoAP api for new message * decouple CoAP and MeshCoP * create a wrapper for creating meshcop message * create meshcop.hpp
This commit is contained in:
@@ -299,6 +299,7 @@ noinst_HEADERS = \
|
||||
meshcop/leader.hpp \
|
||||
meshcop/leader_ftd.hpp \
|
||||
meshcop/leader_mtd.hpp \
|
||||
meshcop/meshcop.hpp \
|
||||
meshcop/panid_query_client.hpp \
|
||||
meshcop/timestamp.hpp \
|
||||
meshcop/tlvs.hpp \
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
namespace Thread {
|
||||
namespace Coap {
|
||||
|
||||
Message *CoapBase::NewMessage(const Header &aHeader)
|
||||
Message *CoapBase::NewMessage(const Header &aHeader, uint8_t aPriority)
|
||||
{
|
||||
Message *message = NULL;
|
||||
|
||||
@@ -47,18 +47,7 @@ Message *CoapBase::NewMessage(const Header &aHeader)
|
||||
VerifyOrExit((message = mSocket.NewMessage(aHeader.GetLength())) != NULL);
|
||||
message->Prepend(aHeader.GetBytes(), aHeader.GetLength());
|
||||
message->SetOffset(0);
|
||||
|
||||
exit:
|
||||
return message;
|
||||
}
|
||||
|
||||
Message *CoapBase::NewMeshCoPMessage(const Header &aHeader)
|
||||
{
|
||||
Message *message = NULL;
|
||||
|
||||
VerifyOrExit((message = NewMessage(aHeader)) != NULL);
|
||||
|
||||
message->SetPriority(kMeshCoPMessagePriority);
|
||||
message->SetPriority(aPriority);
|
||||
|
||||
exit:
|
||||
return message;
|
||||
|
||||
@@ -77,12 +77,6 @@ enum
|
||||
kNonLifetime = kMaxTransmitSpan + kMaxLatency
|
||||
};
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
kMeshCoPMessagePriority = Message::kPriorityHigh, // The priority for MeshCoP message
|
||||
};
|
||||
|
||||
/**
|
||||
* This class implements a common code base for CoAP client/server.
|
||||
*
|
||||
@@ -127,22 +121,13 @@ public:
|
||||
/**
|
||||
* This method creates a new message with a CoAP header.
|
||||
*
|
||||
* @param[in] aHeader A reference to a CoAP header that is used to create the message.
|
||||
* @param[in] aHeader A reference to a CoAP header that is used to create the message.
|
||||
* @param[in] aPrority The message priority level.
|
||||
*
|
||||
* @returns A pointer to the message or NULL if failed to allocate message.
|
||||
*
|
||||
*/
|
||||
Message *NewMessage(const Header &aHeader);
|
||||
|
||||
/**
|
||||
* This method creates a new MeshCoP message with a CoAP header.
|
||||
*
|
||||
* @param[in] aHeader A reference to a CoAP header that is used to create the message.
|
||||
*
|
||||
* @returns A pointer to the MeshCoP message or NULL if failed to allocate message.
|
||||
*
|
||||
*/
|
||||
Message *NewMeshCoPMessage(const Header &aHeader);
|
||||
Message *NewMessage(const Header &aHeader, uint8_t aPriority = kDefaultCoapMessagePriority);
|
||||
|
||||
/**
|
||||
* This method returns a port number used by CoAP client.
|
||||
@@ -191,7 +176,6 @@ protected:
|
||||
ReceiverFunction mReceiver;
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* This method sends a CoAP empty message, i.e. a header-only message with code equals kCoapCodeEmpty.
|
||||
*
|
||||
@@ -207,6 +191,11 @@ private:
|
||||
ThreadError SendEmptyMessage(Header::Type aType, const Header &aRequestHeader,
|
||||
const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
enum
|
||||
{
|
||||
kDefaultCoapMessagePriority = Message::kPriorityLow,
|
||||
};
|
||||
|
||||
static void HandleUdpReceive(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo);
|
||||
};
|
||||
|
||||
|
||||
@@ -99,23 +99,6 @@ exit:
|
||||
aResource.mNext = NULL;
|
||||
}
|
||||
|
||||
Message *Server::NewMessage(uint16_t aReserved)
|
||||
{
|
||||
return mSocket.NewMessage(aReserved);
|
||||
}
|
||||
|
||||
Message *Server::NewMeshCoPMessage(uint16_t aReserved)
|
||||
{
|
||||
Message *message = NULL;
|
||||
|
||||
VerifyOrExit((message = NewMessage(aReserved)) != NULL);
|
||||
|
||||
message->SetPriority(kMeshCoPMessagePriority);
|
||||
|
||||
exit:
|
||||
return message;
|
||||
}
|
||||
|
||||
ThreadError Server::SendMessage(Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||
{
|
||||
mResponsesQueue.EnqueueResponse(aMessage, aMessageInfo);
|
||||
|
||||
@@ -334,46 +334,6 @@ public:
|
||||
*/
|
||||
void RemoveResource(Resource &aResource);
|
||||
|
||||
/**
|
||||
* This method returns a new UDP message with sufficient header space reserved.
|
||||
*
|
||||
* @param[in] aReserved The number of header bytes to reserve after the UDP header.
|
||||
*
|
||||
* @returns A pointer to the message or NULL if no buffers are available.
|
||||
*
|
||||
*/
|
||||
Message *NewMessage(uint16_t aReserved);
|
||||
|
||||
/**
|
||||
* This method returns a new MeshCoP message with sufficient header space reserved.
|
||||
*
|
||||
* @param[in] aReserved The number of header bytes to reserve after the UDP header.
|
||||
*
|
||||
* @returns A pointer to the MeshCoP message or NULL if no buffers are available.
|
||||
*
|
||||
*/
|
||||
Message *NewMeshCoPMessage(uint16_t aReserved);
|
||||
|
||||
/**
|
||||
* This method creates a new message with a CoAP header.
|
||||
*
|
||||
* @param[in] aHeader A reference to a CoAP header that is used to create the message.
|
||||
*
|
||||
* @returns A pointer to the message or NULL if failed to allocate message.
|
||||
*
|
||||
*/
|
||||
Message *NewMessage(const Header &aHeader) { return CoapBase::NewMessage(aHeader); };
|
||||
|
||||
/**
|
||||
* This method creates a new MeshCoP message with a CoAP header.
|
||||
*
|
||||
* @param[in] aHeader A reference to a CoAP header that is used to create the message.
|
||||
*
|
||||
* @returns A pointer to the MeshCoP message or NULL if failed to allocate message.
|
||||
*
|
||||
*/
|
||||
Message *NewMeshCoPMessage(const Header &aHeader) { return CoapBase::NewMeshCoPMessage(aHeader); };
|
||||
|
||||
/**
|
||||
* This method sends a CoAP response from the server.
|
||||
*
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
#include <common/debug.hpp>
|
||||
#include <common/logging.hpp>
|
||||
#include <meshcop/announce_begin_client.hpp>
|
||||
#include <meshcop/meshcop.hpp>
|
||||
#include <meshcop/tlvs.hpp>
|
||||
#include <thread/thread_netif.hpp>
|
||||
#include <thread/thread_uris.hpp>
|
||||
@@ -81,7 +82,8 @@ ThreadError AnnounceBeginClient::SendRequest(uint32_t aChannelMask, uint8_t aCou
|
||||
header.AppendUriPathOptions(OPENTHREAD_URI_ANNOUNCE_BEGIN);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = mNetif.GetCoapClient().NewMeshCoPMessage(header)) != NULL, error = kThreadError_NoBufs);
|
||||
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(mNetif.GetCoapClient(), header)) != NULL,
|
||||
error = kThreadError_NoBufs);
|
||||
|
||||
sessionId.Init();
|
||||
sessionId.SetCommissionerSessionId(mNetif.GetCommissioner().GetSessionId());
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
#include <crypto/pbkdf2_cmac.h>
|
||||
#include <meshcop/commissioner.hpp>
|
||||
#include <meshcop/joiner_router.hpp>
|
||||
#include <meshcop/meshcop.hpp>
|
||||
#include <meshcop/tlvs.hpp>
|
||||
#include <thread/thread_netif.hpp>
|
||||
#include <thread/thread_tlvs.hpp>
|
||||
@@ -424,7 +425,8 @@ ThreadError Commissioner::SendMgmtCommissionerGetRequest(const uint8_t *aTlvs,
|
||||
header.SetPayloadMarker();
|
||||
}
|
||||
|
||||
VerifyOrExit((message = mNetif.GetCoapClient().NewMeshCoPMessage(header)) != NULL, error = kThreadError_NoBufs);
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoapClient(), header)) != NULL,
|
||||
error = kThreadError_NoBufs);
|
||||
|
||||
if (aLength > 0)
|
||||
{
|
||||
@@ -490,7 +492,8 @@ ThreadError Commissioner::SendMgmtCommissionerSetRequest(const otCommissioningDa
|
||||
header.AppendUriPathOptions(OPENTHREAD_URI_COMMISSIONER_SET);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = mNetif.GetCoapClient().NewMeshCoPMessage(header)) != NULL, error = kThreadError_NoBufs);
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoapClient(), header)) != NULL,
|
||||
error = kThreadError_NoBufs);
|
||||
|
||||
if (aDataset.mIsLocatorSet)
|
||||
{
|
||||
@@ -594,7 +597,9 @@ ThreadError Commissioner::SendPetition(void)
|
||||
header.AppendUriPathOptions(OPENTHREAD_URI_LEADER_PETITION);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = mNetif.GetCoapClient().NewMeshCoPMessage(header)) != NULL, error = kThreadError_NoBufs);
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoapClient(), header)) != NULL,
|
||||
error = kThreadError_NoBufs);
|
||||
|
||||
commissionerId.Init();
|
||||
commissionerId.SetCommissionerId("OpenThread Commissioner");
|
||||
|
||||
@@ -695,7 +700,8 @@ ThreadError Commissioner::SendKeepAlive(void)
|
||||
header.AppendUriPathOptions(OPENTHREAD_URI_LEADER_KEEP_ALIVE);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = mNetif.GetCoapClient().NewMeshCoPMessage(header)) != NULL, error = kThreadError_NoBufs);
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoapClient(), header)) != NULL,
|
||||
error = kThreadError_NoBufs);
|
||||
|
||||
state.Init();
|
||||
state.SetState(mState == kCommissionerStateActive ? StateTlv::kAccept : StateTlv::kReject);
|
||||
@@ -935,7 +941,7 @@ void Commissioner::SendJoinFinalizeResponse(const Coap::Header &aRequestHeader,
|
||||
responseHeader.SetDefaultResponseHeader(aRequestHeader);
|
||||
responseHeader.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = mNetif.GetSecureCoapServer().NewMeshCoPMessage(responseHeader)) != NULL,
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetSecureCoapServer(), responseHeader)) != NULL,
|
||||
error = kThreadError_NoBufs);
|
||||
|
||||
message->SetSubType(Message::kSubTypeJoinerFinalizeResponse);
|
||||
@@ -998,7 +1004,8 @@ ThreadError Commissioner::SendRelayTransmit(Message &aMessage, const Ip6::Messag
|
||||
header.AppendUriPathOptions(OPENTHREAD_URI_RELAY_TX);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = mNetif.GetCoapClient().NewMeshCoPMessage(header)) != NULL, error = kThreadError_NoBufs);
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoapClient(), header)) != NULL,
|
||||
error = kThreadError_NoBufs);
|
||||
|
||||
udpPort.Init();
|
||||
udpPort.SetUdpPort(mJoinerPort);
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#include <common/timer.hpp>
|
||||
#include <meshcop/dataset.hpp>
|
||||
#include <meshcop/dataset_manager.hpp>
|
||||
#include <meshcop/meshcop.hpp>
|
||||
#include <meshcop/tlvs.hpp>
|
||||
#include <thread/thread_netif.hpp>
|
||||
#include <thread/thread_tlvs.hpp>
|
||||
@@ -294,7 +295,8 @@ ThreadError DatasetManager::Register(void)
|
||||
pending->UpdateDelayTimer();
|
||||
}
|
||||
|
||||
VerifyOrExit((message = mNetif.GetCoapClient().NewMeshCoPMessage(header)) != NULL, error = kThreadError_NoBufs);
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoapClient(), header)) != NULL,
|
||||
error = kThreadError_NoBufs);
|
||||
|
||||
SuccessOrExit(error = message->Append(mLocal.GetBytes(), mLocal.GetSize()));
|
||||
|
||||
@@ -580,7 +582,8 @@ ThreadError DatasetManager::SendSetRequest(const otOperationalDataset &aDataset,
|
||||
header.AppendUriPathOptions(mUriSet);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = mNetif.GetCoapClient().NewMeshCoPMessage(header)) != NULL, error = kThreadError_NoBufs);
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoapClient(), header)) != NULL,
|
||||
error = kThreadError_NoBufs);
|
||||
|
||||
#if OPENTHREAD_ENABLE_COMMISSIONER
|
||||
bool isCommissioner;
|
||||
@@ -745,7 +748,9 @@ ThreadError DatasetManager::SendGetRequest(const uint8_t *aTlvTypes, const uint8
|
||||
header.SetPayloadMarker();
|
||||
}
|
||||
|
||||
VerifyOrExit((message = mNetif.GetCoapClient().NewMeshCoPMessage(header)) != NULL, error = kThreadError_NoBufs);
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoapClient(), header)) != NULL,
|
||||
error = kThreadError_NoBufs);
|
||||
|
||||
|
||||
if (aLength > 0)
|
||||
{
|
||||
@@ -787,12 +792,11 @@ void DatasetManager::SendSetResponse(const Coap::Header &aRequestHeader, const I
|
||||
Message *message;
|
||||
StateTlv state;
|
||||
|
||||
VerifyOrExit((message = mNetif.GetCoapServer().NewMeshCoPMessage(0)) != NULL, error = kThreadError_NoBufs);
|
||||
|
||||
responseHeader.SetDefaultResponseHeader(aRequestHeader);
|
||||
responseHeader.SetPayloadMarker();
|
||||
|
||||
SuccessOrExit(error = message->Append(responseHeader.GetBytes(), responseHeader.GetLength()));
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoapServer(), responseHeader)) != NULL,
|
||||
error = kThreadError_NoBufs);
|
||||
|
||||
state.Init();
|
||||
state.SetState(aState);
|
||||
@@ -819,12 +823,12 @@ void DatasetManager::SendGetResponse(const Coap::Header &aRequestHeader, const I
|
||||
Message *message;
|
||||
uint8_t index;
|
||||
|
||||
VerifyOrExit((message = mNetif.GetCoapServer().NewMeshCoPMessage(0)) != NULL, error = kThreadError_NoBufs);
|
||||
|
||||
responseHeader.SetDefaultResponseHeader(aRequestHeader);
|
||||
responseHeader.SetPayloadMarker();
|
||||
|
||||
SuccessOrExit(error = message->Append(responseHeader.GetBytes(), responseHeader.GetLength()));
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoapServer(), responseHeader)) != NULL,
|
||||
error = kThreadError_NoBufs);
|
||||
|
||||
if (aLength == 0)
|
||||
{
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include <common/encoding.hpp>
|
||||
#include <common/logging.hpp>
|
||||
#include <meshcop/energy_scan_client.hpp>
|
||||
#include <meshcop/meshcop.hpp>
|
||||
#include <meshcop/tlvs.hpp>
|
||||
#include <thread/thread_netif.hpp>
|
||||
#include <thread/thread_uris.hpp>
|
||||
@@ -84,7 +85,8 @@ ThreadError EnergyScanClient::SendQuery(uint32_t aChannelMask, uint8_t aCount, u
|
||||
header.AppendUriPathOptions(OPENTHREAD_URI_ENERGY_SCAN);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = mNetif.GetCoapClient().NewMeshCoPMessage(header)) != NULL, error = kThreadError_NoBufs);
|
||||
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(mNetif.GetCoapClient(), header)) != NULL,
|
||||
error = kThreadError_NoBufs);
|
||||
|
||||
sessionId.Init();
|
||||
sessionId.SetCommissionerSessionId(mNetif.GetCommissioner().GetSessionId());
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
#include <common/logging.hpp>
|
||||
#include <mac/mac_frame.hpp>
|
||||
#include <meshcop/joiner.hpp>
|
||||
#include <meshcop/meshcop.hpp>
|
||||
#include <thread/thread_netif.hpp>
|
||||
#include <thread/thread_uris.hpp>
|
||||
|
||||
@@ -272,7 +273,7 @@ void Joiner::SendJoinerFinalize(void)
|
||||
header.AppendUriPathOptions(OPENTHREAD_URI_JOINER_FINALIZE);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = mNetif.GetSecureCoapClient().NewMeshCoPMessage(header)) != NULL,
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetSecureCoapClient(), header)) != NULL,
|
||||
error = kThreadError_NoBufs);
|
||||
|
||||
stateTlv.Init();
|
||||
@@ -449,12 +450,11 @@ void Joiner::SendJoinerEntrustResponse(const Coap::Header &aRequestHeader,
|
||||
|
||||
otLogFuncEntry();
|
||||
|
||||
VerifyOrExit((message = mNetif.GetCoapServer().NewMeshCoPMessage(0)) != NULL, error = kThreadError_NoBufs);
|
||||
message->SetSubType(Message::kSubTypeJoinerEntrust);
|
||||
|
||||
responseHeader.SetDefaultResponseHeader(aRequestHeader);
|
||||
|
||||
SuccessOrExit(error = message->Append(responseHeader.GetBytes(), responseHeader.GetLength()));
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoapServer(), responseHeader)) != NULL,
|
||||
error = kThreadError_NoBufs);
|
||||
message->SetSubType(Message::kSubTypeJoinerEntrust);
|
||||
|
||||
memset(&responseInfo.mSockAddr, 0, sizeof(responseInfo.mSockAddr));
|
||||
SuccessOrExit(error = mNetif.GetCoapServer().SendMessage(*message, responseInfo));
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include <common/encoding.hpp>
|
||||
#include <common/logging.hpp>
|
||||
#include <meshcop/joiner_router.hpp>
|
||||
#include <meshcop/meshcop.hpp>
|
||||
#include <meshcop/tlvs.hpp>
|
||||
#include <thread/mle.hpp>
|
||||
#include <thread/thread_netif.hpp>
|
||||
@@ -179,7 +180,8 @@ void JoinerRouter::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &a
|
||||
header.AppendUriPathOptions(OPENTHREAD_URI_RELAY_RX);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = mNetif.GetCoapClient().NewMeshCoPMessage(header)) != NULL, error = kThreadError_NoBufs);
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoapClient(), header)) != NULL,
|
||||
error = kThreadError_NoBufs);
|
||||
|
||||
udpPort.Init();
|
||||
udpPort.SetUdpPort(aMessageInfo.GetPeerPort());
|
||||
@@ -265,7 +267,7 @@ void JoinerRouter::HandleRelayTransmit(Coap::Header &aHeader, Message &aMessage,
|
||||
SuccessOrExit(error = Tlv::GetValueOffset(aMessage, Tlv::kJoinerDtlsEncapsulation, offset, length));
|
||||
|
||||
VerifyOrExit((message = mSocket.NewMessage(0)) != NULL, error = kThreadError_NoBufs);
|
||||
message->SetPriority(Coap::kMeshCoPMessagePriority);
|
||||
message->SetPriority(kMeshCoPMessagePriority);
|
||||
message->SetLinkSecurityEnabled(false);
|
||||
|
||||
while (length)
|
||||
@@ -336,7 +338,8 @@ ThreadError JoinerRouter::DelaySendingJoinerEntrust(const Ip6::MessageInfo &aMes
|
||||
header.AppendUriPathOptions(OPENTHREAD_URI_JOINER_ENTRUST);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = mNetif.GetCoapClient().NewMeshCoPMessage(header)) != NULL, error = kThreadError_NoBufs);
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoapClient(), header)) != NULL,
|
||||
error = kThreadError_NoBufs);
|
||||
message->SetSubType(Message::kSubTypeJoinerEntrust);
|
||||
|
||||
masterKey.Init();
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include <common/code_utils.hpp>
|
||||
#include <common/logging.hpp>
|
||||
#include <meshcop/leader.hpp>
|
||||
#include <meshcop/meshcop.hpp>
|
||||
#include <meshcop/tlvs.hpp>
|
||||
#include <thread/thread_netif.hpp>
|
||||
#include <thread/thread_tlvs.hpp>
|
||||
@@ -118,12 +119,11 @@ ThreadError Leader::SendPetitionResponse(const Coap::Header &aRequestHeader, con
|
||||
CommissionerSessionIdTlv sessionId;
|
||||
Message *message;
|
||||
|
||||
VerifyOrExit((message = mNetif.GetCoapServer().NewMeshCoPMessage(0)) != NULL, error = kThreadError_NoBufs);
|
||||
|
||||
responseHeader.SetDefaultResponseHeader(aRequestHeader);
|
||||
responseHeader.SetPayloadMarker();
|
||||
|
||||
SuccessOrExit(error = message->Append(responseHeader.GetBytes(), responseHeader.GetLength()));
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoapServer(), responseHeader)) != NULL,
|
||||
error = kThreadError_NoBufs);
|
||||
|
||||
state.Init();
|
||||
state.SetState(aState);
|
||||
@@ -208,12 +208,12 @@ ThreadError Leader::SendKeepAliveResponse(const Coap::Header &aRequestHeader, co
|
||||
StateTlv state;
|
||||
Message *message;
|
||||
|
||||
VerifyOrExit((message = mNetif.GetCoapServer().NewMeshCoPMessage(0)) != NULL, error = kThreadError_NoBufs);
|
||||
|
||||
responseHeader.SetDefaultResponseHeader(aRequestHeader);
|
||||
responseHeader.SetPayloadMarker();
|
||||
|
||||
SuccessOrExit(error = message->Append(responseHeader.GetBytes(), responseHeader.GetLength()));
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoapServer(), responseHeader)) != NULL,
|
||||
error = kThreadError_NoBufs);
|
||||
|
||||
state.Init();
|
||||
state.SetState(aState);
|
||||
@@ -244,7 +244,8 @@ ThreadError Leader::SendDatasetChanged(const Ip6::Address &aAddress)
|
||||
header.SetToken(Coap::Header::kDefaultTokenLength);
|
||||
header.AppendUriPathOptions(OPENTHREAD_URI_DATASET_CHANGED);
|
||||
|
||||
VerifyOrExit((message = mNetif.GetCoapClient().NewMeshCoPMessage(header)) != NULL, error = kThreadError_NoBufs);
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoapClient(), header)) != NULL,
|
||||
error = kThreadError_NoBufs);
|
||||
|
||||
messageInfo.SetPeerAddr(aAddress);
|
||||
messageInfo.SetPeerPort(kCoapUdpPort);
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2016, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file includes definitions for MeshCoP.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MESHCOP_HPP_
|
||||
#define MESHCOP_HPP_
|
||||
|
||||
#include <common/message.hpp>
|
||||
#include <coap/coap_base.hpp>
|
||||
|
||||
namespace Thread {
|
||||
namespace MeshCoP {
|
||||
|
||||
enum
|
||||
{
|
||||
kMeshCoPMessagePriority = Message::kPriorityHigh, // The priority for MeshCoP message
|
||||
};
|
||||
|
||||
/**
|
||||
* This function create Message for MeshCoP
|
||||
*
|
||||
*/
|
||||
inline Message* NewMeshCoPMessage(Coap::CoapBase &aCoapBase, const Coap::Header &aHeader)
|
||||
{
|
||||
return aCoapBase.NewMessage(aHeader, kMeshCoPMessagePriority);
|
||||
}
|
||||
|
||||
|
||||
} // namespace MeshCoP
|
||||
|
||||
} // namespace Thread
|
||||
|
||||
#endif // MESHCOP_HPP_
|
||||
@@ -40,6 +40,7 @@
|
||||
#include <common/debug.hpp>
|
||||
#include <common/logging.hpp>
|
||||
#include <meshcop/panid_query_client.hpp>
|
||||
#include <meshcop/meshcop.hpp>
|
||||
#include <meshcop/tlvs.hpp>
|
||||
#include <thread/thread_netif.hpp>
|
||||
#include <thread/thread_uris.hpp>
|
||||
@@ -77,7 +78,8 @@ ThreadError PanIdQueryClient::SendQuery(uint16_t aPanId, uint32_t aChannelMask,
|
||||
header.AppendUriPathOptions(OPENTHREAD_URI_PANID_QUERY);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = mNetif.GetCoapClient().NewMeshCoPMessage(header)) != NULL, error = kThreadError_NoBufs);
|
||||
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(mNetif.GetCoapClient(), header)) != NULL,
|
||||
error = kThreadError_NoBufs);
|
||||
|
||||
sessionId.Init();
|
||||
sessionId.SetCommissionerSessionId(mNetif.GetCommissioner().GetSessionId());
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include <common/code_utils.hpp>
|
||||
#include <common/debug.hpp>
|
||||
#include <common/logging.hpp>
|
||||
#include <meshcop/meshcop.hpp>
|
||||
#include <meshcop/tlvs.hpp>
|
||||
#include <thread/energy_scan_server.hpp>
|
||||
#include <thread/thread_netif.hpp>
|
||||
@@ -195,7 +196,8 @@ ThreadError EnergyScanServer::SendReport(void)
|
||||
header.AppendUriPathOptions(OPENTHREAD_URI_ENERGY_REPORT);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = mNetif.GetCoapClient().NewMeshCoPMessage(header)) != NULL, error = kThreadError_NoBufs);
|
||||
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(mNetif.GetCoapClient(), header)) != NULL,
|
||||
error = kThreadError_NoBufs);
|
||||
|
||||
channelMask.Init();
|
||||
channelMask.SetMask(mChannelMask);
|
||||
|
||||
@@ -3945,12 +3945,10 @@ void MleRouter::SendAddressSolicitResponse(const Coap::Header &aRequestHeader, u
|
||||
ThreadRloc16Tlv rlocTlv;
|
||||
Message *message;
|
||||
|
||||
VerifyOrExit((message = mNetif.GetCoapServer().NewMessage(0)) != NULL, error = kThreadError_NoBufs);
|
||||
|
||||
responseHeader.SetDefaultResponseHeader(aRequestHeader);
|
||||
responseHeader.SetPayloadMarker();
|
||||
|
||||
SuccessOrExit(error = message->Append(responseHeader.GetBytes(), responseHeader.GetLength()));
|
||||
VerifyOrExit((message = mNetif.GetCoapServer().NewMessage(responseHeader)) != NULL, error = kThreadError_NoBufs);
|
||||
|
||||
statusTlv.Init();
|
||||
statusTlv.SetStatus(!IsRouterIdValid(aRouterId) ? statusTlv.kNoAddressAvailable : statusTlv.kSuccess);
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include <common/message.hpp>
|
||||
#include <common/timer.hpp>
|
||||
#include <mac/mac_frame.hpp>
|
||||
#include <meshcop/meshcop.hpp>
|
||||
#include <thread/mle_router.hpp>
|
||||
#include <thread/network_data_leader.hpp>
|
||||
#include <thread/thread_netif.hpp>
|
||||
@@ -311,12 +312,11 @@ void Leader::SendCommissioningGetResponse(const Coap::Header &aRequestHeader, co
|
||||
uint8_t *data = NULL;
|
||||
uint8_t length = 0;
|
||||
|
||||
VerifyOrExit((message = mNetif.GetCoapServer().NewMeshCoPMessage(0)) != NULL, error = kThreadError_NoBufs);
|
||||
|
||||
responseHeader.SetDefaultResponseHeader(aRequestHeader);
|
||||
responseHeader.SetPayloadMarker();
|
||||
|
||||
SuccessOrExit(error = message->Append(responseHeader.GetBytes(), responseHeader.GetLength()));
|
||||
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(mNetif.GetCoapServer(), responseHeader)) != NULL,
|
||||
error = kThreadError_NoBufs);
|
||||
|
||||
for (NetworkDataTlv *cur = reinterpret_cast<NetworkDataTlv *>(mTlvs);
|
||||
cur < reinterpret_cast<NetworkDataTlv *>(mTlvs + mLength);
|
||||
@@ -379,12 +379,11 @@ void Leader::SendCommissioningSetResponse(const Coap::Header &aRequestHeader, co
|
||||
Message *message;
|
||||
MeshCoP::StateTlv state;
|
||||
|
||||
VerifyOrExit((message = mNetif.GetCoapServer().NewMeshCoPMessage(0)) != NULL, error = kThreadError_NoBufs);
|
||||
|
||||
responseHeader.SetDefaultResponseHeader(aRequestHeader);
|
||||
responseHeader.SetPayloadMarker();
|
||||
|
||||
SuccessOrExit(error = message->Append(responseHeader.GetBytes(), responseHeader.GetLength()));
|
||||
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(mNetif.GetCoapServer(), responseHeader)) != NULL,
|
||||
error = kThreadError_NoBufs);
|
||||
|
||||
state.Init();
|
||||
state.SetState(aState);
|
||||
|
||||
@@ -514,12 +514,10 @@ void NetworkDiagnostic::HandleDiagnosticGetRequest(Coap::Header &aHeader, Messag
|
||||
|
||||
VerifyOrExit((static_cast<TypeListTlv *>(&networkDiagnosticTlv)->IsValid()), error = kThreadError_Drop);
|
||||
|
||||
VerifyOrExit((message = mNetif.GetCoapServer().NewMessage(0)) != NULL, error = kThreadError_NoBufs);
|
||||
|
||||
header.SetDefaultResponseHeader(aHeader);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
SuccessOrExit(error = message->Append(header.GetBytes(), header.GetLength()));
|
||||
VerifyOrExit((message = mNetif.GetCoapServer().NewMessage(header)) != NULL, error = kThreadError_NoBufs);
|
||||
|
||||
SuccessOrExit(error = FillRequestedTlvs(aMessage, *message, networkDiagnosticTlv));
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include <common/code_utils.hpp>
|
||||
#include <common/debug.hpp>
|
||||
#include <common/logging.hpp>
|
||||
#include <meshcop/meshcop.hpp>
|
||||
#include <meshcop/tlvs.hpp>
|
||||
#include <thread/panid_query_server.hpp>
|
||||
#include <thread/thread_netif.hpp>
|
||||
@@ -135,7 +136,8 @@ ThreadError PanIdQueryServer::SendConflict(void)
|
||||
header.AppendUriPathOptions(OPENTHREAD_URI_PANID_CONFLICT);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = mNetif.GetCoapClient().NewMeshCoPMessage(header)) != NULL, error = kThreadError_NoBufs);
|
||||
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(mNetif.GetCoapClient(), header)) != NULL,
|
||||
error = kThreadError_NoBufs);
|
||||
|
||||
channelMask.Init();
|
||||
channelMask.SetMask(mChannelMask);
|
||||
|
||||
Reference in New Issue
Block a user