diff --git a/etc/visual-studio/libopenthread.vcxproj b/etc/visual-studio/libopenthread.vcxproj
index bfd77af42..063256f4d 100644
--- a/etc/visual-studio/libopenthread.vcxproj
+++ b/etc/visual-studio/libopenthread.vcxproj
@@ -62,6 +62,7 @@
+
@@ -73,6 +74,7 @@
+
@@ -230,4 +232,4 @@
-
\ No newline at end of file
+
diff --git a/etc/visual-studio/libopenthread.vcxproj.filters b/etc/visual-studio/libopenthread.vcxproj.filters
index 8c708a406..35e75bada 100644
--- a/etc/visual-studio/libopenthread.vcxproj.filters
+++ b/etc/visual-studio/libopenthread.vcxproj.filters
@@ -75,6 +75,9 @@
Source Files\api
+
+ Source Files\api
+
Source Files\api
@@ -108,6 +111,9 @@
Source Files\api
+
+ Source Files\api
+
Source Files\coap
@@ -564,4 +570,4 @@
Header Files\missing
-
\ No newline at end of file
+
diff --git a/etc/visual-studio/libopenthread_k.vcxproj b/etc/visual-studio/libopenthread_k.vcxproj
index 8dfe37bf7..18dfe9c9c 100644
--- a/etc/visual-studio/libopenthread_k.vcxproj
+++ b/etc/visual-studio/libopenthread_k.vcxproj
@@ -69,6 +69,7 @@
+
@@ -79,6 +80,7 @@
+
@@ -152,6 +154,7 @@
+
@@ -165,6 +168,7 @@
+
@@ -258,4 +262,4 @@
-
\ No newline at end of file
+
diff --git a/etc/visual-studio/libopenthread_k.vcxproj.filters b/etc/visual-studio/libopenthread_k.vcxproj.filters
index 61a06ad17..ed0be3508 100644
--- a/etc/visual-studio/libopenthread_k.vcxproj.filters
+++ b/etc/visual-studio/libopenthread_k.vcxproj.filters
@@ -78,6 +78,9 @@
Source Files\api
+
+ Source Files\api
+
Source Files\api
@@ -108,6 +111,9 @@
Source Files\api
+
+ Source Files\api
+
Source Files\coap
@@ -581,6 +587,9 @@
Header Files\openthread
+
+ Header Files\openthread
+
Header Files\openthread
@@ -620,6 +629,9 @@
Header Files\openthread
+
+ Header Files\openthread
+
Header Files\openthread
@@ -633,4 +645,4 @@
Header Files\missing
-
\ No newline at end of file
+
diff --git a/examples/drivers/windows/otApi/precomp.h b/examples/drivers/windows/otApi/precomp.h
index 25627c556..cf29dceab 100644
--- a/examples/drivers/windows/otApi/precomp.h
+++ b/examples/drivers/windows/otApi/precomp.h
@@ -22,6 +22,8 @@
#define OTAPI EXTERN_C __declspec(dllexport)
#include
+#include
+#include
#include
#include
#include
diff --git a/examples/drivers/windows/otLwf/precomp.h b/examples/drivers/windows/otLwf/precomp.h
index 5a90d66ab..5fd2e9b6f 100644
--- a/examples/drivers/windows/otLwf/precomp.h
+++ b/examples/drivers/windows/otLwf/precomp.h
@@ -62,6 +62,8 @@ RtlCopyBufferToMdl(
#include
#include
#include
+#include
+#include
#include
#include
#include
diff --git a/examples/drivers/windows/otNodeApi/precomp.h b/examples/drivers/windows/otNodeApi/precomp.h
index 3acf1b247..5ab5e10f2 100644
--- a/examples/drivers/windows/otNodeApi/precomp.h
+++ b/examples/drivers/windows/otNodeApi/precomp.h
@@ -50,6 +50,8 @@ using namespace std;
#define OTNODEAPI EXTERN_C __declspec(dllexport)
#include
+#include
+#include
#include
#include
#include
diff --git a/include/openthread/Makefile.am b/include/openthread/Makefile.am
index f87d2e5cf..c4f023b67 100644
--- a/include/openthread/Makefile.am
+++ b/include/openthread/Makefile.am
@@ -52,6 +52,7 @@ openthread_headers = \
commissioner.h \
crypto.h \
dataset.h \
+ dataset_ftd.h \
diag.h \
dhcp6_client.h \
dhcp6_server.h \
@@ -69,6 +70,7 @@ openthread_headers = \
openthread.h \
tasklet.h \
thread.h \
+ thread_ftd.h \
types.h \
udp.h \
$(NULL)
diff --git a/include/openthread/dataset.h b/include/openthread/dataset.h
index 0b47b01db..f2b42005b 100644
--- a/include/openthread/dataset.h
+++ b/include/openthread/dataset.h
@@ -29,7 +29,7 @@
/**
* @file
* @brief
- * This file defines the OpenThread Operational Dataset API.
+ * This file defines the OpenThread Operational Dataset API (for both FTD and MTD).
*/
#ifndef OPENTHREAD_DATASET_H_
@@ -73,19 +73,6 @@ OTAPI bool OTCALL otDatasetIsCommissioned(otInstance *aInstance);
*/
OTAPI ThreadError OTCALL otDatasetGetActive(otInstance *aInstance, otOperationalDataset *aDataset);
-/**
- * This function sets the Active Operational Dataset.
- *
- * @param[in] aInstance A pointer to an OpenThread instance.
- * @param[in] aDataset A pointer to the Active Operational Dataset.
- *
- * @retval kThreadError_None Successfully set the Active Operational Dataset.
- * @retval kThreadError_NoBufs Insufficient buffer space to set the Active Operational Datset.
- * @retval kThreadError_InvalidArgs @p aDataset was NULL.
- *
- */
-OTAPI ThreadError OTCALL otDatasetSetActive(otInstance *aInstance, const otOperationalDataset *aDataset);
-
/**
* This function gets the Pending Operational Dataset.
*
@@ -98,101 +85,6 @@ OTAPI ThreadError OTCALL otDatasetSetActive(otInstance *aInstance, const otOpera
*/
OTAPI ThreadError OTCALL otDatasetGetPending(otInstance *aInstance, otOperationalDataset *aDataset);
-/**
- * This function sets the Pending Operational Dataset.
- *
- * @param[in] aInstance A pointer to an OpenThread instance.
- * @param[in] aDataset A pointer to the Pending Operational Dataset.
- *
- * @retval kThreadError_None Successfully set the Pending Operational Dataset.
- * @retval kThreadError_NoBufs Insufficient buffer space to set the Pending Operational Dataset.
- * @retval kThreadError_InvalidArgs @p aDataset was NULL.
- *
- */
-OTAPI ThreadError OTCALL otDatasetSetPending(otInstance *aInstance, const otOperationalDataset *aDataset);
-
-/**
- * This function sends MGMT_ACTIVE_GET.
- *
- * @param[in] aInstance A pointer to an OpenThread instance.
- * @param[in] aTlvTypes A pointer to the TLV Types.
- * @param[in] aLength The length of TLV Types.
- * @param[in] aAddress A pointer to the IPv6 destination, if it is NULL, will use Leader ALOC as default.
- *
- * @retval kThreadError_None Successfully send the meshcop dataset command.
- * @retval kThreadError_NoBufs Insufficient buffer space to send.
- *
- */
-OTAPI ThreadError OTCALL otDatasetSendMgmtActiveGet(otInstance *aInstance, const uint8_t *aTlvTypes, uint8_t aLength,
- const otIp6Address *aAddress);
-
-/**
- * This function sends MGMT_ACTIVE_SET.
- *
- * @param[in] aInstance A pointer to an OpenThread instance.
- * @param[in] aDataset A pointer to operational dataset.
- * @param[in] aTlvs A pointer to TLVs.
- * @param[in] aLength The length of TLVs.
- *
- * @retval kThreadError_None Successfully send the meshcop dataset command.
- * @retval kThreadError_NoBufs Insufficient buffer space to send.
- *
- */
-OTAPI ThreadError OTCALL otDatasetSendMgmtActiveSet(otInstance *aInstance, const otOperationalDataset *aDataset,
- const uint8_t *aTlvs, uint8_t aLength);
-
-/**
- * This function sends MGMT_PENDING_GET.
- *
- * @param[in] aInstance A pointer to an OpenThread instance.
- * @param[in] aTlvTypes A pointer to the TLV Types.
- * @param[in] aLength The length of TLV Types.
- * @param[in] aAddress A pointer to the IPv6 destination, if it is NULL, will use Leader ALOC as default.
- *
- * @retval kThreadError_None Successfully send the meshcop dataset command.
- * @retval kThreadError_NoBufs Insufficient buffer space to send.
- *
- */
-OTAPI ThreadError OTCALL otDatasetSendMgmtPendingGet(otInstance *aInstance, const uint8_t *aTlvTypes, uint8_t aLength,
- const otIp6Address *aAddress);
-
-/**
- * This function sends MGMT_PENDING_SET.
- *
- * @param[in] aInstance A pointer to an OpenThread instance.
- * @param[in] aDataset A pointer to operational dataset.
- * @param[in] aTlvs A pointer to TLVs.
- * @param[in] aLength The length of TLVs.
- *
- * @retval kThreadError_None Successfully send the meshcop dataset command.
- * @retval kThreadError_NoBufs Insufficient buffer space to send.
- *
- */
-OTAPI ThreadError OTCALL otDatasetSendMgmtPendingSet(otInstance *aInstance, const otOperationalDataset *aDataset,
- const uint8_t *aTlvs, uint8_t aLength);
-
-/**
- * Get minimal delay timer.
- *
- * @param[in] aInstance A pointer to an OpenThread instance.
- *
- * @retval the value of minimal delay timer (in ms).
- *
- */
-OTAPI uint32_t OTCALL otDatasetGetDelayTimerMinimal(otInstance *aInstance);
-
-/**
- * Set minimal delay timer.
- *
- * @param[in] aInstance A pointer to an OpenThread instance.
- * @param[in] aDelayTimerMinimal The value of minimal delay timer (in ms).
- *
- * @retval kThreadError_None Successfully set minimal delay timer.
- * @retval kThreadError_InvalidArgs If @p aDelayTimerMinimal is not valid.
- *
- */
-OTAPI ThreadError OTCALL otDatasetSetDelayTimerMinimal(otInstance *aInstance, uint32_t aDelayTimerMinimal);
-
/**
* @}
*
diff --git a/include/openthread/dataset_ftd.h b/include/openthread/dataset_ftd.h
new file mode 100644
index 000000000..15e4391de
--- /dev/null
+++ b/include/openthread/dataset_ftd.h
@@ -0,0 +1,171 @@
+/*
+ * Copyright (c) 2016-2017, 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
+ * @brief
+ * This file defines the OpenThread Operational Dataset API (FTD only).
+ */
+
+#ifndef OPENTHREAD_DATASET_FTD_H_
+#define OPENTHREAD_DATASET_FTD_H_
+
+#include "openthread/types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup dataset Operational Dataset
+ *
+ * @brief
+ * This module includes functions for Operational Dataset configuration for FTD.
+ *
+ * @{
+ *
+ */
+
+/**
+ * This function sets the Active Operational Dataset.
+ *
+ * @param[in] aInstance A pointer to an OpenThread instance.
+ * @param[in] aDataset A pointer to the Active Operational Dataset.
+ *
+ * @retval kThreadError_None Successfully set the Active Operational Dataset.
+ * @retval kThreadError_NoBufs Insufficient buffer space to set the Active Operational Datset.
+ * @retval kThreadError_InvalidArgs @p aDataset was NULL.
+ *
+ */
+OTAPI ThreadError OTCALL otDatasetSetActive(otInstance *aInstance, const otOperationalDataset *aDataset);
+
+/**
+ * This function sets the Pending Operational Dataset.
+ *
+ * @param[in] aInstance A pointer to an OpenThread instance.
+ * @param[in] aDataset A pointer to the Pending Operational Dataset.
+ *
+ * @retval kThreadError_None Successfully set the Pending Operational Dataset.
+ * @retval kThreadError_NoBufs Insufficient buffer space to set the Pending Operational Dataset.
+ * @retval kThreadError_InvalidArgs @p aDataset was NULL.
+ *
+ */
+OTAPI ThreadError OTCALL otDatasetSetPending(otInstance *aInstance, const otOperationalDataset *aDataset);
+
+/**
+ * This function sends MGMT_ACTIVE_GET.
+ *
+ * @param[in] aInstance A pointer to an OpenThread instance.
+ * @param[in] aTlvTypes A pointer to the TLV Types.
+ * @param[in] aLength The length of TLV Types.
+ * @param[in] aAddress A pointer to the IPv6 destination, if it is NULL, will use Leader ALOC as default.
+ *
+ * @retval kThreadError_None Successfully send the meshcop dataset command.
+ * @retval kThreadError_NoBufs Insufficient buffer space to send.
+ *
+ */
+OTAPI ThreadError OTCALL otDatasetSendMgmtActiveGet(otInstance *aInstance, const uint8_t *aTlvTypes, uint8_t aLength,
+ const otIp6Address *aAddress);
+
+/**
+ * This function sends MGMT_ACTIVE_SET.
+ *
+ * @param[in] aInstance A pointer to an OpenThread instance.
+ * @param[in] aDataset A pointer to operational dataset.
+ * @param[in] aTlvs A pointer to TLVs.
+ * @param[in] aLength The length of TLVs.
+ *
+ * @retval kThreadError_None Successfully send the meshcop dataset command.
+ * @retval kThreadError_NoBufs Insufficient buffer space to send.
+ *
+ */
+OTAPI ThreadError OTCALL otDatasetSendMgmtActiveSet(otInstance *aInstance, const otOperationalDataset *aDataset,
+ const uint8_t *aTlvs, uint8_t aLength);
+
+/**
+ * This function sends MGMT_PENDING_GET.
+ *
+ * @param[in] aInstance A pointer to an OpenThread instance.
+ * @param[in] aTlvTypes A pointer to the TLV Types.
+ * @param[in] aLength The length of TLV Types.
+ * @param[in] aAddress A pointer to the IPv6 destination, if it is NULL, will use Leader ALOC as default.
+ *
+ * @retval kThreadError_None Successfully send the meshcop dataset command.
+ * @retval kThreadError_NoBufs Insufficient buffer space to send.
+ *
+ */
+OTAPI ThreadError OTCALL otDatasetSendMgmtPendingGet(otInstance *aInstance, const uint8_t *aTlvTypes, uint8_t aLength,
+ const otIp6Address *aAddress);
+
+/**
+ * This function sends MGMT_PENDING_SET.
+ *
+ * @param[in] aInstance A pointer to an OpenThread instance.
+ * @param[in] aDataset A pointer to operational dataset.
+ * @param[in] aTlvs A pointer to TLVs.
+ * @param[in] aLength The length of TLVs.
+ *
+ * @retval kThreadError_None Successfully send the meshcop dataset command.
+ * @retval kThreadError_NoBufs Insufficient buffer space to send.
+ *
+ */
+OTAPI ThreadError OTCALL otDatasetSendMgmtPendingSet(otInstance *aInstance, const otOperationalDataset *aDataset,
+ const uint8_t *aTlvs, uint8_t aLength);
+
+/**
+ * Get minimal delay timer.
+ *
+ * @param[in] aInstance A pointer to an OpenThread instance.
+ *
+ * @retval the value of minimal delay timer (in ms).
+ *
+ */
+OTAPI uint32_t OTCALL otDatasetGetDelayTimerMinimal(otInstance *aInstance);
+
+/**
+ * Set minimal delay timer.
+ *
+ * @param[in] aInstance A pointer to an OpenThread instance.
+ * @param[in] aDelayTimerMinimal The value of minimal delay timer (in ms).
+ *
+ * @retval kThreadError_None Successfully set minimal delay timer.
+ * @retval kThreadError_InvalidArgs If @p aDelayTimerMinimal is not valid.
+ *
+ */
+OTAPI ThreadError OTCALL otDatasetSetDelayTimerMinimal(otInstance *aInstance, uint32_t aDelayTimerMinimal);
+
+/**
+ * @}
+ *
+ */
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // OPENTHREAD_DATASET_FTD_H_
diff --git a/include/openthread/thread.h b/include/openthread/thread.h
index 0f0e61da8..ba58d1979 100644
--- a/include/openthread/thread.h
+++ b/include/openthread/thread.h
@@ -442,29 +442,6 @@ OTAPI uint32_t OTCALL otThreadGetLocalLeaderPartitionId(otInstance *aInstance);
*/
OTAPI void OTCALL otThreadSetLocalLeaderPartitionId(otInstance *aInstance, uint32_t aPartitionId);
-/**
- * Get the Joiner UDP Port.
- *
- * @param[in] aInstance A pointer to an OpenThread instance.
- *
- * @returns The Joiner UDP Port number.
- *
- * @sa otThreadSetJoinerUdpPort
- */
-OTAPI uint16_t OTCALL otThreadGetJoinerUdpPort(otInstance *aInstance);
-
-/**
- * Set the Joiner UDP Port
- *
- * @param[in] aInstance A pointer to an OpenThread instance.
- * @param[in] aJoinerUdpPort The Joiner UDP Port number.
- *
- * @retval kThreadErrorNone Successfully set the Joiner UDP Port.
- *
- * @sa otThreadGetJoinerUdpPort
- */
-OTAPI ThreadError OTCALL otThreadSetJoinerUdpPort(otInstance *aInstance, uint16_t aJoinerUdpPort);
-
/**
* @}
*/
diff --git a/src/core/meshcop/joiner_router_mtd.hpp b/include/openthread/thread_ftd.h
similarity index 57%
rename from src/core/meshcop/joiner_router_mtd.hpp
rename to include/openthread/thread_ftd.h
index b87a1f922..7c8f3983a 100644
--- a/src/core/meshcop/joiner_router_mtd.hpp
+++ b/include/openthread/thread_ftd.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, The OpenThread Authors.
+ * Copyright (c) 2016-2017, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -28,24 +28,61 @@
/**
* @file
- * This file includes definitions for the Joiner Router role.
+ * @brief
+ * This file defines the OpenThread Thread API (FTD only).
*/
-#ifndef JOINER_ROUTER_HPP_
-#define JOINER_ROUTER_HPP_
+#ifndef OPENTHREAD_THREAD_FTD_H_
+#define OPENTHREAD_THREAD_FTD_H_
-namespace Thread {
-namespace MeshCoP {
+#include "openthread/types.h"
+#include "openthread/link.h"
+#include "openthread/message.h"
-class JoinerRouter
-{
-public:
- JoinerRouter(ThreadNetif &) { }
- uint16_t GetJoinerUdpPort(void) { return 0; }
- ThreadError SetJoinerUdpPort(uint16_t) { return kThreadError_NotImplemented; }
-};
+#ifdef __cplusplus
+extern "C" {
+#endif
-} // namespace MeshCoP
-} // namespace Thread
+/**
+ * @addtogroup thread Thread
+ *
+ * @brief
+ * This module includes functions that control Thread-specific functions.
+ *
+ * @{
+ *
+ */
-#endif // JOINER_ROUTER_HPP_
+/**
+ * Get the Joiner UDP Port.
+ *
+ * @param[in] aInstance A pointer to an OpenThread instance.
+ *
+ * @returns The Joiner UDP Port number.
+ *
+ * @sa otThreadSetJoinerUdpPort
+ */
+OTAPI uint16_t OTCALL otThreadGetJoinerUdpPort(otInstance *aInstance);
+
+/**
+ * Set the Joiner UDP Port
+ *
+ * @param[in] aInstance A pointer to an OpenThread instance.
+ * @param[in] aJoinerUdpPort The Joiner UDP Port number.
+ *
+ * @retval kThreadErrorNone Successfully set the Joiner UDP Port.
+ *
+ * @sa otThreadGetJoinerUdpPort
+ */
+OTAPI ThreadError OTCALL otThreadSetJoinerUdpPort(otInstance *aInstance, uint16_t aJoinerUdpPort);
+
+/**
+ * @}
+ *
+ */
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // OPENTHREAD_THREAD_FTD_H_
diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp
index 8a36634a3..b14fd90f1 100644
--- a/src/cli/cli.cpp
+++ b/src/cli/cli.cpp
@@ -49,6 +49,11 @@
#include "openthread/commissioner.h"
#include "openthread/joiner.h"
+#if OPENTHREAD_FTD
+#include "openthread/dataset_ftd.h"
+#include "openthread/thread_ftd.h"
+#endif
+
#ifndef OTDLL
#include
#include "openthread/diag.h"
@@ -96,7 +101,9 @@ const struct Command Interpreter::sCommands[] =
{ "contextreusedelay", &Interpreter::ProcessContextIdReuseDelay },
{ "counter", &Interpreter::ProcessCounters },
{ "dataset", &Interpreter::ProcessDataset },
+#if OPENTHREAD_FTD
{ "delaytimermin", &Interpreter::ProcessDelayTimerMin},
+#endif
#if OPENTHREAD_ENABLE_DIAG
{ "diag", &Interpreter::ProcessDiag },
#endif
@@ -125,7 +132,9 @@ const struct Command Interpreter::sCommands[] =
#if OPENTHREAD_ENABLE_JOINER
{ "joiner", &Interpreter::ProcessJoiner },
#endif
+#if OPENTHREAD_FTD
{ "joinerport", &Interpreter::ProcessJoinerPort },
+#endif
{ "keysequence", &Interpreter::ProcessKeySequence },
{ "leaderdata", &Interpreter::ProcessLeaderData },
{ "leaderpartitionid", &Interpreter::ProcessLeaderPartitionId },
@@ -701,6 +710,7 @@ void Interpreter::ProcessDataset(int argc, char *argv[])
AppendResult(error);
}
+#if OPENTHREAD_FTD
void Interpreter::ProcessDelayTimerMin(int argc, char *argv[])
{
ThreadError error = kThreadError_None;
@@ -723,6 +733,7 @@ void Interpreter::ProcessDelayTimerMin(int argc, char *argv[])
exit:
AppendResult(error);
}
+#endif
void Interpreter::ProcessDiscover(int argc, char *argv[])
{
@@ -2753,6 +2764,7 @@ void Interpreter::HandleJoinerCallback(ThreadError aError)
}
}
+#if OPENTHREAD_FTD
void Interpreter::ProcessJoinerPort(int argc, char *argv[])
{
ThreadError error = kThreadError_None;
@@ -2771,6 +2783,7 @@ void Interpreter::ProcessJoinerPort(int argc, char *argv[])
exit:
AppendResult(error);
}
+#endif
void Interpreter::ProcessWhitelist(int argc, char *argv[])
{
diff --git a/src/cli/cli_dataset.cpp b/src/cli/cli_dataset.cpp
index e41d7ca89..d4bac0997 100644
--- a/src/cli/cli_dataset.cpp
+++ b/src/cli/cli_dataset.cpp
@@ -43,6 +43,10 @@
#include "openthread/openthread.h"
+#if OPENTHREAD_FTD
+#include "openthread/dataset_ftd.h"
+#endif
+
#include "cli.hpp"
#include "cli_dataset.hpp"
@@ -53,6 +57,7 @@ const DatasetCommand Dataset::sCommands[] =
{
{ "help", &ProcessHelp },
{ "active", &ProcessActive },
+#if OPENTHREAD_FTD
{ "activetimestamp", &ProcessActiveTimestamp },
{ "channel", &ProcessChannel },
{ "channelmask", &ProcessChannelMask },
@@ -66,10 +71,13 @@ const DatasetCommand Dataset::sCommands[] =
{ "mgmtsetcommand", &ProcessMgmtSetCommand },
{ "networkname", &ProcessNetworkName },
{ "panid", &ProcessPanId },
+#endif
{ "pending", &ProcessPending },
+#if OPENTHREAD_FTD
{ "pendingtimestamp", &ProcessPendingTimestamp },
{ "pskc", &ProcessPSKc },
{ "securitypolicy", &ProcessSecurityPolicy },
+#endif
};
Server *Dataset::sServer;
@@ -234,6 +242,17 @@ ThreadError Dataset::ProcessActive(otInstance *aInstance, int argc, char *argv[]
return Print(dataset);
}
+ThreadError Dataset::ProcessPending(otInstance *aInstance, int argc, char *argv[])
+{
+ otOperationalDataset dataset;
+ otDatasetGetPending(aInstance, &dataset);
+
+ (void)argc;
+ (void)argv;
+ return Print(dataset);
+}
+
+#if OPENTHREAD_FTD
ThreadError Dataset::ProcessActiveTimestamp(otInstance *aInstance, int argc, char *argv[])
{
ThreadError error = kThreadError_None;
@@ -418,16 +437,6 @@ exit:
return error;
}
-ThreadError Dataset::ProcessPending(otInstance *aInstance, int argc, char *argv[])
-{
- otOperationalDataset dataset;
- otDatasetGetPending(aInstance, &dataset);
-
- (void)argc;
- (void)argv;
- return Print(dataset);
-}
-
ThreadError Dataset::ProcessPendingTimestamp(otInstance *aInstance, int argc, char *argv[])
{
ThreadError error = kThreadError_None;
@@ -729,6 +738,7 @@ ThreadError Dataset::ProcessSecurityPolicy(otInstance *aInstance, int argc, char
exit:
return error;
}
+#endif // OPENTHREAD_FTD
} // namespace Cli
} // namespace Thread
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index 9a1061299..d60235dc8 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -95,6 +95,7 @@ SOURCES_COMMON = \
api/commissioner_api.cpp \
api/crypto_api.cpp \
api/dataset_api.cpp \
+ api/dataset_ftd_api.cpp \
api/dhcp6_api.cpp \
api/dhcp6_api.cpp \
api/dns_api.cpp \
@@ -109,6 +110,7 @@ SOURCES_COMMON = \
api/netdata_api.cpp \
api/tasklet_api.cpp \
api/thread_api.cpp \
+ api/thread_ftd_api.cpp \
api/udp_api.cpp \
coap/coap_base.cpp \
coap/coap_client.cpp \
@@ -275,11 +277,7 @@ HEADERS_COMMON = \
meshcop/energy_scan_client.hpp \
meshcop/joiner.hpp \
meshcop/joiner_router.hpp \
- meshcop/joiner_router_ftd.hpp \
- meshcop/joiner_router_mtd.hpp \
meshcop/leader.hpp \
- meshcop/leader_ftd.hpp \
- meshcop/leader_mtd.hpp \
meshcop/meshcop.hpp \
meshcop/panid_query_client.hpp \
meshcop/timestamp.hpp \
diff --git a/src/core/api/dataset_api.cpp b/src/core/api/dataset_api.cpp
index 7c24f0013..70505e7bd 100644
--- a/src/core/api/dataset_api.cpp
+++ b/src/core/api/dataset_api.cpp
@@ -28,7 +28,7 @@
/**
* @file
- * This file implements the OpenThread Operational Dataset API.
+ * This file implements the OpenThread Operational Dataset API (for both FTD and MTD).
*/
#include "openthread/dataset.h"
@@ -64,18 +64,6 @@ exit:
return error;
}
-ThreadError otDatasetSetActive(otInstance *aInstance, const otOperationalDataset *aDataset)
-{
- ThreadError error;
-
- VerifyOrExit(aDataset != NULL, error = kThreadError_InvalidArgs);
-
- error = aInstance->mThreadNetif.GetActiveDataset().Set(*aDataset);
-
-exit:
- return error;
-}
-
ThreadError otDatasetGetPending(otInstance *aInstance, otOperationalDataset *aDataset)
{
ThreadError error = kThreadError_None;
@@ -87,49 +75,3 @@ ThreadError otDatasetGetPending(otInstance *aInstance, otOperationalDataset *aDa
exit:
return error;
}
-
-ThreadError otDatasetSetPending(otInstance *aInstance, const otOperationalDataset *aDataset)
-{
- ThreadError error;
-
- VerifyOrExit(aDataset != NULL, error = kThreadError_InvalidArgs);
-
- error = aInstance->mThreadNetif.GetPendingDataset().Set(*aDataset);
-
-exit:
- return error;
-}
-
-ThreadError otDatasetSendMgmtActiveGet(otInstance *aInstance, const uint8_t *aTlvTypes, uint8_t aLength,
- const otIp6Address *aAddress)
-{
- return aInstance->mThreadNetif.GetActiveDataset().SendGetRequest(aTlvTypes, aLength, aAddress);
-}
-
-ThreadError otDatasetSendMgmtActiveSet(otInstance *aInstance, const otOperationalDataset *aDataset,
- const uint8_t *aTlvs, uint8_t aLength)
-{
- return aInstance->mThreadNetif.GetActiveDataset().SendSetRequest(*aDataset, aTlvs, aLength);
-}
-
-ThreadError otDatasetSendMgmtPendingGet(otInstance *aInstance, const uint8_t *aTlvTypes, uint8_t aLength,
- const otIp6Address *aAddress)
-{
- return aInstance->mThreadNetif.GetPendingDataset().SendGetRequest(aTlvTypes, aLength, aAddress);
-}
-
-ThreadError otDatasetSendMgmtPendingSet(otInstance *aInstance, const otOperationalDataset *aDataset,
- const uint8_t *aTlvs, uint8_t aLength)
-{
- return aInstance->mThreadNetif.GetPendingDataset().SendSetRequest(*aDataset, aTlvs, aLength);
-}
-
-uint32_t otDatasetGetDelayTimerMinimal(otInstance *aInstance)
-{
- return aInstance->mThreadNetif.GetLeader().GetDelayTimerMinimal();
-}
-
-ThreadError otDatasetSetDelayTimerMinimal(otInstance *aInstance, uint32_t aDelayTimerMinimal)
-{
- return aInstance->mThreadNetif.GetLeader().SetDelayTimerMinimal(aDelayTimerMinimal);
-}
diff --git a/src/core/api/dataset_ftd_api.cpp b/src/core/api/dataset_ftd_api.cpp
new file mode 100644
index 000000000..74701a401
--- /dev/null
+++ b/src/core/api/dataset_ftd_api.cpp
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2016-2017, 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 OpenThread Operational Dataset API (FTD only).
+ */
+
+#include "openthread/dataset_ftd.h"
+
+#include "openthread-instance.h"
+
+using namespace Thread;
+
+#if OPENTHREAD_FTD
+
+ThreadError otDatasetSetActive(otInstance *aInstance, const otOperationalDataset *aDataset)
+{
+ ThreadError error;
+
+ VerifyOrExit(aDataset != NULL, error = kThreadError_InvalidArgs);
+
+ error = aInstance->mThreadNetif.GetActiveDataset().Set(*aDataset);
+
+exit:
+ return error;
+}
+
+ThreadError otDatasetSetPending(otInstance *aInstance, const otOperationalDataset *aDataset)
+{
+ ThreadError error;
+
+ VerifyOrExit(aDataset != NULL, error = kThreadError_InvalidArgs);
+
+ error = aInstance->mThreadNetif.GetPendingDataset().Set(*aDataset);
+
+exit:
+ return error;
+}
+
+ThreadError otDatasetSendMgmtActiveGet(otInstance *aInstance, const uint8_t *aTlvTypes, uint8_t aLength,
+ const otIp6Address *aAddress)
+{
+ return aInstance->mThreadNetif.GetActiveDataset().SendGetRequest(aTlvTypes, aLength, aAddress);
+}
+
+ThreadError otDatasetSendMgmtActiveSet(otInstance *aInstance, const otOperationalDataset *aDataset,
+ const uint8_t *aTlvs, uint8_t aLength)
+{
+ return aInstance->mThreadNetif.GetActiveDataset().SendSetRequest(*aDataset, aTlvs, aLength);
+}
+
+ThreadError otDatasetSendMgmtPendingGet(otInstance *aInstance, const uint8_t *aTlvTypes, uint8_t aLength,
+ const otIp6Address *aAddress)
+{
+ return aInstance->mThreadNetif.GetPendingDataset().SendGetRequest(aTlvTypes, aLength, aAddress);
+}
+
+ThreadError otDatasetSendMgmtPendingSet(otInstance *aInstance, const otOperationalDataset *aDataset,
+ const uint8_t *aTlvs, uint8_t aLength)
+{
+ return aInstance->mThreadNetif.GetPendingDataset().SendSetRequest(*aDataset, aTlvs, aLength);
+}
+
+uint32_t otDatasetGetDelayTimerMinimal(otInstance *aInstance)
+{
+ return aInstance->mThreadNetif.GetLeader().GetDelayTimerMinimal();
+}
+
+ThreadError otDatasetSetDelayTimerMinimal(otInstance *aInstance, uint32_t aDelayTimerMinimal)
+{
+ return aInstance->mThreadNetif.GetLeader().SetDelayTimerMinimal(aDelayTimerMinimal);
+}
+
+#endif // OPENTHREAD_FTD
diff --git a/src/core/api/thread_api.cpp b/src/core/api/thread_api.cpp
index 1cd8ff6a5..3b403fd36 100644
--- a/src/core/api/thread_api.cpp
+++ b/src/core/api/thread_api.cpp
@@ -28,7 +28,7 @@
/**
* @file
- * This file implements the OpenThread Thread API.
+ * This file implements the OpenThread Thread API (for both FTD and MTD).
*/
#define WPP_NAME "thread_api.tmh"
@@ -258,16 +258,6 @@ void otThreadSetLocalLeaderPartitionId(otInstance *aInstance, uint32_t aPartitio
return aInstance->mThreadNetif.GetMle().SetLeaderPartitionId(aPartitionId);
}
-uint16_t otThreadGetJoinerUdpPort(otInstance *aInstance)
-{
- return aInstance->mThreadNetif.GetJoinerRouter().GetJoinerUdpPort();
-}
-
-ThreadError otThreadSetJoinerUdpPort(otInstance *aInstance, uint16_t aJoinerUdpPort)
-{
- return aInstance->mThreadNetif.GetJoinerRouter().SetJoinerUdpPort(aJoinerUdpPort);
-}
-
uint32_t otThreadGetContextIdReuseDelay(otInstance *aInstance)
{
return aInstance->mThreadNetif.GetNetworkDataLeader().GetContextIdReuseDelay();
diff --git a/src/core/meshcop/leader_mtd.hpp b/src/core/api/thread_ftd_api.cpp
similarity index 72%
rename from src/core/meshcop/leader_mtd.hpp
rename to src/core/api/thread_ftd_api.cpp
index 9552f2486..1718688c1 100644
--- a/src/core/meshcop/leader_mtd.hpp
+++ b/src/core/api/thread_ftd_api.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, The OpenThread Authors.
+ * Copyright (c) 2016-2017, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -28,27 +28,27 @@
/**
* @file
- * This file includes definitions for a MeshCoP Leader.
+ * This file implements the OpenThread Thread API (FTD only).
*/
-#ifndef MESHCOP_LEADER_HPP_
-#define MESHCOP_LEADER_HPP_
+#define WPP_NAME "thread_ftd_api.tmh"
-#include
+#include "openthread/thread_ftd.h"
-namespace Thread {
-namespace MeshCoP {
+#include "openthread-instance.h"
-class Leader
+using namespace Thread;
+
+#if OPENTHREAD_FTD
+
+uint16_t otThreadGetJoinerUdpPort(otInstance *aInstance)
{
-public:
- Leader(ThreadNetif &) { }
- ThreadError SendDatasetChanged(const Ip6::Address &) { return kThreadError_NotImplemented; }
- ThreadError SetDelayTimerMinimal(uint32_t) { return kThreadError_NotImplemented; }
- uint32_t GetDelayTimerMinimal(void) { return 0; }
-};
+ return aInstance->mThreadNetif.GetJoinerRouter().GetJoinerUdpPort();
+}
-} // namespace MeshCoP
-} // namespace Thread
+ThreadError otThreadSetJoinerUdpPort(otInstance *aInstance, uint16_t aJoinerUdpPort)
+{
+ return aInstance->mThreadNetif.GetJoinerRouter().SetJoinerUdpPort(aJoinerUdpPort);
+}
-#endif // MESHCOP_LEADER_HPP_
+#endif // OPENTHREAD_FTD
diff --git a/src/core/meshcop/dataset.cpp b/src/core/meshcop/dataset.cpp
index 85c02d705..49930530e 100644
--- a/src/core/meshcop/dataset.cpp
+++ b/src/core/meshcop/dataset.cpp
@@ -252,6 +252,7 @@ ThreadError Dataset::Set(const Dataset &aDataset)
return kThreadError_None;
}
+#if OPENTHREAD_FTD
ThreadError Dataset::Set(const otOperationalDataset &aDataset)
{
ThreadError error = kThreadError_None;
@@ -361,6 +362,7 @@ ThreadError Dataset::Set(const otOperationalDataset &aDataset)
exit:
return error;
}
+#endif // OPENTHREAD_FTD
const Timestamp *Dataset::GetTimestamp(void) const
{
diff --git a/src/core/meshcop/dataset.hpp b/src/core/meshcop/dataset.hpp
index 5435bf0c7..d38ec65ee 100644
--- a/src/core/meshcop/dataset.hpp
+++ b/src/core/meshcop/dataset.hpp
@@ -164,7 +164,9 @@ public:
ThreadError Set(const Dataset &aDataset);
+#if OPENTHREAD_FTD
ThreadError Set(const otOperationalDataset &aDataset);
+#endif
/**
* This method removes a TLV from the Dataset.
diff --git a/src/core/meshcop/dataset_manager.cpp b/src/core/meshcop/dataset_manager.cpp
index 4c52f4f20..081b40c4a 100644
--- a/src/core/meshcop/dataset_manager.cpp
+++ b/src/core/meshcop/dataset_manager.cpp
@@ -156,6 +156,7 @@ ThreadError DatasetManager::ApplyConfiguration(void)
return error;
}
+#if OPENTHREAD_FTD
ThreadError DatasetManager::Set(const otOperationalDataset &aDataset, uint8_t &aFlags)
{
ThreadError error = kThreadError_None;
@@ -185,6 +186,7 @@ ThreadError DatasetManager::Set(const otOperationalDataset &aDataset, uint8_t &a
exit:
return error;
}
+#endif // OPENTHREAD_FTD
ThreadError DatasetManager::Clear(uint8_t &aFlags, bool aOnlyClearNetwork)
{
@@ -342,6 +344,7 @@ void DatasetManager::Get(Coap::Header &aHeader, Message &aMessage, const Ip6::Me
SendGetResponse(aHeader, aMessageInfo, tlvs, length);
}
+#if OPENTHREAD_FTD
ThreadError DatasetManager::Set(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
Tlv tlv;
@@ -813,6 +816,7 @@ exit:
message->Free();
}
}
+#endif // OPENTHREAD_FTD
void DatasetManager::SendGetResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aMessageInfo,
uint8_t *aTlvs, uint8_t aLength)
@@ -910,6 +914,7 @@ exit:
return error;
}
+#if OPENTHREAD_FTD
ThreadError ActiveDatasetBase::Set(const otOperationalDataset &aDataset)
{
ThreadError error = kThreadError_None;
@@ -921,6 +926,7 @@ ThreadError ActiveDatasetBase::Set(const otOperationalDataset &aDataset)
exit:
return error;
}
+#endif // OPENTHREAD_FTD
ThreadError ActiveDatasetBase::Set(const Dataset &aDataset)
{
@@ -999,6 +1005,7 @@ exit:
return error;
}
+#if OPENTHREAD_FTD
ThreadError PendingDatasetBase::Set(const otOperationalDataset &aDataset)
{
ThreadError error = kThreadError_None;
@@ -1010,6 +1017,7 @@ ThreadError PendingDatasetBase::Set(const otOperationalDataset &aDataset)
exit:
return error;
}
+#endif // OPENTHREAD_FTD
ThreadError PendingDatasetBase::Set(const Dataset &aDataset)
{
@@ -1120,45 +1128,6 @@ void PendingDatasetBase::HandleTimer(void)
Clear(false);
}
-void PendingDatasetBase::ApplyActiveDataset(const Timestamp &aTimestamp, Message &aMessage)
-{
- uint16_t offset = aMessage.GetOffset();
- DelayTimerTlv delayTimer;
- uint8_t flags;
-
- VerifyOrExit(mNetif.GetMle().IsAttached());
-
- while (offset < aMessage.GetLength())
- {
- OT_TOOL_PACKED_BEGIN
- struct
- {
- Tlv tlv;
- uint8_t value[Dataset::kMaxValueSize];
- } OT_TOOL_PACKED_END data;
-
- aMessage.Read(offset, sizeof(Tlv), &data.tlv);
- aMessage.Read(offset + sizeof(Tlv), data.tlv.GetLength(), data.value);
- mNetwork.Set(data.tlv);
- offset += sizeof(Tlv) + data.tlv.GetLength();
- }
-
- // add delay timer tlv
- delayTimer.Init();
- delayTimer.SetDelayTimer(mNetif.GetLeader().GetDelayTimerMinimal());
- mNetwork.Set(delayTimer);
-
- // add pending timestamp tlv
- mNetwork.SetTimestamp(aTimestamp);
- HandleNetworkUpdate(flags);
-
- // reset delay timer
- ResetDelayTimer(kFlagNetworkUpdated);
-
-exit:
- return;
-}
-
void PendingDatasetBase::HandleNetworkUpdate(uint8_t &aFlags)
{
DatasetManager::HandleNetworkUpdate(aFlags);
diff --git a/src/core/meshcop/dataset_manager.hpp b/src/core/meshcop/dataset_manager.hpp
index 465b92f18..b688326ae 100644
--- a/src/core/meshcop/dataset_manager.hpp
+++ b/src/core/meshcop/dataset_manager.hpp
@@ -67,9 +67,6 @@ public:
ThreadError ApplyConfiguration(void);
- ThreadError SendSetRequest(const otOperationalDataset &aDataset, const uint8_t *aTlvs, uint8_t aLength);
- ThreadError SendGetRequest(const uint8_t *aTlvTypes, uint8_t aLength, const otIp6Address *aAddress);
-
protected:
enum
{
@@ -81,8 +78,6 @@ protected:
ThreadError Clear(uint8_t &aFlags, bool aOnlyClearNetwork);
- ThreadError Set(const otOperationalDataset &aDataset, uint8_t &aFlags);
-
ThreadError Set(const Dataset &aDataset);
ThreadError Set(const Timestamp &aTimestamp, const Message &aMessage, uint16_t aOffset, uint8_t aLength,
@@ -92,8 +87,6 @@ protected:
void HandleNetworkUpdate(uint8_t &aFlags);
- ThreadError Set(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
-
Dataset mLocal;
Dataset mNetwork;
@@ -107,7 +100,6 @@ private:
void HandleTimer(void);
ThreadError Register(void);
- void SendSetResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aMessageInfo, StateTlv::State aState);
void SendGetResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aMessageInfo,
uint8_t *aTlvs, uint8_t aLength);
@@ -115,6 +107,19 @@ private:
const char *mUriSet;
const char *mUriGet;
+
+#if OPENTHREAD_FTD
+public:
+ ThreadError SendSetRequest(const otOperationalDataset &aDataset, const uint8_t *aTlvs, uint8_t aLength);
+ ThreadError SendGetRequest(const uint8_t *aTlvTypes, uint8_t aLength, const otIp6Address *aAddress);
+
+protected:
+ ThreadError Set(const otOperationalDataset &aDataset, uint8_t &aFlags);
+ ThreadError Set(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
+
+private:
+ void SendSetResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aMessageInfo, StateTlv::State aState);
+#endif
};
class ActiveDatasetBase: public DatasetManager
@@ -126,7 +131,9 @@ public:
ThreadError Clear(bool aOnlyClearNetwork);
+#if OPENTHREAD_FTD
ThreadError Set(const otOperationalDataset &aDataset);
+#endif
ThreadError Set(const Dataset &aDataset);
@@ -149,7 +156,9 @@ public:
ThreadError Clear(bool aOnlyClearNetwork);
+#if OPENTHREAD_FTD
ThreadError Set(const otOperationalDataset &aDataset);
+#endif
ThreadError Set(const Dataset &aDataset);
@@ -157,8 +166,6 @@ public:
void UpdateDelayTimer(void);
- void ApplyActiveDataset(const Timestamp &aTimestamp, Message &aMessage);
-
protected:
static void HandleTimer(void *aContext);
void HandleTimer(void);
diff --git a/src/core/meshcop/dataset_manager_ftd.cpp b/src/core/meshcop/dataset_manager_ftd.cpp
index 7513352bc..d2d4e17a8 100644
--- a/src/core/meshcop/dataset_manager_ftd.cpp
+++ b/src/core/meshcop/dataset_manager_ftd.cpp
@@ -252,6 +252,45 @@ exit:
return;
}
+void PendingDataset::ApplyActiveDataset(const Timestamp &aTimestamp, Message &aMessage)
+{
+ uint16_t offset = aMessage.GetOffset();
+ DelayTimerTlv delayTimer;
+ uint8_t flags;
+
+ VerifyOrExit(mNetif.GetMle().IsAttached());
+
+ while (offset < aMessage.GetLength())
+ {
+ OT_TOOL_PACKED_BEGIN
+ struct
+ {
+ Tlv tlv;
+ uint8_t value[Dataset::kMaxValueSize];
+ } OT_TOOL_PACKED_END data;
+
+ aMessage.Read(offset, sizeof(Tlv), &data.tlv);
+ aMessage.Read(offset + sizeof(Tlv), data.tlv.GetLength(), data.value);
+ mNetwork.Set(data.tlv);
+ offset += sizeof(Tlv) + data.tlv.GetLength();
+ }
+
+ // add delay timer tlv
+ delayTimer.Init();
+ delayTimer.SetDelayTimer(mNetif.GetLeader().GetDelayTimerMinimal());
+ mNetwork.Set(delayTimer);
+
+ // add pending timestamp tlv
+ mNetwork.SetTimestamp(aTimestamp);
+ HandleNetworkUpdate(flags);
+
+ // reset delay timer
+ ResetDelayTimer(kFlagNetworkUpdated);
+
+exit:
+ return;
+}
+
} // namespace MeshCoP
} // namespace Thread
diff --git a/src/core/meshcop/dataset_manager_ftd.hpp b/src/core/meshcop/dataset_manager_ftd.hpp
index 7e437077e..8c3ecb193 100644
--- a/src/core/meshcop/dataset_manager_ftd.hpp
+++ b/src/core/meshcop/dataset_manager_ftd.hpp
@@ -75,6 +75,8 @@ public:
void StopLeader(void);
+ void ApplyActiveDataset(const Timestamp &aTimestamp, Message &aMessage);
+
private:
static void HandleSet(void *aContext, otCoapHeader *aHeader, otMessage *aMessage,
const otMessageInfo *aMessageInfo);
diff --git a/src/core/meshcop/dataset_manager_mtd.hpp b/src/core/meshcop/dataset_manager_mtd.hpp
index 9edb816e9..de267bf3f 100644
--- a/src/core/meshcop/dataset_manager_mtd.hpp
+++ b/src/core/meshcop/dataset_manager_mtd.hpp
@@ -49,20 +49,12 @@ public:
ActiveDataset(ThreadNetif &aThreadNetif) : ActiveDatasetBase(aThreadNetif) { }
ThreadError GenerateLocal(void) { return kThreadError_NotImplemented; }
-
- void StartLeader(void) { }
-
- void StopLeader(void) { }
};
class PendingDataset: public PendingDatasetBase
{
public:
PendingDataset(ThreadNetif &aThreadNetif) : PendingDatasetBase(aThreadNetif) { }
-
- void StartLeader(void) { }
-
- void StopLeader(void) { }
};
} // namespace MeshCoP
diff --git a/src/core/meshcop/joiner_router.hpp b/src/core/meshcop/joiner_router.hpp
index 9653ade39..84a7b9564 100644
--- a/src/core/meshcop/joiner_router.hpp
+++ b/src/core/meshcop/joiner_router.hpp
@@ -26,10 +26,230 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#if OPENTHREAD_MTD
-#include "joiner_router_mtd.hpp"
-#elif OPENTHREAD_FTD
-#include "joiner_router_ftd.hpp"
-#else
-#error "Please define OPENTHREAD_MTD=1, or OPENTHREAD_FTD=1"
-#endif
+/**
+ * @file
+ * This file includes definitions for the Joiner Router role.
+ */
+
+#ifndef JOINER_ROUTER_HPP_
+#define JOINER_ROUTER_HPP_
+
+#include "openthread/types.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+namespace Thread {
+
+class ThreadNetif;
+
+namespace MeshCoP {
+
+class JoinerRouter
+{
+public:
+ /**
+ * This constructor initializes the Joiner Router object.
+ *
+ * @param[in] aThreadNetif A reference to the Thread network interface.
+ *
+ */
+ JoinerRouter(ThreadNetif &aNetif);
+
+ /**
+ * This method returns the pointer to the parent otInstance structure.
+ *
+ * @returns The pointer to the parent otInstance structure.
+ *
+ */
+ otInstance *GetInstance(void);
+
+ /**
+ * This method returns the Joiner UDP Port.
+ *
+ * @returns The Joiner UDP Port number .
+ *
+ */
+ uint16_t GetJoinerUdpPort(void);
+
+ /**
+ * This method sets the Joiner UDP Port.
+ *
+ * @param[in] The Joiner UDP Port number.
+ *
+ * @retval kThreadError_None Successfully set the Joiner UDP Port.
+ *
+ */
+ ThreadError SetJoinerUdpPort(uint16_t aJoinerUdpPort);
+
+private:
+ enum
+ {
+ kDelayJoinEnt = 50, ///< milliseconds
+ };
+
+ static void HandleNetifStateChanged(uint32_t aFlags, void *aContext);
+ void HandleNetifStateChanged(uint32_t aFlags);
+
+ static void HandleUdpReceive(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo);
+ void HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
+
+ static void HandleRelayTransmit(void *aContext, otCoapHeader *aHeader, otMessage *aMessage,
+ const otMessageInfo *aMessageInfo);
+ void HandleRelayTransmit(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
+
+ static void HandleJoinerEntrustResponse(void *aContext, otCoapHeader *aHeader, otMessage *aMessage,
+ const otMessageInfo *aMessageInfo, ThreadError result);
+ void HandleJoinerEntrustResponse(Coap::Header *aHeader, Message *aMessage,
+ const Ip6::MessageInfo *aMessageInfo, ThreadError result);
+
+ static void HandleTimer(void *aContext);
+ void HandleTimer(void);
+
+ ThreadError DelaySendingJoinerEntrust(const Ip6::MessageInfo &aMessageInfo, const JoinerRouterKekTlv &aKek);
+ void SendDelayedJoinerEntrust(void);
+ ThreadError SendJoinerEntrust(Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
+
+ ThreadError GetBorderAgentRloc(uint16_t &aRloc);
+
+ Ip6::NetifCallback mNetifCallback;
+
+ Ip6::UdpSocket mSocket;
+ Coap::Resource mRelayTransmit;
+ ThreadNetif &mNetif;
+
+ Timer mTimer;
+ MessageQueue mDelayedJoinEnts;
+
+ uint16_t mJoinerUdpPort;
+
+ bool mIsJoinerPortConfigured : 1;
+ bool mExpectJoinEntRsp : 1;
+};
+
+/**
+ * This class implements functionality required for delaying JOIN_ENT.ntf messages.
+ *
+ */
+class DelayedJoinEntHeader
+{
+public:
+ /**
+ * Default constructor for the object.
+ *
+ */
+ DelayedJoinEntHeader(void) { memset(this, 0, sizeof(*this)); }
+
+ /**
+ * This constructor initializes the object with specific values.
+ *
+ * @param[in] aSendTime Time when the message shall be sent.
+ * @param[in] aDestination IPv6 address of the message destination.
+ *
+ */
+ DelayedJoinEntHeader(uint32_t aSendTime, Ip6::MessageInfo &aMessageInfo, const uint8_t *aKek) {
+ mSendTime = aSendTime;
+ mMessageInfo = aMessageInfo;
+ memcpy(&mKek, aKek, sizeof(mKek));
+ }
+
+ /**
+ * This method appends delayed response header to the message.
+ *
+ * @param[in] aMessage A reference to the message.
+ *
+ * @retval kThreadError_None Successfully appended the bytes.
+ * @retval kThreadError_NoBufs Insufficient available buffers to grow the message.
+ *
+ */
+ ThreadError AppendTo(Message &aMessage) {
+ return aMessage.Append(this, sizeof(*this));
+ }
+
+ /**
+ * This method reads delayed response header from the message.
+ *
+ * @param[in] aMessage A reference to the message.
+ *
+ * @returns The number of bytes read.
+ *
+ */
+ uint16_t ReadFrom(Message &aMessage) {
+ return aMessage.Read(aMessage.GetLength() - sizeof(*this), sizeof(*this), this);
+ }
+
+ /**
+ * This method removes delayed response header from the message.
+ *
+ * @param[in] aMessage A reference to the message.
+ *
+ * @retval kThreadError_None Successfully removed the header.
+ *
+ */
+ static ThreadError RemoveFrom(Message &aMessage) {
+ return aMessage.SetLength(aMessage.GetLength() - sizeof(DelayedJoinEntHeader));
+ }
+
+ /**
+ * This method returns a time when the message shall be sent.
+ *
+ * @returns A time when the message shall be sent.
+ *
+ */
+ uint32_t GetSendTime(void) const { return mSendTime; }
+
+ /**
+ * This method returns a destination of the delayed message.
+ *
+ * @returns A destination of the delayed message.
+ *
+ */
+ const Ip6::MessageInfo *GetMessageInfo(void) const { return &mMessageInfo; }
+
+ /**
+ * This method returns a pointer to the KEK that should be used to send the delayed message.
+ *
+ * @returns A pointer to the KEK.
+ *
+ */
+ const uint8_t *GetKek(void) const { return mKek; }
+
+ /**
+ * This method checks if the message shall be sent before the given time.
+ *
+ * @param[in] aTime A time to compare.
+ *
+ * @retval TRUE If the message shall be sent before the given time.
+ * @retval FALSE Otherwise.
+ */
+ bool IsEarlier(uint32_t aTime) { return (static_cast(aTime - mSendTime) > 0); }
+
+ /**
+ * This method checks if the message shall be sent after the given time.
+ *
+ * @param[in] aTime A time to compare.
+ *
+ * @retval TRUE If the message shall be sent after the given time.
+ * @retval FALSE Otherwise.
+ */
+ bool IsLater(uint32_t aTime) { return (static_cast(aTime - mSendTime) < 0); }
+
+private:
+ Ip6::MessageInfo mMessageInfo; ///< Message info of the message to send.
+ uint32_t mSendTime; ///< Time when the message shall be sent.
+ uint8_t mKek[KeyManager::kMaxKeyLength]; ///< KEK used by MAC layer to encode this message.
+};
+
+
+} // namespace MeshCoP
+} // namespace Thread
+
+#endif // JOINER_ROUTER_HPP_
diff --git a/src/core/meshcop/joiner_router_ftd.hpp b/src/core/meshcop/joiner_router_ftd.hpp
deleted file mode 100644
index 84a7b9564..000000000
--- a/src/core/meshcop/joiner_router_ftd.hpp
+++ /dev/null
@@ -1,255 +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 the Joiner Router role.
- */
-
-#ifndef JOINER_ROUTER_HPP_
-#define JOINER_ROUTER_HPP_
-
-#include "openthread/types.h"
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-namespace Thread {
-
-class ThreadNetif;
-
-namespace MeshCoP {
-
-class JoinerRouter
-{
-public:
- /**
- * This constructor initializes the Joiner Router object.
- *
- * @param[in] aThreadNetif A reference to the Thread network interface.
- *
- */
- JoinerRouter(ThreadNetif &aNetif);
-
- /**
- * This method returns the pointer to the parent otInstance structure.
- *
- * @returns The pointer to the parent otInstance structure.
- *
- */
- otInstance *GetInstance(void);
-
- /**
- * This method returns the Joiner UDP Port.
- *
- * @returns The Joiner UDP Port number .
- *
- */
- uint16_t GetJoinerUdpPort(void);
-
- /**
- * This method sets the Joiner UDP Port.
- *
- * @param[in] The Joiner UDP Port number.
- *
- * @retval kThreadError_None Successfully set the Joiner UDP Port.
- *
- */
- ThreadError SetJoinerUdpPort(uint16_t aJoinerUdpPort);
-
-private:
- enum
- {
- kDelayJoinEnt = 50, ///< milliseconds
- };
-
- static void HandleNetifStateChanged(uint32_t aFlags, void *aContext);
- void HandleNetifStateChanged(uint32_t aFlags);
-
- static void HandleUdpReceive(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo);
- void HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
-
- static void HandleRelayTransmit(void *aContext, otCoapHeader *aHeader, otMessage *aMessage,
- const otMessageInfo *aMessageInfo);
- void HandleRelayTransmit(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
-
- static void HandleJoinerEntrustResponse(void *aContext, otCoapHeader *aHeader, otMessage *aMessage,
- const otMessageInfo *aMessageInfo, ThreadError result);
- void HandleJoinerEntrustResponse(Coap::Header *aHeader, Message *aMessage,
- const Ip6::MessageInfo *aMessageInfo, ThreadError result);
-
- static void HandleTimer(void *aContext);
- void HandleTimer(void);
-
- ThreadError DelaySendingJoinerEntrust(const Ip6::MessageInfo &aMessageInfo, const JoinerRouterKekTlv &aKek);
- void SendDelayedJoinerEntrust(void);
- ThreadError SendJoinerEntrust(Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
-
- ThreadError GetBorderAgentRloc(uint16_t &aRloc);
-
- Ip6::NetifCallback mNetifCallback;
-
- Ip6::UdpSocket mSocket;
- Coap::Resource mRelayTransmit;
- ThreadNetif &mNetif;
-
- Timer mTimer;
- MessageQueue mDelayedJoinEnts;
-
- uint16_t mJoinerUdpPort;
-
- bool mIsJoinerPortConfigured : 1;
- bool mExpectJoinEntRsp : 1;
-};
-
-/**
- * This class implements functionality required for delaying JOIN_ENT.ntf messages.
- *
- */
-class DelayedJoinEntHeader
-{
-public:
- /**
- * Default constructor for the object.
- *
- */
- DelayedJoinEntHeader(void) { memset(this, 0, sizeof(*this)); }
-
- /**
- * This constructor initializes the object with specific values.
- *
- * @param[in] aSendTime Time when the message shall be sent.
- * @param[in] aDestination IPv6 address of the message destination.
- *
- */
- DelayedJoinEntHeader(uint32_t aSendTime, Ip6::MessageInfo &aMessageInfo, const uint8_t *aKek) {
- mSendTime = aSendTime;
- mMessageInfo = aMessageInfo;
- memcpy(&mKek, aKek, sizeof(mKek));
- }
-
- /**
- * This method appends delayed response header to the message.
- *
- * @param[in] aMessage A reference to the message.
- *
- * @retval kThreadError_None Successfully appended the bytes.
- * @retval kThreadError_NoBufs Insufficient available buffers to grow the message.
- *
- */
- ThreadError AppendTo(Message &aMessage) {
- return aMessage.Append(this, sizeof(*this));
- }
-
- /**
- * This method reads delayed response header from the message.
- *
- * @param[in] aMessage A reference to the message.
- *
- * @returns The number of bytes read.
- *
- */
- uint16_t ReadFrom(Message &aMessage) {
- return aMessage.Read(aMessage.GetLength() - sizeof(*this), sizeof(*this), this);
- }
-
- /**
- * This method removes delayed response header from the message.
- *
- * @param[in] aMessage A reference to the message.
- *
- * @retval kThreadError_None Successfully removed the header.
- *
- */
- static ThreadError RemoveFrom(Message &aMessage) {
- return aMessage.SetLength(aMessage.GetLength() - sizeof(DelayedJoinEntHeader));
- }
-
- /**
- * This method returns a time when the message shall be sent.
- *
- * @returns A time when the message shall be sent.
- *
- */
- uint32_t GetSendTime(void) const { return mSendTime; }
-
- /**
- * This method returns a destination of the delayed message.
- *
- * @returns A destination of the delayed message.
- *
- */
- const Ip6::MessageInfo *GetMessageInfo(void) const { return &mMessageInfo; }
-
- /**
- * This method returns a pointer to the KEK that should be used to send the delayed message.
- *
- * @returns A pointer to the KEK.
- *
- */
- const uint8_t *GetKek(void) const { return mKek; }
-
- /**
- * This method checks if the message shall be sent before the given time.
- *
- * @param[in] aTime A time to compare.
- *
- * @retval TRUE If the message shall be sent before the given time.
- * @retval FALSE Otherwise.
- */
- bool IsEarlier(uint32_t aTime) { return (static_cast(aTime - mSendTime) > 0); }
-
- /**
- * This method checks if the message shall be sent after the given time.
- *
- * @param[in] aTime A time to compare.
- *
- * @retval TRUE If the message shall be sent after the given time.
- * @retval FALSE Otherwise.
- */
- bool IsLater(uint32_t aTime) { return (static_cast(aTime - mSendTime) < 0); }
-
-private:
- Ip6::MessageInfo mMessageInfo; ///< Message info of the message to send.
- uint32_t mSendTime; ///< Time when the message shall be sent.
- uint8_t mKek[KeyManager::kMaxKeyLength]; ///< KEK used by MAC layer to encode this message.
-};
-
-
-} // namespace MeshCoP
-} // namespace Thread
-
-#endif // JOINER_ROUTER_HPP_
diff --git a/src/core/meshcop/leader.hpp b/src/core/meshcop/leader.hpp
index f2e90667b..27afeea99 100644
--- a/src/core/meshcop/leader.hpp
+++ b/src/core/meshcop/leader.hpp
@@ -26,11 +26,131 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#if OPENTHREAD_MTD
-#include "leader_mtd.hpp"
-#elif OPENTHREAD_FTD
-#include "leader_ftd.hpp"
-#else
-#error "Please define OPENTHREAD_MTD=1 or OPENTHREAD_FTD=1"
-#endif
+/**
+ * @file
+ * This file includes definitions for a MeshCoP Leader.
+ */
+#ifndef MESHCOP_LEADER_HPP_
+#define MESHCOP_LEADER_HPP_
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+namespace Thread {
+namespace MeshCoP {
+
+OT_TOOL_PACKED_BEGIN
+class CommissioningData
+{
+public:
+ uint8_t GetLength(void) const {
+ return sizeof(Tlv) + mBorderAgentLocator.GetLength() +
+ sizeof(Tlv) + mCommissionerSessionId.GetLength() +
+ sizeof(Tlv) + mSteeringData.GetLength();
+ }
+
+ BorderAgentLocatorTlv mBorderAgentLocator;
+ CommissionerSessionIdTlv mCommissionerSessionId;
+ SteeringDataTlv mSteeringData;
+} OT_TOOL_PACKED_END;
+
+class Leader
+{
+public:
+ /**
+ * This constructor initializes the Leader object.
+ *
+ * @param[in] aThreadNetif A reference to the Thread network interface.
+ *
+ */
+ Leader(ThreadNetif &aThreadNetif);
+
+ /**
+ * This method returns the pointer to the parent otInstance structure.
+ *
+ * @returns The pointer to the parent otInstance structure.
+ *
+ */
+ otInstance *GetInstance(void);
+
+ /**
+ * This method sends a MGMT_DATASET_CHANGED message to commissioner.
+ *
+ * @param[in] aAddress The IPv6 address of destination.
+ *
+ * @retval kThreadError_None Successfully send MGMT_DATASET_CHANGED message.
+ * @retval kThreadError_NoBufs Insufficient buffers to generate a MGMT_DATASET_CHANGED message.
+ *
+ */
+ ThreadError SendDatasetChanged(const Ip6::Address &aAddress);
+
+ /**
+ * This method sets minimal delay timer.
+ *
+ * @param[in] aDelayTimerMinimal The value of minimal delay timer (in ms).
+ *
+ * @retval kThreadError_None Successfully set the minimal delay timer.
+ * @retval kThreadError_InvalidArgs If @p aDelayTimerMinimal is not valid.
+ *
+ */
+ ThreadError SetDelayTimerMinimal(uint32_t aDelayTimerMinimal);
+
+ /**
+ * This method gets minimal delay timer.
+ *
+ * @retval the miniaml delay timer (in ms).
+ *
+ */
+ uint32_t GetDelayTimerMinimal(void) const;
+
+ /**
+ * This method sets empty Commissioner Data TLV in the Thread Network Data.
+ *
+ */
+ void SetEmptyCommissionerData(void);
+
+private:
+ enum
+ {
+ kTimeoutLeaderPetition = 50, ///< TIMEOUT_LEAD_PET (seconds)
+ };
+
+ static void HandleTimer(void *aContext);
+ void HandleTimer(void);
+
+ static void HandlePetition(void *aContext, otCoapHeader *aHeader, otMessage *aMessage,
+ const otMessageInfo *aMessageInfo);
+ void HandlePetition(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
+ ThreadError SendPetitionResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aMessageInfo,
+ StateTlv::State aState);
+
+ static void HandleKeepAlive(void *aContext, otCoapHeader *aHeader, otMessage *aMessage,
+ const otMessageInfo *aMessageInfo);
+ void HandleKeepAlive(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
+ ThreadError SendKeepAliveResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aMessageInfo,
+ StateTlv::State aState);
+
+ static void HandleUdpReceive(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo);
+
+ void ResignCommissioner(void);
+
+ Coap::Resource mPetition;
+ Coap::Resource mKeepAlive;
+ Timer mTimer;
+
+ uint32_t mDelayTimerMinimal;
+
+ CommissionerIdTlv mCommissionerId;
+ uint16_t mSessionId;
+ ThreadNetif &mNetif;
+};
+
+} // namespace MeshCoP
+} // namespace Thread
+
+#endif // MESHCOP_LEADER_HPP_
diff --git a/src/core/meshcop/leader_ftd.hpp b/src/core/meshcop/leader_ftd.hpp
deleted file mode 100644
index 27afeea99..000000000
--- a/src/core/meshcop/leader_ftd.hpp
+++ /dev/null
@@ -1,156 +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 a MeshCoP Leader.
- */
-
-#ifndef MESHCOP_LEADER_HPP_
-#define MESHCOP_LEADER_HPP_
-
-#include
-#include
-#include
-#include
-#include
-#include
-
-namespace Thread {
-namespace MeshCoP {
-
-OT_TOOL_PACKED_BEGIN
-class CommissioningData
-{
-public:
- uint8_t GetLength(void) const {
- return sizeof(Tlv) + mBorderAgentLocator.GetLength() +
- sizeof(Tlv) + mCommissionerSessionId.GetLength() +
- sizeof(Tlv) + mSteeringData.GetLength();
- }
-
- BorderAgentLocatorTlv mBorderAgentLocator;
- CommissionerSessionIdTlv mCommissionerSessionId;
- SteeringDataTlv mSteeringData;
-} OT_TOOL_PACKED_END;
-
-class Leader
-{
-public:
- /**
- * This constructor initializes the Leader object.
- *
- * @param[in] aThreadNetif A reference to the Thread network interface.
- *
- */
- Leader(ThreadNetif &aThreadNetif);
-
- /**
- * This method returns the pointer to the parent otInstance structure.
- *
- * @returns The pointer to the parent otInstance structure.
- *
- */
- otInstance *GetInstance(void);
-
- /**
- * This method sends a MGMT_DATASET_CHANGED message to commissioner.
- *
- * @param[in] aAddress The IPv6 address of destination.
- *
- * @retval kThreadError_None Successfully send MGMT_DATASET_CHANGED message.
- * @retval kThreadError_NoBufs Insufficient buffers to generate a MGMT_DATASET_CHANGED message.
- *
- */
- ThreadError SendDatasetChanged(const Ip6::Address &aAddress);
-
- /**
- * This method sets minimal delay timer.
- *
- * @param[in] aDelayTimerMinimal The value of minimal delay timer (in ms).
- *
- * @retval kThreadError_None Successfully set the minimal delay timer.
- * @retval kThreadError_InvalidArgs If @p aDelayTimerMinimal is not valid.
- *
- */
- ThreadError SetDelayTimerMinimal(uint32_t aDelayTimerMinimal);
-
- /**
- * This method gets minimal delay timer.
- *
- * @retval the miniaml delay timer (in ms).
- *
- */
- uint32_t GetDelayTimerMinimal(void) const;
-
- /**
- * This method sets empty Commissioner Data TLV in the Thread Network Data.
- *
- */
- void SetEmptyCommissionerData(void);
-
-private:
- enum
- {
- kTimeoutLeaderPetition = 50, ///< TIMEOUT_LEAD_PET (seconds)
- };
-
- static void HandleTimer(void *aContext);
- void HandleTimer(void);
-
- static void HandlePetition(void *aContext, otCoapHeader *aHeader, otMessage *aMessage,
- const otMessageInfo *aMessageInfo);
- void HandlePetition(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
- ThreadError SendPetitionResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aMessageInfo,
- StateTlv::State aState);
-
- static void HandleKeepAlive(void *aContext, otCoapHeader *aHeader, otMessage *aMessage,
- const otMessageInfo *aMessageInfo);
- void HandleKeepAlive(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
- ThreadError SendKeepAliveResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aMessageInfo,
- StateTlv::State aState);
-
- static void HandleUdpReceive(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo);
-
- void ResignCommissioner(void);
-
- Coap::Resource mPetition;
- Coap::Resource mKeepAlive;
- Timer mTimer;
-
- uint32_t mDelayTimerMinimal;
-
- CommissionerIdTlv mCommissionerId;
- uint16_t mSessionId;
- ThreadNetif &mNetif;
-};
-
-} // namespace MeshCoP
-} // namespace Thread
-
-#endif // MESHCOP_LEADER_HPP_
diff --git a/src/core/thread/thread_netif.cpp b/src/core/thread/thread_netif.cpp
index 9e7a15eae..2fc2b9590 100644
--- a/src/core/thread/thread_netif.cpp
+++ b/src/core/thread/thread_netif.cpp
@@ -92,8 +92,10 @@ ThreadNetif::ThreadNetif(Ip6::Ip6 &aIp6):
#if OPENTHREAD_ENABLE_JAM_DETECTION
mJamDetector(*this),
#endif // OPENTHREAD_ENABLE_JAM_DETECTTION
+#if OPENTHREAD_FTD
mJoinerRouter(*this),
mLeader(*this),
+#endif // OPENTHREAD_FTD
mAnnounceBegin(*this),
mPanIdQuery(*this),
mEnergyScan(*this)
diff --git a/src/core/thread/thread_netif.hpp b/src/core/thread/thread_netif.hpp
index 02b90e748..b6b9ec7a7 100644
--- a/src/core/thread/thread_netif.hpp
+++ b/src/core/thread/thread_netif.hpp
@@ -287,9 +287,11 @@ public:
MeshCoP::PendingDataset &GetPendingDataset(void) { return mPendingDataset; }
+#if OPENTHREAD_FTD
MeshCoP::JoinerRouter &GetJoinerRouter(void) { return mJoinerRouter; }
MeshCoP::Leader &GetLeader(void) { return mLeader; }
+#endif // OPENTHREAD_FTD
AnnounceBeginServer &GetAnnounceBeginServer(void) { return mAnnounceBegin; }
@@ -371,8 +373,11 @@ private:
Utils::JamDetector mJamDetector;
#endif // OPENTHREAD_ENABLE_JAM_DETECTION
+#if OPENTHREAD_FTD
MeshCoP::JoinerRouter mJoinerRouter;
MeshCoP::Leader mLeader;
+#endif // OPENTHREAD_FTD
+
AnnounceBeginServer mAnnounceBegin;
PanIdQueryServer mPanIdQuery;
EnergyScanServer mEnergyScan;