diff --git a/src/core/BUILD.gn b/src/core/BUILD.gn index 7aeb396d1..0c9386147 100644 --- a/src/core/BUILD.gn +++ b/src/core/BUILD.gn @@ -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", diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index d7d7cb4cd..60503c96f 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -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 diff --git a/src/core/api/commissioner_api.cpp b/src/core/api/commissioner_api.cpp index 8d76ead52..fdd97d86b 100644 --- a/src/core/api/commissioner_api.cpp +++ b/src/core/api/commissioner_api.cpp @@ -127,8 +127,8 @@ otError otCommissionerAnnounceBegin(otInstance *aInstance, uint16_t aPeriod, const otIp6Address *aAddress) { - return AsCoreType(aInstance).Get().GetAnnounceBeginClient().SendRequest( - aChannelMask, aCount, aPeriod, AsCoreType(aAddress)); + return AsCoreType(aInstance).Get().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().GetEnergyScanClient().SendQuery( + return AsCoreType(aInstance).Get().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().GetPanIdQueryClient().SendQuery( - aPanId, aChannelMask, AsCoreType(aAddress), aCallback, aContext); + return AsCoreType(aInstance).Get().SendPanIdQuery(aPanId, aChannelMask, AsCoreType(aAddress), + aCallback, aContext); } otError otCommissionerSendMgmtGet(otInstance *aInstance, const uint8_t *aTlvs, uint8_t aLength) diff --git a/src/core/instance/instance.hpp b/src/core/instance/instance.hpp index 00d35354e..fc5a42aec 100644 --- a/src/core/instance/instance.hpp +++ b/src/core/instance/instance.hpp @@ -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 diff --git a/src/core/meshcop/announce_begin_client.cpp b/src/core/meshcop/announce_begin_client.cpp deleted file mode 100644 index f9a9176cf..000000000 --- a/src/core/meshcop/announce_begin_client.cpp +++ /dev/null @@ -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().IsActive(), error = kErrorInvalidState); - VerifyOrExit((message = Get().NewPriorityMessage()) != nullptr, error = kErrorNoBufs); - - SuccessOrExit(error = message->InitAsPost(aAddress, kUriAnnounceBegin)); - SuccessOrExit(error = message->AppendPayloadMarker()); - - SuccessOrExit( - error = Tlv::Append(*message, Get().GetSessionId())); - - SuccessOrExit(error = MeshCoP::ChannelMaskTlv::AppendTo(*message, aChannelMask)); - - SuccessOrExit(error = Tlv::Append(*message, aCount)); - SuccessOrExit(error = Tlv::Append(*message, aPeriod)); - - SuccessOrExit(error = Get().SendMessageTo(*message, aAddress)); - - LogInfo("Sent %s", UriToString()); - -exit: - FreeMessageOnError(message, error); - return error; -} - -} // namespace ot - -#endif // OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD diff --git a/src/core/meshcop/announce_begin_client.hpp b/src/core/meshcop/announce_begin_client.hpp deleted file mode 100644 index 06a4638b2..000000000 --- a/src/core/meshcop/announce_begin_client.hpp +++ /dev/null @@ -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_ diff --git a/src/core/meshcop/commissioner.cpp b/src/core/meshcop/commissioner.cpp index 7b3bf1ff4..2b30d5be7 100644 --- a/src/core/meshcop/commissioner.cpp +++ b/src/core/meshcop/commissioner.cpp @@ -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().NewPriorityMessage()) != nullptr, error = kErrorNoBufs); + + SuccessOrExit(error = message->InitAsPost(aAddress, kUriAnnounceBegin)); + SuccessOrExit(error = message->AppendPayloadMarker()); + + SuccessOrExit(error = Tlv::Append(*message, GetSessionId())); + + SuccessOrExit(error = ChannelMaskTlv::AppendTo(*message, aChannelMask)); + + SuccessOrExit(error = Tlv::Append(*message, aCount)); + SuccessOrExit(error = Tlv::Append(*message, aPeriod)); + + SuccessOrExit(error = Get().SendMessageTo(*message, aAddress)); + + LogInfo("Sent %s", UriToString()); + +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().NewPriorityMessage()) != nullptr, error = kErrorNoBufs); + + SuccessOrExit(error = message->InitAsPost(aAddress, kUriEnergyScan)); + SuccessOrExit(error = message->AppendPayloadMarker()); + + SuccessOrExit(error = Tlv::Append(*message, GetSessionId())); + + SuccessOrExit(error = ChannelMaskTlv::AppendTo(*message, aChannelMask)); + + SuccessOrExit(error = Tlv::Append(*message, aCount)); + SuccessOrExit(error = Tlv::Append(*message, aPeriod)); + SuccessOrExit(error = Tlv::Append(*message, aScanDuration)); + + SuccessOrExit(error = Get().SendMessageTo(*message, aAddress)); + + LogInfo("Sent %s", UriToString()); + + mEnergyReportCallback.Set(aCallback, aContext); + +exit: + FreeMessageOnError(message, error); + return error; +} + +template <> void Commissioner::HandleTmf(Coap::Msg &aMsg) +{ + uint32_t mask; + EnergyListTlv energyListTlv; + + VerifyOrExit(aMsg.IsConfirmablePostRequest()); + + LogInfo("Received %s", UriToString()); + + 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().SendEmptyAck(aMsg)); + + LogInfo("Sent %s ack", UriToString()); + +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().NewPriorityMessage()) != nullptr, error = kErrorNoBufs); + + SuccessOrExit(error = message->InitAsPost(aAddress, kUriPanIdQuery)); + SuccessOrExit(error = message->AppendPayloadMarker()); + + SuccessOrExit(error = Tlv::Append(*message, GetSessionId())); + + SuccessOrExit(error = ChannelMaskTlv::AppendTo(*message, aChannelMask)); + + SuccessOrExit(error = Tlv::Append(*message, aPanId)); + + SuccessOrExit(error = Get().SendMessageTo(*message, aAddress)); + + LogInfo("Sent %s", UriToString()); + + mPanIdConflictCallback.Set(aCallback, aContext); + +exit: + FreeMessageOnError(message, error); + return error; +} + +template <> void Commissioner::HandleTmf(Coap::Msg &aMsg) +{ + uint16_t panId; + uint32_t mask; + + VerifyOrExit(aMsg.IsConfirmablePostRequest()); + + LogInfo("Received %s", UriToString()); + + SuccessOrExit(Tlv::Find(aMsg.mMessage, panId)); + + SuccessOrExit(ChannelMaskTlv::FindIn(aMsg.mMessage, mask)); + + mPanIdConflictCallback.InvokeIfSet(panId, mask); + + SuccessOrExit(Get().SendEmptyAck(aMsg)); + + LogInfo("Sent %s response", UriToString()); + +exit: + return; +} + // LCOV_EXCL_START #if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO) diff --git a/src/core/meshcop/commissioner.hpp b/src/core/meshcop/commissioner.hpp index a2c050a4e..bb7d41c6c 100644 --- a/src/core/meshcop/commissioner.hpp +++ b/src/core/meshcop/commissioner.hpp @@ -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 mStateCallback; - Callback mJoinerCallback; + Callback mStateCallback; + Callback mJoinerCallback; + Callback mEnergyReportCallback; + Callback mPanIdConflictCallback; }; DeclareTmfHandler(Commissioner, kUriDatasetChanged); DeclareTmfHandler(Commissioner, kUriRelayRx); DeclareTmfHandler(Commissioner, kUriJoinerFinalize); +DeclareTmfHandler(Commissioner, kUriEnergyReport); +DeclareTmfHandler(Commissioner, kUriPanIdConflict); } // namespace MeshCoP diff --git a/src/core/meshcop/energy_scan_client.cpp b/src/core/meshcop/energy_scan_client.cpp deleted file mode 100644 index 4d1c8d1a2..000000000 --- a/src/core/meshcop/energy_scan_client.cpp +++ /dev/null @@ -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().IsActive(), error = kErrorInvalidState); - VerifyOrExit((message = Get().NewPriorityMessage()) != nullptr, error = kErrorNoBufs); - - SuccessOrExit(error = message->InitAsPost(aAddress, kUriEnergyScan)); - SuccessOrExit(error = message->AppendPayloadMarker()); - - SuccessOrExit( - error = Tlv::Append(*message, Get().GetSessionId())); - - SuccessOrExit(error = MeshCoP::ChannelMaskTlv::AppendTo(*message, aChannelMask)); - - SuccessOrExit(error = Tlv::Append(*message, aCount)); - SuccessOrExit(error = Tlv::Append(*message, aPeriod)); - SuccessOrExit(error = Tlv::Append(*message, aScanDuration)); - - SuccessOrExit(error = Get().SendMessageTo(*message, aAddress)); - - LogInfo("Sent %s", UriToString()); - - mCallback.Set(aCallback, aContext); - -exit: - FreeMessageOnError(message, error); - return error; -} - -template <> void EnergyScanClient::HandleTmf(Coap::Msg &aMsg) -{ - uint32_t mask; - MeshCoP::EnergyListTlv energyListTlv; - - VerifyOrExit(aMsg.IsConfirmablePostRequest()); - - LogInfo("Received %s", UriToString()); - - 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().SendEmptyAck(aMsg)); - - LogInfo("Sent %s ack", UriToString()); - -exit: - return; -} - -} // namespace ot - -#endif // OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD diff --git a/src/core/meshcop/energy_scan_client.hpp b/src/core/meshcop/energy_scan_client.hpp deleted file mode 100644 index 473eb4e35..000000000 --- a/src/core/meshcop/energy_scan_client.hpp +++ /dev/null @@ -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 - -#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 void HandleTmf(Coap::Msg &aMsg); - - Callback mCallback; -}; - -DeclareTmfHandler(EnergyScanClient, kUriEnergyReport); - -/** - * @} - */ - -} // namespace ot - -#endif // OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD - -#endif // OT_CORE_MESHCOP_ENERGY_SCAN_CLIENT_HPP_ diff --git a/src/core/meshcop/panid_query_client.cpp b/src/core/meshcop/panid_query_client.cpp deleted file mode 100644 index de5c068fa..000000000 --- a/src/core/meshcop/panid_query_client.cpp +++ /dev/null @@ -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().IsActive(), error = kErrorInvalidState); - VerifyOrExit((message = Get().NewPriorityMessage()) != nullptr, error = kErrorNoBufs); - - SuccessOrExit(error = message->InitAsPost(aAddress, kUriPanIdQuery)); - SuccessOrExit(error = message->AppendPayloadMarker()); - - SuccessOrExit( - error = Tlv::Append(*message, Get().GetSessionId())); - - SuccessOrExit(error = MeshCoP::ChannelMaskTlv::AppendTo(*message, aChannelMask)); - - SuccessOrExit(error = Tlv::Append(*message, aPanId)); - - SuccessOrExit(error = Get().SendMessageTo(*message, aAddress)); - - LogInfo("Sent %s", UriToString()); - - mCallback.Set(aCallback, aContext); - -exit: - FreeMessageOnError(message, error); - return error; -} - -template <> void PanIdQueryClient::HandleTmf(Coap::Msg &aMsg) -{ - uint16_t panId; - uint32_t mask; - - VerifyOrExit(aMsg.IsConfirmablePostRequest()); - - LogInfo("Received %s", UriToString()); - - SuccessOrExit(Tlv::Find(aMsg.mMessage, panId)); - - SuccessOrExit(MeshCoP::ChannelMaskTlv::FindIn(aMsg.mMessage, mask)); - - mCallback.InvokeIfSet(panId, mask); - - SuccessOrExit(Get().SendEmptyAck(aMsg)); - - LogInfo("Sent %s response", UriToString()); - -exit: - return; -} - -} // namespace ot - -#endif // OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD diff --git a/src/core/meshcop/panid_query_client.hpp b/src/core/meshcop/panid_query_client.hpp deleted file mode 100644 index 303779e8c..000000000 --- a/src/core/meshcop/panid_query_client.hpp +++ /dev/null @@ -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 - -#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 void HandleTmf(Coap::Msg &aMsg); - - Callback mCallback; -}; - -DeclareTmfHandler(PanIdQueryClient, kUriPanIdConflict); - -/** - * @} - */ - -} // namespace ot - -#endif // OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD - -#endif // OT_CORE_MESHCOP_PANID_QUERY_CLIENT_HPP_ diff --git a/src/core/thread/tmf.cpp b/src/core/thread/tmf.cpp index b88a2e737..2e1dd2e49 100644 --- a/src/core/thread/tmf.cpp +++ b/src/core/thread/tmf.cpp @@ -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 diff --git a/tests/nexus/test_1_1_9_2_14.cpp b/tests/nexus/test_1_1_9_2_14.cpp index a518b1e25..852bcea57 100644 --- a/tests/nexus/test_1_1_9_2_14.cpp +++ b/tests/nexus/test_1_1_9_2_14.cpp @@ -191,7 +191,7 @@ void Test9_2_14(void) { uint32_t channelMask = (1 << kSecondaryChannel); - SuccessOrQuit(commissioner.Get().GetPanIdQueryClient().SendQuery( + SuccessOrQuit(commissioner.Get().SendPanIdQuery( kPanId, channelMask, router1.Get().GetMeshLocalRloc(), nullptr, nullptr)); } @@ -228,7 +228,7 @@ void Test9_2_14(void) { uint32_t channelMask = (1 << kSecondaryChannel); - SuccessOrQuit(commissioner.Get().GetPanIdQueryClient().SendQuery( + SuccessOrQuit(commissioner.Get().SendPanIdQuery( kPanId, channelMask, commissioner.Get().GetRealmLocalAllThreadNodesAddress(), nullptr, nullptr)); }