[posix] allow bind to Thread interface only (#4965)

This commit is contained in:
Yakun Xu
2020-08-28 18:52:31 -07:00
committed by GitHub
parent e952128c05
commit 5e233fb617
44 changed files with 608 additions and 295 deletions
+1
View File
@@ -272,6 +272,7 @@ LOCAL_SRC_FILES := \
src/core/thread/router_table.cpp \
src/core/thread/src_match_controller.cpp \
src/core/thread/thread_netif.cpp \
src/core/thread/tmf.cpp \
src/core/thread/topology.cpp \
src/core/utils/channel_manager.cpp \
src/core/utils/channel_monitor.cpp \
+1 -1
View File
@@ -53,7 +53,7 @@ extern "C" {
* @note This number versions both OpenThread platform and user APIs.
*
*/
#define OPENTHREAD_API_VERSION (25)
#define OPENTHREAD_API_VERSION (26)
/**
* @addtogroup api-instance
+20
View File
@@ -39,6 +39,12 @@
extern "C" {
#endif
typedef enum otNetifIdentifier
{
OT_NETIF_UNSPECIFIED = 0, ///< Unspecified network interface.
OT_NETIF_THREAD, ///< The Thread interface.
} otNetifIdentifier;
/**
* This function initializes the UDP socket by platform.
*
@@ -72,6 +78,20 @@ otError otPlatUdpClose(otUdpSocket *aUdpSocket);
*/
otError otPlatUdpBind(otUdpSocket *aUdpSocket);
/**
* This function binds the UDP socket to a platform network interface.
*
* Note: only available when `OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE` is used.
*
* @param[in] aUdpSocket A pointer to the UDP socket.
* @param[in] aNetifIdentifier The network interface identifier.
*
* @retval OT_ERROR_NONE Successfully bound UDP socket.
* @retval OT_ERROR_FAILED Failed to bind UDP.
*
*/
otError otPlatUdpBindToNetif(otUdpSocket *aUdpSocket, otNetifIdentifier aNetifIdentifier);
/**
* This function connects UDP socket by platform.
*
+2
View File
@@ -538,6 +538,8 @@ openthread_core_files = [
"thread/thread_uri_paths.hpp",
"thread/time_sync_service.cpp",
"thread/time_sync_service.hpp",
"thread/tmf.cpp",
"thread/tmf.hpp",
"thread/topology.cpp",
"thread/topology.hpp",
"utils/channel_manager.cpp",
+1
View File
@@ -202,6 +202,7 @@ set(COMMON_SOURCES
thread/src_match_controller.cpp
thread/thread_netif.cpp
thread/time_sync_service.cpp
thread/tmf.cpp
thread/topology.cpp
utils/channel_manager.cpp
utils/channel_monitor.cpp
+2
View File
@@ -244,6 +244,7 @@ SOURCES_COMMON = \
thread/src_match_controller.cpp \
thread/thread_netif.cpp \
thread/time_sync_service.cpp \
thread/tmf.cpp \
thread/topology.cpp \
utils/channel_manager.cpp \
utils/channel_monitor.cpp \
@@ -468,6 +469,7 @@ HEADERS_COMMON = \
thread/thread_tlvs.hpp \
thread/thread_uri_paths.hpp \
thread/time_sync_service.hpp \
thread/tmf.hpp \
thread/topology.hpp \
utils/channel_manager.hpp \
utils/channel_monitor.hpp \
+2 -2
View File
@@ -201,8 +201,8 @@ void otMessageGetBufferInfo(otInstance *aInstance, otBufferInfo *aBufferInfo)
instance.Get<Mle::MleRouter>().GetMessageQueue().GetInfo(aBufferInfo->mMleMessages, aBufferInfo->mMleBuffers);
instance.Get<Coap::Coap>().GetRequestMessages().GetInfo(aBufferInfo->mCoapMessages, aBufferInfo->mCoapBuffers);
instance.Get<Coap::Coap>().GetCachedResponses().GetInfo(messages, buffers);
instance.Get<Tmf::TmfAgent>().GetRequestMessages().GetInfo(aBufferInfo->mCoapMessages, aBufferInfo->mCoapBuffers);
instance.Get<Tmf::TmfAgent>().GetCachedResponses().GetInfo(messages, buffers);
aBufferInfo->mCoapMessages += messages;
aBufferInfo->mCoapBuffers += buffers;
+8 -8
View File
@@ -70,15 +70,15 @@ void Manager::HandleNotifierEvents(Events aEvents)
{
if (Get<BackboneRouter::Local>().GetState() == OT_BACKBONE_ROUTER_STATE_DISABLED)
{
Get<Coap::Coap>().RemoveResource(mMulticastListenerRegistration);
Get<Coap::Coap>().RemoveResource(mDuaRegistration);
Get<Tmf::TmfAgent>().RemoveResource(mMulticastListenerRegistration);
Get<Tmf::TmfAgent>().RemoveResource(mDuaRegistration);
mTimer.Stop();
mMulticastListenersTable.Clear();
}
else
{
Get<Coap::Coap>().AddResource(mMulticastListenerRegistration);
Get<Coap::Coap>().AddResource(mDuaRegistration);
Get<Tmf::TmfAgent>().AddResource(mMulticastListenerRegistration);
Get<Tmf::TmfAgent>().AddResource(mDuaRegistration);
if (!mTimer.IsRunning())
{
mTimer.Start(kTimerInterval);
@@ -182,7 +182,7 @@ void Manager::SendMulticastListenerRegistrationResponse(const Coap::Message &
otError error = OT_ERROR_NONE;
Coap::Message *message = nullptr;
VerifyOrExit((message = Get<Coap::Coap>().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = Get<Tmf::TmfAgent>().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(message->SetDefaultResponseHeader(aMessage));
SuccessOrExit(message->SetPayloadMarker());
@@ -203,7 +203,7 @@ void Manager::SendMulticastListenerRegistrationResponse(const Coap::Message &
}
}
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, aMessageInfo));
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, aMessageInfo));
exit:
if (error != OT_ERROR_NONE && message != nullptr)
@@ -266,7 +266,7 @@ void Manager::SendDuaRegistrationResponse(const Coap::Message & aMessage,
otError error = OT_ERROR_NONE;
Coap::Message *message = nullptr;
VerifyOrExit((message = Get<Coap::Coap>().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = Get<Tmf::TmfAgent>().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(message->SetDefaultResponseHeader(aMessage));
SuccessOrExit(message->SetPayloadMarker());
@@ -274,7 +274,7 @@ void Manager::SendDuaRegistrationResponse(const Coap::Message & aMessage,
SuccessOrExit(Tlv::AppendUint8Tlv(*message, ThreadTlv::kStatus, aStatus));
SuccessOrExit(Tlv::AppendTlv(*message, ThreadTlv::kTarget, &aTarget, sizeof(aTarget)));
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, aMessageInfo));
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, aMessageInfo));
exit:
if (error != OT_ERROR_NONE && message != nullptr)
+3 -2
View File
@@ -623,12 +623,13 @@ public:
*/
otError Stop(void);
protected:
Ip6::Udp::Socket mSocket;
private:
static otError Send(CoapBase &aCoapBase, ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
static void HandleUdpReceive(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo);
otError Send(ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
Ip6::Udp::Socket mSocket;
};
} // namespace Coap
+3 -3
View File
@@ -59,9 +59,9 @@
#include "mac/link_raw.hpp"
#endif
#if OPENTHREAD_FTD || OPENTHREAD_MTD
#include "coap/coap.hpp"
#include "common/code_utils.hpp"
#include "crypto/mbedtls.hpp"
#include "thread/tmf.hpp"
#if !OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE
#include "utils/heap.hpp"
#endif
@@ -608,9 +608,9 @@ template <> inline Ip6::Mpl &Instance::Get(void)
return mIp6.mMpl;
}
template <> inline Coap::Coap &Instance::Get(void)
template <> inline Tmf::TmfAgent &Instance::Get(void)
{
return mThreadNetif.mCoap;
return mThreadNetif.mTmfAgent;
}
#if OPENTHREAD_CONFIG_DTLS_ENABLE
+3 -3
View File
@@ -64,7 +64,7 @@ otError AnnounceBeginClient::SendRequest(uint32_t aChannelMask,
Coap::Message * message = nullptr;
VerifyOrExit(Get<MeshCoP::Commissioner>().IsActive(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get<Coap::Coap>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error =
message->Init(aAddress.IsMulticast() ? OT_COAP_TYPE_NON_CONFIRMABLE : OT_COAP_TYPE_CONFIRMABLE,
@@ -83,9 +83,9 @@ otError AnnounceBeginClient::SendRequest(uint32_t aChannelMask,
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetMeshLocal16());
messageInfo.SetPeerAddr(aAddress);
messageInfo.SetPeerPort(kCoapUdpPort);
messageInfo.SetPeerPort(Tmf::kUdpPort);
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo));
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo));
otLogInfoMeshCoP("sent announce begin query");
+10 -10
View File
@@ -538,7 +538,7 @@ void BorderAgent::HandleRelayTransmit(const Coap::Message &aMessage)
SuccessOrExit(error = Tlv::FindUint16Tlv(aMessage, Tlv::kJoinerRouterLocator, joinerRouterRloc));
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::Coap>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error = message->Init(OT_COAP_TYPE_NON_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_RELAY_TX));
SuccessOrExit(error = message->SetPayloadMarker());
@@ -547,13 +547,13 @@ void BorderAgent::HandleRelayTransmit(const Coap::Message &aMessage)
SuccessOrExit(error = message->SetLength(offset + aMessage.GetLength() - aMessage.GetOffset()));
aMessage.CopyTo(aMessage.GetOffset(), offset, aMessage.GetLength() - aMessage.GetOffset(), *message);
messageInfo.SetSockPort(kCoapUdpPort);
messageInfo.SetSockPort(Tmf::kUdpPort);
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetMeshLocal16());
messageInfo.SetPeerPort(kCoapUdpPort);
messageInfo.SetPeerPort(Tmf::kUdpPort);
messageInfo.SetPeerAddr(Get<Mle::MleRouter>().GetMeshLocal16());
messageInfo.GetPeerAddr().GetIid().SetLocator(joinerRouterRloc);
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo));
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo));
otLogInfoMeshCoP("Sent to joiner router request on %s", OT_URI_PATH_RELAY_TX);
@@ -581,7 +581,7 @@ otError BorderAgent::ForwardToLeader(const Coap::Message & aMessage,
Coap::Message * message = nullptr;
uint16_t offset = 0;
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::Coap>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
if (aSeparate)
{
@@ -606,11 +606,11 @@ otError BorderAgent::ForwardToLeader(const Coap::Message & aMessage,
aMessage.CopyTo(aMessage.GetOffset(), offset, aMessage.GetLength() - aMessage.GetOffset(), *message);
SuccessOrExit(error = Get<Mle::MleRouter>().GetLeaderAloc(messageInfo.GetPeerAddr()));
messageInfo.SetPeerPort(kCoapUdpPort);
messageInfo.SetPeerPort(Tmf::kUdpPort);
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetMeshLocal16());
messageInfo.SetSockPort(kCoapUdpPort);
messageInfo.SetSockPort(Tmf::kUdpPort);
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo, HandleCoapResponse, forwardContext));
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo, HandleCoapResponse, forwardContext));
// HandleCoapResponse is responsible to free this forward context.
forwardContext = nullptr;
@@ -676,7 +676,7 @@ otError BorderAgent::Start(void)
coaps.AddResource(mProxyTransmit);
coaps.AddResource(mRelayTransmit);
Get<Coap::Coap>().AddResource(mRelayReceive);
Get<Tmf::TmfAgent>().AddResource(mRelayReceive);
SetState(OT_BORDER_AGENT_STATE_STARTED);
@@ -718,7 +718,7 @@ otError BorderAgent::Stop(void)
coaps.RemoveResource(mProxyTransmit);
coaps.RemoveResource(mRelayTransmit);
Get<Coap::Coap>().RemoveResource(mRelayReceive);
Get<Tmf::TmfAgent>().RemoveResource(mRelayReceive);
coaps.Stop();
+24 -24
View File
@@ -136,15 +136,15 @@ exit:
void Commissioner::AddCoapResources(void)
{
Get<Coap::Coap>().AddResource(mRelayReceive);
Get<Coap::Coap>().AddResource(mDatasetChanged);
Get<Tmf::TmfAgent>().AddResource(mRelayReceive);
Get<Tmf::TmfAgent>().AddResource(mDatasetChanged);
Get<Coap::CoapSecure>().AddResource(mJoinerFinalize);
}
void Commissioner::RemoveCoapResources(void)
{
Get<Coap::Coap>().RemoveResource(mRelayReceive);
Get<Coap::Coap>().RemoveResource(mDatasetChanged);
Get<Tmf::TmfAgent>().RemoveResource(mRelayReceive);
Get<Tmf::TmfAgent>().RemoveResource(mDatasetChanged);
Get<Coap::CoapSecure>().RemoveResource(mJoinerFinalize);
}
@@ -696,7 +696,7 @@ otError Commissioner::SendMgmtCommissionerGetRequest(const uint8_t *aTlvs, uint8
Ip6::MessageInfo messageInfo;
MeshCoP::Tlv tlv;
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::Coap>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_COMMISSIONER_GET));
@@ -715,9 +715,9 @@ otError Commissioner::SendMgmtCommissionerGetRequest(const uint8_t *aTlvs, uint8
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetMeshLocal16());
SuccessOrExit(error = Get<Mle::MleRouter>().GetLeaderAloc(messageInfo.GetPeerAddr()));
messageInfo.SetPeerPort(kCoapUdpPort);
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo,
Commissioner::HandleMgmtCommissionerGetResponse, this));
messageInfo.SetPeerPort(Tmf::kUdpPort);
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo,
Commissioner::HandleMgmtCommissionerGetResponse, this));
otLogInfoMeshCoP("sent MGMT_COMMISSIONER_GET.req to leader");
@@ -761,7 +761,7 @@ otError Commissioner::SendMgmtCommissionerSetRequest(const otCommissioningDatase
Coap::Message * message;
Ip6::MessageInfo messageInfo;
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::Coap>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_COMMISSIONER_SET));
SuccessOrExit(error = message->SetPayloadMarker());
@@ -801,9 +801,9 @@ otError Commissioner::SendMgmtCommissionerSetRequest(const otCommissioningDatase
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetMeshLocal16());
SuccessOrExit(error = Get<Mle::MleRouter>().GetLeaderAloc(messageInfo.GetPeerAddr()));
messageInfo.SetPeerPort(kCoapUdpPort);
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo,
Commissioner::HandleMgmtCommissionerSetResponse, this));
messageInfo.SetPeerPort(Tmf::kUdpPort);
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo,
Commissioner::HandleMgmtCommissionerSetResponse, this));
otLogInfoMeshCoP("sent MGMT_COMMISSIONER_SET.req to leader");
@@ -848,7 +848,7 @@ otError Commissioner::SendPetition(void)
mTransmitAttempts++;
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::Coap>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_LEADER_PETITION));
SuccessOrExit(error = message->SetPayloadMarker());
@@ -859,10 +859,10 @@ otError Commissioner::SendPetition(void)
SuccessOrExit(error = commissionerId.AppendTo(*message));
SuccessOrExit(error = Get<Mle::MleRouter>().GetLeaderAloc(messageInfo.GetPeerAddr()));
messageInfo.SetPeerPort(kCoapUdpPort);
messageInfo.SetPeerPort(Tmf::kUdpPort);
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetMeshLocal16());
SuccessOrExit(
error = Get<Coap::Coap>().SendMessage(*message, messageInfo, Commissioner::HandleLeaderPetitionResponse, this));
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo,
Commissioner::HandleLeaderPetitionResponse, this));
otLogInfoMeshCoP("sent petition");
@@ -948,7 +948,7 @@ void Commissioner::SendKeepAlive(uint16_t aSessionId)
Coap::Message * message = nullptr;
Ip6::MessageInfo messageInfo;
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::Coap>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_LEADER_KEEP_ALIVE));
SuccessOrExit(error = message->SetPayloadMarker());
@@ -961,9 +961,9 @@ void Commissioner::SendKeepAlive(uint16_t aSessionId)
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetMeshLocal16());
SuccessOrExit(error = Get<Mle::MleRouter>().GetLeaderAloc(messageInfo.GetPeerAddr()));
messageInfo.SetPeerPort(kCoapUdpPort);
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo,
Commissioner::HandleLeaderKeepAliveResponse, this));
messageInfo.SetPeerPort(Tmf::kUdpPort);
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo,
Commissioner::HandleLeaderKeepAliveResponse, this));
otLogInfoMeshCoP("sent keep alive");
@@ -1093,7 +1093,7 @@ void Commissioner::HandleDatasetChanged(Coap::Message &aMessage, const Ip6::Mess
otLogInfoMeshCoP("received dataset changed");
SuccessOrExit(Get<Coap::Coap>().SendEmptyAck(aMessage, aMessageInfo));
SuccessOrExit(Get<Tmf::TmfAgent>().SendEmptyAck(aMessage, aMessageInfo));
otLogInfoMeshCoP("sent dataset changed acknowledgment");
@@ -1203,7 +1203,7 @@ otError Commissioner::SendRelayTransmit(Message &aMessage, const Ip6::MessageInf
uint16_t offset;
Ip6::MessageInfo messageInfo;
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::Coap>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
message->Init(OT_COAP_TYPE_NON_CONFIRMABLE, OT_COAP_CODE_POST);
SuccessOrExit(error = message->AppendUriPathOptions(OT_URI_PATH_RELAY_TX));
@@ -1228,9 +1228,9 @@ otError Commissioner::SendRelayTransmit(Message &aMessage, const Ip6::MessageInf
messageInfo.SetPeerAddr(Get<Mle::MleRouter>().GetMeshLocal16());
messageInfo.GetPeerAddr().GetIid().SetLocator(mJoinerRloc);
messageInfo.SetPeerPort(kCoapUdpPort);
messageInfo.SetPeerPort(Tmf::kUdpPort);
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo));
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo));
aMessage.Free();
+14 -14
View File
@@ -278,7 +278,7 @@ void DatasetManager::SendSet(void)
}
}
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::Coap>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, mUriSet));
SuccessOrExit(error = message->SetPayloadMarker());
@@ -288,9 +288,9 @@ void DatasetManager::SendSet(void)
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetMeshLocal16());
IgnoreError(Get<Mle::MleRouter>().GetLeaderAloc(messageInfo.GetPeerAddr()));
messageInfo.SetPeerPort(kCoapUdpPort);
SuccessOrExit(error =
Get<Coap::Coap>().SendMessage(*message, messageInfo, &DatasetManager::HandleCoapResponse, this));
messageInfo.SetPeerPort(Tmf::kUdpPort);
SuccessOrExit(
error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo, &DatasetManager::HandleCoapResponse, this));
otLogInfoMeshCoP("Sent %s to leader", mUriSet);
@@ -392,7 +392,7 @@ void DatasetManager::SendGetResponse(const Coap::Message & aRequest,
IgnoreError(mLocal.Read(dataset));
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::Coap>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error = message->SetDefaultResponseHeader(aRequest));
SuccessOrExit(error = message->SetPayloadMarker());
@@ -431,7 +431,7 @@ void DatasetManager::SendGetResponse(const Coap::Message & aRequest,
IgnoreError(message->SetLength(message->GetLength() - 1));
}
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, aMessageInfo));
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, aMessageInfo));
otLogInfoMeshCoP("sent dataset get response");
@@ -449,7 +449,7 @@ otError DatasetManager::SendSetRequest(const otOperationalDataset &aDataset, con
Coap::Message * message;
Ip6::MessageInfo messageInfo;
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::Coap>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, mUriSet));
SuccessOrExit(error = message->SetPayloadMarker());
@@ -578,8 +578,8 @@ otError DatasetManager::SendSetRequest(const otOperationalDataset &aDataset, con
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetMeshLocal16());
IgnoreError(Get<Mle::MleRouter>().GetLeaderAloc(messageInfo.GetPeerAddr()));
messageInfo.SetPeerPort(kCoapUdpPort);
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo));
messageInfo.SetPeerPort(Tmf::kUdpPort);
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo));
otLogInfoMeshCoP("sent dataset set request to leader");
@@ -667,7 +667,7 @@ otError DatasetManager::SendGetRequest(const otOperationalDatasetComponents &aDa
datasetTlvs[length++] = Tlv::kChannelMask;
}
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::Coap>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, mUriGet));
@@ -703,8 +703,8 @@ otError DatasetManager::SendGetRequest(const otOperationalDatasetComponents &aDa
}
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetMeshLocal16());
messageInfo.SetPeerPort(kCoapUdpPort);
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo));
messageInfo.SetPeerPort(Tmf::kUdpPort);
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo));
otLogInfoMeshCoP("sent dataset get request");
@@ -729,7 +729,7 @@ ActiveDataset::ActiveDataset(Instance &aInstance)
, mResourceSet(OT_URI_PATH_ACTIVE_SET, &ActiveDataset::HandleSet, this)
#endif
{
Get<Coap::Coap>().AddResource(mResourceGet);
Get<Tmf::TmfAgent>().AddResource(mResourceGet);
}
bool ActiveDataset::IsPartiallyComplete(void) const
@@ -778,7 +778,7 @@ PendingDataset::PendingDataset(Instance &aInstance)
, mResourceSet(OT_URI_PATH_PENDING_SET, &PendingDataset::HandleSet, this)
#endif
{
Get<Coap::Coap>().AddResource(mResourceGet);
Get<Tmf::TmfAgent>().AddResource(mResourceGet);
}
void PendingDataset::Clear(void)
+6 -6
View File
@@ -276,14 +276,14 @@ void DatasetManager::SendSetResponse(const Coap::Message & aRequest,
otError error = OT_ERROR_NONE;
Coap::Message *message;
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::Coap>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error = message->SetDefaultResponseHeader(aRequest));
SuccessOrExit(error = message->SetPayloadMarker());
SuccessOrExit(error = Tlv::AppendUint8Tlv(*message, Tlv::kState, static_cast<uint8_t>(aState)));
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, aMessageInfo));
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, aMessageInfo));
otLogInfoMeshCoP("sent dataset set response");
@@ -460,12 +460,12 @@ exit:
void ActiveDataset::StartLeader(void)
{
IgnoreError(GenerateLocal());
Get<Coap::Coap>().AddResource(mResourceSet);
Get<Tmf::TmfAgent>().AddResource(mResourceSet);
}
void ActiveDataset::StopLeader(void)
{
Get<Coap::Coap>().RemoveResource(mResourceSet);
Get<Tmf::TmfAgent>().RemoveResource(mResourceSet);
}
void ActiveDataset::HandleSet(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo)
@@ -486,12 +486,12 @@ exit:
void PendingDataset::StartLeader(void)
{
StartDelayTimer();
Get<Coap::Coap>().AddResource(mResourceSet);
Get<Tmf::TmfAgent>().AddResource(mResourceSet);
}
void PendingDataset::StopLeader(void)
{
Get<Coap::Coap>().RemoveResource(mResourceSet);
Get<Tmf::TmfAgent>().RemoveResource(mResourceSet);
}
void PendingDataset::HandleSet(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo)
+5 -5
View File
@@ -55,7 +55,7 @@ EnergyScanClient::EnergyScanClient(Instance &aInstance)
, mContext(nullptr)
, mEnergyScan(OT_URI_PATH_ENERGY_REPORT, &EnergyScanClient::HandleReport, this)
{
Get<Coap::Coap>().AddResource(mEnergyScan);
Get<Tmf::TmfAgent>().AddResource(mEnergyScan);
}
otError EnergyScanClient::SendQuery(uint32_t aChannelMask,
@@ -72,7 +72,7 @@ otError EnergyScanClient::SendQuery(uint32_t aChannelM
Coap::Message * message = nullptr;
VerifyOrExit(Get<MeshCoP::Commissioner>().IsActive(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get<Coap::Coap>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error =
message->Init(aAddress.IsMulticast() ? OT_COAP_TYPE_NON_CONFIRMABLE : OT_COAP_TYPE_CONFIRMABLE,
@@ -92,8 +92,8 @@ otError EnergyScanClient::SendQuery(uint32_t aChannelM
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetMeshLocal16());
messageInfo.SetPeerAddr(aAddress);
messageInfo.SetPeerPort(kCoapUdpPort);
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo));
messageInfo.SetPeerPort(Tmf::kUdpPort);
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo));
otLogInfoMeshCoP("sent energy scan query");
@@ -141,7 +141,7 @@ void EnergyScanClient::HandleReport(Coap::Message &aMessage, const Ip6::MessageI
mCallback(mask, energyList.list, energyList.tlv.GetLength(), mContext);
}
SuccessOrExit(Get<Coap::Coap>().SendEmptyAck(aMessage, aMessageInfo));
SuccessOrExit(Get<Tmf::TmfAgent>().SendEmptyAck(aMessage, aMessageInfo));
otLogInfoMeshCoP("sent energy scan report response");
+3 -3
View File
@@ -70,7 +70,7 @@ Joiner::Joiner(Instance &aInstance)
SetIdFromIeeeEui64();
mDiscerner.Clear();
memset(mJoinerRouters, 0, sizeof(mJoinerRouters));
Get<Coap::Coap>().AddResource(mJoinerEntrust);
Get<Tmf::TmfAgent>().AddResource(mJoinerEntrust);
}
void Joiner::SetIdFromIeeeEui64(void)
@@ -611,12 +611,12 @@ void Joiner::SendJoinerEntrustResponse(const Coap::Message &aRequest, const Ip6:
Coap::Message * message;
Ip6::MessageInfo responseInfo(aRequestInfo);
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::Coap>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error = message->SetDefaultResponseHeader(aRequest));
message->SetSubType(Message::kSubTypeJoinerEntrust);
responseInfo.GetSockAddr().Clear();
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, responseInfo));
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, responseInfo));
SetState(OT_JOINER_STATE_JOINED);
+9 -9
View File
@@ -61,7 +61,7 @@ JoinerRouter::JoinerRouter(Instance &aInstance)
, mJoinerUdpPort(0)
, mIsJoinerPortConfigured(false)
{
Get<Coap::Coap>().AddResource(mRelayTransmit);
Get<Tmf::TmfAgent>().AddResource(mRelayTransmit);
}
void JoinerRouter::HandleNotifierEvents(Events aEvents)
@@ -143,7 +143,7 @@ void JoinerRouter::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &a
SuccessOrExit(error = GetBorderAgentRloc(Get<ThreadNetif>(), borderAgentRloc));
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::Coap>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error = message->Init(OT_COAP_TYPE_NON_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_RELAY_RX));
SuccessOrExit(error = message->SetPayloadMarker());
@@ -163,9 +163,9 @@ void JoinerRouter::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &a
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetMeshLocal16());
messageInfo.SetPeerAddr(Get<Mle::MleRouter>().GetMeshLocal16());
messageInfo.GetPeerAddr().GetIid().SetLocator(borderAgentRloc);
messageInfo.SetPeerPort(kCoapUdpPort);
messageInfo.SetPeerPort(Tmf::kUdpPort);
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo));
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo));
otLogInfoMeshCoP("Sent relay rx");
@@ -239,7 +239,7 @@ void JoinerRouter::DelaySendingJoinerEntrust(const Ip6::MessageInfo &aMessageInf
VerifyOrExit(message != nullptr, error = OT_ERROR_NO_BUFS);
metadata.mMessageInfo = aMessageInfo;
metadata.mMessageInfo.SetPeerPort(kCoapUdpPort);
metadata.mMessageInfo.SetPeerPort(Tmf::kUdpPort);
metadata.mSendTime = TimerMilli::GetNow() + kJoinerEntrustTxDelay;
metadata.mKek = aKek;
@@ -314,11 +314,11 @@ otError JoinerRouter::SendJoinerEntrust(const Ip6::MessageInfo &aMessageInfo)
message = PrepareJoinerEntrustMessage();
VerifyOrExit(message != nullptr, error = OT_ERROR_NO_BUFS);
IgnoreError(Get<Coap::Coap>().AbortTransaction(&JoinerRouter::HandleJoinerEntrustResponse, this));
IgnoreError(Get<Tmf::TmfAgent>().AbortTransaction(&JoinerRouter::HandleJoinerEntrustResponse, this));
otLogInfoMeshCoP("Sending JOIN_ENT.ntf");
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, aMessageInfo,
&JoinerRouter::HandleJoinerEntrustResponse, this));
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, aMessageInfo,
&JoinerRouter::HandleJoinerEntrustResponse, this));
otLogInfoMeshCoP("Sent joiner entrust length = %d", message->GetLength());
otLogCertMeshCoP("[THCI] direction=send | type=JOIN_ENT.ntf");
@@ -341,7 +341,7 @@ Coap::Message *JoinerRouter::PrepareJoinerEntrustMessage(void)
NetworkNameTlv networkName;
const Tlv * tlv;
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::Coap>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST);
SuccessOrExit(error = message->AppendUriPathOptions(OT_URI_PATH_JOINER_ENTRUST));
+9 -9
View File
@@ -60,8 +60,8 @@ Leader::Leader(Instance &aInstance)
, mDelayTimerMinimal(DelayTimerTlv::kDelayTimerMinimal)
, mSessionId(Random::NonCrypto::GetUint16())
{
Get<Coap::Coap>().AddResource(mPetition);
Get<Coap::Coap>().AddResource(mKeepAlive);
Get<Tmf::TmfAgent>().AddResource(mPetition);
Get<Tmf::TmfAgent>().AddResource(mKeepAlive);
}
void Leader::HandlePetition(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo)
@@ -127,7 +127,7 @@ void Leader::SendPetitionResponse(const Coap::Message & aRequest,
otError error = OT_ERROR_NONE;
Coap::Message *message;
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::Coap>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error = message->SetDefaultResponseHeader(aRequest));
SuccessOrExit(error = message->SetPayloadMarker());
@@ -144,7 +144,7 @@ void Leader::SendPetitionResponse(const Coap::Message & aRequest,
SuccessOrExit(error = Tlv::AppendUint16Tlv(*message, Tlv::kCommissionerSessionId, mSessionId));
}
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, aMessageInfo));
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, aMessageInfo));
otLogInfoMeshCoP("sent petition response");
@@ -219,14 +219,14 @@ void Leader::SendKeepAliveResponse(const Coap::Message & aRequest,
otError error = OT_ERROR_NONE;
Coap::Message *message;
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::Coap>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error = message->SetDefaultResponseHeader(aRequest));
SuccessOrExit(error = message->SetPayloadMarker());
SuccessOrExit(error = Tlv::AppendUint8Tlv(*message, Tlv::kState, static_cast<uint8_t>(aState)));
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, aMessageInfo));
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, aMessageInfo));
otLogInfoMeshCoP("sent keep alive response");
@@ -249,14 +249,14 @@ void Leader::SendDatasetChanged(const Ip6::Address &aAddress)
Ip6::MessageInfo messageInfo;
Coap::Message * message;
VerifyOrExit((message = NewMeshCoPMessage(Get<Coap::Coap>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_DATASET_CHANGED));
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetMeshLocal16());
messageInfo.SetPeerAddr(aAddress);
messageInfo.SetPeerPort(kCoapUdpPort);
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo));
messageInfo.SetPeerPort(Tmf::kUdpPort);
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo));
otLogInfoMeshCoP("sent dataset changed");
+5 -5
View File
@@ -54,7 +54,7 @@ PanIdQueryClient::PanIdQueryClient(Instance &aInstance)
, mContext(nullptr)
, mPanIdQuery(OT_URI_PATH_PANID_CONFLICT, &PanIdQueryClient::HandleConflict, this)
{
Get<Coap::Coap>().AddResource(mPanIdQuery);
Get<Tmf::TmfAgent>().AddResource(mPanIdQuery);
}
otError PanIdQueryClient::SendQuery(uint16_t aPanId,
@@ -69,7 +69,7 @@ otError PanIdQueryClient::SendQuery(uint16_t aPanId,
Coap::Message * message = nullptr;
VerifyOrExit(Get<MeshCoP::Commissioner>().IsActive(), error = OT_ERROR_INVALID_STATE);
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get<Coap::Coap>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error =
message->Init(aAddress.IsMulticast() ? OT_COAP_TYPE_NON_CONFIRMABLE : OT_COAP_TYPE_CONFIRMABLE,
@@ -87,8 +87,8 @@ otError PanIdQueryClient::SendQuery(uint16_t aPanId,
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetMeshLocal16());
messageInfo.SetPeerAddr(aAddress);
messageInfo.SetPeerPort(kCoapUdpPort);
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo));
messageInfo.SetPeerPort(Tmf::kUdpPort);
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo));
otLogInfoMeshCoP("sent panid query");
@@ -130,7 +130,7 @@ void PanIdQueryClient::HandleConflict(Coap::Message &aMessage, const Ip6::Messag
mCallback(panId, mask, mContext);
}
SuccessOrExit(Get<Coap::Coap>().SendEmptyAck(aMessage, responseInfo));
SuccessOrExit(Get<Tmf::TmfAgent>().SendEmptyAck(aMessage, responseInfo));
otLogInfoMeshCoP("sent panid query conflict response");
+1 -1
View File
@@ -1054,7 +1054,7 @@ otError Ip6::ProcessReceiveCallback(Message & aMessage,
ExitNow(error = OT_ERROR_NO_ROUTE);
}
#if !OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE
else if ((destPort == kCoapUdpPort) && Get<ThreadNetif>().IsTmfMessage(aMessageInfo))
else if ((destPort == Tmf::kUdpPort) && Get<Tmf::TmfAgent>().IsTmfMessage(aMessageInfo))
{
// do not pass TMF messages
ExitNow(error = OT_ERROR_NO_ROUTE);
+12 -1
View File
@@ -100,6 +100,13 @@ otError Udp::Socket::Bind(uint16_t aPort)
return Bind(SockAddr(aPort));
}
#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE
otError Udp::Socket::BindToNetif(otNetifIdentifier aNetifIdentifier)
{
return otPlatUdpBindToNetif(this, aNetifIdentifier);
}
#endif
otError Udp::Socket::Connect(const SockAddr &aSockAddr)
{
return Get<Udp>().Connect(*this, aSockAddr);
@@ -172,6 +179,9 @@ otError Udp::Bind(SocketHandle &aSocket, const SockAddr &aSockAddr)
{
otError error = OT_ERROR_NONE;
VerifyOrExit(aSockAddr.GetAddress().IsUnspecified() || Get<ThreadNetif>().HasUnicastAddress(aSockAddr.GetAddress()),
error = OT_ERROR_INVALID_ARGS);
aSocket.mSockName = aSockAddr;
if (!aSocket.IsBound())
@@ -191,6 +201,7 @@ otError Udp::Bind(SocketHandle &aSocket, const SockAddr &aSockAddr)
}
#endif
exit:
return error;
}
@@ -270,7 +281,7 @@ otError Udp::SendTo(SocketHandle &aSocket, Message &aMessage, const MessageInfo
#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE
if (!IsMlePort(aSocket.mSockName.mPort) &&
!(aSocket.mSockName.mPort == ot::kCoapUdpPort && aMessage.GetSubType() == Message::kSubTypeJoinerEntrust))
!(aSocket.mSockName.mPort == ot::Tmf::kUdpPort && aMessage.GetSubType() == Message::kSubTypeJoinerEntrust))
{
SuccessOrExit(error = otPlatUdpSend(&aSocket, &aMessage, &messageInfoLocal));
}
+26 -10
View File
@@ -37,6 +37,7 @@
#include "openthread-core-config.h"
#include <openthread/udp.h>
#include <openthread/platform/udp.h>
#include "common/linked_list.hpp"
#include "common/locator.hpp"
@@ -167,21 +168,35 @@ public:
/**
* This method binds the UDP socket.
*
* @param[in] aSockAddr A reference to the socket address.
* @param[in] aSockAddr A reference to the socket address.
*
* @retval OT_ERROR_NONE Successfully bound the socket.
* @retval OT_ERROR_FAILED Failed to bind UDP Socket.
* @retval OT_ERROR_NONE Successfully bound the socket.
* @retval OT_ERROR_INVALID_ARGS Unable to bind to Thread network interface with the given address.
* @retval OT_ERROR_FAILED Failed to bind UDP Socket.
*
*/
otError Bind(const SockAddr &aSockAddr);
#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE
/**
* This method binds the UDP socket to a specified network interface.
*
* @param[in] aNetifIdentifier The network interface identifier.
*
* @retval OT_ERROR_NONE Successfully bound to the network interface.
* @retval OT_ERROR_FAILED Failed to bind to the network interface.
*
*/
otError BindToNetif(otNetifIdentifier aNetifIdentifier);
#endif // OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE
/**
* This method binds the UDP socket.
*
* @param[in] aPort A port number.
* @param[in] aPort A port number.
*
* @retval OT_ERROR_NONE Successfully bound the socket.
* @retval OT_ERROR_FAILED Failed to bind UDP Socket.
* @retval OT_ERROR_NONE Successfully bound the socket.
* @retval OT_ERROR_FAILED Failed to bind UDP Socket.
*
*/
otError Bind(uint16_t aPort);
@@ -413,11 +428,12 @@ public:
/**
* This method binds a UDP socket.
*
* @param[in] aSocket A reference to the socket.
* @param[in] aSockAddr A reference to the socket address.
* @param[in] aSocket A reference to the socket.
* @param[in] aSockAddr A reference to the socket address.
*
* @retval OT_ERROR_NONE Successfully bound the socket.
* @retval OT_ERROR_FAILED Failed to bind UDP Socket.
* @retval OT_ERROR_NONE Successfully bound the socket.
* @retval OT_ERROR_INVALID_ARGS Unable to bind to Thread network interface with the given address.
* @retval OT_ERROR_FAILED Failed to bind UDP Socket.
*
*/
otError Bind(SocketHandle &aSocket, const SockAddr &aSockAddr);
+14 -14
View File
@@ -65,9 +65,9 @@ AddressResolver::AddressResolver(Instance &aInstance)
, mQueryRetryList()
, mIcmpHandler(&AddressResolver::HandleIcmpReceive, this)
{
Get<Coap::Coap>().AddResource(mAddressError);
Get<Coap::Coap>().AddResource(mAddressQuery);
Get<Coap::Coap>().AddResource(mAddressNotification);
Get<Tmf::TmfAgent>().AddResource(mAddressError);
Get<Tmf::TmfAgent>().AddResource(mAddressQuery);
Get<Tmf::TmfAgent>().AddResource(mAddressNotification);
IgnoreError(Get<Ip6::Icmp>().RegisterHandler(mIcmpHandler));
}
@@ -523,7 +523,7 @@ otError AddressResolver::SendAddressQuery(const Ip6::Address &aEid)
Coap::Message * message;
Ip6::MessageInfo messageInfo;
VerifyOrExit((message = Get<Coap::Coap>().NewPriorityMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = Get<Tmf::TmfAgent>().NewPriorityMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
message->Init(OT_COAP_TYPE_NON_CONFIRMABLE, OT_COAP_CODE_POST);
SuccessOrExit(error = message->AppendUriPathOptions(OT_URI_PATH_ADDRESS_QUERY));
@@ -534,9 +534,9 @@ otError AddressResolver::SendAddressQuery(const Ip6::Address &aEid)
messageInfo.GetPeerAddr().SetToRealmLocalAllRoutersMulticast();
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetMeshLocal16());
messageInfo.SetPeerPort(kCoapUdpPort);
messageInfo.SetPeerPort(Tmf::kUdpPort);
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo));
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo));
otLogInfoArp("Sending address query for %s", aEid.ToString().AsCString());
@@ -615,7 +615,7 @@ void AddressResolver::HandleAddressNotification(Coap::Message &aMessage, const I
LogCacheEntryChange(kEntryUpdated, kReasonReceivedNotification, *entry);
if (Get<Coap::Coap>().SendEmptyAck(aMessage, aMessageInfo) == OT_ERROR_NONE)
if (Get<Tmf::TmfAgent>().SendEmptyAck(aMessage, aMessageInfo) == OT_ERROR_NONE)
{
otLogInfoArp("Sending address notification acknowledgment");
}
@@ -634,7 +634,7 @@ void AddressResolver::SendAddressError(const Ip6::Address & aTarget,
Coap::Message * message;
Ip6::MessageInfo messageInfo;
VerifyOrExit((message = Get<Coap::Coap>().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = Get<Tmf::TmfAgent>().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
message->Init(aDestination == nullptr ? OT_COAP_TYPE_NON_CONFIRMABLE : OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST);
SuccessOrExit(error = message->AppendUriPathOptions(OT_URI_PATH_ADDRESS_ERROR));
@@ -653,9 +653,9 @@ void AddressResolver::SendAddressError(const Ip6::Address & aTarget,
}
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetMeshLocal16());
messageInfo.SetPeerPort(kCoapUdpPort);
messageInfo.SetPeerPort(Tmf::kUdpPort);
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo));
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo));
otLogInfoArp("Sending address error for target %s", aTarget.ToString().AsCString());
@@ -692,7 +692,7 @@ void AddressResolver::HandleAddressError(Coap::Message &aMessage, const Ip6::Mes
if (aMessage.IsConfirmable() && !aMessageInfo.GetSockAddr().IsMulticast())
{
if (Get<Coap::Coap>().SendEmptyAck(aMessage, aMessageInfo) == OT_ERROR_NONE)
if (Get<Tmf::TmfAgent>().SendEmptyAck(aMessage, aMessageInfo) == OT_ERROR_NONE)
{
otLogInfoArp("Sent address error notification acknowledgment");
}
@@ -797,7 +797,7 @@ void AddressResolver::SendAddressQueryResponse(const Ip6::Address & a
Coap::Message * message;
Ip6::MessageInfo messageInfo;
VerifyOrExit((message = Get<Coap::Coap>().NewPriorityMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = Get<Tmf::TmfAgent>().NewPriorityMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST);
SuccessOrExit(error = message->AppendUriPathOptions(OT_URI_PATH_ADDRESS_NOTIFY));
@@ -814,9 +814,9 @@ void AddressResolver::SendAddressQueryResponse(const Ip6::Address & a
messageInfo.SetPeerAddr(aDestination);
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetMeshLocal16());
messageInfo.SetPeerPort(kCoapUdpPort);
messageInfo.SetPeerPort(Tmf::kUdpPort);
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo));
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo));
otLogInfoArp("Sending address notification for target %s", aTarget.ToString().AsCString());
+2 -2
View File
@@ -51,7 +51,7 @@ AnnounceBeginServer::AnnounceBeginServer(Instance &aInstance)
: AnnounceSenderBase(aInstance, AnnounceBeginServer::HandleTimer)
, mAnnounceBegin(OT_URI_PATH_ANNOUNCE_BEGIN, &AnnounceBeginServer::HandleRequest, this)
{
Get<Coap::Coap>().AddResource(mAnnounceBegin);
Get<Tmf::TmfAgent>().AddResource(mAnnounceBegin);
}
void AnnounceBeginServer::SendAnnounce(uint32_t aChannelMask, uint8_t aCount, uint16_t aPeriod)
@@ -82,7 +82,7 @@ void AnnounceBeginServer::HandleRequest(Coap::Message &aMessage, const Ip6::Mess
if (aMessage.IsConfirmable() && !aMessageInfo.GetSockAddr().IsMulticast())
{
SuccessOrExit(Get<Coap::Coap>().SendEmptyAck(aMessage, responseInfo));
SuccessOrExit(Get<Tmf::TmfAgent>().SendEmptyAck(aMessage, responseInfo));
otLogInfoMeshCoP("sent announce begin response");
}
+12 -11
View File
@@ -76,7 +76,7 @@ DuaManager::DuaManager(Instance &aInstance)
mChildDuaRegisteredMask.Clear();
#endif
Get<Coap::Coap>().AddResource(mDuaNotification);
Get<Tmf::TmfAgent>().AddResource(mDuaNotification);
}
void DuaManager::HandleDomainPrefixUpdate(BackboneRouter::Leader::DomainPrefixState aState)
@@ -86,7 +86,7 @@ void DuaManager::HandleDomainPrefixUpdate(BackboneRouter::Leader::DomainPrefixSt
{
if (mIsDuaPending)
{
IgnoreError(Get<Coap::Coap>().AbortTransaction(&DuaManager::HandleDuaResponse, this));
IgnoreError(Get<Tmf::TmfAgent>().AbortTransaction(&DuaManager::HandleDuaResponse, this));
}
#if OPENTHREAD_CONFIG_DUA_ENABLE
@@ -240,7 +240,7 @@ void DuaManager::RemoveDomainUnicastAddress(void)
{
if (mDuaState == kRegistering && mIsDuaPending)
{
IgnoreError(Get<Coap::Coap>().AbortTransaction(&DuaManager::HandleDuaResponse, this));
IgnoreError(Get<Tmf::TmfAgent>().AbortTransaction(&DuaManager::HandleDuaResponse, this));
}
mDuaState = kNotExist;
@@ -422,7 +422,7 @@ void DuaManager::PerformNextRegistration(void)
#endif // OPENTHREAD_CONFIG_DUA_ENABLE
// Prepare DUA.req
VerifyOrExit((message = Get<Coap::Coap>().NewPriorityMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = Get<Tmf::TmfAgent>().NewPriorityMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error =
message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_DUA_REGISTRATION_REQUEST));
@@ -488,10 +488,11 @@ void DuaManager::PerformNextRegistration(void)
Get<BackboneRouter::Leader>().GetServer16());
}
messageInfo.SetPeerPort(kCoapUdpPort);
messageInfo.SetPeerPort(Tmf::kUdpPort);
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetMeshLocal16());
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo, &DuaManager::HandleDuaResponse, this));
SuccessOrExit(error =
Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo, &DuaManager::HandleDuaResponse, this));
mIsDuaPending = true;
@@ -550,7 +551,7 @@ void DuaManager::HandleDuaNotification(Coap::Message &aMessage, const Ip6::Messa
VerifyOrExit(aMessage.GetCode() == OT_COAP_CODE_POST, error = OT_ERROR_PARSE);
if (aMessage.IsConfirmable() && Get<Coap::Coap>().SendEmptyAck(aMessage, aMessageInfo) == OT_ERROR_NONE)
if (aMessage.IsConfirmable() && Get<Tmf::TmfAgent>().SendEmptyAck(aMessage, aMessageInfo) == OT_ERROR_NONE)
{
otLogInfoDua("Sent DUA.ntf acknowledgment");
}
@@ -655,7 +656,7 @@ void DuaManager::SendAddressNotification(Ip6::Address & aAddress,
Ip6::MessageInfo messageInfo;
otError error;
VerifyOrExit((message = Get<Coap::Coap>().NewPriorityMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = Get<Tmf::TmfAgent>().NewPriorityMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error =
message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_DUA_REGISTRATION_NOTIFY));
@@ -665,10 +666,10 @@ void DuaManager::SendAddressNotification(Ip6::Address & aAddress,
SuccessOrExit(error = Tlv::AppendTlv(*message, ThreadTlv::kTarget, &aAddress, sizeof(aAddress)));
messageInfo.GetPeerAddr().SetToRoutingLocator(Get<Mle::MleRouter>().GetMeshLocalPrefix(), aChild.GetRloc16());
messageInfo.SetPeerPort(kCoapUdpPort);
messageInfo.SetPeerPort(Tmf::kUdpPort);
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetMeshLocal16());
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo));
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo));
otLogInfoDua("Sent ADDR_NTF for child %04x DUA %s", aChild.GetRloc16(), aAddress.ToString().AsCString());
@@ -700,7 +701,7 @@ void DuaManager::UpdateChildDomainUnicastAddress(const Child &aChild, Mle::Child
if (mIsDuaPending && mChildIndexDuaRegistering == childIndex)
#endif
{
IgnoreError(Get<Coap::Coap>().AbortTransaction(&DuaManager::HandleDuaResponse, this));
IgnoreError(Get<Tmf::TmfAgent>().AbortTransaction(&DuaManager::HandleDuaResponse, this));
// Reset mRegisterCurrentChildIndex properly
mRegisterCurrentChildIndex = mRegisterCurrentChildIndex && (aState == Mle::ChildDuaState::kRemoved);
+5 -5
View File
@@ -58,7 +58,7 @@ EnergyScanServer::EnergyScanServer(Instance &aInstance)
, mTimer(aInstance, EnergyScanServer::HandleTimer, this)
, mEnergyScan(OT_URI_PATH_ENERGY_SCAN, &EnergyScanServer::HandleRequest, this)
{
Get<Coap::Coap>().AddResource(mEnergyScan);
Get<Tmf::TmfAgent>().AddResource(mEnergyScan);
}
void EnergyScanServer::HandleRequest(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo)
@@ -96,7 +96,7 @@ void EnergyScanServer::HandleRequest(Coap::Message &aMessage, const Ip6::Message
if (aMessage.IsConfirmable() && !aMessageInfo.GetSockAddr().IsMulticast())
{
SuccessOrExit(Get<Coap::Coap>().SendEmptyAck(aMessage, responseInfo));
SuccessOrExit(Get<Tmf::TmfAgent>().SendEmptyAck(aMessage, responseInfo));
otLogInfoMeshCoP("sent energy scan query response");
}
@@ -175,7 +175,7 @@ void EnergyScanServer::SendReport(void)
Ip6::MessageInfo messageInfo;
Coap::Message * message;
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get<Coap::Coap>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_ENERGY_REPORT));
SuccessOrExit(error = message->SetPayloadMarker());
@@ -191,8 +191,8 @@ void EnergyScanServer::SendReport(void)
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetMeshLocal16());
messageInfo.SetPeerAddr(mCommissioner);
messageInfo.SetPeerPort(kCoapUdpPort);
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo));
messageInfo.SetPeerPort(Tmf::kUdpPort);
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo));
otLogInfoMeshCoP("sent scan results");
+1 -1
View File
@@ -1271,7 +1271,7 @@ otError MeshForwarder::GetFramePriority(const uint8_t * aFrame,
dstPort = reinterpret_cast<const Ip6::Udp::Header *>(aFrame)->GetDestinationPort();
}
if ((dstPort == Mle::kUdpPort) || (dstPort == kCoapUdpPort))
if ((dstPort == Mle::kUdpPort) || (dstPort == Tmf::kUdpPort))
{
aPriority = Message::kPriorityNet;
}
+1 -1
View File
@@ -889,7 +889,7 @@ void Mle::SetRloc16(uint16_t aRloc16)
// Clear cached CoAP with old RLOC source
if (oldRloc16 != Mac::kShortAddrInvalid)
{
Get<Coap::Coap>().ClearRequests(mMeshLocal16.GetAddress());
Get<Tmf::TmfAgent>().ClearRequests(mMeshLocal16.GetAddress());
}
}
+15 -15
View File
@@ -105,7 +105,7 @@ void MleRouter::HandlePartitionChange(void)
mPreviousPartitionIdTimeout = GetNetworkIdTimeout();
Get<AddressResolver>().Clear();
IgnoreError(Get<Coap::Coap>().AbortTransaction(&MleRouter::HandleAddressSolicitResponse, this));
IgnoreError(Get<Tmf::TmfAgent>().AbortTransaction(&MleRouter::HandleAddressSolicitResponse, this));
mRouterTable.Clear();
}
@@ -217,8 +217,8 @@ exit:
void MleRouter::StopLeader(void)
{
Get<Coap::Coap>().RemoveResource(mAddressSolicit);
Get<Coap::Coap>().RemoveResource(mAddressRelease);
Get<Tmf::TmfAgent>().RemoveResource(mAddressSolicit);
Get<Tmf::TmfAgent>().RemoveResource(mAddressRelease);
Get<MeshCoP::ActiveDataset>().StopLeader();
Get<MeshCoP::PendingDataset>().StopLeader();
StopAdvertiseTimer();
@@ -362,8 +362,8 @@ void MleRouter::SetStateLeader(uint16_t aRloc16)
Get<NetworkData::Leader>().Start();
Get<MeshCoP::ActiveDataset>().StartLeader();
Get<MeshCoP::PendingDataset>().StartLeader();
Get<Coap::Coap>().AddResource(mAddressSolicit);
Get<Coap::Coap>().AddResource(mAddressRelease);
Get<Tmf::TmfAgent>().AddResource(mAddressSolicit);
Get<Tmf::TmfAgent>().AddResource(mAddressRelease);
Get<Ip6::Ip6>().SetForwardingEnabled(true);
Get<Ip6::Mpl>().SetTimerExpirations(kMplRouterDataMessageTimerExpirations);
Get<Mac::Mac>().SetBeaconEnabled(true);
@@ -3578,7 +3578,7 @@ otError MleRouter::SendAddressSolicit(ThreadStatusTlv::Status aStatus)
VerifyOrExit(!mAddressSolicitPending, OT_NOOP);
VerifyOrExit((message = Get<Coap::Coap>().NewPriorityMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = Get<Tmf::TmfAgent>().NewPriorityMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_ADDRESS_SOLICIT));
SuccessOrExit(error = message->SetPayloadMarker());
@@ -3600,10 +3600,10 @@ otError MleRouter::SendAddressSolicit(ThreadStatusTlv::Status aStatus)
SuccessOrExit(error = GetLeaderAddress(messageInfo.GetPeerAddr()));
messageInfo.SetSockAddr(GetMeshLocal16());
messageInfo.SetPeerPort(kCoapUdpPort);
messageInfo.SetPeerPort(Tmf::kUdpPort);
SuccessOrExit(
error = Get<Coap::Coap>().SendMessage(*message, messageInfo, &MleRouter::HandleAddressSolicitResponse, this));
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo,
&MleRouter::HandleAddressSolicitResponse, this));
mAddressSolicitPending = true;
Log("Send Address Solicit", messageInfo.GetPeerAddr());
@@ -3624,7 +3624,7 @@ void MleRouter::SendAddressRelease(void)
Ip6::MessageInfo messageInfo;
Coap::Message * message;
VerifyOrExit((message = Get<Coap::Coap>().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = Get<Tmf::TmfAgent>().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_ADDRESS_RELEASE));
SuccessOrExit(error = message->SetPayloadMarker());
@@ -3636,8 +3636,8 @@ void MleRouter::SendAddressRelease(void)
messageInfo.SetSockAddr(GetMeshLocal16());
SuccessOrExit(error = GetLeaderAddress(messageInfo.GetPeerAddr()));
messageInfo.SetPeerPort(kCoapUdpPort);
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo));
messageInfo.SetPeerPort(Tmf::kUdpPort);
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo));
Log("Send Address Release", messageInfo.GetPeerAddr());
@@ -3860,7 +3860,7 @@ void MleRouter::SendAddressSolicitResponse(const Coap::Message & aRequest,
ThreadRouterMaskTlv routerMaskTlv;
Coap::Message * message;
VerifyOrExit((message = Get<Coap::Coap>().NewPriorityMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = Get<Tmf::TmfAgent>().NewPriorityMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error = message->SetDefaultResponseHeader(aRequest));
SuccessOrExit(error = message->SetPayloadMarker());
@@ -3880,7 +3880,7 @@ void MleRouter::SendAddressSolicitResponse(const Coap::Message & aRequest,
SuccessOrExit(error = routerMaskTlv.AppendTo(*message));
}
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, aMessageInfo));
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, aMessageInfo));
Log("Send Address Reply", aMessageInfo.GetPeerAddr());
@@ -3920,7 +3920,7 @@ void MleRouter::HandleAddressRelease(Coap::Message &aMessage, const Ip6::Message
IgnoreError(mRouterTable.Release(routerId));
SuccessOrExit(Get<Coap::Coap>().SendEmptyAck(aMessage, aMessageInfo));
SuccessOrExit(Get<Tmf::TmfAgent>().SendEmptyAck(aMessage, aMessageInfo));
Log("Send Address Release Reply", aMessageInfo.GetPeerAddr());
+3 -3
View File
@@ -281,7 +281,7 @@ void MlrManager::SendMulticastListenerRegistration(void)
VerifyOrExit(addressesNum > 0, error = OT_ERROR_NOT_FOUND);
VerifyOrExit((message = Get<Coap::Coap>().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = Get<Tmf::TmfAgent>().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST);
SuccessOrExit(message->SetToken(Coap::Message::kDefaultTokenLength));
@@ -306,10 +306,10 @@ void MlrManager::SendMulticastListenerRegistration(void)
Get<BackboneRouter::Leader>().GetServer16());
}
messageInfo.SetPeerPort(kCoapUdpPort);
messageInfo.SetPeerPort(Tmf::kUdpPort);
messageInfo.SetSockAddr(mle.GetMeshLocal16());
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(
*message, messageInfo, &MlrManager::HandleMulticastListenerRegistrationResponse, this));
mMlrPending = true;
+3 -3
View File
@@ -806,7 +806,7 @@ otError NetworkData::SendServerDataNotification(uint16_t aRloc16, Coap::Response
Coap::Message * message = nullptr;
Ip6::MessageInfo messageInfo;
VerifyOrExit((message = Get<Coap::Coap>().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = Get<Tmf::TmfAgent>().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_SERVER_DATA));
SuccessOrExit(error = message->SetPayloadMarker());
@@ -827,8 +827,8 @@ otError NetworkData::SendServerDataNotification(uint16_t aRloc16, Coap::Response
IgnoreError(Get<Mle::MleRouter>().GetLeaderAloc(messageInfo.GetPeerAddr()));
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetMeshLocal16());
messageInfo.SetPeerPort(kCoapUdpPort);
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo, aHandler, aContext));
messageInfo.SetPeerPort(Tmf::kUdpPort);
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo, aHandler, aContext));
otLogInfoNetData("Sent server data notification");
+11 -11
View File
@@ -76,16 +76,16 @@ void Leader::Reset(void)
void Leader::Start(void)
{
Get<Coap::Coap>().AddResource(mServerData);
Get<Coap::Coap>().AddResource(mCommissioningDataGet);
Get<Coap::Coap>().AddResource(mCommissioningDataSet);
Get<Tmf::TmfAgent>().AddResource(mServerData);
Get<Tmf::TmfAgent>().AddResource(mCommissioningDataGet);
Get<Tmf::TmfAgent>().AddResource(mCommissioningDataSet);
}
void Leader::Stop(void)
{
Get<Coap::Coap>().RemoveResource(mServerData);
Get<Coap::Coap>().RemoveResource(mCommissioningDataGet);
Get<Coap::Coap>().RemoveResource(mCommissioningDataSet);
Get<Tmf::TmfAgent>().RemoveResource(mServerData);
Get<Tmf::TmfAgent>().RemoveResource(mCommissioningDataGet);
Get<Tmf::TmfAgent>().RemoveResource(mCommissioningDataSet);
}
void Leader::IncrementVersion(void)
@@ -164,7 +164,7 @@ void Leader::HandleServerData(Coap::Message &aMessage, const Ip6::MessageInfo &a
networkData.GetLength());
}
SuccessOrExit(Get<Coap::Coap>().SendEmptyAck(aMessage, aMessageInfo));
SuccessOrExit(Get<Tmf::TmfAgent>().SendEmptyAck(aMessage, aMessageInfo));
otLogInfoNetData("Sent network data registration acknowledgment");
@@ -305,7 +305,7 @@ void Leader::SendCommissioningGetResponse(const Coap::Message & aRequest,
uint8_t * data = nullptr;
uint8_t length = 0;
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get<Coap::Coap>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error = message->SetDefaultResponseHeader(aRequest));
SuccessOrExit(error = message->SetPayloadMarker());
@@ -350,7 +350,7 @@ void Leader::SendCommissioningGetResponse(const Coap::Message & aRequest,
IgnoreError(message->SetLength(message->GetLength() - 1));
}
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, aMessageInfo));
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, aMessageInfo));
otLogInfoMeshCoP("sent commissioning dataset get response");
@@ -369,14 +369,14 @@ void Leader::SendCommissioningSetResponse(const Coap::Message & aRequest,
otError error = OT_ERROR_NONE;
Coap::Message *message;
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get<Coap::Coap>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error = message->SetDefaultResponseHeader(aRequest));
SuccessOrExit(error = message->SetPayloadMarker());
SuccessOrExit(error = Tlv::AppendUint8Tlv(*message, MeshCoP::Tlv::kState, static_cast<uint8_t>(aState)));
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, aMessageInfo));
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, aMessageInfo));
otLogInfoMeshCoP("sent commissioning dataset set response");
+18 -18
View File
@@ -63,10 +63,10 @@ NetworkDiagnostic::NetworkDiagnostic(Instance &aInstance)
, mReceiveDiagnosticGetCallback(nullptr)
, mReceiveDiagnosticGetCallbackContext(nullptr)
{
Get<Coap::Coap>().AddResource(mDiagnosticGetRequest);
Get<Coap::Coap>().AddResource(mDiagnosticGetQuery);
Get<Coap::Coap>().AddResource(mDiagnosticGetAnswer);
Get<Coap::Coap>().AddResource(mDiagnosticReset);
Get<Tmf::TmfAgent>().AddResource(mDiagnosticGetRequest);
Get<Tmf::TmfAgent>().AddResource(mDiagnosticGetQuery);
Get<Tmf::TmfAgent>().AddResource(mDiagnosticGetAnswer);
Get<Tmf::TmfAgent>().AddResource(mDiagnosticReset);
}
void NetworkDiagnostic::SetReceiveDiagnosticGetCallback(otReceiveDiagnosticGetCallback aCallback,
@@ -85,7 +85,7 @@ otError NetworkDiagnostic::SendDiagnosticGet(const Ip6::Address &aDestination,
Ip6::MessageInfo messageInfo;
otCoapResponseHandler handler = nullptr;
VerifyOrExit((message = Get<Coap::Coap>().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = Get<Tmf::TmfAgent>().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
if (aDestination.IsMulticast())
{
@@ -119,9 +119,9 @@ otError NetworkDiagnostic::SendDiagnosticGet(const Ip6::Address &aDestination,
}
messageInfo.SetPeerAddr(aDestination);
messageInfo.SetPeerPort(kCoapUdpPort);
messageInfo.SetPeerPort(Tmf::kUdpPort);
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo, handler, this));
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo, handler, this));
otLogInfoNetDiag("Sent diagnostic get");
@@ -181,7 +181,7 @@ void NetworkDiagnostic::HandleDiagnosticGetAnswer(Coap::Message &aMessage, const
mReceiveDiagnosticGetCallback(&aMessage, &aMessageInfo, mReceiveDiagnosticGetCallbackContext);
}
SuccessOrExit(Get<Coap::Coap>().SendEmptyAck(aMessage, aMessageInfo));
SuccessOrExit(Get<Tmf::TmfAgent>().SendEmptyAck(aMessage, aMessageInfo));
otLogInfoNetDiag("Sent diagnostic answer acknowledgment");
@@ -487,13 +487,13 @@ void NetworkDiagnostic::HandleDiagnosticGetQuery(Coap::Message &aMessage, const
// DIAG_GET.qry may be sent as a confirmable message.
if (aMessage.IsConfirmable())
{
if (Get<Coap::Coap>().SendEmptyAck(aMessage, aMessageInfo) == OT_ERROR_NONE)
if (Get<Tmf::TmfAgent>().SendEmptyAck(aMessage, aMessageInfo) == OT_ERROR_NONE)
{
otLogInfoNetDiag("Sent diagnostic get query acknowledgment");
}
}
VerifyOrExit((message = Get<Coap::Coap>().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = Get<Tmf::TmfAgent>().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error =
message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_DIAGNOSTIC_GET_ANSWER));
@@ -513,7 +513,7 @@ void NetworkDiagnostic::HandleDiagnosticGetQuery(Coap::Message &aMessage, const
}
messageInfo.SetPeerAddr(aMessageInfo.GetPeerAddr());
messageInfo.SetPeerPort(kCoapUdpPort);
messageInfo.SetPeerPort(Tmf::kUdpPort);
SuccessOrExit(error = FillRequestedTlvs(aMessage, *message, networkDiagnosticTlv));
@@ -523,7 +523,7 @@ void NetworkDiagnostic::HandleDiagnosticGetQuery(Coap::Message &aMessage, const
IgnoreError(message->SetLength(message->GetLength() - 1));
}
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo, nullptr, this));
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo, nullptr, this));
otLogInfoNetDiag("Sent diagnostic get answer");
@@ -560,7 +560,7 @@ void NetworkDiagnostic::HandleDiagnosticGetRequest(Coap::Message &aMessage, cons
VerifyOrExit(networkDiagnosticTlv.GetType() == NetworkDiagnosticTlv::kTypeList, error = OT_ERROR_PARSE);
VerifyOrExit((message = Get<Coap::Coap>().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = Get<Tmf::TmfAgent>().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error = message->SetDefaultResponseHeader(aMessage));
SuccessOrExit(error = message->SetPayloadMarker());
@@ -573,7 +573,7 @@ void NetworkDiagnostic::HandleDiagnosticGetRequest(Coap::Message &aMessage, cons
IgnoreError(message->SetLength(message->GetOffset() - 1));
}
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo));
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo));
otLogInfoNetDiag("Sent diagnostic get response");
@@ -593,7 +593,7 @@ otError NetworkDiagnostic::SendDiagnosticReset(const Ip6::Address &aDestination,
Coap::Message * message = nullptr;
Ip6::MessageInfo messageInfo;
VerifyOrExit((message = Get<Coap::Coap>().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = Get<Tmf::TmfAgent>().NewMessage()) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_DIAGNOSTIC_RESET));
@@ -617,9 +617,9 @@ otError NetworkDiagnostic::SendDiagnosticReset(const Ip6::Address &aDestination,
}
messageInfo.SetPeerAddr(aDestination);
messageInfo.SetPeerPort(kCoapUdpPort);
messageInfo.SetPeerPort(Tmf::kUdpPort);
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo));
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo));
otLogInfoNetDiag("Sent network diagnostic reset");
@@ -672,7 +672,7 @@ void NetworkDiagnostic::HandleDiagnosticReset(Coap::Message &aMessage, const Ip6
}
}
SuccessOrExit(Get<Coap::Coap>().SendEmptyAck(aMessage, aMessageInfo));
SuccessOrExit(Get<Tmf::TmfAgent>().SendEmptyAck(aMessage, aMessageInfo));
otLogInfoNetDiag("Sent diagnostic reset acknowledgment");
+5 -5
View File
@@ -53,7 +53,7 @@ PanIdQueryServer::PanIdQueryServer(Instance &aInstance)
, mTimer(aInstance, PanIdQueryServer::HandleTimer, this)
, mPanIdQuery(OT_URI_PATH_PANID_QUERY, &PanIdQueryServer::HandleQuery, this)
{
Get<Coap::Coap>().AddResource(mPanIdQuery);
Get<Tmf::TmfAgent>().AddResource(mPanIdQuery);
}
void PanIdQueryServer::HandleQuery(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo)
@@ -80,7 +80,7 @@ void PanIdQueryServer::HandleQuery(Coap::Message &aMessage, const Ip6::MessageIn
if (aMessage.IsConfirmable() && !aMessageInfo.GetSockAddr().IsMulticast())
{
SuccessOrExit(Get<Coap::Coap>().SendEmptyAck(aMessage, responseInfo));
SuccessOrExit(Get<Tmf::TmfAgent>().SendEmptyAck(aMessage, responseInfo));
otLogInfoMeshCoP("sent panid query response");
}
@@ -115,7 +115,7 @@ void PanIdQueryServer::SendConflict(void)
Ip6::MessageInfo messageInfo;
Coap::Message * message;
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get<Coap::Coap>())) != nullptr, error = OT_ERROR_NO_BUFS);
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(Get<Tmf::TmfAgent>())) != nullptr, error = OT_ERROR_NO_BUFS);
SuccessOrExit(error = message->Init(OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_POST, OT_URI_PATH_PANID_CONFLICT));
SuccessOrExit(error = message->SetPayloadMarker());
@@ -128,8 +128,8 @@ void PanIdQueryServer::SendConflict(void)
messageInfo.SetSockAddr(Get<Mle::MleRouter>().GetMeshLocal16());
messageInfo.SetPeerAddr(mCommissioner);
messageInfo.SetPeerPort(kCoapUdpPort);
SuccessOrExit(error = Get<Coap::Coap>().SendMessage(*message, messageInfo));
messageInfo.SetPeerPort(Tmf::kUdpPort);
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, messageInfo));
otLogInfoMeshCoP("sent panid conflict");
+3 -30
View File
@@ -49,7 +49,7 @@ namespace ot {
ThreadNetif::ThreadNetif(Instance &aInstance)
: Netif(aInstance)
, mCoap(aInstance)
, mTmfAgent(aInstance)
#if OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE
, mDhcp6Client(aInstance)
#endif
@@ -127,7 +127,6 @@ ThreadNetif::ThreadNetif(Instance &aInstance)
, mTimeSync(aInstance)
#endif
{
Get<Coap::Coap>().SetInterceptor(&ThreadNetif::TmfFilter, this);
}
void ThreadNetif::Up(void)
@@ -145,7 +144,7 @@ void ThreadNetif::Up(void)
SubscribeAllNodesMulticast();
IgnoreError(Get<Mle::MleRouter>().Enable());
IgnoreError(Get<Coap::Coap>().Start(kCoapUdpPort));
IgnoreError(Get<Tmf::TmfAgent>().Start());
#if OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE
IgnoreError(Get<Dns::Client>().Start());
#endif
@@ -171,7 +170,7 @@ void ThreadNetif::Down(void)
#if OPENTHREAD_CONFIG_DTLS_ENABLE
Get<Coap::CoapSecure>().Stop();
#endif
IgnoreError(Get<Coap::Coap>().Stop());
IgnoreError(Get<Tmf::TmfAgent>().Stop());
IgnoreError(Get<Mle::MleRouter>().Disable());
RemoveAllExternalUnicastAddresses();
UnsubscribeAllExternalMulticastAddresses();
@@ -205,35 +204,9 @@ exit:
return error;
}
otError ThreadNetif::TmfFilter(const Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo, void *aContext)
{
OT_UNUSED_VARIABLE(aMessage);
return static_cast<ThreadNetif *>(aContext)->IsTmfMessage(aMessageInfo) ? OT_ERROR_NONE : OT_ERROR_NOT_TMF;
}
bool ThreadNetif::IsOnMesh(const Ip6::Address &aAddress) const
{
return Get<NetworkData::Leader>().IsOnMesh(aAddress);
}
bool ThreadNetif::IsTmfMessage(const Ip6::MessageInfo &aMessageInfo)
{
bool rval = true;
// A TMF message must comply with following rules:
// 1. The destination is a Mesh Local Address or a Link-Local Multicast Address or a Realm-Local Multicast Address,
// and the source is a Mesh Local Address. Or
// 2. Both the destination and the source are Link-Local Addresses.
VerifyOrExit(
((Get<Mle::MleRouter>().IsMeshLocalAddress(aMessageInfo.GetSockAddr()) ||
aMessageInfo.GetSockAddr().IsLinkLocalMulticast() || aMessageInfo.GetSockAddr().IsRealmLocalMulticast()) &&
Get<Mle::MleRouter>().IsMeshLocalAddress(aMessageInfo.GetPeerAddr())) ||
((aMessageInfo.GetSockAddr().IsLinkLocal() || aMessageInfo.GetSockAddr().IsLinkLocalMulticast()) &&
aMessageInfo.GetPeerAddr().IsLinkLocal()),
rval = false);
exit:
return rval;
}
} // namespace ot
+2 -13
View File
@@ -36,9 +36,9 @@
#include "openthread-core-config.h"
#include "coap/coap.hpp"
#include "coap/coap_secure.hpp"
#include "mac/mac.hpp"
#include "thread/tmf.hpp"
#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
#include "meshcop/border_agent.hpp"
@@ -180,19 +180,8 @@ public:
*/
bool IsOnMesh(const Ip6::Address &aAddress) const;
/**
* This method returns whether Thread Management Framework Addressing Rules are met.
*
* @retval TRUE if Thread Management Framework Addressing Rules are met.
* @retval FALSE if Thread Management Framework Addressing Rules are not met.
*
*/
bool IsTmfMessage(const Ip6::MessageInfo &aMessageInfo);
private:
static otError TmfFilter(const Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo, void *aContext);
Coap::Coap mCoap;
Tmf::TmfAgent mTmfAgent;
#if OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE
Dhcp6::Client mDhcp6Client;
#endif // OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE
-2
View File
@@ -50,8 +50,6 @@ using ot::Encoding::BigEndian::HostSwap32;
enum
{
kCoapUdpPort = 61631,
// Thread 1.2.0 5.19.13 limits the number of IPv6 addresses should be [1, 15].
kIPv6AddressesNumMin = 1,
kIPv6AddressesNumMax = 15,
+82
View File
@@ -0,0 +1,82 @@
/*
* Copyright (c) 2020, 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 implements Thread Management Framework (TMF) functionalities.
*/
#include "thread/tmf.hpp"
#include "common/locator-getters.hpp"
namespace ot {
namespace Tmf {
otError TmfAgent::Start(void)
{
otError error;
SuccessOrExit(error = Coap::Start(kUdpPort));
#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE
error = mSocket.BindToNetif(OT_NETIF_THREAD);
VerifyOrExit(OT_ERROR_NONE == error, IgnoreError(mSocket.Close()));
#endif
exit:
return error;
}
otError TmfAgent::Filter(const ot::Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo, void *aContext)
{
OT_UNUSED_VARIABLE(aMessage);
return static_cast<TmfAgent *>(aContext)->IsTmfMessage(aMessageInfo) ? OT_ERROR_NONE : OT_ERROR_NOT_TMF;
}
bool TmfAgent::IsTmfMessage(const Ip6::MessageInfo &aMessageInfo) const
{
bool rval = true;
// A TMF message must comply with following rules:
// 1. The destination is a Mesh Local Address or a Link-Local Multicast Address or a Realm-Local Multicast Address,
// and the source is a Mesh Local Address. Or
// 2. Both the destination and the source are Link-Local Addresses.
VerifyOrExit(
((Get<Mle::MleRouter>().IsMeshLocalAddress(aMessageInfo.GetSockAddr()) ||
aMessageInfo.GetSockAddr().IsLinkLocalMulticast() || aMessageInfo.GetSockAddr().IsRealmLocalMulticast()) &&
Get<Mle::MleRouter>().IsMeshLocalAddress(aMessageInfo.GetPeerAddr())) ||
((aMessageInfo.GetSockAddr().IsLinkLocal() || aMessageInfo.GetSockAddr().IsLinkLocalMulticast()) &&
aMessageInfo.GetPeerAddr().IsLinkLocal()),
rval = false);
exit:
return rval;
}
} // namespace Tmf
} // namespace ot
+92
View File
@@ -0,0 +1,92 @@
/*
* Copyright (c) 2020, 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 TMF functionality.
*/
#ifndef OT_CORE_THREAD_TMF_HPP_
#define OT_CORE_THREAD_TMF_HPP_
#include "coap/coap.hpp"
namespace ot {
namespace Tmf {
enum
{
kUdpPort = 61631, ///< TMF UDP Port
};
/**
* This class implements functionality of the Thread TMF agent.
*
*/
class TmfAgent : public Coap::Coap
{
public:
/**
* This constructor initializes the object.
*
* @param[in] aInstance A reference to the OpenThread instance.
*
*/
explicit TmfAgent(Instance &aInstance)
: Coap::Coap(aInstance)
{
SetInterceptor(&Filter, this);
}
/**
* This method starts the TMF agent.
*
* @retval OT_ERROR_NONE Successfully started the CoAP service.
* @retval OT_ERROR_ALREADY Already started.
*
*/
otError Start(void);
/**
* This method returns whether Thread Management Framework Addressing Rules are met.
*
* @retval TRUE if Thread Management Framework Addressing Rules are met.
* @retval FALSE if Thread Management Framework Addressing Rules are not met.
*
*/
bool IsTmfMessage(const Ip6::MessageInfo &aMessageInfo) const;
private:
otError Start(uint16_t aPort);
static otError Filter(const ot::Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo, void *aContext);
};
} // namespace Tmf
} // namespace ot
#endif // OT_CORE_THREAD_TMF_HPP_
+29 -27
View File
@@ -147,6 +147,9 @@ extern int
#include "common/logging.hpp"
#include "net/ip6_address.hpp"
unsigned int gNetifIndex = 0;
char gNetifName[IFNAMSIZ];
#if OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE
#ifndef OPENTHREAD_POSIX_TUN_DEVICE
@@ -213,8 +216,6 @@ static int sNetlinkFd = -1; ///< Used to receive netlink events.
#if OPENTHREAD_POSIX_USE_MLD_MONITOR
static int sMLDMonitorFd = -1; ///< Used to receive MLD events.
#endif
static unsigned int sTunIndex = 0;
static char sTunName[IFNAMSIZ];
#if OPENTHREAD_POSIX_USE_MLD_MONITOR
// ff02::16
static const otIp6Address kMLDv2MulticastAddress = {
@@ -312,7 +313,7 @@ static void UpdateUnicast(otInstance *aInstance, const otIp6Address &aAddress, u
struct in6_ifreq ifr6;
memcpy(&ifr6.ifr6_addr, &aAddress, sizeof(ifr6.ifr6_addr));
ifr6.ifr6_ifindex = static_cast<int>(sTunIndex);
ifr6.ifr6_ifindex = static_cast<int>(gNetifIndex);
ifr6.ifr6_prefixlen = aPrefixLength;
if (aIsAdded)
@@ -330,7 +331,7 @@ static void UpdateUnicast(otInstance *aInstance, const otIp6Address &aAddress, u
struct in6_aliasreq ifr6;
memset(&ifr6, 0, sizeof(ifr6));
strlcpy(ifr6.ifra_name, sTunName, sizeof(ifr6.ifra_name));
strlcpy(ifr6.ifra_name, gNetifName, sizeof(ifr6.ifra_name));
ifr6.ifra_addr.sin6_family = AF_INET6;
ifr6.ifra_addr.sin6_len = sizeof(ifr6.ifra_addr);
memcpy(&ifr6.ifra_addr.sin6_addr, &aAddress, sizeof(struct in6_addr));
@@ -376,7 +377,7 @@ static void UpdateMulticast(otInstance *aInstance, const otIp6Address &aAddress,
VerifyOrExit(sIpFd >= 0, OT_NOOP);
memcpy(&mreq.ipv6mr_multiaddr, &aAddress, sizeof(mreq.ipv6mr_multiaddr));
mreq.ipv6mr_interface = sTunIndex;
mreq.ipv6mr_interface = gNetifIndex;
int err;
err = setsockopt(sIpFd, IPPROTO_IPV6, (aIsAdded ? IPV6_JOIN_GROUP : IPV6_LEAVE_GROUP), &mreq, sizeof(mreq));
@@ -419,7 +420,7 @@ static void UpdateLink(otInstance *aInstance)
VerifyOrExit(sIpFd >= 0, OT_NOOP);
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, sTunName, sizeof(ifr.ifr_name));
strncpy(ifr.ifr_name, gNetifName, sizeof(ifr.ifr_name));
VerifyOrExit(ioctl(sIpFd, SIOCGIFFLAGS, &ifr) == 0, perror("ioctl"); error = OT_ERROR_FAILED);
ifState = ((ifr.ifr_flags & IFF_UP) == IFF_UP) ? true : false;
@@ -601,7 +602,8 @@ static void processNetifAddrEvent(otInstance *aInstance, struct nlmsghdr *aNetli
otError error = OT_ERROR_NONE;
struct sockaddr_in6 addr6;
VerifyOrExit(ifaddr->ifa_index == static_cast<unsigned int>(sTunIndex) && ifaddr->ifa_family == AF_INET6, OT_NOOP);
VerifyOrExit(ifaddr->ifa_index == static_cast<unsigned int>(gNetifIndex) && ifaddr->ifa_family == AF_INET6,
OT_NOOP);
rtaLength = IFA_PAYLOAD(aNetlinkMessage);
@@ -699,7 +701,7 @@ static void processNetifLinkEvent(otInstance *aInstance, struct nlmsghdr *aNetli
struct ifinfomsg *ifinfo = reinterpret_cast<struct ifinfomsg *>(NLMSG_DATA(aNetlinkMessage));
otError error = OT_ERROR_NONE;
VerifyOrExit(ifinfo->ifi_index == static_cast<int>(sTunIndex), OT_NOOP);
VerifyOrExit(ifinfo->ifi_index == static_cast<int>(gNetifIndex), OT_NOOP);
SuccessOrExit(error = otIp6SetEnabled(aInstance, ifinfo->ifi_flags & IFF_UP));
exit:
@@ -756,7 +758,7 @@ static void processNetifAddrEvent(otInstance *aInstance, struct rt_msghdr *rtm)
{
ifam = reinterpret_cast<struct ifa_msghdr *>(rtm);
VerifyOrExit(ifam->ifam_index == static_cast<unsigned int>(sTunIndex), OT_NOOP);
VerifyOrExit(ifam->ifam_index == static_cast<unsigned int>(gNetifIndex), OT_NOOP);
addrbuf = (uint8_t *)&ifam[1];
addrmask = (unsigned int)ifam->ifam_addrs;
@@ -766,7 +768,7 @@ static void processNetifAddrEvent(otInstance *aInstance, struct rt_msghdr *rtm)
{
ifmam = reinterpret_cast<struct ifma_msghdr *>(rtm);
VerifyOrExit(ifmam->ifmam_index == static_cast<unsigned int>(sTunIndex), OT_NOOP);
VerifyOrExit(ifmam->ifmam_index == static_cast<unsigned int>(gNetifIndex), OT_NOOP);
addrbuf = (uint8_t *)&ifmam[1];
addrmask = (unsigned int)ifmam->ifmam_addrs;
@@ -847,7 +849,7 @@ static void processNetifAddrEvent(otInstance *aInstance, struct rt_msghdr *rtm)
OT_UNUSED_VARIABLE(addressString); // if otLog*Plat is disabled, we'll get a warning
memset(&ifr6, 0, sizeof(ifr6));
strlcpy(ifr6.ifra_name, sTunName, sizeof(ifr6.ifra_name));
strlcpy(ifr6.ifra_name, gNetifName, sizeof(ifr6.ifra_name));
ifr6.ifra_addr.sin6_family = AF_INET6;
ifr6.ifra_addr.sin6_len = sizeof(ifr6.ifra_addr);
memcpy(&ifr6.ifra_addr.sin6_addr, &addr6.sin6_addr, sizeof(struct in6_addr));
@@ -940,7 +942,7 @@ static void processNetifInfoEvent(otInstance *aInstance, struct rt_msghdr *rtm)
struct if_msghdr *ifm = reinterpret_cast<struct if_msghdr *>(rtm);
otError error = OT_ERROR_NONE;
VerifyOrExit(ifm->ifm_index == static_cast<int>(sTunIndex), OT_NOOP);
VerifyOrExit(ifm->ifm_index == static_cast<int>(gNetifIndex), OT_NOOP);
UpdateLink(aInstance);
@@ -1054,7 +1056,7 @@ void platformNetifDeinit(void)
}
#endif
sTunIndex = 0;
gNetifIndex = 0;
}
#if OPENTHREAD_POSIX_USE_MLD_MONITOR
@@ -1063,13 +1065,13 @@ static void mldListenerInit(void)
struct ipv6_mreq mreq6;
sMLDMonitorFd = SocketWithCloseExec(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6, kSocketNonBlock);
mreq6.ipv6mr_interface = sTunIndex;
mreq6.ipv6mr_interface = gNetifIndex;
memcpy(&mreq6.ipv6mr_multiaddr, kMLDv2MulticastAddress.mFields.m8, sizeof(kMLDv2MulticastAddress.mFields.m8));
VerifyOrDie(setsockopt(sMLDMonitorFd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq6, sizeof(mreq6)) == 0, OT_EXIT_FAILURE);
#if defined(__linux__)
VerifyOrDie(setsockopt(sMLDMonitorFd, SOL_SOCKET, SO_BINDTODEVICE, sTunName,
static_cast<socklen_t>(strnlen(sTunName, IFNAMSIZ))) == 0,
VerifyOrDie(setsockopt(sMLDMonitorFd, SOL_SOCKET, SO_BINDTODEVICE, gNetifName,
static_cast<socklen_t>(strnlen(gNetifName, IFNAMSIZ))) == 0,
OT_EXIT_FAILURE);
#endif
}
@@ -1099,7 +1101,7 @@ static void processMLDEvent(otInstance *aInstance)
for (struct ifaddrs *ifAddr = ifAddrs; ifAddr != nullptr; ifAddr = ifAddr->ifa_next)
{
if (ifAddr->ifa_addr != nullptr && ifAddr->ifa_addr->sa_family == AF_INET6 &&
strncmp(sTunName, ifAddr->ifa_name, IFNAMSIZ) == 0)
strncmp(gNetifName, ifAddr->ifa_name, IFNAMSIZ) == 0)
{
struct sockaddr_in6 *addr6 = reinterpret_cast<struct sockaddr_in6 *>(ifAddr->ifa_addr);
@@ -1254,7 +1256,7 @@ static otError destroyTunnel(void)
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, sTunName, sizeof(ifr.ifr_name));
strncpy(ifr.ifr_name, gNetifName, sizeof(ifr.ifr_name));
VerifyOrExit(ioctl(sIpFd, SIOCIFDESTROY, &ifr) == 0, perror("ioctl"); error = OT_ERROR_FAILED);
error = OT_ERROR_NONE;
@@ -1355,13 +1357,13 @@ void platformNetifInit(otInstance *aInstance, const char *aInterfaceName)
VerifyOrDie(sIpFd >= 0, OT_EXIT_ERROR_ERRNO);
platformConfigureNetLink();
platformConfigureTunDevice(aInstance, aInterfaceName, sTunName, sizeof(sTunName));
platformConfigureTunDevice(aInstance, aInterfaceName, gNetifName, sizeof(gNetifName));
sTunIndex = if_nametoindex(sTunName);
VerifyOrDie(sTunIndex > 0, OT_EXIT_FAILURE);
gNetifIndex = if_nametoindex(gNetifName);
VerifyOrDie(gNetifIndex > 0, OT_EXIT_FAILURE);
#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE
platformUdpInit(sTunName);
platformUdpInit(gNetifName);
#endif
#if OPENTHREAD_POSIX_USE_MLD_MONITOR
mldListenerInit();
@@ -1382,7 +1384,7 @@ void platformNetifUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, fd_set *a
{
OT_UNUSED_VARIABLE(aWriteFdSet);
VerifyOrExit(sTunIndex > 0, OT_NOOP);
VerifyOrExit(gNetifIndex > 0, OT_NOOP);
assert(sTunFd >= 0);
assert(sNetlinkFd >= 0);
@@ -1420,7 +1422,7 @@ exit:
void platformNetifProcess(const fd_set *aReadFdSet, const fd_set *aWriteFdSet, const fd_set *aErrorFdSet)
{
OT_UNUSED_VARIABLE(aWriteFdSet);
VerifyOrExit(sTunIndex > 0, OT_NOOP);
VerifyOrExit(gNetifIndex > 0, OT_NOOP);
if (FD_ISSET(sTunFd, aErrorFdSet))
{
@@ -1469,10 +1471,10 @@ otError otPlatGetNetif(otInstance *aInstance, const char **outNetIfName, unsigne
otError error;
VerifyOrExit(sTunIndex != 0, error = OT_ERROR_FAILED);
VerifyOrExit(gNetifIndex != 0, error = OT_ERROR_FAILED);
*outNetIfName = sTunName;
*outNetIfIndex = sTunIndex;
*outNetIfName = gNetifName;
*outNetIfIndex = gNetifIndex;
error = OT_ERROR_NONE;
exit:
+13
View File
@@ -38,6 +38,7 @@
#include "openthread-posix-config.h"
#include <errno.h>
#include <net/if.h>
#include <stdio.h>
#include <string.h>
#include <sys/select.h>
@@ -394,6 +395,18 @@ enum SocketBlockOption
*/
int SocketWithCloseExec(int aDomain, int aType, int aProtocol, SocketBlockOption aBlockOption);
/**
* The name of Thread network interface.
*
*/
extern char gNetifName[IFNAMSIZ];
/**
* The index of Thread network interface.
*
*/
extern unsigned int gNetifIndex;
#ifdef __cplusplus
}
#endif
+65 -18
View File
@@ -55,8 +55,6 @@
#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE
static uint32_t sPlatNetifIndex = 0;
static const size_t kMaxUdpSize = 1280;
static void *FdToHandle(int aFd)
@@ -99,7 +97,7 @@ static otError transmitPacket(int aFd, uint8_t *aPayload, uint16_t aLength, cons
if (IsLinkLocal(peerAddr.sin6_addr) && !aMessageInfo.mIsHostInterface)
{
// sin6_scope_id only works for link local destinations
peerAddr.sin6_scope_id = sPlatNetifIndex;
peerAddr.sin6_scope_id = gNetifIndex;
}
memset(control, 0, sizeof(control));
@@ -139,7 +137,7 @@ static otError transmitPacket(int aFd, uint8_t *aPayload, uint16_t aLength, cons
cmsg->cmsg_type = IPV6_PKTINFO;
cmsg->cmsg_len = CMSG_LEN(sizeof(pktinfo));
pktinfo.ipi6_ifindex = aMessageInfo.mIsHostInterface ? 0 : sPlatNetifIndex;
pktinfo.ipi6_ifindex = aMessageInfo.mIsHostInterface ? 0 : gNetifIndex;
memcpy(&pktinfo.ipi6_addr, &aMessageInfo.mSockAddr, sizeof(pktinfo.ipi6_addr));
memcpy(CMSG_DATA(cmsg), &pktinfo, sizeof(pktinfo));
@@ -208,7 +206,7 @@ static otError receivePacket(int aFd, uint8_t *aPayload, uint16_t &aLength, otMe
memcpy(&pktinfo, CMSG_DATA(cmsg), sizeof(pktinfo));
aMessageInfo.mIsHostInterface = (pktinfo.ipi6_ifindex != sPlatNetifIndex);
aMessageInfo.mIsHostInterface = (pktinfo.ipi6_ifindex != gNetifIndex);
memcpy(&aMessageInfo.mSockAddr, &pktinfo.ipi6_addr, sizeof(aMessageInfo.mSockAddr));
}
}
@@ -257,10 +255,8 @@ otError otPlatUdpBind(otUdpSocket *aUdpSocket)
otError error = OT_ERROR_NONE;
int fd;
assert(sPlatNetifIndex != 0);
assert(gNetifIndex != 0);
assert(aUdpSocket->mHandle != nullptr);
VerifyOrExit(sPlatNetifIndex != 0, error = OT_ERROR_INVALID_STATE);
VerifyOrExit(aUdpSocket->mHandle != nullptr, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aUdpSocket->mSockName.mPort != 0, error = OT_ERROR_INVALID_ARGS);
fd = FdFromHandle(aUdpSocket->mHandle);
@@ -280,18 +276,52 @@ otError otPlatUdpBind(otUdpSocket *aUdpSocket)
VerifyOrExit(0 == setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &on, sizeof(on)), error = OT_ERROR_FAILED);
}
VerifyOrExit(0 == setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_IF, &sPlatNetifIndex, sizeof(sPlatNetifIndex)),
VerifyOrExit(0 == setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_IF, &gNetifIndex, sizeof(gNetifIndex)),
error = OT_ERROR_FAILED);
exit:
if (error == OT_ERROR_FAILED)
{
perror("otPlatUdpBind");
otLogCritPlat("Failed to bind UDP socket: %s", strerror(errno));
}
return error;
}
otError otPlatUdpBindToNetif(otUdpSocket *aUdpSocket, otNetifIdentifier aNetifIdentifier)
{
otError error = OT_ERROR_NONE;
int fd = FdFromHandle(aUdpSocket->mHandle);
switch (aNetifIdentifier)
{
case OT_NETIF_UNSPECIFIED:
{
#if __linux__
VerifyOrExit(setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, nullptr, 0) == 0, error = OT_ERROR_FAILED);
#else // __NetBSD__ || __FreeBSD__ || __APPLE__
unsigned int netifIndex = 0;
VerifyOrExit(setsockopt(fd, IPPROTO_IP, IP_BOUND_IF, &netifIndex, sizeof(netifIndex)), error = OT_ERROR_FAILED);
#endif // __linux__
break;
}
case OT_NETIF_THREAD:
{
#if __linux__
VerifyOrExit(setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &gNetifName, strlen(gNetifName)) == 0,
error = OT_ERROR_FAILED);
#else // __NetBSD__ || __FreeBSD__ || __APPLE__
VerifyOrExit(setsockopt(fd, IPPROTO_IP, IP_BOUND_IF, &gNetifIndex, sizeof(gNetifIndex)),
error = OT_ERROR_FAILED);
#endif // __linux__
break;
}
}
exit:
return error;
}
otError otPlatUdpConnect(otUdpSocket *aUdpSocket)
{
otError error = OT_ERROR_NONE;
@@ -316,11 +346,27 @@ otError otPlatUdpConnect(otUdpSocket *aUdpSocket)
#ifdef __APPLE__
sin6.sin6_family = AF_UNSPEC;
#else
char netifName[IFNAMSIZ];
socklen_t len = sizeof(netifName);
if (getsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &netifName, &len) != 0)
{
otLogWarnPlat("Failed to read socket bound device: %s", strerror(errno));
len = 0;
}
// There is a bug in linux that connecting to AF_UNSPEC does not disconnect.
// We create new socket to disconnect.
SuccessOrExit(error = otPlatUdpClose(aUdpSocket));
SuccessOrExit(error = otPlatUdpSocket(aUdpSocket));
SuccessOrExit(error = otPlatUdpBind(aUdpSocket));
if (len > 0 && netifName[0] != '\0')
{
fd = FdFromHandle(aUdpSocket->mHandle);
VerifyOrExit(setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &netifName, len) == 0, error = OT_ERROR_FAILED);
}
ExitNow();
#endif
}
@@ -371,7 +417,7 @@ exit:
void platformUdpUpdateFdSet(otInstance *aInstance, fd_set *aReadFdSet, int *aMaxFd)
{
VerifyOrExit(sPlatNetifIndex != 0, OT_NOOP);
VerifyOrExit(gNetifIndex != 0, OT_NOOP);
for (otUdpSocket *socket = otUdpGetSockets(aInstance); socket != nullptr; socket = socket->mNext)
{
@@ -402,20 +448,22 @@ void platformUdpInit(const char *aIfName)
DieNow(OT_EXIT_INVALID_ARGUMENTS);
}
sPlatNetifIndex = if_nametoindex(aIfName);
if (sPlatNetifIndex == 0)
if (aIfName != gNetifName)
{
perror("if_nametoindex");
VerifyOrDie(strlen(aIfName) < sizeof(gNetifName) - 1, OT_EXIT_INVALID_ARGUMENTS);
assert(gNetifIndex == 0);
strcpy(gNetifName, aIfName);
gNetifIndex = if_nametoindex(gNetifName);
VerifyOrDie(gNetifIndex != 0, OT_EXIT_ERROR_ERRNO);
}
assert(gNetifIndex != 0);
}
void platformUdpProcess(otInstance *aInstance, const fd_set *aReadFdSet)
{
otMessageSettings msgSettings = {false, OT_MESSAGE_PRIORITY_NORMAL};
VerifyOrExit(sPlatNetifIndex != 0, OT_NOOP);
for (otUdpSocket *socket = otUdpGetSockets(aInstance); socket != nullptr; socket = socket->mNext)
{
int fd = FdFromHandle(socket->mHandle);
@@ -455,7 +503,6 @@ void platformUdpProcess(otInstance *aInstance, const fd_set *aReadFdSet)
}
}
exit:
return;
}
+62
View File
@@ -0,0 +1,62 @@
#!/usr/bin/expect -f
#
# Copyright (c) 2020, 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.
#
# This script verifies UDP socket can connect and disconnect when platform UDP is enabled.
source "tests/scripts/expect/_common.exp"
set spawn_id [spawn_node 1]
send "panid 0xface\n"
expect "Done"
send "ifconfig up\n"
expect "Done"
send "thread start\n"
expect "Done"
wait_for "state" "leader"
send "udp open\n"
expect "Done"
send "udp bind :: 1234\n"
expect "Done"
send "udp connect fdde:ad00:beef:0:bb1:ebd6:ad10:f33 1234\n"
expect "Done"
send "udp connect :: 0\n"
expect "Done"
send "udp close\n"
expect "Done"
dispose