mirror of
https://github.com/espressif/openthread.git
synced 2026-09-03 07:40:10 +00:00
Append CoAP Token and Message ID field for ED/PANID query/report/conflict message. (#712)
This commit is contained in:
@@ -36,6 +36,7 @@
|
||||
#include <common/debug.hpp>
|
||||
#include <common/encoding.hpp>
|
||||
#include <common/logging.hpp>
|
||||
#include <platform/random.h>
|
||||
#include <meshcop/energy_scan_client.hpp>
|
||||
#include <thread/meshcop_tlvs.hpp>
|
||||
#include <thread/thread_netif.hpp>
|
||||
@@ -49,12 +50,13 @@ namespace Thread {
|
||||
EnergyScanClient::EnergyScanClient(ThreadNetif &aThreadNetif) :
|
||||
mEnergyScan(OPENTHREAD_URI_ENERGY_REPORT, &EnergyScanClient::HandleReport, this),
|
||||
mSocket(aThreadNetif.GetIp6().mUdp),
|
||||
mTimer(aThreadNetif.GetIp6().mTimerScheduler, &EnergyScanClient::HandleTimer, this),
|
||||
mCoapServer(aThreadNetif.GetCoapServer()),
|
||||
mNetif(aThreadNetif)
|
||||
{
|
||||
mCoapServer.AddResource(mEnergyScan);
|
||||
mSocket.Open(HandleUdpReceive, this);
|
||||
|
||||
mCoapMessageId = static_cast<uint8_t>(otPlatRandomGet());
|
||||
}
|
||||
|
||||
ThreadError EnergyScanClient::SendQuery(uint32_t aChannelMask, uint8_t aCount, uint16_t aPeriod,
|
||||
@@ -76,11 +78,16 @@ ThreadError EnergyScanClient::SendQuery(uint32_t aChannelMask, uint8_t aCount, u
|
||||
Ip6::MessageInfo messageInfo;
|
||||
Message *message;
|
||||
|
||||
for (size_t i = 0; i < sizeof(mCoapToken); i++)
|
||||
{
|
||||
mCoapToken[i] = static_cast<uint8_t>(otPlatRandomGet());
|
||||
}
|
||||
|
||||
header.Init();
|
||||
header.SetType(aAddress.IsMulticast() ? Coap::Header::kTypeNonConfirmable : Coap::Header::kTypeConfirmable);
|
||||
header.SetCode(Coap::Header::kCodePost);
|
||||
header.SetMessageId(0);
|
||||
header.SetToken(NULL, 0);
|
||||
header.SetMessageId(++mCoapMessageId);
|
||||
header.SetToken(mCoapToken, sizeof(mCoapToken));
|
||||
header.AppendUriPathOptions(OPENTHREAD_URI_ENERGY_SCAN);
|
||||
header.Finalize();
|
||||
|
||||
@@ -216,15 +223,6 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void EnergyScanClient::HandleTimer(void *aContext)
|
||||
{
|
||||
static_cast<EnergyScanClient *>(aContext)->HandleTimer();
|
||||
}
|
||||
|
||||
void EnergyScanClient::HandleTimer(void)
|
||||
{
|
||||
}
|
||||
|
||||
void EnergyScanClient::HandleUdpReceive(void *aContext, otMessage aMessage, const otMessageInfo *aMessageInfo)
|
||||
{
|
||||
otLogInfoMeshCoP("received energy scan query response\r\n");
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
#include <openthread-types.h>
|
||||
#include <commissioning/commissioner.h>
|
||||
#include <coap/coap_server.hpp>
|
||||
#include <common/timer.hpp>
|
||||
#include <net/ip6_address.hpp>
|
||||
#include <net/udp6.hpp>
|
||||
|
||||
@@ -82,9 +81,6 @@ private:
|
||||
const Ip6::MessageInfo &aMessageInfo);
|
||||
void HandleReport(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
static void HandleTimer(void *aContext);
|
||||
void HandleTimer(void);
|
||||
|
||||
static void HandleUdpReceive(void *aContext, otMessage aMessage, const otMessageInfo *aMessageInfo);
|
||||
|
||||
ThreadError SendResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aRequestMessageInfo);
|
||||
@@ -94,9 +90,10 @@ private:
|
||||
|
||||
Coap::Resource mEnergyScan;
|
||||
Ip6::UdpSocket mSocket;
|
||||
Timer mTimer;
|
||||
|
||||
Coap::Server &mCoapServer;
|
||||
uint8_t mCoapToken[2];
|
||||
uint16_t mCoapMessageId;
|
||||
ThreadNetif &mNetif;
|
||||
};
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include <common/code_utils.hpp>
|
||||
#include <common/debug.hpp>
|
||||
#include <common/logging.hpp>
|
||||
#include <platform/random.h>
|
||||
#include <meshcop/panid_query_client.hpp>
|
||||
#include <thread/meshcop_tlvs.hpp>
|
||||
#include <thread/thread_netif.hpp>
|
||||
@@ -45,12 +46,13 @@ namespace Thread {
|
||||
PanIdQueryClient::PanIdQueryClient(ThreadNetif &aThreadNetif) :
|
||||
mPanIdQuery(OPENTHREAD_URI_PANID_CONFLICT, &PanIdQueryClient::HandleConflict, this),
|
||||
mSocket(aThreadNetif.GetIp6().mUdp),
|
||||
mTimer(aThreadNetif.GetIp6().mTimerScheduler, &PanIdQueryClient::HandleTimer, this),
|
||||
mCoapServer(aThreadNetif.GetCoapServer()),
|
||||
mNetif(aThreadNetif)
|
||||
{
|
||||
mCoapServer.AddResource(mPanIdQuery);
|
||||
mSocket.Open(HandleUdpReceive, this);
|
||||
|
||||
mCoapMessageId = static_cast<uint8_t>(otPlatRandomGet());
|
||||
}
|
||||
|
||||
ThreadError PanIdQueryClient::SendQuery(uint16_t aPanId, uint32_t aChannelMask, const Ip6::Address &aAddress,
|
||||
@@ -69,11 +71,16 @@ ThreadError PanIdQueryClient::SendQuery(uint16_t aPanId, uint32_t aChannelMask,
|
||||
Ip6::MessageInfo messageInfo;
|
||||
Message *message;
|
||||
|
||||
for (size_t i = 0; i < sizeof(mCoapToken); i++)
|
||||
{
|
||||
mCoapToken[i] = static_cast<uint8_t>(otPlatRandomGet());
|
||||
}
|
||||
|
||||
header.Init();
|
||||
header.SetType(aAddress.IsMulticast() ? Coap::Header::kTypeNonConfirmable : Coap::Header::kTypeConfirmable);
|
||||
header.SetCode(Coap::Header::kCodePost);
|
||||
header.SetMessageId(0);
|
||||
header.SetToken(NULL, 0);
|
||||
header.SetMessageId(++mCoapMessageId);
|
||||
header.SetToken(mCoapToken, sizeof(mCoapToken));
|
||||
header.AppendUriPathOptions(OPENTHREAD_URI_PANID_QUERY);
|
||||
header.Finalize();
|
||||
|
||||
@@ -203,15 +210,6 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void PanIdQueryClient::HandleTimer(void *aContext)
|
||||
{
|
||||
static_cast<PanIdQueryClient *>(aContext)->HandleTimer();
|
||||
}
|
||||
|
||||
void PanIdQueryClient::HandleTimer(void)
|
||||
{
|
||||
}
|
||||
|
||||
void PanIdQueryClient::HandleUdpReceive(void *aContext, otMessage aMessage, const otMessageInfo *aMessageInfo)
|
||||
{
|
||||
otLogInfoMeshCoP("received panid query response\r\n");
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
#include <openthread-types.h>
|
||||
#include <commissioning/commissioner.h>
|
||||
#include <coap/coap_server.hpp>
|
||||
#include <common/timer.hpp>
|
||||
#include <net/ip6_address.hpp>
|
||||
#include <net/udp6.hpp>
|
||||
|
||||
@@ -80,9 +79,6 @@ private:
|
||||
const Ip6::MessageInfo &aMessageInfo);
|
||||
void HandleConflict(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
static void HandleTimer(void *aContext);
|
||||
void HandleTimer(void);
|
||||
|
||||
static void HandleUdpReceive(void *aContext, otMessage aMessage, const otMessageInfo *aMessageInfo);
|
||||
|
||||
ThreadError SendConflictResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aRequestMessageInfo);
|
||||
@@ -92,9 +88,10 @@ private:
|
||||
|
||||
Coap::Resource mPanIdQuery;
|
||||
Ip6::UdpSocket mSocket;
|
||||
Timer mTimer;
|
||||
|
||||
Coap::Server &mCoapServer;
|
||||
uint8_t mCoapToken[2];
|
||||
uint16_t mCoapMessageId;
|
||||
ThreadNetif &mNetif;
|
||||
};
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include <common/code_utils.hpp>
|
||||
#include <common/debug.hpp>
|
||||
#include <common/logging.hpp>
|
||||
#include <platform/random.h>
|
||||
#include <thread/meshcop_tlvs.hpp>
|
||||
#include <thread/energy_scan_server.hpp>
|
||||
#include <thread/thread_netif.hpp>
|
||||
@@ -55,6 +56,8 @@ EnergyScanServer::EnergyScanServer(ThreadNetif &aThreadNetif) :
|
||||
|
||||
mCoapServer.AddResource(mEnergyScan);
|
||||
mSocket.Open(HandleUdpReceive, this);
|
||||
|
||||
mCoapMessageId = static_cast<uint8_t>(otPlatRandomGet());
|
||||
}
|
||||
|
||||
void EnergyScanServer::HandleRequest(void *aContext, Coap::Header &aHeader, Message &aMessage,
|
||||
@@ -231,8 +234,8 @@ ThreadError EnergyScanServer::SendReport(void)
|
||||
header.Init();
|
||||
header.SetType(Coap::Header::kTypeConfirmable);
|
||||
header.SetCode(Coap::Header::kCodePost);
|
||||
header.SetMessageId(0);
|
||||
header.SetToken(NULL, 0);
|
||||
header.SetMessageId(++mCoapMessageId);
|
||||
header.SetToken(mCoapToken, sizeof(mCoapToken));
|
||||
header.AppendUriPathOptions(OPENTHREAD_URI_ENERGY_REPORT);
|
||||
header.Finalize();
|
||||
|
||||
@@ -272,6 +275,7 @@ exit:
|
||||
|
||||
void EnergyScanServer::HandleUdpReceive(void *aContext, otMessage aMessage, const otMessageInfo *aMessageInfo)
|
||||
{
|
||||
otLogInfoMeshCoP("received scan report response\r\n");
|
||||
(void)aContext;
|
||||
(void)aMessage;
|
||||
(void)aMessageInfo;
|
||||
|
||||
@@ -105,6 +105,8 @@ private:
|
||||
Ip6::NetifCallback mNetifCallback;
|
||||
|
||||
Coap::Server &mCoapServer;
|
||||
uint8_t mCoapToken[2];
|
||||
uint16_t mCoapMessageId;
|
||||
ThreadNetif &mNetif;
|
||||
};
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include <common/code_utils.hpp>
|
||||
#include <common/debug.hpp>
|
||||
#include <common/logging.hpp>
|
||||
#include <platform/random.h>
|
||||
#include <thread/meshcop_tlvs.hpp>
|
||||
#include <thread/panid_query_server.hpp>
|
||||
#include <thread/thread_netif.hpp>
|
||||
@@ -51,6 +52,8 @@ PanIdQueryServer::PanIdQueryServer(ThreadNetif &aThreadNetif) :
|
||||
{
|
||||
mCoapServer.AddResource(mPanIdQuery);
|
||||
mSocket.Open(HandleUdpReceive, this);
|
||||
|
||||
mCoapMessageId = static_cast<uint8_t>(otPlatRandomGet());
|
||||
}
|
||||
|
||||
void PanIdQueryServer::HandleQuery(void *aContext, Coap::Header &aHeader, Message &aMessage,
|
||||
@@ -170,11 +173,16 @@ ThreadError PanIdQueryServer::SendConflict(void)
|
||||
Ip6::MessageInfo messageInfo;
|
||||
Message *message;
|
||||
|
||||
for (size_t i = 0; i < sizeof(mCoapToken); i++)
|
||||
{
|
||||
mCoapToken[i] = static_cast<uint8_t>(otPlatRandomGet());
|
||||
}
|
||||
|
||||
header.Init();
|
||||
header.SetType(Coap::Header::kTypeConfirmable);
|
||||
header.SetCode(Coap::Header::kCodePost);
|
||||
header.SetMessageId(0);
|
||||
header.SetToken(NULL, 0);
|
||||
header.SetMessageId(++mCoapMessageId);
|
||||
header.SetToken(mCoapToken, sizeof(mCoapToken));
|
||||
header.AppendUriPathOptions(OPENTHREAD_URI_PANID_CONFLICT);
|
||||
header.Finalize();
|
||||
|
||||
@@ -230,6 +238,7 @@ void PanIdQueryServer::HandleTimer(void)
|
||||
|
||||
void PanIdQueryServer::HandleUdpReceive(void *aContext, otMessage aMessage, const otMessageInfo *aMessageInfo)
|
||||
{
|
||||
otLogInfoMeshCoP("received panid conflict response\r\n");
|
||||
(void)aContext;
|
||||
(void)aMessage;
|
||||
(void)aMessageInfo;
|
||||
|
||||
@@ -92,6 +92,8 @@ private:
|
||||
Timer mTimer;
|
||||
|
||||
Coap::Server &mCoapServer;
|
||||
uint8_t mCoapToken[2];
|
||||
uint16_t mCoapMessageId;
|
||||
ThreadNetif &mNetif;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user