[meshcop] integrate commissioner client classes (#12618)

This commit removes the standalone `AnnounceBeginClient`,
`EnergyScanClient`, and `PanIdQueryClient` classes, integrating their
methods and TMF message handlers directly into the
`MeshCoP::Commissioner` class.

Since these client classes contained minimal state and primarily
served as simple wrappers for sending specific requests and handling
callbacks, merging them into the main `Commissioner` class simplifies
the architecture, removes unnecessary auxiliary classes, and shrinks
the overall codebase size.
This commit is contained in:
Abtin Keshavarzian
2026-03-05 10:37:35 -06:00
committed by GitHub
parent 271c50a044
commit 75c554e9b1
14 changed files with 203 additions and 628 deletions
-6
View File
@@ -551,8 +551,6 @@ openthread_core_files = [
"mac/sub_mac_wed.cpp",
"mac/wakeup_tx_scheduler.cpp",
"mac/wakeup_tx_scheduler.hpp",
"meshcop/announce_begin_client.cpp",
"meshcop/announce_begin_client.hpp",
"meshcop/border_agent.cpp",
"meshcop/border_agent.hpp",
"meshcop/border_agent_admitter.cpp",
@@ -572,8 +570,6 @@ openthread_core_files = [
"meshcop/dataset_manager_ftd.cpp",
"meshcop/dataset_updater.cpp",
"meshcop/dataset_updater.hpp",
"meshcop/energy_scan_client.cpp",
"meshcop/energy_scan_client.hpp",
"meshcop/extended_panid.cpp",
"meshcop/extended_panid.hpp",
"meshcop/joiner.cpp",
@@ -590,8 +586,6 @@ openthread_core_files = [
"meshcop/network_identity.hpp",
"meshcop/network_name.cpp",
"meshcop/network_name.hpp",
"meshcop/panid_query_client.cpp",
"meshcop/panid_query_client.hpp",
"meshcop/secure_transport.cpp",
"meshcop/secure_transport.hpp",
"meshcop/seeker.cpp",
-3
View File
@@ -165,7 +165,6 @@ set(COMMON_SOURCES
mac/sub_mac_csl_receiver.cpp
mac/sub_mac_wed.cpp
mac/wakeup_tx_scheduler.cpp
meshcop/announce_begin_client.cpp
meshcop/border_agent.cpp
meshcop/border_agent_admitter.cpp
meshcop/border_agent_ephemeral_key.cpp
@@ -176,7 +175,6 @@ set(COMMON_SOURCES
meshcop/dataset_manager.cpp
meshcop/dataset_manager_ftd.cpp
meshcop/dataset_updater.cpp
meshcop/energy_scan_client.cpp
meshcop/extended_panid.cpp
meshcop/joiner.cpp
meshcop/joiner_router.cpp
@@ -185,7 +183,6 @@ set(COMMON_SOURCES
meshcop/meshcop_tlvs.cpp
meshcop/network_identity.cpp
meshcop/network_name.cpp
meshcop/panid_query_client.cpp
meshcop/secure_transport.cpp
meshcop/seeker.cpp
meshcop/steering_data.cpp
+5 -5
View File
@@ -127,8 +127,8 @@ otError otCommissionerAnnounceBegin(otInstance *aInstance,
uint16_t aPeriod,
const otIp6Address *aAddress)
{
return AsCoreType(aInstance).Get<MeshCoP::Commissioner>().GetAnnounceBeginClient().SendRequest(
aChannelMask, aCount, aPeriod, AsCoreType(aAddress));
return AsCoreType(aInstance).Get<MeshCoP::Commissioner>().SendAnnounceBeginRequest(aChannelMask, aCount, aPeriod,
AsCoreType(aAddress));
}
otError otCommissionerEnergyScan(otInstance *aInstance,
@@ -140,7 +140,7 @@ otError otCommissionerEnergyScan(otInstance *aInstance,
otCommissionerEnergyReportCallback aCallback,
void *aContext)
{
return AsCoreType(aInstance).Get<MeshCoP::Commissioner>().GetEnergyScanClient().SendQuery(
return AsCoreType(aInstance).Get<MeshCoP::Commissioner>().SendEnergyScanQuery(
aChannelMask, aCount, aPeriod, aScanDuration, AsCoreType(aAddress), aCallback, aContext);
}
@@ -151,8 +151,8 @@ otError otCommissionerPanIdQuery(otInstance *aInstance,
otCommissionerPanIdConflictCallback aCallback,
void *aContext)
{
return AsCoreType(aInstance).Get<MeshCoP::Commissioner>().GetPanIdQueryClient().SendQuery(
aPanId, aChannelMask, AsCoreType(aAddress), aCallback, aContext);
return AsCoreType(aInstance).Get<MeshCoP::Commissioner>().SendPanIdQuery(aPanId, aChannelMask, AsCoreType(aAddress),
aCallback, aContext);
}
otError otCommissionerSendMgmtGet(otInstance *aInstance, const uint8_t *aTlvs, uint8_t aLength)
-6
View File
@@ -964,12 +964,6 @@ template <> inline TimeSync &Instance::Get(void) { return mTimeSync; }
#if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD
template <> inline MeshCoP::Commissioner &Instance::Get(void) { return mCommissioner; }
template <> inline AnnounceBeginClient &Instance::Get(void) { return mCommissioner.GetAnnounceBeginClient(); }
template <> inline EnergyScanClient &Instance::Get(void) { return mCommissioner.GetEnergyScanClient(); }
template <> inline PanIdQueryClient &Instance::Get(void) { return mCommissioner.GetPanIdQueryClient(); }
#endif
#if OPENTHREAD_CONFIG_PLATFORM_DNSSD_ENABLE || OPENTHREAD_CONFIG_MULTICAST_DNS_ENABLE
@@ -1,82 +0,0 @@
/*
* Copyright (c) 2016, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file implements the Announce Begin Client.
*/
#include "announce_begin_client.hpp"
#if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD
#include "instance/instance.hpp"
namespace ot {
RegisterLogModule("MeshCoP");
AnnounceBeginClient::AnnounceBeginClient(Instance &aInstance)
: InstanceLocator(aInstance)
{
}
Error AnnounceBeginClient::SendRequest(uint32_t aChannelMask,
uint8_t aCount,
uint16_t aPeriod,
const Ip6::Address &aAddress)
{
Error error = kErrorNone;
Coap::Message *message = nullptr;
VerifyOrExit(Get<MeshCoP::Commissioner>().IsActive(), error = kErrorInvalidState);
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = message->InitAsPost(aAddress, kUriAnnounceBegin));
SuccessOrExit(error = message->AppendPayloadMarker());
SuccessOrExit(
error = Tlv::Append<MeshCoP::CommissionerSessionIdTlv>(*message, Get<MeshCoP::Commissioner>().GetSessionId()));
SuccessOrExit(error = MeshCoP::ChannelMaskTlv::AppendTo(*message, aChannelMask));
SuccessOrExit(error = Tlv::Append<MeshCoP::CountTlv>(*message, aCount));
SuccessOrExit(error = Tlv::Append<MeshCoP::PeriodTlv>(*message, aPeriod));
SuccessOrExit(error = Get<Tmf::Agent>().SendMessageTo(*message, aAddress));
LogInfo("Sent %s", UriToString<kUriAnnounceBegin>());
exit:
FreeMessageOnError(message, error);
return error;
}
} // namespace ot
#endif // OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD
@@ -1,81 +0,0 @@
/*
* Copyright (c) 2016, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file includes definitions for responding to Announce Requests.
*/
#ifndef OT_CORE_MESHCOP_ANNOUNCE_BEGIN_CLIENT_HPP_
#define OT_CORE_MESHCOP_ANNOUNCE_BEGIN_CLIENT_HPP_
#include "openthread-core-config.h"
#if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD
#include "coap/coap.hpp"
#include "common/locator.hpp"
#include "net/ip6_address.hpp"
#include "net/udp6.hpp"
namespace ot {
/**
* Implements handling Announce Begin Requests.
*/
class AnnounceBeginClient : public InstanceLocator
{
public:
/**
* Initializes the object.
*/
explicit AnnounceBeginClient(Instance &aInstance);
/**
* Sends a Announce Begin message.
*
* @param[in] aChannelMask The channel mask value.
* @param[in] aCount The number of Announce messages sent per channel.
* @param[in] aPeriod The time between two successive MLE Announce transmissions (in milliseconds).
* @param[in] aAddress The destination address.
*
* @retval kErrorNone Successfully enqueued the Announce Begin message.
* @retval kErrorNoBufs Insufficient buffers to generate a Announce Begin message.
*/
Error SendRequest(uint32_t aChannelMask, uint8_t aCount, uint16_t aPeriod, const Ip6::Address &aAddress);
};
/**
* @}
*/
} // namespace ot
#endif // OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD
#endif // OT_CORE_MESHCOP_ANNOUNCE_BEGIN_CLIENT_HPP_
+144 -3
View File
@@ -52,9 +52,6 @@ Commissioner::Commissioner(Instance &aInstance)
, mJoinerExpirationTimer(aInstance)
, mTimer(aInstance)
, mJoinerSessionTimer(aInstance)
, mAnnounceBegin(aInstance)
, mEnergyScan(aInstance)
, mPanIdQuery(aInstance)
, mState(kStateDisabled)
{
ClearAllBytes(mJoiners);
@@ -1007,6 +1004,150 @@ exit:
return error;
}
Error Commissioner::SendAnnounceBeginRequest(uint32_t aChannelMask,
uint8_t aCount,
uint16_t aPeriod,
const Ip6::Address &aAddress)
{
Error error = kErrorNone;
Coap::Message *message = nullptr;
VerifyOrExit(IsActive(), error = kErrorInvalidState);
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = message->InitAsPost(aAddress, kUriAnnounceBegin));
SuccessOrExit(error = message->AppendPayloadMarker());
SuccessOrExit(error = Tlv::Append<CommissionerSessionIdTlv>(*message, GetSessionId()));
SuccessOrExit(error = ChannelMaskTlv::AppendTo(*message, aChannelMask));
SuccessOrExit(error = Tlv::Append<CountTlv>(*message, aCount));
SuccessOrExit(error = Tlv::Append<PeriodTlv>(*message, aPeriod));
SuccessOrExit(error = Get<Tmf::Agent>().SendMessageTo(*message, aAddress));
LogInfo("Sent %s", UriToString<kUriAnnounceBegin>());
exit:
FreeMessageOnError(message, error);
return error;
}
Error Commissioner::SendEnergyScanQuery(uint32_t aChannelMask,
uint8_t aCount,
uint16_t aPeriod,
uint16_t aScanDuration,
const Ip6::Address &aAddress,
otCommissionerEnergyReportCallback aCallback,
void *aContext)
{
Error error = kErrorNone;
Coap::Message *message = nullptr;
VerifyOrExit(IsActive(), error = kErrorInvalidState);
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = message->InitAsPost(aAddress, kUriEnergyScan));
SuccessOrExit(error = message->AppendPayloadMarker());
SuccessOrExit(error = Tlv::Append<CommissionerSessionIdTlv>(*message, GetSessionId()));
SuccessOrExit(error = ChannelMaskTlv::AppendTo(*message, aChannelMask));
SuccessOrExit(error = Tlv::Append<CountTlv>(*message, aCount));
SuccessOrExit(error = Tlv::Append<PeriodTlv>(*message, aPeriod));
SuccessOrExit(error = Tlv::Append<ScanDurationTlv>(*message, aScanDuration));
SuccessOrExit(error = Get<Tmf::Agent>().SendMessageTo(*message, aAddress));
LogInfo("Sent %s", UriToString<kUriEnergyScan>());
mEnergyReportCallback.Set(aCallback, aContext);
exit:
FreeMessageOnError(message, error);
return error;
}
template <> void Commissioner::HandleTmf<kUriEnergyReport>(Coap::Msg &aMsg)
{
uint32_t mask;
EnergyListTlv energyListTlv;
VerifyOrExit(aMsg.IsConfirmablePostRequest());
LogInfo("Received %s", UriToString<kUriEnergyReport>());
SuccessOrExit(ChannelMaskTlv::FindIn(aMsg.mMessage, mask));
SuccessOrExit(Tlv::FindTlv(aMsg.mMessage, Tlv::kEnergyList, sizeof(energyListTlv), energyListTlv));
mEnergyReportCallback.InvokeIfSet(mask, energyListTlv.GetEnergyList(), energyListTlv.GetEnergyListLength());
SuccessOrExit(Get<Tmf::Agent>().SendEmptyAck(aMsg));
LogInfo("Sent %s ack", UriToString<kUriEnergyReport>());
exit:
return;
}
Error Commissioner::SendPanIdQuery(uint16_t aPanId,
uint32_t aChannelMask,
const Ip6::Address &aAddress,
otCommissionerPanIdConflictCallback aCallback,
void *aContext)
{
Error error = kErrorNone;
Coap::Message *message = nullptr;
VerifyOrExit(IsActive(), error = kErrorInvalidState);
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = message->InitAsPost(aAddress, kUriPanIdQuery));
SuccessOrExit(error = message->AppendPayloadMarker());
SuccessOrExit(error = Tlv::Append<CommissionerSessionIdTlv>(*message, GetSessionId()));
SuccessOrExit(error = ChannelMaskTlv::AppendTo(*message, aChannelMask));
SuccessOrExit(error = Tlv::Append<PanIdTlv>(*message, aPanId));
SuccessOrExit(error = Get<Tmf::Agent>().SendMessageTo(*message, aAddress));
LogInfo("Sent %s", UriToString<kUriPanIdQuery>());
mPanIdConflictCallback.Set(aCallback, aContext);
exit:
FreeMessageOnError(message, error);
return error;
}
template <> void Commissioner::HandleTmf<kUriPanIdConflict>(Coap::Msg &aMsg)
{
uint16_t panId;
uint32_t mask;
VerifyOrExit(aMsg.IsConfirmablePostRequest());
LogInfo("Received %s", UriToString<kUriPanIdConflict>());
SuccessOrExit(Tlv::Find<PanIdTlv>(aMsg.mMessage, panId));
SuccessOrExit(ChannelMaskTlv::FindIn(aMsg.mMessage, mask));
mPanIdConflictCallback.InvokeIfSet(panId, mask);
SuccessOrExit(Get<Tmf::Agent>().SendEmptyAck(aMsg));
LogInfo("Sent %s response", UriToString<kUriPanIdConflict>());
exit:
return;
}
// LCOV_EXCL_START
#if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO)
+50 -18
View File
@@ -49,9 +49,6 @@
#include "common/non_copyable.hpp"
#include "common/timer.hpp"
#include "mac/mac_types.hpp"
#include "meshcop/announce_begin_client.hpp"
#include "meshcop/energy_scan_client.hpp"
#include "meshcop/panid_query_client.hpp"
#include "meshcop/secure_transport.hpp"
#include "net/ip6_address.hpp"
#include "net/udp6.hpp"
@@ -316,25 +313,60 @@ public:
Error SendMgmtCommissionerSetRequest(const CommissioningDataset &aDataset, const uint8_t *aTlvs, uint8_t aLength);
/**
* Returns a reference to the AnnounceBeginClient instance.
* Sends a Announce Begin message.
*
* @returns A reference to the AnnounceBeginClient instance.
* @param[in] aChannelMask The channel mask value.
* @param[in] aCount The number of Announce messages sent per channel.
* @param[in] aPeriod The time between two successive MLE Announce transmissions (in milliseconds).
* @param[in] aAddress The destination address.
*
* @retval kErrorNone Successfully enqueued the Announce Begin message.
* @retval kErrorNoBufs Insufficient buffers to generate a Announce Begin message.
*/
AnnounceBeginClient &GetAnnounceBeginClient(void) { return mAnnounceBegin; }
Error SendAnnounceBeginRequest(uint32_t aChannelMask,
uint8_t aCount,
uint16_t aPeriod,
const Ip6::Address &aAddress);
/**
* Returns a reference to the EnergyScanClient instance.
* Sends an Energy Scan Query message.
*
* @returns A reference to the EnergyScanClient instance.
* @param[in] aChannelMask The channel mask value.
* @param[in] aCount The number of energy measurements per channel.
* @param[in] aPeriod The time between energy measurements (milliseconds).
* @param[in] aScanDuration The scan duration for each energy measurement (milliseconds).
* @param[in] aAddress A pointer to the IPv6 destination.
* @param[in] aCallback A pointer to a function called on receiving an Energy Report message.
* @param[in] aContext A pointer to application-specific context.
*
* @retval kErrorNone Successfully enqueued the Energy Scan Query message.
* @retval kErrorNoBufs Insufficient buffers to generate an Energy Scan Query message.
*/
EnergyScanClient &GetEnergyScanClient(void) { return mEnergyScan; }
Error SendEnergyScanQuery(uint32_t aChannelMask,
uint8_t aCount,
uint16_t aPeriod,
uint16_t aScanDuration,
const Ip6::Address &aAddress,
otCommissionerEnergyReportCallback aCallback,
void *aContext);
/**
* Returns a reference to the PanIdQueryClient instance.
* Sends a PAN ID Query message.
*
* @returns A reference to the PanIdQueryClient instance.
* @param[in] aPanId The PAN ID to query.
* @param[in] aChannelMask The channel mask value.
* @param[in] aAddress A pointer to the IPv6 destination.
* @param[in] aCallback A pointer to a function called on receiving an Energy Report message.
* @param[in] aContext A pointer to application-specific context.
*
* @retval kErrorNone Successfully enqueued the PAN ID Query message.
* @retval kErrorNoBufs Insufficient buffers to generate a PAN ID Query message.
*/
PanIdQueryClient &GetPanIdQueryClient(void) { return mPanIdQuery; }
Error SendPanIdQuery(uint16_t aPanId,
uint32_t aChannelMask,
const Ip6::Address &aAddress,
otCommissionerPanIdConflictCallback aCallback,
void *aContext);
private:
static constexpr uint32_t kPetitionAttemptDelay = 5; // COMM_PET_ATTEMPT_DELAY (seconds)
@@ -440,10 +472,6 @@ private:
CommissionerTimer mTimer;
JoinerSessionTimer mJoinerSessionTimer;
AnnounceBeginClient mAnnounceBegin;
EnergyScanClient mEnergyScan;
PanIdQueryClient mPanIdQuery;
Ip6::Netif::UnicastAddress mCommissionerAloc;
ProvisioningUrlTlv::StringType mProvisioningUrl;
@@ -451,13 +479,17 @@ private:
State mState;
Callback<StateCallback> mStateCallback;
Callback<JoinerCallback> mJoinerCallback;
Callback<StateCallback> mStateCallback;
Callback<JoinerCallback> mJoinerCallback;
Callback<otCommissionerEnergyReportCallback> mEnergyReportCallback;
Callback<otCommissionerPanIdConflictCallback> mPanIdConflictCallback;
};
DeclareTmfHandler(Commissioner, kUriDatasetChanged);
DeclareTmfHandler(Commissioner, kUriRelayRx);
DeclareTmfHandler(Commissioner, kUriJoinerFinalize);
DeclareTmfHandler(Commissioner, kUriEnergyReport);
DeclareTmfHandler(Commissioner, kUriPanIdConflict);
} // namespace MeshCoP
-112
View File
@@ -1,112 +0,0 @@
/*
* Copyright (c) 2016, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file implements the Energy Scan Client.
*/
#include "energy_scan_client.hpp"
#if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD
#include "instance/instance.hpp"
namespace ot {
RegisterLogModule("EnergyScanClnt");
EnergyScanClient::EnergyScanClient(Instance &aInstance)
: InstanceLocator(aInstance)
{
}
Error EnergyScanClient::SendQuery(uint32_t aChannelMask,
uint8_t aCount,
uint16_t aPeriod,
uint16_t aScanDuration,
const Ip6::Address &aAddress,
otCommissionerEnergyReportCallback aCallback,
void *aContext)
{
Error error = kErrorNone;
Coap::Message *message = nullptr;
VerifyOrExit(Get<MeshCoP::Commissioner>().IsActive(), error = kErrorInvalidState);
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = message->InitAsPost(aAddress, kUriEnergyScan));
SuccessOrExit(error = message->AppendPayloadMarker());
SuccessOrExit(
error = Tlv::Append<MeshCoP::CommissionerSessionIdTlv>(*message, Get<MeshCoP::Commissioner>().GetSessionId()));
SuccessOrExit(error = MeshCoP::ChannelMaskTlv::AppendTo(*message, aChannelMask));
SuccessOrExit(error = Tlv::Append<MeshCoP::CountTlv>(*message, aCount));
SuccessOrExit(error = Tlv::Append<MeshCoP::PeriodTlv>(*message, aPeriod));
SuccessOrExit(error = Tlv::Append<MeshCoP::ScanDurationTlv>(*message, aScanDuration));
SuccessOrExit(error = Get<Tmf::Agent>().SendMessageTo(*message, aAddress));
LogInfo("Sent %s", UriToString<kUriEnergyScan>());
mCallback.Set(aCallback, aContext);
exit:
FreeMessageOnError(message, error);
return error;
}
template <> void EnergyScanClient::HandleTmf<kUriEnergyReport>(Coap::Msg &aMsg)
{
uint32_t mask;
MeshCoP::EnergyListTlv energyListTlv;
VerifyOrExit(aMsg.IsConfirmablePostRequest());
LogInfo("Received %s", UriToString<kUriEnergyReport>());
SuccessOrExit(MeshCoP::ChannelMaskTlv::FindIn(aMsg.mMessage, mask));
SuccessOrExit(
MeshCoP::Tlv::FindTlv(aMsg.mMessage, MeshCoP::Tlv::kEnergyList, sizeof(energyListTlv), energyListTlv));
mCallback.InvokeIfSet(mask, energyListTlv.GetEnergyList(), energyListTlv.GetEnergyListLength());
SuccessOrExit(Get<Tmf::Agent>().SendEmptyAck(aMsg));
LogInfo("Sent %s ack", UriToString<kUriEnergyReport>());
exit:
return;
}
} // namespace ot
#endif // OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD
-103
View File
@@ -1,103 +0,0 @@
/*
* Copyright (c) 2016, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file includes definitions for responding to PANID Query Requests.
*/
#ifndef OT_CORE_MESHCOP_ENERGY_SCAN_CLIENT_HPP_
#define OT_CORE_MESHCOP_ENERGY_SCAN_CLIENT_HPP_
#include "openthread-core-config.h"
#if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD
#include <openthread/commissioner.h>
#include "coap/coap.hpp"
#include "common/callback.hpp"
#include "common/locator.hpp"
#include "net/ip6_address.hpp"
#include "net/udp6.hpp"
#include "thread/tmf.hpp"
namespace ot {
/**
* Implements handling PANID Query Requests.
*/
class EnergyScanClient : public InstanceLocator
{
friend class Tmf::Agent;
public:
/**
* Initializes the object.
*/
explicit EnergyScanClient(Instance &aInstance);
/**
* Sends an Energy Scan Query message.
*
* @param[in] aChannelMask The channel mask value.
* @param[in] aCount The number of energy measurements per channel.
* @param[in] aPeriod The time between energy measurements (milliseconds).
* @param[in] aScanDuration The scan duration for each energy measurement (milliseconds).
* @param[in] aAddress A pointer to the IPv6 destination.
* @param[in] aCallback A pointer to a function called on receiving an Energy Report message.
* @param[in] aContext A pointer to application-specific context.
*
* @retval kErrorNone Successfully enqueued the Energy Scan Query message.
* @retval kErrorNoBufs Insufficient buffers to generate an Energy Scan Query message.
*/
Error SendQuery(uint32_t aChannelMask,
uint8_t aCount,
uint16_t aPeriod,
uint16_t aScanDuration,
const Ip6::Address &aAddress,
otCommissionerEnergyReportCallback aCallback,
void *aContext);
private:
template <Uri kUri> void HandleTmf(Coap::Msg &aMsg);
Callback<otCommissionerEnergyReportCallback> mCallback;
};
DeclareTmfHandler(EnergyScanClient, kUriEnergyReport);
/**
* @}
*/
} // namespace ot
#endif // OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD
#endif // OT_CORE_MESHCOP_ENERGY_SCAN_CLIENT_HPP_
-107
View File
@@ -1,107 +0,0 @@
/*
* Copyright (c) 2016, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file implements the PAN ID Query Client.
*/
#include "panid_query_client.hpp"
#if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD
#include "instance/instance.hpp"
namespace ot {
RegisterLogModule("PanIdQueryClnt");
PanIdQueryClient::PanIdQueryClient(Instance &aInstance)
: InstanceLocator(aInstance)
{
}
Error PanIdQueryClient::SendQuery(uint16_t aPanId,
uint32_t aChannelMask,
const Ip6::Address &aAddress,
otCommissionerPanIdConflictCallback aCallback,
void *aContext)
{
Error error = kErrorNone;
Coap::Message *message = nullptr;
VerifyOrExit(Get<MeshCoP::Commissioner>().IsActive(), error = kErrorInvalidState);
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = message->InitAsPost(aAddress, kUriPanIdQuery));
SuccessOrExit(error = message->AppendPayloadMarker());
SuccessOrExit(
error = Tlv::Append<MeshCoP::CommissionerSessionIdTlv>(*message, Get<MeshCoP::Commissioner>().GetSessionId()));
SuccessOrExit(error = MeshCoP::ChannelMaskTlv::AppendTo(*message, aChannelMask));
SuccessOrExit(error = Tlv::Append<MeshCoP::PanIdTlv>(*message, aPanId));
SuccessOrExit(error = Get<Tmf::Agent>().SendMessageTo(*message, aAddress));
LogInfo("Sent %s", UriToString<kUriPanIdQuery>());
mCallback.Set(aCallback, aContext);
exit:
FreeMessageOnError(message, error);
return error;
}
template <> void PanIdQueryClient::HandleTmf<kUriPanIdConflict>(Coap::Msg &aMsg)
{
uint16_t panId;
uint32_t mask;
VerifyOrExit(aMsg.IsConfirmablePostRequest());
LogInfo("Received %s", UriToString<kUriPanIdConflict>());
SuccessOrExit(Tlv::Find<MeshCoP::PanIdTlv>(aMsg.mMessage, panId));
SuccessOrExit(MeshCoP::ChannelMaskTlv::FindIn(aMsg.mMessage, mask));
mCallback.InvokeIfSet(panId, mask);
SuccessOrExit(Get<Tmf::Agent>().SendEmptyAck(aMsg));
LogInfo("Sent %s response", UriToString<kUriPanIdConflict>());
exit:
return;
}
} // namespace ot
#endif // OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD
-98
View File
@@ -1,98 +0,0 @@
/*
* Copyright (c) 2016, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file includes definitions for responding to PANID Query Requests.
*/
#ifndef OT_CORE_MESHCOP_PANID_QUERY_CLIENT_HPP_
#define OT_CORE_MESHCOP_PANID_QUERY_CLIENT_HPP_
#include "openthread-core-config.h"
#if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD
#include <openthread/commissioner.h>
#include "common/callback.hpp"
#include "common/locator.hpp"
#include "net/ip6_address.hpp"
#include "net/udp6.hpp"
#include "thread/tmf.hpp"
namespace ot {
/**
* Implements handling PANID Query Requests.
*/
class PanIdQueryClient : public InstanceLocator
{
friend class Tmf::Agent;
public:
/**
* Initializes the object.
*/
explicit PanIdQueryClient(Instance &aInstance);
/**
* Sends a PAN ID Query message.
*
* @param[in] aPanId The PAN ID to query.
* @param[in] aChannelMask The channel mask value.
* @param[in] aAddress A pointer to the IPv6 destination.
* @param[in] aCallback A pointer to a function called on receiving an Energy Report message.
* @param[in] aContext A pointer to application-specific context.
*
* @retval kErrorNone Successfully enqueued the PAN ID Query message.
* @retval kErrorNoBufs Insufficient buffers to generate a PAN ID Query message.
*/
Error SendQuery(uint16_t aPanId,
uint32_t aChannelMask,
const Ip6::Address &aAddress,
otCommissionerPanIdConflictCallback aCallback,
void *aContext);
private:
template <Uri kUri> void HandleTmf(Coap::Msg &aMsg);
Callback<otCommissionerPanIdConflictCallback> mCallback;
};
DeclareTmfHandler(PanIdQueryClient, kUriPanIdConflict);
/**
* @}
*/
} // namespace ot
#endif // OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD
#endif // OT_CORE_MESHCOP_PANID_QUERY_CLIENT_HPP_
+2 -2
View File
@@ -107,8 +107,8 @@ bool Agent::HandleResource(const char *aUriPath, Msg &aMsg)
#endif
#if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD
Case(kUriPanIdConflict, PanIdQueryClient);
Case(kUriEnergyReport, EnergyScanClient);
Case(kUriPanIdConflict, MeshCoP::Commissioner);
Case(kUriEnergyReport, MeshCoP::Commissioner);
Case(kUriDatasetChanged, MeshCoP::Commissioner);
// kUriRelayRx is handled below
#endif
+2 -2
View File
@@ -191,7 +191,7 @@ void Test9_2_14(void)
{
uint32_t channelMask = (1 << kSecondaryChannel);
SuccessOrQuit(commissioner.Get<MeshCoP::Commissioner>().GetPanIdQueryClient().SendQuery(
SuccessOrQuit(commissioner.Get<MeshCoP::Commissioner>().SendPanIdQuery(
kPanId, channelMask, router1.Get<Mle::Mle>().GetMeshLocalRloc(), nullptr, nullptr));
}
@@ -228,7 +228,7 @@ void Test9_2_14(void)
{
uint32_t channelMask = (1 << kSecondaryChannel);
SuccessOrQuit(commissioner.Get<MeshCoP::Commissioner>().GetPanIdQueryClient().SendQuery(
SuccessOrQuit(commissioner.Get<MeshCoP::Commissioner>().SendPanIdQuery(
kPanId, channelMask, commissioner.Get<Mle::Mle>().GetRealmLocalAllThreadNodesAddress(), nullptr, nullptr));
}