mirror of
https://github.com/espressif/openthread.git
synced 2026-07-30 07:37:46 +00:00
[commissioning] changing CPU clock for commissioning process (#2041)
This commit is contained in:
committed by
Jonathan Hui
parent
bf0e663ee5
commit
0a82741e86
@@ -43,6 +43,10 @@ LDADD_COMMON = \
|
||||
LDFLAGS_COMMON = \
|
||||
$(NULL)
|
||||
|
||||
LIBTOOLFLAGS_COMMON = \
|
||||
--preserve-dup-deps \
|
||||
$(NULL)
|
||||
|
||||
SOURCES_COMMON = \
|
||||
main.c \
|
||||
$(NULL)
|
||||
@@ -181,12 +185,17 @@ ot_cli_ftd_LDADD = \
|
||||
$(top_builddir)/src/cli/libopenthread-cli-ftd.a \
|
||||
$(top_builddir)/src/core/libopenthread-ftd.a \
|
||||
$(LDADD_COMMON) \
|
||||
$(top_builddir)/src/core/libopenthread-ftd.a \
|
||||
$(NULL)
|
||||
|
||||
ot_cli_ftd_LDFLAGS = \
|
||||
$(LDFLAGS_COMMON) \
|
||||
$(NULL)
|
||||
|
||||
ot_cli_ftd_LIBTOOLFLAGS = \
|
||||
$(LIBTOOLFLAGS_COMMON) \
|
||||
$(NULL)
|
||||
|
||||
ot_cli_ftd_SOURCES = \
|
||||
$(SOURCES_COMMON) \
|
||||
$(NULL)
|
||||
@@ -205,12 +214,17 @@ ot_cli_mtd_LDADD = \
|
||||
$(top_builddir)/src/cli/libopenthread-cli-mtd.a \
|
||||
$(top_builddir)/src/core/libopenthread-mtd.a \
|
||||
$(LDADD_COMMON) \
|
||||
$(top_builddir)/src/core/libopenthread-mtd.a \
|
||||
$(NULL)
|
||||
|
||||
ot_cli_mtd_LDFLAGS = \
|
||||
$(LDFLAGS_COMMON) \
|
||||
$(NULL)
|
||||
|
||||
ot_cli_mtd_LIBTOOLFLAGS = \
|
||||
$(LIBTOOLFLAGS_COMMON) \
|
||||
$(NULL)
|
||||
|
||||
ot_cli_mtd_SOURCES = \
|
||||
$(SOURCES_COMMON) \
|
||||
$(NULL)
|
||||
|
||||
@@ -43,6 +43,10 @@ LDADD_COMMON = \
|
||||
LDFLAGS_COMMON = \
|
||||
$(NULL)
|
||||
|
||||
LIBTOOLFLAGS_COMMON = \
|
||||
--preserve-dup-deps \
|
||||
$(NULL)
|
||||
|
||||
SOURCES_COMMON = \
|
||||
main.c \
|
||||
$(NULL)
|
||||
@@ -173,12 +177,17 @@ ot_ncp_ftd_LDADD = \
|
||||
$(top_builddir)/src/ncp/libopenthread-ncp-ftd.a \
|
||||
$(top_builddir)/src/core/libopenthread-ftd.a \
|
||||
$(LDADD_COMMON) \
|
||||
$(top_builddir)/src/core/libopenthread-ftd.a \
|
||||
$(NULL)
|
||||
|
||||
ot_ncp_ftd_LDFLAGS = \
|
||||
$(LDFLAGS_COMMON) \
|
||||
$(NULL)
|
||||
|
||||
ot_ncp_ftd_LIBTOOLFLAGS = \
|
||||
$(LIBTOOLFLAGS_COMMON) \
|
||||
$(NULL)
|
||||
|
||||
ot_ncp_ftd_SOURCES = \
|
||||
$(SOURCES_COMMON) \
|
||||
$(NULL)
|
||||
@@ -197,12 +206,17 @@ ot_ncp_mtd_LDADD = \
|
||||
$(top_builddir)/src/ncp/libopenthread-ncp-mtd.a \
|
||||
$(top_builddir)/src/core/libopenthread-mtd.a \
|
||||
$(LDADD_COMMON) \
|
||||
$(top_builddir)/src/core/libopenthread-mtd.a \
|
||||
$(NULL)
|
||||
|
||||
ot_ncp_mtd_LDFLAGS = \
|
||||
$(LDFLAGS_COMMON) \
|
||||
$(NULL)
|
||||
|
||||
ot_ncp_mtd_LIBTOOLFLAGS = \
|
||||
$(LIBTOOLFLAGS_COMMON) \
|
||||
$(NULL)
|
||||
|
||||
ot_ncp_mtd_SOURCES = \
|
||||
$(SOURCES_COMMON) \
|
||||
$(NULL)
|
||||
|
||||
@@ -26,10 +26,12 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <openthread/types.h>
|
||||
#include <openthread/config.h>
|
||||
|
||||
#include <openthread/openthread.h>
|
||||
#include <openthread/platform/misc.h>
|
||||
|
||||
#include "hw_cpm.h"
|
||||
#include "sdk_defs.h"
|
||||
|
||||
void otPlatReset(otInstance *aInstance)
|
||||
|
||||
@@ -79,7 +79,15 @@
|
||||
* The DA15000 platform provides an otPlatLog() function.
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_LOG_OUTPUT /* allow command line override */
|
||||
#define OPENTHREAD_CONFIG_LOG_OUTPUT OPENTHERAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED
|
||||
#define OPENTHREAD_CONFIG_LOG_OUTPUT OPENTHREAD_CONFIG_LOG_OUTPUT_APP
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_MAX_STATECHANGE_HANDLERS
|
||||
*
|
||||
* The maximum number of state-changed callback handlers (set using `otSetStateChangedCallback()`).
|
||||
*
|
||||
*/
|
||||
#define OPENTHREAD_CONFIG_MAX_STATECHANGE_HANDLERS 3
|
||||
|
||||
#endif // OPENTHREAD_CORE_DA15000_CONFIG_H_
|
||||
|
||||
@@ -31,9 +31,10 @@
|
||||
* This file includes the platform-specific initializers.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <openthread/config.h>
|
||||
|
||||
#include <openthread/commissioner.h>
|
||||
#include <openthread/joiner.h>
|
||||
#include <openthread/openthread.h>
|
||||
#include <openthread/platform/alarm-milli.h>
|
||||
#include <openthread/platform/uart.h>
|
||||
@@ -58,9 +59,7 @@ static int sMsCounter;
|
||||
#define ROUTER_BLINK_TIME (500)
|
||||
#define CHILD_BLINK_TIME (2000)
|
||||
|
||||
#define SET_CLOCK_TO_96MHZ
|
||||
|
||||
otInstance *sInstance;
|
||||
static otInstance *sInstance = NULL;
|
||||
|
||||
void ClkInit(void)
|
||||
{
|
||||
@@ -80,19 +79,11 @@ void ClkInit(void)
|
||||
|
||||
hw_watchdog_freeze(); // Stop watchdog
|
||||
hw_cpm_set_recharge_period((uint16_t)dg_configSET_RECHARGE_PERIOD);
|
||||
hw_watchdog_unfreeze(); // Start watchdog
|
||||
hw_cpm_pll_sys_on(); // Turn on PLL
|
||||
hw_watchdog_freeze(); // Stop watchdog
|
||||
|
||||
hw_qspi_set_div(HW_QSPI_DIV_2); // Set QSPI div by 2
|
||||
|
||||
hw_cpm_disable_pll_divider(); // Disable divider (div by 2)
|
||||
hw_cpm_set_sysclk(SYS_CLK_IS_PLL);
|
||||
hw_cpm_set_hclk_div(ahb_div2);
|
||||
hw_cpm_set_sysclk(SYS_CLK_IS_XTAL16M);
|
||||
hw_cpm_set_hclk_div(0);
|
||||
hw_cpm_set_pclk_div(0);
|
||||
|
||||
hw_otpc_init();
|
||||
hw_otpc_set_speed(HW_OTPC_SYS_CLK_FREQ_48);
|
||||
hw_otpc_set_speed(HW_OTPC_SYS_CLK_FREQ_16);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -163,7 +154,6 @@ void ExampleProcess(otInstance *aInstance)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PlatformInit(int argc, char *argv[])
|
||||
{
|
||||
// Initialize System Clock
|
||||
@@ -181,10 +171,151 @@ void PlatformInit(int argc, char *argv[])
|
||||
(void)argv;
|
||||
}
|
||||
|
||||
static sys_clk_t ClkGet(void)
|
||||
{
|
||||
sys_clk_t clk = sysclk_RC16;
|
||||
uint32_t hw_clk = hw_cpm_get_sysclk();
|
||||
|
||||
switch (hw_clk)
|
||||
{
|
||||
case SYS_CLK_IS_RC16:
|
||||
clk = sysclk_RC16;
|
||||
break;
|
||||
|
||||
case SYS_CLK_IS_XTAL16M:
|
||||
if (dg_configEXT_CRYSTAL_FREQ == EXT_CRYSTAL_IS_16M)
|
||||
{
|
||||
clk = sysclk_XTAL16M;
|
||||
}
|
||||
else
|
||||
{
|
||||
clk = sysclk_XTAL32M;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SYS_CLK_IS_PLL:
|
||||
if (hw_cpm_get_pll_divider_status() == 1)
|
||||
{
|
||||
clk = sysclk_PLL48;
|
||||
}
|
||||
else
|
||||
{
|
||||
clk = sysclk_PLL96;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SYS_CLK_IS_LP:
|
||||
|
||||
// fall-through
|
||||
|
||||
default:
|
||||
ASSERT_WARNING(0);
|
||||
break;
|
||||
}
|
||||
|
||||
return clk;
|
||||
}
|
||||
|
||||
static void ClkSet(sys_clk_t clock)
|
||||
{
|
||||
switch (clock)
|
||||
{
|
||||
case sysclk_XTAL16M:
|
||||
if (!hw_cpm_check_xtal16m_status()) // XTAL16M disabled
|
||||
{
|
||||
hw_cpm_enable_xtal16m(); // Enable XTAL16M
|
||||
}
|
||||
|
||||
hw_cpm_set_sysclk(SYS_CLK_IS_XTAL16M); // Set XTAL16 as sys_clk
|
||||
hw_watchdog_unfreeze(); // Start watchdog
|
||||
|
||||
while (!hw_cpm_is_xtal16m_started()); // Block until XTAL16M starts
|
||||
|
||||
hw_qspi_set_div(HW_QSPI_DIV_1);
|
||||
hw_watchdog_freeze(); // Stop watchdog
|
||||
hw_cpm_set_hclk_div(0);
|
||||
hw_cpm_set_pclk_div(0);
|
||||
break;
|
||||
|
||||
case sysclk_PLL48:
|
||||
if (hw_cpm_is_pll_locked() == 0)
|
||||
{
|
||||
hw_watchdog_unfreeze(); // Start watchdog
|
||||
hw_cpm_pll_sys_on(); // Turn on PLL
|
||||
hw_watchdog_freeze(); // Stop watchdog
|
||||
}
|
||||
|
||||
hw_cpm_enable_pll_divider(); // Enable divider (div by 2)
|
||||
hw_qspi_set_div(HW_QSPI_DIV_1);
|
||||
hw_cpm_set_sysclk(SYS_CLK_IS_PLL);
|
||||
hw_cpm_set_hclk_div(0);
|
||||
hw_cpm_set_pclk_div(0);
|
||||
break;
|
||||
|
||||
case sysclk_PLL96:
|
||||
if (hw_cpm_is_pll_locked() == 0)
|
||||
{
|
||||
hw_watchdog_unfreeze(); // Start watchdog
|
||||
hw_cpm_pll_sys_on(); // Turn on PLL
|
||||
hw_watchdog_freeze(); // Stop watchdog
|
||||
}
|
||||
|
||||
hw_cpm_disable_pll_divider(); // Disable divider (div by 1)
|
||||
hw_qspi_set_div(HW_QSPI_DIV_2);
|
||||
hw_cpm_set_sysclk(SYS_CLK_IS_PLL);
|
||||
hw_cpm_set_hclk_div(0);
|
||||
hw_cpm_set_pclk_div(0);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void ClkChange(sys_clk_t lastClock, sys_clk_t newClock)
|
||||
{
|
||||
if (ClkGet() == lastClock)
|
||||
{
|
||||
ClkSet(newClock);
|
||||
}
|
||||
}
|
||||
|
||||
void StateChangedCallback(uint32_t aFlags, void *aContext)
|
||||
{
|
||||
if ((aFlags & OT_CHANGED_COMMISSIONER_STATE) != 0)
|
||||
{
|
||||
if (otCommissionerGetState(sInstance) == OT_COMMISSIONER_STATE_ACTIVE)
|
||||
{
|
||||
ClkChange(sysclk_XTAL16M, sysclk_PLL96);
|
||||
}
|
||||
else
|
||||
{
|
||||
ClkChange(sysclk_PLL96, sysclk_XTAL16M);
|
||||
}
|
||||
}
|
||||
|
||||
if ((aFlags & OT_CHANGED_JOINER_STATE) != 0)
|
||||
{
|
||||
if (otJoinerGetState(sInstance) != OT_JOINER_STATE_IDLE)
|
||||
{
|
||||
ClkChange(sysclk_XTAL16M, sysclk_PLL96);
|
||||
}
|
||||
else
|
||||
{
|
||||
ClkChange(sysclk_PLL96, sysclk_XTAL16M);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PlatformProcessDrivers(otInstance *aInstance)
|
||||
{
|
||||
sInstance = aInstance;
|
||||
if (sInstance == NULL)
|
||||
{
|
||||
sInstance = aInstance;
|
||||
otSetStateChangedCallback(aInstance, StateChangedCallback, 0);
|
||||
}
|
||||
|
||||
da15000UartProcess();
|
||||
da15000RadioProcess(aInstance);
|
||||
|
||||
@@ -50,7 +50,7 @@ otError otPlatUartEnable(void)
|
||||
otError error = OT_ERROR_NONE;
|
||||
uart_config uart_init =
|
||||
{
|
||||
.baud_rate = HW_UART_BAUDRATE_115200,
|
||||
.baud_rate = HW_UART_BAUDRATE_57600,
|
||||
.data = HW_UART_DATABITS_8,
|
||||
.stop = HW_UART_STOPBITS_1,
|
||||
.parity = HW_UART_PARITY_NONE,
|
||||
|
||||
@@ -52,6 +52,20 @@ extern "C" {
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This enumeration defines the Joiner State.
|
||||
*
|
||||
*/
|
||||
typedef enum otJoinerState
|
||||
{
|
||||
OT_JOINER_STATE_IDLE = 0,
|
||||
OT_JOINER_STATE_DISCOVER = 1,
|
||||
OT_JOINER_STATE_CONNECT = 2,
|
||||
OT_JOINER_STATE_CONNECTED = 3,
|
||||
OT_JOINER_STATE_ENTRUST = 4,
|
||||
OT_JOINER_STATE_JOINED = 5,
|
||||
} otJoinerState;
|
||||
|
||||
/**
|
||||
* This function pointer is called to notify the completion of a join operation.
|
||||
*
|
||||
@@ -94,6 +108,21 @@ OTAPI otError OTCALL otJoinerStart(otInstance *aInstance, const char *aPSKd, con
|
||||
*/
|
||||
OTAPI otError OTCALL otJoinerStop(otInstance *aInstance);
|
||||
|
||||
/**
|
||||
* This function returns the Joiner State.
|
||||
*
|
||||
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||
*
|
||||
* @retval OT_JOINER_STATE_IDLE
|
||||
* @retval OT_JOINER_STATE_DISCOVER
|
||||
* @retval OT_JOINER_STATE_CONNECT
|
||||
* @retval OT_JOINER_STATE_CONNECTED
|
||||
* @retval OT_JOINER_STATE_ENTRUST
|
||||
* @retval OT_JOINER_STATE_JOINED
|
||||
*
|
||||
*/
|
||||
OTAPI otJoinerState OTCALL otJoinerGetState(otInstance *aInstance);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*
|
||||
|
||||
@@ -685,6 +685,8 @@ enum
|
||||
OT_CHANGED_THREAD_CHILD_REMOVED = 1 << 11, ///< Child was removed
|
||||
OT_CHANGED_IP6_MULTICAST_SUBSRCRIBED = 1 << 12, ///< Subscribed to a IPv6 multicast address
|
||||
OT_CHANGED_IP6_MULTICAST_UNSUBSRCRIBED = 1 << 13, ///< Unsubscribed from a IPv6 multicast address
|
||||
OT_CHANGED_COMMISSIONER_STATE = 1 << 14, ///< Commissioner state changed
|
||||
OT_CHANGED_JOINER_STATE = 1 << 15, ///< Joiner state changed
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -39,84 +39,214 @@
|
||||
|
||||
using namespace ot;
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER
|
||||
|
||||
otError otCommissionerStart(otInstance *aInstance)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetCommissioner().Start();
|
||||
otError error = OT_ERROR_DISABLED_FEATURE;
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER
|
||||
error = aInstance->mThreadNetif.GetCommissioner().Start();
|
||||
#else // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
#endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otCommissionerStop(otInstance *aInstance)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetCommissioner().Stop();
|
||||
otError error = OT_ERROR_DISABLED_FEATURE;
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER
|
||||
error = aInstance->mThreadNetif.GetCommissioner().Stop();
|
||||
#else // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
#endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otCommissionerAddJoiner(otInstance *aInstance, const otExtAddress *aExtAddress, const char *aPSKd,
|
||||
uint32_t aTimeout)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetCommissioner().AddJoiner(static_cast<const Mac::ExtAddress *>(aExtAddress), aPSKd,
|
||||
aTimeout);
|
||||
otError error = OT_ERROR_DISABLED_FEATURE;
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER
|
||||
error = aInstance->mThreadNetif.GetCommissioner().AddJoiner(static_cast<const Mac::ExtAddress *>(aExtAddress), aPSKd,
|
||||
aTimeout);
|
||||
#else // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
OT_UNUSED_VARIABLE(aExtAddress);
|
||||
OT_UNUSED_VARIABLE(aPSKd);
|
||||
OT_UNUSED_VARIABLE(aTimeout);
|
||||
#endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otCommissionerRemoveJoiner(otInstance *aInstance, const otExtAddress *aExtAddress)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetCommissioner().RemoveJoiner(static_cast<const Mac::ExtAddress *>(aExtAddress), 0);
|
||||
otError error = OT_ERROR_DISABLED_FEATURE;
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER
|
||||
error = aInstance->mThreadNetif.GetCommissioner().RemoveJoiner(static_cast<const Mac::ExtAddress *>(aExtAddress), 0);
|
||||
#else // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
OT_UNUSED_VARIABLE(aExtAddress);
|
||||
#endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otCommissionerSetProvisioningUrl(otInstance *aInstance, const char *aProvisioningUrl)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetCommissioner().SetProvisioningUrl(aProvisioningUrl);
|
||||
otError error = OT_ERROR_DISABLED_FEATURE;
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER
|
||||
error = aInstance->mThreadNetif.GetCommissioner().SetProvisioningUrl(aProvisioningUrl);
|
||||
#else // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
OT_UNUSED_VARIABLE(aProvisioningUrl);
|
||||
#endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otCommissionerAnnounceBegin(otInstance *aInstance, uint32_t aChannelMask, uint8_t aCount, uint16_t aPeriod,
|
||||
const otIp6Address *aAddress)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetCommissioner().mAnnounceBegin.SendRequest(aChannelMask, aCount, aPeriod,
|
||||
*static_cast<const Ip6::Address *>(aAddress));
|
||||
otError error = OT_ERROR_DISABLED_FEATURE;
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER
|
||||
error = aInstance->mThreadNetif.GetCommissioner().mAnnounceBegin.SendRequest(aChannelMask, aCount, aPeriod,
|
||||
*static_cast<const Ip6::Address *>(aAddress));
|
||||
#else // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
OT_UNUSED_VARIABLE(aChannelMask);
|
||||
OT_UNUSED_VARIABLE(aCount);
|
||||
OT_UNUSED_VARIABLE(aPeriod);
|
||||
OT_UNUSED_VARIABLE(aAddress);
|
||||
#endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otCommissionerEnergyScan(otInstance *aInstance, uint32_t aChannelMask, uint8_t aCount, uint16_t aPeriod,
|
||||
uint16_t aScanDuration, const otIp6Address *aAddress,
|
||||
otCommissionerEnergyReportCallback aCallback, void *aContext)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetCommissioner().mEnergyScan.SendQuery(aChannelMask, aCount, aPeriod, aScanDuration,
|
||||
*static_cast<const Ip6::Address *>(aAddress),
|
||||
aCallback, aContext);
|
||||
otError error = OT_ERROR_DISABLED_FEATURE;
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER
|
||||
error = aInstance->mThreadNetif.GetCommissioner().mEnergyScan.SendQuery(aChannelMask, aCount, aPeriod, aScanDuration,
|
||||
*static_cast<const Ip6::Address *>(aAddress),
|
||||
aCallback, aContext);
|
||||
#else // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
OT_UNUSED_VARIABLE(aChannelMask);
|
||||
OT_UNUSED_VARIABLE(aCount);
|
||||
OT_UNUSED_VARIABLE(aPeriod);
|
||||
OT_UNUSED_VARIABLE(aScanDuration);
|
||||
OT_UNUSED_VARIABLE(aAddress);
|
||||
OT_UNUSED_VARIABLE(aCallback);
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
#endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otCommissionerPanIdQuery(otInstance *aInstance, uint16_t aPanId, uint32_t aChannelMask,
|
||||
const otIp6Address *aAddress,
|
||||
otCommissionerPanIdConflictCallback aCallback, void *aContext)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetCommissioner().mPanIdQuery.SendQuery(
|
||||
aPanId, aChannelMask, *static_cast<const Ip6::Address *>(aAddress), aCallback, aContext);
|
||||
otError error = OT_ERROR_DISABLED_FEATURE;
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER
|
||||
error = aInstance->mThreadNetif.GetCommissioner().mPanIdQuery.SendQuery(
|
||||
aPanId, aChannelMask, *static_cast<const Ip6::Address *>(aAddress), aCallback, aContext);
|
||||
#else // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
OT_UNUSED_VARIABLE(aPanId);
|
||||
OT_UNUSED_VARIABLE(aChannelMask);
|
||||
OT_UNUSED_VARIABLE(aAddress);
|
||||
OT_UNUSED_VARIABLE(aCallback);
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
#endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otCommissionerSendMgmtGet(otInstance *aInstance, const uint8_t *aTlvs, uint8_t aLength)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetCommissioner().SendMgmtCommissionerGetRequest(aTlvs, aLength);
|
||||
otError error = OT_ERROR_DISABLED_FEATURE;
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER
|
||||
error = aInstance->mThreadNetif.GetCommissioner().SendMgmtCommissionerGetRequest(aTlvs, aLength);
|
||||
#else // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
OT_UNUSED_VARIABLE(aTlvs);
|
||||
OT_UNUSED_VARIABLE(aLength);
|
||||
#endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otCommissionerSendMgmtSet(otInstance *aInstance, const otCommissioningDataset *aDataset,
|
||||
const uint8_t *aTlvs, uint8_t aLength)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetCommissioner().SendMgmtCommissionerSetRequest(*aDataset, aTlvs, aLength);
|
||||
otError error = OT_ERROR_DISABLED_FEATURE;
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER
|
||||
error = aInstance->mThreadNetif.GetCommissioner().SendMgmtCommissionerSetRequest(*aDataset, aTlvs, aLength);
|
||||
#else // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
OT_UNUSED_VARIABLE(aDataset);
|
||||
OT_UNUSED_VARIABLE(aTlvs);
|
||||
OT_UNUSED_VARIABLE(aLength);
|
||||
#endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
uint16_t otCommissionerGetSessionId(otInstance *aInstance)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetCommissioner().GetSessionId();
|
||||
uint16_t sessionId = 0;
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER
|
||||
sessionId = aInstance->mThreadNetif.GetCommissioner().GetSessionId();
|
||||
#else // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
#endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
|
||||
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
otCommissionerState otCommissionerGetState(otInstance *aInstance)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetCommissioner().GetState();
|
||||
otCommissionerState state = OT_COMMISSIONER_STATE_DISABLED;
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER
|
||||
state = aInstance->mThreadNetif.GetCommissioner().GetState();
|
||||
#else // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
#endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
otError otCommissionerGeneratePSKc(otInstance *aInstance, const char *aPassPhrase, const char *aNetworkName,
|
||||
const uint8_t *aExtPanId, uint8_t *aPSKc)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetCommissioner().GeneratePSKc(aPassPhrase, aNetworkName, aExtPanId, aPSKc);
|
||||
}
|
||||
otError error = OT_ERROR_DISABLED_FEATURE;
|
||||
|
||||
#endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER
|
||||
error = aInstance->mThreadNetif.GetCommissioner().GeneratePSKc(aPassPhrase, aNetworkName, aExtPanId, aPSKc);
|
||||
#else // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
OT_UNUSED_VARIABLE(aPassPhrase);
|
||||
OT_UNUSED_VARIABLE(aNetworkName);
|
||||
OT_UNUSED_VARIABLE(aExtPanId);
|
||||
OT_UNUSED_VARIABLE(aPSKc);
|
||||
#endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
@@ -39,21 +39,54 @@
|
||||
|
||||
using namespace ot;
|
||||
|
||||
#if OPENTHREAD_ENABLE_JOINER
|
||||
|
||||
otError otJoinerStart(otInstance *aInstance, const char *aPSKd, const char *aProvisioningUrl,
|
||||
const char *aVendorName, const char *aVendorModel,
|
||||
const char *aVendorSwVersion, const char *aVendorData,
|
||||
otJoinerCallback aCallback, void *aContext)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetJoiner().Start(aPSKd, aProvisioningUrl,
|
||||
aVendorName, aVendorModel, aVendorSwVersion, aVendorData,
|
||||
aCallback, aContext);
|
||||
otError error = OT_ERROR_DISABLED_FEATURE;
|
||||
|
||||
#if OPENTHREAD_ENABLE_JOINER
|
||||
error = aInstance->mThreadNetif.GetJoiner().Start(aPSKd, aProvisioningUrl,
|
||||
aVendorName, aVendorModel, aVendorSwVersion, aVendorData,
|
||||
aCallback, aContext);
|
||||
#else // OPENTHREAD_ENABLE_JOINER
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
OT_UNUSED_VARIABLE(aPSKd);
|
||||
OT_UNUSED_VARIABLE(aProvisioningUrl);
|
||||
OT_UNUSED_VARIABLE(aVendorName);
|
||||
OT_UNUSED_VARIABLE(aVendorModel);
|
||||
OT_UNUSED_VARIABLE(aVendorSwVersion);
|
||||
OT_UNUSED_VARIABLE(aVendorData);
|
||||
OT_UNUSED_VARIABLE(aCallback);
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
#endif // OPENTHREAD_ENABLE_JOINER
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otJoinerStop(otInstance *aInstance)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetJoiner().Stop();
|
||||
otError error = OT_ERROR_DISABLED_FEATURE;
|
||||
|
||||
#if OPENTHREAD_ENABLE_JOINER
|
||||
error = aInstance->mThreadNetif.GetJoiner().Stop();
|
||||
#else // OPENTHREAD_ENABLE_JOINER
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
#endif // OPENTHREAD_ENABLE_JOINER
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
#endif // OPENTHREAD_ENABLE_JOINER
|
||||
otJoinerState otJoinerGetState(otInstance *aInstance)
|
||||
{
|
||||
otJoinerState state = OT_JOINER_STATE_IDLE;
|
||||
|
||||
#if OPENTHREAD_ENABLE_JOINER
|
||||
state = aInstance->mThreadNetif.GetJoiner().GetState();
|
||||
#else // OPENTHREAD_ENABLE_JOINER
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
#endif // OPENTHREAD_ENABLE_JOINER
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -128,6 +128,7 @@ otError Commissioner::Stop(void)
|
||||
GetNetif().GetCoapSecure().Stop();
|
||||
|
||||
mState = OT_COMMISSIONER_STATE_DISABLED;
|
||||
GetNetif().SetStateChangedFlags(OT_CHANGED_COMMISSIONER_STATE);
|
||||
RemoveCoapResources();
|
||||
mTransmitAttempts = 0;
|
||||
|
||||
@@ -671,6 +672,8 @@ exit:
|
||||
}
|
||||
}
|
||||
|
||||
GetNetif().SetStateChangedFlags(OT_CHANGED_COMMISSIONER_STATE);
|
||||
|
||||
otLogFuncExit();
|
||||
}
|
||||
|
||||
|
||||
+25
-17
@@ -62,7 +62,7 @@ namespace MeshCoP {
|
||||
|
||||
Joiner::Joiner(ThreadNetif &aNetif):
|
||||
ThreadNetifLocator(aNetif),
|
||||
mState(kStateIdle),
|
||||
mState(OT_JOINER_STATE_IDLE),
|
||||
mCallback(NULL),
|
||||
mContext(NULL),
|
||||
mCcitt(0),
|
||||
@@ -94,7 +94,9 @@ otError Joiner::Start(const char *aPSKd, const char *aProvisioningUrl,
|
||||
|
||||
otLogFuncEntry();
|
||||
|
||||
VerifyOrExit(mState == kStateIdle, error = OT_ERROR_BUSY);
|
||||
VerifyOrExit(mState == OT_JOINER_STATE_IDLE, error = OT_ERROR_BUSY);
|
||||
|
||||
GetNetif().SetStateChangedFlags(OT_CHANGED_JOINER_STATE);
|
||||
|
||||
// use extended address based on factory-assigned IEEE EUI-64
|
||||
netif.GetMac().GetHashMacAddress(&extAddress);
|
||||
@@ -132,7 +134,7 @@ otError Joiner::Start(const char *aPSKd, const char *aProvisioningUrl,
|
||||
mVendorData = aVendorData;
|
||||
mCallback = aCallback;
|
||||
mContext = aContext;
|
||||
mState = kStateDiscover;
|
||||
mState = OT_JOINER_STATE_DISCOVER;
|
||||
|
||||
exit:
|
||||
otLogFuncExitErr(error);
|
||||
@@ -149,6 +151,11 @@ otError Joiner::Stop(void)
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otJoinerState Joiner::GetState(void) const
|
||||
{
|
||||
return mState;
|
||||
}
|
||||
|
||||
void Joiner::Close(void)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
@@ -162,7 +169,8 @@ void Joiner::Close(void)
|
||||
|
||||
void Joiner::Complete(otError aError)
|
||||
{
|
||||
mState = kStateIdle;
|
||||
mState = OT_JOINER_STATE_IDLE;
|
||||
GetNetif().SetStateChangedFlags(OT_CHANGED_JOINER_STATE);
|
||||
|
||||
GetNetif().GetCoapSecure().Stop();
|
||||
|
||||
@@ -242,7 +250,7 @@ void Joiner::HandleDiscoverResult(otActiveScanResult *aResult)
|
||||
messageInfo.mInterfaceId = OT_NETIF_INTERFACE_ID_THREAD;
|
||||
|
||||
netif.GetCoapSecure().Connect(messageInfo, Joiner::HandleSecureCoapClientConnect, this);
|
||||
mState = kStateConnect;
|
||||
mState = OT_JOINER_STATE_CONNECT;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -263,10 +271,10 @@ void Joiner::HandleSecureCoapClientConnect(bool aConnected)
|
||||
{
|
||||
switch (mState)
|
||||
{
|
||||
case kStateConnect:
|
||||
case OT_JOINER_STATE_CONNECT:
|
||||
if (aConnected)
|
||||
{
|
||||
mState = kStateConnected;
|
||||
mState = OT_JOINER_STATE_CONNECTED;
|
||||
SendJoinerFinalize();
|
||||
mTimer.Start(kTimeout);
|
||||
}
|
||||
@@ -377,7 +385,7 @@ void Joiner::HandleJoinerFinalizeResponse(Coap::Header *aHeader, Message *aMessa
|
||||
|
||||
otLogFuncEntry();
|
||||
|
||||
VerifyOrExit(mState == kStateConnected &&
|
||||
VerifyOrExit(mState == OT_JOINER_STATE_CONNECTED &&
|
||||
aResult == OT_ERROR_NONE &&
|
||||
aHeader->GetType() == OT_COAP_TYPE_ACKNOWLEDGMENT &&
|
||||
aHeader->GetCode() == OT_COAP_CODE_CHANGED);
|
||||
@@ -385,7 +393,7 @@ void Joiner::HandleJoinerFinalizeResponse(Coap::Header *aHeader, Message *aMessa
|
||||
SuccessOrExit(Tlv::GetTlv(*aMessage, Tlv::kState, sizeof(state), state));
|
||||
VerifyOrExit(state.IsValid());
|
||||
|
||||
mState = kStateEntrust;
|
||||
mState = OT_JOINER_STATE_ENTRUST;
|
||||
mTimer.Start(kTimeout);
|
||||
|
||||
otLogInfoMeshCoP(GetInstance(), "received joiner finalize response %d", static_cast<uint8_t>(state.GetState()));
|
||||
@@ -423,7 +431,7 @@ void Joiner::HandleJoinerEntrust(Coap::Header &aHeader, Message &aMessage, const
|
||||
|
||||
otLogFuncEntry();
|
||||
|
||||
VerifyOrExit(mState == kStateEntrust &&
|
||||
VerifyOrExit(mState == OT_JOINER_STATE_ENTRUST &&
|
||||
aHeader.GetType() == OT_COAP_TYPE_CONFIRMABLE &&
|
||||
aHeader.GetCode() == OT_COAP_CODE_POST, error = OT_ERROR_DROP);
|
||||
|
||||
@@ -498,7 +506,7 @@ void Joiner::SendJoinerEntrustResponse(const Coap::Header &aRequestHeader,
|
||||
memset(&responseInfo.mSockAddr, 0, sizeof(responseInfo.mSockAddr));
|
||||
SuccessOrExit(error = netif.GetCoap().SendMessage(*message, responseInfo));
|
||||
|
||||
mState = kStateJoined;
|
||||
mState = OT_JOINER_STATE_JOINED;
|
||||
|
||||
otLogInfoArp(GetInstance(), "Sent Joiner Entrust response");
|
||||
|
||||
@@ -527,18 +535,18 @@ void Joiner::HandleTimer(void)
|
||||
|
||||
switch (mState)
|
||||
{
|
||||
case kStateIdle:
|
||||
case kStateDiscover:
|
||||
case kStateConnect:
|
||||
case OT_JOINER_STATE_IDLE:
|
||||
case OT_JOINER_STATE_DISCOVER:
|
||||
case OT_JOINER_STATE_CONNECT:
|
||||
assert(false);
|
||||
break;
|
||||
|
||||
case kStateConnected:
|
||||
case kStateEntrust:
|
||||
case OT_JOINER_STATE_CONNECTED:
|
||||
case OT_JOINER_STATE_ENTRUST:
|
||||
error = OT_ERROR_RESPONSE_TIMEOUT;
|
||||
break;
|
||||
|
||||
case kStateJoined:
|
||||
case OT_JOINER_STATE_JOINED:
|
||||
Mac::ExtAddress extAddress;
|
||||
|
||||
netif.GetMac().GenerateExtAddress(&extAddress);
|
||||
|
||||
+16
-10
@@ -91,6 +91,21 @@ public:
|
||||
*/
|
||||
otError Stop(void);
|
||||
|
||||
/**
|
||||
* This function returns the Joiner State.
|
||||
*
|
||||
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||
*
|
||||
* @retval OT_JOINER_STATE_IDLE
|
||||
* @retval OT_JOINER_STATE_DISCOVER
|
||||
* @retval OT_JOINER_STATE_CONNECT
|
||||
* @retval OT_JOINER_STATE_CONNECTED
|
||||
* @retval OT_JOINER_STATE_ENTRUST
|
||||
* @retval OT_JOINER_STATE_JOINED
|
||||
*
|
||||
*/
|
||||
otJoinerState GetState(void) const;
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
@@ -123,16 +138,7 @@ private:
|
||||
|
||||
static Joiner &GetOwner(const Context &aContext);
|
||||
|
||||
enum State
|
||||
{
|
||||
kStateIdle = 0,
|
||||
kStateDiscover = 1,
|
||||
kStateConnect = 2,
|
||||
kStateConnected = 3,
|
||||
kStateEntrust = 4,
|
||||
kStateJoined = 5,
|
||||
};
|
||||
State mState;
|
||||
otJoinerState mState;
|
||||
|
||||
otJoinerCallback mCallback;
|
||||
void *mContext;
|
||||
|
||||
Reference in New Issue
Block a user