mirror of
https://github.com/espressif/openthread.git
synced 2026-08-10 12:47:47 +00:00
[instance] single OpenThread instance optimizations (#1926)
This commit new configuration option `enable-multiple-instances` and its corresponding option `OPENTHREAD_ENABLE_MULTIPLE_INSTANCES`. When enabled OpenThread supports handling of multiple instances. By default this is disabled. This commit also adds two optimizations for single instance case to simplify the code and also help reduce memory/RAM usage: (1) OpenThread objects/classes typically keep a reference to a higher level object (e.g., many classes keep track of owning `ThreadNetif`) to be able to access other objects/methods within OpenThread class hierarchy. In single instance mode, the reference member variables are removed and instead global functions are used to access the singleton objects from one class to the other. To implement this, a group of `<Object>Locator` classes are defined (e.g., `ThreadNetifLocator`, etc.) which are then used as base class of other OpenThread classes. (2) OpenThread objects which provide a callback/handler (e.g., `Timer`, `Tasklet`, etc.) have `void *mContext` member variable which is used to keep track of the owner of the object. In single instance mode the `mConext` member variables are removed since the owner is expected to be a singleton and can be uniquely determined from the callback function. To implement this, two changes are made: First the handler methods are modified to provide a reference to the object (e.g., `Timer` handler will provide a `Timer &aTimer` as a parameter of its handler callback). Second, a new base class `Context` is introduced which hides the implementation providing an arbitrary context information. A new static method `GetOwner(aContext)` is added to classes which own a callback providing objects. This method help convert a `Context` to the reference of the owner class object.
This commit is contained in:
committed by
Jonathan Hui
parent
5128602b49
commit
bbab3074ed
@@ -506,6 +506,37 @@ AC_DEFINE_UNQUOTED([OPENTHREAD_ENABLE_NCP_UART],[${OPENTHREAD_ENABLE_NCP_UART}],
|
||||
AC_MSG_CHECKING([sould NCP support UART])
|
||||
AC_MSG_RESULT([${OPENTHREAD_ENABLE_UART}])
|
||||
|
||||
#
|
||||
# Multiple OpenThread Instances
|
||||
#
|
||||
|
||||
AC_ARG_ENABLE(multiple-instances,
|
||||
[AS_HELP_STRING([--enable-multiple-instances],[Enable support for multiple OpenThread instances @<:@default=no@:>@.])],
|
||||
[
|
||||
case "${enableval}" in
|
||||
|
||||
no|yes)
|
||||
enable_multiple_instances=${enableval}
|
||||
;;
|
||||
|
||||
*)
|
||||
AC_MSG_ERROR([Invalid value ${enable_multiple_instances} for --enable-multiple-instances])
|
||||
;;
|
||||
esac
|
||||
],
|
||||
[enable_multiple_instances=no])
|
||||
|
||||
if test "$enable_multiple_instances" = "yes"; then
|
||||
OPENTHREAD_ENABLE_MULTIPLE_INSTANCES=1
|
||||
else
|
||||
OPENTHREAD_ENABLE_MULTIPLE_INSTANCES=0
|
||||
fi
|
||||
|
||||
AC_MSG_RESULT(${enable_multiple_instances})
|
||||
AC_SUBST(OPENTHREAD_ENABLE_MULTIPLE_INSTANCES)
|
||||
AM_CONDITIONAL([OPENTHREAD_ENABLE_MULTIPLE_INSTANCES], [test "${enable_multiple_instances}" = "yes"])
|
||||
AC_DEFINE_UNQUOTED([OPENTHREAD_ENABLE_MULTIPLE_INSTANCES],[${OPENTHREAD_ENABLE_MULTIPLE_INSTANCES}],[Define to 1 if you want to enable support for multiple OpenThread instances.])
|
||||
|
||||
#
|
||||
# Builtin mbedtls
|
||||
#
|
||||
@@ -1382,6 +1413,7 @@ AC_MSG_NOTICE([
|
||||
OpenThread NCP-MTD support : ${enable_ncp_app_mtd}
|
||||
OpenThread NCP-FTD support : ${enable_ncp_app_ftd}
|
||||
OpenThread NCP-BUS Configuration : ${with_ncp_bus}
|
||||
OpenThread Multiple Instances support : ${enable_multiple_instances}
|
||||
OpenThread MTD Network Diagnostic support : ${enable_mtd_network_diagnostic}
|
||||
OpenThread builtin mbedtls support : ${enable_builtin_mbedtls}
|
||||
OpenThread TMF Proxy support : ${enable_tmf_proxy}
|
||||
|
||||
@@ -49,7 +49,6 @@
|
||||
%(PreprocessorDefinitions)
|
||||
MBEDTLS_CONFIG_FILE="mbedtls-config.h";
|
||||
OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";
|
||||
OPENTHREAD_MULTIPLE_INSTANCE;
|
||||
OPENTHREAD_FTD=1;
|
||||
</PreprocessorDefinitions>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="openthread.configuration.props" />
|
||||
<Import Project="openthread.configuration.props" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{41B32069-632E-4578-855B-A36EBFA80B56}</ProjectGuid>
|
||||
<Keyword>StaticLibrary</Keyword>
|
||||
@@ -40,7 +40,6 @@
|
||||
%(PreprocessorDefinitions);
|
||||
MBEDTLS_CONFIG_FILE="mbedtls-config.h";
|
||||
OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";
|
||||
OPENTHREAD_MULTIPLE_INSTANCE;
|
||||
OPENTHREAD_FTD=1;
|
||||
OTBUILD;
|
||||
</PreprocessorDefinitions>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="openthread.configuration.props" />
|
||||
<Import Project="openthread.configuration.props" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{B92F449E-0FD9-44FC-ACFA-6521A3240CA2}</ProjectGuid>
|
||||
<Keyword>StaticLibrary</Keyword>
|
||||
@@ -40,7 +40,6 @@
|
||||
%(PreprocessorDefinitions);
|
||||
MBEDTLS_CONFIG_FILE="mbedtls-config.h";
|
||||
OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";
|
||||
OPENTHREAD_MULTIPLE_INSTANCE;
|
||||
OPENTHREAD_FTD=1;
|
||||
OPENTHREAD_ENABLE_NCP_SPI=1;
|
||||
OPENTHREAD_ENABLE_NCP_UART=0;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="openthread.configuration.props" />
|
||||
<Import Project="openthread.configuration.props" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{D94867D2-6DAE-47E2-962A-5E8E658134D1}</ProjectGuid>
|
||||
<Keyword>StaticLibrary</Keyword>
|
||||
@@ -40,7 +40,6 @@
|
||||
%(PreprocessorDefinitions);
|
||||
MBEDTLS_CONFIG_FILE="mbedtls-config.h";
|
||||
OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";
|
||||
OPENTHREAD_MULTIPLE_INSTANCE;
|
||||
OPENTHREAD_FTD=1;
|
||||
OPENTHREAD_ENABLE_NCP_SPI=0;
|
||||
OPENTHREAD_ENABLE_NCP_UART=1;
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
%(PreprocessorDefinitions);
|
||||
MBEDTLS_CONFIG_FILE="mbedtls-config.h";
|
||||
OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";
|
||||
OPENTHREAD_MULTIPLE_INSTANCE;
|
||||
OPENTHREAD_FTD=1;
|
||||
OTBUILD;
|
||||
</PreprocessorDefinitions>
|
||||
@@ -77,6 +76,7 @@
|
||||
<ClCompile Include="..\..\src\core\coap\coap_header.cpp" />
|
||||
<ClCompile Include="..\..\src\core\coap\coap_secure.cpp" />
|
||||
<ClCompile Include="..\..\src\core\common\crc16.cpp" />
|
||||
<ClCompile Include="..\..\src\core\common\locator.cpp" />
|
||||
<ClCompile Include="..\..\src\core\common\logging.cpp" />
|
||||
<ClCompile Include="..\..\src\core\common\message.cpp" />
|
||||
<ClCompile Include="..\..\src\core\common\tasklet.cpp" />
|
||||
@@ -149,8 +149,10 @@
|
||||
<ClInclude Include="..\..\src\core\coap\coap_secure.hpp" />
|
||||
<ClInclude Include="..\..\src\core\common\code_utils.hpp" />
|
||||
<ClInclude Include="..\..\src\core\common\crc16.hpp" />
|
||||
<ClInclude Include="..\..\src\core\common\context.hpp" />
|
||||
<ClInclude Include="..\..\src\core\common\debug.hpp" />
|
||||
<ClInclude Include="..\..\src\core\common\encoding.hpp" />
|
||||
<ClInclude Include="..\..\src\core\common\locator.hpp" />
|
||||
<ClInclude Include="..\..\src\core\common\logging.hpp" />
|
||||
<ClInclude Include="..\..\src\core\common\message.hpp" />
|
||||
<ClInclude Include="..\..\src\core\common\new.hpp" />
|
||||
|
||||
@@ -126,6 +126,9 @@
|
||||
<ClCompile Include="..\..\src\core\coap\coap_secure.cpp">
|
||||
<Filter>Source Files\coap</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\core\common\locator.cpp">
|
||||
<Filter>Source Files\common</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\core\common\logging.cpp">
|
||||
<Filter>Source Files\common</Filter>
|
||||
</ClCompile>
|
||||
@@ -335,12 +338,18 @@
|
||||
<ClInclude Include="..\..\src\core\common\code_utils.hpp">
|
||||
<Filter>Header Files\common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\core\common\context.hpp">
|
||||
<Filter>Header Files\common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\core\common\debug.hpp">
|
||||
<Filter>Header Files\common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\core\common\encoding.hpp">
|
||||
<Filter>Header Files\common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\core\common\locator.hpp">
|
||||
<Filter>Header Files\common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\core\common\logging.hpp">
|
||||
<Filter>Header Files\common</Filter>
|
||||
</ClInclude>
|
||||
|
||||
@@ -42,7 +42,6 @@
|
||||
OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";
|
||||
OPENTHREAD_PROJECT_CORE_CONFIG_FILE="openthread-core-windows-config.h";
|
||||
WINDOWS_LOGGING;
|
||||
OPENTHREAD_MULTIPLE_INSTANCE;
|
||||
OPENTHREAD_FTD=1;
|
||||
HAVE_STDBOOL_H=1;
|
||||
HAVE_STDINT_H=1;
|
||||
@@ -86,6 +85,7 @@
|
||||
<ClCompile Include="..\..\src\core\coap\coap_header.cpp" />
|
||||
<ClCompile Include="..\..\src\core\coap\coap_secure.cpp" />
|
||||
<ClCompile Include="..\..\src\core\common\crc16.cpp" />
|
||||
<ClCompile Include="..\..\src\core\common\locator.cpp" />
|
||||
<ClCompile Include="..\..\src\core\common\logging.cpp" />
|
||||
<ClCompile Include="..\..\src\core\common\message.cpp" />
|
||||
<ClCompile Include="..\..\src\core\common\tasklet.cpp" />
|
||||
@@ -180,9 +180,11 @@
|
||||
<ClInclude Include="..\..\src\core\coap\coap_header.hpp" />
|
||||
<ClInclude Include="..\..\src\core\coap\coap_secure.hpp" />
|
||||
<ClInclude Include="..\..\src\core\common\code_utils.hpp" />
|
||||
<ClInclude Include="..\..\src\core\common\context.hpp" />
|
||||
<ClInclude Include="..\..\src\core\common\crc16.hpp" />
|
||||
<ClInclude Include="..\..\src\core\common\debug.hpp" />
|
||||
<ClInclude Include="..\..\src\core\common\encoding.hpp" />
|
||||
<ClInclude Include="..\..\src\core\common\locator.hpp" />
|
||||
<ClInclude Include="..\..\src\core\common\logging.hpp" />
|
||||
<ClInclude Include="..\..\src\core\common\message.hpp" />
|
||||
<ClInclude Include="..\..\src\core\common\new.hpp" />
|
||||
|
||||
@@ -126,6 +126,9 @@
|
||||
<ClCompile Include="..\..\src\core\coap\coap_secure.cpp">
|
||||
<Filter>Source Files\coap</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\core\common\locator.cpp">
|
||||
<Filter>Source Files\common</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\core\common\logging.cpp">
|
||||
<Filter>Source Files\common</Filter>
|
||||
</ClCompile>
|
||||
@@ -335,12 +338,18 @@
|
||||
<ClInclude Include="..\..\src\core\common\code_utils.hpp">
|
||||
<Filter>Header Files\common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\core\common\context.hpp">
|
||||
<Filter>Header Files\common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\core\common\debug.hpp">
|
||||
<Filter>Header Files\common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\core\common\encoding.hpp">
|
||||
<Filter>Header Files\common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\core\common\locator.hpp">
|
||||
<Filter>Header Files\common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\core\common\logging.hpp">
|
||||
<Filter>Header Files\common</Filter>
|
||||
</ClInclude>
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
<PreprocessorDefinitions>
|
||||
;%(PreprocessorDefinitions);
|
||||
MBEDTLS_CONFIG_FILE="mbedtls-config.h";
|
||||
OPENTHREAD_MULTIPLE_INSTANCE;
|
||||
OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";
|
||||
</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>
|
||||
..\..\include;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="openthread.configuration.props" />
|
||||
<Import Project="openthread.configuration.props" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{69BE8E8C-CF1E-46D6-932B-DB435F47059B}</ProjectGuid>
|
||||
<TemplateGuid>{8c0e3d8b-df43-455b-815a-4a0e72973bc6}</TemplateGuid>
|
||||
@@ -50,7 +50,6 @@
|
||||
OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";
|
||||
HAVE_STDBOOL_H=1;
|
||||
HAVE_STDINT_H=1;
|
||||
OPENTHREAD_MULTIPLE_INSTANCE;
|
||||
</PreprocessorDefinitions>
|
||||
<DisableSpecificWarnings>4132;4242;4245;4603;4627;4986;4987;4996;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="openthread.configuration.props" />
|
||||
<Import Project="openthread.configuration.props" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{91D3ADEA-F1FE-4433-95B6-F8F6A7CF7BAF}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
@@ -40,7 +40,6 @@
|
||||
%(PreprocessorDefinitions);
|
||||
OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";
|
||||
OPENTHREAD_FTD=1;
|
||||
OPENTHREAD_MULTIPLE_INSTANCE;
|
||||
</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>
|
||||
%(AdditionalIncludeDirectories);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="openthread.configuration.props" />
|
||||
<Import Project="openthread.configuration.props" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{B4C744EC-B662-46C6-A076-FB58FA8FDF1B}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
@@ -40,7 +40,6 @@
|
||||
%(PreprocessorDefinitions);
|
||||
OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";
|
||||
OPENTHREAD_FTD=1;
|
||||
OPENTHREAD_MULTIPLE_INSTANCE;
|
||||
OPENTHREAD_ENABLE_NCP_SPI=1;
|
||||
OPENTHREAD_ENABLE_NCP_UART=0;
|
||||
</PreprocessorDefinitions>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="openthread.configuration.props" />
|
||||
<Import Project="openthread.configuration.props" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{9EEF9DCD-EA8F-4154-BD02-AB2B31CEC324}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
@@ -40,7 +40,6 @@
|
||||
%(PreprocessorDefinitions);
|
||||
OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";
|
||||
OPENTHREAD_FTD=1;
|
||||
OPENTHREAD_MULTIPLE_INSTANCE;
|
||||
OPENTHREAD_ENABLE_NCP_SPI=0;
|
||||
OPENTHREAD_ENABLE_NCP_UART=1;
|
||||
</PreprocessorDefinitions>
|
||||
|
||||
@@ -43,7 +43,6 @@
|
||||
OPENTHREAD_FTD=1;
|
||||
OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";
|
||||
OPENTHREAD_PROJECT_CORE_CONFIG_FILE="openthread-core-windows-config.h";
|
||||
OPENTHREAD_MULTIPLE_INSTANCE;
|
||||
</PreProcessorDefinitions>
|
||||
<AdditionalIncludeDirectories>
|
||||
%(AdditionalIncludeDirectories);
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
#include <openthread/openthread.h>
|
||||
#include <openthread/platform/platform.h>
|
||||
|
||||
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
void *otPlatCAlloc(size_t aNum, size_t aSize)
|
||||
{
|
||||
return calloc(aNum, aSize);
|
||||
@@ -56,14 +56,14 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
otInstance *sInstance;
|
||||
|
||||
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
size_t otInstanceBufferLength = 0;
|
||||
uint8_t *otInstanceBuffer = NULL;
|
||||
#endif
|
||||
|
||||
PlatformInit(argc, argv);
|
||||
|
||||
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
// Call to query the buffer size
|
||||
(void)otInstanceInit(NULL, &otInstanceBufferLength);
|
||||
|
||||
@@ -74,7 +74,7 @@ int main(int argc, char *argv[])
|
||||
// Initialize OpenThread with the buffer
|
||||
sInstance = otInstanceInit(otInstanceBuffer, &otInstanceBufferLength);
|
||||
#else
|
||||
sInstance = otInstanceInit();
|
||||
sInstance = otInstanceInitSingle();
|
||||
#endif
|
||||
assert(sInstance);
|
||||
|
||||
@@ -91,7 +91,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
// otInstanceFinalize(sInstance);
|
||||
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
// free(otInstanceBuffer);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
#include <openthread/openthread.h>
|
||||
#include <openthread/platform/platform.h>
|
||||
|
||||
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
void *otPlatCAlloc(size_t aNum, size_t aSize)
|
||||
{
|
||||
return calloc(aNum, aSize);
|
||||
@@ -56,14 +56,14 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
otInstance *sInstance;
|
||||
|
||||
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
size_t otInstanceBufferLength = 0;
|
||||
uint8_t *otInstanceBuffer = NULL;
|
||||
#endif
|
||||
|
||||
PlatformInit(argc, argv);
|
||||
|
||||
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
// Call to query the buffer size
|
||||
(void)otInstanceInit(NULL, &otInstanceBufferLength);
|
||||
|
||||
@@ -74,7 +74,7 @@ int main(int argc, char *argv[])
|
||||
// Initialize OpenThread with the buffer
|
||||
sInstance = otInstanceInit(otInstanceBuffer, &otInstanceBufferLength);
|
||||
#else
|
||||
sInstance = otInstanceInit();
|
||||
sInstance = otInstanceInitSingle();
|
||||
#endif
|
||||
assert(sInstance);
|
||||
|
||||
@@ -91,7 +91,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
// otInstanceFinalize(sInstance);
|
||||
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
// free(otInstanceBuffer);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -32,6 +32,10 @@
|
||||
/* Define to 1 to enable the NCP SPI interface. */
|
||||
// On the command line: #define OPENTHREAD_ENABLE_NCP_SPI 1
|
||||
|
||||
/* Define to 1 if you want to enable support for multiple OpenThread
|
||||
instances. */
|
||||
#define OPENTHREAD_ENABLE_MULTIPLE_INSTANCES 1
|
||||
|
||||
/* Define to 1 if you want to enable default log output. */
|
||||
#define OPENTHREAD_CONFIG_ENABLE_DEFAULT_LOG_OUTPUT 1
|
||||
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
#ifndef OPENTHREAD_INSTANCE_H_
|
||||
#define OPENTHREAD_INSTANCE_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <openthread/types.h>
|
||||
#include <openthread/platform/logging.h>
|
||||
|
||||
@@ -157,16 +159,18 @@ OTAPI uint32_t OTCALL otGetCompartmentId(otInstance *aInstance);
|
||||
|
||||
#else // OTDLL
|
||||
|
||||
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
|
||||
/**
|
||||
* This function initializes the OpenThread library.
|
||||
*
|
||||
*
|
||||
* This function initializes OpenThread and prepares it for subsequent OpenThread API calls. This function must be
|
||||
* called before any other calls to OpenThread. By default, OpenThread is initialized in the 'enabled' state.
|
||||
*
|
||||
* This function is available and can only be used when support for multiple OpenThread instances is enabled.
|
||||
*
|
||||
* @param[in] aInstanceBuffer The buffer for OpenThread to use for allocating the otInstance structure.
|
||||
* @param[inout] aInstanceBufferSize On input, the size of aInstanceBuffer. On output, if not enough space for otInstance,
|
||||
the number of bytes required for otInstance.
|
||||
* @param[inout] aInstanceBufferSize On input, the size of aInstanceBuffer. On output, if not enough space for
|
||||
* otInstance, the number of bytes required for otInstance.
|
||||
*
|
||||
* @retval otInstance* The new OpenThread instance structure.
|
||||
*
|
||||
@@ -174,18 +178,19 @@ OTAPI uint32_t OTCALL otGetCompartmentId(otInstance *aInstance);
|
||||
*
|
||||
*/
|
||||
otInstance *otInstanceInit(void *aInstanceBuffer, size_t *aInstanceBufferSize);
|
||||
#else // OPENTHREAD_MULTIPLE_INSTANCE
|
||||
|
||||
/**
|
||||
* This function initializes the static instance of the OpenThread library.
|
||||
* This function initializes the static single instance of the OpenThread library.
|
||||
*
|
||||
* This function initializes OpenThread and prepares it for subsequent OpenThread API calls. This function must be
|
||||
* called before any other calls to OpenThread. By default, OpenThread is initialized in the 'enabled' state.
|
||||
*
|
||||
* @retval otInstance* The new OpenThread instance structure.
|
||||
* This function is available and can only be used when support for multiple OpenThread instances is disabled.
|
||||
*
|
||||
* @retval The new single OpenThread instance structure.
|
||||
*
|
||||
*/
|
||||
otInstance *otInstanceInit(void);
|
||||
#endif // OPENTHREAD_MULTIPLE_INSTANCE
|
||||
otInstance *otInstanceInitSingle(void);
|
||||
|
||||
/**
|
||||
* This function disables the OpenThread library.
|
||||
|
||||
@@ -49,9 +49,9 @@ extern "C" {
|
||||
*
|
||||
*/
|
||||
|
||||
// Currently, OpenThread only requires dynamic memory allocation when supporting multiple
|
||||
// simultaneous instances, for MbedTls.
|
||||
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
|
||||
/*
|
||||
* OpenThread only requires dynamic memory allocation when supporting multiple simultaneous instances, for MbedTls.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Dynamically allocates new memory. On platforms that support it, should just redirect to calloc. For
|
||||
@@ -61,6 +61,8 @@ extern "C" {
|
||||
* memory each and returns a pointer to the allocated memory. The allocated memory is filled with bytes
|
||||
* of value zero."
|
||||
*
|
||||
* This function is available and can ONLY be used only when support for multiple OpenThread instances is enabled.
|
||||
*
|
||||
* @param[in] aNum The number of blocks to allocate
|
||||
* @param[in] aSize The size of each block to allocate
|
||||
*
|
||||
@@ -72,12 +74,12 @@ void *otPlatCAlloc(size_t aNum, size_t aSize);
|
||||
/**
|
||||
* Frees memory that was dynamically allocated.
|
||||
*
|
||||
* This function is available and can ONLY be used only when support for multiple OpenThread instances is enabled.
|
||||
*
|
||||
* @param[in] aPtr A pointer the memory blocks to free. The pointer may be NULL.
|
||||
*/
|
||||
void otPlatFree(void *aPtr);
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*
|
||||
|
||||
+13
-2
@@ -1682,9 +1682,9 @@ exit:
|
||||
AppendResult(error);
|
||||
}
|
||||
|
||||
void Interpreter::s_HandlePingTimer(void *aContext)
|
||||
void Interpreter::s_HandlePingTimer(Timer &aTimer)
|
||||
{
|
||||
static_cast<Interpreter *>(aContext)->HandlePingTimer();
|
||||
GetOwner(aTimer).HandlePingTimer();
|
||||
}
|
||||
|
||||
void Interpreter::HandlePingTimer()
|
||||
@@ -3181,5 +3181,16 @@ void Interpreter::HandleDiagnosticGetResponse(Message &aMessage, const Ip6::Mess
|
||||
}
|
||||
#endif
|
||||
|
||||
Interpreter &Interpreter::GetOwner(const Context &aContext)
|
||||
{
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
Interpreter &interpreter = *static_cast<Interpreter *>(aContext.GetContext());
|
||||
#else
|
||||
Interpreter &interpreter = Uart::sUartServer->GetInterpreter();
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
#endif
|
||||
return interpreter;
|
||||
}
|
||||
|
||||
} // namespace Cli
|
||||
} // namespace ot
|
||||
|
||||
+4
-1
@@ -50,6 +50,7 @@
|
||||
#endif
|
||||
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/context.hpp"
|
||||
|
||||
#ifndef OTDLL
|
||||
#include <openthread/dhcp6_client.h>
|
||||
@@ -283,7 +284,7 @@ private:
|
||||
#ifndef OTDLL
|
||||
static void s_HandleIcmpReceive(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo,
|
||||
const otIcmp6Header *aIcmpHeader);
|
||||
static void s_HandlePingTimer(void *aContext);
|
||||
static void s_HandlePingTimer(Timer &aTimer);
|
||||
#endif
|
||||
static void OTCALL s_HandleActiveScanResult(otActiveScanResult *aResult, void *aContext);
|
||||
static void OTCALL s_HandleNetifStateChanged(uint32_t aFlags, void *aContext);
|
||||
@@ -329,6 +330,8 @@ private:
|
||||
void HandleDnsResponse(const char *aHostname, Ip6::Address &aAddress, uint32_t aTtl, otError aResult);
|
||||
#endif
|
||||
|
||||
static Interpreter &GetOwner(const Context &aContext);
|
||||
|
||||
#if OPENTHREAD_ENABLE_APPLICATION_COAP
|
||||
|
||||
Coap mCoap;
|
||||
|
||||
@@ -91,6 +91,14 @@ public:
|
||||
*/
|
||||
int OutputFormatV(const char *aFmt, va_list aAp);
|
||||
|
||||
/**
|
||||
* This method returns a reference to the interpreter object.
|
||||
*
|
||||
* @returns A reference to the interpreter object.
|
||||
*
|
||||
*/
|
||||
Interpreter &GetInterpreter(void) { return mInterpreter; }
|
||||
|
||||
void ReceiveTask(const uint8_t *aBuf, uint16_t aBufLength);
|
||||
void SendDoneTask(void);
|
||||
|
||||
|
||||
@@ -119,6 +119,7 @@ SOURCES_COMMON = \
|
||||
coap/coap_secure.cpp \
|
||||
common/crc16.cpp \
|
||||
common/logging.cpp \
|
||||
common/locator.cpp \
|
||||
common/message.cpp \
|
||||
common/tasklet.cpp \
|
||||
common/timer.cpp \
|
||||
@@ -199,14 +200,17 @@ HEADERS_COMMON = \
|
||||
openthread-core-config.h \
|
||||
openthread-core-default-config.h \
|
||||
openthread-instance.h \
|
||||
openthread-single-instance.h \
|
||||
api/link_raw.hpp \
|
||||
coap/coap.hpp \
|
||||
coap/coap_header.hpp \
|
||||
coap/coap_secure.hpp \
|
||||
common/code_utils.hpp \
|
||||
common/context.hpp \
|
||||
common/crc16.hpp \
|
||||
common/debug.hpp \
|
||||
common/encoding.hpp \
|
||||
common/locator.hpp \
|
||||
common/logging.hpp \
|
||||
common/message.hpp \
|
||||
common/settings.hpp \
|
||||
|
||||
@@ -40,13 +40,45 @@
|
||||
#include <openthread/platform/settings.h>
|
||||
|
||||
#include "openthread-instance.h"
|
||||
#include "openthread-single-instance.h"
|
||||
#include "common/logging.hpp"
|
||||
#include "common/new.hpp"
|
||||
|
||||
#ifndef OPENTHREAD_MULTIPLE_INSTANCE
|
||||
#if !OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
|
||||
static otDEFINE_ALIGNED_VAR(sInstanceRaw, sizeof(otInstance), uint64_t);
|
||||
otInstance *sInstance = NULL;
|
||||
#endif
|
||||
|
||||
otInstance *otGetInstance(void)
|
||||
{
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
ot::ThreadNetif &otGetThreadNetif(void)
|
||||
{
|
||||
return sInstance->mThreadNetif;
|
||||
}
|
||||
|
||||
ot::MeshForwarder &otGetMeshForwarder(void)
|
||||
{
|
||||
return sInstance->mThreadNetif.GetMeshForwarder();
|
||||
}
|
||||
|
||||
ot::TimerScheduler &otGetTimerScheduler(void)
|
||||
{
|
||||
return sInstance->mIp6.mTimerScheduler;
|
||||
}
|
||||
|
||||
ot::TaskletScheduler &otGetTaskletScheduler(void)
|
||||
{
|
||||
return sInstance->mIp6.mTaskletScheduler;
|
||||
}
|
||||
|
||||
ot::Ip6::Ip6 &otGetIp6(void)
|
||||
{
|
||||
return sInstance->mIp6;
|
||||
}
|
||||
#endif // #if !OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
|
||||
otInstance::otInstance(void) :
|
||||
mReceiveIp6DatagramCallback(NULL),
|
||||
@@ -95,11 +127,11 @@ void otInstancePostConstructor(otInstance *aInstance)
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
|
||||
otInstance *otInstanceInit(void *aInstanceBuffer, size_t *aInstanceBufferSize)
|
||||
{
|
||||
otInstance *aInstance = NULL;
|
||||
otInstance *instance = NULL;
|
||||
|
||||
otLogFuncEntry();
|
||||
|
||||
@@ -111,27 +143,31 @@ otInstance *otInstanceInit(void *aInstanceBuffer, size_t *aInstanceBufferSize)
|
||||
VerifyOrExit(aInstanceBuffer != NULL);
|
||||
|
||||
// Construct the context
|
||||
aInstance = new(aInstanceBuffer)otInstance();
|
||||
instance = new(aInstanceBuffer)otInstance();
|
||||
|
||||
// Execute post constructor operations
|
||||
otInstancePostConstructor(aInstance);
|
||||
otInstancePostConstructor(instance);
|
||||
|
||||
otLogInfoApi(aInstance, "otInstance Initialized");
|
||||
otLogInfoApi(instance, "otInstance Initialized");
|
||||
|
||||
exit:
|
||||
|
||||
otLogFuncExit();
|
||||
return aInstance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
#else
|
||||
#else // #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
|
||||
otInstance *otInstanceInit()
|
||||
otInstance *otInstanceInitSingle(void)
|
||||
{
|
||||
otLogFuncEntry();
|
||||
|
||||
VerifyOrExit(sInstance == NULL);
|
||||
|
||||
// We need to ensure `sInstance` pointer is correctly set
|
||||
// before any object constructor is called.
|
||||
sInstance = reinterpret_cast<otInstance *>(&sInstanceRaw);
|
||||
|
||||
// Construct the context
|
||||
sInstance = new(&sInstanceRaw)otInstance();
|
||||
|
||||
@@ -146,7 +182,7 @@ exit:
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif // #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
|
||||
void otInstanceFinalize(otInstance *aInstance)
|
||||
{
|
||||
@@ -156,9 +192,10 @@ void otInstanceFinalize(otInstance *aInstance)
|
||||
(void)otThreadSetEnabled(aInstance, false);
|
||||
(void)otIp6SetEnabled(aInstance, false);
|
||||
|
||||
#ifndef OPENTHREAD_MULTIPLE_INSTANCE
|
||||
#if !OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
sInstance = NULL;
|
||||
#endif
|
||||
|
||||
otLogFuncExit();
|
||||
}
|
||||
|
||||
|
||||
@@ -111,6 +111,8 @@ public:
|
||||
void InvokeEnergyScanDone(int8_t aEnergyScanMaxRssi);
|
||||
|
||||
private:
|
||||
otError DoTransmit(otRadioFrame *aFrame);
|
||||
static LinkRaw &GetOwner(const Context &aContext);
|
||||
|
||||
otInstance &mInstance;
|
||||
bool mEnabled;
|
||||
@@ -119,8 +121,6 @@ private:
|
||||
otLinkRawTransmitDone mTransmitDoneCallback;
|
||||
otLinkRawEnergyScanDone mEnergyScanDoneCallback;
|
||||
|
||||
otError DoTransmit(otRadioFrame *aFrame);
|
||||
|
||||
#if OPENTHREAD_LINKRAW_TIMER_REQUIRED
|
||||
|
||||
enum TimerReason
|
||||
@@ -135,6 +135,7 @@ private:
|
||||
TimerReason mTimerReason;
|
||||
|
||||
static void HandleTimer(void *aContext);
|
||||
static void HandleTimer(Timer &aTimer);
|
||||
void HandleTimer(void);
|
||||
|
||||
#endif // OPENTHREAD_LINKRAW_TIMER_REQUIRED
|
||||
@@ -158,7 +159,7 @@ private:
|
||||
Tasklet mEnergyScanTask;
|
||||
int8_t mEnergyScanRssi;
|
||||
|
||||
static void HandleEnergyScanTask(void *aContext);
|
||||
static void HandleEnergyScanTask(Tasklet &aTasklet);
|
||||
void HandleEnergyScanTask(void);
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_ENABLE_SOFTWARE_ENERGY_SCAN
|
||||
|
||||
@@ -32,12 +32,13 @@
|
||||
*/
|
||||
|
||||
#include <openthread/config.h>
|
||||
#include <common/debug.hpp>
|
||||
#include <common/logging.hpp>
|
||||
|
||||
#include <openthread/platform/random.h>
|
||||
#include <openthread/platform/usec-alarm.h>
|
||||
|
||||
#include "openthread-instance.h"
|
||||
#include "common/debug.hpp"
|
||||
#include "common/logging.hpp"
|
||||
|
||||
#if OPENTHREAD_ENABLE_RAW_LINK_API
|
||||
|
||||
@@ -483,6 +484,11 @@ void LinkRaw::HandleTimer(void *aContext)
|
||||
static_cast<LinkRaw *>(aContext)->HandleTimer();
|
||||
}
|
||||
|
||||
void LinkRaw::HandleTimer(Timer &aTimer)
|
||||
{
|
||||
GetOwner(aTimer).HandleTimer();
|
||||
}
|
||||
|
||||
void LinkRaw::HandleTimer(void)
|
||||
{
|
||||
TimerReason timerReason = mTimerReason;
|
||||
@@ -578,9 +584,9 @@ void LinkRaw::StartCsmaBackoff(void)
|
||||
|
||||
#if OPENTHREAD_CONFIG_ENABLE_SOFTWARE_ENERGY_SCAN
|
||||
|
||||
void LinkRaw::HandleEnergyScanTask(void *aContext)
|
||||
void LinkRaw::HandleEnergyScanTask(Tasklet &aTasklet)
|
||||
{
|
||||
static_cast<LinkRaw *>(aContext)->HandleEnergyScanTask();
|
||||
GetOwner(aTasklet).HandleEnergyScanTask();
|
||||
}
|
||||
|
||||
void LinkRaw::HandleEnergyScanTask(void)
|
||||
@@ -607,6 +613,17 @@ void LinkRaw::HandleEnergyScanTask(void)
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_ENABLE_SOFTWARE_ENERGY_SCAN
|
||||
|
||||
LinkRaw &LinkRaw::GetOwner(const Context &aContext)
|
||||
{
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
LinkRaw &link = *static_cast<LinkRaw *>(aContext.GetContext());
|
||||
#else
|
||||
LinkRaw &link = otGetInstance()->mLinkRaw;
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
#endif
|
||||
return link;
|
||||
}
|
||||
|
||||
} // namespace ot
|
||||
|
||||
#endif // OPENTHREAD_ENABLE_RAW_LINK_API
|
||||
|
||||
+29
-7
@@ -50,7 +50,7 @@ namespace ot {
|
||||
namespace Coap {
|
||||
|
||||
Coap::Coap(ThreadNetif &aNetif):
|
||||
mNetif(aNetif),
|
||||
ThreadNetifLocator(aNetif),
|
||||
mSocket(aNetif.GetIp6().mUdp),
|
||||
mRetransmissionTimer(aNetif.GetIp6().mTimerScheduler, &Coap::HandleRetransmissionTimer, this),
|
||||
mResources(NULL),
|
||||
@@ -287,9 +287,20 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void Coap::HandleRetransmissionTimer(void *aContext)
|
||||
Coap &Coap::GetOwner(const Context &aContext)
|
||||
{
|
||||
static_cast<Coap *>(aContext)->HandleRetransmissionTimer();
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
Coap &coap = *static_cast<Coap *>(aContext.GetContext());
|
||||
#else
|
||||
Coap &coap = otGetThreadNetif().GetCoap();
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
#endif
|
||||
return coap;
|
||||
}
|
||||
|
||||
void Coap::HandleRetransmissionTimer(Timer &aTimer)
|
||||
{
|
||||
GetOwner(aTimer).HandleRetransmissionTimer();
|
||||
}
|
||||
|
||||
void Coap::HandleRetransmissionTimer(void)
|
||||
@@ -543,7 +554,7 @@ exit:
|
||||
|
||||
if (error)
|
||||
{
|
||||
otLogInfoCoapErr(mNetif.GetInstance(), error, "Receive failed");
|
||||
otLogInfoCoapErr(GetNetif().GetInstance(), error, "Receive failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -704,7 +715,7 @@ exit:
|
||||
|
||||
if (error != OT_ERROR_NONE)
|
||||
{
|
||||
otLogInfoCoapErr(mNetif.GetInstance(), error, "Failed to process request");
|
||||
otLogInfoCoapErr(GetNetif().GetInstance(), error, "Failed to process request");
|
||||
|
||||
if (error == OT_ERROR_NOT_FOUND)
|
||||
{
|
||||
@@ -887,9 +898,20 @@ void ResponsesQueue::DequeueAllResponses(void)
|
||||
}
|
||||
}
|
||||
|
||||
void ResponsesQueue::HandleTimer(void *aContext)
|
||||
ResponsesQueue &ResponsesQueue::GetOwner(const Context &aContext)
|
||||
{
|
||||
static_cast<ResponsesQueue *>(aContext)->HandleTimer();
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
ResponsesQueue &queue = *static_cast<ResponsesQueue *>(aContext.GetContext());
|
||||
#else
|
||||
ResponsesQueue &queue = otGetThreadNetif().GetCoap().mResponsesQueue;
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
#endif
|
||||
return queue;
|
||||
}
|
||||
|
||||
void ResponsesQueue::HandleTimer(Timer &aTimer)
|
||||
{
|
||||
GetOwner(aTimer).HandleTimer();
|
||||
}
|
||||
|
||||
void ResponsesQueue::HandleTimer(void)
|
||||
|
||||
+10
-6
@@ -33,6 +33,7 @@
|
||||
|
||||
#include "coap/coap_header.hpp"
|
||||
#include "common/debug.hpp"
|
||||
#include "common/locator.hpp"
|
||||
#include "common/message.hpp"
|
||||
#include "common/timer.hpp"
|
||||
#include "net/ip6.hpp"
|
||||
@@ -407,20 +408,22 @@ private:
|
||||
};
|
||||
|
||||
void DequeueResponse(Message &aMessage) { mQueue.Dequeue(aMessage); aMessage.Free(); }
|
||||
static ResponsesQueue &GetOwner(const Context &aContext);
|
||||
static void HandleTimer(Timer &aTimer);
|
||||
void HandleTimer(void);
|
||||
|
||||
MessageQueue mQueue;
|
||||
Timer mTimer;
|
||||
|
||||
static void HandleTimer(void *aContext);
|
||||
void HandleTimer(void);
|
||||
};
|
||||
|
||||
/**
|
||||
* This class implements the CoAP client and server.
|
||||
*
|
||||
*/
|
||||
class Coap
|
||||
class Coap: public ThreadNetifLocator
|
||||
{
|
||||
friend class ResponsesQueue;
|
||||
|
||||
public:
|
||||
/**
|
||||
* This function pointer is called before CoAP server processing a CoAP packets.
|
||||
@@ -661,7 +664,6 @@ protected:
|
||||
*/
|
||||
virtual void Receive(Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
ThreadNetif &mNetif;
|
||||
Ip6::UdpSocket mSocket;
|
||||
|
||||
private:
|
||||
@@ -686,9 +688,11 @@ private:
|
||||
otError SendCopy(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
otError SendEmptyMessage(Header::Type aType, const Header &aRequestHeader,
|
||||
const Ip6::MessageInfo &aMessageInfo);
|
||||
static void HandleRetransmissionTimer(void *aContext);
|
||||
static void HandleRetransmissionTimer(Timer &aTimer);
|
||||
void HandleRetransmissionTimer(void);
|
||||
|
||||
static Coap &GetOwner(const Context &aContext);
|
||||
|
||||
MessageQueue mPendingRequests;
|
||||
uint16_t mMessageId;
|
||||
Timer mRetransmissionTimer;
|
||||
|
||||
@@ -98,33 +98,33 @@ otError CoapSecure::Connect(const Ip6::MessageInfo &aMessageInfo, ConnectedCallb
|
||||
mConnectedCallback = aCallback;
|
||||
mConnectedContext = aContext;
|
||||
|
||||
return mNetif.GetDtls().Start(true, &CoapSecure::HandleDtlsConnected, &CoapSecure::HandleDtlsReceive,
|
||||
&CoapSecure::HandleDtlsSend, this);
|
||||
return GetNetif().GetDtls().Start(true, &CoapSecure::HandleDtlsConnected, &CoapSecure::HandleDtlsReceive,
|
||||
&CoapSecure::HandleDtlsSend, this);
|
||||
}
|
||||
|
||||
bool CoapSecure::IsConnectionActive(void)
|
||||
{
|
||||
return mNetif.GetDtls().IsStarted();
|
||||
return GetNetif().GetDtls().IsStarted();
|
||||
}
|
||||
|
||||
bool CoapSecure::IsConnected(void)
|
||||
{
|
||||
return mNetif.GetDtls().IsConnected();
|
||||
return GetNetif().GetDtls().IsConnected();
|
||||
}
|
||||
|
||||
otError CoapSecure::Disconnect(void)
|
||||
{
|
||||
return mNetif.GetDtls().Stop();
|
||||
return GetNetif().GetDtls().Stop();
|
||||
}
|
||||
|
||||
MeshCoP::Dtls &CoapSecure::GetDtls(void)
|
||||
{
|
||||
return mNetif.GetDtls();
|
||||
return GetNetif().GetDtls();
|
||||
}
|
||||
|
||||
otError CoapSecure::SetPsk(const uint8_t *aPsk, uint8_t aPskLength)
|
||||
{
|
||||
return mNetif.GetDtls().SetPsk(aPsk, aPskLength);
|
||||
return GetNetif().GetDtls().SetPsk(aPsk, aPskLength);
|
||||
}
|
||||
|
||||
otError CoapSecure::SendMessage(Message &aMessage, otCoapResponseHandler aHandler, void *aContext)
|
||||
@@ -151,14 +151,16 @@ otError CoapSecure::SendMessage(Message &aMessage, const Ip6::MessageInfo &aMess
|
||||
otError CoapSecure::Send(Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aMessageInfo);
|
||||
return mNetif.GetDtls().Send(aMessage, aMessage.GetLength());
|
||||
return GetNetif().GetDtls().Send(aMessage, aMessage.GetLength());
|
||||
}
|
||||
|
||||
void CoapSecure::Receive(Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
|
||||
otLogFuncEntry();
|
||||
|
||||
if (!mNetif.GetDtls().IsStarted())
|
||||
if (!netif.GetDtls().IsStarted())
|
||||
{
|
||||
Ip6::SockAddr sockAddr;
|
||||
sockAddr.mAddress = aMessageInfo.GetPeerAddr();
|
||||
@@ -168,14 +170,14 @@ void CoapSecure::Receive(Message &aMessage, const Ip6::MessageInfo &aMessageInfo
|
||||
mPeerAddress.SetPeerAddr(aMessageInfo.GetPeerAddr());
|
||||
mPeerAddress.SetPeerPort(aMessageInfo.GetPeerPort());
|
||||
|
||||
if (mNetif.IsUnicastAddress(aMessageInfo.GetSockAddr()))
|
||||
if (netif.IsUnicastAddress(aMessageInfo.GetSockAddr()))
|
||||
{
|
||||
mPeerAddress.SetSockAddr(aMessageInfo.GetSockAddr());
|
||||
}
|
||||
|
||||
mPeerAddress.SetSockPort(aMessageInfo.GetSockPort());
|
||||
|
||||
mNetif.GetDtls().Start(false, HandleDtlsConnected, HandleDtlsReceive, HandleDtlsSend, this);
|
||||
netif.GetDtls().Start(false, HandleDtlsConnected, HandleDtlsReceive, HandleDtlsSend, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -184,9 +186,9 @@ void CoapSecure::Receive(Message &aMessage, const Ip6::MessageInfo &aMessageInfo
|
||||
(mPeerAddress.GetPeerPort() == aMessageInfo.GetPeerPort()));
|
||||
}
|
||||
|
||||
mNetif.GetDtls().SetClientId(mPeerAddress.GetPeerAddr().mFields.m8,
|
||||
sizeof(mPeerAddress.GetPeerAddr().mFields));
|
||||
mNetif.GetDtls().Receive(aMessage, aMessage.GetOffset(), aMessage.GetLength() - aMessage.GetOffset());
|
||||
netif.GetDtls().SetClientId(mPeerAddress.GetPeerAddr().mFields.m8,
|
||||
sizeof(mPeerAddress.GetPeerAddr().mFields));
|
||||
netif.GetDtls().Receive(aMessage, aMessage.GetOffset(), aMessage.GetLength() - aMessage.GetOffset());
|
||||
|
||||
exit:
|
||||
otLogFuncExit();
|
||||
@@ -216,7 +218,7 @@ void CoapSecure::HandleDtlsReceive(uint8_t *aBuf, uint16_t aLength)
|
||||
|
||||
otLogFuncEntry();
|
||||
|
||||
VerifyOrExit((message = mNetif.GetIp6().mMessagePool.New(Message::kTypeIp6, 0)) != NULL);
|
||||
VerifyOrExit((message = GetNetif().GetIp6().mMessagePool.New(Message::kTypeIp6, 0)) != NULL);
|
||||
SuccessOrExit(message->Append(aBuf, aLength));
|
||||
|
||||
Coap::Receive(*message, mPeerAddress);
|
||||
@@ -271,9 +273,9 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void CoapSecure::HandleUdpTransmit(void *aContext)
|
||||
void CoapSecure::HandleUdpTransmit(Tasklet &aTasklet)
|
||||
{
|
||||
return static_cast<CoapSecure *>(aContext)->HandleUdpTransmit();
|
||||
GetOwner(aTasklet).HandleUdpTransmit();
|
||||
}
|
||||
|
||||
void CoapSecure::HandleUdpTransmit(void)
|
||||
@@ -305,6 +307,17 @@ exit:
|
||||
otLogFuncExit();
|
||||
}
|
||||
|
||||
CoapSecure &CoapSecure::GetOwner(const Context &aContext)
|
||||
{
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
CoapSecure &coap = *static_cast<CoapSecure *>(aContext.GetContext());
|
||||
#else
|
||||
CoapSecure &coap = otGetThreadNetif().GetCoapSecure();
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
#endif
|
||||
return coap;
|
||||
}
|
||||
|
||||
} // namespace Coap
|
||||
} // namespace ot
|
||||
|
||||
|
||||
@@ -211,9 +211,11 @@ private:
|
||||
static otError HandleDtlsSend(void *aContext, const uint8_t *aBuf, uint16_t aLength, uint8_t aMessageSubType);
|
||||
otError HandleDtlsSend(const uint8_t *aBuf, uint16_t aLength, uint8_t aMessageSubType);
|
||||
|
||||
static void HandleUdpTransmit(void *aContext);
|
||||
static void HandleUdpTransmit(Tasklet &aTasklet);
|
||||
void HandleUdpTransmit(void);
|
||||
|
||||
static CoapSecure &GetOwner(const Context &aContext);
|
||||
|
||||
Ip6::MessageInfo mPeerAddress;
|
||||
ConnectedCallback mConnectedCallback;
|
||||
void *mConnectedContext;
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (c) 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 includes definitions for maintaining a pointer to arbitrary context information.
|
||||
*/
|
||||
|
||||
#ifndef CONTEXT_HPP_
|
||||
#define CONTEXT_HPP_
|
||||
|
||||
#include <openthread/config.h>
|
||||
#include <openthread/platform/toolchain.h>
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
|
||||
namespace ot {
|
||||
|
||||
/**
|
||||
* @addtogroup core-context
|
||||
*
|
||||
* @brief
|
||||
* This module includes definitions for maintaining a pointer to arbitrary context information.
|
||||
*
|
||||
* @{
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class implements definitions for maintaining a pointer to arbitrary context information.
|
||||
*
|
||||
* This is used as base class for objects that provide a callback or handler (e.g., Timer or Tasklet).
|
||||
*
|
||||
*/
|
||||
class Context
|
||||
{
|
||||
public:
|
||||
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
/**
|
||||
* This method returns the pointer to the arbitrary context information.
|
||||
*
|
||||
* @returns The pointer to the context information.
|
||||
*
|
||||
*/
|
||||
void *GetContext(void) const { return mContext; }
|
||||
#endif
|
||||
|
||||
protected:
|
||||
/**
|
||||
* This constructor initializes the context object.
|
||||
*
|
||||
* @param[in] aContext A pointer to arbitrary context information.
|
||||
*
|
||||
*/
|
||||
Context(void *aContext)
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
: mContext(aContext)
|
||||
#endif
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
}
|
||||
|
||||
private:
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
void *mContext;
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*
|
||||
*/
|
||||
|
||||
} // namespace ot
|
||||
|
||||
#endif // CONTEXT_HPP_
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 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 locator class for OpenThread objects.
|
||||
*/
|
||||
|
||||
#define WPP_NAME "locator.tmh"
|
||||
|
||||
#include <openthread/config.h>
|
||||
|
||||
#include "locator.hpp"
|
||||
|
||||
#include "openthread-instance.h"
|
||||
#include "net/ip6.hpp"
|
||||
|
||||
namespace ot {
|
||||
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
|
||||
otInstance *ThreadNetifLocator::GetInstance(void) const
|
||||
{
|
||||
return otInstanceFromThreadNetif(&GetNetif());
|
||||
}
|
||||
|
||||
otInstance *MeshForwarderLocator::GetInstance(void) const
|
||||
{
|
||||
return otInstanceFromThreadNetif(&GetMeshForwarder().GetNetif());
|
||||
}
|
||||
|
||||
otInstance *TimerSchedulerLocator::GetInstance(void) const
|
||||
{
|
||||
return otInstanceFromIp6(Ip6::Ip6FromTimerScheduler(&GetTimerScheduler()));
|
||||
}
|
||||
|
||||
otInstance *TaskletSchedulerLocator::GetInstance(void) const
|
||||
{
|
||||
return otInstanceFromIp6(Ip6::Ip6FromTaskletScheduler(&GetTaskletScheduler()));
|
||||
}
|
||||
|
||||
otInstance *Ip6Locator::GetInstance(void) const
|
||||
{
|
||||
return otInstanceFromIp6(&GetIp6());
|
||||
}
|
||||
|
||||
#endif // #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
|
||||
} // namespace ot
|
||||
@@ -0,0 +1,341 @@
|
||||
/*
|
||||
* Copyright (c) 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 includes definitions for locator class for OpenThread objects.
|
||||
*/
|
||||
|
||||
#ifndef LOCATOR_HPP_
|
||||
#define LOCATOR_HPP_
|
||||
|
||||
#include <openthread/config.h>
|
||||
|
||||
#include <openthread/types.h>
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
#include "openthread-single-instance.h"
|
||||
|
||||
namespace ot {
|
||||
|
||||
class ThreadNetif;
|
||||
class MeshForwarder;
|
||||
class TaskletScheduler;
|
||||
class TimerScheduler;
|
||||
namespace Ip6 { class Ip6; }
|
||||
|
||||
/**
|
||||
* @addtogroup core-locator
|
||||
*
|
||||
* @brief
|
||||
* This module includes definitions for locator base class for OpenThread objects.
|
||||
*
|
||||
* @{
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This template class implements the base locator for OpenThread objects.
|
||||
*
|
||||
*/
|
||||
template <typename Type>
|
||||
class Locator
|
||||
{
|
||||
protected:
|
||||
/**
|
||||
* This constructor initializes the locator.
|
||||
*
|
||||
* @param[in] aObject A reference to the object.
|
||||
*
|
||||
*/
|
||||
Locator(Type &aObject)
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
: mLocatorObject(aObject)
|
||||
#endif
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aObject);
|
||||
}
|
||||
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
Type &mLocatorObject;
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* This class implements a locator for ThreadNetif object.
|
||||
*
|
||||
*/
|
||||
class ThreadNetifLocator: private Locator<ThreadNetif>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This method returns a reference to the thread network interface.
|
||||
*
|
||||
* @returns A reference to the thread network interface.
|
||||
*
|
||||
*/
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
ThreadNetif &GetNetif(void) const { return mLocatorObject; }
|
||||
#else
|
||||
ThreadNetif &GetNetif(void) const { return otGetThreadNetif(); }
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This method returns the pointer to the parent otInstance structure.
|
||||
*
|
||||
* @returns The pointer to the parent otInstance structure, or NULL if the instance has been finalized.
|
||||
*
|
||||
*/
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
otInstance *GetInstance(void) const;
|
||||
#else
|
||||
otInstance *GetInstance(void) const { return otGetInstance(); }
|
||||
#endif
|
||||
|
||||
protected:
|
||||
/**
|
||||
* This constructor initializes the object.
|
||||
*
|
||||
* @param[in] aThreadNetif A reference to the thread network interface.
|
||||
*
|
||||
*/
|
||||
ThreadNetifLocator(ThreadNetif &aThreadNetif): Locator(aThreadNetif) { }
|
||||
};
|
||||
|
||||
/**
|
||||
* This class implements a locator for MeshForwarder object.
|
||||
*
|
||||
*/
|
||||
class MeshForwarderLocator: private Locator<MeshForwarder>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This method returns a reference to the MeshForwarder.
|
||||
*
|
||||
* @returns A reference to the MeshForwarder.
|
||||
*
|
||||
*/
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
MeshForwarder &GetMeshForwarder(void) const { return mLocatorObject; }
|
||||
#else
|
||||
MeshForwarder &GetMeshForwarder(void) const { return otGetMeshForwarder(); }
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This method returns the pointer to the parent otInstance structure.
|
||||
*
|
||||
* @returns The pointer to the parent otInstance structure, or NULL if the instance has been finalized.
|
||||
*
|
||||
*/
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
otInstance *GetInstance(void) const;
|
||||
#else
|
||||
otInstance *GetInstance(void) const { return otGetInstance(); }
|
||||
#endif
|
||||
|
||||
protected:
|
||||
/**
|
||||
* This constructor initializes the object.
|
||||
*
|
||||
* @param[in] aMeshForwarder A reference to the MeshForwarder.
|
||||
*
|
||||
*/
|
||||
MeshForwarderLocator(MeshForwarder &aMeshForwarder): Locator(aMeshForwarder) { }
|
||||
};
|
||||
|
||||
/**
|
||||
* This class implements a locator for TimerScheduler object.
|
||||
*
|
||||
*/
|
||||
class TimerSchedulerLocator: private Locator<TimerScheduler>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This method returns a reference to the TimerScheduler.
|
||||
*
|
||||
* @returns A reference to the TimerScheduler.
|
||||
*
|
||||
*/
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
TimerScheduler &GetTimerScheduler(void) const { return mLocatorObject; }
|
||||
#else
|
||||
TimerScheduler &GetTimerScheduler(void) const { return otGetTimerScheduler(); }
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This method returns the pointer to the parent otInstance structure.
|
||||
*
|
||||
* @returns The pointer to the parent otInstance structure, or NULL if the instance has been finalized.
|
||||
*
|
||||
*/
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
otInstance *GetInstance(void) const;
|
||||
#else
|
||||
otInstance *GetInstance(void) const { return otGetInstance(); }
|
||||
#endif
|
||||
|
||||
protected:
|
||||
/**
|
||||
* This constructor initializes the object.
|
||||
*
|
||||
* @param[in] aTimerScheduler A reference to the TimerScheduler.
|
||||
*
|
||||
*/
|
||||
TimerSchedulerLocator(TimerScheduler &aTimerScheduler): Locator(aTimerScheduler) { }
|
||||
};
|
||||
|
||||
/**
|
||||
* This class implements a locator for TaskletScheduler object.
|
||||
*
|
||||
*/
|
||||
class TaskletSchedulerLocator: private Locator<TaskletScheduler>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This method returns a reference to the TaskletScheduler.
|
||||
*
|
||||
* @returns A reference to the TaskletScheduler.
|
||||
*
|
||||
*/
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
TaskletScheduler &GetTaskletScheduler(void) const { return mLocatorObject; }
|
||||
#else
|
||||
TaskletScheduler &GetTaskletScheduler(void) const { return otGetTaskletScheduler(); }
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This method returns the pointer to the parent otInstance structure.
|
||||
*
|
||||
* @returns The pointer to the parent otInstance structure, or NULL if the instance has been finalized.
|
||||
*
|
||||
*/
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
otInstance *GetInstance(void) const;
|
||||
#else
|
||||
otInstance *GetInstance(void) const { return otGetInstance(); }
|
||||
#endif
|
||||
|
||||
protected:
|
||||
/**
|
||||
* This constructor initializes the object.
|
||||
*
|
||||
* @param[in] aTaskletScheduler A reference to the TaskletScheduler.
|
||||
*
|
||||
*/
|
||||
TaskletSchedulerLocator(TaskletScheduler &aTaskletScheduler): Locator(aTaskletScheduler) { }
|
||||
};
|
||||
|
||||
/**
|
||||
* This class implements a locator for Ip6 object.
|
||||
*
|
||||
*/
|
||||
class Ip6Locator: private Locator<Ip6::Ip6>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This method returns a reference to the Ip6.
|
||||
*
|
||||
* @returns A reference to the Ip6.
|
||||
*
|
||||
*/
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
Ip6::Ip6 &GetIp6(void) const { return mLocatorObject; }
|
||||
#else
|
||||
Ip6::Ip6 &GetIp6(void) const { return otGetIp6(); }
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This method returns the pointer to the parent otInstance structure.
|
||||
*
|
||||
* @returns The pointer to the parent otInstance structure, or NULL if the instance has been finalized.
|
||||
*
|
||||
*/
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
otInstance *GetInstance(void) const;
|
||||
#else
|
||||
otInstance *GetInstance(void) const { return otGetInstance(); }
|
||||
#endif
|
||||
|
||||
protected:
|
||||
/**
|
||||
* This constructor initializes the object.
|
||||
*
|
||||
* @param[in] aIp6 A reference to the Ip6.
|
||||
*
|
||||
*/
|
||||
Ip6Locator(Ip6::Ip6 &aIp6): Locator(aIp6) { }
|
||||
};
|
||||
|
||||
/**
|
||||
* This class implements locator for otInstance object
|
||||
*
|
||||
*/
|
||||
class InstanceLocator
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This method returns the pointer to the parent otInstance structure.
|
||||
*
|
||||
* @returns The pointer to the parent otInstance structure, or NULL if the instance has been finalized.
|
||||
*
|
||||
*/
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
otInstance *GetInstance(void) const { return mInstance; }
|
||||
#else
|
||||
otInstance *GetInstance(void) const { return otGetInstance(); }
|
||||
#endif
|
||||
|
||||
protected:
|
||||
/**
|
||||
* This constructor initializes the object.
|
||||
*
|
||||
* @param[in] aInstance A pointer to the otInstance.
|
||||
*
|
||||
*/
|
||||
InstanceLocator(otInstance *aInstance)
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
: mInstance(aInstance)
|
||||
#endif
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
}
|
||||
|
||||
private:
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
otInstance *mInstance;
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*
|
||||
*/
|
||||
|
||||
} // namespace ot
|
||||
|
||||
#endif // LOCATOR_HPP_
|
||||
@@ -45,12 +45,12 @@
|
||||
namespace ot {
|
||||
|
||||
MessagePool::MessagePool(otInstance *aInstance) :
|
||||
mInstance(aInstance),
|
||||
InstanceLocator(aInstance),
|
||||
mAllQueue()
|
||||
{
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT
|
||||
// Initialize Platform buffer pool management.
|
||||
otPlatMessagePoolInit(mInstance, kNumBuffers, sizeof(Buffer));
|
||||
otPlatMessagePoolInit(GetInstance(), kNumBuffers, sizeof(Buffer));
|
||||
#else
|
||||
memset(mBuffers, 0, sizeof(mBuffers));
|
||||
|
||||
@@ -64,8 +64,6 @@ MessagePool::MessagePool(otInstance *aInstance) :
|
||||
mBuffers[kNumBuffers - 1].SetNextBuffer(NULL);
|
||||
mNumFreeBuffers = kNumBuffers;
|
||||
#endif
|
||||
|
||||
OT_UNUSED_VARIABLE(mInstance);
|
||||
}
|
||||
|
||||
Message *MessagePool::New(uint8_t aType, uint16_t aReserved)
|
||||
@@ -108,7 +106,7 @@ Buffer *MessagePool::NewBuffer(void)
|
||||
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT
|
||||
|
||||
buffer = static_cast<Buffer *>(otPlatMessagePoolNew(mInstance));
|
||||
buffer = static_cast<Buffer *>(otPlatMessagePoolNew(GetInstance()));
|
||||
|
||||
#else
|
||||
|
||||
@@ -124,7 +122,7 @@ Buffer *MessagePool::NewBuffer(void)
|
||||
|
||||
if (buffer == NULL)
|
||||
{
|
||||
otLogInfoMem(mInstance, "No available message buffer");
|
||||
otLogInfoMem(GetInstance(), "No available message buffer");
|
||||
}
|
||||
|
||||
return buffer;
|
||||
@@ -138,7 +136,7 @@ otError MessagePool::FreeBuffers(Buffer *aBuffer)
|
||||
{
|
||||
tmpBuffer = aBuffer->GetNextBuffer();
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT
|
||||
otPlatMessagePoolFree(mInstance, aBuffer);
|
||||
otPlatMessagePoolFree(GetInstance(), aBuffer);
|
||||
#else // OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT
|
||||
aBuffer->SetNextBuffer(mFreeBuffers);
|
||||
mFreeBuffers = aBuffer;
|
||||
@@ -155,7 +153,7 @@ otError MessagePool::ReclaimBuffers(int aNumBuffers)
|
||||
uint16_t numFreeBuffers;
|
||||
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT
|
||||
numFreeBuffers = otPlatMessagePoolNumFreeBuffers(mInstance);
|
||||
numFreeBuffers = otPlatMessagePoolNumFreeBuffers(GetInstance());
|
||||
#else
|
||||
numFreeBuffers = mNumFreeBuffers;
|
||||
#endif
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/locator.hpp"
|
||||
#include "mac/mac_frame.hpp"
|
||||
|
||||
namespace ot {
|
||||
@@ -967,7 +968,7 @@ private:
|
||||
* This class represents a message pool
|
||||
*
|
||||
*/
|
||||
class MessagePool
|
||||
class MessagePool: public InstanceLocator
|
||||
{
|
||||
friend class Message;
|
||||
friend class MessageQueue;
|
||||
@@ -1105,7 +1106,7 @@ public:
|
||||
*
|
||||
*/
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT
|
||||
uint16_t GetFreeBufferCount(void) const { return otPlatMessagePoolNumFreeBuffers(mInstance); }
|
||||
uint16_t GetFreeBufferCount(void) const { return otPlatMessagePoolNumFreeBuffers(GetInstance()); }
|
||||
#else
|
||||
uint16_t GetFreeBufferCount(void) const { return mNumFreeBuffers; }
|
||||
#endif
|
||||
@@ -1127,7 +1128,6 @@ private:
|
||||
Buffer *mFreeBuffers;
|
||||
#endif
|
||||
|
||||
otInstance *mInstance;
|
||||
PriorityQueue mAllQueue;
|
||||
};
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
|
||||
#include <openthread/openthread.h>
|
||||
|
||||
#include "openthread-instance.h"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
#include "net/ip6.hpp"
|
||||
@@ -44,16 +45,16 @@
|
||||
namespace ot {
|
||||
|
||||
Tasklet::Tasklet(TaskletScheduler &aScheduler, Handler aHandler, void *aContext):
|
||||
mScheduler(aScheduler),
|
||||
TaskletSchedulerLocator(aScheduler),
|
||||
Context(aContext),
|
||||
mHandler(aHandler),
|
||||
mContext(aContext),
|
||||
mNext(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
otError Tasklet::Post(void)
|
||||
{
|
||||
return mScheduler.Post(*this);
|
||||
return GetTaskletScheduler().Post(*this);
|
||||
}
|
||||
|
||||
TaskletScheduler::TaskletScheduler(void):
|
||||
@@ -72,7 +73,7 @@ otError TaskletScheduler::Post(Tasklet &aTasklet)
|
||||
{
|
||||
mHead = &aTasklet;
|
||||
mTail = &aTasklet;
|
||||
otTaskletsSignalPending(aTasklet.mScheduler.GetIp6()->GetInstance());
|
||||
otTaskletsSignalPending(aTasklet.GetInstance());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -117,7 +118,7 @@ void TaskletScheduler::ProcessQueuedTasklets(void)
|
||||
{
|
||||
if (mHead != NULL)
|
||||
{
|
||||
otTaskletsSignalPending(cur->mScheduler.GetIp6()->GetInstance());
|
||||
otTaskletsSignalPending(mHead->GetInstance());
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -125,9 +126,4 @@ void TaskletScheduler::ProcessQueuedTasklets(void)
|
||||
}
|
||||
}
|
||||
|
||||
Ip6::Ip6 *TaskletScheduler::GetIp6(void)
|
||||
{
|
||||
return Ip6::Ip6FromTaskletScheduler(this);
|
||||
}
|
||||
|
||||
} // namespace ot
|
||||
|
||||
@@ -38,9 +38,10 @@
|
||||
|
||||
#include <openthread/tasklet.h>
|
||||
|
||||
namespace ot {
|
||||
#include "common/context.hpp"
|
||||
#include "common/locator.hpp"
|
||||
|
||||
namespace Ip6 { class Ip6; }
|
||||
namespace ot {
|
||||
|
||||
class TaskletScheduler;
|
||||
|
||||
@@ -58,7 +59,7 @@ class TaskletScheduler;
|
||||
* This class is used to represent a tasklet.
|
||||
*
|
||||
*/
|
||||
class Tasklet
|
||||
class Tasklet: public TaskletSchedulerLocator, public Context
|
||||
{
|
||||
friend class TaskletScheduler;
|
||||
|
||||
@@ -66,10 +67,10 @@ public:
|
||||
/**
|
||||
* This function pointer is called when the tasklet is run.
|
||||
*
|
||||
* @param[in] aContext A pointer to arbitrary context information.
|
||||
* @param[in] aTasklet A reference to the tasklet being run.
|
||||
*
|
||||
*/
|
||||
typedef void (*Handler)(void *aContext);
|
||||
typedef void (*Handler)(Tasklet &aTasklet);
|
||||
|
||||
/**
|
||||
* This constructor creates a tasklet instance.
|
||||
@@ -88,11 +89,9 @@ public:
|
||||
otError Post(void);
|
||||
|
||||
private:
|
||||
void RunTask(void) { mHandler(mContext); }
|
||||
void RunTask(void) { mHandler(*this); }
|
||||
|
||||
TaskletScheduler &mScheduler;
|
||||
Handler mHandler;
|
||||
void *mContext;
|
||||
Tasklet *mNext;
|
||||
};
|
||||
|
||||
@@ -134,14 +133,6 @@ public:
|
||||
*/
|
||||
void ProcessQueuedTasklets(void);
|
||||
|
||||
/**
|
||||
* This method returns the pointer to the parent Ip6 structure.
|
||||
*
|
||||
* @returns The pointer to the parent Ip6 structure.
|
||||
*
|
||||
*/
|
||||
Ip6::Ip6 *GetIp6(void);
|
||||
|
||||
private:
|
||||
Tasklet *PopTasklet(void);
|
||||
Tasklet *mHead;
|
||||
|
||||
+15
-10
@@ -40,7 +40,9 @@
|
||||
#include <openthread/types.h>
|
||||
#include <openthread/platform/alarm.h>
|
||||
|
||||
#include "common/context.hpp"
|
||||
#include "common/debug.hpp"
|
||||
#include "common/locator.hpp"
|
||||
#include "common/tasklet.hpp"
|
||||
|
||||
namespace ot {
|
||||
@@ -133,7 +135,7 @@ private:
|
||||
* This class implements a timer.
|
||||
*
|
||||
*/
|
||||
class Timer
|
||||
class Timer: public TimerSchedulerLocator, public Context
|
||||
{
|
||||
friend class TimerScheduler;
|
||||
|
||||
@@ -147,9 +149,10 @@ public:
|
||||
/**
|
||||
* This function pointer is called when the timer expires.
|
||||
*
|
||||
* @param[in] aContext A pointer to arbitrary context information.
|
||||
* @param[in] aTimer A reference to the expired timer instance.
|
||||
*
|
||||
*/
|
||||
typedef void (*Handler)(void *aContext);
|
||||
typedef void (*Handler)(Timer &aTimer);
|
||||
|
||||
/**
|
||||
* This constructor creates a timer instance.
|
||||
@@ -160,9 +163,9 @@ public:
|
||||
*
|
||||
*/
|
||||
Timer(TimerScheduler &aScheduler, Handler aHandler, void *aContext):
|
||||
mScheduler(aScheduler),
|
||||
TimerSchedulerLocator(aScheduler),
|
||||
Context(aContext),
|
||||
mHandler(aHandler),
|
||||
mContext(aContext),
|
||||
mFireTime(0),
|
||||
mNext(this) {
|
||||
}
|
||||
@@ -201,13 +204,17 @@ public:
|
||||
* (aDt must be smaller than or equal to kMaxDt).
|
||||
*
|
||||
*/
|
||||
void StartAt(uint32_t aT0, uint32_t aDt) { assert(aDt <= kMaxDt); mFireTime = aT0 + aDt; mScheduler.Add(*this); }
|
||||
void StartAt(uint32_t aT0, uint32_t aDt) {
|
||||
assert(aDt <= kMaxDt);
|
||||
mFireTime = aT0 + aDt;
|
||||
GetTimerScheduler().Add(*this);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method stops the timer.
|
||||
*
|
||||
*/
|
||||
void Stop(void) { mScheduler.Remove(*this); }
|
||||
void Stop(void) { GetTimerScheduler().Remove(*this); }
|
||||
|
||||
/**
|
||||
* This static method returns the current time in milliseconds.
|
||||
@@ -245,11 +252,9 @@ private:
|
||||
*/
|
||||
bool DoesFireBefore(const Timer &aTimer);
|
||||
|
||||
void Fired(void) { mHandler(mContext); }
|
||||
void Fired(void) { mHandler(*this); }
|
||||
|
||||
TimerScheduler &mScheduler;
|
||||
Handler mHandler;
|
||||
void *mContext;
|
||||
uint32_t mFireTime;
|
||||
Timer *mNext;
|
||||
};
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
|
||||
#include <openthread/platform/random.h>
|
||||
|
||||
#include "openthread-instance.h"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
|
||||
@@ -49,7 +50,7 @@ TrickleTimer::TrickleTimer(
|
||||
#endif
|
||||
Handler aTransmitHandler, Handler aIntervalExpiredHandler, void *aContext)
|
||||
:
|
||||
mTimer(aScheduler, HandleTimerFired, this),
|
||||
Timer(aScheduler, HandleTimerFired, aContext),
|
||||
#ifdef ENABLE_TRICKLE_TIMER_SUPPRESSION_SUPPORT
|
||||
k(aRedundancyConstant),
|
||||
c(0),
|
||||
@@ -61,8 +62,7 @@ TrickleTimer::TrickleTimer(
|
||||
t(0),
|
||||
mPhase(kPhaseDormant),
|
||||
mTransmitHandler(aTransmitHandler),
|
||||
mIntervalExpiredHandler(aIntervalExpiredHandler),
|
||||
mContext(aContext)
|
||||
mIntervalExpiredHandler(aIntervalExpiredHandler)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ void TrickleTimer::Start(uint32_t aIntervalMin, uint32_t aIntervalMax, Mode aMod
|
||||
void TrickleTimer::Stop(void)
|
||||
{
|
||||
mPhase = kPhaseDormant;
|
||||
mTimer.Stop();
|
||||
Timer::Stop();
|
||||
}
|
||||
|
||||
#ifdef ENABLE_TRICKLE_TIMER_SUPPRESSION_SUPPORT
|
||||
@@ -117,7 +117,7 @@ void TrickleTimer::IndicateInconsistent(void)
|
||||
I = Imin;
|
||||
|
||||
// Stop the existing timer
|
||||
mTimer.Stop();
|
||||
Timer::Stop();
|
||||
|
||||
// Start a new interval
|
||||
StartNewInterval();
|
||||
@@ -156,13 +156,12 @@ void TrickleTimer::StartNewInterval(void)
|
||||
}
|
||||
|
||||
// Start the timer for 't' milliseconds from now
|
||||
mTimer.Start(t);
|
||||
Timer::Start(t);
|
||||
}
|
||||
|
||||
void TrickleTimer::HandleTimerFired(void *aContext)
|
||||
void TrickleTimer::HandleTimerFired(Timer &aTimer)
|
||||
{
|
||||
TrickleTimer *obj = static_cast<TrickleTimer *>(aContext);
|
||||
obj->HandleTimerFired();
|
||||
static_cast<TrickleTimer *>(&aTimer)->HandleTimerFired();
|
||||
}
|
||||
|
||||
void TrickleTimer::HandleTimerFired(void)
|
||||
@@ -205,7 +204,7 @@ void TrickleTimer::HandleTimerFired(void)
|
||||
mPhase = kPhaseInterval;
|
||||
|
||||
// Start the time for 'I - t' milliseconds
|
||||
mTimer.Start(I - t);
|
||||
Timer::Start(I - t);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#ifndef TRICKLE_TIMER_HPP_
|
||||
#define TRICKLE_TIMER_HPP_
|
||||
|
||||
#include "common/context.hpp"
|
||||
#include "common/timer.hpp"
|
||||
|
||||
namespace ot {
|
||||
@@ -52,7 +53,7 @@ namespace ot {
|
||||
* This class implements a trickle timer.
|
||||
*
|
||||
*/
|
||||
class TrickleTimer
|
||||
class TrickleTimer: public Timer
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -69,12 +70,12 @@ public:
|
||||
/**
|
||||
* This function pointer is called when the timer expires.
|
||||
*
|
||||
* @param[in] aContext A pointer to arbitrary context information.
|
||||
* @param[in] aTimer A reference to the expired timer.
|
||||
*
|
||||
* @retval TRUE If the trickle timer should continue running.
|
||||
* @retval FALSE If the trickle timer should stop running.
|
||||
*/
|
||||
typedef bool (*Handler)(void *aContext);
|
||||
typedef bool (*Handler)(TrickleTimer &aTimer);
|
||||
|
||||
/**
|
||||
* This constructor creates a trickle timer instance.
|
||||
@@ -110,6 +111,17 @@ public:
|
||||
*/
|
||||
void Start(uint32_t aIntervalMin, uint32_t aIntervalMax, Mode aMode);
|
||||
|
||||
/**
|
||||
* This method start the trickle timer.
|
||||
*
|
||||
* @param[in] aStartTime The start time.
|
||||
* @param[in] aIntervalMin The minimum interval for the timer, Imin.
|
||||
* @param[in] aIntervalMax The maximum interval for the timer, Imax.
|
||||
* @param[in] aMode The operating mode for the timer.
|
||||
*
|
||||
*/
|
||||
void StartAt(uint32_t aStartTime, uint32_t aIntervalMin, uint32_t aIntervalMax, Mode aMode);
|
||||
|
||||
/**
|
||||
* This method stops the trickle timer.
|
||||
*
|
||||
@@ -131,14 +143,17 @@ public:
|
||||
void IndicateInconsistent(void);
|
||||
|
||||
private:
|
||||
bool TransmitFired(void) { return mTransmitHandler(mContext); }
|
||||
bool IntervalExpiredFired(void) { return mIntervalExpiredHandler ? mIntervalExpiredHandler(mContext) : true; }
|
||||
bool TransmitFired(void) { return mTransmitHandler(*this); }
|
||||
bool IntervalExpiredFired(void) { return mIntervalExpiredHandler ? mIntervalExpiredHandler(*this) : true; }
|
||||
|
||||
void StartNewInterval(void);
|
||||
|
||||
static void HandleTimerFired(void *aContext);
|
||||
static void HandleTimerFired(Timer &aTimer);
|
||||
void HandleTimerFired(void);
|
||||
|
||||
// Shadow base class method to ensure it is hidden.
|
||||
void StartAt(void) { }
|
||||
|
||||
typedef enum Phase
|
||||
{
|
||||
///< Indicates we are currently not running
|
||||
@@ -149,8 +164,6 @@ private:
|
||||
kPhaseInterval = 3,
|
||||
} Phase;
|
||||
|
||||
Timer mTimer;
|
||||
|
||||
#ifdef ENABLE_TRICKLE_TIMER_SUPPRESSION_SUPPORT
|
||||
// Redundancy constant
|
||||
const uint32_t k;
|
||||
@@ -177,7 +190,6 @@ private:
|
||||
// Callback variables
|
||||
Handler mTransmitHandler;
|
||||
Handler mIntervalExpiredHandler;
|
||||
void *mContext;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
+49
-36
@@ -114,12 +114,12 @@ void Mac::StartCsmaBackoff(void)
|
||||
}
|
||||
|
||||
Mac::Mac(ThreadNetif &aThreadNetif):
|
||||
ThreadNetifLocator(aThreadNetif),
|
||||
mMacTimer(aThreadNetif.GetIp6().mTimerScheduler, &Mac::HandleMacTimer, this),
|
||||
#if !OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_BACKOFF_TIMER
|
||||
mBackoffTimer(aThreadNetif.GetIp6().mTimerScheduler, &Mac::HandleBeginTransmit, this),
|
||||
#endif
|
||||
mReceiveTimer(aThreadNetif.GetIp6().mTimerScheduler, &Mac::HandleReceiveTimer, this),
|
||||
mNetif(aThreadNetif),
|
||||
mShortAddress(kShortAddrInvalid),
|
||||
mPanId(kPanIdBroadcast),
|
||||
mChannel(OPENTHREAD_CONFIG_DEFAULT_CHANNEL),
|
||||
@@ -168,11 +168,6 @@ Mac::Mac(ThreadNetif &aThreadNetif):
|
||||
otPlatRadioEnable(GetInstance());
|
||||
}
|
||||
|
||||
otInstance *Mac::GetInstance(void)
|
||||
{
|
||||
return mNetif.GetInstance();
|
||||
}
|
||||
|
||||
otError Mac::ActiveScan(uint32_t aScanChannels, uint16_t aScanDuration, ActiveScanHandler aHandler, void *aContext)
|
||||
{
|
||||
otError error;
|
||||
@@ -372,9 +367,9 @@ exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void Mac::HandleEnergyScanSampleRssi(void *aContext)
|
||||
void Mac::HandleEnergyScanSampleRssi(Tasklet &aTasklet)
|
||||
{
|
||||
static_cast<Mac *>(aContext)->HandleEnergyScanSampleRssi();
|
||||
GetOwner(aTasklet).HandleEnergyScanSampleRssi();
|
||||
}
|
||||
|
||||
void Mac::HandleEnergyScanSampleRssi(void)
|
||||
@@ -667,12 +662,12 @@ void Mac::SendBeacon(Frame &aFrame)
|
||||
|
||||
beaconPayload = reinterpret_cast<BeaconPayload *>(beacon->GetPayload());
|
||||
|
||||
if (mNetif.GetKeyManager().GetSecurityPolicyFlags() & OT_SECURITY_POLICY_BEACONS)
|
||||
if (GetNetif().GetKeyManager().GetSecurityPolicyFlags() & OT_SECURITY_POLICY_BEACONS)
|
||||
{
|
||||
beaconPayload->Init();
|
||||
|
||||
// set the Joining Permitted flag
|
||||
mNetif.GetIp6Filter().GetUnsecurePorts(numUnsecurePorts);
|
||||
GetNetif().GetIp6Filter().GetUnsecurePorts(numUnsecurePorts);
|
||||
|
||||
if (numUnsecurePorts)
|
||||
{
|
||||
@@ -698,6 +693,7 @@ void Mac::SendBeacon(Frame &aFrame)
|
||||
|
||||
void Mac::ProcessTransmitSecurity(Frame &aFrame)
|
||||
{
|
||||
KeyManager &keyManager = GetNetif().GetKeyManager();
|
||||
uint32_t frameCounter = 0;
|
||||
uint8_t securityLevel;
|
||||
uint8_t keyIdMode;
|
||||
@@ -717,19 +713,19 @@ void Mac::ProcessTransmitSecurity(Frame &aFrame)
|
||||
switch (keyIdMode)
|
||||
{
|
||||
case Frame::kKeyIdMode0:
|
||||
key = mNetif.GetKeyManager().GetKek();
|
||||
key = keyManager.GetKek();
|
||||
extAddress = &mExtAddress;
|
||||
|
||||
if (!aFrame.IsARetransmission())
|
||||
{
|
||||
aFrame.SetFrameCounter(mNetif.GetKeyManager().GetKekFrameCounter());
|
||||
mNetif.GetKeyManager().IncrementKekFrameCounter();
|
||||
aFrame.SetFrameCounter(keyManager.GetKekFrameCounter());
|
||||
keyManager.IncrementKekFrameCounter();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case Frame::kKeyIdMode1:
|
||||
key = mNetif.GetKeyManager().GetCurrentMacKey();
|
||||
key = keyManager.GetCurrentMacKey();
|
||||
extAddress = &mExtAddress;
|
||||
|
||||
// If the frame is marked as a retransmission, the `Mac::Sender` which
|
||||
@@ -740,9 +736,9 @@ void Mac::ProcessTransmitSecurity(Frame &aFrame)
|
||||
|
||||
if (!aFrame.IsARetransmission())
|
||||
{
|
||||
aFrame.SetFrameCounter(mNetif.GetKeyManager().GetMacFrameCounter());
|
||||
mNetif.GetKeyManager().IncrementMacFrameCounter();
|
||||
aFrame.SetKeyId((mNetif.GetKeyManager().GetCurrentKeySequence() & 0x7f) + 1);
|
||||
aFrame.SetFrameCounter(keyManager.GetMacFrameCounter());
|
||||
keyManager.IncrementMacFrameCounter();
|
||||
aFrame.SetKeyId((keyManager.GetCurrentKeySequence() & 0x7f) + 1);
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -787,6 +783,11 @@ void Mac::HandleBeginTransmit(void *aContext)
|
||||
static_cast<Mac *>(aContext)->HandleBeginTransmit();
|
||||
}
|
||||
|
||||
void Mac::HandleBeginTransmit(Timer &aTimer)
|
||||
{
|
||||
GetOwner(aTimer).HandleBeginTransmit();
|
||||
}
|
||||
|
||||
void Mac::HandleBeginTransmit(void)
|
||||
{
|
||||
Frame &sendFrame(*mTxFrame);
|
||||
@@ -1002,7 +1003,7 @@ void Mac::TransmitDoneTask(otRadioFrame *aFrame, otRadioFrame *aAckFrame, otErro
|
||||
Neighbor *neighbor;
|
||||
|
||||
framePending = ackFrame->GetFramePending();
|
||||
neighbor = mNetif.GetMle().GetNeighbor(addr);
|
||||
neighbor = GetNetif().GetMle().GetNeighbor(addr);
|
||||
|
||||
if (neighbor != NULL)
|
||||
{
|
||||
@@ -1124,9 +1125,9 @@ void Mac::RadioSleep(void)
|
||||
}
|
||||
}
|
||||
|
||||
void Mac::HandleMacTimer(void *aContext)
|
||||
void Mac::HandleMacTimer(Timer &aTimer)
|
||||
{
|
||||
static_cast<Mac *>(aContext)->HandleMacTimer();
|
||||
GetOwner(aTimer).HandleMacTimer();
|
||||
}
|
||||
|
||||
void Mac::HandleMacTimer(void)
|
||||
@@ -1189,9 +1190,9 @@ exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void Mac::HandleReceiveTimer(void *aContext)
|
||||
void Mac::HandleReceiveTimer(Timer &aTimer)
|
||||
{
|
||||
static_cast<Mac *>(aContext)->HandleReceiveTimer();
|
||||
GetOwner(aTimer).HandleReceiveTimer();
|
||||
}
|
||||
|
||||
void Mac::HandleReceiveTimer(void)
|
||||
@@ -1322,6 +1323,7 @@ exit:
|
||||
|
||||
otError Mac::ProcessReceiveSecurity(Frame &aFrame, const Address &aSrcAddr, Neighbor *aNeighbor)
|
||||
{
|
||||
KeyManager &keyManager = GetNetif().GetKeyManager();
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint8_t securityLevel;
|
||||
uint8_t keyIdMode;
|
||||
@@ -1351,7 +1353,7 @@ otError Mac::ProcessReceiveSecurity(Frame &aFrame, const Address &aSrcAddr, Neig
|
||||
switch (keyIdMode)
|
||||
{
|
||||
case Frame::kKeyIdMode0:
|
||||
VerifyOrExit((macKey = mNetif.GetKeyManager().GetKek()) != NULL, error = OT_ERROR_SECURITY);
|
||||
VerifyOrExit((macKey = keyManager.GetKek()) != NULL, error = OT_ERROR_SECURITY);
|
||||
extAddress = &aSrcAddr.mExtAddress;
|
||||
break;
|
||||
|
||||
@@ -1361,23 +1363,23 @@ otError Mac::ProcessReceiveSecurity(Frame &aFrame, const Address &aSrcAddr, Neig
|
||||
aFrame.GetKeyId(keyid);
|
||||
keyid--;
|
||||
|
||||
if (keyid == (mNetif.GetKeyManager().GetCurrentKeySequence() & 0x7f))
|
||||
if (keyid == (keyManager.GetCurrentKeySequence() & 0x7f))
|
||||
{
|
||||
// same key index
|
||||
keySequence = mNetif.GetKeyManager().GetCurrentKeySequence();
|
||||
macKey = mNetif.GetKeyManager().GetCurrentMacKey();
|
||||
keySequence = keyManager.GetCurrentKeySequence();
|
||||
macKey = keyManager.GetCurrentMacKey();
|
||||
}
|
||||
else if (keyid == ((mNetif.GetKeyManager().GetCurrentKeySequence() - 1) & 0x7f))
|
||||
else if (keyid == ((keyManager.GetCurrentKeySequence() - 1) & 0x7f))
|
||||
{
|
||||
// previous key index
|
||||
keySequence = mNetif.GetKeyManager().GetCurrentKeySequence() - 1;
|
||||
macKey = mNetif.GetKeyManager().GetTemporaryMacKey(keySequence);
|
||||
keySequence = keyManager.GetCurrentKeySequence() - 1;
|
||||
macKey = keyManager.GetTemporaryMacKey(keySequence);
|
||||
}
|
||||
else if (keyid == ((mNetif.GetKeyManager().GetCurrentKeySequence() + 1) & 0x7f))
|
||||
else if (keyid == ((keyManager.GetCurrentKeySequence() + 1) & 0x7f))
|
||||
{
|
||||
// next key index
|
||||
keySequence = mNetif.GetKeyManager().GetCurrentKeySequence() + 1;
|
||||
macKey = mNetif.GetKeyManager().GetTemporaryMacKey(keySequence);
|
||||
keySequence = keyManager.GetCurrentKeySequence() + 1;
|
||||
macKey = keyManager.GetTemporaryMacKey(keySequence);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1444,9 +1446,9 @@ otError Mac::ProcessReceiveSecurity(Frame &aFrame, const Address &aSrcAddr, Neig
|
||||
|
||||
aNeighbor->SetLinkFrameCounter(frameCounter + 1);
|
||||
|
||||
if (keySequence > mNetif.GetKeyManager().GetCurrentKeySequence())
|
||||
if (keySequence > keyManager.GetCurrentKeySequence())
|
||||
{
|
||||
mNetif.GetKeyManager().SetCurrentKeySequence(keySequence);
|
||||
keyManager.SetCurrentKeySequence(keySequence);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1506,7 +1508,7 @@ void Mac::ReceiveDoneTask(Frame *aFrame, otError aError)
|
||||
SuccessOrExit(error = aFrame->ValidatePsdu());
|
||||
|
||||
aFrame->GetSrcAddr(srcaddr);
|
||||
neighbor = mNetif.GetMle().GetNeighbor(srcaddr);
|
||||
neighbor = GetNetif().GetMle().GetNeighbor(srcaddr);
|
||||
|
||||
switch (srcaddr.mLength)
|
||||
{
|
||||
@@ -1857,7 +1859,7 @@ bool Mac::IsBeaconJoinable(void)
|
||||
uint8_t numUnsecurePorts;
|
||||
bool joinable = false;
|
||||
|
||||
mNetif.GetIp6Filter().GetUnsecurePorts(numUnsecurePorts);
|
||||
GetNetif().GetIp6Filter().GetUnsecurePorts(numUnsecurePorts);
|
||||
|
||||
if (numUnsecurePorts)
|
||||
{
|
||||
@@ -1872,5 +1874,16 @@ bool Mac::IsBeaconJoinable(void)
|
||||
}
|
||||
#endif // OPENTHREAD_CONFIG_ENABLE_BEACON_RSP_IF_JOINABLE
|
||||
|
||||
Mac &Mac::GetOwner(const Context &aContext)
|
||||
{
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
Mac &mac = *static_cast<Mac *>(aContext.GetContext());
|
||||
#else
|
||||
Mac &mac = otGetInstance()->mThreadNetif.GetMac();
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
#endif
|
||||
return mac;
|
||||
}
|
||||
|
||||
} // namespace Mac
|
||||
} // namespace ot
|
||||
|
||||
+35
-41
@@ -37,6 +37,8 @@
|
||||
#include <openthread/platform/radio.h>
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
#include "common/context.hpp"
|
||||
#include "common/locator.hpp"
|
||||
#include "common/tasklet.hpp"
|
||||
#include "common/timer.hpp"
|
||||
#include "mac/mac_blacklist.hpp"
|
||||
@@ -101,7 +103,7 @@ enum
|
||||
* This class implements a MAC receiver client.
|
||||
*
|
||||
*/
|
||||
class Receiver
|
||||
class Receiver: public Context
|
||||
{
|
||||
friend class Mac;
|
||||
|
||||
@@ -109,20 +111,20 @@ public:
|
||||
/**
|
||||
* This function pointer is called when a MAC frame is received.
|
||||
*
|
||||
* @param[in] aContext A pointer to arbitrary context information.
|
||||
* @param[in] aReceiver A reference to the MAC receiver client object.
|
||||
* @param[in] aFrame A reference to the MAC frame.
|
||||
*
|
||||
*/
|
||||
typedef void (*ReceiveFrameHandler)(void *aContext, Frame &aFrame);
|
||||
typedef void (*ReceiveFrameHandler)(Receiver &aReceiver, Frame &aFrame);
|
||||
|
||||
/**
|
||||
* This function pointer is called on a data request command (data poll) timeout, i.e., when the ack in response to
|
||||
* a data request command indicated a frame is pending, but no frame was received after `kDataPollTimeout` interval.
|
||||
*
|
||||
* @param[in] aContext A pointer to arbitrary context information.
|
||||
* @param[in] aReceiver A reference to the MAC receiver client object.
|
||||
*
|
||||
*/
|
||||
typedef void (*DataPollTimeoutHandler)(void *aContext);
|
||||
typedef void (*DataPollTimeoutHandler)(Receiver &aReceiver);
|
||||
|
||||
/**
|
||||
* This constructor creates a MAC receiver client.
|
||||
@@ -132,24 +134,24 @@ public:
|
||||
* @param[in] aContext A pointer to arbitrary context information.
|
||||
*
|
||||
*/
|
||||
Receiver(ReceiveFrameHandler aReceiveFrameHandler, DataPollTimeoutHandler aPollTimeoutHandler, void *aContext) {
|
||||
mReceiveFrameHandler = aReceiveFrameHandler;
|
||||
mPollTimeoutHandler = aPollTimeoutHandler;
|
||||
mContext = aContext;
|
||||
mNext = NULL;
|
||||
Receiver(ReceiveFrameHandler aReceiveFrameHandler, DataPollTimeoutHandler aPollTimeoutHandler, void *aContext):
|
||||
Context(aContext),
|
||||
mReceiveFrameHandler(aReceiveFrameHandler),
|
||||
mPollTimeoutHandler(aPollTimeoutHandler),
|
||||
mNext(NULL) {
|
||||
}
|
||||
|
||||
private:
|
||||
void HandleReceivedFrame(Frame &frame) { mReceiveFrameHandler(mContext, frame); }
|
||||
void HandleReceivedFrame(Frame &frame) { mReceiveFrameHandler(*this, frame); }
|
||||
|
||||
void HandleDataPollTimeout(void) {
|
||||
if (mPollTimeoutHandler != NULL) {
|
||||
mPollTimeoutHandler(mContext);
|
||||
mPollTimeoutHandler(*this);
|
||||
}
|
||||
}
|
||||
|
||||
ReceiveFrameHandler mReceiveFrameHandler;
|
||||
DataPollTimeoutHandler mPollTimeoutHandler;
|
||||
void *mContext;
|
||||
Receiver *mNext;
|
||||
};
|
||||
|
||||
@@ -157,7 +159,7 @@ private:
|
||||
* This class implements a MAC sender client.
|
||||
*
|
||||
*/
|
||||
class Sender
|
||||
class Sender: public Context
|
||||
{
|
||||
friend class Mac;
|
||||
|
||||
@@ -165,21 +167,21 @@ public:
|
||||
/**
|
||||
* This function pointer is called when the MAC is about to transmit the frame.
|
||||
*
|
||||
* @param[in] aContext A pointer to arbitrary context information.
|
||||
* @param[in] aSender A reference to the MAC sender client object.
|
||||
* @param[in] aFrame A reference to the MAC frame buffer.
|
||||
*
|
||||
*/
|
||||
typedef otError(*FrameRequestHandler)(void *aContext, Frame &aFrame);
|
||||
typedef otError(*FrameRequestHandler)(Sender &aSender, Frame &aFrame);
|
||||
|
||||
/**
|
||||
* This function pointer is called when the MAC is done sending the frame.
|
||||
*
|
||||
* @param[in] aContext A pointer to arbitrary context information.
|
||||
* @param[in] aSender A reference to the MAC sender client object.
|
||||
* @param[in] aFrame A reference to the MAC frame buffer that was sent.
|
||||
* @param[in] aError The status of the last MSDU transmission.
|
||||
*
|
||||
*/
|
||||
typedef void (*SentFrameHandler)(void *aContext, Frame &aFrame, otError aError);
|
||||
typedef void (*SentFrameHandler)(Sender &aSender, Frame &aFrame, otError aError);
|
||||
|
||||
/**
|
||||
* This constructor creates a MAC sender client.
|
||||
@@ -189,20 +191,19 @@ public:
|
||||
* @param[in] aContext A pointer to arbitrary context information.
|
||||
*
|
||||
*/
|
||||
Sender(FrameRequestHandler aFrameRequestHandler, SentFrameHandler aSentFrameHandler, void *aContext) {
|
||||
mFrameRequestHandler = aFrameRequestHandler;
|
||||
mSentFrameHandler = aSentFrameHandler;
|
||||
mContext = aContext;
|
||||
mNext = NULL;
|
||||
Sender(FrameRequestHandler aFrameRequestHandler, SentFrameHandler aSentFrameHandler, void *aContext):
|
||||
Context(aContext),
|
||||
mFrameRequestHandler(aFrameRequestHandler),
|
||||
mSentFrameHandler(aSentFrameHandler),
|
||||
mNext(NULL) {
|
||||
}
|
||||
|
||||
private:
|
||||
otError HandleFrameRequest(Frame &frame) { return mFrameRequestHandler(mContext, frame); }
|
||||
void HandleSentFrame(Frame &frame, otError error) { mSentFrameHandler(mContext, frame, error); }
|
||||
otError HandleFrameRequest(Frame &frame) { return mFrameRequestHandler(*this, frame); }
|
||||
void HandleSentFrame(Frame &frame, otError error) { mSentFrameHandler(*this, frame, error); }
|
||||
|
||||
FrameRequestHandler mFrameRequestHandler;
|
||||
SentFrameHandler mSentFrameHandler;
|
||||
void *mContext;
|
||||
Sender *mNext;
|
||||
};
|
||||
|
||||
@@ -210,7 +211,7 @@ private:
|
||||
* This class implements the IEEE 802.15.4 MAC.
|
||||
*
|
||||
*/
|
||||
class Mac
|
||||
class Mac: public ThreadNetifLocator
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -221,14 +222,6 @@ public:
|
||||
*/
|
||||
explicit Mac(ThreadNetif &aThreadNetif);
|
||||
|
||||
/**
|
||||
* This method returns the pointer to the parent otInstance structure.
|
||||
*
|
||||
* @returns The pointer to the parent otInstance structure.
|
||||
*
|
||||
*/
|
||||
otInstance *GetInstance(void);
|
||||
|
||||
/**
|
||||
* This function pointer is called on receiving an IEEE 802.15.4 Beacon during an Active Scan.
|
||||
*
|
||||
@@ -256,7 +249,7 @@ public:
|
||||
* @param[out] aResult A reference to `otActiveScanResult` where the result is stored.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully converted the beacon into active scan result.
|
||||
* @retavl OT_ERROR_INVALID_ARGS The @a aBeaconFrame was NULL.
|
||||
* @retval OT_ERROR_INVALID_ARGS The @a aBeaconFrame was NULL.
|
||||
* @retval OT_ERROR_PARSE Failed parsing the beacon frame.
|
||||
*
|
||||
*/
|
||||
@@ -679,13 +672,14 @@ private:
|
||||
void StartEnergyScan(void);
|
||||
otError HandleMacCommand(Frame &aFrame);
|
||||
|
||||
static void HandleMacTimer(void *aContext);
|
||||
static void HandleMacTimer(Timer &aTimer);
|
||||
void HandleMacTimer(void);
|
||||
static void HandleBeginTransmit(void *aContext);
|
||||
static void HandleBeginTransmit(Timer &aTimer);
|
||||
void HandleBeginTransmit(void);
|
||||
static void HandleReceiveTimer(void *aContext);
|
||||
static void HandleReceiveTimer(Timer &aTimer);
|
||||
void HandleReceiveTimer(void);
|
||||
static void HandleEnergyScanSampleRssi(void *aContext);
|
||||
static void HandleEnergyScanSampleRssi(Tasklet &aTasklet);
|
||||
void HandleEnergyScanSampleRssi(void);
|
||||
|
||||
void StartCsmaBackoff(void);
|
||||
@@ -695,14 +689,14 @@ private:
|
||||
otError RadioReceive(uint8_t aChannel);
|
||||
void RadioSleep(void);
|
||||
|
||||
static Mac &GetOwner(const Context &aContext);
|
||||
|
||||
Timer mMacTimer;
|
||||
#if !OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_BACKOFF_TIMER
|
||||
Timer mBackoffTimer;
|
||||
#endif
|
||||
Timer mReceiveTimer;
|
||||
|
||||
ThreadNetif &mNetif;
|
||||
|
||||
ExtAddress mExtAddress;
|
||||
ShortAddress mShortAddress;
|
||||
PanId mPanId;
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
|
||||
#include <openthread/platform/random.h>
|
||||
|
||||
#include "openthread-instance.h"
|
||||
#include "coap/coap_header.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
@@ -52,16 +53,11 @@
|
||||
|
||||
namespace ot {
|
||||
|
||||
AnnounceBeginClient::AnnounceBeginClient(ThreadNetif &aThreadNetif) :
|
||||
mNetif(aThreadNetif)
|
||||
AnnounceBeginClient::AnnounceBeginClient(ThreadNetif &aThreadNetif):
|
||||
ThreadNetifLocator(aThreadNetif)
|
||||
{
|
||||
}
|
||||
|
||||
otInstance *AnnounceBeginClient::GetInstance(void)
|
||||
{
|
||||
return mNetif.GetInstance();
|
||||
}
|
||||
|
||||
otError AnnounceBeginClient::SendRequest(uint32_t aChannelMask, uint8_t aCount, uint16_t aPeriod,
|
||||
const Ip6::Address &aAddress)
|
||||
{
|
||||
@@ -75,7 +71,7 @@ otError AnnounceBeginClient::SendRequest(uint32_t aChannelMask, uint8_t aCount,
|
||||
Ip6::MessageInfo messageInfo;
|
||||
Message *message = NULL;
|
||||
|
||||
VerifyOrExit(mNetif.GetCommissioner().IsActive(), error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(GetNetif().GetCommissioner().IsActive(), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
header.Init(aAddress.IsMulticast() ? OT_COAP_TYPE_NON_CONFIRMABLE : OT_COAP_TYPE_CONFIRMABLE,
|
||||
OT_COAP_CODE_POST);
|
||||
@@ -83,11 +79,11 @@ otError AnnounceBeginClient::SendRequest(uint32_t aChannelMask, uint8_t aCount,
|
||||
header.AppendUriPathOptions(OT_URI_PATH_ANNOUNCE_BEGIN);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(mNetif.GetCoap(), header)) != NULL,
|
||||
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(GetNetif().GetCoap(), header)) != NULL,
|
||||
error = OT_ERROR_NO_BUFS);
|
||||
|
||||
sessionId.Init();
|
||||
sessionId.SetCommissionerSessionId(mNetif.GetCommissioner().GetSessionId());
|
||||
sessionId.SetCommissionerSessionId(GetNetif().GetCommissioner().GetSessionId());
|
||||
SuccessOrExit(error = message->Append(&sessionId, sizeof(sessionId)));
|
||||
|
||||
channelMask.Init();
|
||||
@@ -102,12 +98,12 @@ otError AnnounceBeginClient::SendRequest(uint32_t aChannelMask, uint8_t aCount,
|
||||
period.SetPeriod(aPeriod);
|
||||
SuccessOrExit(error = message->Append(&period, sizeof(period)));
|
||||
|
||||
messageInfo.SetSockAddr(mNetif.GetMle().GetMeshLocal16());
|
||||
messageInfo.SetSockAddr(GetNetif().GetMle().GetMeshLocal16());
|
||||
messageInfo.SetPeerAddr(aAddress);
|
||||
messageInfo.SetPeerPort(kCoapUdpPort);
|
||||
messageInfo.SetInterfaceId(mNetif.GetInterfaceId());
|
||||
messageInfo.SetInterfaceId(GetNetif().GetInterfaceId());
|
||||
|
||||
SuccessOrExit(error = mNetif.GetCoap().SendMessage(*message, messageInfo));
|
||||
SuccessOrExit(error = GetNetif().GetCoap().SendMessage(*message, messageInfo));
|
||||
|
||||
otLogInfoMeshCoP(GetInstance(), "sent announce begin query");
|
||||
|
||||
|
||||
@@ -35,19 +35,18 @@
|
||||
#define ANNOUNCE_BEGIN_CLIENT_HPP_
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
#include "common/locator.hpp"
|
||||
#include "coap/coap.hpp"
|
||||
#include "net/ip6_address.hpp"
|
||||
#include "net/udp6.hpp"
|
||||
|
||||
namespace ot {
|
||||
|
||||
class ThreadNetif;
|
||||
|
||||
/**
|
||||
* This class implements handling Announce Begin Requests.
|
||||
*
|
||||
*/
|
||||
class AnnounceBeginClient
|
||||
class AnnounceBeginClient: public ThreadNetifLocator
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -56,14 +55,6 @@ public:
|
||||
*/
|
||||
AnnounceBeginClient(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 Announce Begin message.
|
||||
*
|
||||
@@ -76,9 +67,6 @@ public:
|
||||
*
|
||||
*/
|
||||
otError SendRequest(uint32_t aChannelMask, uint8_t aCount, uint16_t mPeriod, const Ip6::Address &aAddress);
|
||||
|
||||
private:
|
||||
ThreadNetif &mNetif;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include <openthread/types.h>
|
||||
#include <openthread/platform/random.h>
|
||||
|
||||
#include "openthread-instance.h"
|
||||
#include "coap/coap_header.hpp"
|
||||
#include "common/encoding.hpp"
|
||||
#include "common/logging.hpp"
|
||||
@@ -62,6 +63,7 @@ namespace ot {
|
||||
namespace MeshCoP {
|
||||
|
||||
Commissioner::Commissioner(ThreadNetif &aThreadNetif):
|
||||
ThreadNetifLocator(aThreadNetif),
|
||||
mAnnounceBegin(aThreadNetif),
|
||||
mEnergyScan(aThreadNetif),
|
||||
mPanIdQuery(aThreadNetif),
|
||||
@@ -74,29 +76,27 @@ Commissioner::Commissioner(ThreadNetif &aThreadNetif):
|
||||
mTransmitAttempts(0),
|
||||
mRelayReceive(OT_URI_PATH_RELAY_RX, &Commissioner::HandleRelayReceive, this),
|
||||
mDatasetChanged(OT_URI_PATH_DATASET_CHANGED, &Commissioner::HandleDatasetChanged, this),
|
||||
mJoinerFinalize(OT_URI_PATH_JOINER_FINALIZE, &Commissioner::HandleJoinerFinalize, this),
|
||||
mNetif(aThreadNetif)
|
||||
mJoinerFinalize(OT_URI_PATH_JOINER_FINALIZE, &Commissioner::HandleJoinerFinalize, this)
|
||||
{
|
||||
memset(mJoiners, 0, sizeof(mJoiners));
|
||||
}
|
||||
|
||||
otInstance *Commissioner::GetInstance(void)
|
||||
{
|
||||
return mNetif.GetInstance();
|
||||
}
|
||||
|
||||
void Commissioner::AddCoapResources(void)
|
||||
{
|
||||
mNetif.GetCoap().AddResource(mRelayReceive);
|
||||
mNetif.GetCoap().AddResource(mDatasetChanged);
|
||||
mNetif.GetCoapSecure().AddResource(mJoinerFinalize);
|
||||
ThreadNetif &netif = GetNetif();
|
||||
|
||||
netif.GetCoap().AddResource(mRelayReceive);
|
||||
netif.GetCoap().AddResource(mDatasetChanged);
|
||||
netif.GetCoapSecure().AddResource(mJoinerFinalize);
|
||||
}
|
||||
|
||||
void Commissioner::RemoveCoapResources(void)
|
||||
{
|
||||
mNetif.GetCoap().RemoveResource(mRelayReceive);
|
||||
mNetif.GetCoap().RemoveResource(mDatasetChanged);
|
||||
mNetif.GetCoapSecure().RemoveResource(mJoinerFinalize);
|
||||
ThreadNetif &netif = GetNetif();
|
||||
|
||||
netif.GetCoap().RemoveResource(mRelayReceive);
|
||||
netif.GetCoap().RemoveResource(mDatasetChanged);
|
||||
netif.GetCoapSecure().RemoveResource(mJoinerFinalize);
|
||||
}
|
||||
|
||||
otError Commissioner::Start(void)
|
||||
@@ -106,7 +106,7 @@ otError Commissioner::Start(void)
|
||||
otLogFuncEntry();
|
||||
VerifyOrExit(mState == OT_COMMISSIONER_STATE_DISABLED, error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
SuccessOrExit(error = mNetif.GetCoapSecure().Start(OPENTHREAD_CONFIG_JOINER_UDP_PORT, SendRelayTransmit, this));
|
||||
SuccessOrExit(error = GetNetif().GetCoapSecure().Start(OPENTHREAD_CONFIG_JOINER_UDP_PORT, SendRelayTransmit, this));
|
||||
|
||||
mState = OT_COMMISSIONER_STATE_PETITION;
|
||||
mTransmitAttempts = 0;
|
||||
@@ -125,7 +125,7 @@ otError Commissioner::Stop(void)
|
||||
otLogFuncEntry();
|
||||
VerifyOrExit(mState != OT_COMMISSIONER_STATE_DISABLED, error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
mNetif.GetCoapSecure().Stop();
|
||||
GetNetif().GetCoapSecure().Stop();
|
||||
|
||||
mState = OT_COMMISSIONER_STATE_DISABLED;
|
||||
RemoveCoapResources();
|
||||
@@ -133,7 +133,7 @@ otError Commissioner::Stop(void)
|
||||
|
||||
mTimer.Stop();
|
||||
|
||||
mNetif.GetDtls().Stop();
|
||||
GetNetif().GetDtls().Stop();
|
||||
|
||||
SendKeepAlive();
|
||||
|
||||
@@ -301,7 +301,7 @@ exit:
|
||||
|
||||
otError Commissioner::SetProvisioningUrl(const char *aProvisioningUrl)
|
||||
{
|
||||
return mNetif.GetDtls().mProvisioningUrl.SetProvisioningUrl(aProvisioningUrl);
|
||||
return GetNetif().GetDtls().mProvisioningUrl.SetProvisioningUrl(aProvisioningUrl);
|
||||
}
|
||||
|
||||
uint16_t Commissioner::GetSessionId(void) const
|
||||
@@ -314,9 +314,9 @@ otCommissionerState Commissioner::GetState(void) const
|
||||
return mState;
|
||||
}
|
||||
|
||||
void Commissioner::HandleTimer(void *aContext)
|
||||
void Commissioner::HandleTimer(Timer &aTimer)
|
||||
{
|
||||
static_cast<Commissioner *>(aContext)->HandleTimer();
|
||||
GetOwner(aTimer).HandleTimer();
|
||||
}
|
||||
|
||||
void Commissioner::HandleTimer(void)
|
||||
@@ -336,9 +336,9 @@ void Commissioner::HandleTimer(void)
|
||||
}
|
||||
}
|
||||
|
||||
void Commissioner::HandleJoinerExpirationTimer(void *aContext)
|
||||
void Commissioner::HandleJoinerExpirationTimer(Timer &aTimer)
|
||||
{
|
||||
static_cast<Commissioner *>(aContext)->HandleJoinerExpirationTimer();
|
||||
GetOwner(aTimer).HandleJoinerExpirationTimer();
|
||||
}
|
||||
|
||||
void Commissioner::HandleJoinerExpirationTimer(void)
|
||||
@@ -399,6 +399,7 @@ void Commissioner::UpdateJoinerExpirationTimer(void)
|
||||
otError Commissioner::SendMgmtCommissionerGetRequest(const uint8_t *aTlvs,
|
||||
uint8_t aLength)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
Coap::Header header;
|
||||
Message *message;
|
||||
@@ -416,7 +417,7 @@ otError Commissioner::SendMgmtCommissionerGetRequest(const uint8_t *aTlvs,
|
||||
header.SetPayloadMarker();
|
||||
}
|
||||
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoap(), header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
VerifyOrExit((message = NewMeshCoPMessage(netif.GetCoap(), header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
if (aLength > 0)
|
||||
{
|
||||
@@ -426,11 +427,11 @@ otError Commissioner::SendMgmtCommissionerGetRequest(const uint8_t *aTlvs,
|
||||
SuccessOrExit(error = message->Append(aTlvs, aLength));
|
||||
}
|
||||
|
||||
messageInfo.SetSockAddr(mNetif.GetMle().GetMeshLocal16());
|
||||
mNetif.GetMle().GetLeaderAloc(messageInfo.GetPeerAddr());
|
||||
messageInfo.SetSockAddr(netif.GetMle().GetMeshLocal16());
|
||||
netif.GetMle().GetLeaderAloc(messageInfo.GetPeerAddr());
|
||||
messageInfo.SetPeerPort(kCoapUdpPort);
|
||||
SuccessOrExit(error = mNetif.GetCoap().SendMessage(*message, messageInfo,
|
||||
Commissioner::HandleMgmtCommissionerGetResponse, this));
|
||||
SuccessOrExit(error = netif.GetCoap().SendMessage(*message, messageInfo,
|
||||
Commissioner::HandleMgmtCommissionerGetResponse, this));
|
||||
|
||||
otLogInfoMeshCoP(GetInstance(), "sent MGMT_COMMISSIONER_GET.req to leader");
|
||||
|
||||
@@ -471,6 +472,7 @@ exit:
|
||||
otError Commissioner::SendMgmtCommissionerSetRequest(const otCommissioningDataset &aDataset,
|
||||
const uint8_t *aTlvs, uint8_t aLength)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
Coap::Header header;
|
||||
Message *message;
|
||||
@@ -483,7 +485,7 @@ otError Commissioner::SendMgmtCommissionerSetRequest(const otCommissioningDatase
|
||||
header.AppendUriPathOptions(OT_URI_PATH_COMMISSIONER_SET);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoap(), header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
VerifyOrExit((message = NewMeshCoPMessage(netif.GetCoap(), header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
if (aDataset.mIsLocatorSet)
|
||||
{
|
||||
@@ -529,11 +531,11 @@ otError Commissioner::SendMgmtCommissionerSetRequest(const otCommissioningDatase
|
||||
message->SetLength(message->GetLength() - 1);
|
||||
}
|
||||
|
||||
messageInfo.SetSockAddr(mNetif.GetMle().GetMeshLocal16());
|
||||
mNetif.GetMle().GetLeaderAloc(messageInfo.GetPeerAddr());
|
||||
messageInfo.SetSockAddr(netif.GetMle().GetMeshLocal16());
|
||||
netif.GetMle().GetLeaderAloc(messageInfo.GetPeerAddr());
|
||||
messageInfo.SetPeerPort(kCoapUdpPort);
|
||||
SuccessOrExit(error = mNetif.GetCoap().SendMessage(*message, messageInfo,
|
||||
Commissioner::HandleMgmtCommissionerSetResponse, this));
|
||||
SuccessOrExit(error = netif.GetCoap().SendMessage(*message, messageInfo,
|
||||
Commissioner::HandleMgmtCommissionerSetResponse, this));
|
||||
|
||||
otLogInfoMeshCoP(GetInstance(), "sent MGMT_COMMISSIONER_SET.req to leader");
|
||||
|
||||
@@ -573,6 +575,7 @@ exit:
|
||||
|
||||
otError Commissioner::SendPetition(void)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
Coap::Header header;
|
||||
Message *message = NULL;
|
||||
@@ -588,18 +591,18 @@ otError Commissioner::SendPetition(void)
|
||||
header.AppendUriPathOptions(OT_URI_PATH_LEADER_PETITION);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoap(), header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
VerifyOrExit((message = NewMeshCoPMessage(netif.GetCoap(), header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
commissionerId.Init();
|
||||
commissionerId.SetCommissionerId("OpenThread Commissioner");
|
||||
|
||||
SuccessOrExit(error = message->Append(&commissionerId, sizeof(Tlv) + commissionerId.GetLength()));
|
||||
|
||||
mNetif.GetMle().GetLeaderAloc(messageInfo.GetPeerAddr());
|
||||
netif.GetMle().GetLeaderAloc(messageInfo.GetPeerAddr());
|
||||
messageInfo.SetPeerPort(kCoapUdpPort);
|
||||
messageInfo.SetSockAddr(mNetif.GetMle().GetMeshLocal16());
|
||||
SuccessOrExit(error = mNetif.GetCoap().SendMessage(*message, messageInfo,
|
||||
Commissioner::HandleLeaderPetitionResponse, this));
|
||||
messageInfo.SetSockAddr(netif.GetMle().GetMeshLocal16());
|
||||
SuccessOrExit(error = netif.GetCoap().SendMessage(*message, messageInfo,
|
||||
Commissioner::HandleLeaderPetitionResponse, this));
|
||||
|
||||
otLogInfoMeshCoP(GetInstance(), "sent petition");
|
||||
|
||||
@@ -673,6 +676,7 @@ exit:
|
||||
|
||||
otError Commissioner::SendKeepAlive(void)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
Coap::Header header;
|
||||
Message *message = NULL;
|
||||
@@ -687,7 +691,7 @@ otError Commissioner::SendKeepAlive(void)
|
||||
header.AppendUriPathOptions(OT_URI_PATH_LEADER_KEEP_ALIVE);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoap(), header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
VerifyOrExit((message = NewMeshCoPMessage(netif.GetCoap(), header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
state.Init();
|
||||
state.SetState(mState == OT_COMMISSIONER_STATE_ACTIVE ? StateTlv::kAccept : StateTlv::kReject);
|
||||
@@ -697,11 +701,11 @@ otError Commissioner::SendKeepAlive(void)
|
||||
sessionId.SetCommissionerSessionId(mSessionId);
|
||||
SuccessOrExit(error = message->Append(&sessionId, sizeof(sessionId)));
|
||||
|
||||
messageInfo.SetSockAddr(mNetif.GetMle().GetMeshLocal16());
|
||||
mNetif.GetMle().GetLeaderAloc(messageInfo.GetPeerAddr());
|
||||
messageInfo.SetSockAddr(netif.GetMle().GetMeshLocal16());
|
||||
netif.GetMle().GetLeaderAloc(messageInfo.GetPeerAddr());
|
||||
messageInfo.SetPeerPort(kCoapUdpPort);
|
||||
SuccessOrExit(error = mNetif.GetCoap().SendMessage(*message, messageInfo,
|
||||
Commissioner::HandleLeaderKeepAliveResponse, this));
|
||||
SuccessOrExit(error = netif.GetCoap().SendMessage(*message, messageInfo,
|
||||
Commissioner::HandleLeaderKeepAliveResponse, this));
|
||||
|
||||
otLogInfoMeshCoP(GetInstance(), "sent keep alive");
|
||||
|
||||
@@ -766,6 +770,7 @@ void Commissioner::HandleRelayReceive(void *aContext, otCoapHeader *aHeader, otM
|
||||
|
||||
void Commissioner::HandleRelayReceive(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error;
|
||||
JoinerUdpPortTlv joinerPort;
|
||||
JoinerIidTlv joinerIid;
|
||||
@@ -794,7 +799,7 @@ void Commissioner::HandleRelayReceive(Coap::Header &aHeader, Message &aMessage,
|
||||
SuccessOrExit(error = Tlv::GetValueOffset(aMessage, Tlv::kJoinerDtlsEncapsulation, offset, length));
|
||||
VerifyOrExit(length <= aMessage.GetLength() - offset, error = OT_ERROR_PARSE);
|
||||
|
||||
if (!mNetif.GetCoapSecure().IsConnectionActive())
|
||||
if (!netif.GetCoapSecure().IsConnectionActive())
|
||||
{
|
||||
memcpy(mJoinerIid, joinerIid.GetIid(), sizeof(mJoinerIid));
|
||||
mJoinerIid[0] ^= 0x2;
|
||||
@@ -809,8 +814,8 @@ void Commissioner::HandleRelayReceive(Coap::Header &aHeader, Message &aMessage,
|
||||
if (mJoiners[i].mAny || !memcmp(&mJoiners[i].mExtAddress, mJoinerIid, sizeof(mJoiners[i].mExtAddress)))
|
||||
{
|
||||
|
||||
error = mNetif.GetCoapSecure().SetPsk(reinterpret_cast<const uint8_t *>(mJoiners[i].mPsk),
|
||||
static_cast<uint8_t>(strlen(mJoiners[i].mPsk)));
|
||||
error = netif.GetCoapSecure().SetPsk(reinterpret_cast<const uint8_t *>(mJoiners[i].mPsk),
|
||||
static_cast<uint8_t>(strlen(mJoiners[i].mPsk)));
|
||||
SuccessOrExit(error);
|
||||
otLogInfoMeshCoP(GetInstance(), "found joiner, starting new session");
|
||||
enableJoiner = true;
|
||||
@@ -835,11 +840,11 @@ void Commissioner::HandleRelayReceive(Coap::Header &aHeader, Message &aMessage,
|
||||
aMessage.SetOffset(offset);
|
||||
SuccessOrExit(error = aMessage.SetLength(offset + length));
|
||||
|
||||
joinerMessageInfo.SetPeerAddr(mNetif.GetMle().GetMeshLocal64());
|
||||
joinerMessageInfo.SetPeerAddr(netif.GetMle().GetMeshLocal64());
|
||||
joinerMessageInfo.GetPeerAddr().SetIid(mJoinerIid);
|
||||
joinerMessageInfo.SetPeerPort(mJoinerPort);
|
||||
|
||||
mNetif.GetCoapSecure().Receive(aMessage, joinerMessageInfo);
|
||||
netif.GetCoapSecure().Receive(aMessage, joinerMessageInfo);
|
||||
|
||||
exit:
|
||||
OT_UNUSED_VARIABLE(aMessageInfo);
|
||||
@@ -863,7 +868,7 @@ void Commissioner::HandleDatasetChanged(Coap::Header &aHeader, Message &aMessage
|
||||
otLogInfoMeshCoP(GetInstance(), "received dataset changed");
|
||||
OT_UNUSED_VARIABLE(aMessage);
|
||||
|
||||
SuccessOrExit(mNetif.GetCoap().SendEmptyAck(aHeader, aMessageInfo));
|
||||
SuccessOrExit(GetNetif().GetCoap().SendEmptyAck(aHeader, aMessageInfo));
|
||||
|
||||
otLogInfoMeshCoP(GetInstance(), "sent dataset changed acknowledgment");
|
||||
|
||||
@@ -890,8 +895,8 @@ void Commissioner::HandleJoinerFinalize(Coap::Header &aHeader, Message &aMessage
|
||||
|
||||
if (Tlv::GetTlv(aMessage, Tlv::kProvisioningUrl, sizeof(provisioningUrl), provisioningUrl) == OT_ERROR_NONE)
|
||||
{
|
||||
if (provisioningUrl.GetLength() != mNetif.GetDtls().mProvisioningUrl.GetLength() ||
|
||||
memcmp(provisioningUrl.GetProvisioningUrl(), mNetif.GetDtls().mProvisioningUrl.GetProvisioningUrl(),
|
||||
if (provisioningUrl.GetLength() != GetNetif().GetDtls().mProvisioningUrl.GetLength() ||
|
||||
memcmp(provisioningUrl.GetProvisioningUrl(), GetNetif().GetDtls().mProvisioningUrl.GetProvisioningUrl(),
|
||||
provisioningUrl.GetLength()) != 0)
|
||||
{
|
||||
state = StateTlv::kReject;
|
||||
@@ -916,6 +921,7 @@ exit:
|
||||
|
||||
void Commissioner::SendJoinFinalizeResponse(const Coap::Header &aRequestHeader, StateTlv::State aState)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
Coap::Header responseHeader;
|
||||
Ip6::MessageInfo joinerMessageInfo;
|
||||
@@ -928,7 +934,7 @@ void Commissioner::SendJoinFinalizeResponse(const Coap::Header &aRequestHeader,
|
||||
responseHeader.SetDefaultResponseHeader(aRequestHeader);
|
||||
responseHeader.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoapSecure(), responseHeader)) != NULL,
|
||||
VerifyOrExit((message = NewMeshCoPMessage(netif.GetCoapSecure(), responseHeader)) != NULL,
|
||||
error = OT_ERROR_NO_BUFS);
|
||||
|
||||
message->SetSubType(Message::kSubTypeJoinerFinalizeResponse);
|
||||
@@ -937,7 +943,7 @@ void Commissioner::SendJoinFinalizeResponse(const Coap::Header &aRequestHeader,
|
||||
stateTlv.SetState(aState);
|
||||
SuccessOrExit(error = message->Append(&stateTlv, sizeof(stateTlv)));
|
||||
|
||||
joinerMessageInfo.SetPeerAddr(mNetif.GetMle().GetMeshLocal64());
|
||||
joinerMessageInfo.SetPeerAddr(netif.GetMle().GetMeshLocal64());
|
||||
joinerMessageInfo.GetPeerAddr().SetIid(mJoinerIid);
|
||||
joinerMessageInfo.SetPeerPort(mJoinerPort);
|
||||
|
||||
@@ -949,7 +955,7 @@ void Commissioner::SendJoinFinalizeResponse(const Coap::Header &aRequestHeader,
|
||||
message->GetLength() - responseHeader.GetLength());
|
||||
#endif
|
||||
|
||||
SuccessOrExit(error = mNetif.GetCoapSecure().SendMessage(*message, joinerMessageInfo));
|
||||
SuccessOrExit(error = netif.GetCoapSecure().SendMessage(*message, joinerMessageInfo));
|
||||
|
||||
memcpy(extAddr.m8, mJoinerIid, sizeof(extAddr.m8));
|
||||
extAddr.SetLocal(!extAddr.IsLocal());
|
||||
@@ -974,7 +980,7 @@ otError Commissioner::SendRelayTransmit(void *aContext, Message &aMessage, const
|
||||
|
||||
otError Commissioner::SendRelayTransmit(Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aMessageInfo);
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
Coap::Header header;
|
||||
JoinerUdpPortTlv udpPort;
|
||||
@@ -985,13 +991,15 @@ otError Commissioner::SendRelayTransmit(Message &aMessage, const Ip6::MessageInf
|
||||
uint16_t offset;
|
||||
Ip6::MessageInfo messageInfo;
|
||||
|
||||
OT_UNUSED_VARIABLE(aMessageInfo);
|
||||
|
||||
otLogFuncEntry();
|
||||
|
||||
header.Init(OT_COAP_TYPE_NON_CONFIRMABLE, OT_COAP_CODE_POST);
|
||||
header.AppendUriPathOptions(OT_URI_PATH_RELAY_TX);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoap(), header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
VerifyOrExit((message = NewMeshCoPMessage(netif.GetCoap(), header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
udpPort.Init();
|
||||
udpPort.SetUdpPort(mJoinerPort);
|
||||
@@ -1009,7 +1017,7 @@ otError Commissioner::SendRelayTransmit(Message &aMessage, const Ip6::MessageInf
|
||||
{
|
||||
JoinerRouterKekTlv kek;
|
||||
kek.Init();
|
||||
kek.SetKek(mNetif.GetKeyManager().GetKek());
|
||||
kek.SetKek(netif.GetKeyManager().GetKek());
|
||||
SuccessOrExit(error = message->Append(&kek, sizeof(kek)));
|
||||
}
|
||||
|
||||
@@ -1020,12 +1028,12 @@ otError Commissioner::SendRelayTransmit(Message &aMessage, const Ip6::MessageInf
|
||||
message->SetLength(offset + aMessage.GetLength());
|
||||
aMessage.CopyTo(0, offset, aMessage.GetLength(), *message);
|
||||
|
||||
messageInfo.SetPeerAddr(mNetif.GetMle().GetMeshLocal16());
|
||||
messageInfo.SetPeerAddr(netif.GetMle().GetMeshLocal16());
|
||||
messageInfo.GetPeerAddr().mFields.m16[7] = HostSwap16(mJoinerRloc);
|
||||
messageInfo.SetPeerPort(kCoapUdpPort);
|
||||
messageInfo.SetInterfaceId(mNetif.GetInterfaceId());
|
||||
messageInfo.SetInterfaceId(netif.GetInterfaceId());
|
||||
|
||||
SuccessOrExit(error = mNetif.GetCoap().SendMessage(*message, messageInfo));
|
||||
SuccessOrExit(error = netif.GetCoap().SendMessage(*message, messageInfo));
|
||||
|
||||
aMessage.Free();
|
||||
|
||||
@@ -1068,6 +1076,17 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Commissioner &Commissioner::GetOwner(const Context &aContext)
|
||||
{
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
Commissioner &commissioner = *static_cast<Commissioner *>(aContext.GetContext());
|
||||
#else
|
||||
Commissioner &commissioner = otGetThreadNetif().GetCommissioner();
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
#endif
|
||||
return commissioner;
|
||||
}
|
||||
|
||||
} // namespace MeshCoP
|
||||
} // namespace ot
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "openthread-core-config.h"
|
||||
#include "coap/coap.hpp"
|
||||
#include "coap/coap_secure.hpp"
|
||||
#include "common/locator.hpp"
|
||||
#include "common/timer.hpp"
|
||||
#include "mac/mac_frame.hpp"
|
||||
#include "meshcop/announce_begin_client.hpp"
|
||||
@@ -54,7 +55,7 @@ class ThreadNetif;
|
||||
|
||||
namespace MeshCoP {
|
||||
|
||||
class Commissioner
|
||||
class Commissioner: public ThreadNetifLocator
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -65,14 +66,6 @@ public:
|
||||
*/
|
||||
Commissioner(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 starts the Commissioner service.
|
||||
*
|
||||
@@ -219,10 +212,10 @@ private:
|
||||
void AddCoapResources(void);
|
||||
void RemoveCoapResources(void);
|
||||
|
||||
static void HandleTimer(void *aContext);
|
||||
static void HandleTimer(Timer &aTimer);
|
||||
void HandleTimer(void);
|
||||
|
||||
static void HandleJoinerExpirationTimer(void *aContext);
|
||||
static void HandleJoinerExpirationTimer(Timer &aTimer);
|
||||
void HandleJoinerExpirationTimer(void);
|
||||
|
||||
void UpdateJoinerExpirationTimer(void);
|
||||
@@ -265,6 +258,8 @@ private:
|
||||
otError SendPetition(void);
|
||||
otError SendKeepAlive(void);
|
||||
|
||||
static Commissioner &GetOwner(const Context &aContext);
|
||||
|
||||
otCommissionerState mState;
|
||||
|
||||
struct Joiner
|
||||
@@ -293,8 +288,6 @@ private:
|
||||
Coap::Resource mRelayReceive;
|
||||
Coap::Resource mDatasetChanged;
|
||||
Coap::Resource mJoinerFinalize;
|
||||
|
||||
ThreadNetif &mNetif;
|
||||
};
|
||||
|
||||
} // namespace MeshCoP
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
|
||||
#include <openthread/platform/settings.h>
|
||||
|
||||
#include "openthread-instance.h"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/settings.hpp"
|
||||
#include "meshcop/meshcop_tlvs.hpp"
|
||||
@@ -49,9 +50,9 @@ namespace ot {
|
||||
namespace MeshCoP {
|
||||
|
||||
Dataset::Dataset(otInstance *aInstance, const Tlv::Type aType) :
|
||||
InstanceLocator(aInstance),
|
||||
mType(aType),
|
||||
mLength(0),
|
||||
mInstance(aInstance)
|
||||
mLength(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -61,7 +62,7 @@ void Dataset::Clear(bool isLocal)
|
||||
|
||||
if (isLocal)
|
||||
{
|
||||
otPlatSettingsDelete(mInstance, GetSettingsKey(), -1);
|
||||
otPlatSettingsDelete(GetInstance(), GetSettingsKey(), -1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -436,7 +437,7 @@ otError Dataset::Restore(void)
|
||||
otError error;
|
||||
uint16_t length = sizeof(mTlvs);
|
||||
|
||||
error = otPlatSettingsGet(mInstance, GetSettingsKey(), 0, mTlvs, &length);
|
||||
error = otPlatSettingsGet(GetInstance(), GetSettingsKey(), 0, mTlvs, &length);
|
||||
mLength = (error == OT_ERROR_NONE) ? length : 0;
|
||||
|
||||
return error;
|
||||
@@ -449,11 +450,11 @@ otError Dataset::Store(void)
|
||||
|
||||
if (mLength == 0)
|
||||
{
|
||||
error = otPlatSettingsDelete(mInstance, key, 0);
|
||||
error = otPlatSettingsDelete(GetInstance(), key, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
error = otPlatSettingsSet(mInstance, key, mTlvs, mLength);
|
||||
error = otPlatSettingsSet(GetInstance(), key, mTlvs, mLength);
|
||||
}
|
||||
|
||||
return error;
|
||||
|
||||
@@ -35,13 +35,14 @@
|
||||
#ifndef MESHCOP_DATASET_HPP_
|
||||
#define MESHCOP_DATASET_HPP_
|
||||
|
||||
#include "common/locator.hpp"
|
||||
#include "common/message.hpp"
|
||||
#include "meshcop/meshcop_tlvs.hpp"
|
||||
|
||||
namespace ot {
|
||||
namespace MeshCoP {
|
||||
|
||||
class Dataset
|
||||
class Dataset: public InstanceLocator
|
||||
{
|
||||
public:
|
||||
enum
|
||||
@@ -193,7 +194,6 @@ private:
|
||||
Tlv::Type mType; ///< Active or Pending
|
||||
uint8_t mTlvs[kMaxSize]; ///< The Dataset buffer
|
||||
uint16_t mLength; ///< The number of valid bytes in @var mTlvs
|
||||
otInstance *mInstance; ///< The pointer to an OpenThread instance
|
||||
};
|
||||
|
||||
} // namespace MeshCoP
|
||||
|
||||
@@ -62,29 +62,25 @@ namespace ot {
|
||||
namespace MeshCoP {
|
||||
|
||||
DatasetManager::DatasetManager(ThreadNetif &aThreadNetif, const Tlv::Type aType, const char *aUriSet,
|
||||
const char *aUriGet):
|
||||
const char *aUriGet, Timer::Handler aTimerHander):
|
||||
ThreadNetifLocator(aThreadNetif),
|
||||
mLocal(aThreadNetif.GetInstance(), aType),
|
||||
mNetwork(aThreadNetif.GetInstance(), aType),
|
||||
mNetif(aThreadNetif),
|
||||
mTimer(aThreadNetif.GetIp6().mTimerScheduler, &DatasetManager::HandleTimer, this),
|
||||
mTimer(aThreadNetif.GetIp6().mTimerScheduler, aTimerHander, this),
|
||||
mUriSet(aUriSet),
|
||||
mUriGet(aUriGet)
|
||||
{
|
||||
}
|
||||
|
||||
otInstance *DatasetManager::GetInstance(void)
|
||||
{
|
||||
return mNetif.GetInstance();
|
||||
}
|
||||
|
||||
otError DatasetManager::ApplyConfiguration(void)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
Dataset *dataset;
|
||||
const Tlv *cur;
|
||||
const Tlv *end;
|
||||
|
||||
dataset = mNetif.GetMle().IsAttached() ? &mNetwork : &mLocal;
|
||||
dataset = netif.GetMle().IsAttached() ? &mNetwork : &mLocal;
|
||||
|
||||
cur = reinterpret_cast<const Tlv *>(dataset->GetBytes());
|
||||
end = reinterpret_cast<const Tlv *>(dataset->GetBytes() + dataset->GetSize());
|
||||
@@ -96,21 +92,21 @@ otError DatasetManager::ApplyConfiguration(void)
|
||||
case Tlv::kChannel:
|
||||
{
|
||||
const ChannelTlv *channel = static_cast<const ChannelTlv *>(cur);
|
||||
mNetif.GetMac().SetChannel(static_cast<uint8_t>(channel->GetChannel()));
|
||||
netif.GetMac().SetChannel(static_cast<uint8_t>(channel->GetChannel()));
|
||||
break;
|
||||
}
|
||||
|
||||
case Tlv::kPanId:
|
||||
{
|
||||
const PanIdTlv *panid = static_cast<const PanIdTlv *>(cur);
|
||||
mNetif.GetMac().SetPanId(panid->GetPanId());
|
||||
netif.GetMac().SetPanId(panid->GetPanId());
|
||||
break;
|
||||
}
|
||||
|
||||
case Tlv::kExtendedPanId:
|
||||
{
|
||||
const ExtendedPanIdTlv *extpanid = static_cast<const ExtendedPanIdTlv *>(cur);
|
||||
mNetif.GetMac().SetExtendedPanId(extpanid->GetExtendedPanId());
|
||||
netif.GetMac().SetExtendedPanId(extpanid->GetExtendedPanId());
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -120,14 +116,14 @@ otError DatasetManager::ApplyConfiguration(void)
|
||||
otNetworkName networkName;
|
||||
memset(networkName.m8, 0, sizeof(networkName));
|
||||
memcpy(networkName.m8, name->GetNetworkName(), name->GetLength());
|
||||
mNetif.GetMac().SetNetworkName(networkName.m8);
|
||||
netif.GetMac().SetNetworkName(networkName.m8);
|
||||
break;
|
||||
}
|
||||
|
||||
case Tlv::kNetworkMasterKey:
|
||||
{
|
||||
const NetworkMasterKeyTlv *key = static_cast<const NetworkMasterKeyTlv *>(cur);
|
||||
mNetif.GetKeyManager().SetMasterKey(key->GetNetworkMasterKey());
|
||||
netif.GetKeyManager().SetMasterKey(key->GetNetworkMasterKey());
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -136,7 +132,7 @@ otError DatasetManager::ApplyConfiguration(void)
|
||||
case Tlv::kPSKc:
|
||||
{
|
||||
const PSKcTlv *pskc = static_cast<const PSKcTlv *>(cur);
|
||||
mNetif.GetKeyManager().SetPSKc(pskc->GetPSKc());
|
||||
netif.GetKeyManager().SetPSKc(pskc->GetPSKc());
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -145,15 +141,15 @@ otError DatasetManager::ApplyConfiguration(void)
|
||||
case Tlv::kMeshLocalPrefix:
|
||||
{
|
||||
const MeshLocalPrefixTlv *prefix = static_cast<const MeshLocalPrefixTlv *>(cur);
|
||||
mNetif.GetMle().SetMeshLocalPrefix(prefix->GetMeshLocalPrefix());
|
||||
netif.GetMle().SetMeshLocalPrefix(prefix->GetMeshLocalPrefix());
|
||||
break;
|
||||
}
|
||||
|
||||
case Tlv::kSecurityPolicy:
|
||||
{
|
||||
const SecurityPolicyTlv *securityPolicy = static_cast<const SecurityPolicyTlv *>(cur);
|
||||
mNetif.GetKeyManager().SetKeyRotation(securityPolicy->GetRotationTime());
|
||||
mNetif.GetKeyManager().SetSecurityPolicyFlags(securityPolicy->GetFlags());
|
||||
netif.GetKeyManager().SetKeyRotation(securityPolicy->GetRotationTime());
|
||||
netif.GetKeyManager().SetSecurityPolicyFlags(securityPolicy->GetFlags());
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -172,13 +168,14 @@ otError DatasetManager::ApplyConfiguration(void)
|
||||
#if OPENTHREAD_FTD
|
||||
otError DatasetManager::Set(const otOperationalDataset &aDataset, uint8_t &aFlags)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
SuccessOrExit(error = mLocal.Set(aDataset));
|
||||
mLocal.Store();
|
||||
aFlags = kFlagLocalUpdated;
|
||||
|
||||
switch (mNetif.GetMle().GetRole())
|
||||
switch (netif.GetMle().GetRole())
|
||||
{
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case OT_DEVICE_ROLE_ROUTER:
|
||||
@@ -188,8 +185,8 @@ otError DatasetManager::Set(const otOperationalDataset &aDataset, uint8_t &aFlag
|
||||
case OT_DEVICE_ROLE_LEADER:
|
||||
mNetwork = mLocal;
|
||||
aFlags |= kFlagNetworkUpdated;
|
||||
mNetif.GetNetworkDataLeader().IncrementVersion();
|
||||
mNetif.GetNetworkDataLeader().IncrementStableVersion();
|
||||
netif.GetNetworkDataLeader().IncrementVersion();
|
||||
netif.GetNetworkDataLeader().IncrementStableVersion();
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -257,27 +254,23 @@ void DatasetManager::HandleNetworkUpdate(uint8_t &aFlags)
|
||||
}
|
||||
}
|
||||
|
||||
void DatasetManager::HandleTimer(void *aContext)
|
||||
{
|
||||
static_cast<DatasetManager *>(aContext)->HandleTimer();
|
||||
}
|
||||
|
||||
void DatasetManager::HandleTimer(void)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
const Timestamp *localActiveTimestamp;
|
||||
const Timestamp *pendingActiveTimestamp;
|
||||
const ActiveTimestampTlv *tlv;
|
||||
|
||||
localActiveTimestamp = mNetif.GetActiveDataset().GetLocal().GetTimestamp();
|
||||
localActiveTimestamp = netif.GetActiveDataset().GetLocal().GetTimestamp();
|
||||
VerifyOrExit(localActiveTimestamp != NULL);
|
||||
|
||||
VerifyOrExit(mNetif.GetMle().IsAttached());
|
||||
VerifyOrExit(netif.GetMle().IsAttached());
|
||||
|
||||
VerifyOrExit(mLocal.Compare(mNetwork) < 0);
|
||||
|
||||
Register();
|
||||
|
||||
tlv = static_cast<const ActiveTimestampTlv *>(mNetif.GetPendingDataset().GetNetwork().Get(Tlv::kActiveTimestamp));
|
||||
tlv = static_cast<const ActiveTimestampTlv *>(netif.GetPendingDataset().GetNetwork().Get(Tlv::kActiveTimestamp));
|
||||
pendingActiveTimestamp = static_cast<const Timestamp *>(tlv);
|
||||
|
||||
if (pendingActiveTimestamp != NULL &&
|
||||
@@ -297,6 +290,7 @@ exit:
|
||||
|
||||
otError DatasetManager::Register(void)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
Coap::Header header;
|
||||
Message *message;
|
||||
@@ -313,14 +307,14 @@ otError DatasetManager::Register(void)
|
||||
pending->UpdateDelayTimer();
|
||||
}
|
||||
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoap(), header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
VerifyOrExit((message = NewMeshCoPMessage(netif.GetCoap(), header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
SuccessOrExit(error = message->Append(mLocal.GetBytes(), mLocal.GetSize()));
|
||||
|
||||
messageInfo.SetSockAddr(mNetif.GetMle().GetMeshLocal16());
|
||||
mNetif.GetMle().GetLeaderAloc(messageInfo.GetPeerAddr());
|
||||
messageInfo.SetSockAddr(netif.GetMle().GetMeshLocal16());
|
||||
netif.GetMle().GetLeaderAloc(messageInfo.GetPeerAddr());
|
||||
messageInfo.SetPeerPort(kCoapUdpPort);
|
||||
SuccessOrExit(error = mNetif.GetCoap().SendMessage(*message, messageInfo));
|
||||
SuccessOrExit(error = netif.GetCoap().SendMessage(*message, messageInfo));
|
||||
|
||||
otLogInfoMeshCoP(GetInstance(), "sent dataset to leader");
|
||||
|
||||
@@ -361,6 +355,7 @@ void DatasetManager::Get(Coap::Header &aHeader, Message &aMessage, const Ip6::Me
|
||||
#if OPENTHREAD_FTD
|
||||
otError DatasetManager::Set(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
Tlv tlv;
|
||||
Timestamp *timestamp;
|
||||
uint16_t offset = aMessage.GetOffset();
|
||||
@@ -387,7 +382,7 @@ otError DatasetManager::Set(Coap::Header &aHeader, Message &aMessage, const Ip6:
|
||||
pendingTimestamp.SetLength(0);
|
||||
sessionId.SetLength(0);
|
||||
|
||||
VerifyOrExit(mNetif.GetMle().GetRole() == OT_DEVICE_ROLE_LEADER, state = StateTlv::kReject);
|
||||
VerifyOrExit(netif.GetMle().GetRole() == OT_DEVICE_ROLE_LEADER, state = StateTlv::kReject);
|
||||
|
||||
// verify that TLV data size is less than maximum TLV value size
|
||||
while (offset < aMessage.GetLength())
|
||||
@@ -430,7 +425,7 @@ otError DatasetManager::Set(Coap::Header &aHeader, Message &aMessage, const Ip6:
|
||||
channel.GetChannel() <= OT_RADIO_CHANNEL_MAX,
|
||||
state = StateTlv::kReject);
|
||||
|
||||
if (channel.GetChannel() != mNetif.GetMac().GetChannel())
|
||||
if (channel.GetChannel() != netif.GetMac().GetChannel())
|
||||
{
|
||||
doesAffectConnectivity = true;
|
||||
}
|
||||
@@ -439,14 +434,14 @@ otError DatasetManager::Set(Coap::Header &aHeader, Message &aMessage, const Ip6:
|
||||
// check PAN ID
|
||||
if (Tlv::GetTlv(aMessage, Tlv::kPanId, sizeof(panId), panId) == OT_ERROR_NONE &&
|
||||
panId.IsValid() &&
|
||||
panId.GetPanId() != mNetif.GetMac().GetPanId())
|
||||
panId.GetPanId() != netif.GetMac().GetPanId())
|
||||
{
|
||||
doesAffectConnectivity = true;
|
||||
}
|
||||
|
||||
// check mesh local prefix
|
||||
if (Tlv::GetTlv(aMessage, Tlv::kMeshLocalPrefix, sizeof(meshLocalPrefix), meshLocalPrefix) == OT_ERROR_NONE &&
|
||||
memcmp(meshLocalPrefix.GetMeshLocalPrefix(), mNetif.GetMle().GetMeshLocalPrefix(),
|
||||
memcmp(meshLocalPrefix.GetMeshLocalPrefix(), netif.GetMle().GetMeshLocalPrefix(),
|
||||
meshLocalPrefix.GetLength()))
|
||||
{
|
||||
doesAffectConnectivity = true;
|
||||
@@ -454,7 +449,7 @@ otError DatasetManager::Set(Coap::Header &aHeader, Message &aMessage, const Ip6:
|
||||
|
||||
// check network master key
|
||||
if (Tlv::GetTlv(aMessage, Tlv::kNetworkMasterKey, sizeof(masterKey), masterKey) == OT_ERROR_NONE &&
|
||||
memcmp(&masterKey.GetNetworkMasterKey(), &mNetif.GetKeyManager().GetMasterKey(), OT_MASTER_KEY_SIZE))
|
||||
memcmp(&masterKey.GetNetworkMasterKey(), &netif.GetKeyManager().GetMasterKey(), OT_MASTER_KEY_SIZE))
|
||||
{
|
||||
doesAffectConnectivity = true;
|
||||
doesAffectMasterKey = true;
|
||||
@@ -463,10 +458,10 @@ otError DatasetManager::Set(Coap::Header &aHeader, Message &aMessage, const Ip6:
|
||||
// check active timestamp rollback
|
||||
if (type == Tlv::kPendingTimestamp &&
|
||||
(masterKey.GetLength() == 0 ||
|
||||
memcmp(&masterKey.GetNetworkMasterKey(), &mNetif.GetKeyManager().GetMasterKey(), OT_MASTER_KEY_SIZE) == 0))
|
||||
memcmp(&masterKey.GetNetworkMasterKey(), &netif.GetKeyManager().GetMasterKey(), OT_MASTER_KEY_SIZE) == 0))
|
||||
{
|
||||
// no change to master key, active timestamp must be ahead
|
||||
const Timestamp *localActiveTimestamp = mNetif.GetActiveDataset().GetNetwork().GetTimestamp();
|
||||
const Timestamp *localActiveTimestamp = netif.GetActiveDataset().GetNetwork().GetTimestamp();
|
||||
|
||||
VerifyOrExit(localActiveTimestamp == NULL || localActiveTimestamp->Compare(activeTimestamp) > 0,
|
||||
state = StateTlv::kReject);
|
||||
@@ -479,7 +474,7 @@ otError DatasetManager::Set(Coap::Header &aHeader, Message &aMessage, const Ip6:
|
||||
|
||||
isUpdateFromCommissioner = true;
|
||||
|
||||
localId = static_cast<CommissionerSessionIdTlv *>(mNetif.GetNetworkDataLeader().GetCommissioningDataSubTlv(
|
||||
localId = static_cast<CommissionerSessionIdTlv *>(netif.GetNetworkDataLeader().GetCommissioningDataSubTlv(
|
||||
Tlv::kCommissionerSessionId));
|
||||
|
||||
VerifyOrExit(sessionId.IsValid() &&
|
||||
@@ -496,7 +491,7 @@ otError DatasetManager::Set(Coap::Header &aHeader, Message &aMessage, const Ip6:
|
||||
if (type == Tlv::kPendingTimestamp && isUpdateFromCommissioner)
|
||||
{
|
||||
mLocal.Clear(true);
|
||||
mLocal.Set(mNetif.GetActiveDataset().GetNetwork());
|
||||
mLocal.Set(netif.GetActiveDataset().GetNetwork());
|
||||
}
|
||||
|
||||
if (type == Tlv::kPendingTimestamp || !doesAffectConnectivity)
|
||||
@@ -529,9 +524,9 @@ otError DatasetManager::Set(Coap::Header &aHeader, Message &aMessage, const Ip6:
|
||||
{
|
||||
delayTimerTlv->SetDelayTimer(DelayTimerTlv::kDelayTimerDefault);
|
||||
}
|
||||
else if (delayTimerTlv->GetDelayTimer() < mNetif.GetLeader().GetDelayTimerMinimal())
|
||||
else if (delayTimerTlv->GetDelayTimer() < netif.GetLeader().GetDelayTimerMinimal())
|
||||
{
|
||||
delayTimerTlv->SetDelayTimer(mNetif.GetLeader().GetDelayTimerMinimal());
|
||||
delayTimerTlv->SetDelayTimer(netif.GetLeader().GetDelayTimerMinimal());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -547,12 +542,12 @@ otError DatasetManager::Set(Coap::Header &aHeader, Message &aMessage, const Ip6:
|
||||
|
||||
mLocal.Store();
|
||||
mNetwork = mLocal;
|
||||
mNetif.GetNetworkDataLeader().IncrementVersion();
|
||||
mNetif.GetNetworkDataLeader().IncrementStableVersion();
|
||||
netif.GetNetworkDataLeader().IncrementVersion();
|
||||
netif.GetNetworkDataLeader().IncrementStableVersion();
|
||||
}
|
||||
else
|
||||
{
|
||||
mNetif.GetPendingDataset().ApplyActiveDataset(activeTimestamp, aMessage);
|
||||
netif.GetPendingDataset().ApplyActiveDataset(activeTimestamp, aMessage);
|
||||
}
|
||||
|
||||
// notify commissioner if update is from thread device
|
||||
@@ -561,20 +556,20 @@ otError DatasetManager::Set(Coap::Header &aHeader, Message &aMessage, const Ip6:
|
||||
BorderAgentLocatorTlv *borderAgentLocator;
|
||||
Ip6::Address destination;
|
||||
|
||||
borderAgentLocator = static_cast<BorderAgentLocatorTlv *>(mNetif.GetNetworkDataLeader().GetCommissioningDataSubTlv(
|
||||
borderAgentLocator = static_cast<BorderAgentLocatorTlv *>(netif.GetNetworkDataLeader().GetCommissioningDataSubTlv(
|
||||
Tlv::kBorderAgentLocator));
|
||||
VerifyOrExit(borderAgentLocator != NULL);
|
||||
|
||||
memset(&destination, 0, sizeof(destination));
|
||||
destination = mNetif.GetMle().GetMeshLocal16();
|
||||
destination = netif.GetMle().GetMeshLocal16();
|
||||
destination.mFields.m16[7] = HostSwap16(borderAgentLocator->GetBorderAgentLocator());
|
||||
|
||||
mNetif.GetLeader().SendDatasetChanged(destination);
|
||||
netif.GetLeader().SendDatasetChanged(destination);
|
||||
}
|
||||
|
||||
exit:
|
||||
|
||||
if (mNetif.GetMle().GetRole() == OT_DEVICE_ROLE_LEADER)
|
||||
if (netif.GetMle().GetRole() == OT_DEVICE_ROLE_LEADER)
|
||||
{
|
||||
SendSetResponse(aHeader, aMessageInfo, state);
|
||||
}
|
||||
@@ -584,6 +579,7 @@ exit:
|
||||
|
||||
otError DatasetManager::SendSetRequest(const otOperationalDataset &aDataset, const uint8_t *aTlvs, uint8_t aLength)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
Coap::Header header;
|
||||
Message *message;
|
||||
@@ -594,11 +590,11 @@ otError DatasetManager::SendSetRequest(const otOperationalDataset &aDataset, con
|
||||
header.AppendUriPathOptions(mUriSet);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoap(), header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
VerifyOrExit((message = NewMeshCoPMessage(netif.GetCoap(), header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
#if OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
|
||||
|
||||
if (mNetif.GetCommissioner().IsActive())
|
||||
if (netif.GetCommissioner().IsActive())
|
||||
{
|
||||
const uint8_t *cur = aTlvs;
|
||||
const uint8_t *end = aTlvs + aLength;
|
||||
@@ -621,7 +617,7 @@ otError DatasetManager::SendSetRequest(const otOperationalDataset &aDataset, con
|
||||
{
|
||||
CommissionerSessionIdTlv sessionId;
|
||||
sessionId.Init();
|
||||
sessionId.SetCommissionerSessionId(mNetif.GetCommissioner().GetSessionId());
|
||||
sessionId.SetCommissionerSessionId(netif.GetCommissioner().GetSessionId());
|
||||
SuccessOrExit(error = message->Append(&sessionId, sizeof(sessionId)));
|
||||
}
|
||||
}
|
||||
@@ -722,10 +718,10 @@ otError DatasetManager::SendSetRequest(const otOperationalDataset &aDataset, con
|
||||
message->SetLength(message->GetLength() - 1);
|
||||
}
|
||||
|
||||
messageInfo.SetSockAddr(mNetif.GetMle().GetMeshLocal16());
|
||||
mNetif.GetMle().GetLeaderAloc(messageInfo.GetPeerAddr());
|
||||
messageInfo.SetSockAddr(netif.GetMle().GetMeshLocal16());
|
||||
netif.GetMle().GetLeaderAloc(messageInfo.GetPeerAddr());
|
||||
messageInfo.SetPeerPort(kCoapUdpPort);
|
||||
SuccessOrExit(error = mNetif.GetCoap().SendMessage(*message, messageInfo));
|
||||
SuccessOrExit(error = netif.GetCoap().SendMessage(*message, messageInfo));
|
||||
|
||||
otLogInfoMeshCoP(GetInstance(), "sent dataset set request to leader");
|
||||
|
||||
@@ -741,6 +737,7 @@ exit:
|
||||
|
||||
otError DatasetManager::SendGetRequest(const uint8_t *aTlvTypes, uint8_t aLength, const otIp6Address *aAddress)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
Coap::Header header;
|
||||
Message *message;
|
||||
@@ -756,7 +753,7 @@ otError DatasetManager::SendGetRequest(const uint8_t *aTlvTypes, uint8_t aLength
|
||||
header.SetPayloadMarker();
|
||||
}
|
||||
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoap(), header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
VerifyOrExit((message = NewMeshCoPMessage(netif.GetCoap(), header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
if (aLength > 0)
|
||||
{
|
||||
@@ -772,12 +769,12 @@ otError DatasetManager::SendGetRequest(const uint8_t *aTlvTypes, uint8_t aLength
|
||||
}
|
||||
else
|
||||
{
|
||||
mNetif.GetMle().GetLeaderAloc(messageInfo.GetPeerAddr());
|
||||
netif.GetMle().GetLeaderAloc(messageInfo.GetPeerAddr());
|
||||
}
|
||||
|
||||
messageInfo.SetSockAddr(mNetif.GetMle().GetMeshLocal16());
|
||||
messageInfo.SetSockAddr(netif.GetMle().GetMeshLocal16());
|
||||
messageInfo.SetPeerPort(kCoapUdpPort);
|
||||
SuccessOrExit(error = mNetif.GetCoap().SendMessage(*message, messageInfo));
|
||||
SuccessOrExit(error = netif.GetCoap().SendMessage(*message, messageInfo));
|
||||
|
||||
otLogInfoMeshCoP(GetInstance(), "sent dataset get request");
|
||||
|
||||
@@ -794,6 +791,7 @@ exit:
|
||||
void DatasetManager::SendSetResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aMessageInfo,
|
||||
StateTlv::State aState)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
Coap::Header responseHeader;
|
||||
Message *message;
|
||||
@@ -802,13 +800,13 @@ void DatasetManager::SendSetResponse(const Coap::Header &aRequestHeader, const I
|
||||
responseHeader.SetDefaultResponseHeader(aRequestHeader);
|
||||
responseHeader.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoap(), responseHeader)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
VerifyOrExit((message = NewMeshCoPMessage(netif.GetCoap(), responseHeader)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
state.Init();
|
||||
state.SetState(aState);
|
||||
SuccessOrExit(error = message->Append(&state, sizeof(state)));
|
||||
|
||||
SuccessOrExit(error = mNetif.GetCoap().SendMessage(*message, aMessageInfo));
|
||||
SuccessOrExit(error = netif.GetCoap().SendMessage(*message, aMessageInfo));
|
||||
|
||||
otLogInfoMeshCoP(GetInstance(), "sent dataset set response");
|
||||
|
||||
@@ -824,6 +822,7 @@ exit:
|
||||
void DatasetManager::SendGetResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aMessageInfo,
|
||||
uint8_t *aTlvs, uint8_t aLength)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
Tlv *tlv;
|
||||
otError error = OT_ERROR_NONE;
|
||||
Coap::Header responseHeader;
|
||||
@@ -834,7 +833,7 @@ void DatasetManager::SendGetResponse(const Coap::Header &aRequestHeader, const I
|
||||
responseHeader.SetDefaultResponseHeader(aRequestHeader);
|
||||
responseHeader.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoap(), responseHeader)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
VerifyOrExit((message = NewMeshCoPMessage(netif.GetCoap(), responseHeader)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
if (aLength == 0)
|
||||
{
|
||||
@@ -844,7 +843,7 @@ void DatasetManager::SendGetResponse(const Coap::Header &aRequestHeader, const I
|
||||
while (cur < end)
|
||||
{
|
||||
if (cur->GetType() != Tlv::kNetworkMasterKey ||
|
||||
(mNetif.GetKeyManager().GetSecurityPolicyFlags() & OT_SECURITY_POLICY_OBTAIN_MASTER_KEY))
|
||||
(netif.GetKeyManager().GetSecurityPolicyFlags() & OT_SECURITY_POLICY_OBTAIN_MASTER_KEY))
|
||||
{
|
||||
SuccessOrExit(error = message->Append(cur, sizeof(Tlv) + cur->GetLength()));
|
||||
}
|
||||
@@ -857,7 +856,7 @@ void DatasetManager::SendGetResponse(const Coap::Header &aRequestHeader, const I
|
||||
for (index = 0; index < aLength; index++)
|
||||
{
|
||||
if (aTlvs[index] == Tlv::kNetworkMasterKey &&
|
||||
!(mNetif.GetKeyManager().GetSecurityPolicyFlags() & OT_SECURITY_POLICY_OBTAIN_MASTER_KEY))
|
||||
!(netif.GetKeyManager().GetSecurityPolicyFlags() & OT_SECURITY_POLICY_OBTAIN_MASTER_KEY))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -875,7 +874,7 @@ void DatasetManager::SendGetResponse(const Coap::Header &aRequestHeader, const I
|
||||
message->SetLength(message->GetLength() - 1);
|
||||
}
|
||||
|
||||
SuccessOrExit(error = mNetif.GetCoap().SendMessage(*message, aMessageInfo));
|
||||
SuccessOrExit(error = netif.GetCoap().SendMessage(*message, aMessageInfo));
|
||||
|
||||
otLogInfoMeshCoP(GetInstance(), "sent dataset get response");
|
||||
|
||||
@@ -887,11 +886,23 @@ exit:
|
||||
}
|
||||
}
|
||||
|
||||
static ActiveDatasetBase &GetActiveDatasetOwner(const Context &aContext)
|
||||
{
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
ActiveDatasetBase &activeDataset = *static_cast<ActiveDatasetBase *>(aContext.GetContext());
|
||||
#else
|
||||
ActiveDatasetBase &activeDataset = otGetThreadNetif().GetActiveDataset();
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
#endif
|
||||
return activeDataset;
|
||||
}
|
||||
|
||||
ActiveDatasetBase::ActiveDatasetBase(ThreadNetif &aThreadNetif):
|
||||
DatasetManager(aThreadNetif, Tlv::kActiveTimestamp, OT_URI_PATH_ACTIVE_SET, OT_URI_PATH_ACTIVE_GET),
|
||||
DatasetManager(aThreadNetif, Tlv::kActiveTimestamp, OT_URI_PATH_ACTIVE_SET, OT_URI_PATH_ACTIVE_GET,
|
||||
&ActiveDatasetBase::HandleTimer),
|
||||
mResourceGet(OT_URI_PATH_ACTIVE_GET, &ActiveDatasetBase::HandleGet, this)
|
||||
{
|
||||
mNetif.GetCoap().AddResource(mResourceGet);
|
||||
aThreadNetif.GetCoap().AddResource(mResourceGet);
|
||||
}
|
||||
|
||||
otError ActiveDatasetBase::Restore(void)
|
||||
@@ -932,15 +943,16 @@ exit:
|
||||
|
||||
otError ActiveDatasetBase::Set(const Dataset &aDataset)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
SuccessOrExit(error = DatasetManager::Set(aDataset));
|
||||
DatasetManager::ApplyConfiguration();
|
||||
|
||||
if (mNetif.GetMle().GetRole() == OT_DEVICE_ROLE_LEADER)
|
||||
if (netif.GetMle().GetRole() == OT_DEVICE_ROLE_LEADER)
|
||||
{
|
||||
mNetif.GetNetworkDataLeader().IncrementVersion();
|
||||
mNetif.GetNetworkDataLeader().IncrementStableVersion();
|
||||
netif.GetNetworkDataLeader().IncrementVersion();
|
||||
netif.GetNetworkDataLeader().IncrementStableVersion();
|
||||
}
|
||||
|
||||
exit:
|
||||
@@ -973,14 +985,31 @@ void ActiveDatasetBase::HandleGet(Coap::Header &aHeader, Message &aMessage, cons
|
||||
DatasetManager::Get(aHeader, aMessage, aMessageInfo);
|
||||
}
|
||||
|
||||
void ActiveDatasetBase::HandleTimer(Timer &aTimer)
|
||||
{
|
||||
GetActiveDatasetOwner(aTimer).HandleTimer();
|
||||
}
|
||||
|
||||
static PendingDatasetBase &GetPendingDatasetOwner(const Context &aContext)
|
||||
{
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
PendingDatasetBase &pendingDataset = *static_cast<PendingDatasetBase *>(aContext.GetContext());
|
||||
#else
|
||||
PendingDatasetBase &pendingDataset = otGetThreadNetif().GetPendingDataset();
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
#endif
|
||||
return pendingDataset;
|
||||
}
|
||||
|
||||
PendingDatasetBase::PendingDatasetBase(ThreadNetif &aThreadNetif):
|
||||
DatasetManager(aThreadNetif, Tlv::kPendingTimestamp, OT_URI_PATH_PENDING_SET, OT_URI_PATH_PENDING_GET),
|
||||
mTimer(aThreadNetif.GetIp6().mTimerScheduler, &PendingDatasetBase::HandleTimer, this),
|
||||
DatasetManager(aThreadNetif, Tlv::kPendingTimestamp, OT_URI_PATH_PENDING_SET, OT_URI_PATH_PENDING_GET,
|
||||
&PendingDatasetBase::HandleTimer),
|
||||
mDelayTimer(aThreadNetif.GetIp6().mTimerScheduler, &PendingDatasetBase::HandleDelayTimer, this),
|
||||
mLocalTime(0),
|
||||
mNetworkTime(0),
|
||||
mResourceGet(OT_URI_PATH_PENDING_GET, &PendingDatasetBase::HandleGet, this)
|
||||
{
|
||||
mNetif.GetCoap().AddResource(mResourceGet);
|
||||
aThreadNetif.GetCoap().AddResource(mResourceGet);
|
||||
}
|
||||
|
||||
otError PendingDatasetBase::Restore(void)
|
||||
@@ -1057,17 +1086,17 @@ void PendingDatasetBase::ResetDelayTimer(uint8_t aFlags)
|
||||
if (aFlags & kFlagNetworkUpdated)
|
||||
{
|
||||
mNetworkTime = Timer::GetNow();
|
||||
mTimer.Stop();
|
||||
mDelayTimer.Stop();
|
||||
|
||||
if ((delayTimer = static_cast<DelayTimerTlv *>(mNetwork.Get(Tlv::kDelayTimer))) != NULL)
|
||||
{
|
||||
if (delayTimer->GetDelayTimer() == 0)
|
||||
{
|
||||
HandleTimer();
|
||||
HandleDelayTimer();
|
||||
}
|
||||
else
|
||||
{
|
||||
mTimer.Start(delayTimer->GetDelayTimer());
|
||||
mDelayTimer.Start(delayTimer->GetDelayTimer());
|
||||
otLogInfoMeshCoP(GetInstance(), "delay timer started");
|
||||
}
|
||||
}
|
||||
@@ -1110,12 +1139,12 @@ exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void PendingDatasetBase::HandleTimer(void *aContext)
|
||||
void PendingDatasetBase::HandleDelayTimer(Timer &aTimer)
|
||||
{
|
||||
static_cast<PendingDatasetBase *>(aContext)->HandleTimer();
|
||||
GetPendingDatasetOwner(aTimer).HandleDelayTimer();
|
||||
}
|
||||
|
||||
void PendingDatasetBase::HandleTimer(void)
|
||||
void PendingDatasetBase::HandleDelayTimer(void)
|
||||
{
|
||||
DelayTimerTlv *delayTimer;
|
||||
|
||||
@@ -1125,7 +1154,7 @@ void PendingDatasetBase::HandleTimer(void)
|
||||
delayTimer = static_cast<DelayTimerTlv *>(mNetwork.Get(Tlv::kDelayTimer));
|
||||
assert(delayTimer != NULL && delayTimer->GetDelayTimer() == 0);
|
||||
|
||||
mNetif.GetActiveDataset().Set(mNetwork);
|
||||
GetNetif().GetActiveDataset().Set(mNetwork);
|
||||
|
||||
Clear(false);
|
||||
}
|
||||
@@ -1148,5 +1177,10 @@ void PendingDatasetBase::HandleGet(Coap::Header &aHeader, Message &aMessage, con
|
||||
DatasetManager::Get(aHeader, aMessage, aMessageInfo);
|
||||
}
|
||||
|
||||
void PendingDatasetBase::HandleTimer(Timer &aTimer)
|
||||
{
|
||||
GetPendingDatasetOwner(aTimer).HandleTimer();
|
||||
}
|
||||
|
||||
} // namespace MeshCoP
|
||||
} // namespace ot
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include <openthread/types.h>
|
||||
|
||||
#include "coap/coap.hpp"
|
||||
#include "common/locator.hpp"
|
||||
#include "common/timer.hpp"
|
||||
#include "meshcop/dataset.hpp"
|
||||
#include "net/udp6.hpp"
|
||||
@@ -50,18 +51,9 @@ class ThreadNetif;
|
||||
|
||||
namespace MeshCoP {
|
||||
|
||||
class DatasetManager
|
||||
class DatasetManager: public ThreadNetifLocator
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* This method returns the pointer to the parent otInstance structure.
|
||||
*
|
||||
* @returns The pointer to the parent otInstance structure.
|
||||
*
|
||||
*/
|
||||
otInstance *GetInstance(void);
|
||||
|
||||
Dataset &GetLocal(void) { return mLocal; }
|
||||
Dataset &GetNetwork(void) { return mNetwork; }
|
||||
|
||||
@@ -74,7 +66,8 @@ protected:
|
||||
kFlagNetworkUpdated = 1 << 1,
|
||||
};
|
||||
|
||||
DatasetManager(ThreadNetif &aThreadNetif, const Tlv::Type aType, const char *aUriSet, const char *aUriGet);
|
||||
DatasetManager(ThreadNetif &aThreadNetif, const Tlv::Type aType, const char *aUriSet, const char *aUriGet,
|
||||
Timer::Handler aTimerHander);
|
||||
|
||||
otError Clear(uint8_t &aFlags, bool aOnlyClearNetwork);
|
||||
|
||||
@@ -86,23 +79,18 @@ protected:
|
||||
void Get(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
void HandleNetworkUpdate(uint8_t &aFlags);
|
||||
void HandleTimer(void);
|
||||
|
||||
Dataset mLocal;
|
||||
Dataset mNetwork;
|
||||
|
||||
ThreadNetif &mNetif;
|
||||
|
||||
private:
|
||||
static void HandleUdpReceive(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo);
|
||||
void HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
static void HandleTimer(void *aContext);
|
||||
void HandleTimer(void);
|
||||
|
||||
otError Register(void);
|
||||
void SendGetResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aMessageInfo,
|
||||
uint8_t *aTlvs, uint8_t aLength);
|
||||
|
||||
Timer mTimer;
|
||||
|
||||
const char *mUriSet;
|
||||
@@ -144,6 +132,9 @@ private:
|
||||
const otMessageInfo *aMessageInfo);
|
||||
void HandleGet(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
static void HandleTimer(Timer &aTimer);
|
||||
void HandleTimer(void) { DatasetManager::HandleTimer(); }
|
||||
|
||||
Coap::Resource mResourceGet;
|
||||
};
|
||||
|
||||
@@ -167,15 +158,15 @@ public:
|
||||
void UpdateDelayTimer(void);
|
||||
|
||||
protected:
|
||||
static void HandleTimer(void *aContext);
|
||||
void HandleTimer(void);
|
||||
static void HandleDelayTimer(Timer &aTimer);
|
||||
void HandleDelayTimer(void);
|
||||
|
||||
void ResetDelayTimer(uint8_t aFlags);
|
||||
void UpdateDelayTimer(Dataset &aDataset, uint32_t &aStartTime);
|
||||
|
||||
void HandleNetworkUpdate(uint8_t &aFlags);
|
||||
|
||||
Timer mTimer;
|
||||
Timer mDelayTimer;
|
||||
uint32_t mLocalTime;
|
||||
uint32_t mNetworkTime;
|
||||
|
||||
@@ -184,6 +175,9 @@ private:
|
||||
const otMessageInfo *aMessageInfo);
|
||||
void HandleGet(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
static void HandleTimer(Timer &aTimer);
|
||||
void HandleTimer(void) { DatasetManager::HandleTimer(); }
|
||||
|
||||
Coap::Resource mResourceGet;
|
||||
};
|
||||
|
||||
|
||||
@@ -74,10 +74,11 @@ bool ActiveDataset::IsTlvInitialized(Tlv::Type aType)
|
||||
|
||||
otError ActiveDataset::GenerateLocal(void)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
otOperationalDataset dataset;
|
||||
|
||||
VerifyOrExit(mNetif.GetMle().IsAttached(), error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(netif.GetMle().IsAttached(), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
memset(&dataset, 0, sizeof(dataset));
|
||||
|
||||
@@ -97,7 +98,7 @@ otError ActiveDataset::GenerateLocal(void)
|
||||
ChannelTlv tlv;
|
||||
tlv.Init();
|
||||
tlv.SetChannelPage(0);
|
||||
tlv.SetChannel(mNetif.GetMac().GetChannel());
|
||||
tlv.SetChannel(netif.GetMac().GetChannel());
|
||||
mLocal.Set(tlv);
|
||||
}
|
||||
|
||||
@@ -115,7 +116,7 @@ otError ActiveDataset::GenerateLocal(void)
|
||||
{
|
||||
ExtendedPanIdTlv tlv;
|
||||
tlv.Init();
|
||||
tlv.SetExtendedPanId(mNetif.GetMac().GetExtendedPanId());
|
||||
tlv.SetExtendedPanId(netif.GetMac().GetExtendedPanId());
|
||||
mLocal.Set(tlv);
|
||||
}
|
||||
|
||||
@@ -124,7 +125,7 @@ otError ActiveDataset::GenerateLocal(void)
|
||||
{
|
||||
MeshLocalPrefixTlv tlv;
|
||||
tlv.Init();
|
||||
tlv.SetMeshLocalPrefix(mNetif.GetMle().GetMeshLocalPrefix());
|
||||
tlv.SetMeshLocalPrefix(netif.GetMle().GetMeshLocalPrefix());
|
||||
mLocal.Set(tlv);
|
||||
}
|
||||
|
||||
@@ -133,7 +134,7 @@ otError ActiveDataset::GenerateLocal(void)
|
||||
{
|
||||
NetworkMasterKeyTlv tlv;
|
||||
tlv.Init();
|
||||
tlv.SetNetworkMasterKey(mNetif.GetKeyManager().GetMasterKey());
|
||||
tlv.SetNetworkMasterKey(netif.GetKeyManager().GetMasterKey());
|
||||
mLocal.Set(tlv);
|
||||
}
|
||||
|
||||
@@ -142,7 +143,7 @@ otError ActiveDataset::GenerateLocal(void)
|
||||
{
|
||||
NetworkNameTlv tlv;
|
||||
tlv.Init();
|
||||
tlv.SetNetworkName(mNetif.GetMac().GetNetworkName());
|
||||
tlv.SetNetworkName(netif.GetMac().GetNetworkName());
|
||||
mLocal.Set(tlv);
|
||||
}
|
||||
|
||||
@@ -151,7 +152,7 @@ otError ActiveDataset::GenerateLocal(void)
|
||||
{
|
||||
PanIdTlv tlv;
|
||||
tlv.Init();
|
||||
tlv.SetPanId(mNetif.GetMac().GetPanId());
|
||||
tlv.SetPanId(netif.GetMac().GetPanId());
|
||||
mLocal.Set(tlv);
|
||||
}
|
||||
|
||||
@@ -160,7 +161,7 @@ otError ActiveDataset::GenerateLocal(void)
|
||||
{
|
||||
PSKcTlv tlv;
|
||||
tlv.Init();
|
||||
tlv.SetPSKc(mNetif.GetKeyManager().GetPSKc());
|
||||
tlv.SetPSKc(netif.GetKeyManager().GetPSKc());
|
||||
mLocal.Set(tlv);
|
||||
}
|
||||
|
||||
@@ -169,8 +170,8 @@ otError ActiveDataset::GenerateLocal(void)
|
||||
{
|
||||
SecurityPolicyTlv tlv;
|
||||
tlv.Init();
|
||||
tlv.SetRotationTime(static_cast<uint16_t>(mNetif.GetKeyManager().GetKeyRotation()));
|
||||
tlv.SetFlags(mNetif.GetKeyManager().GetSecurityPolicyFlags());
|
||||
tlv.SetRotationTime(static_cast<uint16_t>(netif.GetKeyManager().GetKeyRotation()));
|
||||
tlv.SetFlags(netif.GetKeyManager().GetSecurityPolicyFlags());
|
||||
mLocal.Set(tlv);
|
||||
}
|
||||
|
||||
@@ -184,12 +185,12 @@ void ActiveDataset::StartLeader(void)
|
||||
|
||||
mLocal.Store();
|
||||
mNetwork = mLocal;
|
||||
mNetif.GetCoap().AddResource(mResourceSet);
|
||||
GetNetif().GetCoap().AddResource(mResourceSet);
|
||||
}
|
||||
|
||||
void ActiveDataset::StopLeader(void)
|
||||
{
|
||||
mNetif.GetCoap().RemoveResource(mResourceSet);
|
||||
GetNetif().GetCoap().RemoveResource(mResourceSet);
|
||||
}
|
||||
|
||||
void ActiveDataset::HandleSet(void *aContext, otCoapHeader *aHeader, otMessage *aMessage,
|
||||
@@ -222,12 +223,12 @@ void PendingDataset::StartLeader(void)
|
||||
mNetwork = mLocal;
|
||||
ResetDelayTimer(kFlagNetworkUpdated);
|
||||
|
||||
mNetif.GetCoap().AddResource(mResourceSet);
|
||||
GetNetif().GetCoap().AddResource(mResourceSet);
|
||||
}
|
||||
|
||||
void PendingDataset::StopLeader(void)
|
||||
{
|
||||
mNetif.GetCoap().RemoveResource(mResourceSet);
|
||||
GetNetif().GetCoap().RemoveResource(mResourceSet);
|
||||
}
|
||||
|
||||
void PendingDataset::HandleSet(void *aContext, otCoapHeader *aHeader, otMessage *aMessage,
|
||||
@@ -249,11 +250,12 @@ exit:
|
||||
|
||||
void PendingDataset::ApplyActiveDataset(const Timestamp &aTimestamp, Message &aMessage)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
uint16_t offset = aMessage.GetOffset();
|
||||
DelayTimerTlv delayTimer;
|
||||
uint8_t flags;
|
||||
|
||||
VerifyOrExit(mNetif.GetMle().IsAttached());
|
||||
VerifyOrExit(netif.GetMle().IsAttached());
|
||||
|
||||
while (offset < aMessage.GetLength())
|
||||
{
|
||||
@@ -272,7 +274,7 @@ void PendingDataset::ApplyActiveDataset(const Timestamp &aTimestamp, Message &aM
|
||||
|
||||
// add delay timer tlv
|
||||
delayTimer.Init();
|
||||
delayTimer.SetDelayTimer(mNetif.GetLeader().GetDelayTimerMinimal());
|
||||
delayTimer.SetDelayTimer(netif.GetLeader().GetDelayTimerMinimal());
|
||||
mNetwork.Set(delayTimer);
|
||||
|
||||
// add pending timestamp tlv
|
||||
|
||||
+17
-10
@@ -39,6 +39,7 @@
|
||||
#include <mbedtls/debug.h>
|
||||
#include <openthread/platform/radio.h>
|
||||
|
||||
#include "openthread-instance.h"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
#include "common/encoding.hpp"
|
||||
@@ -53,6 +54,7 @@ namespace ot {
|
||||
namespace MeshCoP {
|
||||
|
||||
Dtls::Dtls(ThreadNetif &aNetif):
|
||||
ThreadNetifLocator(aNetif),
|
||||
mPskLength(0),
|
||||
mStarted(false),
|
||||
mTimer(aNetif.GetIp6().mTimerScheduler, &Dtls::HandleTimer, this),
|
||||
@@ -66,8 +68,7 @@ Dtls::Dtls(ThreadNetif &aNetif):
|
||||
mSendHandler(NULL),
|
||||
mContext(NULL),
|
||||
mClient(false),
|
||||
mMessageSubType(0),
|
||||
mNetif(aNetif)
|
||||
mMessageSubType(0)
|
||||
{
|
||||
memset(mPsk, 0, sizeof(mPsk));
|
||||
memset(&mEntropy, 0, sizeof(mEntropy));
|
||||
@@ -78,11 +79,6 @@ Dtls::Dtls(ThreadNetif &aNetif):
|
||||
mProvisioningUrl.Init();
|
||||
}
|
||||
|
||||
otInstance *Dtls::GetInstance(void)
|
||||
{
|
||||
return mNetif.GetInstance();
|
||||
}
|
||||
|
||||
otError Dtls::Start(bool aClient, ConnectedHandler aConnectedHandler, ReceiveHandler aReceiveHandler,
|
||||
SendHandler aSendHandler, void *aContext)
|
||||
{
|
||||
@@ -366,7 +362,7 @@ int Dtls::HandleMbedtlsExportKeys(const unsigned char *aMasterSecret, const unsi
|
||||
sha256.Update(aKeyBlock, 2 * static_cast<uint16_t>(aMacLength + aKeyLength + aIvLength));
|
||||
sha256.Finish(kek);
|
||||
|
||||
mNetif.GetKeyManager().SetKek(kek);
|
||||
GetNetif().GetKeyManager().SetKek(kek);
|
||||
|
||||
otLogInfoMeshCoP(GetInstance(), "Generated KEK");
|
||||
|
||||
@@ -374,9 +370,9 @@ int Dtls::HandleMbedtlsExportKeys(const unsigned char *aMasterSecret, const unsi
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Dtls::HandleTimer(void *aContext)
|
||||
void Dtls::HandleTimer(Timer &aTimer)
|
||||
{
|
||||
static_cast<Dtls *>(aContext)->HandleTimer();
|
||||
GetOwner(aTimer).HandleTimer();
|
||||
}
|
||||
|
||||
void Dtls::HandleTimer(void)
|
||||
@@ -514,6 +510,17 @@ void Dtls::HandleMbedtlsDebug(void *ctx, int level, const char *, int, const cha
|
||||
}
|
||||
}
|
||||
|
||||
Dtls &Dtls::GetOwner(const Context &aContext)
|
||||
{
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
Dtls &dtls = *static_cast<Dtls *>(aContext.GetContext());
|
||||
#else
|
||||
Dtls &dtls = otGetThreadNetif().GetDtls();
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
#endif
|
||||
return dtls;
|
||||
}
|
||||
|
||||
} // namespace MeshCoP
|
||||
} // namespace ot
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include <mbedtls/certs.h>
|
||||
#include <mbedtls/ssl_cookie.h>
|
||||
|
||||
#include "common/locator.hpp"
|
||||
#include "common/message.hpp"
|
||||
#include "common/timer.hpp"
|
||||
#include "crypto/sha256.hpp"
|
||||
@@ -54,7 +55,7 @@ class ThreadNetif;
|
||||
|
||||
namespace MeshCoP {
|
||||
|
||||
class Dtls
|
||||
class Dtls: public ThreadNetifLocator
|
||||
{
|
||||
public:
|
||||
enum
|
||||
@@ -71,14 +72,6 @@ public:
|
||||
*/
|
||||
Dtls(ThreadNetif &aNetif);
|
||||
|
||||
/**
|
||||
* This method returns the pointer to the parent otInstance structure.
|
||||
*
|
||||
* @returns The pointer to the parent otInstance structure.
|
||||
*
|
||||
*/
|
||||
otInstance *GetInstance(void);
|
||||
|
||||
/**
|
||||
* This function pointer is called when a connection is established or torn down.
|
||||
*
|
||||
@@ -224,12 +217,14 @@ private:
|
||||
int HandleMbedtlsExportKeys(const unsigned char *aMasterSecret, const unsigned char *aKeyBlock,
|
||||
size_t aMacLength, size_t aKeyLength, size_t aIvLength);
|
||||
|
||||
static void HandleTimer(void *aContext);
|
||||
static void HandleTimer(Timer &aTimer);
|
||||
void HandleTimer(void);
|
||||
|
||||
void Close(void);
|
||||
void Process(void);
|
||||
|
||||
static Dtls &GetOwner(const Context &aContext);
|
||||
|
||||
uint8_t mPsk[kPskMaxLength];
|
||||
uint8_t mPskLength;
|
||||
|
||||
@@ -255,8 +250,6 @@ private:
|
||||
bool mClient;
|
||||
|
||||
uint8_t mMessageSubType;
|
||||
|
||||
ThreadNetif &mNetif;
|
||||
};
|
||||
|
||||
} // namespace MeshCoP
|
||||
|
||||
@@ -56,23 +56,19 @@ using ot::Encoding::BigEndian::HostSwap32;
|
||||
namespace ot {
|
||||
|
||||
EnergyScanClient::EnergyScanClient(ThreadNetif &aThreadNetif) :
|
||||
mEnergyScan(OT_URI_PATH_ENERGY_REPORT, &EnergyScanClient::HandleReport, this),
|
||||
mNetif(aThreadNetif)
|
||||
ThreadNetifLocator(aThreadNetif),
|
||||
mEnergyScan(OT_URI_PATH_ENERGY_REPORT, &EnergyScanClient::HandleReport, this)
|
||||
{
|
||||
mContext = NULL;
|
||||
mCallback = NULL;
|
||||
mNetif.GetCoap().AddResource(mEnergyScan);
|
||||
}
|
||||
|
||||
otInstance *EnergyScanClient::GetInstance(void)
|
||||
{
|
||||
return mNetif.GetInstance();
|
||||
aThreadNetif.GetCoap().AddResource(mEnergyScan);
|
||||
}
|
||||
|
||||
otError EnergyScanClient::SendQuery(uint32_t aChannelMask, uint8_t aCount, uint16_t aPeriod,
|
||||
uint16_t aScanDuration, const Ip6::Address &aAddress,
|
||||
otCommissionerEnergyReportCallback aCallback, void *aContext)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
Coap::Header header;
|
||||
MeshCoP::CommissionerSessionIdTlv sessionId;
|
||||
@@ -83,7 +79,7 @@ otError EnergyScanClient::SendQuery(uint32_t aChannelMask, uint8_t aCount, uint1
|
||||
Ip6::MessageInfo messageInfo;
|
||||
Message *message = NULL;
|
||||
|
||||
VerifyOrExit(mNetif.GetCommissioner().IsActive(), error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(netif.GetCommissioner().IsActive(), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
header.Init(aAddress.IsMulticast() ? OT_COAP_TYPE_NON_CONFIRMABLE : OT_COAP_TYPE_CONFIRMABLE,
|
||||
OT_COAP_CODE_POST);
|
||||
@@ -91,11 +87,11 @@ otError EnergyScanClient::SendQuery(uint32_t aChannelMask, uint8_t aCount, uint1
|
||||
header.AppendUriPathOptions(OT_URI_PATH_ENERGY_SCAN);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(mNetif.GetCoap(), header)) != NULL,
|
||||
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(netif.GetCoap(), header)) != NULL,
|
||||
error = OT_ERROR_NO_BUFS);
|
||||
|
||||
sessionId.Init();
|
||||
sessionId.SetCommissionerSessionId(mNetif.GetCommissioner().GetSessionId());
|
||||
sessionId.SetCommissionerSessionId(netif.GetCommissioner().GetSessionId());
|
||||
SuccessOrExit(error = message->Append(&sessionId, sizeof(sessionId)));
|
||||
|
||||
channelMask.Init();
|
||||
@@ -114,11 +110,11 @@ otError EnergyScanClient::SendQuery(uint32_t aChannelMask, uint8_t aCount, uint1
|
||||
scanDuration.SetScanDuration(aScanDuration);
|
||||
SuccessOrExit(error = message->Append(&scanDuration, sizeof(scanDuration)));
|
||||
|
||||
messageInfo.SetSockAddr(mNetif.GetMle().GetMeshLocal16());
|
||||
messageInfo.SetSockAddr(netif.GetMle().GetMeshLocal16());
|
||||
messageInfo.SetPeerAddr(aAddress);
|
||||
messageInfo.SetPeerPort(kCoapUdpPort);
|
||||
messageInfo.SetInterfaceId(mNetif.GetInterfaceId());
|
||||
SuccessOrExit(error = mNetif.GetCoap().SendMessage(*message, messageInfo));
|
||||
messageInfo.SetInterfaceId(netif.GetInterfaceId());
|
||||
SuccessOrExit(error = netif.GetCoap().SendMessage(*message, messageInfo));
|
||||
|
||||
otLogInfoMeshCoP(GetInstance(), "sent energy scan query");
|
||||
|
||||
@@ -145,6 +141,7 @@ void EnergyScanClient::HandleReport(void *aContext, otCoapHeader *aHeader, otMes
|
||||
|
||||
void EnergyScanClient::HandleReport(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
MeshCoP::ChannelMask0Tlv channelMask;
|
||||
Ip6::MessageInfo responseInfo(aMessageInfo);
|
||||
|
||||
@@ -171,7 +168,7 @@ void EnergyScanClient::HandleReport(Coap::Header &aHeader, Message &aMessage, co
|
||||
mCallback(channelMask.GetMask(), energyList.list, energyList.tlv.GetLength(), mContext);
|
||||
}
|
||||
|
||||
SuccessOrExit(mNetif.GetCoap().SendEmptyAck(aHeader, responseInfo));
|
||||
SuccessOrExit(netif.GetCoap().SendEmptyAck(aHeader, responseInfo));
|
||||
|
||||
otLogInfoMeshCoP(GetInstance(), "sent energy scan report response");
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
#include "coap/coap.hpp"
|
||||
#include "common/locator.hpp"
|
||||
#include "net/ip6_address.hpp"
|
||||
#include "net/udp6.hpp"
|
||||
|
||||
@@ -49,7 +50,7 @@ class ThreadNetif;
|
||||
* This class implements handling PANID Query Requests.
|
||||
*
|
||||
*/
|
||||
class EnergyScanClient
|
||||
class EnergyScanClient: public ThreadNetifLocator
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -58,14 +59,6 @@ public:
|
||||
*/
|
||||
EnergyScanClient(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 an Energy Scan Query message.
|
||||
*
|
||||
@@ -93,8 +86,6 @@ private:
|
||||
void *mContext;
|
||||
|
||||
Coap::Resource mEnergyScan;
|
||||
|
||||
ThreadNetif &mNetif;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
+54
-41
@@ -61,6 +61,7 @@ namespace ot {
|
||||
namespace MeshCoP {
|
||||
|
||||
Joiner::Joiner(ThreadNetif &aNetif):
|
||||
ThreadNetifLocator(aNetif),
|
||||
mState(kStateIdle),
|
||||
mCallback(NULL),
|
||||
mContext(NULL),
|
||||
@@ -74,21 +75,16 @@ Joiner::Joiner(ThreadNetif &aNetif):
|
||||
mVendorSwVersion(NULL),
|
||||
mVendorData(NULL),
|
||||
mTimer(aNetif.GetIp6().mTimerScheduler, &Joiner::HandleTimer, this),
|
||||
mJoinerEntrust(OT_URI_PATH_JOINER_ENTRUST, &Joiner::HandleJoinerEntrust, this),
|
||||
mNetif(aNetif)
|
||||
mJoinerEntrust(OT_URI_PATH_JOINER_ENTRUST, &Joiner::HandleJoinerEntrust, this)
|
||||
{
|
||||
mNetif.GetCoap().AddResource(mJoinerEntrust);
|
||||
}
|
||||
|
||||
otInstance *Joiner::GetInstance(void)
|
||||
{
|
||||
return mNetif.GetInstance();
|
||||
aNetif.GetCoap().AddResource(mJoinerEntrust);
|
||||
}
|
||||
|
||||
otError Joiner::Start(const char *aPSKd, const char *aProvisioningUrl,
|
||||
const char *aVendorName, const char *aVendorModel, const char *aVendorSwVersion,
|
||||
const char *aVendorData, otJoinerCallback aCallback, void *aContext)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error;
|
||||
Mac::ExtAddress extAddress;
|
||||
Crc16 ccitt(Crc16::kCcitt);
|
||||
@@ -99,9 +95,9 @@ otError Joiner::Start(const char *aPSKd, const char *aProvisioningUrl,
|
||||
VerifyOrExit(mState == kStateIdle, error = OT_ERROR_BUSY);
|
||||
|
||||
// use extended address based on factory-assigned IEEE EUI-64
|
||||
mNetif.GetMac().GetHashMacAddress(&extAddress);
|
||||
mNetif.GetMac().SetExtAddress(extAddress);
|
||||
mNetif.GetMle().UpdateLinkLocalAddress();
|
||||
netif.GetMac().GetHashMacAddress(&extAddress);
|
||||
netif.GetMac().SetExtAddress(extAddress);
|
||||
netif.GetMle().UpdateLinkLocalAddress();
|
||||
|
||||
for (size_t i = 0; i < sizeof(extAddress); i++)
|
||||
{
|
||||
@@ -112,18 +108,19 @@ otError Joiner::Start(const char *aPSKd, const char *aProvisioningUrl,
|
||||
mCcitt = ccitt.Get();
|
||||
mAnsi = ansi.Get();
|
||||
|
||||
error = mNetif.GetCoapSecure().Start(OPENTHREAD_CONFIG_JOINER_UDP_PORT);
|
||||
error = netif.GetCoapSecure().Start(OPENTHREAD_CONFIG_JOINER_UDP_PORT);
|
||||
SuccessOrExit(error);
|
||||
|
||||
error = mNetif.GetCoapSecure().GetDtls().SetPsk(reinterpret_cast<const uint8_t *>(aPSKd),
|
||||
static_cast<uint8_t>(strlen(aPSKd)));
|
||||
error = netif.GetCoapSecure().GetDtls().SetPsk(reinterpret_cast<const uint8_t *>(aPSKd),
|
||||
static_cast<uint8_t>(strlen(aPSKd)));
|
||||
SuccessOrExit(error);
|
||||
|
||||
error = mNetif.GetCoapSecure().GetDtls().mProvisioningUrl.SetProvisioningUrl(aProvisioningUrl);
|
||||
error = netif.GetCoapSecure().GetDtls().mProvisioningUrl.SetProvisioningUrl(aProvisioningUrl);
|
||||
SuccessOrExit(error);
|
||||
|
||||
mJoinerRouterPanId = Mac::kPanIdBroadcast;
|
||||
SuccessOrExit(error = mNetif.GetMle().Discover(0, mNetif.GetMac().GetPanId(), true, false, HandleDiscoverResult, this));
|
||||
SuccessOrExit(error = netif.GetMle().Discover(0, netif.GetMac().GetPanId(), true, false, HandleDiscoverResult,
|
||||
this));
|
||||
|
||||
mVendorName = aVendorName;
|
||||
mVendorModel = aVendorModel;
|
||||
@@ -150,10 +147,11 @@ otError Joiner::Stop(void)
|
||||
|
||||
void Joiner::Close(void)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otLogFuncEntry();
|
||||
|
||||
mNetif.GetCoapSecure().Disconnect();
|
||||
mNetif.GetIp6Filter().RemoveUnsecurePort(mNetif.GetCoapSecure().GetPort());
|
||||
netif.GetCoapSecure().Disconnect();
|
||||
netif.GetIp6Filter().RemoveUnsecurePort(netif.GetCoapSecure().GetPort());
|
||||
|
||||
otLogFuncExit();
|
||||
}
|
||||
@@ -162,7 +160,7 @@ void Joiner::Complete(otError aError)
|
||||
{
|
||||
mState = kStateIdle;
|
||||
|
||||
mNetif.GetCoapSecure().Stop();
|
||||
GetNetif().GetCoapSecure().Stop();
|
||||
|
||||
if (mCallback)
|
||||
{
|
||||
@@ -179,6 +177,7 @@ void Joiner::HandleDiscoverResult(otActiveScanResult *aResult, void *aContext)
|
||||
|
||||
void Joiner::HandleDiscoverResult(otActiveScanResult *aResult)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
Ip6::MessageInfo messageInfo;
|
||||
|
||||
otLogFuncEntry();
|
||||
@@ -216,16 +215,16 @@ void Joiner::HandleDiscoverResult(otActiveScanResult *aResult)
|
||||
{
|
||||
otLogFuncEntryMsg("aResult = NULL");
|
||||
|
||||
mNetif.GetMac().SetPanId(mJoinerRouterPanId);
|
||||
mNetif.GetMac().SetChannel(mJoinerRouterChannel);
|
||||
mNetif.GetIp6Filter().AddUnsecurePort(mNetif.GetCoapSecure().GetPort());
|
||||
netif.GetMac().SetPanId(mJoinerRouterPanId);
|
||||
netif.GetMac().SetChannel(mJoinerRouterChannel);
|
||||
netif.GetIp6Filter().AddUnsecurePort(netif.GetCoapSecure().GetPort());
|
||||
|
||||
messageInfo.GetPeerAddr().mFields.m16[0] = HostSwap16(0xfe80);
|
||||
messageInfo.GetPeerAddr().SetIid(mJoinerRouter);
|
||||
messageInfo.mPeerPort = mJoinerUdpPort;
|
||||
messageInfo.mInterfaceId = OT_NETIF_INTERFACE_ID_THREAD;
|
||||
|
||||
mNetif.GetCoapSecure().Connect(messageInfo, Joiner::HandleSecureCoapClientConnect, this);
|
||||
netif.GetCoapSecure().Connect(messageInfo, Joiner::HandleSecureCoapClientConnect, this);
|
||||
mState = kStateConnect;
|
||||
}
|
||||
else
|
||||
@@ -268,6 +267,7 @@ void Joiner::HandleSecureCoapClientConnect(bool aConnected)
|
||||
|
||||
void Joiner::SendJoinerFinalize(void)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
Coap::Header header;
|
||||
otError error = OT_ERROR_NONE;
|
||||
Message *message = NULL;
|
||||
@@ -283,7 +283,7 @@ void Joiner::SendJoinerFinalize(void)
|
||||
header.AppendUriPathOptions(OT_URI_PATH_JOINER_FINALIZE);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoapSecure(), header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
VerifyOrExit((message = NewMeshCoPMessage(netif.GetCoapSecure(), header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
stateTlv.Init();
|
||||
stateTlv.SetState(MeshCoP::StateTlv::kAccept);
|
||||
@@ -316,10 +316,10 @@ void Joiner::SendJoinerFinalize(void)
|
||||
SuccessOrExit(error = message->Append(&vendorDataTlv, vendorDataTlv.GetSize()));
|
||||
}
|
||||
|
||||
if (mNetif.GetCoapSecure().GetDtls().mProvisioningUrl.GetLength() > 0)
|
||||
if (netif.GetCoapSecure().GetDtls().mProvisioningUrl.GetLength() > 0)
|
||||
{
|
||||
SuccessOrExit(error = message->Append(&mNetif.GetCoapSecure().GetDtls().mProvisioningUrl,
|
||||
mNetif.GetCoapSecure().GetDtls().mProvisioningUrl.GetSize()));
|
||||
SuccessOrExit(error = message->Append(&netif.GetCoapSecure().GetDtls().mProvisioningUrl,
|
||||
netif.GetCoapSecure().GetDtls().mProvisioningUrl.GetSize()));
|
||||
}
|
||||
|
||||
#if OPENTHREAD_ENABLE_CERT_LOG
|
||||
@@ -330,7 +330,7 @@ void Joiner::SendJoinerFinalize(void)
|
||||
message->GetLength() - header.GetLength());
|
||||
#endif
|
||||
|
||||
SuccessOrExit(error = mNetif.GetCoapSecure().SendMessage(*message, Joiner::HandleJoinerFinalizeResponse, this));
|
||||
SuccessOrExit(error = netif.GetCoapSecure().SendMessage(*message, Joiner::HandleJoinerFinalizeResponse, this));
|
||||
|
||||
otLogInfoMeshCoP(GetInstance(), "Sent joiner finalize");
|
||||
|
||||
@@ -395,8 +395,8 @@ void Joiner::HandleJoinerEntrust(void *aContext, otCoapHeader *aHeader, otMessag
|
||||
|
||||
void Joiner::HandleJoinerEntrust(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error;
|
||||
|
||||
NetworkMasterKeyTlv masterKey;
|
||||
MeshLocalPrefixTlv meshLocalPrefix;
|
||||
ExtendedPanIdTlv extendedPanId;
|
||||
@@ -431,11 +431,11 @@ void Joiner::HandleJoinerEntrust(Coap::Header &aHeader, Message &aMessage, const
|
||||
SuccessOrExit(error = Tlv::GetTlv(aMessage, Tlv::kNetworkKeySequence, sizeof(networkKeySeq), networkKeySeq));
|
||||
VerifyOrExit(networkKeySeq.IsValid(), error = OT_ERROR_PARSE);
|
||||
|
||||
mNetif.GetKeyManager().SetMasterKey(masterKey.GetNetworkMasterKey());
|
||||
mNetif.GetKeyManager().SetCurrentKeySequence(networkKeySeq.GetNetworkKeySequence());
|
||||
mNetif.GetMle().SetMeshLocalPrefix(meshLocalPrefix.GetMeshLocalPrefix());
|
||||
mNetif.GetMac().SetExtendedPanId(extendedPanId.GetExtendedPanId());
|
||||
mNetif.GetMac().SetNetworkName(networkName.GetNetworkName());
|
||||
netif.GetKeyManager().SetMasterKey(masterKey.GetNetworkMasterKey());
|
||||
netif.GetKeyManager().SetCurrentKeySequence(networkKeySeq.GetNetworkKeySequence());
|
||||
netif.GetMle().SetMeshLocalPrefix(meshLocalPrefix.GetMeshLocalPrefix());
|
||||
netif.GetMac().SetExtendedPanId(extendedPanId.GetExtendedPanId());
|
||||
netif.GetMac().SetNetworkName(networkName.GetNetworkName());
|
||||
|
||||
otLogInfoMeshCoP(GetInstance(), "join success!");
|
||||
|
||||
@@ -459,6 +459,7 @@ exit:
|
||||
void Joiner::SendJoinerEntrustResponse(const Coap::Header &aRequestHeader,
|
||||
const Ip6::MessageInfo &aRequestInfo)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
Message *message;
|
||||
Coap::Header responseHeader;
|
||||
@@ -468,11 +469,11 @@ void Joiner::SendJoinerEntrustResponse(const Coap::Header &aRequestHeader,
|
||||
|
||||
responseHeader.SetDefaultResponseHeader(aRequestHeader);
|
||||
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoap(), responseHeader)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
VerifyOrExit((message = NewMeshCoPMessage(netif.GetCoap(), responseHeader)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
message->SetSubType(Message::kSubTypeJoinerEntrust);
|
||||
|
||||
memset(&responseInfo.mSockAddr, 0, sizeof(responseInfo.mSockAddr));
|
||||
SuccessOrExit(error = mNetif.GetCoap().SendMessage(*message, responseInfo));
|
||||
SuccessOrExit(error = netif.GetCoap().SendMessage(*message, responseInfo));
|
||||
|
||||
mState = kStateJoined;
|
||||
|
||||
@@ -491,13 +492,14 @@ exit:
|
||||
otLogFuncExit();
|
||||
}
|
||||
|
||||
void Joiner::HandleTimer(void *aContext)
|
||||
void Joiner::HandleTimer(Timer &aTimer)
|
||||
{
|
||||
static_cast<Joiner *>(aContext)->HandleTimer();
|
||||
GetOwner(aTimer).HandleTimer();
|
||||
}
|
||||
|
||||
void Joiner::HandleTimer(void)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
switch (mState)
|
||||
@@ -516,9 +518,9 @@ void Joiner::HandleTimer(void)
|
||||
case kStateJoined:
|
||||
Mac::ExtAddress extAddress;
|
||||
|
||||
mNetif.GetMac().GenerateExtAddress(&extAddress);
|
||||
mNetif.GetMac().SetExtAddress(extAddress);
|
||||
mNetif.GetMle().UpdateLinkLocalAddress();
|
||||
netif.GetMac().GenerateExtAddress(&extAddress);
|
||||
netif.GetMac().SetExtAddress(extAddress);
|
||||
netif.GetMle().UpdateLinkLocalAddress();
|
||||
|
||||
error = OT_ERROR_NONE;
|
||||
break;
|
||||
@@ -528,6 +530,17 @@ void Joiner::HandleTimer(void)
|
||||
Complete(error);
|
||||
}
|
||||
|
||||
Joiner &Joiner::GetOwner(const Context &aContext)
|
||||
{
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
Joiner &joiner = *static_cast<Joiner *>(aContext.GetContext());
|
||||
#else
|
||||
Joiner &joiner = otGetThreadNetif().GetJoiner();
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
#endif
|
||||
return joiner;
|
||||
}
|
||||
|
||||
} // namespace MeshCoP
|
||||
} // namespace ot
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "coap/coap_header.hpp"
|
||||
#include "coap/coap_secure.hpp"
|
||||
#include "common/crc16.hpp"
|
||||
#include "common/locator.hpp"
|
||||
#include "common/message.hpp"
|
||||
#include "meshcop/dtls.hpp"
|
||||
#include "meshcop/meshcop_tlvs.hpp"
|
||||
@@ -51,7 +52,7 @@ class ThreadNetif;
|
||||
|
||||
namespace MeshCoP {
|
||||
|
||||
class Joiner
|
||||
class Joiner: public ThreadNetifLocator
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -62,14 +63,6 @@ public:
|
||||
*/
|
||||
Joiner(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 starts the Joiner service.
|
||||
*
|
||||
@@ -108,7 +101,7 @@ private:
|
||||
static void HandleDiscoverResult(otActiveScanResult *aResult, void *aContext);
|
||||
void HandleDiscoverResult(otActiveScanResult *aResult);
|
||||
|
||||
static void HandleTimer(void *aContext);
|
||||
static void HandleTimer(Timer &aTimer);
|
||||
void HandleTimer(void);
|
||||
|
||||
void Close(void);
|
||||
@@ -128,6 +121,8 @@ private:
|
||||
void HandleJoinerEntrust(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
void SendJoinerEntrustResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aRequestInfo);
|
||||
|
||||
static Joiner &GetOwner(const Context &aContext);
|
||||
|
||||
enum State
|
||||
{
|
||||
kStateIdle = 0,
|
||||
@@ -157,7 +152,6 @@ private:
|
||||
|
||||
Timer mTimer;
|
||||
Coap::Resource mJoinerEntrust;
|
||||
ThreadNetif &mNetif;
|
||||
};
|
||||
|
||||
} // namespace MeshCoP
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "openthread-instance.h"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/encoding.hpp"
|
||||
#include "common/logging.hpp"
|
||||
@@ -57,23 +58,18 @@ namespace ot {
|
||||
namespace MeshCoP {
|
||||
|
||||
JoinerRouter::JoinerRouter(ThreadNetif &aNetif):
|
||||
ThreadNetifLocator(aNetif),
|
||||
mSocket(aNetif.GetIp6().mUdp),
|
||||
mRelayTransmit(OT_URI_PATH_RELAY_TX, &JoinerRouter::HandleRelayTransmit, this),
|
||||
mNetif(aNetif),
|
||||
mTimer(aNetif.GetIp6().mTimerScheduler, &JoinerRouter::HandleTimer, this),
|
||||
mJoinerUdpPort(0),
|
||||
mIsJoinerPortConfigured(false),
|
||||
mExpectJoinEntRsp(false)
|
||||
{
|
||||
mSocket.GetSockName().mPort = OPENTHREAD_CONFIG_JOINER_UDP_PORT;
|
||||
mNetif.GetCoap().AddResource(mRelayTransmit);
|
||||
aNetif.GetCoap().AddResource(mRelayTransmit);
|
||||
mNetifCallback.Set(HandleNetifStateChanged, this);
|
||||
mNetif.RegisterCallback(mNetifCallback);
|
||||
}
|
||||
|
||||
otInstance *JoinerRouter::GetInstance(void)
|
||||
{
|
||||
return mNetif.GetInstance();
|
||||
aNetif.RegisterCallback(mNetifCallback);
|
||||
}
|
||||
|
||||
void JoinerRouter::HandleNetifStateChanged(uint32_t aFlags, void *aContext)
|
||||
@@ -83,12 +79,14 @@ void JoinerRouter::HandleNetifStateChanged(uint32_t aFlags, void *aContext)
|
||||
|
||||
void JoinerRouter::HandleNetifStateChanged(uint32_t aFlags)
|
||||
{
|
||||
VerifyOrExit(mNetif.GetMle().GetDeviceMode() & Mle::ModeTlv::kModeFFD);
|
||||
ThreadNetif &netif = GetNetif();
|
||||
|
||||
VerifyOrExit(netif.GetMle().GetDeviceMode() & Mle::ModeTlv::kModeFFD);
|
||||
VerifyOrExit(aFlags & OT_CHANGED_THREAD_NETDATA);
|
||||
|
||||
mNetif.GetIp6Filter().RemoveUnsecurePort(mSocket.GetSockName().mPort);
|
||||
netif.GetIp6Filter().RemoveUnsecurePort(mSocket.GetSockName().mPort);
|
||||
|
||||
if (mNetif.GetNetworkDataLeader().IsJoiningEnabled())
|
||||
if (netif.GetNetworkDataLeader().IsJoiningEnabled())
|
||||
{
|
||||
Ip6::SockAddr sockaddr;
|
||||
|
||||
@@ -96,7 +94,7 @@ void JoinerRouter::HandleNetifStateChanged(uint32_t aFlags)
|
||||
|
||||
mSocket.Open(&JoinerRouter::HandleUdpReceive, this);
|
||||
mSocket.Bind(sockaddr);
|
||||
mNetif.GetIp6Filter().AddUnsecurePort(sockaddr.mPort);
|
||||
netif.GetIp6Filter().AddUnsecurePort(sockaddr.mPort);
|
||||
otLogInfoMeshCoP(GetInstance(), "Joiner Router: start");
|
||||
}
|
||||
else
|
||||
@@ -113,7 +111,7 @@ otError JoinerRouter::GetBorderAgentRloc(uint16_t &aRloc)
|
||||
otError error = OT_ERROR_NONE;
|
||||
BorderAgentLocatorTlv *borderAgentLocator;
|
||||
|
||||
borderAgentLocator = static_cast<BorderAgentLocatorTlv *>(mNetif.GetNetworkDataLeader().GetCommissioningDataSubTlv(
|
||||
borderAgentLocator = static_cast<BorderAgentLocatorTlv *>(GetNetif().GetNetworkDataLeader().GetCommissioningDataSubTlv(
|
||||
Tlv::kBorderAgentLocator));
|
||||
VerifyOrExit(borderAgentLocator != NULL, error = OT_ERROR_NOT_FOUND);
|
||||
|
||||
@@ -130,7 +128,7 @@ uint16_t JoinerRouter::GetJoinerUdpPort(void)
|
||||
|
||||
VerifyOrExit(!mIsJoinerPortConfigured, rval = mJoinerUdpPort);
|
||||
|
||||
joinerUdpPort = static_cast<JoinerUdpPortTlv *>(mNetif.GetNetworkDataLeader().GetCommissioningDataSubTlv(
|
||||
joinerUdpPort = static_cast<JoinerUdpPortTlv *>(GetNetif().GetNetworkDataLeader().GetCommissioningDataSubTlv(
|
||||
Tlv::kJoinerUdpPort));
|
||||
VerifyOrExit(joinerUdpPort != NULL);
|
||||
|
||||
@@ -158,6 +156,7 @@ void JoinerRouter::HandleUdpReceive(void *aContext, otMessage *aMessage, const o
|
||||
|
||||
void JoinerRouter::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error;
|
||||
Message *message = NULL;
|
||||
Coap::Header header;
|
||||
@@ -179,7 +178,7 @@ void JoinerRouter::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &a
|
||||
header.AppendUriPathOptions(OT_URI_PATH_RELAY_RX);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoap(), header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
VerifyOrExit((message = NewMeshCoPMessage(netif.GetCoap(), header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
udpPort.Init();
|
||||
udpPort.SetUdpPort(aMessageInfo.GetPeerPort());
|
||||
@@ -190,7 +189,7 @@ void JoinerRouter::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &a
|
||||
SuccessOrExit(error = message->Append(&iid, sizeof(iid)));
|
||||
|
||||
rloc.Init();
|
||||
rloc.SetJoinerRouterLocator(mNetif.GetMle().GetRloc16());
|
||||
rloc.SetJoinerRouterLocator(netif.GetMle().GetRloc16());
|
||||
SuccessOrExit(error = message->Append(&rloc, sizeof(rloc)));
|
||||
|
||||
tlv.SetType(Tlv::kJoinerDtlsEncapsulation);
|
||||
@@ -213,12 +212,12 @@ void JoinerRouter::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &a
|
||||
SuccessOrExit(error = message->Append(tmp, length));
|
||||
}
|
||||
|
||||
messageInfo.SetSockAddr(mNetif.GetMle().GetMeshLocal16());
|
||||
messageInfo.SetPeerAddr(mNetif.GetMle().GetMeshLocal16());
|
||||
messageInfo.SetSockAddr(netif.GetMle().GetMeshLocal16());
|
||||
messageInfo.SetPeerAddr(netif.GetMle().GetMeshLocal16());
|
||||
messageInfo.GetPeerAddr().mFields.m16[7] = HostSwap16(borderAgentRloc);
|
||||
messageInfo.SetPeerPort(kCoapUdpPort);
|
||||
|
||||
SuccessOrExit(error = mNetif.GetCoap().SendMessage(*message, messageInfo));
|
||||
SuccessOrExit(error = netif.GetCoap().SendMessage(*message, messageInfo));
|
||||
|
||||
otLogInfoMeshCoP(GetInstance(), "Sent relay rx");
|
||||
|
||||
@@ -291,7 +290,7 @@ void JoinerRouter::HandleRelayTransmit(Coap::Header &aHeader, Message &aMessage,
|
||||
messageInfo.mPeerAddr.mFields.m16[0] = HostSwap16(0xfe80);
|
||||
memcpy(messageInfo.mPeerAddr.mFields.m8 + 8, joinerIid.GetIid(), 8);
|
||||
messageInfo.SetPeerPort(joinerPort.GetUdpPort());
|
||||
messageInfo.SetInterfaceId(mNetif.GetInterfaceId());
|
||||
messageInfo.SetInterfaceId(GetNetif().GetInterfaceId());
|
||||
|
||||
SuccessOrExit(error = mSocket.SendTo(*message, messageInfo));
|
||||
|
||||
@@ -317,6 +316,7 @@ exit:
|
||||
otError JoinerRouter::DelaySendingJoinerEntrust(const Ip6::MessageInfo &aMessageInfo,
|
||||
const JoinerRouterKekTlv &aKek)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error;
|
||||
Message *message = NULL;
|
||||
Coap::Header header;
|
||||
@@ -337,26 +337,26 @@ otError JoinerRouter::DelaySendingJoinerEntrust(const Ip6::MessageInfo &aMessage
|
||||
header.AppendUriPathOptions(OT_URI_PATH_JOINER_ENTRUST);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoap(), header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
VerifyOrExit((message = NewMeshCoPMessage(netif.GetCoap(), header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
message->SetSubType(Message::kSubTypeJoinerEntrust);
|
||||
|
||||
masterKey.Init();
|
||||
masterKey.SetNetworkMasterKey(mNetif.GetKeyManager().GetMasterKey());
|
||||
masterKey.SetNetworkMasterKey(netif.GetKeyManager().GetMasterKey());
|
||||
SuccessOrExit(error = message->Append(&masterKey, sizeof(masterKey)));
|
||||
|
||||
meshLocalPrefix.Init();
|
||||
meshLocalPrefix.SetMeshLocalPrefix(mNetif.GetMle().GetMeshLocalPrefix());
|
||||
meshLocalPrefix.SetMeshLocalPrefix(netif.GetMle().GetMeshLocalPrefix());
|
||||
SuccessOrExit(error = message->Append(&meshLocalPrefix, sizeof(meshLocalPrefix)));
|
||||
|
||||
extendedPanId.Init();
|
||||
extendedPanId.SetExtendedPanId(mNetif.GetMac().GetExtendedPanId());
|
||||
extendedPanId.SetExtendedPanId(netif.GetMac().GetExtendedPanId());
|
||||
SuccessOrExit(error = message->Append(&extendedPanId, sizeof(extendedPanId)));
|
||||
|
||||
networkName.Init();
|
||||
networkName.SetNetworkName(mNetif.GetMac().GetNetworkName());
|
||||
networkName.SetNetworkName(netif.GetMac().GetNetworkName());
|
||||
SuccessOrExit(error = message->Append(&networkName, sizeof(Tlv) + networkName.GetLength()));
|
||||
|
||||
if ((tlv = mNetif.GetActiveDataset().GetNetwork().Get(Tlv::kActiveTimestamp)) != NULL)
|
||||
if ((tlv = netif.GetActiveDataset().GetNetwork().Get(Tlv::kActiveTimestamp)) != NULL)
|
||||
{
|
||||
SuccessOrExit(error = message->Append(tlv, sizeof(Tlv) + tlv->GetLength()));
|
||||
}
|
||||
@@ -367,7 +367,7 @@ otError JoinerRouter::DelaySendingJoinerEntrust(const Ip6::MessageInfo &aMessage
|
||||
SuccessOrExit(error = message->Append(&activeTimestamp, sizeof(activeTimestamp)));
|
||||
}
|
||||
|
||||
if ((tlv = mNetif.GetActiveDataset().GetNetwork().Get(Tlv::kChannelMask)) != NULL)
|
||||
if ((tlv = netif.GetActiveDataset().GetNetwork().Get(Tlv::kChannelMask)) != NULL)
|
||||
{
|
||||
SuccessOrExit(error = message->Append(tlv, sizeof(Tlv) + tlv->GetLength()));
|
||||
}
|
||||
@@ -378,7 +378,7 @@ otError JoinerRouter::DelaySendingJoinerEntrust(const Ip6::MessageInfo &aMessage
|
||||
SuccessOrExit(error = message->Append(&channelMask, sizeof(channelMask)));
|
||||
}
|
||||
|
||||
if ((tlv = mNetif.GetActiveDataset().GetNetwork().Get(Tlv::kPSKc)) != NULL)
|
||||
if ((tlv = netif.GetActiveDataset().GetNetwork().Get(Tlv::kPSKc)) != NULL)
|
||||
{
|
||||
SuccessOrExit(error = message->Append(tlv, sizeof(Tlv) + tlv->GetLength()));
|
||||
}
|
||||
@@ -389,7 +389,7 @@ otError JoinerRouter::DelaySendingJoinerEntrust(const Ip6::MessageInfo &aMessage
|
||||
SuccessOrExit(error = message->Append(&pskc, sizeof(pskc)));
|
||||
}
|
||||
|
||||
if ((tlv = mNetif.GetActiveDataset().GetNetwork().Get(Tlv::kSecurityPolicy)) != NULL)
|
||||
if ((tlv = netif.GetActiveDataset().GetNetwork().Get(Tlv::kSecurityPolicy)) != NULL)
|
||||
{
|
||||
SuccessOrExit(error = message->Append(tlv, sizeof(Tlv) + tlv->GetLength()));
|
||||
}
|
||||
@@ -401,7 +401,7 @@ otError JoinerRouter::DelaySendingJoinerEntrust(const Ip6::MessageInfo &aMessage
|
||||
}
|
||||
|
||||
networkKeySequence.Init();
|
||||
networkKeySequence.SetNetworkKeySequence(mNetif.GetKeyManager().GetCurrentKeySequence());
|
||||
networkKeySequence.SetNetworkKeySequence(netif.GetKeyManager().GetCurrentKeySequence());
|
||||
SuccessOrExit(error = message->Append(&networkKeySequence, networkKeySequence.GetSize()));
|
||||
|
||||
messageInfo = aMessageInfo;
|
||||
@@ -427,9 +427,9 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void JoinerRouter::HandleTimer(void *aContext)
|
||||
void JoinerRouter::HandleTimer(Timer &aTimer)
|
||||
{
|
||||
static_cast<JoinerRouter *>(aContext)->HandleTimer();
|
||||
GetOwner(aTimer).HandleTimer();
|
||||
}
|
||||
|
||||
void JoinerRouter::HandleTimer(void)
|
||||
@@ -439,6 +439,7 @@ void JoinerRouter::HandleTimer(void)
|
||||
|
||||
void JoinerRouter::SendDelayedJoinerEntrust(void)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
DelayedJoinEntHeader delayedJoinEnt;
|
||||
Message *message = mDelayedJoinEnts.GetHead();
|
||||
uint32_t now = Timer::GetNow();
|
||||
@@ -451,7 +452,7 @@ void JoinerRouter::SendDelayedJoinerEntrust(void)
|
||||
|
||||
// The message can be sent during CoAP transaction if KEK did not change (i.e. retransmission).
|
||||
VerifyOrExit(!mExpectJoinEntRsp ||
|
||||
memcmp(mNetif.GetKeyManager().GetKek(), delayedJoinEnt.GetKek(), KeyManager::kMaxKeyLength) == 0);
|
||||
memcmp(netif.GetKeyManager().GetKek(), delayedJoinEnt.GetKek(), KeyManager::kMaxKeyLength) == 0);
|
||||
|
||||
|
||||
if (delayedJoinEnt.IsLater(now))
|
||||
@@ -466,7 +467,7 @@ void JoinerRouter::SendDelayedJoinerEntrust(void)
|
||||
DelayedJoinEntHeader::RemoveFrom(*message);
|
||||
|
||||
// Set KEK to one used for this message.
|
||||
mNetif.GetKeyManager().SetKek(delayedJoinEnt.GetKek());
|
||||
netif.GetKeyManager().SetKek(delayedJoinEnt.GetKek());
|
||||
|
||||
// Send the message.
|
||||
memcpy(&messageInfo, delayedJoinEnt.GetMessageInfo(), sizeof(messageInfo));
|
||||
@@ -484,13 +485,14 @@ exit:
|
||||
|
||||
otError JoinerRouter::SendJoinerEntrust(Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error;
|
||||
|
||||
mNetif.GetCoap().AbortTransaction(&JoinerRouter::HandleJoinerEntrustResponse, this);
|
||||
netif.GetCoap().AbortTransaction(&JoinerRouter::HandleJoinerEntrustResponse, this);
|
||||
|
||||
otLogInfoMeshCoP(GetInstance(), "Sending JOIN_ENT.ntf");
|
||||
SuccessOrExit(error = mNetif.GetCoap().SendMessage(aMessage, aMessageInfo,
|
||||
&JoinerRouter::HandleJoinerEntrustResponse, this));
|
||||
SuccessOrExit(error = netif.GetCoap().SendMessage(aMessage, aMessageInfo,
|
||||
&JoinerRouter::HandleJoinerEntrustResponse, this));
|
||||
|
||||
otLogInfoMeshCoP(GetInstance(), "Sent joiner entrust length = %d", aMessage.GetLength());
|
||||
otLogCertMeshCoP(GetInstance(), "[THCI] direction=send | type=JOIN_ENT.ntf");
|
||||
@@ -529,6 +531,17 @@ exit:
|
||||
return ;
|
||||
}
|
||||
|
||||
JoinerRouter &JoinerRouter::GetOwner(const Context &aContext)
|
||||
{
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
JoinerRouter &joiner = *static_cast<JoinerRouter *>(aContext.GetContext());
|
||||
#else
|
||||
JoinerRouter &joiner = otGetThreadNetif().GetJoinerRouter();
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
#endif
|
||||
return joiner;
|
||||
}
|
||||
|
||||
} // namespace Dtls
|
||||
} // namespace ot
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
|
||||
#include "coap/coap.hpp"
|
||||
#include "coap/coap_header.hpp"
|
||||
#include "common/locator.hpp"
|
||||
#include "common/message.hpp"
|
||||
#include "common/timer.hpp"
|
||||
#include "mac/mac_frame.hpp"
|
||||
@@ -51,7 +52,7 @@ class ThreadNetif;
|
||||
|
||||
namespace MeshCoP {
|
||||
|
||||
class JoinerRouter
|
||||
class JoinerRouter: public ThreadNetifLocator
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -62,14 +63,6 @@ public:
|
||||
*/
|
||||
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.
|
||||
*
|
||||
@@ -109,7 +102,7 @@ private:
|
||||
void HandleJoinerEntrustResponse(Coap::Header *aHeader, Message *aMessage,
|
||||
const Ip6::MessageInfo *aMessageInfo, otError result);
|
||||
|
||||
static void HandleTimer(void *aContext);
|
||||
static void HandleTimer(Timer &aTimer);
|
||||
void HandleTimer(void);
|
||||
|
||||
otError DelaySendingJoinerEntrust(const Ip6::MessageInfo &aMessageInfo, const JoinerRouterKekTlv &aKek);
|
||||
@@ -118,11 +111,12 @@ private:
|
||||
|
||||
otError GetBorderAgentRloc(uint16_t &aRloc);
|
||||
|
||||
static JoinerRouter &GetOwner(const Context &aContext);
|
||||
|
||||
Ip6::NetifCallback mNetifCallback;
|
||||
|
||||
Ip6::UdpSocket mSocket;
|
||||
Coap::Resource mRelayTransmit;
|
||||
ThreadNetif &mNetif;
|
||||
|
||||
Timer mTimer;
|
||||
MessageQueue mDelayedJoinEnts;
|
||||
|
||||
+33
-23
@@ -43,6 +43,7 @@
|
||||
|
||||
#include <openthread/platform/random.h>
|
||||
|
||||
#include "openthread-instance.h"
|
||||
#include "coap/coap_header.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/logging.hpp"
|
||||
@@ -56,20 +57,15 @@ namespace ot {
|
||||
namespace MeshCoP {
|
||||
|
||||
Leader::Leader(ThreadNetif &aThreadNetif):
|
||||
ThreadNetifLocator(aThreadNetif),
|
||||
mPetition(OT_URI_PATH_LEADER_PETITION, Leader::HandlePetition, this),
|
||||
mKeepAlive(OT_URI_PATH_LEADER_KEEP_ALIVE, Leader::HandleKeepAlive, this),
|
||||
mTimer(aThreadNetif.GetIp6().mTimerScheduler, HandleTimer, this),
|
||||
mDelayTimerMinimal(DelayTimerTlv::kDelayTimerMinimal),
|
||||
mSessionId(0xffff),
|
||||
mNetif(aThreadNetif)
|
||||
mSessionId(0xffff)
|
||||
{
|
||||
mNetif.GetCoap().AddResource(mPetition);
|
||||
mNetif.GetCoap().AddResource(mKeepAlive);
|
||||
}
|
||||
|
||||
otInstance *Leader::GetInstance(void)
|
||||
{
|
||||
return mNetif.GetInstance();
|
||||
aThreadNetif.GetCoap().AddResource(mPetition);
|
||||
aThreadNetif.GetCoap().AddResource(mKeepAlive);
|
||||
}
|
||||
|
||||
void Leader::HandlePetition(void *aContext, otCoapHeader *aHeader, otMessage *aMessage,
|
||||
@@ -109,7 +105,8 @@ void Leader::HandlePetition(Coap::Header &aHeader, Message &aMessage, const Ip6:
|
||||
data.mSteeringData.SetLength(1);
|
||||
data.mSteeringData.Clear();
|
||||
|
||||
SuccessOrExit(mNetif.GetNetworkDataLeader().SetCommissioningData(reinterpret_cast<uint8_t *>(&data), data.GetLength()));
|
||||
SuccessOrExit(GetNetif().GetNetworkDataLeader().SetCommissioningData(reinterpret_cast<uint8_t *>(&data),
|
||||
data.GetLength()));
|
||||
|
||||
mCommissionerId = commissionerId;
|
||||
|
||||
@@ -124,6 +121,7 @@ exit:
|
||||
otError Leader::SendPetitionResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aMessageInfo,
|
||||
StateTlv::State aState)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
Coap::Header responseHeader;
|
||||
StateTlv state;
|
||||
@@ -133,7 +131,7 @@ otError Leader::SendPetitionResponse(const Coap::Header &aRequestHeader, const I
|
||||
responseHeader.SetDefaultResponseHeader(aRequestHeader);
|
||||
responseHeader.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoap(), responseHeader)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
VerifyOrExit((message = NewMeshCoPMessage(netif.GetCoap(), responseHeader)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
state.Init();
|
||||
state.SetState(aState);
|
||||
@@ -152,7 +150,7 @@ otError Leader::SendPetitionResponse(const Coap::Header &aRequestHeader, const I
|
||||
SuccessOrExit(error = message->Append(&sessionId, sizeof(sessionId)));
|
||||
}
|
||||
|
||||
SuccessOrExit(error = mNetif.GetCoap().SendMessage(*message, aMessageInfo));
|
||||
SuccessOrExit(error = netif.GetCoap().SendMessage(*message, aMessageInfo));
|
||||
|
||||
otLogInfoMeshCoP(GetInstance(), "sent petition response");
|
||||
|
||||
@@ -212,22 +210,22 @@ exit:
|
||||
otError Leader::SendKeepAliveResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aMessageInfo,
|
||||
StateTlv::State aState)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
Coap::Header responseHeader;
|
||||
StateTlv state;
|
||||
Message *message;
|
||||
|
||||
|
||||
responseHeader.SetDefaultResponseHeader(aRequestHeader);
|
||||
responseHeader.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoap(), responseHeader)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
VerifyOrExit((message = NewMeshCoPMessage(netif.GetCoap(), responseHeader)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
state.Init();
|
||||
state.SetState(aState);
|
||||
SuccessOrExit(error = message->Append(&state, sizeof(state)));
|
||||
|
||||
SuccessOrExit(error = mNetif.GetCoap().SendMessage(*message, aMessageInfo));
|
||||
SuccessOrExit(error = netif.GetCoap().SendMessage(*message, aMessageInfo));
|
||||
|
||||
otLogInfoMeshCoP(GetInstance(), "sent keep alive response");
|
||||
|
||||
@@ -243,6 +241,7 @@ exit:
|
||||
|
||||
otError Leader::SendDatasetChanged(const Ip6::Address &aAddress)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
Coap::Header header;
|
||||
Ip6::MessageInfo messageInfo;
|
||||
@@ -252,12 +251,12 @@ otError Leader::SendDatasetChanged(const Ip6::Address &aAddress)
|
||||
header.SetToken(Coap::Header::kDefaultTokenLength);
|
||||
header.AppendUriPathOptions(OT_URI_PATH_DATASET_CHANGED);
|
||||
|
||||
VerifyOrExit((message = NewMeshCoPMessage(mNetif.GetCoap(), header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
VerifyOrExit((message = NewMeshCoPMessage(netif.GetCoap(), header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
messageInfo.SetSockAddr(mNetif.GetMle().GetMeshLocal16());
|
||||
messageInfo.SetSockAddr(netif.GetMle().GetMeshLocal16());
|
||||
messageInfo.SetPeerAddr(aAddress);
|
||||
messageInfo.SetPeerPort(kCoapUdpPort);
|
||||
SuccessOrExit(error = mNetif.GetCoap().SendMessage(*message, messageInfo));
|
||||
SuccessOrExit(error = netif.GetCoap().SendMessage(*message, messageInfo));
|
||||
|
||||
otLogInfoMeshCoP(GetInstance(), "sent dataset changed");
|
||||
|
||||
@@ -287,14 +286,14 @@ uint32_t Leader::GetDelayTimerMinimal(void) const
|
||||
return mDelayTimerMinimal;
|
||||
}
|
||||
|
||||
void Leader::HandleTimer(void *aContext)
|
||||
void Leader::HandleTimer(Timer &aTimer)
|
||||
{
|
||||
static_cast<Leader *>(aContext)->HandleTimer();
|
||||
GetOwner(aTimer).HandleTimer();
|
||||
}
|
||||
|
||||
void Leader::HandleTimer(void)
|
||||
{
|
||||
VerifyOrExit(mNetif.GetMle().GetRole() == OT_DEVICE_ROLE_LEADER);
|
||||
VerifyOrExit(GetNetif().GetMle().GetRole() == OT_DEVICE_ROLE_LEADER);
|
||||
|
||||
ResignCommissioner();
|
||||
|
||||
@@ -309,8 +308,8 @@ void Leader::SetEmptyCommissionerData(void)
|
||||
mCommissionerSessionId.Init();
|
||||
mCommissionerSessionId.SetCommissionerSessionId(++mSessionId);
|
||||
|
||||
mNetif.GetNetworkDataLeader().SetCommissioningData(reinterpret_cast<uint8_t *>(&mCommissionerSessionId),
|
||||
sizeof(Tlv) + mCommissionerSessionId.GetLength());
|
||||
GetNetif().GetNetworkDataLeader().SetCommissioningData(reinterpret_cast<uint8_t *>(&mCommissionerSessionId),
|
||||
sizeof(Tlv) + mCommissionerSessionId.GetLength());
|
||||
}
|
||||
|
||||
void Leader::ResignCommissioner(void)
|
||||
@@ -321,6 +320,17 @@ void Leader::ResignCommissioner(void)
|
||||
otLogInfoMeshCoP(GetInstance(), "commissioner inactive");
|
||||
}
|
||||
|
||||
Leader &Leader::GetOwner(const Context &aContext)
|
||||
{
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
Leader &leader = *static_cast<Leader *>(aContext.GetContext());
|
||||
#else
|
||||
Leader &leader = otGetThreadNetif().GetLeader();
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
#endif
|
||||
return leader;
|
||||
}
|
||||
|
||||
} // namespace MeshCoP
|
||||
} // namespace ot
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#define MESHCOP_LEADER_HPP_
|
||||
|
||||
#include "coap/coap.hpp"
|
||||
#include "common/locator.hpp"
|
||||
#include "common/timer.hpp"
|
||||
#include "meshcop/meshcop_tlvs.hpp"
|
||||
#include "net/udp6.hpp"
|
||||
@@ -58,7 +59,7 @@ public:
|
||||
SteeringDataTlv mSteeringData;
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
class Leader
|
||||
class Leader: public ThreadNetifLocator
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -69,14 +70,6 @@ public:
|
||||
*/
|
||||
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.
|
||||
*
|
||||
@@ -119,7 +112,7 @@ private:
|
||||
kTimeoutLeaderPetition = 50, ///< TIMEOUT_LEAD_PET (seconds)
|
||||
};
|
||||
|
||||
static void HandleTimer(void *aContext);
|
||||
static void HandleTimer(Timer &aTimer);
|
||||
void HandleTimer(void);
|
||||
|
||||
static void HandlePetition(void *aContext, otCoapHeader *aHeader, otMessage *aMessage,
|
||||
@@ -138,6 +131,8 @@ private:
|
||||
|
||||
void ResignCommissioner(void);
|
||||
|
||||
static Leader &GetOwner(const Context &aContext);
|
||||
|
||||
Coap::Resource mPetition;
|
||||
Coap::Resource mKeepAlive;
|
||||
Timer mTimer;
|
||||
@@ -146,7 +141,6 @@ private:
|
||||
|
||||
CommissionerIdTlv mCommissionerId;
|
||||
uint16_t mSessionId;
|
||||
ThreadNetif &mNetif;
|
||||
};
|
||||
|
||||
} // namespace MeshCoP
|
||||
|
||||
@@ -53,22 +53,18 @@
|
||||
namespace ot {
|
||||
|
||||
PanIdQueryClient::PanIdQueryClient(ThreadNetif &aThreadNetif) :
|
||||
ThreadNetifLocator(aThreadNetif),
|
||||
mCallback(NULL),
|
||||
mContext(NULL),
|
||||
mPanIdQuery(OT_URI_PATH_PANID_CONFLICT, &PanIdQueryClient::HandleConflict, this),
|
||||
mNetif(aThreadNetif)
|
||||
mPanIdQuery(OT_URI_PATH_PANID_CONFLICT, &PanIdQueryClient::HandleConflict, this)
|
||||
{
|
||||
mNetif.GetCoap().AddResource(mPanIdQuery);
|
||||
}
|
||||
|
||||
otInstance *PanIdQueryClient::GetInstance(void)
|
||||
{
|
||||
return mNetif.GetInstance();
|
||||
aThreadNetif.GetCoap().AddResource(mPanIdQuery);
|
||||
}
|
||||
|
||||
otError PanIdQueryClient::SendQuery(uint16_t aPanId, uint32_t aChannelMask, const Ip6::Address &aAddress,
|
||||
otCommissionerPanIdConflictCallback aCallback, void *aContext)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
Coap::Header header;
|
||||
MeshCoP::CommissionerSessionIdTlv sessionId;
|
||||
@@ -77,7 +73,7 @@ otError PanIdQueryClient::SendQuery(uint16_t aPanId, uint32_t aChannelMask, cons
|
||||
Ip6::MessageInfo messageInfo;
|
||||
Message *message = NULL;
|
||||
|
||||
VerifyOrExit(mNetif.GetCommissioner().IsActive(), error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(netif.GetCommissioner().IsActive(), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
header.Init(aAddress.IsMulticast() ? OT_COAP_TYPE_NON_CONFIRMABLE : OT_COAP_TYPE_CONFIRMABLE,
|
||||
OT_COAP_CODE_POST);
|
||||
@@ -85,11 +81,11 @@ otError PanIdQueryClient::SendQuery(uint16_t aPanId, uint32_t aChannelMask, cons
|
||||
header.AppendUriPathOptions(OT_URI_PATH_PANID_QUERY);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(mNetif.GetCoap(), header)) != NULL,
|
||||
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(netif.GetCoap(), header)) != NULL,
|
||||
error = OT_ERROR_NO_BUFS);
|
||||
|
||||
sessionId.Init();
|
||||
sessionId.SetCommissionerSessionId(mNetif.GetCommissioner().GetSessionId());
|
||||
sessionId.SetCommissionerSessionId(netif.GetCommissioner().GetSessionId());
|
||||
SuccessOrExit(error = message->Append(&sessionId, sizeof(sessionId)));
|
||||
|
||||
channelMask.Init();
|
||||
@@ -100,11 +96,11 @@ otError PanIdQueryClient::SendQuery(uint16_t aPanId, uint32_t aChannelMask, cons
|
||||
panId.SetPanId(aPanId);
|
||||
SuccessOrExit(error = message->Append(&panId, sizeof(panId)));
|
||||
|
||||
messageInfo.SetSockAddr(mNetif.GetMle().GetMeshLocal16());
|
||||
messageInfo.SetSockAddr(netif.GetMle().GetMeshLocal16());
|
||||
messageInfo.SetPeerAddr(aAddress);
|
||||
messageInfo.SetPeerPort(kCoapUdpPort);
|
||||
messageInfo.SetInterfaceId(mNetif.GetInterfaceId());
|
||||
SuccessOrExit(error = mNetif.GetCoap().SendMessage(*message, messageInfo));
|
||||
messageInfo.SetInterfaceId(netif.GetInterfaceId());
|
||||
SuccessOrExit(error = netif.GetCoap().SendMessage(*message, messageInfo));
|
||||
|
||||
otLogInfoMeshCoP(GetInstance(), "sent panid query");
|
||||
|
||||
@@ -131,6 +127,7 @@ void PanIdQueryClient::HandleConflict(void *aContext, otCoapHeader *aHeader, otM
|
||||
|
||||
void PanIdQueryClient::HandleConflict(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
MeshCoP::PanIdTlv panId;
|
||||
MeshCoP::ChannelMask0Tlv channelMask;
|
||||
Ip6::MessageInfo responseInfo(aMessageInfo);
|
||||
@@ -151,7 +148,7 @@ void PanIdQueryClient::HandleConflict(Coap::Header &aHeader, Message &aMessage,
|
||||
mCallback(panId.GetPanId(), channelMask.GetMask(), mContext);
|
||||
}
|
||||
|
||||
SuccessOrExit(mNetif.GetCoap().SendEmptyAck(aHeader, responseInfo));
|
||||
SuccessOrExit(netif.GetCoap().SendEmptyAck(aHeader, responseInfo));
|
||||
|
||||
otLogInfoMeshCoP(GetInstance(), "sent panid query conflict response");
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
#include "coap/coap.hpp"
|
||||
#include "common/locator.hpp"
|
||||
#include "net/ip6_address.hpp"
|
||||
#include "net/udp6.hpp"
|
||||
|
||||
@@ -49,7 +50,7 @@ class ThreadNetif;
|
||||
* This class implements handling PANID Query Requests.
|
||||
*
|
||||
*/
|
||||
class PanIdQueryClient
|
||||
class PanIdQueryClient: public ThreadNetifLocator
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -58,14 +59,6 @@ public:
|
||||
*/
|
||||
PanIdQueryClient(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 PAN ID Query message.
|
||||
*
|
||||
@@ -91,8 +84,6 @@ private:
|
||||
void *mContext;
|
||||
|
||||
Coap::Resource mPanIdQuery;
|
||||
|
||||
ThreadNetif &mNetif;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -58,9 +58,9 @@ namespace ot {
|
||||
namespace Dhcp6 {
|
||||
|
||||
Dhcp6Client::Dhcp6Client(ThreadNetif &aThreadNetif) :
|
||||
ThreadNetifLocator(aThreadNetif),
|
||||
mTrickleTimer(aThreadNetif.GetIp6().mTimerScheduler, &Dhcp6Client::HandleTrickleTimer, NULL, this),
|
||||
mSocket(aThreadNetif.GetIp6().mUdp),
|
||||
mNetif(aThreadNetif),
|
||||
mStartTime(0),
|
||||
mAddresses(NULL),
|
||||
mNumAddresses(0)
|
||||
@@ -76,11 +76,6 @@ Dhcp6Client::Dhcp6Client(ThreadNetif &aThreadNetif) :
|
||||
mIdentityAssociationAvail = &mIdentityAssociations[0];
|
||||
}
|
||||
|
||||
otInstance *Dhcp6Client::GetInstance(void)
|
||||
{
|
||||
return mNetif.GetInstance();
|
||||
}
|
||||
|
||||
void Dhcp6Client::UpdateAddresses(otInstance *aInstance, otDhcpAddress *aAddresses, uint32_t aNumAddresses,
|
||||
void *aContext)
|
||||
{
|
||||
@@ -336,10 +331,9 @@ exit:
|
||||
return rval;
|
||||
}
|
||||
|
||||
bool Dhcp6Client::HandleTrickleTimer(void *aContext)
|
||||
bool Dhcp6Client::HandleTrickleTimer(TrickleTimer &aTrickleTimer)
|
||||
{
|
||||
Dhcp6Client *obj = static_cast<Dhcp6Client *>(aContext);
|
||||
return obj->HandleTrickleTimer();
|
||||
return GetOwner(aTrickleTimer).HandleTrickleTimer();
|
||||
}
|
||||
|
||||
bool Dhcp6Client::HandleTrickleTimer(void)
|
||||
@@ -380,6 +374,7 @@ exit:
|
||||
|
||||
otError Dhcp6Client::Solicit(uint16_t aRloc16)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
Message *message;
|
||||
Ip6::MessageInfo messageInfo;
|
||||
@@ -395,14 +390,14 @@ otError Dhcp6Client::Solicit(uint16_t aRloc16)
|
||||
SuccessOrExit(error = AppendRapidCommit(*message));
|
||||
|
||||
memset(&messageInfo, 0, sizeof(messageInfo));
|
||||
memcpy(messageInfo.GetPeerAddr().mFields.m8, mNetif.GetMle().GetMeshLocalPrefix(), 8);
|
||||
memcpy(messageInfo.GetPeerAddr().mFields.m8, netif.GetMle().GetMeshLocalPrefix(), 8);
|
||||
messageInfo.GetPeerAddr().mFields.m16[4] = HostSwap16(0x0000);
|
||||
messageInfo.GetPeerAddr().mFields.m16[5] = HostSwap16(0x00ff);
|
||||
messageInfo.GetPeerAddr().mFields.m16[6] = HostSwap16(0xfe00);
|
||||
messageInfo.GetPeerAddr().mFields.m16[7] = HostSwap16(aRloc16);
|
||||
messageInfo.SetSockAddr(mNetif.GetMle().GetMeshLocal16());
|
||||
messageInfo.SetSockAddr(netif.GetMle().GetMeshLocal16());
|
||||
messageInfo.mPeerPort = kDhcpServerPort;
|
||||
messageInfo.mInterfaceId = mNetif.GetInterfaceId();
|
||||
messageInfo.mInterfaceId = netif.GetInterfaceId();
|
||||
|
||||
SuccessOrExit(error = mSocket.SendTo(*message, messageInfo));
|
||||
otLogInfoIp6(GetInstance(), "solicit");
|
||||
@@ -443,7 +438,7 @@ otError Dhcp6Client::AppendClientIdentifier(Message &aMessage)
|
||||
option.Init();
|
||||
option.SetDuidType(kDuidLL);
|
||||
option.SetDuidHardwareType(kHardwareTypeEui64);
|
||||
option.SetDuidLinkLayerAddress(mNetif.GetMac().GetExtAddress());
|
||||
option.SetDuidLinkLayerAddress(GetNetif().GetMac().GetExtAddress());
|
||||
return aMessage.Append(&option, sizeof(option));
|
||||
}
|
||||
|
||||
@@ -614,7 +609,7 @@ otError Dhcp6Client::ProcessClientIdentifier(Message &aMessage, uint16_t aOffset
|
||||
(option.GetLength() == (sizeof(option) - sizeof(Dhcp6Option))) &&
|
||||
(option.GetDuidType() == kDuidLL) &&
|
||||
(option.GetDuidHardwareType() == kHardwareTypeEui64)) &&
|
||||
(!memcmp(option.GetDuidLinkLayerAddress(), mNetif.GetMac().GetExtAddress(),
|
||||
(!memcmp(option.GetDuidLinkLayerAddress(), GetNetif().GetMac().GetExtAddress(),
|
||||
sizeof(Mac::ExtAddress)))),
|
||||
error = OT_ERROR_PARSE);
|
||||
exit:
|
||||
@@ -700,7 +695,7 @@ otError Dhcp6Client::ProcessIaAddress(Message &aMessage, uint16_t aOffset)
|
||||
address->mValidLifetime = option.GetValidLifetime();
|
||||
address->mAddress.mPreferred = address->mPreferredLifetime != 0;
|
||||
address->mAddress.mValid = address->mValidLifetime != 0;
|
||||
otIp6AddUnicastAddress(mNetif.GetInstance(), &address->mAddress);
|
||||
otIp6AddUnicastAddress(GetNetif().GetInstance(), &address->mAddress);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -722,6 +717,17 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Dhcp6Client &Dhcp6Client::GetOwner(const Context &aContext)
|
||||
{
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
Dhcp6Client &client = *static_cast<Dhcp6Client *>(aContext.GetContext());
|
||||
#else
|
||||
Dhcp6Client &client = otGetThreadNetif().GetDhcp6Client();
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
#endif
|
||||
return client;
|
||||
}
|
||||
|
||||
} // namespace Dhcp6
|
||||
} // namespace ot
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
|
||||
#include <openthread/dhcp6_client.h>
|
||||
|
||||
#include "common/locator.hpp"
|
||||
#include "common/message.hpp"
|
||||
#include "common/timer.hpp"
|
||||
#include "common/trickle_timer.hpp"
|
||||
@@ -167,7 +168,7 @@ private:
|
||||
* This class implements DHCPv6 Client.
|
||||
*
|
||||
*/
|
||||
class Dhcp6Client
|
||||
class Dhcp6Client: public ThreadNetifLocator
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -178,14 +179,6 @@ public:
|
||||
*/
|
||||
explicit Dhcp6Client(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 update addresses that shall be automatically created using DHCP.
|
||||
*
|
||||
@@ -226,13 +219,14 @@ private:
|
||||
otError ProcessStatusCode(Message &aMessage, uint16_t aOffset);
|
||||
otError ProcessIaAddress(Message &aMessage, uint16_t aOffset);
|
||||
|
||||
static bool HandleTrickleTimer(void *aContext);
|
||||
static bool HandleTrickleTimer(TrickleTimer &aTrickleTimer);
|
||||
bool HandleTrickleTimer(void);
|
||||
|
||||
static Dhcp6Client &GetOwner(const Context &aContext);
|
||||
|
||||
TrickleTimer mTrickleTimer;
|
||||
|
||||
Ip6::UdpSocket mSocket;
|
||||
ThreadNetif &mNetif;
|
||||
|
||||
uint8_t mTransactionId[kTransactionIdSize];
|
||||
uint32_t mStartTime;
|
||||
|
||||
@@ -54,8 +54,8 @@ namespace ot {
|
||||
namespace Dhcp6 {
|
||||
|
||||
Dhcp6Server::Dhcp6Server(ThreadNetif &aThreadNetif):
|
||||
mSocket(aThreadNetif.GetIp6().mUdp),
|
||||
mNetif(aThreadNetif)
|
||||
ThreadNetifLocator(aThreadNetif),
|
||||
mSocket(aThreadNetif.GetIp6().mUdp)
|
||||
{
|
||||
for (uint8_t i = 0; i < OPENTHREAD_CONFIG_NUM_DHCP_PREFIXES; i++)
|
||||
{
|
||||
@@ -69,10 +69,11 @@ Dhcp6Server::Dhcp6Server(ThreadNetif &aThreadNetif):
|
||||
|
||||
otError Dhcp6Server::UpdateService(void)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
bool found;
|
||||
uint8_t i;
|
||||
uint16_t rloc16 = mNetif.GetMle().GetRloc16();
|
||||
uint16_t rloc16 = netif.GetMle().GetRloc16();
|
||||
Ip6::Address *address = NULL;
|
||||
otNetworkDataIterator iterator;
|
||||
otBorderRouterConfig config;
|
||||
@@ -91,15 +92,15 @@ otError Dhcp6Server::UpdateService(void)
|
||||
address = &(mAgentsAloc[i].GetAddress());
|
||||
iterator = OT_NETWORK_DATA_ITERATOR_INIT;
|
||||
|
||||
while (mNetif.GetNetworkDataLeader().GetNextOnMeshPrefix(&iterator, rloc16, &config) == OT_ERROR_NONE)
|
||||
while (netif.GetNetworkDataLeader().GetNextOnMeshPrefix(&iterator, rloc16, &config) == OT_ERROR_NONE)
|
||||
{
|
||||
if (!config.mDhcp)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
mNetif.GetNetworkDataLeader().GetContext(*static_cast<const Ip6::Address *>(&(config.mPrefix.mPrefix)),
|
||||
lowpanContext);
|
||||
netif.GetNetworkDataLeader().GetContext(*static_cast<const Ip6::Address *>(&(config.mPrefix.mPrefix)),
|
||||
lowpanContext);
|
||||
|
||||
if (address->mFields.m8[15] == lowpanContext.mContextId)
|
||||
{
|
||||
@@ -111,8 +112,8 @@ otError Dhcp6Server::UpdateService(void)
|
||||
|
||||
if (!found)
|
||||
{
|
||||
mNetif.GetNetworkDataLeader().GetContext(address->mFields.m8[15], lowpanContext);
|
||||
mNetif.RemoveUnicastAddress(mAgentsAloc[i]);
|
||||
netif.GetNetworkDataLeader().GetContext(address->mFields.m8[15], lowpanContext);
|
||||
netif.RemoveUnicastAddress(mAgentsAloc[i]);
|
||||
mAgentsAloc[i].mValid = false;
|
||||
RemovePrefixAgent(lowpanContext.mPrefix);
|
||||
}
|
||||
@@ -121,7 +122,7 @@ otError Dhcp6Server::UpdateService(void)
|
||||
// add dhcp agent aloc and prefix delegation
|
||||
iterator = OT_NETWORK_DATA_ITERATOR_INIT;
|
||||
|
||||
while (mNetif.GetNetworkDataLeader().GetNextOnMeshPrefix(&iterator, rloc16, &config) == OT_ERROR_NONE)
|
||||
while (netif.GetNetworkDataLeader().GetNextOnMeshPrefix(&iterator, rloc16, &config) == OT_ERROR_NONE)
|
||||
{
|
||||
found = false;
|
||||
|
||||
@@ -130,8 +131,8 @@ otError Dhcp6Server::UpdateService(void)
|
||||
continue;
|
||||
}
|
||||
|
||||
mNetif.GetNetworkDataLeader().GetContext(*static_cast<const Ip6::Address *>(&config.mPrefix.mPrefix),
|
||||
lowpanContext);
|
||||
netif.GetNetworkDataLeader().GetContext(*static_cast<const Ip6::Address *>(&config.mPrefix.mPrefix),
|
||||
lowpanContext);
|
||||
|
||||
for (i = 0; i < OPENTHREAD_CONFIG_NUM_DHCP_PREFIXES; i++)
|
||||
{
|
||||
@@ -155,7 +156,7 @@ otError Dhcp6Server::UpdateService(void)
|
||||
if (!mAgentsAloc[i].mValid)
|
||||
{
|
||||
address = &(mAgentsAloc[i].GetAddress());
|
||||
memcpy(address, mNetif.GetMle().GetMeshLocalPrefix(), 8);
|
||||
memcpy(address, netif.GetMle().GetMeshLocalPrefix(), 8);
|
||||
address->mFields.m16[4] = HostSwap16(0x0000);
|
||||
address->mFields.m16[5] = HostSwap16(0x00ff);
|
||||
address->mFields.m16[6] = HostSwap16(0xfe00);
|
||||
@@ -164,7 +165,7 @@ otError Dhcp6Server::UpdateService(void)
|
||||
mAgentsAloc[i].mPrefixLength = 128;
|
||||
mAgentsAloc[i].mPreferred = true;
|
||||
mAgentsAloc[i].mValid = true;
|
||||
mNetif.AddUnicastAddress(mAgentsAloc[i]);
|
||||
netif.AddUnicastAddress(mAgentsAloc[i]);
|
||||
AddPrefixAgent(config.mPrefix);
|
||||
break;
|
||||
}
|
||||
@@ -466,7 +467,7 @@ otError Dhcp6Server::AppendServerIdentifier(Message &aMessage)
|
||||
option.Init();
|
||||
option.SetDuidType(kDuidLL);
|
||||
option.SetDuidHardwareType(kHardwareTypeEui64);
|
||||
option.SetDuidLinkLayerAddress(mNetif.GetMac().GetExtAddress());
|
||||
option.SetDuidLinkLayerAddress(GetNetif().GetMac().GetExtAddress());
|
||||
SuccessOrExit(error = aMessage.Append(&option, sizeof(option)));
|
||||
|
||||
exit:
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
|
||||
#include <openthread/types.h>
|
||||
|
||||
#include "common/locator.hpp"
|
||||
#include "mac/mac_frame.hpp"
|
||||
#include "mac/mac.hpp"
|
||||
#include "net/dhcp6.hpp"
|
||||
@@ -99,7 +100,7 @@ private:
|
||||
otIp6Prefix mIp6Prefix; ///< prefix
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
class Dhcp6Server
|
||||
class Dhcp6Server: public ThreadNetifLocator
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -149,8 +150,6 @@ private:
|
||||
|
||||
Ip6::UdpSocket mSocket;
|
||||
|
||||
ThreadNetif &mNetif;
|
||||
|
||||
Ip6::NetifUnicastAddress mAgentsAloc[OPENTHREAD_CONFIG_NUM_DHCP_PREFIXES];
|
||||
PrefixAgent mPrefixAgents[OPENTHREAD_CONFIG_NUM_DHCP_PREFIXES];
|
||||
uint8_t mPrefixAgentsMask;
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
#include "net/udp6.hpp"
|
||||
#include "thread/thread_netif.hpp"
|
||||
|
||||
#if OPENTHREAD_ENABLE_DNS_CLIENT
|
||||
|
||||
@@ -381,9 +382,9 @@ void Client::FinalizeDnsTransaction(Message &aQuery, const QueryMetadata &aQuery
|
||||
}
|
||||
}
|
||||
|
||||
void Client::HandleRetransmissionTimer(void *aContext)
|
||||
void Client::HandleRetransmissionTimer(Timer &aTimer)
|
||||
{
|
||||
static_cast<Client *>(aContext)->HandleRetransmissionTimer();
|
||||
GetOwner(aTimer).HandleRetransmissionTimer();
|
||||
}
|
||||
|
||||
void Client::HandleRetransmissionTimer(void)
|
||||
@@ -518,6 +519,17 @@ exit:
|
||||
return;
|
||||
}
|
||||
|
||||
Client &Client::GetOwner(const Context &aContext)
|
||||
{
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
Client &client = *static_cast<Client *>(aContext.GetContext());
|
||||
#else
|
||||
Client &client = otGetThreadNetif().GetDnsClient();
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
#endif
|
||||
return client;
|
||||
}
|
||||
|
||||
} // namespace Coap
|
||||
} // namespace ot
|
||||
|
||||
|
||||
@@ -46,7 +46,6 @@
|
||||
namespace ot {
|
||||
namespace Dns {
|
||||
|
||||
|
||||
/**
|
||||
* This class implements metadata required for DNS retransmission.
|
||||
*
|
||||
@@ -245,12 +244,14 @@ private:
|
||||
otIp6Address *aAddress, uint32_t aTtl,
|
||||
otError aResult);
|
||||
|
||||
static void HandleRetransmissionTimer(void *aContext);
|
||||
static void HandleRetransmissionTimer(Timer &aTimer);
|
||||
void HandleRetransmissionTimer(void);
|
||||
|
||||
static void HandleUdpReceive(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo);
|
||||
void HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
static Client &GetOwner(const Context &aContext);
|
||||
|
||||
Ip6::UdpSocket mSocket;
|
||||
|
||||
uint16_t mMessageId;
|
||||
|
||||
+8
-13
@@ -51,21 +51,16 @@ namespace ot {
|
||||
namespace Ip6 {
|
||||
|
||||
Icmp::Icmp(Ip6 &aIp6):
|
||||
Ip6Locator(aIp6),
|
||||
mHandlers(NULL),
|
||||
mEchoSequence(1),
|
||||
mIsEchoEnabled(true),
|
||||
mIp6(aIp6)
|
||||
mIsEchoEnabled(true)
|
||||
{
|
||||
}
|
||||
|
||||
otInstance *Icmp::GetInstance(void)
|
||||
{
|
||||
return mIp6.GetInstance();
|
||||
}
|
||||
|
||||
Message *Icmp::NewMessage(uint16_t aReserved)
|
||||
{
|
||||
return mIp6.NewMessage(sizeof(IcmpHeader) + aReserved);
|
||||
return GetIp6().NewMessage(sizeof(IcmpHeader) + aReserved);
|
||||
}
|
||||
|
||||
otError Icmp::RegisterHandler(IcmpHandler &aHandler)
|
||||
@@ -103,7 +98,7 @@ otError Icmp::SendEchoRequest(Message &aMessage, const MessageInfo &aMessageInfo
|
||||
|
||||
SuccessOrExit(error = aMessage.Prepend(&icmpHeader, sizeof(icmpHeader)));
|
||||
aMessage.SetOffset(0);
|
||||
SuccessOrExit(error = mIp6.SendDatagram(aMessage, messageInfoLocal, kProtoIcmp6));
|
||||
SuccessOrExit(error = GetIp6().SendDatagram(aMessage, messageInfoLocal, kProtoIcmp6));
|
||||
|
||||
otLogInfoIcmp(GetInstance(), "Sent echo request: (seq = %d)", icmpHeader.GetSequence());
|
||||
|
||||
@@ -121,7 +116,7 @@ otError Icmp::SendError(IcmpHeader::Type aType, IcmpHeader::Code aCode, const Me
|
||||
|
||||
messageInfoLocal = aMessageInfo;
|
||||
|
||||
VerifyOrExit((message = mIp6.NewMessage(0)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
VerifyOrExit((message = GetIp6().NewMessage(0)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
SuccessOrExit(error = message->SetLength(sizeof(icmp6Header) + sizeof(aHeader)));
|
||||
|
||||
message->Write(sizeof(icmp6Header), sizeof(aHeader), &aHeader);
|
||||
@@ -131,7 +126,7 @@ otError Icmp::SendError(IcmpHeader::Type aType, IcmpHeader::Code aCode, const Me
|
||||
icmp6Header.SetCode(aCode);
|
||||
message->Write(0, sizeof(icmp6Header), &icmp6Header);
|
||||
|
||||
SuccessOrExit(error = mIp6.SendDatagram(*message, messageInfoLocal, kProtoIcmp6));
|
||||
SuccessOrExit(error = GetIp6().SendDatagram(*message, messageInfoLocal, kProtoIcmp6));
|
||||
|
||||
otLogInfoIcmp(GetInstance(), "Sent ICMPv6 Error");
|
||||
|
||||
@@ -191,7 +186,7 @@ otError Icmp::HandleEchoRequest(Message &aRequestMessage, const MessageInfo &aMe
|
||||
icmp6Header.Init();
|
||||
icmp6Header.SetType(IcmpHeader::kTypeEchoReply);
|
||||
|
||||
if ((replyMessage = mIp6.NewMessage(0)) == NULL)
|
||||
if ((replyMessage = GetIp6().NewMessage(0)) == NULL)
|
||||
{
|
||||
otLogDebgIcmp(GetInstance(), "Failed to allocate a new message");
|
||||
ExitNow();
|
||||
@@ -213,7 +208,7 @@ otError Icmp::HandleEchoRequest(Message &aRequestMessage, const MessageInfo &aMe
|
||||
|
||||
replyMessageInfo.SetInterfaceId(aMessageInfo.mInterfaceId);
|
||||
|
||||
SuccessOrExit(error = mIp6.SendDatagram(*replyMessage, replyMessageInfo, kProtoIcmp6));
|
||||
SuccessOrExit(error = GetIp6().SendDatagram(*replyMessage, replyMessageInfo, kProtoIcmp6));
|
||||
|
||||
replyMessage->Read(replyMessage->GetOffset(), sizeof(icmp6Header), &icmp6Header);
|
||||
otLogInfoIcmp(GetInstance(), "Sent Echo Reply (seq = %d)", icmp6Header.GetSequence());
|
||||
|
||||
+2
-11
@@ -37,6 +37,7 @@
|
||||
#include <openthread/icmp6.h>
|
||||
|
||||
#include "common/encoding.hpp"
|
||||
#include "common/locator.hpp"
|
||||
#include "net/ip6_headers.hpp"
|
||||
|
||||
using ot::Encoding::BigEndian::HostSwap16;
|
||||
@@ -219,7 +220,7 @@ private:
|
||||
* This class implements ICMPv6.
|
||||
*
|
||||
*/
|
||||
class Icmp
|
||||
class Icmp: public Ip6Locator
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -230,14 +231,6 @@ public:
|
||||
*/
|
||||
Icmp(Ip6 &aIp6);
|
||||
|
||||
/**
|
||||
* This method returns the pointer to the parent otInstance structure.
|
||||
*
|
||||
* @returns The pointer to the parent otInstance structure.
|
||||
*
|
||||
*/
|
||||
otInstance *GetInstance(void);
|
||||
|
||||
/**
|
||||
* This method returns a new ICMP message with sufficient header space reserved.
|
||||
*
|
||||
@@ -337,8 +330,6 @@ private:
|
||||
|
||||
uint16_t mEchoSequence;
|
||||
bool mIsEchoEnabled;
|
||||
|
||||
Ip6 &mIp6;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
+13
-2
@@ -421,9 +421,9 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void Ip6::HandleSendQueue(void *aContext)
|
||||
void Ip6::HandleSendQueue(Tasklet &aTasklet)
|
||||
{
|
||||
static_cast<Ip6 *>(aContext)->HandleSendQueue();
|
||||
GetOwner(aTasklet).HandleSendQueue();
|
||||
}
|
||||
|
||||
void Ip6::HandleSendQueue(void)
|
||||
@@ -1119,6 +1119,17 @@ otInstance *Ip6::GetInstance(void)
|
||||
return otInstanceFromIp6(this);
|
||||
}
|
||||
|
||||
Ip6 &Ip6::GetOwner(const Context &aContext)
|
||||
{
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
Ip6 &ip6 = *static_cast<Ip6 *>(aContext.GetContext());
|
||||
#else
|
||||
Ip6 &ip6 = otGetIp6();
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
#endif
|
||||
return ip6;
|
||||
}
|
||||
|
||||
const char *Ip6::IpProtoToString(IpProto aIpProto)
|
||||
{
|
||||
const char *retval;
|
||||
|
||||
@@ -377,7 +377,7 @@ public:
|
||||
TimerScheduler mTimerScheduler;
|
||||
|
||||
private:
|
||||
static void HandleSendQueue(void *aContext);
|
||||
static void HandleSendQueue(Tasklet &aTasklet);
|
||||
void HandleSendQueue(void);
|
||||
|
||||
otError ProcessReceiveCallback(const Message &aMessage, const MessageInfo &aMessageInfo, uint8_t aIpProto,
|
||||
@@ -393,6 +393,8 @@ private:
|
||||
otError HandlePayload(Message &aMessage, MessageInfo &aMessageInfo, uint8_t aIpProto);
|
||||
int8_t FindForwardInterfaceId(const MessageInfo &aMessageInfo);
|
||||
|
||||
static Ip6 &GetOwner(const Context &aContext);
|
||||
|
||||
bool mForwardingEnabled;
|
||||
|
||||
PriorityQueue mSendQueue;
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
|
||||
#include <openthread/platform/random.h>
|
||||
|
||||
#include "openthread-instance.h"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/message.hpp"
|
||||
#include "net/ip6.hpp"
|
||||
@@ -55,7 +56,7 @@ void MplBufferedMessageMetadata::GenerateNextTransmissionTime(uint32_t aCurrentT
|
||||
}
|
||||
|
||||
Mpl::Mpl(Ip6 &aIp6):
|
||||
mIp6(aIp6),
|
||||
Ip6Locator(aIp6),
|
||||
mSeedSetTimer(aIp6.mTimerScheduler, &Mpl::HandleSeedSetTimer, this),
|
||||
mRetransmissionTimer(aIp6.mTimerScheduler, &Mpl::HandleRetransmissionTimer, this),
|
||||
mTimerExpirations(0),
|
||||
@@ -250,12 +251,12 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void Mpl::HandleRetransmissionTimer(void *aContext)
|
||||
void Mpl::HandleRetransmissionTimer(Timer &aTimer)
|
||||
{
|
||||
static_cast<Mpl *>(aContext)->HandleRetransmissionTimer();
|
||||
GetOwner(aTimer).HandleRetransmissionTimer();
|
||||
}
|
||||
|
||||
void Mpl::HandleRetransmissionTimer()
|
||||
void Mpl::HandleRetransmissionTimer(void)
|
||||
{
|
||||
uint32_t now = Timer::GetNow();
|
||||
uint32_t nextDelta = 0xffffffff;
|
||||
@@ -293,7 +294,7 @@ void Mpl::HandleRetransmissionTimer()
|
||||
messageCopy->SetSubType(Message::kSubTypeMplRetransmission);
|
||||
}
|
||||
|
||||
mIp6.EnqueueDatagram(*messageCopy);
|
||||
GetIp6().EnqueueDatagram(*messageCopy);
|
||||
}
|
||||
|
||||
messageMetadata.GenerateNextTransmissionTime(now, kDataMessageInterval);
|
||||
@@ -318,7 +319,7 @@ void Mpl::HandleRetransmissionTimer()
|
||||
|
||||
// Remove the extra metadata from the MPL Data Message.
|
||||
messageMetadata.RemoveFrom(*message);
|
||||
mIp6.EnqueueDatagram(*message);
|
||||
GetIp6().EnqueueDatagram(*message);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -337,12 +338,12 @@ void Mpl::HandleRetransmissionTimer()
|
||||
}
|
||||
}
|
||||
|
||||
void Mpl::HandleSeedSetTimer(void *aContext)
|
||||
void Mpl::HandleSeedSetTimer(Timer &aTimer)
|
||||
{
|
||||
static_cast<Mpl *>(aContext)->HandleSeedSetTimer();
|
||||
GetOwner(aTimer).HandleSeedSetTimer();
|
||||
}
|
||||
|
||||
void Mpl::HandleSeedSetTimer()
|
||||
void Mpl::HandleSeedSetTimer(void)
|
||||
{
|
||||
bool startTimer = false;
|
||||
|
||||
@@ -361,5 +362,16 @@ void Mpl::HandleSeedSetTimer()
|
||||
}
|
||||
}
|
||||
|
||||
Mpl &Mpl::GetOwner(const Context &aContext)
|
||||
{
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
Mpl &mpl = *static_cast<Mpl *>(aContext.GetContext());
|
||||
#else
|
||||
Mpl &mpl = otGetIp6().mMpl;
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
#endif
|
||||
return mpl;
|
||||
}
|
||||
|
||||
} // namespace Ip6
|
||||
} // namespace ot
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
|
||||
#include <openthread/types.h>
|
||||
|
||||
#include "common/locator.hpp"
|
||||
#include "common/message.hpp"
|
||||
#include "common/timer.hpp"
|
||||
#include "net/ip6_headers.hpp"
|
||||
@@ -427,7 +428,7 @@ private:
|
||||
* This class implements MPL message processing.
|
||||
*
|
||||
*/
|
||||
class Mpl
|
||||
class Mpl: public Ip6Locator
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -526,13 +527,13 @@ private:
|
||||
void UpdateBufferedSet(uint16_t aSeedId, uint8_t aSequence);
|
||||
void AddBufferedMessage(Message &aMessage, uint16_t aSeedId, uint8_t aSequence, bool aIsOutbound);
|
||||
|
||||
static void HandleSeedSetTimer(void *aContext);
|
||||
static void HandleSeedSetTimer(Timer &aTimer);
|
||||
void HandleSeedSetTimer(void);
|
||||
|
||||
static void HandleRetransmissionTimer(void *aContext);
|
||||
static void HandleRetransmissionTimer(Timer &aTimer);
|
||||
void HandleRetransmissionTimer(void);
|
||||
|
||||
Ip6 &mIp6;
|
||||
static Mpl &GetOwner(const Context &aContext);
|
||||
|
||||
Timer mSeedSetTimer;
|
||||
Timer mRetransmissionTimer;
|
||||
|
||||
@@ -44,8 +44,8 @@ namespace ot {
|
||||
namespace Ip6 {
|
||||
|
||||
Routes::Routes(Ip6 &aIp6):
|
||||
mRoutes(NULL),
|
||||
mIp6(aIp6)
|
||||
Ip6Locator(aIp6),
|
||||
mRoutes(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ int8_t Routes::Lookup(const Address &aSource, const Address &aDestination)
|
||||
rval = cur->mInterfaceId;
|
||||
}
|
||||
|
||||
for (Netif *netif = mIp6.GetNetifList(); netif; netif = netif->GetNext())
|
||||
for (Netif *netif = GetIp6().GetNetifList(); netif; netif = netif->GetNext())
|
||||
{
|
||||
if (netif->RouteLookup(aSource, aDestination, &prefixMatch) == OT_ERROR_NONE &&
|
||||
static_cast<int8_t>(prefixMatch) > maxPrefixMatch)
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
|
||||
#include <openthread/types.h>
|
||||
|
||||
#include "common/locator.hpp"
|
||||
#include "common/message.hpp"
|
||||
#include "net/ip6_address.hpp"
|
||||
#include "net/ip6_routes.hpp"
|
||||
@@ -68,7 +69,7 @@ struct Route
|
||||
* This class implements IPv6 route management.
|
||||
*
|
||||
*/
|
||||
class Routes
|
||||
class Routes: public Ip6Locator
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -114,7 +115,6 @@ public:
|
||||
|
||||
private:
|
||||
Route *mRoutes;
|
||||
Ip6 &mIp6;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
+15
-3
@@ -34,6 +34,7 @@
|
||||
|
||||
#include "netif.hpp"
|
||||
|
||||
#include "openthread-instance.h"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
#include "common/message.hpp"
|
||||
@@ -43,7 +44,7 @@ namespace ot {
|
||||
namespace Ip6 {
|
||||
|
||||
Netif::Netif(Ip6 &aIp6, int8_t aInterfaceId):
|
||||
mIp6(aIp6),
|
||||
Ip6Locator(aIp6),
|
||||
mCallbacks(NULL),
|
||||
mUnicastAddresses(NULL),
|
||||
mMulticastAddresses(NULL),
|
||||
@@ -444,9 +445,9 @@ void Netif::SetStateChangedFlags(uint32_t aFlags)
|
||||
mStateChangedTask.Post();
|
||||
}
|
||||
|
||||
void Netif::HandleStateChangedTask(void *aContext)
|
||||
void Netif::HandleStateChangedTask(Tasklet &aTasklet)
|
||||
{
|
||||
static_cast<Netif *>(aContext)->HandleStateChangedTask();
|
||||
GetOwner(aTasklet).HandleStateChangedTask();
|
||||
}
|
||||
|
||||
void Netif::HandleStateChangedTask(void)
|
||||
@@ -461,5 +462,16 @@ void Netif::HandleStateChangedTask(void)
|
||||
}
|
||||
}
|
||||
|
||||
Netif &Netif::GetOwner(const Context &aContext)
|
||||
{
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
Netif &netif = *static_cast<Netif *>(aContext.GetContext());
|
||||
#else
|
||||
Netif &netif = otGetThreadNetif();
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
#endif
|
||||
return netif;
|
||||
}
|
||||
|
||||
} // namespace Ip6
|
||||
} // namespace ot
|
||||
|
||||
+4
-13
@@ -34,6 +34,7 @@
|
||||
#ifndef NET_NETIF_HPP_
|
||||
#define NET_NETIF_HPP_
|
||||
|
||||
#include "common/locator.hpp"
|
||||
#include "common/message.hpp"
|
||||
#include "common/tasklet.hpp"
|
||||
#include "mac/mac_frame.hpp"
|
||||
@@ -247,7 +248,7 @@ private:
|
||||
* This class implements an IPv6 network interface.
|
||||
*
|
||||
*/
|
||||
class Netif
|
||||
class Netif: public Ip6Locator
|
||||
{
|
||||
friend class Ip6;
|
||||
|
||||
@@ -261,14 +262,6 @@ public:
|
||||
*/
|
||||
Netif(Ip6 &aIp6, int8_t aInterfaceId);
|
||||
|
||||
/**
|
||||
* This method returns a reference to the IPv6 network object.
|
||||
*
|
||||
* @returns A reference to the IPv6 network object.
|
||||
*
|
||||
*/
|
||||
Ip6 &GetIp6(void) { return mIp6; }
|
||||
|
||||
/**
|
||||
* This method returns the next network interface in the list.
|
||||
*
|
||||
@@ -527,12 +520,10 @@ public:
|
||||
virtual otError RouteLookup(const Address &aSource, const Address &aDestination,
|
||||
uint8_t *aPrefixMatch) = 0;
|
||||
|
||||
protected:
|
||||
Ip6 &mIp6;
|
||||
|
||||
private:
|
||||
static void HandleStateChangedTask(void *aContext);
|
||||
static void HandleStateChangedTask(Tasklet &aTasklet);
|
||||
void HandleStateChangedTask(void);
|
||||
static Netif &GetOwner(const Context &aContext);
|
||||
|
||||
NetifCallback *mCallbacks;
|
||||
NetifUnicastAddress *mUnicastAddresses;
|
||||
|
||||
@@ -128,9 +128,9 @@ exit:
|
||||
}
|
||||
|
||||
Udp::Udp(Ip6 &aIp6):
|
||||
Ip6Locator(aIp6),
|
||||
mEphemeralPort(kDynamicPortMin),
|
||||
mSockets(NULL),
|
||||
mIp6(aIp6)
|
||||
mSockets(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -192,12 +192,12 @@ uint16_t Udp::GetEphemeralPort(void)
|
||||
|
||||
Message *Udp::NewMessage(uint16_t aReserved)
|
||||
{
|
||||
return mIp6.NewMessage(sizeof(UdpHeader) + aReserved);
|
||||
return GetIp6().NewMessage(sizeof(UdpHeader) + aReserved);
|
||||
}
|
||||
|
||||
otError Udp::SendDatagram(Message &aMessage, MessageInfo &aMessageInfo, IpProto aIpProto)
|
||||
{
|
||||
return mIp6.SendDatagram(aMessage, aMessageInfo, aIpProto);
|
||||
return GetIp6().SendDatagram(aMessage, aMessageInfo, aIpProto);
|
||||
}
|
||||
|
||||
otError Udp::HandleMessage(Message &aMessage, MessageInfo &aMessageInfo)
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
|
||||
#include <openthread/udp.h>
|
||||
|
||||
#include "common/locator.hpp"
|
||||
#include "net/ip6_headers.hpp"
|
||||
|
||||
namespace ot {
|
||||
@@ -160,7 +161,7 @@ private:
|
||||
* This class implements core UDP message handling.
|
||||
*
|
||||
*/
|
||||
class Udp
|
||||
class Udp: public Ip6Locator
|
||||
{
|
||||
friend class UdpSocket;
|
||||
|
||||
@@ -256,8 +257,6 @@ private:
|
||||
};
|
||||
uint16_t mEphemeralPort;
|
||||
UdpSocket *mSockets;
|
||||
|
||||
Ip6 &mIp6;
|
||||
};
|
||||
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
|
||||
@@ -44,11 +44,10 @@
|
||||
#include <openthread/platform/logging.h>
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
|
||||
#include "openthread-single-instance.h"
|
||||
#if OPENTHREAD_ENABLE_RAW_LINK_API
|
||||
#include "api/link_raw.hpp"
|
||||
#endif
|
||||
|
||||
#include "coap/coap.hpp"
|
||||
#include "crypto/mbedtls.hpp"
|
||||
#include "net/ip6.hpp"
|
||||
@@ -78,7 +77,7 @@ typedef struct otInstance
|
||||
// State
|
||||
//
|
||||
|
||||
#ifndef OPENTHREAD_MULTIPLE_INSTANCE
|
||||
#if !OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
ot::Crypto::MbedTls mMbedTls;
|
||||
#endif
|
||||
ot::Ip6::Ip6 mIp6;
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (c) 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 getter functions for single instance OpenThread objects.
|
||||
*/
|
||||
|
||||
#ifndef SINGLE_OPENTHREAD_INSTANCE_H_
|
||||
#define SINGLE_OPENTHREAD_INSTANCE_H_
|
||||
|
||||
#include <openthread/config.h>
|
||||
|
||||
#include <openthread/types.h>
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
|
||||
|
||||
#if !OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
|
||||
namespace ot {
|
||||
|
||||
class ThreadNetif;
|
||||
class MeshForwarder;
|
||||
class TimerScheduler;
|
||||
class TaskletScheduler;
|
||||
namespace Ip6 { class Ip6; }
|
||||
|
||||
} // namespace ot
|
||||
|
||||
/**
|
||||
* This function returns a pointer to the single otInstance (if initialized and ready).
|
||||
*
|
||||
* @returns A pointer to single otInstance structure, or NULL if the instance is not ready, i.e. either it is not yet
|
||||
* initialized (no call to `otInstanceInitSingle()`) or it is finalized (call to `otInstanceFinalize()`).
|
||||
*
|
||||
*/
|
||||
otInstance *otGetInstance(void);
|
||||
|
||||
/**
|
||||
* This function returns a reference to the single thread network interface instance.
|
||||
*
|
||||
* @returns A reference to the thread network interface instance.
|
||||
*
|
||||
*/
|
||||
ot::ThreadNetif &otGetThreadNetif(void);
|
||||
|
||||
/**
|
||||
* This function returns a reference to the single MeshForwarder instance.
|
||||
*
|
||||
* @returns A reference to the MeshForwarder instance.
|
||||
*
|
||||
*/
|
||||
ot::MeshForwarder &otGetMeshForwarder(void);
|
||||
|
||||
/**
|
||||
* This function returns a reference to the single TimerScheduler instance.
|
||||
*
|
||||
* @returns A reference to the TimerScheduler instance.
|
||||
*
|
||||
*/
|
||||
ot::TimerScheduler &otGetTimerScheduler(void);
|
||||
|
||||
/**
|
||||
* This function returns a reference to the single TaskletShceduler instance.
|
||||
*
|
||||
* @returns A reference to the TaskletShceduler instance.
|
||||
*
|
||||
*/
|
||||
ot::TaskletScheduler &otGetTaskletScheduler(void);
|
||||
|
||||
/**
|
||||
* This function returns a reference to the single Ip6 instance.
|
||||
*
|
||||
* @returns A reference to the Ip6 instance.
|
||||
*
|
||||
*/
|
||||
ot::Ip6::Ip6 &otGetIp6(void);
|
||||
|
||||
#endif // #if !OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
|
||||
#endif // SINGLE_OPENTHREAD_INSTANCE_H_
|
||||
@@ -41,6 +41,7 @@
|
||||
|
||||
#include <openthread/platform/random.h>
|
||||
|
||||
#include "openthread-instance.h"
|
||||
#include "coap/coap_header.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
@@ -58,25 +59,20 @@ using ot::Encoding::BigEndian::HostSwap16;
|
||||
namespace ot {
|
||||
|
||||
AddressResolver::AddressResolver(ThreadNetif &aThreadNetif) :
|
||||
ThreadNetifLocator(aThreadNetif),
|
||||
mAddressError(OT_URI_PATH_ADDRESS_ERROR, &AddressResolver::HandleAddressError, this),
|
||||
mAddressQuery(OT_URI_PATH_ADDRESS_QUERY, &AddressResolver::HandleAddressQuery, this),
|
||||
mAddressNotification(OT_URI_PATH_ADDRESS_NOTIFY, &AddressResolver::HandleAddressNotification, this),
|
||||
mIcmpHandler(&AddressResolver::HandleIcmpReceive, this),
|
||||
mTimer(aThreadNetif.GetIp6().mTimerScheduler, &AddressResolver::HandleTimer, this),
|
||||
mNetif(aThreadNetif)
|
||||
mTimer(aThreadNetif.GetIp6().mTimerScheduler, &AddressResolver::HandleTimer, this)
|
||||
{
|
||||
Clear();
|
||||
|
||||
mNetif.GetCoap().AddResource(mAddressError);
|
||||
mNetif.GetCoap().AddResource(mAddressQuery);
|
||||
mNetif.GetCoap().AddResource(mAddressNotification);
|
||||
aThreadNetif.GetCoap().AddResource(mAddressError);
|
||||
aThreadNetif.GetCoap().AddResource(mAddressQuery);
|
||||
aThreadNetif.GetCoap().AddResource(mAddressNotification);
|
||||
|
||||
mNetif.GetIp6().mIcmp.RegisterHandler(mIcmpHandler);
|
||||
}
|
||||
|
||||
otInstance *AddressResolver::GetInstance(void)
|
||||
{
|
||||
return mNetif.GetInstance();
|
||||
aThreadNetif.GetIp6().mIcmp.RegisterHandler(mIcmpHandler);
|
||||
}
|
||||
|
||||
void AddressResolver::Clear()
|
||||
@@ -233,6 +229,7 @@ exit:
|
||||
|
||||
otError AddressResolver::SendAddressQuery(const Ip6::Address &aEid)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error;
|
||||
Message *message;
|
||||
Coap::Header header;
|
||||
@@ -243,7 +240,7 @@ otError AddressResolver::SendAddressQuery(const Ip6::Address &aEid)
|
||||
header.AppendUriPathOptions(OT_URI_PATH_ADDRESS_QUERY);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = mNetif.GetCoap().NewMessage(header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
VerifyOrExit((message = netif.GetCoap().NewMessage(header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
targetTlv.Init();
|
||||
targetTlv.SetTarget(aEid);
|
||||
@@ -251,11 +248,11 @@ otError AddressResolver::SendAddressQuery(const Ip6::Address &aEid)
|
||||
|
||||
messageInfo.GetPeerAddr().mFields.m16[0] = HostSwap16(0xff03);
|
||||
messageInfo.GetPeerAddr().mFields.m16[7] = HostSwap16(0x0002);
|
||||
messageInfo.SetSockAddr(mNetif.GetMle().GetMeshLocal16());
|
||||
messageInfo.SetSockAddr(netif.GetMle().GetMeshLocal16());
|
||||
messageInfo.SetPeerPort(kCoapUdpPort);
|
||||
messageInfo.SetInterfaceId(mNetif.GetInterfaceId());
|
||||
messageInfo.SetInterfaceId(netif.GetInterfaceId());
|
||||
|
||||
SuccessOrExit(error = mNetif.GetCoap().SendMessage(*message, messageInfo));
|
||||
SuccessOrExit(error = netif.GetCoap().SendMessage(*message, messageInfo));
|
||||
|
||||
otLogInfoArp(GetInstance(), "Sent address query");
|
||||
|
||||
@@ -285,6 +282,7 @@ void AddressResolver::HandleAddressNotification(void *aContext, otCoapHeader *aH
|
||||
void AddressResolver::HandleAddressNotification(Coap::Header &aHeader, Message &aMessage,
|
||||
const Ip6::MessageInfo &aMessageInfo)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
ThreadTargetTlv targetTlv;
|
||||
ThreadMeshLocalEidTlv mlIidTlv;
|
||||
ThreadRloc16Tlv rloc16Tlv;
|
||||
@@ -351,12 +349,12 @@ void AddressResolver::HandleAddressNotification(Coap::Header &aHeader, Message &
|
||||
mCache[i].mState = Cache::kStateCached;
|
||||
MarkCacheEntryAsUsed(mCache[i]);
|
||||
|
||||
if (mNetif.GetCoap().SendEmptyAck(aHeader, aMessageInfo) == OT_ERROR_NONE)
|
||||
if (netif.GetCoap().SendEmptyAck(aHeader, aMessageInfo) == OT_ERROR_NONE)
|
||||
{
|
||||
otLogInfoArp(GetInstance(), "Sent address notification acknowledgment");
|
||||
}
|
||||
|
||||
mNetif.GetMeshForwarder().HandleResolved(*targetTlv.GetTarget(), OT_ERROR_NONE);
|
||||
netif.GetMeshForwarder().HandleResolved(*targetTlv.GetTarget(), OT_ERROR_NONE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -368,6 +366,7 @@ exit:
|
||||
otError AddressResolver::SendAddressError(const ThreadTargetTlv &aTarget, const ThreadMeshLocalEidTlv &aEid,
|
||||
const Ip6::Address *aDestination)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error;
|
||||
Message *message;
|
||||
Coap::Header header;
|
||||
@@ -378,7 +377,7 @@ otError AddressResolver::SendAddressError(const ThreadTargetTlv &aTarget, const
|
||||
header.AppendUriPathOptions(OT_URI_PATH_ADDRESS_ERROR);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = mNetif.GetCoap().NewMessage(header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
VerifyOrExit((message = netif.GetCoap().NewMessage(header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
SuccessOrExit(error = message->Append(&aTarget, sizeof(aTarget)));
|
||||
SuccessOrExit(error = message->Append(&aEid, sizeof(aEid)));
|
||||
@@ -393,11 +392,11 @@ otError AddressResolver::SendAddressError(const ThreadTargetTlv &aTarget, const
|
||||
memcpy(&messageInfo.GetPeerAddr(), aDestination, sizeof(messageInfo.GetPeerAddr()));
|
||||
}
|
||||
|
||||
messageInfo.SetSockAddr(mNetif.GetMle().GetMeshLocal16());
|
||||
messageInfo.SetSockAddr(netif.GetMle().GetMeshLocal16());
|
||||
messageInfo.SetPeerPort(kCoapUdpPort);
|
||||
messageInfo.SetInterfaceId(mNetif.GetInterfaceId());
|
||||
messageInfo.SetInterfaceId(netif.GetInterfaceId());
|
||||
|
||||
SuccessOrExit(error = mNetif.GetCoap().SendMessage(*message, messageInfo));
|
||||
SuccessOrExit(error = netif.GetCoap().SendMessage(*message, messageInfo));
|
||||
|
||||
otLogInfoArp(GetInstance(), "Sent address error");
|
||||
|
||||
@@ -422,6 +421,7 @@ void AddressResolver::HandleAddressError(void *aContext, otCoapHeader *aHeader,
|
||||
void AddressResolver::HandleAddressError(Coap::Header &aHeader, Message &aMessage,
|
||||
const Ip6::MessageInfo &aMessageInfo)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
ThreadTargetTlv targetTlv;
|
||||
ThreadMeshLocalEidTlv mlIidTlv;
|
||||
@@ -437,7 +437,7 @@ void AddressResolver::HandleAddressError(Coap::Header &aHeader, Message &aMessag
|
||||
|
||||
if (aHeader.IsConfirmable() && !aMessageInfo.GetSockAddr().IsMulticast())
|
||||
{
|
||||
if (mNetif.GetCoap().SendEmptyAck(aHeader, aMessageInfo) == OT_ERROR_NONE)
|
||||
if (netif.GetCoap().SendEmptyAck(aHeader, aMessageInfo) == OT_ERROR_NONE)
|
||||
{
|
||||
otLogInfoArp(GetInstance(), "Sent address error notification acknowledgment");
|
||||
}
|
||||
@@ -449,18 +449,18 @@ void AddressResolver::HandleAddressError(Coap::Header &aHeader, Message &aMessag
|
||||
SuccessOrExit(error = ThreadTlv::GetTlv(aMessage, ThreadTlv::kMeshLocalEid, sizeof(mlIidTlv), mlIidTlv));
|
||||
VerifyOrExit(mlIidTlv.IsValid(), error = OT_ERROR_PARSE);
|
||||
|
||||
for (const Ip6::NetifUnicastAddress *address = mNetif.GetUnicastAddresses(); address; address = address->GetNext())
|
||||
for (const Ip6::NetifUnicastAddress *address = netif.GetUnicastAddresses(); address; address = address->GetNext())
|
||||
{
|
||||
if (memcmp(&address->mAddress, targetTlv.GetTarget(), sizeof(address->mAddress)) == 0 &&
|
||||
memcmp(mNetif.GetMle().GetMeshLocal64().GetIid(), mlIidTlv.GetIid(), 8))
|
||||
memcmp(netif.GetMle().GetMeshLocal64().GetIid(), mlIidTlv.GetIid(), 8))
|
||||
{
|
||||
// Target EID matches address and Mesh Local EID differs
|
||||
mNetif.RemoveUnicastAddress(*address);
|
||||
netif.RemoveUnicastAddress(*address);
|
||||
ExitNow();
|
||||
}
|
||||
}
|
||||
|
||||
children = mNetif.GetMle().GetChildren(&numChildren);
|
||||
children = netif.GetMle().GetChildren(&numChildren);
|
||||
|
||||
memcpy(&macAddr, mlIidTlv.GetIid(), sizeof(macAddr));
|
||||
macAddr.m8[0] ^= 0x2;
|
||||
@@ -512,6 +512,7 @@ void AddressResolver::HandleAddressQuery(void *aContext, otCoapHeader *aHeader,
|
||||
void AddressResolver::HandleAddressQuery(Coap::Header &aHeader, Message &aMessage,
|
||||
const Ip6::MessageInfo &aMessageInfo)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
ThreadTargetTlv targetTlv;
|
||||
ThreadMeshLocalEidTlv mlIidTlv;
|
||||
ThreadLastTransactionTimeTlv lastTransactionTimeTlv;
|
||||
@@ -530,14 +531,14 @@ void AddressResolver::HandleAddressQuery(Coap::Header &aHeader, Message &aMessag
|
||||
|
||||
lastTransactionTimeTlv.Init();
|
||||
|
||||
if (mNetif.IsUnicastAddress(*targetTlv.GetTarget()))
|
||||
if (netif.IsUnicastAddress(*targetTlv.GetTarget()))
|
||||
{
|
||||
mlIidTlv.SetIid(mNetif.GetMle().GetMeshLocal64().GetIid());
|
||||
mlIidTlv.SetIid(netif.GetMle().GetMeshLocal64().GetIid());
|
||||
SendAddressQueryResponse(targetTlv, mlIidTlv, NULL, aMessageInfo.GetPeerAddr());
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
children = mNetif.GetMle().GetChildren(&numChildren);
|
||||
children = netif.GetMle().GetChildren(&numChildren);
|
||||
|
||||
for (int i = 0; i < numChildren; i++)
|
||||
{
|
||||
@@ -571,6 +572,7 @@ void AddressResolver::SendAddressQueryResponse(const ThreadTargetTlv &aTargetTlv
|
||||
const ThreadLastTransactionTimeTlv *aLastTransactionTimeTlv,
|
||||
const Ip6::Address &aDestination)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error;
|
||||
Message *message;
|
||||
Coap::Header header;
|
||||
@@ -581,13 +583,13 @@ void AddressResolver::SendAddressQueryResponse(const ThreadTargetTlv &aTargetTlv
|
||||
header.AppendUriPathOptions(OT_URI_PATH_ADDRESS_NOTIFY);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = mNetif.GetCoap().NewMessage(header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
VerifyOrExit((message = netif.GetCoap().NewMessage(header)) != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
SuccessOrExit(error = message->Append(&aTargetTlv, sizeof(aTargetTlv)));
|
||||
SuccessOrExit(error = message->Append(&aMlIidTlv, sizeof(aMlIidTlv)));
|
||||
|
||||
rloc16Tlv.Init();
|
||||
rloc16Tlv.SetRloc16(mNetif.GetMle().GetRloc16());
|
||||
rloc16Tlv.SetRloc16(netif.GetMle().GetRloc16());
|
||||
SuccessOrExit(error = message->Append(&rloc16Tlv, sizeof(rloc16Tlv)));
|
||||
|
||||
if (aLastTransactionTimeTlv != NULL)
|
||||
@@ -596,10 +598,10 @@ void AddressResolver::SendAddressQueryResponse(const ThreadTargetTlv &aTargetTlv
|
||||
}
|
||||
|
||||
messageInfo.SetPeerAddr(aDestination);
|
||||
messageInfo.SetSockAddr(mNetif.GetMle().GetMeshLocal16());
|
||||
messageInfo.SetSockAddr(netif.GetMle().GetMeshLocal16());
|
||||
messageInfo.SetPeerPort(kCoapUdpPort);
|
||||
|
||||
SuccessOrExit(error = mNetif.GetCoap().SendMessage(*message, messageInfo));
|
||||
SuccessOrExit(error = netif.GetCoap().SendMessage(*message, messageInfo));
|
||||
|
||||
otLogInfoArp(GetInstance(), "Sent address notification");
|
||||
|
||||
@@ -611,9 +613,9 @@ exit:
|
||||
}
|
||||
}
|
||||
|
||||
void AddressResolver::HandleTimer(void *aContext)
|
||||
void AddressResolver::HandleTimer(Timer &aTimer)
|
||||
{
|
||||
static_cast<AddressResolver *>(aContext)->HandleTimer();
|
||||
GetOwner(aTimer).HandleTimer();
|
||||
}
|
||||
|
||||
void AddressResolver::HandleTimer()
|
||||
@@ -647,7 +649,7 @@ void AddressResolver::HandleTimer()
|
||||
mCache[i].mRetryTimeout = kAddressQueryMaxRetryDelay;
|
||||
}
|
||||
|
||||
mNetif.GetMeshForwarder().HandleResolved(mCache[i].mTarget, OT_ERROR_DROP);
|
||||
GetNetif().GetMeshForwarder().HandleResolved(mCache[i].mTarget, OT_ERROR_DROP);
|
||||
}
|
||||
}
|
||||
else if (mCache[i].mRetryTimeout > 0)
|
||||
@@ -695,6 +697,17 @@ exit:
|
||||
OT_UNUSED_VARIABLE(aMessageInfo);
|
||||
}
|
||||
|
||||
AddressResolver &AddressResolver::GetOwner(const Context &aContext)
|
||||
{
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
AddressResolver &resolver = *static_cast<AddressResolver *>(aContext.GetContext());
|
||||
#else
|
||||
AddressResolver &resolver = otGetThreadNetif().GetAddressResolver();
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
#endif
|
||||
return resolver;
|
||||
}
|
||||
|
||||
} // namespace ot
|
||||
|
||||
#endif // OPENTHREAD_FTD
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
#include "coap/coap.hpp"
|
||||
#include "common/locator.hpp"
|
||||
#include "common/timer.hpp"
|
||||
#include "mac/mac.hpp"
|
||||
#include "net/icmp6.hpp"
|
||||
@@ -64,7 +65,7 @@ class ThreadTargetTlv;
|
||||
* This class implements the EID-to-RLOC mapping and caching.
|
||||
*
|
||||
*/
|
||||
class AddressResolver
|
||||
class AddressResolver: public ThreadNetifLocator
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -73,14 +74,6 @@ public:
|
||||
*/
|
||||
explicit AddressResolver(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 clears the EID-to-RLOC cache.
|
||||
*
|
||||
@@ -186,17 +179,17 @@ private:
|
||||
const otIcmp6Header *aIcmpHeader);
|
||||
void HandleIcmpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageInfo, const Ip6::IcmpHeader &aIcmpHeader);
|
||||
|
||||
static void HandleTimer(void *aContext);
|
||||
static void HandleTimer(Timer &aTimer);
|
||||
void HandleTimer(void);
|
||||
|
||||
static AddressResolver &GetOwner(const Context &aContext);
|
||||
|
||||
Coap::Resource mAddressError;
|
||||
Coap::Resource mAddressQuery;
|
||||
Coap::Resource mAddressNotification;
|
||||
Cache mCache[kCacheEntries];
|
||||
Ip6::IcmpHandler mIcmpHandler;
|
||||
Timer mTimer;
|
||||
|
||||
ThreadNetif &mNetif;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
|
||||
#include <openthread/platform/radio.h>
|
||||
|
||||
#include "openthread-instance.h"
|
||||
#include "coap/coap_header.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
@@ -52,20 +53,15 @@ using ot::Encoding::BigEndian::HostSwap32;
|
||||
namespace ot {
|
||||
|
||||
AnnounceBeginServer::AnnounceBeginServer(ThreadNetif &aThreadNetif) :
|
||||
ThreadNetifLocator(aThreadNetif),
|
||||
mChannelMask(0),
|
||||
mPeriod(0),
|
||||
mCount(0),
|
||||
mChannel(0),
|
||||
mTimer(aThreadNetif.GetIp6().mTimerScheduler, &AnnounceBeginServer::HandleTimer, this),
|
||||
mAnnounceBegin(OT_URI_PATH_ANNOUNCE_BEGIN, &AnnounceBeginServer::HandleRequest, this),
|
||||
mNetif(aThreadNetif)
|
||||
mAnnounceBegin(OT_URI_PATH_ANNOUNCE_BEGIN, &AnnounceBeginServer::HandleRequest, this)
|
||||
{
|
||||
mNetif.GetCoap().AddResource(mAnnounceBegin);
|
||||
}
|
||||
|
||||
otInstance *AnnounceBeginServer::GetInstance(void)
|
||||
{
|
||||
return mNetif.GetInstance();
|
||||
aThreadNetif.GetCoap().AddResource(mAnnounceBegin);
|
||||
}
|
||||
|
||||
otError AnnounceBeginServer::SendAnnounce(uint32_t aChannelMask)
|
||||
@@ -123,7 +119,7 @@ void AnnounceBeginServer::HandleRequest(Coap::Header &aHeader, Message &aMessage
|
||||
|
||||
if (aHeader.IsConfirmable() && !aMessageInfo.GetSockAddr().IsMulticast())
|
||||
{
|
||||
SuccessOrExit(mNetif.GetCoap().SendEmptyAck(aHeader, responseInfo));
|
||||
SuccessOrExit(GetNetif().GetCoap().SendEmptyAck(aHeader, responseInfo));
|
||||
otLogInfoMeshCoP(GetInstance(), "sent announce begin response");
|
||||
}
|
||||
|
||||
@@ -131,14 +127,14 @@ exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void AnnounceBeginServer::HandleTimer(void *aContext)
|
||||
void AnnounceBeginServer::HandleTimer(Timer &aTimer)
|
||||
{
|
||||
static_cast<AnnounceBeginServer *>(aContext)->HandleTimer();
|
||||
GetOwner(aTimer).HandleTimer();
|
||||
}
|
||||
|
||||
void AnnounceBeginServer::HandleTimer(void)
|
||||
{
|
||||
mNetif.GetMle().SendAnnounce(mChannel++, false);
|
||||
GetNetif().GetMle().SendAnnounce(mChannel++, false);
|
||||
|
||||
while (mCount > 0)
|
||||
{
|
||||
@@ -158,4 +154,15 @@ void AnnounceBeginServer::HandleTimer(void)
|
||||
}
|
||||
}
|
||||
|
||||
AnnounceBeginServer &AnnounceBeginServer::GetOwner(const Context &aContext)
|
||||
{
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
AnnounceBeginServer &server = *static_cast<AnnounceBeginServer *>(aContext.GetContext());
|
||||
#else
|
||||
AnnounceBeginServer &server = otGetThreadNetif().GetAnnounceBeginServer();
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
#endif
|
||||
return server;
|
||||
}
|
||||
|
||||
} // namespace ot
|
||||
|
||||
@@ -38,18 +38,17 @@
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
#include "coap/coap.hpp"
|
||||
#include "common/locator.hpp"
|
||||
#include "common/timer.hpp"
|
||||
#include "net/ip6_address.hpp"
|
||||
|
||||
namespace ot {
|
||||
|
||||
class ThreadNetif;
|
||||
|
||||
/**
|
||||
* This class implements handling Announce Begin Requests.
|
||||
*
|
||||
*/
|
||||
class AnnounceBeginServer
|
||||
class AnnounceBeginServer: public ThreadNetifLocator
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -58,14 +57,6 @@ public:
|
||||
*/
|
||||
AnnounceBeginServer(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 begins the MLE Announce transmission process using Count=3 and Period=1s.
|
||||
*
|
||||
@@ -99,9 +90,11 @@ private:
|
||||
const otMessageInfo *aMessageInfo);
|
||||
void HandleRequest(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
static void HandleTimer(void *aContext);
|
||||
static void HandleTimer(Timer &aTimer);
|
||||
void HandleTimer(void);
|
||||
|
||||
static AnnounceBeginServer &GetOwner(const Context &aContext);
|
||||
|
||||
uint32_t mChannelMask;
|
||||
uint16_t mPeriod;
|
||||
uint8_t mCount;
|
||||
@@ -110,7 +103,6 @@ private:
|
||||
Timer mTimer;
|
||||
|
||||
Coap::Resource mAnnounceBegin;
|
||||
ThreadNetif &mNetif;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "data_poll_manager.hpp"
|
||||
#include <openthread/platform/random.h>
|
||||
|
||||
#include "openthread-instance.h"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/logging.hpp"
|
||||
#include "common/message.hpp"
|
||||
@@ -49,7 +50,7 @@
|
||||
namespace ot {
|
||||
|
||||
DataPollManager::DataPollManager(MeshForwarder &aMeshForwarder):
|
||||
mMeshForwarder(aMeshForwarder),
|
||||
MeshForwarderLocator(aMeshForwarder),
|
||||
mTimer(aMeshForwarder.GetNetif().GetIp6().mTimerScheduler, &DataPollManager::HandlePollTimer, this),
|
||||
mTimerStartTime(0),
|
||||
mExternalPollPeriod(0),
|
||||
@@ -64,17 +65,12 @@ DataPollManager::DataPollManager(MeshForwarder &aMeshForwarder):
|
||||
{
|
||||
}
|
||||
|
||||
otInstance *DataPollManager::GetInstance(void)
|
||||
{
|
||||
return mMeshForwarder.GetInstance();
|
||||
}
|
||||
|
||||
otError DataPollManager::StartPolling(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
VerifyOrExit(!mEnabled, error = OT_ERROR_ALREADY);
|
||||
VerifyOrExit((mMeshForwarder.GetNetif().GetMle().GetDeviceMode() & Mle::ModeTlv::kModeFFD) == 0,
|
||||
VerifyOrExit((GetMeshForwarder().GetNetif().GetMle().GetDeviceMode() & Mle::ModeTlv::kModeFFD) == 0,
|
||||
error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
mEnabled = true;
|
||||
@@ -98,23 +94,24 @@ void DataPollManager::StopPolling(void)
|
||||
|
||||
otError DataPollManager::SendDataPoll(void)
|
||||
{
|
||||
MeshForwarder &meshForwarder = GetMeshForwarder();
|
||||
otError error;
|
||||
Message *message;
|
||||
|
||||
VerifyOrExit(mEnabled, error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(!mMeshForwarder.GetNetif().GetMac().GetRxOnWhenIdle(), error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(!meshForwarder.GetNetif().GetMac().GetRxOnWhenIdle(), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
mTimer.Stop();
|
||||
|
||||
for (message = mMeshForwarder.GetSendQueue().GetHead(); message; message = message->GetNext())
|
||||
for (message = meshForwarder.GetSendQueue().GetHead(); message; message = message->GetNext())
|
||||
{
|
||||
VerifyOrExit(message->GetType() != Message::kTypeMacDataPoll, error = OT_ERROR_ALREADY);
|
||||
}
|
||||
|
||||
message = mMeshForwarder.GetNetif().GetIp6().mMessagePool.New(Message::kTypeMacDataPoll, 0);
|
||||
message = meshForwarder.GetNetif().GetIp6().mMessagePool.New(Message::kTypeMacDataPoll, 0);
|
||||
VerifyOrExit(message != NULL, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
error = mMeshForwarder.SendMessage(*message);
|
||||
error = meshForwarder.SendMessage(*message);
|
||||
|
||||
if (error != OT_ERROR_NONE)
|
||||
{
|
||||
@@ -380,7 +377,7 @@ uint32_t DataPollManager::CalculatePollPeriod(void) const
|
||||
|
||||
if (period == 0)
|
||||
{
|
||||
period = Timer::SecToMsec(mMeshForwarder.GetNetif().GetMle().GetTimeout()) -
|
||||
period = Timer::SecToMsec(GetMeshForwarder().GetNetif().GetMle().GetTimeout()) -
|
||||
static_cast<uint32_t>(kRetxPollPeriod) * kMaxPollRetxAttempts;
|
||||
|
||||
if (period == 0)
|
||||
@@ -392,9 +389,20 @@ uint32_t DataPollManager::CalculatePollPeriod(void) const
|
||||
return period;
|
||||
}
|
||||
|
||||
void DataPollManager::HandlePollTimer(void *aContext)
|
||||
void DataPollManager::HandlePollTimer(Timer &aTimer)
|
||||
{
|
||||
static_cast<DataPollManager *>(aContext)->SendDataPoll();
|
||||
GetOwner(aTimer).SendDataPoll();
|
||||
}
|
||||
|
||||
DataPollManager &DataPollManager::GetOwner(Context &aContext)
|
||||
{
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
DataPollManager &manager = *static_cast<DataPollManager *>(aContext.GetContext());
|
||||
#else
|
||||
DataPollManager &manager = otGetMeshForwarder().GetDataPollManager();
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
#endif
|
||||
return manager;
|
||||
}
|
||||
|
||||
} // namespace ot
|
||||
|
||||
@@ -38,13 +38,12 @@
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/locator.hpp"
|
||||
#include "common/timer.hpp"
|
||||
#include "mac/mac_frame.hpp"
|
||||
|
||||
namespace ot {
|
||||
|
||||
class MeshForwarder;
|
||||
|
||||
/**
|
||||
* @addtogroup core-data-poll-manager
|
||||
*
|
||||
@@ -59,7 +58,7 @@ class MeshForwarder;
|
||||
*
|
||||
*/
|
||||
|
||||
class DataPollManager
|
||||
class DataPollManager: public MeshForwarderLocator
|
||||
{
|
||||
public:
|
||||
enum
|
||||
@@ -76,14 +75,6 @@ public:
|
||||
*/
|
||||
explicit DataPollManager(MeshForwarder &aMeshForwarder);
|
||||
|
||||
/**
|
||||
* This method returns the pointer to the parent otInstance structure.
|
||||
*
|
||||
* @returns The pointer to the parent otInstance structure.
|
||||
*
|
||||
*/
|
||||
otInstance *GetInstance(void);
|
||||
|
||||
/**
|
||||
* This method instructs the data poll manager to start sending periodic data polls.
|
||||
*
|
||||
@@ -218,9 +209,9 @@ private:
|
||||
|
||||
void ScheduleNextPoll(PollPeriodSelector aPollPeriodSelector);
|
||||
uint32_t CalculatePollPeriod(void) const;
|
||||
static void HandlePollTimer(void *aContext);
|
||||
static void HandlePollTimer(Timer &aTimer);
|
||||
static DataPollManager &GetOwner(Context &aContext);
|
||||
|
||||
MeshForwarder &mMeshForwarder;
|
||||
Timer mTimer;
|
||||
uint32_t mTimerStartTime;
|
||||
uint32_t mExternalPollPeriod;
|
||||
|
||||
@@ -34,14 +34,11 @@
|
||||
#define WPP_NAME "energy_scan_server.tmh"
|
||||
#include <openthread/config.h>
|
||||
|
||||
|
||||
|
||||
#include "energy_scan_server.hpp"
|
||||
|
||||
|
||||
|
||||
#include <openthread/platform/random.h>
|
||||
|
||||
#include "openthread-instance.h"
|
||||
#include "coap/coap_header.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
@@ -54,6 +51,7 @@
|
||||
namespace ot {
|
||||
|
||||
EnergyScanServer::EnergyScanServer(ThreadNetif &aThreadNetif) :
|
||||
ThreadNetifLocator(aThreadNetif),
|
||||
mChannelMask(0),
|
||||
mChannelMaskCurrent(0),
|
||||
mPeriod(0),
|
||||
@@ -62,18 +60,12 @@ EnergyScanServer::EnergyScanServer(ThreadNetif &aThreadNetif) :
|
||||
mActive(false),
|
||||
mScanResultsLength(0),
|
||||
mTimer(aThreadNetif.GetIp6().mTimerScheduler, &EnergyScanServer::HandleTimer, this),
|
||||
mEnergyScan(OT_URI_PATH_ENERGY_SCAN, &EnergyScanServer::HandleRequest, this),
|
||||
mNetif(aThreadNetif)
|
||||
mEnergyScan(OT_URI_PATH_ENERGY_SCAN, &EnergyScanServer::HandleRequest, this)
|
||||
{
|
||||
mNetifCallback.Set(&EnergyScanServer::HandleNetifStateChanged, this);
|
||||
mNetif.RegisterCallback(mNetifCallback);
|
||||
aThreadNetif.RegisterCallback(mNetifCallback);
|
||||
|
||||
mNetif.GetCoap().AddResource(mEnergyScan);
|
||||
}
|
||||
|
||||
otInstance *EnergyScanServer::GetInstance(void)
|
||||
{
|
||||
return mNetif.GetInstance();
|
||||
aThreadNetif.GetCoap().AddResource(mEnergyScan);
|
||||
}
|
||||
|
||||
void EnergyScanServer::HandleRequest(void *aContext, otCoapHeader *aHeader, otMessage *aMessage,
|
||||
@@ -119,7 +111,7 @@ void EnergyScanServer::HandleRequest(Coap::Header &aHeader, Message &aMessage, c
|
||||
|
||||
if (aHeader.IsConfirmable() && !aMessageInfo.GetSockAddr().IsMulticast())
|
||||
{
|
||||
SuccessOrExit(mNetif.GetCoap().SendEmptyAck(aHeader, responseInfo));
|
||||
SuccessOrExit(GetNetif().GetCoap().SendEmptyAck(aHeader, responseInfo));
|
||||
otLogInfoMeshCoP(GetInstance(), "sent energy scan query response");
|
||||
}
|
||||
|
||||
@@ -127,9 +119,9 @@ exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void EnergyScanServer::HandleTimer(void *aContext)
|
||||
void EnergyScanServer::HandleTimer(Timer &aTimer)
|
||||
{
|
||||
static_cast<EnergyScanServer *>(aContext)->HandleTimer();
|
||||
GetOwner(aTimer).HandleTimer();
|
||||
}
|
||||
|
||||
void EnergyScanServer::HandleTimer(void)
|
||||
@@ -140,7 +132,7 @@ void EnergyScanServer::HandleTimer(void)
|
||||
{
|
||||
// grab the lowest channel to scan
|
||||
uint32_t channelMask = mChannelMaskCurrent & ~(mChannelMaskCurrent - 1);
|
||||
mNetif.GetMac().EnergyScan(channelMask, mScanDuration, HandleScanResult, this);
|
||||
GetNetif().GetMac().EnergyScan(channelMask, mScanDuration, HandleScanResult, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -203,7 +195,7 @@ otError EnergyScanServer::SendReport(void)
|
||||
header.AppendUriPathOptions(OT_URI_PATH_ENERGY_REPORT);
|
||||
header.SetPayloadMarker();
|
||||
|
||||
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(mNetif.GetCoap(), header)) != NULL,
|
||||
VerifyOrExit((message = MeshCoP::NewMeshCoPMessage(GetNetif().GetCoap(), header)) != NULL,
|
||||
error = OT_ERROR_NO_BUFS);
|
||||
|
||||
channelMask.Init();
|
||||
@@ -215,10 +207,10 @@ otError EnergyScanServer::SendReport(void)
|
||||
SuccessOrExit(error = message->Append(&energyList, sizeof(energyList)));
|
||||
SuccessOrExit(error = message->Append(mScanResults, mScanResultsLength));
|
||||
|
||||
messageInfo.SetSockAddr(mNetif.GetMle().GetMeshLocal16());
|
||||
messageInfo.SetSockAddr(GetNetif().GetMle().GetMeshLocal16());
|
||||
messageInfo.SetPeerAddr(mCommissioner);
|
||||
messageInfo.SetPeerPort(kCoapUdpPort);
|
||||
SuccessOrExit(error = mNetif.GetCoap().SendMessage(*message, messageInfo));
|
||||
SuccessOrExit(error = GetNetif().GetCoap().SendMessage(*message, messageInfo));
|
||||
|
||||
otLogInfoMeshCoP(GetInstance(), "sent scan results");
|
||||
|
||||
@@ -243,11 +235,22 @@ void EnergyScanServer::HandleNetifStateChanged(uint32_t aFlags)
|
||||
{
|
||||
if ((aFlags & OT_CHANGED_THREAD_NETDATA) != 0 &&
|
||||
!mActive &&
|
||||
mNetif.GetNetworkDataLeader().GetCommissioningData() == NULL)
|
||||
GetNetif().GetNetworkDataLeader().GetCommissioningData() == NULL)
|
||||
{
|
||||
mActive = false;
|
||||
mTimer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
EnergyScanServer &EnergyScanServer::GetOwner(const Context &aContext)
|
||||
{
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
EnergyScanServer &server = *static_cast<EnergyScanServer *>(aContext.GetContext());
|
||||
#else
|
||||
EnergyScanServer &server = otGetThreadNetif().GetEnergyScanServer();
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
#endif
|
||||
return server;
|
||||
}
|
||||
|
||||
} // namespace ot
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
#include "coap/coap.hpp"
|
||||
#include "common/locator.hpp"
|
||||
#include "common/timer.hpp"
|
||||
#include "net/ip6_address.hpp"
|
||||
#include "net/udp6.hpp"
|
||||
@@ -54,7 +55,7 @@ class ThreadTargetTlv;
|
||||
* This class implements handling Energy Scan Requests.
|
||||
*
|
||||
*/
|
||||
class EnergyScanServer
|
||||
class EnergyScanServer: public ThreadNetifLocator
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -63,14 +64,6 @@ public:
|
||||
*/
|
||||
EnergyScanServer(ThreadNetif &aThreadNetif);
|
||||
|
||||
/**
|
||||
* This method returns the pointer to the parent otInstance structure.
|
||||
*
|
||||
* @returns The pointer to the parent otInstance structure.
|
||||
*
|
||||
*/
|
||||
otInstance *GetInstance(void);
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
@@ -85,7 +78,7 @@ private:
|
||||
static void HandleScanResult(void *aContext, otEnergyScanResult *aResult);
|
||||
void HandleScanResult(otEnergyScanResult *aResult);
|
||||
|
||||
static void HandleTimer(void *aContext);
|
||||
static void HandleTimer(Timer &aTimer);
|
||||
void HandleTimer(void);
|
||||
|
||||
static void HandleNetifStateChanged(uint32_t aFlags, void *aContext);
|
||||
@@ -93,6 +86,8 @@ private:
|
||||
|
||||
otError SendReport(void);
|
||||
|
||||
static EnergyScanServer &GetOwner(const Context &aContext);
|
||||
|
||||
Ip6::Address mCommissioner;
|
||||
uint32_t mChannelMask;
|
||||
uint32_t mChannelMaskCurrent;
|
||||
@@ -109,8 +104,6 @@ private:
|
||||
Ip6::NetifCallback mNetifCallback;
|
||||
|
||||
Coap::Resource mEnergyScan;
|
||||
|
||||
ThreadNetif &mNetif;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
|
||||
#include "key_manager.hpp"
|
||||
|
||||
#include "openthread-instance.h"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/timer.hpp"
|
||||
#include "crypto/hmac_sha256.hpp"
|
||||
@@ -50,7 +51,7 @@ static const uint8_t kThreadString[] =
|
||||
};
|
||||
|
||||
KeyManager::KeyManager(ThreadNetif &aThreadNetif):
|
||||
mNetif(aThreadNetif),
|
||||
ThreadNetifLocator(aThreadNetif),
|
||||
mKeySequence(0),
|
||||
mMacFrameCounter(0),
|
||||
mMleFrameCounter(0),
|
||||
@@ -108,13 +109,13 @@ otError KeyManager::SetMasterKey(const otMasterKey &aKey)
|
||||
ComputeKey(mKeySequence, mKey);
|
||||
|
||||
// reset parent frame counters
|
||||
routers = mNetif.GetMle().GetParent();
|
||||
routers = GetNetif().GetMle().GetParent();
|
||||
routers->SetKeySequence(0);
|
||||
routers->SetLinkFrameCounter(0);
|
||||
routers->SetMleFrameCounter(0);
|
||||
|
||||
// reset router frame counters
|
||||
routers = mNetif.GetMle().GetRouters(&num);
|
||||
routers = GetNetif().GetMle().GetRouters(&num);
|
||||
|
||||
for (uint8_t i = 0; i < num; i++)
|
||||
{
|
||||
@@ -124,7 +125,7 @@ otError KeyManager::SetMasterKey(const otMasterKey &aKey)
|
||||
}
|
||||
|
||||
// reset child frame counters
|
||||
children = mNetif.GetMle().GetChildren(&num);
|
||||
children = GetNetif().GetMle().GetChildren(&num);
|
||||
|
||||
for (uint8_t i = 0; i < num; i++)
|
||||
{
|
||||
@@ -133,7 +134,7 @@ otError KeyManager::SetMasterKey(const otMasterKey &aKey)
|
||||
children[i].SetMleFrameCounter(0);
|
||||
}
|
||||
|
||||
mNetif.SetStateChangedFlags(OT_CHANGED_THREAD_KEY_SEQUENCE_COUNTER);
|
||||
GetNetif().SetStateChangedFlags(OT_CHANGED_THREAD_KEY_SEQUENCE_COUNTER);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
@@ -186,7 +187,7 @@ void KeyManager::SetCurrentKeySequence(uint32_t aKeySequence)
|
||||
StartKeyRotationTimer();
|
||||
}
|
||||
|
||||
mNetif.SetStateChangedFlags(OT_CHANGED_THREAD_KEY_SEQUENCE_COUNTER);
|
||||
GetNetif().SetStateChangedFlags(OT_CHANGED_THREAD_KEY_SEQUENCE_COUNTER);
|
||||
|
||||
exit:
|
||||
return;
|
||||
@@ -210,7 +211,7 @@ void KeyManager::IncrementMacFrameCounter(void)
|
||||
|
||||
if (mMacFrameCounter >= mStoredMacFrameCounter)
|
||||
{
|
||||
mNetif.GetMle().Store();
|
||||
GetNetif().GetMle().Store();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,7 +221,7 @@ void KeyManager::IncrementMleFrameCounter(void)
|
||||
|
||||
if (mMleFrameCounter >= mStoredMleFrameCounter)
|
||||
{
|
||||
mNetif.GetMle().Store();
|
||||
GetNetif().GetMle().Store();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,9 +249,9 @@ void KeyManager::StartKeyRotationTimer(void)
|
||||
mKeyRotationTimer.Start(kOneHourIntervalInMsec);
|
||||
}
|
||||
|
||||
void KeyManager::HandleKeyRotationTimer(void *aContext)
|
||||
void KeyManager::HandleKeyRotationTimer(Timer &aTimer)
|
||||
{
|
||||
static_cast<KeyManager *>(aContext)->HandleKeyRotationTimer();
|
||||
GetOwner(aTimer).HandleKeyRotationTimer();
|
||||
}
|
||||
|
||||
void KeyManager::HandleKeyRotationTimer(void)
|
||||
@@ -272,4 +273,15 @@ void KeyManager::HandleKeyRotationTimer(void)
|
||||
}
|
||||
}
|
||||
|
||||
KeyManager &KeyManager::GetOwner(const Context &aContext)
|
||||
{
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
KeyManager &keyManager = *static_cast<KeyManager *>(aContext.GetContext());
|
||||
#else
|
||||
KeyManager &keyManager = otGetThreadNetif().GetKeyManager();
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
#endif
|
||||
return keyManager;
|
||||
}
|
||||
|
||||
} // namespace ot
|
||||
|
||||
@@ -38,13 +38,12 @@
|
||||
|
||||
#include <openthread/types.h>
|
||||
|
||||
#include "common/locator.hpp"
|
||||
#include "common/timer.hpp"
|
||||
#include "crypto/hmac_sha256.hpp"
|
||||
|
||||
namespace ot {
|
||||
|
||||
class ThreadNetif;
|
||||
|
||||
/**
|
||||
* @addtogroup core-security
|
||||
*
|
||||
@@ -54,7 +53,7 @@ class ThreadNetif;
|
||||
* @{
|
||||
*/
|
||||
|
||||
class KeyManager
|
||||
class KeyManager: public ThreadNetifLocator
|
||||
{
|
||||
public:
|
||||
enum
|
||||
@@ -337,10 +336,10 @@ private:
|
||||
otError ComputeKey(uint32_t aKeySequence, uint8_t *aKey);
|
||||
|
||||
void StartKeyRotationTimer(void);
|
||||
static void HandleKeyRotationTimer(void *aContext);
|
||||
static void HandleKeyRotationTimer(Timer &aTimer);
|
||||
void HandleKeyRotationTimer(void);
|
||||
|
||||
ThreadNetif &mNetif;
|
||||
static KeyManager &GetOwner(const Context &aContext);
|
||||
|
||||
otMasterKey mMasterKey;
|
||||
|
||||
|
||||
+13
-10
@@ -49,7 +49,7 @@ namespace ot {
|
||||
namespace Lowpan {
|
||||
|
||||
Lowpan::Lowpan(ThreadNetif &aThreadNetif):
|
||||
mNetworkData(aThreadNetif.GetNetworkDataLeader())
|
||||
ThreadNetifLocator(aThreadNetif)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -176,6 +176,7 @@ int Lowpan::CompressDestinationIid(const Mac::Address &aMacAddr, const Ip6::Addr
|
||||
|
||||
int Lowpan::CompressMulticast(const Ip6::Address &aIpAddr, uint16_t &aHcCtl, uint8_t *aBuf)
|
||||
{
|
||||
NetworkData::Leader &networkData = GetNetif().GetNetworkDataLeader();
|
||||
uint8_t *cur = aBuf;
|
||||
Context multicastContext;
|
||||
|
||||
@@ -211,7 +212,7 @@ int Lowpan::CompressMulticast(const Ip6::Address &aIpAddr, uint16_t &aHcCtl, uin
|
||||
else
|
||||
{
|
||||
// Check if multicast address can be compressed using Context ID 0.
|
||||
if (mNetworkData.GetContext(0, multicastContext) == OT_ERROR_NONE &&
|
||||
if (networkData.GetContext(0, multicastContext) == OT_ERROR_NONE &&
|
||||
multicastContext.mPrefixLength == aIpAddr.mFields.m8[3] &&
|
||||
memcmp(multicastContext.mPrefix, aIpAddr.mFields.m8 + 4, 8) == 0)
|
||||
{
|
||||
@@ -236,6 +237,7 @@ int Lowpan::CompressMulticast(const Ip6::Address &aIpAddr, uint16_t &aHcCtl, uin
|
||||
|
||||
int Lowpan::Compress(Message &aMessage, const Mac::Address &aMacSource, const Mac::Address &aMacDest, uint8_t *aBuf)
|
||||
{
|
||||
NetworkData::Leader &networkData = GetNetif().GetNetworkDataLeader();
|
||||
uint8_t *cur = aBuf;
|
||||
uint16_t hcCtl = 0;
|
||||
Ip6::Header ip6Header;
|
||||
@@ -248,17 +250,17 @@ int Lowpan::Compress(Message &aMessage, const Mac::Address &aMacSource, const Ma
|
||||
|
||||
aMessage.Read(aMessage.GetOffset(), sizeof(ip6Header), &ip6Header);
|
||||
|
||||
if (mNetworkData.GetContext(ip6Header.GetSource(), srcContext) != OT_ERROR_NONE ||
|
||||
if (networkData.GetContext(ip6Header.GetSource(), srcContext) != OT_ERROR_NONE ||
|
||||
srcContext.mCompressFlag == false)
|
||||
{
|
||||
mNetworkData.GetContext(0, srcContext);
|
||||
networkData.GetContext(0, srcContext);
|
||||
srcContextValid = false;
|
||||
}
|
||||
|
||||
if (mNetworkData.GetContext(ip6Header.GetDestination(), dstContext) != OT_ERROR_NONE ||
|
||||
if (networkData.GetContext(ip6Header.GetDestination(), dstContext) != OT_ERROR_NONE ||
|
||||
dstContext.mCompressFlag == false)
|
||||
{
|
||||
mNetworkData.GetContext(0, dstContext);
|
||||
networkData.GetContext(0, dstContext);
|
||||
dstContextValid = false;
|
||||
}
|
||||
|
||||
@@ -595,6 +597,7 @@ exit:
|
||||
int Lowpan::DecompressBaseHeader(Ip6::Header &ip6Header, const Mac::Address &aMacSource, const Mac::Address &aMacDest,
|
||||
const uint8_t *aBuf, uint16_t aBufLength)
|
||||
{
|
||||
NetworkData::Leader &networkData = GetNetif().GetNetworkDataLeader();
|
||||
otError error = OT_ERROR_PARSE;
|
||||
const uint8_t *cur = aBuf;
|
||||
uint16_t remaining = aBufLength;
|
||||
@@ -620,12 +623,12 @@ int Lowpan::DecompressBaseHeader(Ip6::Header &ip6Header, const Mac::Address &aMa
|
||||
{
|
||||
VerifyOrExit(remaining >= 1);
|
||||
|
||||
if (mNetworkData.GetContext(cur[0] >> 4, srcContext) != OT_ERROR_NONE)
|
||||
if (networkData.GetContext(cur[0] >> 4, srcContext) != OT_ERROR_NONE)
|
||||
{
|
||||
srcContextValid = false;
|
||||
}
|
||||
|
||||
if (mNetworkData.GetContext(cur[0] & 0xf, dstContext) != OT_ERROR_NONE)
|
||||
if (networkData.GetContext(cur[0] & 0xf, dstContext) != OT_ERROR_NONE)
|
||||
{
|
||||
dstContextValid = false;
|
||||
}
|
||||
@@ -635,8 +638,8 @@ int Lowpan::DecompressBaseHeader(Ip6::Header &ip6Header, const Mac::Address &aMa
|
||||
}
|
||||
else
|
||||
{
|
||||
mNetworkData.GetContext(0, srcContext);
|
||||
mNetworkData.GetContext(0, dstContext);
|
||||
networkData.GetContext(0, srcContext);
|
||||
networkData.GetContext(0, dstContext);
|
||||
}
|
||||
|
||||
memset(&ip6Header, 0, sizeof(ip6Header));
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#ifndef LOWPAN_HPP_
|
||||
#define LOWPAN_HPP_
|
||||
|
||||
#include "common/locator.hpp"
|
||||
#include "common/message.hpp"
|
||||
#include "mac/mac_frame.hpp"
|
||||
#include "net/ip6.hpp"
|
||||
@@ -41,10 +42,6 @@
|
||||
|
||||
namespace ot {
|
||||
|
||||
class ThreadNetif;
|
||||
|
||||
namespace NetworkData { class Leader; }
|
||||
|
||||
/**
|
||||
* @addtogroup core-6lowpan
|
||||
*
|
||||
@@ -79,7 +76,7 @@ struct Context
|
||||
* This class implements LOWPAN_IPHC header compression.
|
||||
*
|
||||
*/
|
||||
class Lowpan
|
||||
class Lowpan: public ThreadNetifLocator
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -209,8 +206,6 @@ private:
|
||||
|
||||
static otError CopyContext(const Context &aContext, Ip6::Address &aAddress);
|
||||
static otError ComputeIid(const Mac::Address &aMacAddr, const Context &aContext, Ip6::Address &aIpAddress);
|
||||
|
||||
NetworkData::Leader &mNetworkData;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
+165
-131
@@ -39,6 +39,7 @@
|
||||
|
||||
#include <openthread/platform/random.h>
|
||||
|
||||
#include "openthread-instance.h"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
#include "common/encoding.hpp"
|
||||
@@ -58,7 +59,7 @@ using ot::Encoding::BigEndian::HostSwap16;
|
||||
namespace ot {
|
||||
|
||||
MeshForwarder::MeshForwarder(ThreadNetif &aThreadNetif):
|
||||
mNetif(aThreadNetif),
|
||||
ThreadNetifLocator(aThreadNetif),
|
||||
mMacReceiver(&MeshForwarder::HandleReceivedFrame, &MeshForwarder::HandleDataPollTimeout, this),
|
||||
mMacSender(&MeshForwarder::HandleFrameRequest, &MeshForwarder::HandleSentFrame, this),
|
||||
mDiscoverTimer(aThreadNetif.GetIp6().mTimerScheduler, &MeshForwarder::HandleDiscoverTimer, this),
|
||||
@@ -86,7 +87,7 @@ MeshForwarder::MeshForwarder(ThreadNetif &aThreadNetif):
|
||||
mSourceMatchController(*this)
|
||||
{
|
||||
mFragTag = static_cast<uint16_t>(otPlatRandomGet());
|
||||
mNetif.GetMac().RegisterReceiver(mMacReceiver);
|
||||
aThreadNetif.GetMac().RegisterReceiver(mMacReceiver);
|
||||
mMacSource.mLength = 0;
|
||||
mMacDest.mLength = 0;
|
||||
|
||||
@@ -96,18 +97,13 @@ MeshForwarder::MeshForwarder(ThreadNetif &aThreadNetif):
|
||||
mIpCounters.mRxFailure = 0;
|
||||
}
|
||||
|
||||
otInstance *MeshForwarder::GetInstance(void)
|
||||
{
|
||||
return mNetif.GetInstance();
|
||||
}
|
||||
|
||||
otError MeshForwarder::Start(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (mEnabled == false)
|
||||
{
|
||||
mNetif.GetMac().SetRxOnWhenIdle(true);
|
||||
GetNetif().GetMac().SetRxOnWhenIdle(true);
|
||||
mEnabled = true;
|
||||
}
|
||||
|
||||
@@ -116,6 +112,7 @@ otError MeshForwarder::Start(void)
|
||||
|
||||
otError MeshForwarder::Stop(void)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
Message *message;
|
||||
|
||||
@@ -126,9 +123,9 @@ otError MeshForwarder::Stop(void)
|
||||
|
||||
if (mScanning)
|
||||
{
|
||||
mNetif.GetMac().SetChannel(mRestoreChannel);
|
||||
netif.GetMac().SetChannel(mRestoreChannel);
|
||||
mScanning = false;
|
||||
mNetif.GetMle().HandleDiscoverComplete();
|
||||
netif.GetMle().HandleDiscoverComplete();
|
||||
}
|
||||
|
||||
while ((message = mSendQueue.GetHead()) != NULL)
|
||||
@@ -145,7 +142,7 @@ otError MeshForwarder::Stop(void)
|
||||
|
||||
mEnabled = false;
|
||||
mSendMessage = NULL;
|
||||
mNetif.GetMac().SetRxOnWhenIdle(false);
|
||||
netif.GetMac().SetRxOnWhenIdle(false);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
@@ -200,7 +197,7 @@ void MeshForwarder::ClearChildIndirectMessages(Child &aChild)
|
||||
{
|
||||
nextMessage = message->GetNext();
|
||||
|
||||
message->ClearChildMask(mNetif.GetMle().GetChildIndex(aChild));
|
||||
message->ClearChildMask(GetNetif().GetMle().GetChildIndex(aChild));
|
||||
|
||||
if (!message->IsChildPending() && !message->GetDirectTransmission())
|
||||
{
|
||||
@@ -225,7 +222,7 @@ void MeshForwarder::UpdateIndirectMessages(void)
|
||||
Child *children;
|
||||
uint8_t numChildren;
|
||||
|
||||
children = mNetif.GetMle().GetChildren(&numChildren);
|
||||
children = GetNetif().GetMle().GetChildren(&numChildren);
|
||||
|
||||
for (uint8_t i = 0; i < numChildren; i++)
|
||||
{
|
||||
@@ -240,13 +237,14 @@ void MeshForwarder::UpdateIndirectMessages(void)
|
||||
}
|
||||
}
|
||||
|
||||
void MeshForwarder::ScheduleTransmissionTask(void *aContext)
|
||||
void MeshForwarder::ScheduleTransmissionTask(Tasklet &aTasklet)
|
||||
{
|
||||
static_cast<MeshForwarder *>(aContext)->ScheduleTransmissionTask();
|
||||
GetOwner(aTasklet).ScheduleTransmissionTask();
|
||||
}
|
||||
|
||||
void MeshForwarder::ScheduleTransmissionTask(void)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint8_t numChildren;
|
||||
uint8_t childIndex;
|
||||
@@ -259,7 +257,7 @@ void MeshForwarder::ScheduleTransmissionTask(void)
|
||||
|
||||
mSendMessageIsARetransmission = false;
|
||||
|
||||
children = mNetif.GetMle().GetChildren(&numChildren);
|
||||
children = netif.GetMle().GetChildren(&numChildren);
|
||||
|
||||
if (mStartChildIndex >= numChildren)
|
||||
{
|
||||
@@ -301,12 +299,12 @@ void MeshForwarder::ScheduleTransmissionTask(void)
|
||||
if (child.IsIndirectSourceMatchShort())
|
||||
{
|
||||
mMacSource.mLength = sizeof(mMacSource.mShortAddress);
|
||||
mMacSource.mShortAddress = mNetif.GetMac().GetShortAddress();
|
||||
mMacSource.mShortAddress = netif.GetMac().GetShortAddress();
|
||||
}
|
||||
else
|
||||
{
|
||||
mMacSource.mLength = sizeof(mMacSource.mExtAddress);
|
||||
memcpy(mMacSource.mExtAddress.m8, mNetif.GetMac().GetExtAddress(), sizeof(mMacDest.mExtAddress));
|
||||
memcpy(mMacSource.mExtAddress.m8, netif.GetMac().GetExtAddress(), sizeof(mMacDest.mExtAddress));
|
||||
}
|
||||
|
||||
child.GetMacAddress(mMacDest);
|
||||
@@ -321,13 +319,13 @@ void MeshForwarder::ScheduleTransmissionTask(void)
|
||||
|
||||
mStartChildIndex = nextIndex;
|
||||
|
||||
mNetif.GetMac().SendFrameRequest(mMacSender);
|
||||
netif.GetMac().SendFrameRequest(mMacSender);
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
if ((mSendMessage = GetDirectTransmission()) != NULL)
|
||||
{
|
||||
mNetif.GetMac().SendFrameRequest(mMacSender);
|
||||
netif.GetMac().SendFrameRequest(mMacSender);
|
||||
mSendMessageMaxMacTxAttempts = Mac::kDirectFrameMacTxAttempts;
|
||||
ExitNow();
|
||||
}
|
||||
@@ -343,6 +341,7 @@ exit:
|
||||
|
||||
otError MeshForwarder::SendMessage(Message &aMessage)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
Neighbor *neighbor;
|
||||
|
||||
@@ -357,9 +356,9 @@ otError MeshForwarder::SendMessage(Message &aMessage)
|
||||
|
||||
aMessage.Read(0, sizeof(ip6Header), &ip6Header);
|
||||
|
||||
if (!memcmp(&ip6Header.GetDestination(), mNetif.GetMle().GetLinkLocalAllThreadNodesAddress(),
|
||||
if (!memcmp(&ip6Header.GetDestination(), netif.GetMle().GetLinkLocalAllThreadNodesAddress(),
|
||||
sizeof(ip6Header.GetDestination())) ||
|
||||
!memcmp(&ip6Header.GetDestination(), mNetif.GetMle().GetRealmLocalAllThreadNodesAddress(),
|
||||
!memcmp(&ip6Header.GetDestination(), netif.GetMle().GetRealmLocalAllThreadNodesAddress(),
|
||||
sizeof(ip6Header.GetDestination())))
|
||||
{
|
||||
// schedule direct transmission
|
||||
@@ -368,7 +367,7 @@ otError MeshForwarder::SendMessage(Message &aMessage)
|
||||
if (aMessage.GetSubType() != Message::kSubTypeMplRetransmission)
|
||||
{
|
||||
// destined for all sleepy children
|
||||
child = mNetif.GetMle().GetChildren(&numChildren);
|
||||
child = netif.GetMle().GetChildren(&numChildren);
|
||||
|
||||
for (uint8_t i = 0; i < numChildren; i++, child++)
|
||||
{
|
||||
@@ -380,13 +379,13 @@ otError MeshForwarder::SendMessage(Message &aMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((neighbor = mNetif.GetMle().GetNeighbor(ip6Header.GetDestination())) != NULL &&
|
||||
else if ((neighbor = netif.GetMle().GetNeighbor(ip6Header.GetDestination())) != NULL &&
|
||||
!neighbor->IsRxOnWhenIdle() &&
|
||||
!aMessage.GetDirectTransmission())
|
||||
{
|
||||
// destined for a sleepy child
|
||||
child = static_cast<Child *>(neighbor);
|
||||
aMessage.SetChildMask(mNetif.GetMle().GetChildIndex(*child));
|
||||
aMessage.SetChildMask(netif.GetMle().GetChildIndex(*child));
|
||||
mSourceMatchController.IncrementMessageCount(*child);
|
||||
}
|
||||
else
|
||||
@@ -404,12 +403,12 @@ otError MeshForwarder::SendMessage(Message &aMessage)
|
||||
|
||||
IgnoreReturnValue(meshHeader.Init(aMessage));
|
||||
|
||||
if ((neighbor = mNetif.GetMle().GetNeighbor(meshHeader.GetDestination())) != NULL &&
|
||||
if ((neighbor = netif.GetMle().GetNeighbor(meshHeader.GetDestination())) != NULL &&
|
||||
!neighbor->IsRxOnWhenIdle())
|
||||
{
|
||||
// destined for a sleepy child
|
||||
child = static_cast<Child *>(neighbor);
|
||||
aMessage.SetChildMask(mNetif.GetMle().GetChildIndex(*child));
|
||||
aMessage.SetChildMask(netif.GetMle().GetChildIndex(*child));
|
||||
mSourceMatchController.IncrementMessageCount(*child);
|
||||
}
|
||||
else
|
||||
@@ -426,11 +425,11 @@ otError MeshForwarder::SendMessage(Message &aMessage)
|
||||
break;
|
||||
|
||||
case Message::kTypeSupervision:
|
||||
child = mNetif.GetChildSupervisor().GetDestination(aMessage);
|
||||
child = netif.GetChildSupervisor().GetDestination(aMessage);
|
||||
VerifyOrExit(child != NULL, error = OT_ERROR_DROP);
|
||||
VerifyOrExit(!child->IsRxOnWhenIdle(), error = OT_ERROR_DROP);
|
||||
|
||||
aMessage.SetChildMask(mNetif.GetMle().GetChildIndex(*child));
|
||||
aMessage.SetChildMask(netif.GetMle().GetChildIndex(*child));
|
||||
mSourceMatchController.IncrementMessageCount(*child);
|
||||
break;
|
||||
}
|
||||
@@ -446,14 +445,15 @@ exit:
|
||||
|
||||
otError MeshForwarder::PrepareDiscoverRequest(void)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
VerifyOrExit(!mScanning);
|
||||
|
||||
mScanChannel = OT_RADIO_CHANNEL_MIN;
|
||||
mScanChannels >>= OT_RADIO_CHANNEL_MIN;
|
||||
mRestoreChannel = mNetif.GetMac().GetChannel();
|
||||
mRestorePanId = mNetif.GetMac().GetPanId();
|
||||
mRestoreChannel = netif.GetMac().GetChannel();
|
||||
mRestorePanId = netif.GetMac().GetPanId();
|
||||
|
||||
while ((mScanChannels & 1) == 0)
|
||||
{
|
||||
@@ -462,7 +462,7 @@ otError MeshForwarder::PrepareDiscoverRequest(void)
|
||||
|
||||
if (mScanChannel > OT_RADIO_CHANNEL_MAX)
|
||||
{
|
||||
mNetif.GetMle().HandleDiscoverComplete();
|
||||
netif.GetMle().HandleDiscoverComplete();
|
||||
ExitNow(error = OT_ERROR_DROP);
|
||||
}
|
||||
}
|
||||
@@ -541,7 +541,7 @@ Message *MeshForwarder::GetIndirectTransmission(Child &aChild)
|
||||
{
|
||||
Message *message = NULL;
|
||||
Message *next;
|
||||
uint8_t childIndex = mNetif.GetMle().GetChildIndex(aChild);
|
||||
uint8_t childIndex = GetNetif().GetMle().GetChildIndex(aChild);
|
||||
|
||||
for (message = mSendQueue.GetHead(); message; message = next)
|
||||
{
|
||||
@@ -622,7 +622,7 @@ void MeshForwarder::PrepareIndirectTransmission(Message &aMessage, const Child &
|
||||
mMeshDest = meshHeader.GetDestination();
|
||||
mMeshSource = meshHeader.GetSource();
|
||||
mMacSource.mLength = sizeof(mMacSource.mShortAddress);
|
||||
mMacSource.mShortAddress = mNetif.GetMac().GetShortAddress();
|
||||
mMacSource.mShortAddress = GetNetif().GetMac().GetShortAddress();
|
||||
mMacDest.mLength = sizeof(mMacDest.mShortAddress);
|
||||
mMacDest.mShortAddress = meshHeader.GetDestination();
|
||||
break;
|
||||
@@ -640,6 +640,7 @@ void MeshForwarder::PrepareIndirectTransmission(Message &aMessage, const Child &
|
||||
|
||||
otError MeshForwarder::UpdateMeshRoute(Message &aMessage)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
Lowpan::MeshHeader meshHeader;
|
||||
Neighbor *neighbor;
|
||||
@@ -647,15 +648,15 @@ otError MeshForwarder::UpdateMeshRoute(Message &aMessage)
|
||||
|
||||
IgnoreReturnValue(meshHeader.Init(aMessage));
|
||||
|
||||
nextHop = mNetif.GetMle().GetNextHop(meshHeader.GetDestination());
|
||||
nextHop = netif.GetMle().GetNextHop(meshHeader.GetDestination());
|
||||
|
||||
if (nextHop != Mac::kShortAddrInvalid)
|
||||
{
|
||||
neighbor = mNetif.GetMle().GetNeighbor(nextHop);
|
||||
neighbor = netif.GetMle().GetNeighbor(nextHop);
|
||||
}
|
||||
else
|
||||
{
|
||||
neighbor = mNetif.GetMle().GetNeighbor(meshHeader.GetDestination());
|
||||
neighbor = netif.GetMle().GetNeighbor(meshHeader.GetDestination());
|
||||
}
|
||||
|
||||
if (neighbor == NULL)
|
||||
@@ -666,7 +667,7 @@ otError MeshForwarder::UpdateMeshRoute(Message &aMessage)
|
||||
mMacDest.mLength = sizeof(mMacDest.mShortAddress);
|
||||
mMacDest.mShortAddress = neighbor->GetRloc16();
|
||||
mMacSource.mLength = sizeof(mMacSource.mShortAddress);
|
||||
mMacSource.mShortAddress = mNetif.GetMac().GetShortAddress();
|
||||
mMacSource.mShortAddress = netif.GetMac().GetShortAddress();
|
||||
|
||||
mAddMeshHeader = true;
|
||||
mMeshDest = meshHeader.GetDestination();
|
||||
@@ -678,6 +679,7 @@ exit:
|
||||
|
||||
otError MeshForwarder::UpdateIp6Route(Message &aMessage)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
Ip6::Header ip6Header;
|
||||
|
||||
@@ -685,7 +687,7 @@ otError MeshForwarder::UpdateIp6Route(Message &aMessage)
|
||||
|
||||
aMessage.Read(0, sizeof(ip6Header), &ip6Header);
|
||||
|
||||
switch (mNetif.GetMle().GetRole())
|
||||
switch (netif.GetMle().GetRole())
|
||||
{
|
||||
case OT_DEVICE_ROLE_DISABLED:
|
||||
case OT_DEVICE_ROLE_DETACHED:
|
||||
@@ -704,7 +706,7 @@ otError MeshForwarder::UpdateIp6Route(Message &aMessage)
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case OT_DEVICE_ROLE_ROUTER:
|
||||
case OT_DEVICE_ROLE_LEADER:
|
||||
if (mNetif.GetMle().IsMinimalEndDevice())
|
||||
if (netif.GetMle().IsMinimalEndDevice())
|
||||
{
|
||||
if (aMessage.IsLinkSecurityEnabled())
|
||||
{
|
||||
@@ -716,7 +718,7 @@ otError MeshForwarder::UpdateIp6Route(Message &aMessage)
|
||||
}
|
||||
else
|
||||
{
|
||||
mMacDest.mShortAddress = mNetif.GetMle().GetNextHop(Mac::kShortAddrBroadcast);
|
||||
mMacDest.mShortAddress = netif.GetMle().GetNextHop(Mac::kShortAddrBroadcast);
|
||||
}
|
||||
|
||||
GetMacSourceAddress(ip6Header.GetSource(), mMacSource);
|
||||
@@ -746,20 +748,20 @@ otError MeshForwarder::UpdateIp6Route(Message &aMessage)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mNetif.GetMle().IsRoutingLocator(ip6Header.GetDestination()))
|
||||
if (netif.GetMle().IsRoutingLocator(ip6Header.GetDestination()))
|
||||
{
|
||||
rloc16 = HostSwap16(ip6Header.GetDestination().mFields.m16[7]);
|
||||
VerifyOrExit(mNetif.GetMle().IsRouterIdValid(mNetif.GetMle().GetRouterId(rloc16)),
|
||||
VerifyOrExit(netif.GetMle().IsRouterIdValid(netif.GetMle().GetRouterId(rloc16)),
|
||||
error = OT_ERROR_DROP);
|
||||
mMeshDest = rloc16;
|
||||
}
|
||||
else if (mNetif.GetMle().IsAnycastLocator(ip6Header.GetDestination()))
|
||||
else if (netif.GetMle().IsAnycastLocator(ip6Header.GetDestination()))
|
||||
{
|
||||
aloc16 = HostSwap16(ip6Header.GetDestination().mFields.m16[7]);
|
||||
|
||||
if (aloc16 == Mle::kAloc16Leader)
|
||||
{
|
||||
mMeshDest = mNetif.GetMle().GetRloc16(mNetif.GetMle().GetLeaderId());
|
||||
mMeshDest = netif.GetMle().GetRloc16(netif.GetMle().GetLeaderId());
|
||||
}
|
||||
|
||||
#if OPENTHREAD_ENABLE_DHCP6_SERVER || OPENTHREAD_ENABLE_DHCP6_CLIENT
|
||||
@@ -767,23 +769,23 @@ otError MeshForwarder::UpdateIp6Route(Message &aMessage)
|
||||
{
|
||||
uint16_t agentRloc16;
|
||||
uint8_t routerId;
|
||||
VerifyOrExit((mNetif.GetNetworkDataLeader().GetRlocByContextId(
|
||||
VerifyOrExit((netif.GetNetworkDataLeader().GetRlocByContextId(
|
||||
static_cast<uint8_t>(aloc16 & Mle::kAloc16DhcpAgentMask),
|
||||
agentRloc16) == OT_ERROR_NONE),
|
||||
error = OT_ERROR_DROP);
|
||||
|
||||
routerId = mNetif.GetMle().GetRouterId(agentRloc16);
|
||||
routerId = netif.GetMle().GetRouterId(agentRloc16);
|
||||
|
||||
// if agent is active router or the child of the device
|
||||
if ((mNetif.GetMle().IsActiveRouter(agentRloc16)) ||
|
||||
(mNetif.GetMle().GetRloc16(routerId) == mNetif.GetMle().GetRloc16()))
|
||||
if ((netif.GetMle().IsActiveRouter(agentRloc16)) ||
|
||||
(netif.GetMle().GetRloc16(routerId) == netif.GetMle().GetRloc16()))
|
||||
{
|
||||
mMeshDest = agentRloc16;
|
||||
}
|
||||
else
|
||||
{
|
||||
// use the parent of the ED Agent as Dest
|
||||
mMeshDest = mNetif.GetMle().GetRloc16(routerId);
|
||||
mMeshDest = netif.GetMle().GetRloc16(routerId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -794,17 +796,17 @@ otError MeshForwarder::UpdateIp6Route(Message &aMessage)
|
||||
ExitNow(error = OT_ERROR_DROP);
|
||||
}
|
||||
}
|
||||
else if ((neighbor = mNetif.GetMle().GetNeighbor(ip6Header.GetDestination())) != NULL)
|
||||
else if ((neighbor = netif.GetMle().GetNeighbor(ip6Header.GetDestination())) != NULL)
|
||||
{
|
||||
mMeshDest = neighbor->GetRloc16();
|
||||
}
|
||||
else if (mNetif.GetNetworkDataLeader().IsOnMesh(ip6Header.GetDestination()))
|
||||
else if (netif.GetNetworkDataLeader().IsOnMesh(ip6Header.GetDestination()))
|
||||
{
|
||||
SuccessOrExit(error = mNetif.GetAddressResolver().Resolve(ip6Header.GetDestination(), mMeshDest));
|
||||
SuccessOrExit(error = netif.GetAddressResolver().Resolve(ip6Header.GetDestination(), mMeshDest));
|
||||
}
|
||||
else
|
||||
{
|
||||
mNetif.GetNetworkDataLeader().RouteLookup(
|
||||
netif.GetNetworkDataLeader().RouteLookup(
|
||||
ip6Header.GetSource(),
|
||||
ip6Header.GetDestination(),
|
||||
NULL,
|
||||
@@ -814,7 +816,7 @@ otError MeshForwarder::UpdateIp6Route(Message &aMessage)
|
||||
|
||||
VerifyOrExit(mMeshDest != Mac::kShortAddrInvalid, error = OT_ERROR_DROP);
|
||||
|
||||
if (mNetif.GetMle().GetNeighbor(mMeshDest) != NULL)
|
||||
if (netif.GetMle().GetNeighbor(mMeshDest) != NULL)
|
||||
{
|
||||
// destination is neighbor
|
||||
mMacDest.mLength = sizeof(mMacDest.mShortAddress);
|
||||
@@ -824,12 +826,12 @@ otError MeshForwarder::UpdateIp6Route(Message &aMessage)
|
||||
else
|
||||
{
|
||||
// destination is not neighbor
|
||||
mMeshSource = mNetif.GetMac().GetShortAddress();
|
||||
mMeshSource = netif.GetMac().GetShortAddress();
|
||||
|
||||
SuccessOrExit(error = mNetif.GetMle().CheckReachability(mMeshSource, mMeshDest, ip6Header));
|
||||
SuccessOrExit(error = netif.GetMle().CheckReachability(mMeshSource, mMeshDest, ip6Header));
|
||||
|
||||
mMacDest.mLength = sizeof(mMacDest.mShortAddress);
|
||||
mMacDest.mShortAddress = mNetif.GetMle().GetNextHop(mMeshDest);
|
||||
mMacDest.mShortAddress = netif.GetMle().GetNextHop(mMeshDest);
|
||||
mMacSource.mLength = sizeof(mMacSource.mShortAddress);
|
||||
mMacSource.mShortAddress = mMeshSource;
|
||||
mAddMeshHeader = true;
|
||||
@@ -850,41 +852,47 @@ exit:
|
||||
|
||||
void MeshForwarder::SetRxOff(void)
|
||||
{
|
||||
mNetif.GetMac().SetRxOnWhenIdle(false);
|
||||
ThreadNetif &netif = GetNetif();
|
||||
|
||||
netif.GetMac().SetRxOnWhenIdle(false);
|
||||
mDataPollManager.StopPolling();
|
||||
mNetif.GetSupervisionListener().Stop();
|
||||
netif.GetSupervisionListener().Stop();
|
||||
}
|
||||
|
||||
bool MeshForwarder::GetRxOnWhenIdle(void)
|
||||
{
|
||||
return mNetif.GetMac().GetRxOnWhenIdle();
|
||||
return GetNetif().GetMac().GetRxOnWhenIdle();
|
||||
}
|
||||
|
||||
void MeshForwarder::SetRxOnWhenIdle(bool aRxOnWhenIdle)
|
||||
{
|
||||
mNetif.GetMac().SetRxOnWhenIdle(aRxOnWhenIdle);
|
||||
ThreadNetif &netif = GetNetif();
|
||||
|
||||
netif.GetMac().SetRxOnWhenIdle(aRxOnWhenIdle);
|
||||
|
||||
if (aRxOnWhenIdle)
|
||||
{
|
||||
mDataPollManager.StopPolling();
|
||||
mNetif.GetSupervisionListener().Stop();
|
||||
netif.GetSupervisionListener().Stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
mDataPollManager.StartPolling();
|
||||
mNetif.GetSupervisionListener().Start();
|
||||
netif.GetSupervisionListener().Start();
|
||||
}
|
||||
}
|
||||
|
||||
otError MeshForwarder::GetMacSourceAddress(const Ip6::Address &aIp6Addr, Mac::Address &aMacAddr)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
|
||||
aMacAddr.mLength = sizeof(aMacAddr.mExtAddress);
|
||||
aMacAddr.mExtAddress.Set(aIp6Addr);
|
||||
|
||||
if (memcmp(&aMacAddr.mExtAddress, mNetif.GetMac().GetExtAddress(), sizeof(aMacAddr.mExtAddress)) != 0)
|
||||
if (memcmp(&aMacAddr.mExtAddress, netif.GetMac().GetExtAddress(), sizeof(aMacAddr.mExtAddress)) != 0)
|
||||
{
|
||||
aMacAddr.mLength = sizeof(aMacAddr.mShortAddress);
|
||||
aMacAddr.mShortAddress = mNetif.GetMac().GetShortAddress();
|
||||
aMacAddr.mShortAddress = netif.GetMac().GetShortAddress();
|
||||
}
|
||||
|
||||
return OT_ERROR_NONE;
|
||||
@@ -908,7 +916,7 @@ otError MeshForwarder::GetMacDestinationAddress(const Ip6::Address &aIp6Addr, Ma
|
||||
aMacAddr.mLength = sizeof(aMacAddr.mShortAddress);
|
||||
aMacAddr.mShortAddress = HostSwap16(aIp6Addr.mFields.m16[7]);
|
||||
}
|
||||
else if (mNetif.GetMle().IsRoutingLocator(aIp6Addr))
|
||||
else if (GetNetif().GetMle().IsRoutingLocator(aIp6Addr))
|
||||
{
|
||||
aMacAddr.mLength = sizeof(aMacAddr.mShortAddress);
|
||||
aMacAddr.mShortAddress = HostSwap16(aIp6Addr.mFields.m16[7]);
|
||||
@@ -922,13 +930,14 @@ otError MeshForwarder::GetMacDestinationAddress(const Ip6::Address &aIp6Addr, Ma
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError MeshForwarder::HandleFrameRequest(void *aContext, Mac::Frame &aFrame)
|
||||
otError MeshForwarder::HandleFrameRequest(Mac::Sender &aSender, Mac::Frame &aFrame)
|
||||
{
|
||||
return static_cast<MeshForwarder *>(aContext)->HandleFrameRequest(aFrame);
|
||||
return GetOwner(aSender).HandleFrameRequest(aFrame);
|
||||
}
|
||||
|
||||
otError MeshForwarder::HandleFrameRequest(Mac::Frame &aFrame)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
Mac::Address macDest;
|
||||
Child *child = NULL;
|
||||
@@ -950,7 +959,7 @@ otError MeshForwarder::HandleFrameRequest(Mac::Frame &aFrame)
|
||||
case Message::kTypeIp6:
|
||||
if (mSendMessage->GetSubType() == Message::kSubTypeMleDiscoverRequest)
|
||||
{
|
||||
mNetif.GetMac().SetChannel(mScanChannel);
|
||||
netif.GetMac().SetChannel(mScanChannel);
|
||||
aFrame.SetChannel(mScanChannel);
|
||||
|
||||
// In case a specific PAN ID of a Thread Network to be discovered is not known, Discovery
|
||||
@@ -958,7 +967,7 @@ otError MeshForwarder::HandleFrameRequest(Mac::Frame &aFrame)
|
||||
// to be the Broadcast PAN ID (0xFFFF) and the Source PAN ID set to a randomly generated
|
||||
// value.
|
||||
if (mSendMessage->GetPanId() == Mac::kPanIdBroadcast &&
|
||||
mNetif.GetMac().GetPanId() == Mac::kPanIdBroadcast)
|
||||
netif.GetMac().GetPanId() == Mac::kPanIdBroadcast)
|
||||
{
|
||||
uint16_t panid;
|
||||
|
||||
@@ -968,7 +977,7 @@ otError MeshForwarder::HandleFrameRequest(Mac::Frame &aFrame)
|
||||
}
|
||||
while (panid == Mac::kPanIdBroadcast);
|
||||
|
||||
mNetif.GetMac().SetPanId(panid);
|
||||
netif.GetMac().SetPanId(panid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1009,7 +1018,7 @@ otError MeshForwarder::HandleFrameRequest(Mac::Frame &aFrame)
|
||||
// The case where the current message requires fragmentation is
|
||||
// already checked and handled in `SendFragment()` method.
|
||||
|
||||
if (((child = mNetif.GetMle().GetChild(macDest)) != NULL)
|
||||
if (((child = netif.GetMle().GetChild(macDest)) != NULL)
|
||||
&& !child->IsRxOnWhenIdle()
|
||||
&& (child->GetIndirectMessageCount() > 1))
|
||||
{
|
||||
@@ -1040,11 +1049,12 @@ exit:
|
||||
|
||||
otError MeshForwarder::SendPoll(Message &aMessage, Mac::Frame &aFrame)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
Mac::Address macSource;
|
||||
uint16_t fcf;
|
||||
Neighbor *neighbor;
|
||||
|
||||
macSource.mShortAddress = mNetif.GetMac().GetShortAddress();
|
||||
macSource.mShortAddress = netif.GetMac().GetShortAddress();
|
||||
|
||||
if (macSource.mShortAddress != Mac::kShortAddrInvalid)
|
||||
{
|
||||
@@ -1053,7 +1063,7 @@ otError MeshForwarder::SendPoll(Message &aMessage, Mac::Frame &aFrame)
|
||||
else
|
||||
{
|
||||
macSource.mLength = sizeof(macSource.mExtAddress);
|
||||
memcpy(&macSource.mExtAddress, mNetif.GetMac().GetExtAddress(), sizeof(macSource.mExtAddress));
|
||||
memcpy(&macSource.mExtAddress, netif.GetMac().GetExtAddress(), sizeof(macSource.mExtAddress));
|
||||
}
|
||||
|
||||
// initialize MAC header
|
||||
@@ -1071,9 +1081,9 @@ otError MeshForwarder::SendPoll(Message &aMessage, Mac::Frame &aFrame)
|
||||
fcf |= Mac::Frame::kFcfAckRequest | Mac::Frame::kFcfSecurityEnabled;
|
||||
|
||||
aFrame.InitMacHeader(fcf, Mac::Frame::kKeyIdMode1 | Mac::Frame::kSecEncMic32);
|
||||
aFrame.SetDstPanId(mNetif.GetMac().GetPanId());
|
||||
aFrame.SetDstPanId(netif.GetMac().GetPanId());
|
||||
|
||||
neighbor = mNetif.GetMle().GetParent();
|
||||
neighbor = netif.GetMle().GetParent();
|
||||
assert(neighbor != NULL);
|
||||
|
||||
if (macSource.mLength == 2)
|
||||
@@ -1096,6 +1106,7 @@ otError MeshForwarder::SendPoll(Message &aMessage, Mac::Frame &aFrame)
|
||||
|
||||
otError MeshForwarder::SendMesh(Message &aMessage, Mac::Frame &aFrame)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
uint16_t fcf;
|
||||
|
||||
// initialize MAC header
|
||||
@@ -1104,7 +1115,7 @@ otError MeshForwarder::SendMesh(Message &aMessage, Mac::Frame &aFrame)
|
||||
Mac::Frame::kFcfAckRequest | Mac::Frame::kFcfSecurityEnabled;
|
||||
|
||||
aFrame.InitMacHeader(fcf, Mac::Frame::kKeyIdMode1 | Mac::Frame::kSecEncMic32);
|
||||
aFrame.SetDstPanId(mNetif.GetMac().GetPanId());
|
||||
aFrame.SetDstPanId(netif.GetMac().GetPanId());
|
||||
aFrame.SetDstAddr(mMacDest.mShortAddress);
|
||||
aFrame.SetSrcAddr(mMacSource.mShortAddress);
|
||||
|
||||
@@ -1120,6 +1131,7 @@ otError MeshForwarder::SendMesh(Message &aMessage, Mac::Frame &aFrame)
|
||||
|
||||
otError MeshForwarder::SendFragment(Message &aMessage, Mac::Frame &aFrame)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
Mac::Address meshDest, meshSource;
|
||||
uint16_t fcf;
|
||||
Lowpan::FragmentHeader *fragmentHeader;
|
||||
@@ -1180,7 +1192,7 @@ otError MeshForwarder::SendFragment(Message &aMessage, Mac::Frame &aFrame)
|
||||
secCtl |= Mac::Frame::kSecEncMic32;
|
||||
}
|
||||
|
||||
dstpan = mNetif.GetMac().GetPanId();
|
||||
dstpan = netif.GetMac().GetPanId();
|
||||
|
||||
switch (aMessage.GetSubType())
|
||||
{
|
||||
@@ -1198,14 +1210,14 @@ otError MeshForwarder::SendFragment(Message &aMessage, Mac::Frame &aFrame)
|
||||
break;
|
||||
}
|
||||
|
||||
if (dstpan == mNetif.GetMac().GetPanId())
|
||||
if (dstpan == netif.GetMac().GetPanId())
|
||||
{
|
||||
fcf |= Mac::Frame::kFcfPanidCompression;
|
||||
}
|
||||
|
||||
aFrame.InitMacHeader(fcf, secCtl);
|
||||
aFrame.SetDstPanId(dstpan);
|
||||
aFrame.SetSrcPanId(mNetif.GetMac().GetPanId());
|
||||
aFrame.SetSrcPanId(netif.GetMac().GetPanId());
|
||||
|
||||
if (mMacDest.mLength == 2)
|
||||
{
|
||||
@@ -1232,7 +1244,7 @@ otError MeshForwarder::SendFragment(Message &aMessage, Mac::Frame &aFrame)
|
||||
// initialize Mesh header
|
||||
if (mAddMeshHeader)
|
||||
{
|
||||
if (mNetif.GetMle().GetRole() == OT_DEVICE_ROLE_CHILD)
|
||||
if (netif.GetMle().GetRole() == OT_DEVICE_ROLE_CHILD)
|
||||
{
|
||||
// REED sets hopsLeft to max (16) + 1. It does not know the route cost.
|
||||
hopsLeft = Mle::kMaxRouteCost + 1;
|
||||
@@ -1240,24 +1252,24 @@ otError MeshForwarder::SendFragment(Message &aMessage, Mac::Frame &aFrame)
|
||||
else
|
||||
{
|
||||
// Calculate the number of predicted hops.
|
||||
hopsLeft = mNetif.GetMle().GetRouteCost(mMeshDest);
|
||||
hopsLeft = netif.GetMle().GetRouteCost(mMeshDest);
|
||||
|
||||
if (hopsLeft != Mle::kMaxRouteCost)
|
||||
{
|
||||
hopsLeft += mNetif.GetMle().GetLinkCost(
|
||||
mNetif.GetMle().GetRouterId(mNetif.GetMle().GetNextHop(mMeshDest)));
|
||||
hopsLeft += netif.GetMle().GetLinkCost(
|
||||
netif.GetMle().GetRouterId(netif.GetMle().GetNextHop(mMeshDest)));
|
||||
}
|
||||
else
|
||||
{
|
||||
// In case there is no route to the destination router (only link).
|
||||
hopsLeft = mNetif.GetMle().GetLinkCost(mNetif.GetMle().GetRouterId(mMeshDest));
|
||||
hopsLeft = netif.GetMle().GetLinkCost(netif.GetMle().GetRouterId(mMeshDest));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// The hopsLft field MUST be incremented by one if the destination RLOC16
|
||||
// is not that of an active Router.
|
||||
if (!mNetif.GetMle().IsActiveRouter(mMeshDest))
|
||||
if (!netif.GetMle().IsActiveRouter(mMeshDest))
|
||||
{
|
||||
hopsLeft += 1;
|
||||
}
|
||||
@@ -1274,7 +1286,7 @@ otError MeshForwarder::SendFragment(Message &aMessage, Mac::Frame &aFrame)
|
||||
// copy IPv6 Header
|
||||
if (aMessage.GetOffset() == 0)
|
||||
{
|
||||
hcLength = mNetif.GetLowpan().Compress(aMessage, meshSource, meshDest, payload);
|
||||
hcLength = netif.GetLowpan().Compress(aMessage, meshSource, meshDest, payload);
|
||||
assert(hcLength > 0);
|
||||
headerLength += static_cast<uint8_t>(hcLength);
|
||||
|
||||
@@ -1365,11 +1377,12 @@ exit:
|
||||
|
||||
otError MeshForwarder::SendEmptyFrame(Mac::Frame &aFrame, bool aAckRequest)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
uint16_t fcf;
|
||||
uint8_t secCtl;
|
||||
Mac::Address macSource;
|
||||
|
||||
macSource.mShortAddress = mNetif.GetMac().GetShortAddress();
|
||||
macSource.mShortAddress = netif.GetMac().GetShortAddress();
|
||||
|
||||
if (macSource.mShortAddress != Mac::kShortAddrInvalid)
|
||||
{
|
||||
@@ -1378,7 +1391,7 @@ otError MeshForwarder::SendEmptyFrame(Mac::Frame &aFrame, bool aAckRequest)
|
||||
else
|
||||
{
|
||||
macSource.mLength = sizeof(macSource.mExtAddress);
|
||||
memcpy(&macSource.mExtAddress, mNetif.GetMac().GetExtAddress(), sizeof(macSource.mExtAddress));
|
||||
memcpy(&macSource.mExtAddress, netif.GetMac().GetExtAddress(), sizeof(macSource.mExtAddress));
|
||||
}
|
||||
|
||||
fcf = Mac::Frame::kFcfFrameData | Mac::Frame::kFcfFrameVersion2006;
|
||||
@@ -1398,8 +1411,8 @@ otError MeshForwarder::SendEmptyFrame(Mac::Frame &aFrame, bool aAckRequest)
|
||||
|
||||
aFrame.InitMacHeader(fcf, secCtl);
|
||||
|
||||
aFrame.SetDstPanId(mNetif.GetMac().GetPanId());
|
||||
aFrame.SetSrcPanId(mNetif.GetMac().GetPanId());
|
||||
aFrame.SetDstPanId(netif.GetMac().GetPanId());
|
||||
aFrame.SetSrcPanId(netif.GetMac().GetPanId());
|
||||
|
||||
if (mMacDest.mLength == 2)
|
||||
{
|
||||
@@ -1425,13 +1438,14 @@ otError MeshForwarder::SendEmptyFrame(Mac::Frame &aFrame, bool aAckRequest)
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
void MeshForwarder::HandleSentFrame(void *aContext, Mac::Frame &aFrame, otError aError)
|
||||
void MeshForwarder::HandleSentFrame(Mac::Sender &aSender, Mac::Frame &aFrame, otError aError)
|
||||
{
|
||||
static_cast<MeshForwarder *>(aContext)->HandleSentFrame(aFrame, aError);
|
||||
GetOwner(aSender).HandleSentFrame(aFrame, aError);
|
||||
}
|
||||
|
||||
void MeshForwarder::HandleSentFrame(Mac::Frame &aFrame, otError aError)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
Mac::Address macDest;
|
||||
Child *child;
|
||||
Neighbor *neighbor;
|
||||
@@ -1448,7 +1462,7 @@ void MeshForwarder::HandleSentFrame(Mac::Frame &aFrame, otError aError)
|
||||
|
||||
aFrame.GetDstAddr(macDest);
|
||||
|
||||
if ((neighbor = mNetif.GetMle().GetNeighbor(macDest)) != NULL)
|
||||
if ((neighbor = netif.GetMle().GetNeighbor(macDest)) != NULL)
|
||||
{
|
||||
switch (aError)
|
||||
{
|
||||
@@ -1467,11 +1481,11 @@ void MeshForwarder::HandleSentFrame(Mac::Frame &aFrame, otError aError)
|
||||
case OT_ERROR_NO_ACK:
|
||||
neighbor->IncrementLinkFailures();
|
||||
|
||||
if (mNetif.GetMle().IsActiveRouter(neighbor->GetRloc16()))
|
||||
if (netif.GetMle().IsActiveRouter(neighbor->GetRloc16()))
|
||||
{
|
||||
if (neighbor->GetLinkFailures() >= Mle::kFailedRouterTransmissions)
|
||||
{
|
||||
mNetif.GetMle().RemoveNeighbor(*neighbor);
|
||||
netif.GetMle().RemoveNeighbor(*neighbor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1483,7 +1497,7 @@ void MeshForwarder::HandleSentFrame(Mac::Frame &aFrame, otError aError)
|
||||
}
|
||||
}
|
||||
|
||||
if ((child = mNetif.GetMle().GetChild(macDest)) != NULL)
|
||||
if ((child = netif.GetMle().GetChild(macDest)) != NULL)
|
||||
{
|
||||
child->SetDataRequestPending(false);
|
||||
|
||||
@@ -1561,7 +1575,7 @@ void MeshForwarder::HandleSentFrame(Mac::Frame &aFrame, otError aError)
|
||||
mSourceMatchController.SetSrcMatchAsShort(*child, true);
|
||||
}
|
||||
|
||||
childIndex = mNetif.GetMle().GetChildIndex(*child);
|
||||
childIndex = netif.GetMle().GetChildIndex(*child);
|
||||
|
||||
if (mSendMessage->GetChildMask(childIndex))
|
||||
{
|
||||
@@ -1572,7 +1586,7 @@ void MeshForwarder::HandleSentFrame(Mac::Frame &aFrame, otError aError)
|
||||
|
||||
if (aError == OT_ERROR_NONE)
|
||||
{
|
||||
mNetif.GetChildSupervisor().UpdateOnSend(*child);
|
||||
netif.GetChildSupervisor().UpdateOnSend(*child);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1613,12 +1627,12 @@ void MeshForwarder::HandleSentFrame(Mac::Frame &aFrame, otError aError)
|
||||
|
||||
if (mSendMessage->GetType() == Message::kTypeMacDataPoll)
|
||||
{
|
||||
neighbor = mNetif.GetMle().GetParent();
|
||||
neighbor = netif.GetMle().GetParent();
|
||||
|
||||
if (neighbor->GetState() == Neighbor::kStateInvalid)
|
||||
{
|
||||
mDataPollManager.StopPolling();
|
||||
mNetif.GetMle().BecomeDetached();
|
||||
netif.GetMle().BecomeDetached();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1661,14 +1675,15 @@ void MeshForwarder::SetDiscoverParameters(uint32_t aScanChannels)
|
||||
mScanChannels = (aScanChannels == 0) ? static_cast<uint32_t>(Mac::kScanChannelsAll) : aScanChannels;
|
||||
}
|
||||
|
||||
void MeshForwarder::HandleDiscoverTimer(void *aContext)
|
||||
void MeshForwarder::HandleDiscoverTimer(Timer &aTimer)
|
||||
{
|
||||
MeshForwarder *obj = static_cast<MeshForwarder *>(aContext);
|
||||
obj->HandleDiscoverTimer();
|
||||
GetOwner(aTimer).HandleDiscoverTimer();
|
||||
}
|
||||
|
||||
void MeshForwarder::HandleDiscoverTimer(void)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
|
||||
do
|
||||
{
|
||||
mScanChannels >>= 1;
|
||||
@@ -1679,10 +1694,10 @@ void MeshForwarder::HandleDiscoverTimer(void)
|
||||
mSendQueue.Dequeue(*mSendMessage);
|
||||
mSendMessage->Free();
|
||||
mSendMessage = NULL;
|
||||
mNetif.GetMac().SetChannel(mRestoreChannel);
|
||||
mNetif.GetMac().SetPanId(mRestorePanId);
|
||||
netif.GetMac().SetChannel(mRestoreChannel);
|
||||
netif.GetMac().SetPanId(mRestorePanId);
|
||||
mScanning = false;
|
||||
mNetif.GetMle().HandleDiscoverComplete();
|
||||
netif.GetMle().HandleDiscoverComplete();
|
||||
ExitNow();
|
||||
}
|
||||
}
|
||||
@@ -1695,13 +1710,14 @@ exit:
|
||||
mScheduleTransmissionTask.Post();
|
||||
}
|
||||
|
||||
void MeshForwarder::HandleReceivedFrame(void *aContext, Mac::Frame &aFrame)
|
||||
void MeshForwarder::HandleReceivedFrame(Mac::Receiver &aReceiver, Mac::Frame &aFrame)
|
||||
{
|
||||
static_cast<MeshForwarder *>(aContext)->HandleReceivedFrame(aFrame);
|
||||
GetOwner(aReceiver).HandleReceivedFrame(aFrame);
|
||||
}
|
||||
|
||||
void MeshForwarder::HandleReceivedFrame(Mac::Frame &aFrame)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
ThreadMessageInfo messageInfo;
|
||||
Mac::Address macDest;
|
||||
Mac::Address macSource;
|
||||
@@ -1727,7 +1743,7 @@ void MeshForwarder::HandleReceivedFrame(Mac::Frame &aFrame)
|
||||
payload = aFrame.GetPayload();
|
||||
payloadLength = aFrame.GetPayloadLength();
|
||||
|
||||
mNetif.GetSupervisionListener().UpdateOnReceive(macSource, messageInfo.mLinkSecurity);
|
||||
netif.GetSupervisionListener().UpdateOnReceive(macSource, messageInfo.mLinkSecurity);
|
||||
|
||||
mDataPollManager.CheckFramePending(aFrame);
|
||||
|
||||
@@ -1790,6 +1806,7 @@ exit:
|
||||
void MeshForwarder::HandleMesh(uint8_t *aFrame, uint8_t aFrameLength, const Mac::Address &aMacSource,
|
||||
const ThreadMessageInfo &aMessageInfo)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
Message *message = NULL;
|
||||
Mac::Address meshDest;
|
||||
@@ -1807,7 +1824,7 @@ void MeshForwarder::HandleMesh(uint8_t *aFrame, uint8_t aFrameLength, const Mac:
|
||||
meshDest.mLength = sizeof(meshDest.mShortAddress);
|
||||
meshDest.mShortAddress = meshHeader.GetDestination();
|
||||
|
||||
if (meshDest.mShortAddress == mNetif.GetMac().GetShortAddress())
|
||||
if (meshDest.mShortAddress == netif.GetMac().GetShortAddress())
|
||||
{
|
||||
aFrame += meshHeader.GetHeaderLength();
|
||||
aFrameLength -= meshHeader.GetHeaderLength();
|
||||
@@ -1827,14 +1844,14 @@ void MeshForwarder::HandleMesh(uint8_t *aFrame, uint8_t aFrameLength, const Mac:
|
||||
}
|
||||
else if (meshHeader.GetHopsLeft() > 0)
|
||||
{
|
||||
mNetif.GetMle().ResolveRoutingLoops(aMacSource.mShortAddress, meshDest.mShortAddress);
|
||||
netif.GetMle().ResolveRoutingLoops(aMacSource.mShortAddress, meshDest.mShortAddress);
|
||||
|
||||
SuccessOrExit(error = CheckReachability(aFrame, aFrameLength, meshSource, meshDest));
|
||||
|
||||
meshHeader.SetHopsLeft(meshHeader.GetHopsLeft() - 1);
|
||||
meshHeader.AppendTo(aFrame);
|
||||
|
||||
VerifyOrExit((message = mNetif.GetIp6().mMessagePool.New(Message::kType6lowpan, 0)) != NULL,
|
||||
VerifyOrExit((message = netif.GetIp6().mMessagePool.New(Message::kType6lowpan, 0)) != NULL,
|
||||
error = OT_ERROR_NO_BUFS);
|
||||
SuccessOrExit(error = message->SetLength(aFrameLength));
|
||||
message->Write(0, aFrameLength, aFrame);
|
||||
@@ -1871,6 +1888,7 @@ exit:
|
||||
otError MeshForwarder::CheckReachability(uint8_t *aFrame, uint8_t aFrameLength,
|
||||
const Mac::Address &aMeshSource, const Mac::Address &aMeshDest)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
Ip6::Header ip6Header;
|
||||
Lowpan::MeshHeader meshHeader;
|
||||
@@ -1895,10 +1913,10 @@ otError MeshForwarder::CheckReachability(uint8_t *aFrame, uint8_t aFrameLength,
|
||||
// only process IPv6 packets
|
||||
VerifyOrExit(aFrameLength >= 1 && Lowpan::Lowpan::IsLowpanHc(aFrame));
|
||||
|
||||
VerifyOrExit(mNetif.GetLowpan().DecompressBaseHeader(ip6Header, aMeshSource, aMeshDest, aFrame, aFrameLength) > 0,
|
||||
VerifyOrExit(netif.GetLowpan().DecompressBaseHeader(ip6Header, aMeshSource, aMeshDest, aFrame, aFrameLength) > 0,
|
||||
error = OT_ERROR_DROP);
|
||||
|
||||
error = mNetif.GetMle().CheckReachability(aMeshSource.mShortAddress, aMeshDest.mShortAddress, ip6Header);
|
||||
error = netif.GetMle().CheckReachability(aMeshSource.mShortAddress, aMeshDest.mShortAddress, ip6Header);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
@@ -1908,6 +1926,7 @@ void MeshForwarder::HandleFragment(uint8_t *aFrame, uint8_t aFrameLength,
|
||||
const Mac::Address &aMacSource, const Mac::Address &aMacDest,
|
||||
const ThreadMessageInfo &aMessageInfo)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
Lowpan::FragmentHeader *fragmentHeader = reinterpret_cast<Lowpan::FragmentHeader *>(aFrame);
|
||||
uint16_t datagramLength = fragmentHeader->GetDatagramSize();
|
||||
@@ -1920,12 +1939,12 @@ void MeshForwarder::HandleFragment(uint8_t *aFrame, uint8_t aFrameLength,
|
||||
aFrame += fragmentHeader->GetHeaderLength();
|
||||
aFrameLength -= fragmentHeader->GetHeaderLength();
|
||||
|
||||
VerifyOrExit((message = mNetif.GetIp6().mMessagePool.New(Message::kTypeIp6, 0)) != NULL,
|
||||
VerifyOrExit((message = netif.GetIp6().mMessagePool.New(Message::kTypeIp6, 0)) != NULL,
|
||||
error = OT_ERROR_NO_BUFS);
|
||||
message->SetLinkSecurityEnabled(aMessageInfo.mLinkSecurity);
|
||||
message->SetPanId(aMessageInfo.mPanId);
|
||||
headerLength = mNetif.GetLowpan().Decompress(*message, aMacSource, aMacDest, aFrame, aFrameLength,
|
||||
datagramLength);
|
||||
headerLength = netif.GetLowpan().Decompress(*message, aMacSource, aMacDest, aFrame, aFrameLength,
|
||||
datagramLength);
|
||||
VerifyOrExit(headerLength > 0, error = OT_ERROR_PARSE);
|
||||
|
||||
aFrame += headerLength;
|
||||
@@ -1943,7 +1962,7 @@ void MeshForwarder::HandleFragment(uint8_t *aFrame, uint8_t aFrameLength,
|
||||
message->MoveOffset(aFrameLength);
|
||||
|
||||
// Security Check
|
||||
VerifyOrExit(mNetif.GetIp6Filter().Accept(*message), error = OT_ERROR_DROP);
|
||||
VerifyOrExit(netif.GetIp6Filter().Accept(*message), error = OT_ERROR_DROP);
|
||||
|
||||
// Allow re-assembly of only one message at a time on a SED by clearing
|
||||
// any remaining fragments in reassembly list upon receiving of a new
|
||||
@@ -2054,12 +2073,12 @@ void MeshForwarder::ClearReassemblyList(void)
|
||||
}
|
||||
}
|
||||
|
||||
void MeshForwarder::HandleReassemblyTimer(void *aContext)
|
||||
void MeshForwarder::HandleReassemblyTimer(Timer &aTimer)
|
||||
{
|
||||
static_cast<MeshForwarder *>(aContext)->HandleReassemblyTimer();
|
||||
GetOwner(aTimer).HandleReassemblyTimer();
|
||||
}
|
||||
|
||||
void MeshForwarder::HandleReassemblyTimer()
|
||||
void MeshForwarder::HandleReassemblyTimer(void)
|
||||
{
|
||||
Message *next = NULL;
|
||||
uint8_t timeout;
|
||||
@@ -2094,16 +2113,17 @@ void MeshForwarder::HandleLowpanHC(uint8_t *aFrame, uint8_t aFrameLength,
|
||||
const Mac::Address &aMacSource, const Mac::Address &aMacDest,
|
||||
const ThreadMessageInfo &aMessageInfo)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
otError error = OT_ERROR_NONE;
|
||||
Message *message;
|
||||
int headerLength;
|
||||
|
||||
VerifyOrExit((message = mNetif.GetIp6().mMessagePool.New(Message::kTypeIp6, 0)) != NULL,
|
||||
VerifyOrExit((message = netif.GetIp6().mMessagePool.New(Message::kTypeIp6, 0)) != NULL,
|
||||
error = OT_ERROR_NO_BUFS);
|
||||
message->SetLinkSecurityEnabled(aMessageInfo.mLinkSecurity);
|
||||
message->SetPanId(aMessageInfo.mPanId);
|
||||
|
||||
headerLength = mNetif.GetLowpan().Decompress(*message, aMacSource, aMacDest, aFrame, aFrameLength, 0);
|
||||
headerLength = netif.GetLowpan().Decompress(*message, aMacSource, aMacDest, aFrame, aFrameLength, 0);
|
||||
VerifyOrExit(headerLength > 0, error = OT_ERROR_PARSE);
|
||||
|
||||
aFrame += headerLength;
|
||||
@@ -2113,7 +2133,7 @@ void MeshForwarder::HandleLowpanHC(uint8_t *aFrame, uint8_t aFrameLength,
|
||||
message->Write(message->GetOffset(), aFrameLength, aFrame);
|
||||
|
||||
// Security Check
|
||||
VerifyOrExit(mNetif.GetIp6Filter().Accept(*message), error = OT_ERROR_DROP);
|
||||
VerifyOrExit(netif.GetIp6Filter().Accept(*message), error = OT_ERROR_DROP);
|
||||
|
||||
exit:
|
||||
|
||||
@@ -2149,23 +2169,26 @@ exit:
|
||||
otError MeshForwarder::HandleDatagram(Message &aMessage, const ThreadMessageInfo &aMessageInfo,
|
||||
const Mac::Address &aMacSource)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
|
||||
LogIp6Message(kMessageReceive, aMessage, &aMacSource, OT_ERROR_NONE);
|
||||
mIpCounters.mRxSuccess++;
|
||||
|
||||
return mNetif.GetIp6().HandleDatagram(aMessage, &mNetif, mNetif.GetInterfaceId(), &aMessageInfo, false);
|
||||
return netif.GetIp6().HandleDatagram(aMessage, &netif, netif.GetInterfaceId(), &aMessageInfo, false);
|
||||
}
|
||||
|
||||
void MeshForwarder::HandleDataRequest(const Mac::Address &aMacSource, const ThreadMessageInfo &aMessageInfo)
|
||||
{
|
||||
ThreadNetif &netif = GetNetif();
|
||||
Child *child;
|
||||
uint16_t indirectMsgCount;
|
||||
|
||||
// Security Check: only process secure Data Poll frames.
|
||||
VerifyOrExit(aMessageInfo.mLinkSecurity);
|
||||
|
||||
VerifyOrExit(mNetif.GetMle().GetRole() != OT_DEVICE_ROLE_DETACHED);
|
||||
VerifyOrExit(netif.GetMle().GetRole() != OT_DEVICE_ROLE_DETACHED);
|
||||
|
||||
VerifyOrExit((child = mNetif.GetMle().GetChild(aMacSource)) != NULL);
|
||||
VerifyOrExit((child = netif.GetMle().GetChild(aMacSource)) != NULL);
|
||||
child->SetLastHeard(Timer::GetNow());
|
||||
child->ResetLinkFailures();
|
||||
indirectMsgCount = child->GetIndirectMessageCount();
|
||||
@@ -2183,9 +2206,20 @@ exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void MeshForwarder::HandleDataPollTimeout(void *aContext)
|
||||
void MeshForwarder::HandleDataPollTimeout(Mac::Receiver &aReceiver)
|
||||
{
|
||||
static_cast<MeshForwarder *>(aContext)->GetDataPollManager().HandlePollTimeout();
|
||||
GetOwner(aReceiver).GetDataPollManager().HandlePollTimeout();
|
||||
}
|
||||
|
||||
MeshForwarder &MeshForwarder::GetOwner(const Context &aContext)
|
||||
{
|
||||
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
|
||||
MeshForwarder &meshForwader = *static_cast<MeshForwarder *>(aContext.GetContext());
|
||||
#else
|
||||
MeshForwarder &meshForwader = otGetMeshForwarder();
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
#endif
|
||||
return meshForwader;
|
||||
}
|
||||
|
||||
#if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_MAC == 1)
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <openthread/types.h>
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
#include "common/locator.hpp"
|
||||
#include "common/tasklet.hpp"
|
||||
#include "mac/mac.hpp"
|
||||
#include "net/ip6.hpp"
|
||||
@@ -70,7 +71,7 @@ struct ThreadMessageInfo;
|
||||
* This class implements mesh forwarding within Thread.
|
||||
*
|
||||
*/
|
||||
class MeshForwarder
|
||||
class MeshForwarder: public ThreadNetifLocator
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -81,14 +82,6 @@ public:
|
||||
*/
|
||||
explicit MeshForwarder(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 enables mesh forwarding and the IEEE 802.15.4 MAC layer.
|
||||
*
|
||||
@@ -171,13 +164,6 @@ public:
|
||||
*/
|
||||
void UpdateIndirectMessages(void);
|
||||
|
||||
/**
|
||||
* This method returns a reference to the thread network interface instance.
|
||||
*
|
||||
* @ returns A reference to the thread network interface instance.
|
||||
*/
|
||||
ThreadNetif &GetNetif(void) { return mNetif; }
|
||||
|
||||
/**
|
||||
* This method returns a reference to the send queue.
|
||||
*
|
||||
@@ -285,30 +271,29 @@ private:
|
||||
const Mac::Address &aMacSource);
|
||||
void ClearReassemblyList(void);
|
||||
|
||||
static void HandleReceivedFrame(void *aContext, Mac::Frame &aFrame);
|
||||
static void HandleReceivedFrame(Mac::Receiver &aReceiver, Mac::Frame &aFrame);
|
||||
void HandleReceivedFrame(Mac::Frame &aFrame);
|
||||
static otError HandleFrameRequest(void *aContext, Mac::Frame &aFrame);
|
||||
static otError HandleFrameRequest(Mac::Sender &aSender, Mac::Frame &aFrame);
|
||||
otError HandleFrameRequest(Mac::Frame &aFrame);
|
||||
static void HandleSentFrame(void *aContext, Mac::Frame &aFrame, otError aError);
|
||||
static void HandleSentFrame(Mac::Sender &aSender, Mac::Frame &aFrame, otError aError);
|
||||
void HandleSentFrame(Mac::Frame &aFrame, otError aError);
|
||||
static void HandleDiscoverTimer(void *aContext);
|
||||
static void HandleDiscoverTimer(Timer &aTimer);
|
||||
void HandleDiscoverTimer(void);
|
||||
static void HandleReassemblyTimer(void *aContext);
|
||||
static void HandleReassemblyTimer(Timer &aTimer);
|
||||
void HandleReassemblyTimer(void);
|
||||
static void ScheduleTransmissionTask(void *aContext);
|
||||
static void ScheduleTransmissionTask(Tasklet &aTasklet);
|
||||
void ScheduleTransmissionTask(void);
|
||||
static void HandleDataPollTimeout(void *aContext);
|
||||
static void HandleDataPollTimeout(Mac::Receiver &aReceiver);
|
||||
|
||||
otError AddPendingSrcMatchEntries(void);
|
||||
otError AddSrcMatchEntry(Child &aChild);
|
||||
void ClearSrcMatchEntry(Child &aChild);
|
||||
|
||||
static MeshForwarder &GetOwner(const Context &aContext);
|
||||
|
||||
void LogIp6Message(MessageAction aAction, const Message &aMessage, const Mac::Address *aMacAddress,
|
||||
otError aError);
|
||||
|
||||
|
||||
ThreadNetif &mNetif;
|
||||
|
||||
Mac::Receiver mMacReceiver;
|
||||
Mac::Sender mMacSender;
|
||||
Timer mDiscoverTimer;
|
||||
|
||||
+256
-213
File diff suppressed because it is too large
Load Diff
+7
-14
@@ -37,6 +37,7 @@
|
||||
#include <openthread/openthread.h>
|
||||
|
||||
#include "common/encoding.hpp"
|
||||
#include "common/locator.hpp"
|
||||
#include "common/timer.hpp"
|
||||
#include "mac/mac.hpp"
|
||||
#include "meshcop/joiner_router.hpp"
|
||||
@@ -446,7 +447,7 @@ private:
|
||||
* This class implements MLE functionality required by the Thread EndDevices, Router, and Leader roles.
|
||||
*
|
||||
*/
|
||||
class Mle
|
||||
class Mle: public ThreadNetifLocator
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -457,14 +458,6 @@ public:
|
||||
*/
|
||||
explicit Mle(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 enables MLE.
|
||||
*
|
||||
@@ -1319,8 +1312,6 @@ protected:
|
||||
*/
|
||||
otError AddDelayedResponse(Message &aMessage, const Ip6::Address &aDestination, uint16_t aDelay);
|
||||
|
||||
ThreadNetif &mNetif; ///< The Thread Network Interface object.
|
||||
|
||||
LeaderDataTlv mLeaderData; ///< Last received Leader Data TLV.
|
||||
bool mRetrieveNewNetworkData; ///< Indicating new Network Data is needed if set.
|
||||
|
||||
@@ -1380,13 +1371,13 @@ private:
|
||||
|
||||
static void HandleNetifStateChanged(uint32_t aFlags, void *aContext);
|
||||
void HandleNetifStateChanged(uint32_t aFlags);
|
||||
static void HandleParentRequestTimer(void *aContext);
|
||||
static void HandleParentRequestTimer(Timer &aTimer);
|
||||
void HandleParentRequestTimer(void);
|
||||
static void HandleDelayedResponseTimer(void *aContext);
|
||||
static void HandleDelayedResponseTimer(Timer &aTimer);
|
||||
void HandleDelayedResponseTimer(void);
|
||||
static void HandleUdpReceive(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo);
|
||||
void HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
static void HandleSendChildUpdateRequest(void *aContext);
|
||||
static void HandleSendChildUpdateRequest(Tasklet &aTasklet);
|
||||
void HandleSendChildUpdateRequest(void);
|
||||
|
||||
otError HandleAdvertisement(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
@@ -1407,6 +1398,8 @@ private:
|
||||
bool IsBetterParent(uint16_t aRloc16, uint8_t aLinkQuality, ConnectivityTlv &aConnectivityTlv);
|
||||
void ResetParentCandidate(void);
|
||||
|
||||
static Mle &GetOwner(const Context &aContext);
|
||||
|
||||
MessageQueue mDelayedResponses;
|
||||
|
||||
struct
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user