[instance] define ot::Instance class (#2307)

This commit makes the following changes: It defines the public
`otInstance` as an empty opaque structure which is used by all public
C OpenThread APIs. It defines a new class `ot::Instance` (inheriting
from `otInstance) which is then used in core source files. The
functionality related to the instance is also moved/added into the
newly added `Instance` class (as class/static or member methods).
This commit is contained in:
Abtin Keshavarzian
2017-11-13 08:27:57 -08:00
committed by Jonathan Hui
parent a394155372
commit 02c876ef62
174 changed files with 1903 additions and 1137 deletions
@@ -49,6 +49,8 @@
..\..\include; ..\..\include;
..\..\src; ..\..\src;
..\..\src\core; ..\..\src\core;
..\..\third_party\mbedtls;
..\..\third_party\mbedtls\repo.patched\include;
</AdditionalIncludeDirectories> </AdditionalIncludeDirectories>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
+2
View File
@@ -77,6 +77,7 @@
<ClCompile Include="..\..\src\core\coap\coap_header.cpp" /> <ClCompile Include="..\..\src\core\coap\coap_header.cpp" />
<ClCompile Include="..\..\src\core\coap\coap_secure.cpp" /> <ClCompile Include="..\..\src\core\coap\coap_secure.cpp" />
<ClCompile Include="..\..\src\core\common\crc16.cpp" /> <ClCompile Include="..\..\src\core\common\crc16.cpp" />
<ClCompile Include="..\..\src\core\common\instance.cpp" />
<ClCompile Include="..\..\src\core\common\locator.cpp" /> <ClCompile Include="..\..\src\core\common\locator.cpp" />
<ClCompile Include="..\..\src\core\common\logging.cpp" /> <ClCompile Include="..\..\src\core\common\logging.cpp" />
<ClCompile Include="..\..\src\core\common\message.cpp" /> <ClCompile Include="..\..\src\core\common\message.cpp" />
@@ -155,6 +156,7 @@
<ClInclude Include="..\..\src\core\common\context.hpp" /> <ClInclude Include="..\..\src\core\common\context.hpp" />
<ClInclude Include="..\..\src\core\common\debug.hpp" /> <ClInclude Include="..\..\src\core\common\debug.hpp" />
<ClInclude Include="..\..\src\core\common\encoding.hpp" /> <ClInclude Include="..\..\src\core\common\encoding.hpp" />
<ClInclude Include="..\..\src\core\common\instance.hpp" />
<ClInclude Include="..\..\src\core\common\locator.hpp" /> <ClInclude Include="..\..\src\core\common\locator.hpp" />
<ClInclude Include="..\..\src\core\common\logging.hpp" /> <ClInclude Include="..\..\src\core\common\logging.hpp" />
<ClInclude Include="..\..\src\core\common\message.hpp" /> <ClInclude Include="..\..\src\core\common\message.hpp" />
@@ -129,6 +129,9 @@
<ClCompile Include="..\..\src\core\coap\coap_secure.cpp"> <ClCompile Include="..\..\src\core\coap\coap_secure.cpp">
<Filter>Source Files\coap</Filter> <Filter>Source Files\coap</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\core\common\instance.cpp">
<Filter>Source Files\common</Filter>
</ClCompile>
<ClCompile Include="..\..\src\core\common\locator.cpp"> <ClCompile Include="..\..\src\core\common\locator.cpp">
<Filter>Source Files\common</Filter> <Filter>Source Files\common</Filter>
</ClCompile> </ClCompile>
@@ -353,6 +356,9 @@
<ClInclude Include="..\..\src\core\common\encoding.hpp"> <ClInclude Include="..\..\src\core\common\encoding.hpp">
<Filter>Header Files\common</Filter> <Filter>Header Files\common</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\core\common\instance.hpp">
<Filter>Header Files\common</Filter>
</ClInclude>
<ClInclude Include="..\..\src\core\common\locator.hpp"> <ClInclude Include="..\..\src\core\common\locator.hpp">
<Filter>Header Files\common</Filter> <Filter>Header Files\common</Filter>
</ClInclude> </ClInclude>
+2 -1
View File
@@ -86,6 +86,7 @@
<ClCompile Include="..\..\src\core\coap\coap_header.cpp" /> <ClCompile Include="..\..\src\core\coap\coap_header.cpp" />
<ClCompile Include="..\..\src\core\coap\coap_secure.cpp" /> <ClCompile Include="..\..\src\core\coap\coap_secure.cpp" />
<ClCompile Include="..\..\src\core\common\crc16.cpp" /> <ClCompile Include="..\..\src\core\common\crc16.cpp" />
<ClCompile Include="..\..\src\core\common\instance.cpp" />
<ClCompile Include="..\..\src\core\common\locator.cpp" /> <ClCompile Include="..\..\src\core\common\locator.cpp" />
<ClCompile Include="..\..\src\core\common\logging.cpp" /> <ClCompile Include="..\..\src\core\common\logging.cpp" />
<ClCompile Include="..\..\src\core\common\message.cpp" /> <ClCompile Include="..\..\src\core\common\message.cpp" />
@@ -187,6 +188,7 @@
<ClInclude Include="..\..\src\core\common\crc16.hpp" /> <ClInclude Include="..\..\src\core\common\crc16.hpp" />
<ClInclude Include="..\..\src\core\common\debug.hpp" /> <ClInclude Include="..\..\src\core\common\debug.hpp" />
<ClInclude Include="..\..\src\core\common\encoding.hpp" /> <ClInclude Include="..\..\src\core\common\encoding.hpp" />
<ClInclude Include="..\..\src\core\common\instance.hpp" />
<ClInclude Include="..\..\src\core\common\locator.hpp" /> <ClInclude Include="..\..\src\core\common\locator.hpp" />
<ClInclude Include="..\..\src\core\common\logging.hpp" /> <ClInclude Include="..\..\src\core\common\logging.hpp" />
<ClInclude Include="..\..\src\core\common\message.hpp" /> <ClInclude Include="..\..\src\core\common\message.hpp" />
@@ -232,7 +234,6 @@
<ClInclude Include="..\..\src\core\net\udp6.hpp" /> <ClInclude Include="..\..\src\core\net\udp6.hpp" />
<ClInclude Include="..\..\src\core\openthread-core-config.h" /> <ClInclude Include="..\..\src\core\openthread-core-config.h" />
<ClInclude Include="..\..\src\core\openthread-core-default-config.h" /> <ClInclude Include="..\..\src\core\openthread-core-default-config.h" />
<ClInclude Include="..\..\src\core\openthread-instance.h" />
<ClInclude Include="..\..\src\core\thread\address_resolver.hpp" /> <ClInclude Include="..\..\src\core\thread\address_resolver.hpp" />
<ClInclude Include="..\..\src\core\meshcop\announce_begin_server.hpp" /> <ClInclude Include="..\..\src\core\meshcop\announce_begin_server.hpp" />
<ClInclude Include="..\..\src\core\thread\data_poll_manager.hpp" /> <ClInclude Include="..\..\src\core\thread\data_poll_manager.hpp" />
@@ -129,6 +129,9 @@
<ClCompile Include="..\..\src\core\coap\coap_secure.cpp"> <ClCompile Include="..\..\src\core\coap\coap_secure.cpp">
<Filter>Source Files\coap</Filter> <Filter>Source Files\coap</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\core\common\instance.cpp">
<Filter>Source Files\common</Filter>
</ClCompile>
<ClCompile Include="..\..\src\core\common\locator.cpp"> <ClCompile Include="..\..\src\core\common\locator.cpp">
<Filter>Source Files\common</Filter> <Filter>Source Files\common</Filter>
</ClCompile> </ClCompile>
@@ -353,6 +356,9 @@
<ClInclude Include="..\..\src\core\common\encoding.hpp"> <ClInclude Include="..\..\src\core\common\encoding.hpp">
<Filter>Header Files\common</Filter> <Filter>Header Files\common</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\core\common\instance.hpp">
<Filter>Header Files\common</Filter>
</ClInclude>
<ClInclude Include="..\..\src\core\common\locator.hpp"> <ClInclude Include="..\..\src\core\common\locator.hpp">
<Filter>Header Files\common</Filter> <Filter>Header Files\common</Filter>
</ClInclude> </ClInclude>
@@ -569,9 +575,6 @@
<ClInclude Include="..\..\src\core\openthread-core-default-config.h"> <ClInclude Include="..\..\src\core\openthread-core-default-config.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\core\openthread-instance.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\include\openthread\types.h"> <ClInclude Include="..\..\include\openthread\types.h">
<Filter>Header Files\openthread</Filter> <Filter>Header Files\openthread</Filter>
</ClInclude> </ClInclude>
-3
View File
@@ -43,9 +43,6 @@
#include "board/board.h" #include "board/board.h"
// Global OpenThread instance structure
extern otInstance *sInstance;
/** /**
* This function initializes the alarm service used by OpenThread. * This function initializes the alarm service used by OpenThread.
* *
-2
View File
@@ -55,8 +55,6 @@ void PlatformInit(int argc, char *argv[])
void PlatformProcessDrivers(otInstance *aInstance) void PlatformProcessDrivers(otInstance *aInstance)
{ {
// sInstance = aInstance;
emskUartProcess(); emskUartProcess();
emskRadioProcess(aInstance); emskRadioProcess(aInstance);
emskAlarmProcess(aInstance); emskAlarmProcess(aInstance);
+14 -5
View File
@@ -68,15 +68,24 @@ otError otPlatRandomGetTrue(uint8_t *aOutput, uint16_t aOutputLength)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
uint8_t channel = 0; uint8_t channel = 0;
otInstance *aInstance = NULL;
otEXPECT_ACTION(aOutput && aOutputLength, error = OT_ERROR_INVALID_ARGS); otEXPECT_ACTION(aOutput && aOutputLength, error = OT_ERROR_INVALID_ARGS);
// TODO: `otPlatRandomGet()` and `otPlatRandomGetTrue()` should include a pointer to the
// owning OpenThread Instance as an input argument (similar to other platform APIs).
//
// The platform implementation requires to know the OpenThread instance to be able to
// use other radio platform APIs. However, the emsk platform implementation of radio API
// does not actually use the passed-in instance argument. Till the above TODO is done, as
// a workaround, a NULL `aInstance` is used instead.
/* disable radio*/ /* disable radio*/
if (otPlatRadioIsEnabled(sInstance)) if (otPlatRadioIsEnabled(aInstance))
{ {
channel = (mrf24j40_read_long_ctrl_reg(MRF24J40_RFCON0) >> 4) + 11; channel = (mrf24j40_read_long_ctrl_reg(MRF24J40_RFCON0) >> 4) + 11;
otPlatRadioSleep(sInstance); otPlatRadioSleep(aInstance);
otPlatRadioDisable(sInstance); otPlatRadioDisable(aInstance);
} }
/* /*
@@ -97,8 +106,8 @@ otError otPlatRandomGetTrue(uint8_t *aOutput, uint16_t aOutputLength)
if (channel) if (channel)
{ {
emskRadioInit(); emskRadioInit();
otPlatRadioEnable(sInstance); otPlatRadioEnable(aInstance);
otPlatRadioReceive(sInstance, channel); otPlatRadioReceive(aInstance, channel);
} }
exit: exit:
+12 -15
View File
@@ -120,7 +120,7 @@ OTAPI otDeviceList *OTCALL otEnumerateDevices(otApiInstance *aApiInstance);
* @param[in] aApiInstance The OpenThread api instance. * @param[in] aApiInstance The OpenThread api instance.
* @param[in] aDeviceGuid The device guid to create an OpenThread context for. * @param[in] aDeviceGuid The device guid to create an OpenThread context for.
* *
* @retval otInstance* The new OpenThread device instance structure for the device. * @returns The new OpenThread device instance structure for the device.
* *
* @sa otFreeMemory * @sa otFreeMemory
* *
@@ -132,7 +132,7 @@ OTAPI otInstance *OTCALL otInstanceInit(otApiInstance *aApiInstance, const GUID
* *
* @param[in] aContext The OpenThread context structure. * @param[in] aContext The OpenThread context structure.
* *
* @retval GUID The device GUID. * @returns The device GUID.
* *
*/ */
OTAPI GUID OTCALL otGetDeviceGuid(otInstance *aInstance); OTAPI GUID OTCALL otGetDeviceGuid(otInstance *aInstance);
@@ -142,7 +142,7 @@ OTAPI GUID OTCALL otGetDeviceGuid(otInstance *aInstance);
* *
* @param[in] aContext The OpenThread context structure. * @param[in] aContext The OpenThread context structure.
* *
* @retval uint32_t The device IfIndex. * @returns The device IfIndex.
* *
*/ */
OTAPI uint32_t OTCALL otGetDeviceIfIndex(otInstance *aInstance); OTAPI uint32_t OTCALL otGetDeviceIfIndex(otInstance *aInstance);
@@ -152,7 +152,7 @@ OTAPI uint32_t OTCALL otGetDeviceIfIndex(otInstance *aInstance);
* *
* @param[in] aContext The OpenThread context structure. * @param[in] aContext The OpenThread context structure.
* *
* @retval uint32_t The compartment ID. * @returns The compartment ID.
* *
*/ */
OTAPI uint32_t OTCALL otGetCompartmentId(otInstance *aInstance); OTAPI uint32_t OTCALL otGetCompartmentId(otInstance *aInstance);
@@ -162,9 +162,8 @@ OTAPI uint32_t OTCALL otGetCompartmentId(otInstance *aInstance);
/** /**
* This function initializes the OpenThread library. * This function initializes the OpenThread library.
* *
*
* This function initializes OpenThread and prepares it for subsequent OpenThread API calls. This function must be * 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. * called before any other calls to OpenThread.
* *
* This function is available and can only be used when support for multiple OpenThread instances is enabled. * This function is available and can only be used when support for multiple OpenThread instances is enabled.
* *
@@ -172,9 +171,9 @@ OTAPI uint32_t OTCALL otGetCompartmentId(otInstance *aInstance);
* @param[inout] aInstanceBufferSize On input, the size of aInstanceBuffer. On output, if not enough space for * @param[inout] aInstanceBufferSize On input, the size of aInstanceBuffer. On output, if not enough space for
* otInstance, the number of bytes required for otInstance. * otInstance, the number of bytes required for otInstance.
* *
* @retval otInstance* The new OpenThread instance structure. * @returns A pointer to the new OpenThread instance.
* *
* @sa otContextFinalize * @sa otInstanceFinalize
* *
*/ */
otInstance *otInstanceInit(void *aInstanceBuffer, size_t *aInstanceBufferSize); otInstance *otInstanceInit(void *aInstanceBuffer, size_t *aInstanceBufferSize);
@@ -183,11 +182,11 @@ otInstance *otInstanceInit(void *aInstanceBuffer, size_t *aInstanceBufferSize);
* This function initializes the static single 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 * 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. * called before any other calls to OpenThread.
* *
* This function is available and can only be used when support for multiple OpenThread instances is disabled. * This function is available and can only be used when support for multiple OpenThread instances is disabled.
* *
* @retval A pointer to the single OpenThread instance structure. * @returns A pointer to the single OpenThread instance.
* *
*/ */
otInstance *otInstanceInitSingle(void); otInstance *otInstanceInitSingle(void);
@@ -195,11 +194,9 @@ otInstance *otInstanceInitSingle(void);
/** /**
* This function indicates whether or not the instance is valid/initialized. * This function indicates whether or not the instance is valid/initialized.
* *
* For single-instance case, the instance is considered valid if it is acquired and initialized using * The instance is considered valid if it is acquired and initialized using either `otInstanceInitSingle()` (in single
* `otInstanceInitSingle()`. A subsequent call to `otInstanceFinalize()` causes the instance to be considered as * instance case) or `otInstanceInit()` (in multi instance case). A subsequent call to `otInstanceFinalize()` causes
* invalid (not initialized). * the instance to be considered as uninitialized.
*
* For multi-instance case, any non-NULL instance pointer is considered as valid/initialized.
* *
* @param[in] aInstance A pointer to an OpenThread instance. * @param[in] aInstance A pointer to an OpenThread instance.
* *
+5 -5
View File
@@ -31,14 +31,14 @@ include $(abs_top_nlbuild_autotools_dir)/automake/pre.am
#---------------------------------------- #----------------------------------------
# #
# This library on the face of it, appears to be identical # This library on the face of it, appears to be identical
# for both the MTD and FTD varients, however ... # for both the MTD and FTD variants, however ...
# #
# The source code here includes numerous OpenThread internal headers. # The source code here includes numerous OpenThread internal headers.
# Due to the "domino-effect" other internal headers are included. # Due to the "domino-effect" other internal headers are included.
# #
# For example: # For example:
# cli.cpp includes: # cli.cpp includes:
# src/core/openthread-instance.h # src/core/common/instance.hpp
# Which Includes: # Which Includes:
# src/core/therad/thread_netif.hpp # src/core/therad/thread_netif.hpp
# Which Includes: # Which Includes:
@@ -51,8 +51,8 @@ include $(abs_top_nlbuild_autotools_dir)/automake/pre.am
# The FTD flavor has many private components (class variables). # The FTD flavor has many private components (class variables).
# The MTD flavor has no private components. # The MTD flavor has no private components.
# #
# Bottom line: The Class(structs) are thus different in the downstream # Bottom line: The Class(structs) are thus different in the downstream
# libs. At this level (in the CLI, and likewise in the NCP) they are # libs. At this level (in the CLI, and likewise in the NCP) they are
# functionally identical. # functionally identical.
# #
# ORIGINALLY (historical note about how things are/where built): # ORIGINALLY (historical note about how things are/where built):
+1 -2
View File
@@ -66,7 +66,6 @@
#include <openthread/icmp6.h> #include <openthread/icmp6.h>
#include <openthread/platform/uart.h> #include <openthread/platform/uart.h>
#include "openthread-instance.h"
#include "common/new.hpp" #include "common/new.hpp"
#include "net/ip6.hpp" #include "net/ip6.hpp"
#endif #endif
@@ -252,7 +251,7 @@ typedef otPtr<const otNetifAddress> otNetifAddressPtr;
typedef otPtr<const uint8_t> otBufferPtr; typedef otPtr<const uint8_t> otBufferPtr;
typedef otPtr<const char> otStringPtr; typedef otPtr<const char> otStringPtr;
Interpreter::Interpreter(otInstance *aInstance): Interpreter::Interpreter(Instance *aInstance):
#if OPENTHREAD_ENABLE_APPLICATION_COAP #if OPENTHREAD_ENABLE_APPLICATION_COAP
mCoap(*this), mCoap(*this),
#endif #endif
+4 -3
View File
@@ -53,6 +53,7 @@
#include "common/code_utils.hpp" #include "common/code_utils.hpp"
#include "common/context.hpp" #include "common/context.hpp"
#include "common/instance.hpp"
#ifndef OTDLL #ifndef OTDLL
#include <openthread/dhcp6_client.h> #include <openthread/dhcp6_client.h>
@@ -104,7 +105,7 @@ public:
* *
* @param[in] aInstance The OpenThread instance structure. * @param[in] aInstance The OpenThread instance structure.
*/ */
Interpreter(otInstance *aInstance); Interpreter(Instance *aInstance);
/** /**
* This method interprets a CLI command. * This method interprets a CLI command.
@@ -396,7 +397,7 @@ private:
struct otCliContext struct otCliContext
{ {
Interpreter *mInterpreter; Interpreter *mInterpreter;
otInstance *mInstance; Instance *mInstance;
}; };
otCliContext mInstances[MAX_CLI_OT_INSTANCES]; otCliContext mInstances[MAX_CLI_OT_INSTANCES];
uint8_t mInstancesLength; uint8_t mInstancesLength;
@@ -426,7 +427,7 @@ private:
#endif #endif
otInstance *mInstance; Instance *mInstance;
}; };
} // namespace Cli } // namespace Cli
+5 -2
View File
@@ -39,6 +39,7 @@
#include "utils/wrap_string.h" #include "utils/wrap_string.h"
#include "cli/cli.hpp" #include "cli/cli.hpp"
#include "common/instance.hpp"
#include "common/new.hpp" #include "common/new.hpp"
namespace ot { namespace ot {
@@ -50,7 +51,9 @@ static otDEFINE_ALIGNED_VAR(sCliConsoleRaw, sizeof(Console), uint64_t);
extern "C" void otCliConsoleInit(otInstance *aInstance, otCliConsoleOutputCallback aCallback, void *aContext) extern "C" void otCliConsoleInit(otInstance *aInstance, otCliConsoleOutputCallback aCallback, void *aContext)
{ {
sServer = new(&sCliConsoleRaw) Console(aInstance); Instance *instance = static_cast<Instance *>(aInstance);
sServer = new(&sCliConsoleRaw) Console(instance);
sServer->SetOutputCallback(aCallback); sServer->SetOutputCallback(aCallback);
sServer->SetContext(aContext); sServer->SetContext(aContext);
} }
@@ -60,7 +63,7 @@ extern "C" void otCliConsoleInputLine(char *aBuf, uint16_t aBufLength)
sServer->ReceiveTask(aBuf, aBufLength); sServer->ReceiveTask(aBuf, aBufLength);
} }
Console::Console(otInstance *aInstance): Console::Console(Instance *aInstance):
mCallback(NULL), mCallback(NULL),
mContext(NULL), mContext(NULL),
mInterpreter(aInstance) mInterpreter(aInstance)
+1 -1
View File
@@ -57,7 +57,7 @@ public:
* @param[in] aInstance The OpenThread instance structure. * @param[in] aInstance The OpenThread instance structure.
* *
*/ */
Console(otInstance *aInstance); Console(Instance *aInstance);
/** /**
* This method delivers raw characters to the client. * This method delivers raw characters to the client.
+1 -1
View File
@@ -61,7 +61,7 @@ void Interpreter::CacheInstances()
for (uint8_t i = 0; i < mInstancesLength; i++) for (uint8_t i = 0; i < mInstancesLength; i++)
{ {
mInstances[i].mInterpreter = this; mInstances[i].mInterpreter = this;
mInstances[i].mInstance = otInstanceInit(mApiInstance, &aDeviceList->aDevices[i]); mInstances[i].mInstance = static_cast<Instance *>(otInstanceInit(mApiInstance, &aDeviceList->aDevices[i]));
assert(mInstances[i].mInstance); assert(mInstances[i].mInstance);
otSetStateChangedCallback(mInstances[i].mInstance, &Interpreter::s_HandleNetifStateChanged, &mInstances[i]); otSetStateChangedCallback(mInstances[i].mInstance, &Interpreter::s_HandleNetifStateChanged, &mInstances[i]);
} }
+6 -4
View File
@@ -64,7 +64,9 @@ static otDEFINE_ALIGNED_VAR(sCliUartRaw, sizeof(Uart), uint64_t);
extern "C" void otCliUartInit(otInstance *aInstance) extern "C" void otCliUartInit(otInstance *aInstance)
{ {
Uart::sUartServer = new(&sCliUartRaw) Uart(aInstance); Instance *instance = static_cast<Instance *>(aInstance);
Uart::sUartServer = new(&sCliUartRaw) Uart(instance);
} }
extern "C" void otCliUartSetUserCommands(const otCliCommand *aUserCommands, uint8_t aLength) extern "C" void otCliUartSetUserCommands(const otCliCommand *aUserCommands, uint8_t aLength)
@@ -90,7 +92,7 @@ extern "C" void otCliUartAppendResult(otError aError)
Uart::sUartServer->GetInterpreter().AppendResult(aError); Uart::sUartServer->GetInterpreter().AppendResult(aError);
} }
Uart::Uart(otInstance *aInstance): Uart::Uart(Instance *aInstance):
mInterpreter(aInstance) mInterpreter(aInstance)
{ {
mRxLength = 0; mRxLength = 0;
@@ -193,13 +195,13 @@ otError Uart::ProcessCommand(void)
* *
* Yes, while rare it is a race condition that is hard to debug. * Yes, while rare it is a race condition that is hard to debug.
* *
* Thus this is here to afirmatively LOG exactly when the CLI * Thus this is here to affirmatively LOG exactly when the CLI
* command is being executed. * command is being executed.
*/ */
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
/* TODO: how exactly do we get the instance here? */ /* TODO: how exactly do we get the instance here? */
#else #else
otLogInfoCli(otGetInstance(), "execute command: %s", mRxBuffer); otLogInfoCli(&Instance::Get(), "execute command: %s", mRxBuffer);
#endif #endif
#endif #endif
mInterpreter.ProcessLine(mRxBuffer, mRxLength, *this); mInterpreter.ProcessLine(mRxBuffer, mRxLength, *this);
+3 -1
View File
@@ -40,8 +40,10 @@
#include "cli/cli.hpp" #include "cli/cli.hpp"
#include "cli/cli_server.hpp" #include "cli/cli_server.hpp"
#include "common/instance.hpp"
#include "common/tasklet.hpp" #include "common/tasklet.hpp"
namespace ot { namespace ot {
namespace Cli { namespace Cli {
@@ -58,7 +60,7 @@ public:
* @param[in] aInstance The OpenThread instance structure. * @param[in] aInstance The OpenThread instance structure.
* *
*/ */
Uart(otInstance *aInstance); Uart(Instance *aInstance);
/** /**
* This method delivers raw characters to the client. * This method delivers raw characters to the client.
+2 -2
View File
@@ -116,6 +116,7 @@ SOURCES_COMMON = \
coap/coap_header.cpp \ coap/coap_header.cpp \
coap/coap_secure.cpp \ coap/coap_secure.cpp \
common/crc16.cpp \ common/crc16.cpp \
common/instance.cpp \
common/logging.cpp \ common/logging.cpp \
common/locator.cpp \ common/locator.cpp \
common/message.cpp \ common/message.cpp \
@@ -200,8 +201,6 @@ libopenthread_ftd_a_SOURCES = \
HEADERS_COMMON = \ HEADERS_COMMON = \
openthread-core-config.h \ openthread-core-config.h \
openthread-core-default-config.h \ openthread-core-default-config.h \
openthread-instance.h \
openthread-single-instance.h \
api/link_raw.hpp \ api/link_raw.hpp \
coap/coap.hpp \ coap/coap.hpp \
coap/coap_header.hpp \ coap/coap_header.hpp \
@@ -211,6 +210,7 @@ HEADERS_COMMON = \
common/crc16.hpp \ common/crc16.hpp \
common/debug.hpp \ common/debug.hpp \
common/encoding.hpp \ common/encoding.hpp \
common/instance.hpp \
common/locator.hpp \ common/locator.hpp \
common/logging.hpp \ common/logging.hpp \
common/message.hpp \ common/message.hpp \
+27 -14
View File
@@ -37,17 +37,18 @@
#include <openthread/border_router.h> #include <openthread/border_router.h>
#include "openthread-instance.h" #include "common/instance.hpp"
using namespace ot; using namespace ot;
otError otBorderRouterGetNetData(otInstance *aInstance, bool aStable, uint8_t *aData, uint8_t *aDataLength) otError otBorderRouterGetNetData(otInstance *aInstance, bool aStable, uint8_t *aData, uint8_t *aDataLength)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aData != NULL && aDataLength != NULL, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aData != NULL && aDataLength != NULL, error = OT_ERROR_INVALID_ARGS);
error = aInstance->mThreadNetif.GetNetworkDataLocal().GetNetworkData(aStable, aData, *aDataLength); error = instance.GetThreadNetif().GetNetworkDataLocal().GetNetworkData(aStable, aData, *aDataLength);
exit: exit:
return error; return error;
@@ -56,6 +57,7 @@ exit:
otError otBorderRouterAddOnMeshPrefix(otInstance *aInstance, const otBorderRouterConfig *aConfig) otError otBorderRouterAddOnMeshPrefix(otInstance *aInstance, const otBorderRouterConfig *aConfig)
{ {
uint8_t flags = 0; uint8_t flags = 0;
Instance &instance = *static_cast<Instance *>(aInstance);
if (aConfig->mPreferred) if (aConfig->mPreferred)
{ {
@@ -87,24 +89,28 @@ otError otBorderRouterAddOnMeshPrefix(otInstance *aInstance, const otBorderRoute
flags |= NetworkData::BorderRouterEntry::kOnMeshFlag; flags |= NetworkData::BorderRouterEntry::kOnMeshFlag;
} }
return aInstance->mThreadNetif.GetNetworkDataLocal().AddOnMeshPrefix(aConfig->mPrefix.mPrefix.mFields.m8, return instance.GetThreadNetif().GetNetworkDataLocal().AddOnMeshPrefix(aConfig->mPrefix.mPrefix.mFields.m8,
aConfig->mPrefix.mLength, aConfig->mPrefix.mLength,
aConfig->mPreference, flags, aConfig->mStable); aConfig->mPreference, flags, aConfig->mStable);
} }
otError otBorderRouterRemoveOnMeshPrefix(otInstance *aInstance, const otIp6Prefix *aPrefix) otError otBorderRouterRemoveOnMeshPrefix(otInstance *aInstance, const otIp6Prefix *aPrefix)
{ {
return aInstance->mThreadNetif.GetNetworkDataLocal().RemoveOnMeshPrefix(aPrefix->mPrefix.mFields.m8, aPrefix->mLength); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetNetworkDataLocal().RemoveOnMeshPrefix(aPrefix->mPrefix.mFields.m8,
aPrefix->mLength);
} }
otError otBorderRouterGetNextOnMeshPrefix(otInstance *aInstance, otNetworkDataIterator *aIterator, otError otBorderRouterGetNextOnMeshPrefix(otInstance *aInstance, otNetworkDataIterator *aIterator,
otBorderRouterConfig *aConfig) otBorderRouterConfig *aConfig)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aIterator && aConfig, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aIterator && aConfig, error = OT_ERROR_INVALID_ARGS);
error = aInstance->mThreadNetif.GetNetworkDataLocal().GetNextOnMeshPrefix(aIterator, aConfig); error = instance.GetThreadNetif().GetNetworkDataLocal().GetNextOnMeshPrefix(aIterator, aConfig);
exit: exit:
return error; return error;
@@ -112,25 +118,30 @@ exit:
otError otBorderRouterAddRoute(otInstance *aInstance, const otExternalRouteConfig *aConfig) otError otBorderRouterAddRoute(otInstance *aInstance, const otExternalRouteConfig *aConfig)
{ {
return aInstance->mThreadNetif.GetNetworkDataLocal().AddHasRoutePrefix(aConfig->mPrefix.mPrefix.mFields.m8, Instance &instance = *static_cast<Instance *>(aInstance);
aConfig->mPrefix.mLength,
aConfig->mPreference, aConfig->mStable); return instance.GetThreadNetif().GetNetworkDataLocal().AddHasRoutePrefix(aConfig->mPrefix.mPrefix.mFields.m8,
aConfig->mPrefix.mLength,
aConfig->mPreference, aConfig->mStable);
} }
otError otBorderRouterRemoveRoute(otInstance *aInstance, const otIp6Prefix *aPrefix) otError otBorderRouterRemoveRoute(otInstance *aInstance, const otIp6Prefix *aPrefix)
{ {
return aInstance->mThreadNetif.GetNetworkDataLocal().RemoveHasRoutePrefix(aPrefix->mPrefix.mFields.m8, Instance &instance = *static_cast<Instance *>(aInstance);
aPrefix->mLength);
return instance.GetThreadNetif().GetNetworkDataLocal().RemoveHasRoutePrefix(aPrefix->mPrefix.mFields.m8,
aPrefix->mLength);
} }
otError otBorderRouterGetNextRoute(otInstance *aInstance, otNetworkDataIterator *aIterator, otError otBorderRouterGetNextRoute(otInstance *aInstance, otNetworkDataIterator *aIterator,
otExternalRouteConfig *aConfig) otExternalRouteConfig *aConfig)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aIterator && aConfig, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aIterator && aConfig, error = OT_ERROR_INVALID_ARGS);
error = aInstance->mThreadNetif.GetNetworkDataLocal().GetNextExternalRoute(aIterator, aConfig); error = instance.GetThreadNetif().GetNetworkDataLocal().GetNextExternalRoute(aIterator, aConfig);
exit: exit:
return error; return error;
@@ -138,7 +149,9 @@ exit:
otError otBorderRouterRegister(otInstance *aInstance) otError otBorderRouterRegister(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetNetworkDataLocal().SendServerDataNotification(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetNetworkDataLocal().SendServerDataNotification();
} }
#endif // OPENTHREAD_ENABLE_BORDER_ROUTER #endif // OPENTHREAD_ENABLE_BORDER_ROUTER
+13 -5
View File
@@ -34,7 +34,7 @@
#include "openthread-core-config.h" #include "openthread-core-config.h"
#include "openthread/child_supervision.h" #include "openthread/child_supervision.h"
#include "openthread-instance.h" #include "common/instance.hpp"
using namespace ot; using namespace ot;
@@ -42,22 +42,30 @@ using namespace ot;
uint16_t otChildSupervisionGetInterval(otInstance *aInstance) uint16_t otChildSupervisionGetInterval(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetChildSupervisor().GetSupervisionInterval(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetChildSupervisor().GetSupervisionInterval();
} }
void otChildSupervisionSetInterval(otInstance *aInstance, uint16_t aInterval) void otChildSupervisionSetInterval(otInstance *aInstance, uint16_t aInterval)
{ {
aInstance->mThreadNetif.GetChildSupervisor().SetSupervisionInterval(aInterval); Instance &instance = *static_cast<Instance *>(aInstance);
instance.GetThreadNetif().GetChildSupervisor().SetSupervisionInterval(aInterval);
} }
uint16_t otChildSupervisionGetCheckTimeout(otInstance *aInstance) uint16_t otChildSupervisionGetCheckTimeout(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetSupervisionListener().GetTimeout(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetSupervisionListener().GetTimeout();
} }
void otChildSupervisionSetCheckTimeout(otInstance *aInstance, uint16_t aTimeout) void otChildSupervisionSetCheckTimeout(otInstance *aInstance, uint16_t aTimeout)
{ {
aInstance->mThreadNetif.GetSupervisionListener().SetTimeout(aTimeout); Instance &instance = *static_cast<Instance *>(aInstance);
instance.GetThreadNetif().GetSupervisionListener().SetTimeout(aTimeout);
} }
#endif // OPENTHREAD_ENABLE_CHILD_SUPERVISION #endif // OPENTHREAD_ENABLE_CHILD_SUPERVISION
+25 -9
View File
@@ -35,7 +35,7 @@
#include <openthread/coap.h> #include <openthread/coap.h>
#include "openthread-instance.h" #include "common/instance.hpp"
#include "coap/coap_header.hpp" #include "coap/coap_header.hpp"
#if OPENTHREAD_ENABLE_APPLICATION_COAP #if OPENTHREAD_ENABLE_APPLICATION_COAP
@@ -141,8 +141,10 @@ const otCoapOption *otCoapHeaderGetNextOption(otCoapHeader *aHeader)
otMessage *otCoapNewMessage(otInstance *aInstance, const otCoapHeader *aHeader) otMessage *otCoapNewMessage(otInstance *aInstance, const otCoapHeader *aHeader)
{ {
Message *message; Message *message;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aHeader != NULL, message = NULL); VerifyOrExit(aHeader != NULL, message = NULL);
message = aInstance->mApplicationCoap.NewMessage(*(static_cast<const Coap::Header *>(aHeader))); message = instance.GetApplicationCoap().NewMessage(*(static_cast<const Coap::Header *>(aHeader)));
exit: exit:
return message; return message;
} }
@@ -150,7 +152,9 @@ exit:
otError otCoapSendRequest(otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo, otError otCoapSendRequest(otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo,
otCoapResponseHandler aHandler, void *aContext) otCoapResponseHandler aHandler, void *aContext)
{ {
return aInstance->mApplicationCoap.SendMessage( Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetApplicationCoap().SendMessage(
*static_cast<Message *>(aMessage), *static_cast<Message *>(aMessage),
*static_cast<const Ip6::MessageInfo *>(aMessageInfo), *static_cast<const Ip6::MessageInfo *>(aMessageInfo),
aHandler, aContext); aHandler, aContext);
@@ -158,32 +162,44 @@ otError otCoapSendRequest(otInstance *aInstance, otMessage *aMessage, const otMe
otError otCoapStart(otInstance *aInstance, uint16_t aPort) otError otCoapStart(otInstance *aInstance, uint16_t aPort)
{ {
return aInstance->mApplicationCoap.Start(aPort); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetApplicationCoap().Start(aPort);
} }
otError otCoapStop(otInstance *aInstance) otError otCoapStop(otInstance *aInstance)
{ {
return aInstance->mApplicationCoap.Stop(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetApplicationCoap().Stop();
} }
otError otCoapAddResource(otInstance *aInstance, otCoapResource *aResource) otError otCoapAddResource(otInstance *aInstance, otCoapResource *aResource)
{ {
return aInstance->mApplicationCoap.AddResource(*static_cast<Coap::Resource *>(aResource)); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetApplicationCoap().AddResource(*static_cast<Coap::Resource *>(aResource));
} }
void otCoapRemoveResource(otInstance *aInstance, otCoapResource *aResource) void otCoapRemoveResource(otInstance *aInstance, otCoapResource *aResource)
{ {
aInstance->mApplicationCoap.RemoveResource(*static_cast<Coap::Resource *>(aResource)); Instance &instance = *static_cast<Instance *>(aInstance);
instance.GetApplicationCoap().RemoveResource(*static_cast<Coap::Resource *>(aResource));
} }
void otCoapSetDefaultHandler(otInstance *aInstance, otCoapRequestHandler aHandler, void *aContext) void otCoapSetDefaultHandler(otInstance *aInstance, otCoapRequestHandler aHandler, void *aContext)
{ {
aInstance->mApplicationCoap.SetDefaultHandler(aHandler, aContext); Instance &instance = *static_cast<Instance *>(aInstance);
instance.GetApplicationCoap().SetDefaultHandler(aHandler, aContext);
} }
otError otCoapSendResponse(otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo) otError otCoapSendResponse(otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo)
{ {
return aInstance->mApplicationCoap.SendMessage( Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetApplicationCoap().SendMessage(
*static_cast<Message *>(aMessage), *static_cast<const Ip6::MessageInfo *>(aMessageInfo)); *static_cast<Message *>(aMessage), *static_cast<const Ip6::MessageInfo *>(aMessageInfo));
} }
+68 -41
View File
@@ -35,7 +35,7 @@
#include <openthread/commissioner.h> #include <openthread/commissioner.h>
#include "openthread-instance.h" #include "common/instance.hpp"
using namespace ot; using namespace ot;
@@ -44,10 +44,12 @@ otError otCommissionerStart(otInstance *aInstance)
otError error = OT_ERROR_DISABLED_FEATURE; otError error = OT_ERROR_DISABLED_FEATURE;
#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER #if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER
error = aInstance->mThreadNetif.GetCommissioner().Start(); Instance &instance = *static_cast<Instance *>(aInstance);
#else // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
error = instance.GetThreadNetif().GetCommissioner().Start();
#else
OT_UNUSED_VARIABLE(aInstance); OT_UNUSED_VARIABLE(aInstance);
#endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD #endif
return error; return error;
} }
@@ -57,10 +59,12 @@ otError otCommissionerStop(otInstance *aInstance)
otError error = OT_ERROR_DISABLED_FEATURE; otError error = OT_ERROR_DISABLED_FEATURE;
#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER #if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER
error = aInstance->mThreadNetif.GetCommissioner().Stop(); Instance &instance = *static_cast<Instance *>(aInstance);
#else // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
error = instance.GetThreadNetif().GetCommissioner().Stop();
#else
OT_UNUSED_VARIABLE(aInstance); OT_UNUSED_VARIABLE(aInstance);
#endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD #endif
return error; return error;
} }
@@ -70,15 +74,18 @@ otError otCommissionerAddJoiner(otInstance *aInstance, const otExtAddress *aEui6
{ {
otError error = OT_ERROR_DISABLED_FEATURE; otError error = OT_ERROR_DISABLED_FEATURE;
#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER #if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER
error = aInstance->mThreadNetif.GetCommissioner().AddJoiner(static_cast<const Mac::ExtAddress *>(aEui64), aPSKd, Instance &instance = *static_cast<Instance *>(aInstance);
aTimeout);
#else // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD error = instance.GetThreadNetif().GetCommissioner().AddJoiner(static_cast<const Mac::ExtAddress *>(aEui64), aPSKd,
aTimeout);
#else
OT_UNUSED_VARIABLE(aInstance); OT_UNUSED_VARIABLE(aInstance);
OT_UNUSED_VARIABLE(aEui64); OT_UNUSED_VARIABLE(aEui64);
OT_UNUSED_VARIABLE(aPSKd); OT_UNUSED_VARIABLE(aPSKd);
OT_UNUSED_VARIABLE(aTimeout); OT_UNUSED_VARIABLE(aTimeout);
#endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD #endif
return error; return error;
} }
@@ -88,11 +95,13 @@ otError otCommissionerRemoveJoiner(otInstance *aInstance, const otExtAddress *aE
otError error = OT_ERROR_DISABLED_FEATURE; otError error = OT_ERROR_DISABLED_FEATURE;
#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER #if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER
error = aInstance->mThreadNetif.GetCommissioner().RemoveJoiner(static_cast<const Mac::ExtAddress *>(aEui64), 0); Instance &instance = *static_cast<Instance *>(aInstance);
#else // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
error = instance.GetThreadNetif().GetCommissioner().RemoveJoiner(static_cast<const Mac::ExtAddress *>(aEui64), 0);
#else
OT_UNUSED_VARIABLE(aInstance); OT_UNUSED_VARIABLE(aInstance);
OT_UNUSED_VARIABLE(aEui64); OT_UNUSED_VARIABLE(aEui64);
#endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD #endif
return error; return error;
} }
@@ -102,11 +111,13 @@ otError otCommissionerSetProvisioningUrl(otInstance *aInstance, const char *aPro
otError error = OT_ERROR_DISABLED_FEATURE; otError error = OT_ERROR_DISABLED_FEATURE;
#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER #if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER
error = aInstance->mThreadNetif.GetCommissioner().SetProvisioningUrl(aProvisioningUrl); Instance &instance = *static_cast<Instance *>(aInstance);
#else // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
error = instance.GetThreadNetif().GetCommissioner().SetProvisioningUrl(aProvisioningUrl);
#else
OT_UNUSED_VARIABLE(aInstance); OT_UNUSED_VARIABLE(aInstance);
OT_UNUSED_VARIABLE(aProvisioningUrl); OT_UNUSED_VARIABLE(aProvisioningUrl);
#endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD #endif
return error; return error;
} }
@@ -117,15 +128,17 @@ otError otCommissionerAnnounceBegin(otInstance *aInstance, uint32_t aChannelMask
otError error = OT_ERROR_DISABLED_FEATURE; otError error = OT_ERROR_DISABLED_FEATURE;
#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER #if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER
error = aInstance->mThreadNetif.GetCommissioner().GetAnnounceBeginClient().SendRequest( Instance &instance = *static_cast<Instance *>(aInstance);
error = instance.GetThreadNetif().GetCommissioner().GetAnnounceBeginClient().SendRequest(
aChannelMask, aCount, aPeriod, *static_cast<const Ip6::Address *>(aAddress)); aChannelMask, aCount, aPeriod, *static_cast<const Ip6::Address *>(aAddress));
#else // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD #else
OT_UNUSED_VARIABLE(aInstance); OT_UNUSED_VARIABLE(aInstance);
OT_UNUSED_VARIABLE(aChannelMask); OT_UNUSED_VARIABLE(aChannelMask);
OT_UNUSED_VARIABLE(aCount); OT_UNUSED_VARIABLE(aCount);
OT_UNUSED_VARIABLE(aPeriod); OT_UNUSED_VARIABLE(aPeriod);
OT_UNUSED_VARIABLE(aAddress); OT_UNUSED_VARIABLE(aAddress);
#endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD #endif
return error; return error;
} }
@@ -137,10 +150,12 @@ otError otCommissionerEnergyScan(otInstance *aInstance, uint32_t aChannelMask, u
otError error = OT_ERROR_DISABLED_FEATURE; otError error = OT_ERROR_DISABLED_FEATURE;
#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER #if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER
error = aInstance->mThreadNetif.GetCommissioner().GetEnergyScanClient().SendQuery( Instance &instance = *static_cast<Instance *>(aInstance);
error = instance.GetThreadNetif().GetCommissioner().GetEnergyScanClient().SendQuery(
aChannelMask, aCount, aPeriod, aScanDuration, *static_cast<const Ip6::Address *>(aAddress), aChannelMask, aCount, aPeriod, aScanDuration, *static_cast<const Ip6::Address *>(aAddress),
aCallback, aContext); aCallback, aContext);
#else // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD #else
OT_UNUSED_VARIABLE(aInstance); OT_UNUSED_VARIABLE(aInstance);
OT_UNUSED_VARIABLE(aChannelMask); OT_UNUSED_VARIABLE(aChannelMask);
OT_UNUSED_VARIABLE(aCount); OT_UNUSED_VARIABLE(aCount);
@@ -149,7 +164,7 @@ otError otCommissionerEnergyScan(otInstance *aInstance, uint32_t aChannelMask, u
OT_UNUSED_VARIABLE(aAddress); OT_UNUSED_VARIABLE(aAddress);
OT_UNUSED_VARIABLE(aCallback); OT_UNUSED_VARIABLE(aCallback);
OT_UNUSED_VARIABLE(aContext); OT_UNUSED_VARIABLE(aContext);
#endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD #endif
return error; return error;
} }
@@ -161,16 +176,18 @@ otError otCommissionerPanIdQuery(otInstance *aInstance, uint16_t aPanId, uint32_
otError error = OT_ERROR_DISABLED_FEATURE; otError error = OT_ERROR_DISABLED_FEATURE;
#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER #if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER
error = aInstance->mThreadNetif.GetCommissioner().GetPanIdQueryClient().SendQuery( Instance &instance = *static_cast<Instance *>(aInstance);
error = instance.GetThreadNetif().GetCommissioner().GetPanIdQueryClient().SendQuery(
aPanId, aChannelMask, *static_cast<const Ip6::Address *>(aAddress), aCallback, aContext); aPanId, aChannelMask, *static_cast<const Ip6::Address *>(aAddress), aCallback, aContext);
#else // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD #else
OT_UNUSED_VARIABLE(aInstance); OT_UNUSED_VARIABLE(aInstance);
OT_UNUSED_VARIABLE(aPanId); OT_UNUSED_VARIABLE(aPanId);
OT_UNUSED_VARIABLE(aChannelMask); OT_UNUSED_VARIABLE(aChannelMask);
OT_UNUSED_VARIABLE(aAddress); OT_UNUSED_VARIABLE(aAddress);
OT_UNUSED_VARIABLE(aCallback); OT_UNUSED_VARIABLE(aCallback);
OT_UNUSED_VARIABLE(aContext); OT_UNUSED_VARIABLE(aContext);
#endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD #endif
return error; return error;
} }
@@ -180,12 +197,14 @@ otError otCommissionerSendMgmtGet(otInstance *aInstance, const uint8_t *aTlvs, u
otError error = OT_ERROR_DISABLED_FEATURE; otError error = OT_ERROR_DISABLED_FEATURE;
#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER #if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER
error = aInstance->mThreadNetif.GetCommissioner().SendMgmtCommissionerGetRequest(aTlvs, aLength); Instance &instance = *static_cast<Instance *>(aInstance);
#else // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
error = instance.GetThreadNetif().GetCommissioner().SendMgmtCommissionerGetRequest(aTlvs, aLength);
#else
OT_UNUSED_VARIABLE(aInstance); OT_UNUSED_VARIABLE(aInstance);
OT_UNUSED_VARIABLE(aTlvs); OT_UNUSED_VARIABLE(aTlvs);
OT_UNUSED_VARIABLE(aLength); OT_UNUSED_VARIABLE(aLength);
#endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD #endif
return error; return error;
} }
@@ -196,13 +215,15 @@ otError otCommissionerSendMgmtSet(otInstance *aInstance, const otCommissioningDa
otError error = OT_ERROR_DISABLED_FEATURE; otError error = OT_ERROR_DISABLED_FEATURE;
#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER #if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER
error = aInstance->mThreadNetif.GetCommissioner().SendMgmtCommissionerSetRequest(*aDataset, aTlvs, aLength); Instance &instance = *static_cast<Instance *>(aInstance);
#else // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
error = instance.GetThreadNetif().GetCommissioner().SendMgmtCommissionerSetRequest(*aDataset, aTlvs, aLength);
#else
OT_UNUSED_VARIABLE(aInstance); OT_UNUSED_VARIABLE(aInstance);
OT_UNUSED_VARIABLE(aDataset); OT_UNUSED_VARIABLE(aDataset);
OT_UNUSED_VARIABLE(aTlvs); OT_UNUSED_VARIABLE(aTlvs);
OT_UNUSED_VARIABLE(aLength); OT_UNUSED_VARIABLE(aLength);
#endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD #endif
return error; return error;
} }
@@ -212,10 +233,12 @@ uint16_t otCommissionerGetSessionId(otInstance *aInstance)
uint16_t sessionId = 0; uint16_t sessionId = 0;
#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER #if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER
sessionId = aInstance->mThreadNetif.GetCommissioner().GetSessionId(); Instance &instance = *static_cast<Instance *>(aInstance);
#else // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
sessionId = instance.GetThreadNetif().GetCommissioner().GetSessionId();
#else
OT_UNUSED_VARIABLE(aInstance); OT_UNUSED_VARIABLE(aInstance);
#endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD #endif
return sessionId; return sessionId;
} }
@@ -225,10 +248,12 @@ otCommissionerState otCommissionerGetState(otInstance *aInstance)
otCommissionerState state = OT_COMMISSIONER_STATE_DISABLED; otCommissionerState state = OT_COMMISSIONER_STATE_DISABLED;
#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER #if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER
state = aInstance->mThreadNetif.GetCommissioner().GetState(); Instance &instance = *static_cast<Instance *>(aInstance);
#else // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
state = instance.GetThreadNetif().GetCommissioner().GetState();
#else
OT_UNUSED_VARIABLE(aInstance); OT_UNUSED_VARIABLE(aInstance);
#endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD #endif
return state; return state;
} }
@@ -239,14 +264,16 @@ otError otCommissionerGeneratePSKc(otInstance *aInstance, const char *aPassPhras
otError error = OT_ERROR_DISABLED_FEATURE; otError error = OT_ERROR_DISABLED_FEATURE;
#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER #if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER
error = aInstance->mThreadNetif.GetCommissioner().GeneratePSKc(aPassPhrase, aNetworkName, aExtPanId, aPSKc); Instance &instance = *static_cast<Instance *>(aInstance);
#else // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD
error = instance.GetThreadNetif().GetCommissioner().GeneratePSKc(aPassPhrase, aNetworkName, aExtPanId, aPSKc);
#else
OT_UNUSED_VARIABLE(aInstance); OT_UNUSED_VARIABLE(aInstance);
OT_UNUSED_VARIABLE(aPassPhrase); OT_UNUSED_VARIABLE(aPassPhrase);
OT_UNUSED_VARIABLE(aNetworkName); OT_UNUSED_VARIABLE(aNetworkName);
OT_UNUSED_VARIABLE(aExtPanId); OT_UNUSED_VARIABLE(aExtPanId);
OT_UNUSED_VARIABLE(aPSKc); OT_UNUSED_VARIABLE(aPSKc);
#endif // OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD #endif
return error; return error;
} }
+5 -3
View File
@@ -35,7 +35,7 @@
#include <openthread/dataset.h> #include <openthread/dataset.h>
#include "openthread-instance.h" #include "common/instance.hpp"
using namespace ot; using namespace ot;
@@ -57,10 +57,11 @@ bool otDatasetIsCommissioned(otInstance *aInstance)
otError otDatasetGetActive(otInstance *aInstance, otOperationalDataset *aDataset) otError otDatasetGetActive(otInstance *aInstance, otOperationalDataset *aDataset)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aDataset != NULL, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aDataset != NULL, error = OT_ERROR_INVALID_ARGS);
error = aInstance->mThreadNetif.GetActiveDataset().GetLocal().Get(*aDataset); error = instance.GetThreadNetif().GetActiveDataset().GetLocal().Get(*aDataset);
exit: exit:
return error; return error;
@@ -69,10 +70,11 @@ exit:
otError otDatasetGetPending(otInstance *aInstance, otOperationalDataset *aDataset) otError otDatasetGetPending(otInstance *aInstance, otOperationalDataset *aDataset)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aDataset != NULL, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aDataset != NULL, error = OT_ERROR_INVALID_ARGS);
error = aInstance->mThreadNetif.GetPendingDataset().GetLocal().Get(*aDataset); error = instance.GetThreadNetif().GetPendingDataset().GetLocal().Get(*aDataset);
exit: exit:
return error; return error;
+23 -9
View File
@@ -37,17 +37,18 @@
#include <openthread/dataset_ftd.h> #include <openthread/dataset_ftd.h>
#include "openthread-instance.h" #include "common/instance.hpp"
using namespace ot; using namespace ot;
otError otDatasetSetActive(otInstance *aInstance, const otOperationalDataset *aDataset) otError otDatasetSetActive(otInstance *aInstance, const otOperationalDataset *aDataset)
{ {
otError error; otError error;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aDataset != NULL, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aDataset != NULL, error = OT_ERROR_INVALID_ARGS);
error = aInstance->mThreadNetif.GetActiveDataset().Set(*aDataset); error = instance.GetThreadNetif().GetActiveDataset().Set(*aDataset);
exit: exit:
return error; return error;
@@ -56,10 +57,11 @@ exit:
otError otDatasetSetPending(otInstance *aInstance, const otOperationalDataset *aDataset) otError otDatasetSetPending(otInstance *aInstance, const otOperationalDataset *aDataset)
{ {
otError error; otError error;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aDataset != NULL, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aDataset != NULL, error = OT_ERROR_INVALID_ARGS);
error = aInstance->mThreadNetif.GetPendingDataset().Set(*aDataset); error = instance.GetThreadNetif().GetPendingDataset().Set(*aDataset);
exit: exit:
return error; return error;
@@ -68,35 +70,47 @@ exit:
otError otDatasetSendMgmtActiveGet(otInstance *aInstance, const uint8_t *aTlvTypes, uint8_t aLength, otError otDatasetSendMgmtActiveGet(otInstance *aInstance, const uint8_t *aTlvTypes, uint8_t aLength,
const otIp6Address *aAddress) const otIp6Address *aAddress)
{ {
return aInstance->mThreadNetif.GetActiveDataset().SendGetRequest(aTlvTypes, aLength, aAddress); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetActiveDataset().SendGetRequest(aTlvTypes, aLength, aAddress);
} }
otError otDatasetSendMgmtActiveSet(otInstance *aInstance, const otOperationalDataset *aDataset, otError otDatasetSendMgmtActiveSet(otInstance *aInstance, const otOperationalDataset *aDataset,
const uint8_t *aTlvs, uint8_t aLength) const uint8_t *aTlvs, uint8_t aLength)
{ {
return aInstance->mThreadNetif.GetActiveDataset().SendSetRequest(*aDataset, aTlvs, aLength); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetActiveDataset().SendSetRequest(*aDataset, aTlvs, aLength);
} }
otError otDatasetSendMgmtPendingGet(otInstance *aInstance, const uint8_t *aTlvTypes, uint8_t aLength, otError otDatasetSendMgmtPendingGet(otInstance *aInstance, const uint8_t *aTlvTypes, uint8_t aLength,
const otIp6Address *aAddress) const otIp6Address *aAddress)
{ {
return aInstance->mThreadNetif.GetPendingDataset().SendGetRequest(aTlvTypes, aLength, aAddress); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetPendingDataset().SendGetRequest(aTlvTypes, aLength, aAddress);
} }
otError otDatasetSendMgmtPendingSet(otInstance *aInstance, const otOperationalDataset *aDataset, otError otDatasetSendMgmtPendingSet(otInstance *aInstance, const otOperationalDataset *aDataset,
const uint8_t *aTlvs, uint8_t aLength) const uint8_t *aTlvs, uint8_t aLength)
{ {
return aInstance->mThreadNetif.GetPendingDataset().SendSetRequest(*aDataset, aTlvs, aLength); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetPendingDataset().SendSetRequest(*aDataset, aTlvs, aLength);
} }
uint32_t otDatasetGetDelayTimerMinimal(otInstance *aInstance) uint32_t otDatasetGetDelayTimerMinimal(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetLeader().GetDelayTimerMinimal(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetLeader().GetDelayTimerMinimal();
} }
otError otDatasetSetDelayTimerMinimal(otInstance *aInstance, uint32_t aDelayTimerMinimal) otError otDatasetSetDelayTimerMinimal(otInstance *aInstance, uint32_t aDelayTimerMinimal)
{ {
return aInstance->mThreadNetif.GetLeader().SetDelayTimerMinimal(aDelayTimerMinimal); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetLeader().SetDelayTimerMinimal(aDelayTimerMinimal);
} }
#endif // OPENTHREAD_FTD #endif // OPENTHREAD_FTD
+9 -5
View File
@@ -36,20 +36,24 @@
#include <openthread/dhcp6_client.h> #include <openthread/dhcp6_client.h>
#include <openthread/dhcp6_server.h> #include <openthread/dhcp6_server.h>
#include "openthread-instance.h" #include "common/instance.hpp"
using namespace ot; using namespace ot;
#if OPENTHREAD_ENABLE_DHCP6_CLIENT #if OPENTHREAD_ENABLE_DHCP6_CLIENT
void otDhcp6ClientUpdate(otInstance *aInstance, otDhcpAddress *aAddresses, uint32_t aNumAddresses, void *aContext) void otDhcp6ClientUpdate(otInstance *aInstance, otDhcpAddress *aAddresses, uint32_t aNumAddresses, void *aContext)
{ {
aInstance->mThreadNetif.GetDhcp6Client().UpdateAddresses(aInstance, aAddresses, aNumAddresses, aContext); Instance &instance = *static_cast<Instance *>(aInstance);
instance.GetThreadNetif().GetDhcp6Client().UpdateAddresses(aInstance, aAddresses, aNumAddresses, aContext);
} }
#endif // OPENTHREAD_ENABLE_DHCP6_CLIENT #endif
#if OPENTHREAD_ENABLE_DHCP6_SERVER #if OPENTHREAD_ENABLE_DHCP6_SERVER
void otDhcp6ServerUpdate(otInstance *aInstance) void otDhcp6ServerUpdate(otInstance *aInstance)
{ {
aInstance->mThreadNetif.GetDhcp6Server().UpdateService(); Instance &instance = *static_cast<Instance *>(aInstance);
instance.GetThreadNetif().GetDhcp6Server().UpdateService();
} }
#endif // OPENTHREAD_ENABLE_DHCP6_SERVER #endif
+5 -3
View File
@@ -35,7 +35,7 @@
#include <openthread/dns.h> #include <openthread/dns.h>
#include "openthread-instance.h" #include "common/instance.hpp"
using namespace ot; using namespace ot;
@@ -43,6 +43,8 @@ using namespace ot;
otError otDnsClientQuery(otInstance *aInstance, const otDnsQuery *aQuery, otDnsResponseHandler aHandler, otError otDnsClientQuery(otInstance *aInstance, const otDnsQuery *aQuery, otDnsResponseHandler aHandler,
void *aContext) void *aContext)
{ {
return aInstance->mThreadNetif.GetDnsClient().Query(aQuery, aHandler, aContext); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetDnsClient().Query(aQuery, aHandler, aContext);
} }
#endif // OPENTHREAD_ENABLE_DNS_CLIENT #endif
+15 -7
View File
@@ -35,29 +35,37 @@
#include <openthread/icmp6.h> #include <openthread/icmp6.h>
#include "openthread-instance.h" #include "common/instance.hpp"
using namespace ot; using namespace ot;
bool otIcmp6IsEchoEnabled(otInstance *aInstance) bool otIcmp6IsEchoEnabled(otInstance *aInstance)
{ {
return aInstance->mIp6.GetIcmp().IsEchoEnabled(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetIp6().GetIcmp().IsEchoEnabled();
} }
void otIcmp6SetEchoEnabled(otInstance *aInstance, bool aEnabled) void otIcmp6SetEchoEnabled(otInstance *aInstance, bool aEnabled)
{ {
aInstance->mIp6.GetIcmp().SetEchoEnabled(aEnabled); Instance &instance = *static_cast<Instance *>(aInstance);
instance.GetIp6().GetIcmp().SetEchoEnabled(aEnabled);
} }
otError otIcmp6RegisterHandler(otInstance *aInstance, otIcmp6Handler *aHandler) otError otIcmp6RegisterHandler(otInstance *aInstance, otIcmp6Handler *aHandler)
{ {
return aInstance->mIp6.GetIcmp().RegisterHandler(*static_cast<Ip6::IcmpHandler *>(aHandler)); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetIp6().GetIcmp().RegisterHandler(*static_cast<Ip6::IcmpHandler *>(aHandler));
} }
otError otIcmp6SendEchoRequest(otInstance *aInstance, otMessage *aMessage, otError otIcmp6SendEchoRequest(otInstance *aInstance, otMessage *aMessage,
const otMessageInfo *aMessageInfo, uint16_t aIdentifier) const otMessageInfo *aMessageInfo, uint16_t aIdentifier)
{ {
return aInstance->mIp6.GetIcmp().SendEchoRequest(*static_cast<Message *>(aMessage), Instance &instance = *static_cast<Instance *>(aInstance);
*static_cast<const Ip6::MessageInfo *>(aMessageInfo),
aIdentifier); return instance.GetIp6().GetIcmp().SendEchoRequest(*static_cast<Message *>(aMessage),
*static_cast<const Ip6::MessageInfo *>(aMessageInfo),
aIdentifier);
} }
+33 -175
View File
@@ -39,227 +39,81 @@
#include <openthread/platform/misc.h> #include <openthread/platform/misc.h>
#include <openthread/platform/settings.h> #include <openthread/platform/settings.h>
#include "openthread-instance.h" #include "common/instance.hpp"
#include "openthread-single-instance.h"
#include "common/logging.hpp" #include "common/logging.hpp"
#include "common/new.hpp" #include "common/new.hpp"
#if !OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
static otDEFINE_ALIGNED_VAR(sInstanceRaw, sizeof(otInstance), uint64_t);
otInstance *sInstance = NULL;
otInstance *otGetInstance(void)
{
return sInstance;
}
ot::ThreadNetif &otGetThreadNetif(void)
{
return sInstance->mThreadNetif;
}
ot::MeshForwarder &otGetMeshForwarder(void)
{
return sInstance->mThreadNetif.GetMeshForwarder();
}
ot::TaskletScheduler &otGetTaskletScheduler(void)
{
return sInstance->mTaskletScheduler;
}
ot::Ip6::Ip6 &otGetIp6(void)
{
return sInstance->mIp6;
}
#endif // #if !OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
otInstance::otInstance(void) :
mReceiveIp6DatagramCallback(NULL),
mReceiveIp6DatagramCallbackContext(NULL),
mActiveScanCallback(NULL),
mActiveScanCallbackContext(NULL),
mEnergyScanCallback(NULL),
mEnergyScanCallbackContext(NULL),
mTimerMilliScheduler(*this),
#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER
mTimerMicroScheduler(*this),
#endif
mIp6(*this),
mThreadNetif(*this),
#if OPENTHREAD_ENABLE_RAW_LINK_API
mLinkRaw(*this),
#endif // OPENTHREAD_ENABLE_RAW_LINK_API
#if OPENTHREAD_ENABLE_APPLICATION_COAP
mApplicationCoap(*this),
#endif // OPENTHREAD_ENABLE_APPLICATION_COAP
#if OPENTHREAD_CONFIG_ENABLE_DYNAMIC_LOG_LEVEL
mLogLevel(static_cast<otLogLevel>(OPENTHREAD_CONFIG_LOG_LEVEL)),
#endif // OPENTHREAD_CONFIG_ENABLE_DYNAMIC_LOG_LEVEL
mMessagePool(*this)
{
}
using namespace ot; using namespace ot;
void otInstancePostConstructor(otInstance *aInstance)
{
// restore datasets and network information
otPlatSettingsInit(aInstance);
aInstance->mThreadNetif.GetMle().Restore();
#if OPENTHREAD_CONFIG_ENABLE_AUTO_START_SUPPORT
// If auto start is configured, do that now
if (otThreadGetAutoStart(aInstance))
{
if (otIp6SetEnabled(aInstance, true) == OT_ERROR_NONE)
{
// Only try to start Thread if we could bring up the interface
if (otThreadSetEnabled(aInstance, true) != OT_ERROR_NONE)
{
// Bring the interface down if Thread failed to start
otIp6SetEnabled(aInstance, false);
}
}
}
#endif
}
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
otInstance *otInstanceInit(void *aInstanceBuffer, size_t *aInstanceBufferSize) otInstance *otInstanceInit(void *aInstanceBuffer, size_t *aInstanceBufferSize)
{ {
otInstance *instance = NULL; Instance *instance;
otLogFuncEntry(); otLogFuncEntry();
instance = Instance::Init(aInstanceBuffer, aInstanceBufferSize);
VerifyOrExit(aInstanceBufferSize != NULL);
// Make sure the input buffer is big enough
VerifyOrExit(sizeof(otInstance) <= *aInstanceBufferSize, *aInstanceBufferSize = sizeof(otInstance));
VerifyOrExit(aInstanceBuffer != NULL);
// Construct the context
instance = new(aInstanceBuffer)otInstance();
// Execute post constructor operations
otInstancePostConstructor(instance);
otLogInfoApi(*instance, "otInstance Initialized"); otLogInfoApi(*instance, "otInstance Initialized");
exit:
otLogFuncExit(); otLogFuncExit();
return instance; return instance;
} }
#else
bool otInstanceIsInitialized(otInstance *aInstance)
{
return (aInstance != NULL);
}
#else // #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
otInstance *otInstanceInitSingle(void) otInstance *otInstanceInitSingle(void)
{ {
otLogFuncEntry(); return &Instance::InitSingle();
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();
// Execute post constructor operations
otInstancePostConstructor(sInstance);
otLogInfoApi(*sInstance, "otInstance Initialized");
exit:
otLogFuncExit();
return sInstance;
} }
#endif // #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
bool otInstanceIsInitialized(otInstance *aInstance) bool otInstanceIsInitialized(otInstance *aInstance)
{ {
return (aInstance != NULL) && (aInstance == sInstance); Instance &instance = *static_cast<Instance *>(aInstance);
}
#endif // #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES return instance.IsInitialized();
}
void otInstanceFinalize(otInstance *aInstance) void otInstanceFinalize(otInstance *aInstance)
{ {
Instance &instance = *static_cast<Instance *>(aInstance);
otLogFuncEntry(); otLogFuncEntry();
instance.Finalize();
// Ensure we are disabled
(void)otThreadSetEnabled(aInstance, false);
(void)otIp6SetEnabled(aInstance, false);
#if !OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
sInstance = NULL;
#endif
otLogFuncExit(); otLogFuncExit();
} }
otError otSetStateChangedCallback(otInstance *aInstance, otStateChangedCallback aCallback, void *aCallbackContext) otError otSetStateChangedCallback(otInstance *aInstance, otStateChangedCallback aCallback, void *aCallbackContext)
{ {
otError error = OT_ERROR_NO_BUFS; Instance &instance = *static_cast<Instance *>(aInstance);
for (size_t i = 0; i < OPENTHREAD_CONFIG_MAX_STATECHANGE_HANDLERS; i++) return instance.RegisterStateChangedCallback(aCallback, aCallbackContext);
{
if (aInstance->mNetifCallback[i].IsFree())
{
aInstance->mNetifCallback[i].Set(aCallback, aCallbackContext);
error = aInstance->mThreadNetif.RegisterCallback(aInstance->mNetifCallback[i]);
break;
}
}
return error;
} }
void otRemoveStateChangeCallback(otInstance *aInstance, otStateChangedCallback aCallback, void *aCallbackContext) void otRemoveStateChangeCallback(otInstance *aInstance, otStateChangedCallback aCallback, void *aCallbackContext)
{ {
for (size_t i = 0; i < OPENTHREAD_CONFIG_MAX_STATECHANGE_HANDLERS; i++) Instance &instance = *static_cast<Instance *>(aInstance);
{
if (aInstance->mNetifCallback[i].IsServing(aCallback, aCallbackContext)) instance.RemoveStateChangedCallback(aCallback, aCallbackContext);
{
aInstance->mThreadNetif.RemoveCallback(aInstance->mNetifCallback[i]);
aInstance->mNetifCallback[i].Free();
break;
}
}
} }
void otInstanceReset(otInstance *aInstance) void otInstanceReset(otInstance *aInstance)
{ {
otPlatReset(aInstance); Instance &instance = *static_cast<Instance *>(aInstance);
instance.Reset();
} }
void otInstanceFactoryReset(otInstance *aInstance) void otInstanceFactoryReset(otInstance *aInstance)
{ {
otPlatSettingsWipe(aInstance); Instance &instance = *static_cast<Instance *>(aInstance);
otPlatReset(aInstance);
instance.FactoryReset();
} }
otError otInstanceErasePersistentInfo(otInstance *aInstance) otError otInstanceErasePersistentInfo(otInstance *aInstance)
{ {
otError error = OT_ERROR_NONE; Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(otThreadGetDeviceRole(aInstance) == OT_DEVICE_ROLE_DISABLED, error = OT_ERROR_INVALID_STATE); return instance.ErasePersistentInfo();
otPlatSettingsWipe(aInstance);
exit:
return error;
} }
otLogLevel otGetDynamicLogLevel(otInstance *aInstance) otLogLevel otGetDynamicLogLevel(otInstance *aInstance)
@@ -267,7 +121,9 @@ otLogLevel otGetDynamicLogLevel(otInstance *aInstance)
otLogLevel logLevel; otLogLevel logLevel;
#if OPENTHREAD_CONFIG_ENABLE_DYNAMIC_LOG_LEVEL #if OPENTHREAD_CONFIG_ENABLE_DYNAMIC_LOG_LEVEL
logLevel = aInstance->mLogLevel; Instance &instance = *static_cast<Instance *>(aInstance);
logLevel = instance.GetDynamicLogLevel();
#else #else
logLevel = static_cast<otLogLevel>(OPENTHREAD_CONFIG_LOG_LEVEL); logLevel = static_cast<otLogLevel>(OPENTHREAD_CONFIG_LOG_LEVEL);
OT_UNUSED_VARIABLE(aInstance); OT_UNUSED_VARIABLE(aInstance);
@@ -281,7 +137,9 @@ otError otSetDynamicLogLevel(otInstance *aInstance, otLogLevel aLogLevel)
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
#if OPENTHREAD_CONFIG_ENABLE_DYNAMIC_LOG_LEVEL #if OPENTHREAD_CONFIG_ENABLE_DYNAMIC_LOG_LEVEL
aInstance->mLogLevel = aLogLevel; Instance &instance = *static_cast<Instance *>(aInstance);
instance.SetDynamicLogLevel(aLogLevel);
#else #else
error = OT_ERROR_DISABLED_FEATURE; error = OT_ERROR_DISABLED_FEATURE;
OT_UNUSED_VARIABLE(aInstance); OT_UNUSED_VARIABLE(aInstance);
+60 -24
View File
@@ -37,7 +37,7 @@
#include <openthread/ip6.h> #include <openthread/ip6.h>
#include "openthread-instance.h" #include "common/instance.hpp"
#include "common/logging.hpp" #include "common/logging.hpp"
#include "utils/slaac_address.hpp" #include "utils/slaac_address.hpp"
@@ -46,22 +46,23 @@ using namespace ot;
otError otIp6SetEnabled(otInstance *aInstance, bool aEnabled) otError otIp6SetEnabled(otInstance *aInstance, bool aEnabled)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
otLogFuncEntry(); otLogFuncEntry();
if (aEnabled) if (aEnabled)
{ {
#if OPENTHREAD_ENABLE_RAW_LINK_API #if OPENTHREAD_ENABLE_RAW_LINK_API
VerifyOrExit(!aInstance->mLinkRaw.IsEnabled(), error = OT_ERROR_INVALID_STATE); VerifyOrExit(!instance.GetLinkRaw().IsEnabled(), error = OT_ERROR_INVALID_STATE);
#endif // OPENTHREAD_ENABLE_RAW_LINK_API #endif // OPENTHREAD_ENABLE_RAW_LINK_API
error = aInstance->mThreadNetif.Up(); error = instance.GetThreadNetif().Up();
} }
else else
{ {
#if OPENTHREAD_ENABLE_RAW_LINK_API #if OPENTHREAD_ENABLE_RAW_LINK_API
VerifyOrExit(!aInstance->mLinkRaw.IsEnabled(), error = OT_ERROR_INVALID_STATE); VerifyOrExit(!instance.GetLinkRaw().IsEnabled(), error = OT_ERROR_INVALID_STATE);
#endif // OPENTHREAD_ENABLE_RAW_LINK_API #endif // OPENTHREAD_ENABLE_RAW_LINK_API
error = aInstance->mThreadNetif.Down(); error = instance.GetThreadNetif().Down();
} }
#if OPENTHREAD_ENABLE_RAW_LINK_API #if OPENTHREAD_ENABLE_RAW_LINK_API
@@ -73,47 +74,65 @@ exit:
bool otIp6IsEnabled(otInstance *aInstance) bool otIp6IsEnabled(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.IsUp(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().IsUp();
} }
const otNetifAddress *otIp6GetUnicastAddresses(otInstance *aInstance) const otNetifAddress *otIp6GetUnicastAddresses(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetUnicastAddresses(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetUnicastAddresses();
} }
otError otIp6AddUnicastAddress(otInstance *aInstance, const otNetifAddress *address) otError otIp6AddUnicastAddress(otInstance *aInstance, const otNetifAddress *address)
{ {
return aInstance->mThreadNetif.AddExternalUnicastAddress(*static_cast<const Ip6::NetifUnicastAddress *>(address)); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().AddExternalUnicastAddress(*static_cast<const Ip6::NetifUnicastAddress *>(address));
} }
otError otIp6RemoveUnicastAddress(otInstance *aInstance, const otIp6Address *address) otError otIp6RemoveUnicastAddress(otInstance *aInstance, const otIp6Address *address)
{ {
return aInstance->mThreadNetif.RemoveExternalUnicastAddress(*static_cast<const Ip6::Address *>(address)); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().RemoveExternalUnicastAddress(*static_cast<const Ip6::Address *>(address));
} }
const otNetifMulticastAddress *otIp6GetMulticastAddresses(otInstance *aInstance) const otNetifMulticastAddress *otIp6GetMulticastAddresses(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMulticastAddresses(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMulticastAddresses();
} }
otError otIp6SubscribeMulticastAddress(otInstance *aInstance, const otIp6Address *aAddress) otError otIp6SubscribeMulticastAddress(otInstance *aInstance, const otIp6Address *aAddress)
{ {
return aInstance->mThreadNetif.SubscribeExternalMulticast(*static_cast<const Ip6::Address *>(aAddress)); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().SubscribeExternalMulticast(*static_cast<const Ip6::Address *>(aAddress));
} }
otError otIp6UnsubscribeMulticastAddress(otInstance *aInstance, const otIp6Address *aAddress) otError otIp6UnsubscribeMulticastAddress(otInstance *aInstance, const otIp6Address *aAddress)
{ {
return aInstance->mThreadNetif.UnsubscribeExternalMulticast(*static_cast<const Ip6::Address *>(aAddress)); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().UnsubscribeExternalMulticast(*static_cast<const Ip6::Address *>(aAddress));
} }
bool otIp6IsMulticastPromiscuousEnabled(otInstance *aInstance) bool otIp6IsMulticastPromiscuousEnabled(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.IsMulticastPromiscuousEnabled(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().IsMulticastPromiscuousEnabled();
} }
void otIp6SetMulticastPromiscuousEnabled(otInstance *aInstance, bool aEnabled) void otIp6SetMulticastPromiscuousEnabled(otInstance *aInstance, bool aEnabled)
{ {
aInstance->mThreadNetif.SetMulticastPromiscuous(aEnabled); Instance &instance = *static_cast<Instance *>(aInstance);
instance.GetThreadNetif().SetMulticastPromiscuous(aEnabled);
} }
void otIp6SlaacUpdate(otInstance *aInstance, otNetifAddress *aAddresses, uint32_t aNumAddresses, void otIp6SlaacUpdate(otInstance *aInstance, otNetifAddress *aAddresses, uint32_t aNumAddresses,
@@ -129,8 +148,10 @@ otError otIp6CreateRandomIid(otInstance *aInstance, otNetifAddress *aAddress, vo
otError otIp6CreateMacIid(otInstance *aInstance, otNetifAddress *aAddress, void *) otError otIp6CreateMacIid(otInstance *aInstance, otNetifAddress *aAddress, void *)
{ {
Instance &instance = *static_cast<Instance *>(aInstance);
memcpy(&aAddress->mAddress.mFields.m8[OT_IP6_ADDRESS_SIZE - OT_IP6_IID_SIZE], memcpy(&aAddress->mAddress.mFields.m8[OT_IP6_ADDRESS_SIZE - OT_IP6_IID_SIZE],
aInstance->mThreadNetif.GetMac().GetExtAddress(), OT_IP6_IID_SIZE); instance.GetThreadNetif().GetMac().GetExtAddress(), OT_IP6_IID_SIZE);
aAddress->mAddress.mFields.m8[OT_IP6_ADDRESS_SIZE - OT_IP6_IID_SIZE] ^= 0x02; aAddress->mAddress.mFields.m8[OT_IP6_ADDRESS_SIZE - OT_IP6_IID_SIZE] ^= 0x02;
return OT_ERROR_NONE; return OT_ERROR_NONE;
@@ -143,27 +164,34 @@ otError otIp6CreateSemanticallyOpaqueIid(otInstance *aInstance, otNetifAddress *
void otIp6SetReceiveCallback(otInstance *aInstance, otIp6ReceiveCallback aCallback, void *aCallbackContext) void otIp6SetReceiveCallback(otInstance *aInstance, otIp6ReceiveCallback aCallback, void *aCallbackContext)
{ {
aInstance->mIp6.SetReceiveDatagramCallback(aCallback, aCallbackContext); Instance &instance = *static_cast<Instance *>(aInstance);
instance.GetIp6().SetReceiveDatagramCallback(aCallback, aCallbackContext);
} }
bool otIp6IsReceiveFilterEnabled(otInstance *aInstance) bool otIp6IsReceiveFilterEnabled(otInstance *aInstance)
{ {
return aInstance->mIp6.IsReceiveIp6FilterEnabled(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetIp6().IsReceiveIp6FilterEnabled();
} }
void otIp6SetReceiveFilterEnabled(otInstance *aInstance, bool aEnabled) void otIp6SetReceiveFilterEnabled(otInstance *aInstance, bool aEnabled)
{ {
aInstance->mIp6.SetReceiveIp6FilterEnabled(aEnabled); Instance &instance = *static_cast<Instance *>(aInstance);
instance.GetIp6().SetReceiveIp6FilterEnabled(aEnabled);
} }
otError otIp6Send(otInstance *aInstance, otMessage *aMessage) otError otIp6Send(otInstance *aInstance, otMessage *aMessage)
{ {
otError error; otError error;
Instance &instance = *static_cast<Instance *>(aInstance);
otLogFuncEntry(); otLogFuncEntry();
error = aInstance->mIp6.SendRaw(*static_cast<Message *>(aMessage), error = instance.GetIp6().SendRaw(*static_cast<Message *>(aMessage),
aInstance->mThreadNetif.GetInterfaceId()); instance.GetThreadNetif().GetInterfaceId());
otLogFuncExitErr(error); otLogFuncExitErr(error);
@@ -172,7 +200,9 @@ otError otIp6Send(otInstance *aInstance, otMessage *aMessage)
otMessage *otIp6NewMessage(otInstance *aInstance, bool aLinkSecurityEnabled) otMessage *otIp6NewMessage(otInstance *aInstance, bool aLinkSecurityEnabled)
{ {
Message *message = aInstance->mMessagePool.New(Message::kTypeIp6, 0); Instance &instance = *static_cast<Instance *>(aInstance);
Message *message = instance.GetMessagePool().New(Message::kTypeIp6, 0);
if (message) if (message)
{ {
@@ -184,17 +214,23 @@ otMessage *otIp6NewMessage(otInstance *aInstance, bool aLinkSecurityEnabled)
otError otIp6AddUnsecurePort(otInstance *aInstance, uint16_t aPort) otError otIp6AddUnsecurePort(otInstance *aInstance, uint16_t aPort)
{ {
return aInstance->mThreadNetif.GetIp6Filter().AddUnsecurePort(aPort); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetIp6Filter().AddUnsecurePort(aPort);
} }
otError otIp6RemoveUnsecurePort(otInstance *aInstance, uint16_t aPort) otError otIp6RemoveUnsecurePort(otInstance *aInstance, uint16_t aPort)
{ {
return aInstance->mThreadNetif.GetIp6Filter().RemoveUnsecurePort(aPort); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetIp6Filter().RemoveUnsecurePort(aPort);
} }
const uint16_t *otIp6GetUnsecurePorts(otInstance *aInstance, uint8_t *aNumEntries) const uint16_t *otIp6GetUnsecurePorts(otInstance *aInstance, uint8_t *aNumEntries)
{ {
return aInstance->mThreadNetif.GetIp6Filter().GetUnsecurePorts(*aNumEntries); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetIp6Filter().GetUnsecurePorts(*aNumEntries);
} }
bool otIp6IsAddressEqual(const otIp6Address *a, const otIp6Address *b) bool otIp6IsAddressEqual(const otIp6Address *a, const otIp6Address *b)
+34 -12
View File
@@ -35,7 +35,7 @@
#include <openthread/jam_detection.h> #include <openthread/jam_detection.h>
#include "openthread-instance.h" #include "common/instance.hpp"
using namespace ot; using namespace ot;
@@ -43,57 +43,79 @@ using namespace ot;
otError otJamDetectionSetRssiThreshold(otInstance *aInstance, int8_t aRssiThreshold) otError otJamDetectionSetRssiThreshold(otInstance *aInstance, int8_t aRssiThreshold)
{ {
return aInstance->mThreadNetif.GetJamDetector().SetRssiThreshold(aRssiThreshold); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetJamDetector().SetRssiThreshold(aRssiThreshold);
} }
int8_t otJamDetectionGetRssiThreshold(otInstance *aInstance) int8_t otJamDetectionGetRssiThreshold(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetJamDetector().GetRssiThreshold(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetJamDetector().GetRssiThreshold();
} }
otError otJamDetectionSetWindow(otInstance *aInstance, uint8_t aWindow) otError otJamDetectionSetWindow(otInstance *aInstance, uint8_t aWindow)
{ {
return aInstance->mThreadNetif.GetJamDetector().SetWindow(aWindow); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetJamDetector().SetWindow(aWindow);
} }
uint8_t otJamDetectionGetWindow(otInstance *aInstance) uint8_t otJamDetectionGetWindow(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetJamDetector().GetWindow(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetJamDetector().GetWindow();
} }
otError otJamDetectionSetBusyPeriod(otInstance *aInstance, uint8_t aBusyPeriod) otError otJamDetectionSetBusyPeriod(otInstance *aInstance, uint8_t aBusyPeriod)
{ {
return aInstance->mThreadNetif.GetJamDetector().SetBusyPeriod(aBusyPeriod); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetJamDetector().SetBusyPeriod(aBusyPeriod);
} }
uint8_t otJamDetectionGetBusyPeriod(otInstance *aInstance) uint8_t otJamDetectionGetBusyPeriod(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetJamDetector().GetBusyPeriod(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetJamDetector().GetBusyPeriod();
} }
otError otJamDetectionStart(otInstance *aInstance, otJamDetectionCallback aCallback, void *aContext) otError otJamDetectionStart(otInstance *aInstance, otJamDetectionCallback aCallback, void *aContext)
{ {
return aInstance->mThreadNetif.GetJamDetector().Start(aCallback, aContext); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetJamDetector().Start(aCallback, aContext);
} }
otError otJamDetectionStop(otInstance *aInstance) otError otJamDetectionStop(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetJamDetector().Stop(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetJamDetector().Stop();
} }
bool otJamDetectionIsEnabled(otInstance *aInstance) bool otJamDetectionIsEnabled(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetJamDetector().IsEnabled(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetJamDetector().IsEnabled();
} }
bool otJamDetectionGetState(otInstance *aInstance) bool otJamDetectionGetState(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetJamDetector().GetState(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetJamDetector().GetState();
} }
uint64_t otJamDetectionGetHistoryBitmap(otInstance *aInstance) uint64_t otJamDetectionGetHistoryBitmap(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetJamDetector().GetHistoryBitmap(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetJamDetector().GetHistoryBitmap();
} }
#endif // OPENTHREAD_ENABLE_JAM_DETECTION #endif // OPENTHREAD_ENABLE_JAM_DETECTION
+14 -8
View File
@@ -35,7 +35,7 @@
#include <openthread/joiner.h> #include <openthread/joiner.h>
#include "openthread-instance.h" #include "common/instance.hpp"
using namespace ot; using namespace ot;
@@ -45,11 +45,11 @@ otError otJoinerStart(otInstance *aInstance, const char *aPSKd, const char *aPro
otJoinerCallback aCallback, void *aContext) otJoinerCallback aCallback, void *aContext)
{ {
otError error = OT_ERROR_DISABLED_FEATURE; otError error = OT_ERROR_DISABLED_FEATURE;
#if OPENTHREAD_ENABLE_JOINER #if OPENTHREAD_ENABLE_JOINER
error = aInstance->mThreadNetif.GetJoiner().Start(aPSKd, aProvisioningUrl, Instance &instance = *static_cast<Instance *>(aInstance);
aVendorName, aVendorModel, aVendorSwVersion, aVendorData,
aCallback, aContext); error = instance.GetThreadNetif().GetJoiner().Start(aPSKd, aProvisioningUrl, aVendorName, aVendorModel,
aVendorSwVersion, aVendorData, aCallback, aContext);
#else #else
OT_UNUSED_VARIABLE(aInstance); OT_UNUSED_VARIABLE(aInstance);
OT_UNUSED_VARIABLE(aPSKd); OT_UNUSED_VARIABLE(aPSKd);
@@ -70,7 +70,9 @@ otError otJoinerStop(otInstance *aInstance)
otError error = OT_ERROR_DISABLED_FEATURE; otError error = OT_ERROR_DISABLED_FEATURE;
#if OPENTHREAD_ENABLE_JOINER #if OPENTHREAD_ENABLE_JOINER
error = aInstance->mThreadNetif.GetJoiner().Stop(); Instance &instance = *static_cast<Instance *>(aInstance);
error = instance.GetThreadNetif().GetJoiner().Stop();
#else #else
OT_UNUSED_VARIABLE(aInstance); OT_UNUSED_VARIABLE(aInstance);
#endif #endif
@@ -83,7 +85,9 @@ otJoinerState otJoinerGetState(otInstance *aInstance)
otJoinerState state = OT_JOINER_STATE_IDLE; otJoinerState state = OT_JOINER_STATE_IDLE;
#if OPENTHREAD_ENABLE_JOINER #if OPENTHREAD_ENABLE_JOINER
state = aInstance->mThreadNetif.GetJoiner().GetState(); Instance &instance = *static_cast<Instance *>(aInstance);
state = instance.GetThreadNetif().GetJoiner().GetState();
#else #else
OT_UNUSED_VARIABLE(aInstance); OT_UNUSED_VARIABLE(aInstance);
#endif #endif
@@ -96,7 +100,9 @@ otError otJoinerGetId(otInstance *aInstance, otExtAddress *aJoinerId)
otError error = OT_ERROR_DISABLED_FEATURE; otError error = OT_ERROR_DISABLED_FEATURE;
#if OPENTHREAD_ENABLE_JOINER #if OPENTHREAD_ENABLE_JOINER
aInstance->mThreadNetif.GetJoiner().GetJoinerId(*static_cast<Mac::ExtAddress *>(aJoinerId)); Instance &instance = *static_cast<Instance *>(aInstance);
instance.GetThreadNetif().GetJoiner().GetJoinerId(*static_cast<Mac::ExtAddress *>(aJoinerId));
error = OT_ERROR_NONE; error = OT_ERROR_NONE;
#else #else
OT_UNUSED_VARIABLE(aInstance); OT_UNUSED_VARIABLE(aInstance);
+118 -59
View File
@@ -35,7 +35,7 @@
#include <openthread/link.h> #include <openthread/link.h>
#include "openthread-instance.h" #include "common/instance.hpp"
using namespace ot; using namespace ot;
@@ -44,19 +44,22 @@ static void HandleEnergyScanResult(void *aContext, otEnergyScanResult *aResult);
uint8_t otLinkGetChannel(otInstance *aInstance) uint8_t otLinkGetChannel(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMac().GetChannel(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMac().GetChannel();
} }
otError otLinkSetChannel(otInstance *aInstance, uint8_t aChannel) otError otLinkSetChannel(otInstance *aInstance, uint8_t aChannel)
{ {
otError error; otError error;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aInstance->mThreadNetif.GetMle().GetRole() == OT_DEVICE_ROLE_DISABLED, VerifyOrExit(instance.GetThreadNetif().GetMle().GetRole() == OT_DEVICE_ROLE_DISABLED,
error = OT_ERROR_INVALID_STATE); error = OT_ERROR_INVALID_STATE);
SuccessOrExit(error = aInstance->mThreadNetif.GetMac().SetChannel(aChannel)); SuccessOrExit(error = instance.GetThreadNetif().GetMac().SetChannel(aChannel));
aInstance->mThreadNetif.GetActiveDataset().Clear(); instance.GetThreadNetif().GetActiveDataset().Clear();
aInstance->mThreadNetif.GetPendingDataset().Clear(); instance.GetThreadNetif().GetPendingDataset().Clear();
exit: exit:
return error; return error;
@@ -64,20 +67,23 @@ exit:
const otExtAddress *otLinkGetExtendedAddress(otInstance *aInstance) const otExtAddress *otLinkGetExtendedAddress(otInstance *aInstance)
{ {
return reinterpret_cast<const otExtAddress *>(aInstance->mThreadNetif.GetMac().GetExtAddress()); Instance &instance = *static_cast<Instance *>(aInstance);
return reinterpret_cast<const otExtAddress *>(instance.GetThreadNetif().GetMac().GetExtAddress());
} }
otError otLinkSetExtendedAddress(otInstance *aInstance, const otExtAddress *aExtAddress) otError otLinkSetExtendedAddress(otInstance *aInstance, const otExtAddress *aExtAddress)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aExtAddress != NULL, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aExtAddress != NULL, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aInstance->mThreadNetif.GetMle().GetRole() == OT_DEVICE_ROLE_DISABLED, VerifyOrExit(instance.GetThreadNetif().GetMle().GetRole() == OT_DEVICE_ROLE_DISABLED,
error = OT_ERROR_INVALID_STATE); error = OT_ERROR_INVALID_STATE);
aInstance->mThreadNetif.GetMac().SetExtAddress(*static_cast<const Mac::ExtAddress *>(aExtAddress)); instance.GetThreadNetif().GetMac().SetExtAddress(*static_cast<const Mac::ExtAddress *>(aExtAddress));
SuccessOrExit(error = aInstance->mThreadNetif.GetMle().UpdateLinkLocalAddress()); SuccessOrExit(error = instance.GetThreadNetif().GetMle().UpdateLinkLocalAddress());
exit: exit:
return error; return error;
@@ -90,30 +96,37 @@ void otLinkGetFactoryAssignedIeeeEui64(otInstance *aInstance, otExtAddress *aEui
int8_t otLinkGetMaxTransmitPower(otInstance *aInstance) int8_t otLinkGetMaxTransmitPower(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMac().GetMaxTransmitPower(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMac().GetMaxTransmitPower();
} }
void otLinkSetMaxTransmitPower(otInstance *aInstance, int8_t aPower) void otLinkSetMaxTransmitPower(otInstance *aInstance, int8_t aPower)
{ {
aInstance->mThreadNetif.GetMac().SetMaxTransmitPower(aPower); Instance &instance = *static_cast<Instance *>(aInstance);
instance.GetThreadNetif().GetMac().SetMaxTransmitPower(aPower);
otPlatRadioSetDefaultTxPower(aInstance, aPower); otPlatRadioSetDefaultTxPower(aInstance, aPower);
} }
otPanId otLinkGetPanId(otInstance *aInstance) otPanId otLinkGetPanId(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMac().GetPanId(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMac().GetPanId();
} }
otError otLinkSetPanId(otInstance *aInstance, otPanId aPanId) otError otLinkSetPanId(otInstance *aInstance, otPanId aPanId)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aInstance->mThreadNetif.GetMle().GetRole() == OT_DEVICE_ROLE_DISABLED, VerifyOrExit(instance.GetThreadNetif().GetMle().GetRole() == OT_DEVICE_ROLE_DISABLED,
error = OT_ERROR_INVALID_STATE); error = OT_ERROR_INVALID_STATE);
error = aInstance->mThreadNetif.GetMac().SetPanId(aPanId); error = instance.GetThreadNetif().GetMac().SetPanId(aPanId);
aInstance->mThreadNetif.GetActiveDataset().Clear(); instance.GetThreadNetif().GetActiveDataset().Clear();
aInstance->mThreadNetif.GetPendingDataset().Clear(); instance.GetThreadNetif().GetPendingDataset().Clear();
exit: exit:
return error; return error;
@@ -121,43 +134,56 @@ exit:
uint32_t otLinkGetPollPeriod(otInstance *aInstance) uint32_t otLinkGetPollPeriod(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMeshForwarder().GetDataPollManager().GetKeepAlivePollPeriod(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMeshForwarder().GetDataPollManager().GetKeepAlivePollPeriod();
} }
void otLinkSetPollPeriod(otInstance *aInstance, uint32_t aPollPeriod) void otLinkSetPollPeriod(otInstance *aInstance, uint32_t aPollPeriod)
{ {
aInstance->mThreadNetif.GetMeshForwarder().GetDataPollManager().SetExternalPollPeriod(aPollPeriod); Instance &instance = *static_cast<Instance *>(aInstance);
instance.GetThreadNetif().GetMeshForwarder().GetDataPollManager().SetExternalPollPeriod(aPollPeriod);
} }
otError otLinkSendDataRequest(otInstance *aInstance) otError otLinkSendDataRequest(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMeshForwarder().GetDataPollManager().SendDataPoll(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMeshForwarder().GetDataPollManager().SendDataPoll();
} }
otShortAddress otLinkGetShortAddress(otInstance *aInstance) otShortAddress otLinkGetShortAddress(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMac().GetShortAddress(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMac().GetShortAddress();
} }
#if OPENTHREAD_ENABLE_MAC_FILTER #if OPENTHREAD_ENABLE_MAC_FILTER
otMacFilterAddressMode otLinkFilterGetAddressMode(otInstance *aInstance) otMacFilterAddressMode otLinkFilterGetAddressMode(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMac().GetFilter().GetAddressMode(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMac().GetFilter().GetAddressMode();
} }
otError otLinkFilterSetAddressMode(otInstance *aInstance, otMacFilterAddressMode aMode) otError otLinkFilterSetAddressMode(otInstance *aInstance, otMacFilterAddressMode aMode)
{ {
return aInstance->mThreadNetif.GetMac().GetFilter().SetAddressMode(aMode); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMac().GetFilter().SetAddressMode(aMode);
} }
otError otLinkFilterAddAddress(otInstance *aInstance, const otExtAddress *aExtAddress) otError otLinkFilterAddAddress(otInstance *aInstance, const otExtAddress *aExtAddress)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aExtAddress != NULL, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aExtAddress != NULL, error = OT_ERROR_INVALID_ARGS);
error = aInstance->mThreadNetif.GetMac().GetFilter().AddAddress(*static_cast<const Mac::ExtAddress *>(aExtAddress)); error = instance.GetThreadNetif().GetMac().GetFilter().AddAddress(*static_cast<const Mac::ExtAddress *>(aExtAddress));
exit: exit:
return error; return error;
@@ -166,10 +192,11 @@ exit:
otError otLinkFilterRemoveAddress(otInstance *aInstance, const otExtAddress *aExtAddress) otError otLinkFilterRemoveAddress(otInstance *aInstance, const otExtAddress *aExtAddress)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aExtAddress != NULL, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aExtAddress != NULL, error = OT_ERROR_INVALID_ARGS);
error = aInstance->mThreadNetif.GetMac().GetFilter().RemoveAddress( error = instance.GetThreadNetif().GetMac().GetFilter().RemoveAddress(
*static_cast<const Mac::ExtAddress *>(aExtAddress)); *static_cast<const Mac::ExtAddress *>(aExtAddress));
exit: exit:
@@ -178,17 +205,19 @@ exit:
void otLinkFilterClearAddresses(otInstance *aInstance) void otLinkFilterClearAddresses(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMac().GetFilter().ClearAddresses(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMac().GetFilter().ClearAddresses();
} }
otError otLinkFilterGetNextAddress(otInstance *aInstance, otMacFilterIterator *aIterator, otMacFilterEntry *aEntry) otError otLinkFilterGetNextAddress(otInstance *aInstance, otMacFilterIterator *aIterator, otMacFilterEntry *aEntry)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aIterator != NULL && aEntry != NULL, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aIterator != NULL && aEntry != NULL, error = OT_ERROR_INVALID_ARGS);
error = aInstance->mThreadNetif.GetMac().GetFilter().GetNextAddress(*aIterator, *aEntry); error = instance.GetThreadNetif().GetMac().GetFilter().GetNextAddress(*aIterator, *aEntry);
exit: exit:
return error; return error;
@@ -196,27 +225,34 @@ exit:
otError otLinkFilterAddRssIn(otInstance *aInstance, const otExtAddress *aExtAddress, int8_t aRss) otError otLinkFilterAddRssIn(otInstance *aInstance, const otExtAddress *aExtAddress, int8_t aRss)
{ {
return aInstance->mThreadNetif.GetMac().GetFilter().AddRssIn( Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMac().GetFilter().AddRssIn(
static_cast<const Mac::ExtAddress *>(aExtAddress), aRss); static_cast<const Mac::ExtAddress *>(aExtAddress), aRss);
} }
otError otLinkFilterRemoveRssIn(otInstance *aInstance, const otExtAddress *aExtAddress) otError otLinkFilterRemoveRssIn(otInstance *aInstance, const otExtAddress *aExtAddress)
{ {
return aInstance->mThreadNetif.GetMac().GetFilter().RemoveRssIn(static_cast<const Mac::ExtAddress *>(aExtAddress)); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMac().GetFilter().RemoveRssIn(static_cast<const Mac::ExtAddress *>(aExtAddress));
} }
void otLinkFilterClearRssIn(otInstance *aInstance) void otLinkFilterClearRssIn(otInstance *aInstance)
{ {
aInstance->mThreadNetif.GetMac().GetFilter().ClearRssIn(); Instance &instance = *static_cast<Instance *>(aInstance);
instance.GetThreadNetif().GetMac().GetFilter().ClearRssIn();
} }
otError otLinkFilterGetNextRssIn(otInstance *aInstance, otMacFilterIterator *aIterator, otMacFilterEntry *aEntry) otError otLinkFilterGetNextRssIn(otInstance *aInstance, otMacFilterIterator *aIterator, otMacFilterEntry *aEntry)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aIterator != NULL && aEntry != NULL, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aIterator != NULL && aEntry != NULL, error = OT_ERROR_INVALID_ARGS);
error = aInstance->mThreadNetif.GetMac().GetFilter().GetNextRssIn(*aIterator, *aEntry); error = instance.GetThreadNetif().GetMac().GetFilter().GetNextRssIn(*aIterator, *aEntry);
exit: exit:
return error; return error;
@@ -224,34 +260,43 @@ exit:
uint8_t otLinkConvertRssToLinkQuality(otInstance *aInstance, int8_t aRss) uint8_t otLinkConvertRssToLinkQuality(otInstance *aInstance, int8_t aRss)
{ {
return LinkQualityInfo::ConvertRssToLinkQuality(aInstance->mThreadNetif.GetMac().GetNoiseFloor(), aRss); Instance &instance = *static_cast<Instance *>(aInstance);
return LinkQualityInfo::ConvertRssToLinkQuality(instance.GetThreadNetif().GetMac().GetNoiseFloor(), aRss);
} }
int8_t otLinkConvertLinkQualityToRss(otInstance *aInstance, uint8_t aLinkQuality) int8_t otLinkConvertLinkQualityToRss(otInstance *aInstance, uint8_t aLinkQuality)
{ {
return LinkQualityInfo::ConvertLinkQualityToRss(aInstance->mThreadNetif.GetMac().GetNoiseFloor(), aLinkQuality); Instance &instance = *static_cast<Instance *>(aInstance);
return LinkQualityInfo::ConvertLinkQualityToRss(instance.GetThreadNetif().GetMac().GetNoiseFloor(), aLinkQuality);
} }
#endif // OPENTHREAD_ENABLE_MAC_FILTER #endif // OPENTHREAD_ENABLE_MAC_FILTER
void otLinkSetPcapCallback(otInstance *aInstance, otLinkPcapCallback aPcapCallback, void *aCallbackContext) void otLinkSetPcapCallback(otInstance *aInstance, otLinkPcapCallback aPcapCallback, void *aCallbackContext)
{ {
aInstance->mThreadNetif.GetMac().SetPcapCallback(aPcapCallback, aCallbackContext); Instance &instance = *static_cast<Instance *>(aInstance);
instance.GetThreadNetif().GetMac().SetPcapCallback(aPcapCallback, aCallbackContext);
} }
bool otLinkIsPromiscuous(otInstance *aInstance) bool otLinkIsPromiscuous(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMac().IsPromiscuous(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMac().IsPromiscuous();
} }
otError otLinkSetPromiscuous(otInstance *aInstance, bool aPromiscuous) otError otLinkSetPromiscuous(otInstance *aInstance, bool aPromiscuous)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
// cannot enable IEEE 802.15.4 promiscuous mode if the Thread interface is enabled // cannot enable IEEE 802.15.4 promiscuous mode if the Thread interface is enabled
VerifyOrExit(aInstance->mThreadNetif.IsUp() == false, error = OT_ERROR_INVALID_STATE); VerifyOrExit(instance.GetThreadNetif().IsUp() == false, error = OT_ERROR_INVALID_STATE);
aInstance->mThreadNetif.GetMac().SetPromiscuous(aPromiscuous); instance.GetThreadNetif().GetMac().SetPromiscuous(aPromiscuous);
exit: exit:
return error; return error;
@@ -259,58 +304,72 @@ exit:
const otMacCounters *otLinkGetCounters(otInstance *aInstance) const otMacCounters *otLinkGetCounters(otInstance *aInstance)
{ {
return &aInstance->mThreadNetif.GetMac().GetCounters(); Instance &instance = *static_cast<Instance *>(aInstance);
return &instance.GetThreadNetif().GetMac().GetCounters();
} }
otError otLinkActiveScan(otInstance *aInstance, uint32_t aScanChannels, uint16_t aScanDuration, otError otLinkActiveScan(otInstance *aInstance, uint32_t aScanChannels, uint16_t aScanDuration,
otHandleActiveScanResult aCallback, void *aCallbackContext) otHandleActiveScanResult aCallback, void *aCallbackContext)
{ {
aInstance->mActiveScanCallback = aCallback; Instance &instance = *static_cast<Instance *>(aInstance);
aInstance->mActiveScanCallbackContext = aCallbackContext;
return aInstance->mThreadNetif.GetMac().ActiveScan(aScanChannels, aScanDuration, instance.RegisterActiveScanCallback(aCallback, aCallbackContext);
&HandleActiveScanResult, aInstance); return instance.GetThreadNetif().GetMac().ActiveScan(aScanChannels, aScanDuration,
&HandleActiveScanResult, aInstance);
} }
bool otLinkIsActiveScanInProgress(otInstance *aInstance) bool otLinkIsActiveScanInProgress(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMac().IsActiveScanInProgress(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMac().IsActiveScanInProgress();
} }
void HandleActiveScanResult(void *aContext, Mac::Frame *aFrame) void HandleActiveScanResult(void *aContext, Mac::Frame *aFrame)
{ {
otInstance *aInstance = static_cast<otInstance *>(aContext); Instance &instance = *static_cast<Instance *>(aContext);
otActiveScanResult result;
VerifyOrExit(aFrame != NULL, aInstance->mActiveScanCallback(NULL, aInstance->mActiveScanCallbackContext)); if (aFrame == NULL)
aInstance->mThreadNetif.GetMac().ConvertBeaconToActiveScanResult(aFrame, result); {
aInstance->mActiveScanCallback(&result, aInstance->mActiveScanCallbackContext); instance.InvokeActiveScanCallback(NULL);
}
else
{
otActiveScanResult result;
exit: instance.GetThreadNetif().GetMac().ConvertBeaconToActiveScanResult(aFrame, result);
return; instance.InvokeActiveScanCallback(&result);
}
} }
otError otLinkEnergyScan(otInstance *aInstance, uint32_t aScanChannels, uint16_t aScanDuration, otError otLinkEnergyScan(otInstance *aInstance, uint32_t aScanChannels, uint16_t aScanDuration,
otHandleEnergyScanResult aCallback, void *aCallbackContext) otHandleEnergyScanResult aCallback, void *aCallbackContext)
{ {
aInstance->mEnergyScanCallback = aCallback; Instance &instance = *static_cast<Instance *>(aInstance);
aInstance->mEnergyScanCallbackContext = aCallbackContext;
return aInstance->mThreadNetif.GetMac().EnergyScan(aScanChannels, aScanDuration, instance.RegisterEnergyScanCallback(aCallback, aCallbackContext);
&HandleEnergyScanResult, aInstance); return instance.GetThreadNetif().GetMac().EnergyScan(aScanChannels, aScanDuration,
&HandleEnergyScanResult, aInstance);
} }
void HandleEnergyScanResult(void *aContext, otEnergyScanResult *aResult) void HandleEnergyScanResult(void *aContext, otEnergyScanResult *aResult)
{ {
otInstance *aInstance = static_cast<otInstance *>(aContext); Instance &instance = *static_cast<Instance *>(aContext);
aInstance->mEnergyScanCallback(aResult, aInstance->mEnergyScanCallbackContext); instance.InvokeEnergyScanCallback(aResult);
} }
bool otLinkIsEnergyScanInProgress(otInstance *aInstance) bool otLinkIsEnergyScanInProgress(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMac().IsEnergyScanInProgress(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMac().IsEnergyScanInProgress();
} }
bool otLinkIsInTransmitState(otInstance *aInstance) bool otLinkIsInTransmitState(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMac().IsInTransmitState(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMac().IsInTransmitState();
} }
+1 -1
View File
@@ -55,7 +55,7 @@ public:
* This constructor initializes the object. * This constructor initializes the object.
* *
*/ */
LinkRaw(otInstance &aInstance); LinkRaw(Instance &aInstance);
/** /**
* This method returns true if the raw link-layer is enabled. * This method returns true if the raw link-layer is enabled.
+49 -23
View File
@@ -35,21 +35,24 @@
#include <openthread/platform/random.h> #include <openthread/platform/random.h>
#include "openthread-instance.h"
#include "common/debug.hpp" #include "common/debug.hpp"
#include "common/instance.hpp"
#include "common/logging.hpp" #include "common/logging.hpp"
using namespace ot;
#if OPENTHREAD_ENABLE_RAW_LINK_API #if OPENTHREAD_ENABLE_RAW_LINK_API
otError otLinkRawSetEnable(otInstance *aInstance, bool aEnabled) otError otLinkRawSetEnable(otInstance *aInstance, bool aEnabled)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(!aInstance->mThreadNetif.IsUp(), error = OT_ERROR_INVALID_STATE); VerifyOrExit(!instance.GetThreadNetif().IsUp(), error = OT_ERROR_INVALID_STATE);
otLogInfoPlat(aInstance, "LinkRaw Enabled=%d", aEnabled ? 1 : 0); otLogInfoPlat(aInstance, "LinkRaw Enabled=%d", aEnabled ? 1 : 0);
aInstance->mLinkRaw.SetEnabled(aEnabled); instance.GetLinkRaw().SetEnabled(aEnabled);
exit: exit:
return error; return error;
@@ -57,14 +60,17 @@ exit:
bool otLinkRawIsEnabled(otInstance *aInstance) bool otLinkRawIsEnabled(otInstance *aInstance)
{ {
return aInstance->mLinkRaw.IsEnabled(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetLinkRaw().IsEnabled();
} }
otError otLinkRawSetPanId(otInstance *aInstance, uint16_t aPanId) otError otLinkRawSetPanId(otInstance *aInstance, uint16_t aPanId)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aInstance->mLinkRaw.IsEnabled(), error = OT_ERROR_INVALID_STATE); VerifyOrExit(instance.GetLinkRaw().IsEnabled(), error = OT_ERROR_INVALID_STATE);
otPlatRadioSetPanId(aInstance, aPanId); otPlatRadioSetPanId(aInstance, aPanId);
@@ -75,9 +81,10 @@ exit:
otError otLinkRawSetExtendedAddress(otInstance *aInstance, const otExtAddress *aExtAddress) otError otLinkRawSetExtendedAddress(otInstance *aInstance, const otExtAddress *aExtAddress)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
otExtAddress address; otExtAddress address;
VerifyOrExit(aInstance->mLinkRaw.IsEnabled(), error = OT_ERROR_INVALID_STATE); VerifyOrExit(instance.GetLinkRaw().IsEnabled(), error = OT_ERROR_INVALID_STATE);
for (size_t i = 0; i < sizeof(address); i++) for (size_t i = 0; i < sizeof(address); i++)
{ {
@@ -93,8 +100,9 @@ exit:
otError otLinkRawSetShortAddress(otInstance *aInstance, uint16_t aShortAddress) otError otLinkRawSetShortAddress(otInstance *aInstance, uint16_t aShortAddress)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aInstance->mLinkRaw.IsEnabled(), error = OT_ERROR_INVALID_STATE); VerifyOrExit(instance.GetLinkRaw().IsEnabled(), error = OT_ERROR_INVALID_STATE);
otPlatRadioSetShortAddress(aInstance, aShortAddress); otPlatRadioSetShortAddress(aInstance, aShortAddress);
@@ -110,8 +118,9 @@ bool otLinkRawGetPromiscuous(otInstance *aInstance)
otError otLinkRawSetPromiscuous(otInstance *aInstance, bool aEnable) otError otLinkRawSetPromiscuous(otInstance *aInstance, bool aEnable)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aInstance->mLinkRaw.IsEnabled(), error = OT_ERROR_INVALID_STATE); VerifyOrExit(instance.GetLinkRaw().IsEnabled(), error = OT_ERROR_INVALID_STATE);
otLogInfoPlat(aInstance, "LinkRaw Promiscuous=%d", aEnable ? 1 : 0); otLogInfoPlat(aInstance, "LinkRaw Promiscuous=%d", aEnable ? 1 : 0);
@@ -124,8 +133,9 @@ exit:
otError otLinkRawSleep(otInstance *aInstance) otError otLinkRawSleep(otInstance *aInstance)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aInstance->mLinkRaw.IsEnabled(), error = OT_ERROR_INVALID_STATE); VerifyOrExit(instance.GetLinkRaw().IsEnabled(), error = OT_ERROR_INVALID_STATE);
otLogInfoPlat(aInstance, "LinkRaw Sleep"); otLogInfoPlat(aInstance, "LinkRaw Sleep");
@@ -137,15 +147,18 @@ exit:
otError otLinkRawReceive(otInstance *aInstance, uint8_t aChannel, otLinkRawReceiveDone aCallback) otError otLinkRawReceive(otInstance *aInstance, uint8_t aChannel, otLinkRawReceiveDone aCallback)
{ {
Instance &instance = *static_cast<Instance *>(aInstance);
otLogInfoPlat(aInstance, "LinkRaw Recv (Channel %d)", aChannel); otLogInfoPlat(aInstance, "LinkRaw Recv (Channel %d)", aChannel);
return aInstance->mLinkRaw.Receive(aChannel, aCallback); return instance.GetLinkRaw().Receive(aChannel, aCallback);
} }
otRadioFrame *otLinkRawGetTransmitBuffer(otInstance *aInstance) otRadioFrame *otLinkRawGetTransmitBuffer(otInstance *aInstance)
{ {
otRadioFrame *buffer = NULL; otRadioFrame *buffer = NULL;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aInstance->mLinkRaw.IsEnabled()); VerifyOrExit(instance.GetLinkRaw().IsEnabled());
buffer = otPlatRadioGetTransmitBuffer(aInstance); buffer = otPlatRadioGetTransmitBuffer(aInstance);
@@ -155,8 +168,10 @@ exit:
otError otLinkRawTransmit(otInstance *aInstance, otRadioFrame *aFrame, otLinkRawTransmitDone aCallback) otError otLinkRawTransmit(otInstance *aInstance, otRadioFrame *aFrame, otLinkRawTransmitDone aCallback)
{ {
Instance &instance = *static_cast<Instance *>(aInstance);
otLogInfoPlat(aInstance, "LinkRaw Transmit (%d bytes on channel %d)", aFrame->mLength, aFrame->mChannel); otLogInfoPlat(aInstance, "LinkRaw Transmit (%d bytes on channel %d)", aFrame->mLength, aFrame->mChannel);
return aInstance->mLinkRaw.Transmit(aFrame, aCallback); return instance.GetLinkRaw().Transmit(aFrame, aCallback);
} }
int8_t otLinkRawGetRssi(otInstance *aInstance) int8_t otLinkRawGetRssi(otInstance *aInstance)
@@ -166,20 +181,25 @@ int8_t otLinkRawGetRssi(otInstance *aInstance)
otRadioCaps otLinkRawGetCaps(otInstance *aInstance) otRadioCaps otLinkRawGetCaps(otInstance *aInstance)
{ {
return aInstance->mLinkRaw.GetCaps(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetLinkRaw().GetCaps();
} }
otError otLinkRawEnergyScan(otInstance *aInstance, uint8_t aScanChannel, uint16_t aScanDuration, otError otLinkRawEnergyScan(otInstance *aInstance, uint8_t aScanChannel, uint16_t aScanDuration,
otLinkRawEnergyScanDone aCallback) otLinkRawEnergyScanDone aCallback)
{ {
return aInstance->mLinkRaw.EnergyScan(aScanChannel, aScanDuration, aCallback); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetLinkRaw().EnergyScan(aScanChannel, aScanDuration, aCallback);
} }
otError otLinkRawSrcMatchEnable(otInstance *aInstance, bool aEnable) otError otLinkRawSrcMatchEnable(otInstance *aInstance, bool aEnable)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aInstance->mLinkRaw.IsEnabled(), error = OT_ERROR_INVALID_STATE); VerifyOrExit(instance.GetLinkRaw().IsEnabled(), error = OT_ERROR_INVALID_STATE);
otPlatRadioEnableSrcMatch(aInstance, aEnable); otPlatRadioEnableSrcMatch(aInstance, aEnable);
@@ -190,8 +210,9 @@ exit:
otError otLinkRawSrcMatchAddShortEntry(otInstance *aInstance, const uint16_t aShortAddress) otError otLinkRawSrcMatchAddShortEntry(otInstance *aInstance, const uint16_t aShortAddress)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aInstance->mLinkRaw.IsEnabled(), error = OT_ERROR_INVALID_STATE); VerifyOrExit(instance.GetLinkRaw().IsEnabled(), error = OT_ERROR_INVALID_STATE);
error = otPlatRadioAddSrcMatchShortEntry(aInstance, aShortAddress); error = otPlatRadioAddSrcMatchShortEntry(aInstance, aShortAddress);
@@ -202,8 +223,9 @@ exit:
otError otLinkRawSrcMatchAddExtEntry(otInstance *aInstance, const otExtAddress *aExtAddress) otError otLinkRawSrcMatchAddExtEntry(otInstance *aInstance, const otExtAddress *aExtAddress)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aInstance->mLinkRaw.IsEnabled(), error = OT_ERROR_INVALID_STATE); VerifyOrExit(instance.GetLinkRaw().IsEnabled(), error = OT_ERROR_INVALID_STATE);
error = otPlatRadioAddSrcMatchExtEntry(aInstance, aExtAddress); error = otPlatRadioAddSrcMatchExtEntry(aInstance, aExtAddress);
@@ -214,8 +236,9 @@ exit:
otError otLinkRawSrcMatchClearShortEntry(otInstance *aInstance, const uint16_t aShortAddress) otError otLinkRawSrcMatchClearShortEntry(otInstance *aInstance, const uint16_t aShortAddress)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aInstance->mLinkRaw.IsEnabled(), error = OT_ERROR_INVALID_STATE); VerifyOrExit(instance.GetLinkRaw().IsEnabled(), error = OT_ERROR_INVALID_STATE);
error = otPlatRadioClearSrcMatchShortEntry(aInstance, aShortAddress); error = otPlatRadioClearSrcMatchShortEntry(aInstance, aShortAddress);
@@ -226,8 +249,9 @@ exit:
otError otLinkRawSrcMatchClearExtEntry(otInstance *aInstance, const otExtAddress *aExtAddress) otError otLinkRawSrcMatchClearExtEntry(otInstance *aInstance, const otExtAddress *aExtAddress)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aInstance->mLinkRaw.IsEnabled(), error = OT_ERROR_INVALID_STATE); VerifyOrExit(instance.GetLinkRaw().IsEnabled(), error = OT_ERROR_INVALID_STATE);
error = otPlatRadioClearSrcMatchExtEntry(aInstance, aExtAddress); error = otPlatRadioClearSrcMatchExtEntry(aInstance, aExtAddress);
@@ -238,8 +262,9 @@ exit:
otError otLinkRawSrcMatchClearShortEntries(otInstance *aInstance) otError otLinkRawSrcMatchClearShortEntries(otInstance *aInstance)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aInstance->mLinkRaw.IsEnabled(), error = OT_ERROR_INVALID_STATE); VerifyOrExit(instance.GetLinkRaw().IsEnabled(), error = OT_ERROR_INVALID_STATE);
otPlatRadioClearSrcMatchShortEntries(aInstance); otPlatRadioClearSrcMatchShortEntries(aInstance);
@@ -250,8 +275,9 @@ exit:
otError otLinkRawSrcMatchClearExtEntries(otInstance *aInstance) otError otLinkRawSrcMatchClearExtEntries(otInstance *aInstance)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aInstance->mLinkRaw.IsEnabled(), error = OT_ERROR_INVALID_STATE); VerifyOrExit(instance.GetLinkRaw().IsEnabled(), error = OT_ERROR_INVALID_STATE);
otPlatRadioClearSrcMatchExtEntries(aInstance); otPlatRadioClearSrcMatchExtEntries(aInstance);
@@ -261,7 +287,7 @@ exit:
namespace ot { namespace ot {
LinkRaw::LinkRaw(otInstance &aInstance): LinkRaw::LinkRaw(Instance &aInstance):
mInstance(aInstance), mInstance(aInstance),
mEnabled(false), mEnabled(false),
mReceiveChannel(OPENTHREAD_CONFIG_DEFAULT_CHANNEL), mReceiveChannel(OPENTHREAD_CONFIG_DEFAULT_CHANNEL),
@@ -607,7 +633,7 @@ LinkRaw &LinkRaw::GetOwner(const Context &aContext)
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
LinkRaw &link = *static_cast<LinkRaw *>(aContext.GetContext()); LinkRaw &link = *static_cast<LinkRaw *>(aContext.GetContext());
#else #else
LinkRaw &link = otGetInstance()->mLinkRaw; LinkRaw &link = Instance::Get().GetLinkRaw();
OT_UNUSED_VARIABLE(aContext); OT_UNUSED_VARIABLE(aContext);
#endif #endif
return link; return link;
+65 -60
View File
@@ -35,7 +35,7 @@
#include <openthread/message.h> #include <openthread/message.h>
#include "openthread-instance.h" #include "common/instance.hpp"
using namespace ot; using namespace ot;
@@ -46,70 +46,70 @@ void otMessageFree(otMessage *aMessage)
uint16_t otMessageGetLength(otMessage *aMessage) uint16_t otMessageGetLength(otMessage *aMessage)
{ {
Message *message = static_cast<Message *>(aMessage); Message &message = *static_cast<Message *>(aMessage);
return message->GetLength(); return message.GetLength();
} }
otError otMessageSetLength(otMessage *aMessage, uint16_t aLength) otError otMessageSetLength(otMessage *aMessage, uint16_t aLength)
{ {
Message *message = static_cast<Message *>(aMessage); Message &message = *static_cast<Message *>(aMessage);
return message->SetLength(aLength); return message.SetLength(aLength);
} }
uint16_t otMessageGetOffset(otMessage *aMessage) uint16_t otMessageGetOffset(otMessage *aMessage)
{ {
Message *message = static_cast<Message *>(aMessage); Message &message = *static_cast<Message *>(aMessage);
return message->GetOffset(); return message.GetOffset();
} }
otError otMessageSetOffset(otMessage *aMessage, uint16_t aOffset) otError otMessageSetOffset(otMessage *aMessage, uint16_t aOffset)
{ {
Message *message = static_cast<Message *>(aMessage); Message &message = *static_cast<Message *>(aMessage);
return message->SetOffset(aOffset); return message.SetOffset(aOffset);
} }
bool otMessageIsLinkSecurityEnabled(otMessage *aMessage) bool otMessageIsLinkSecurityEnabled(otMessage *aMessage)
{ {
Message *message = static_cast<Message *>(aMessage); Message &message = *static_cast<Message *>(aMessage);
return message->IsLinkSecurityEnabled(); return message.IsLinkSecurityEnabled();
} }
void otMessageSetDirectTransmission(otMessage *aMessage, bool aEnabled) void otMessageSetDirectTransmission(otMessage *aMessage, bool aEnabled)
{ {
Message *message = static_cast<Message *>(aMessage); Message &message = *static_cast<Message *>(aMessage);
if (aEnabled) if (aEnabled)
{ {
message->SetDirectTransmission(); message.SetDirectTransmission();
} }
else else
{ {
message->ClearDirectTransmission(); message.ClearDirectTransmission();
} }
} }
int8_t otMessageGetRss(otMessage *aMessage) int8_t otMessageGetRss(otMessage *aMessage)
{ {
Message *message = static_cast<Message *>(aMessage); Message &message = *static_cast<Message *>(aMessage);
return message->GetAverageRss(); return message.GetAverageRss();
} }
otError otMessageAppend(otMessage *aMessage, const void *aBuf, uint16_t aLength) otError otMessageAppend(otMessage *aMessage, const void *aBuf, uint16_t aLength)
{ {
Message *message = static_cast<Message *>(aMessage); Message &message = *static_cast<Message *>(aMessage);
return message->Append(aBuf, aLength); return message.Append(aBuf, aLength);
} }
int otMessageRead(otMessage *aMessage, uint16_t aOffset, void *aBuf, uint16_t aLength) int otMessageRead(otMessage *aMessage, uint16_t aOffset, void *aBuf, uint16_t aLength)
{ {
Message *message = static_cast<Message *>(aMessage); Message &message = *static_cast<Message *>(aMessage);
return message->Read(aOffset, aLength, aBuf); return message.Read(aOffset, aLength, aBuf);
} }
int otMessageWrite(otMessage *aMessage, uint16_t aOffset, const void *aBuf, uint16_t aLength) int otMessageWrite(otMessage *aMessage, uint16_t aOffset, const void *aBuf, uint16_t aLength)
{ {
Message *message = static_cast<Message *>(aMessage); Message &message = *static_cast<Message *>(aMessage);
return message->Write(aOffset, aLength, aBuf); return message.Write(aOffset, aLength, aBuf);
} }
void otMessageQueueInit(otMessageQueue *aQueue) void otMessageQueueInit(otMessageQueue *aQueue)
@@ -119,40 +119,44 @@ void otMessageQueueInit(otMessageQueue *aQueue)
otError otMessageQueueEnqueue(otMessageQueue *aQueue, otMessage *aMessage) otError otMessageQueueEnqueue(otMessageQueue *aQueue, otMessage *aMessage)
{ {
Message *message = static_cast<Message *>(aMessage); Message &message = *static_cast<Message *>(aMessage);
MessageQueue *queue = static_cast<MessageQueue *>(aQueue); MessageQueue &queue = *static_cast<MessageQueue *>(aQueue);
return queue->Enqueue(*message); return queue.Enqueue(message);
} }
otError otMessageQueueEnqueueAtHead(otMessageQueue *aQueue, otMessage *aMessage) otError otMessageQueueEnqueueAtHead(otMessageQueue *aQueue, otMessage *aMessage)
{ {
Message *message = static_cast<Message *>(aMessage); Message &message = *static_cast<Message *>(aMessage);
MessageQueue *queue = static_cast<MessageQueue *>(aQueue); MessageQueue &queue = *static_cast<MessageQueue *>(aQueue);
return queue->Enqueue(*message, MessageQueue::kQueuePositionHead); return queue.Enqueue(message, MessageQueue::kQueuePositionHead);
} }
otError otMessageQueueDequeue(otMessageQueue *aQueue, otMessage *aMessage) otError otMessageQueueDequeue(otMessageQueue *aQueue, otMessage *aMessage)
{ {
Message *message = static_cast<Message *>(aMessage); Message &message = *static_cast<Message *>(aMessage);
MessageQueue *queue = static_cast<MessageQueue *>(aQueue); MessageQueue &queue = *static_cast<MessageQueue *>(aQueue);
return queue->Dequeue(*message); return queue.Dequeue(message);
} }
otMessage *otMessageQueueGetHead(otMessageQueue *aQueue) otMessage *otMessageQueueGetHead(otMessageQueue *aQueue)
{ {
MessageQueue *queue = static_cast<MessageQueue *>(aQueue); MessageQueue &queue = *static_cast<MessageQueue *>(aQueue);
return queue->GetHead(); return queue.GetHead();
} }
otMessage *otMessageQueueGetNext(otMessageQueue *aQueue, const otMessage *aMessage) otMessage *otMessageQueueGetNext(otMessageQueue *aQueue, const otMessage *aMessage)
{ {
Message *next; Message *next;
const Message *message = static_cast<const Message *>(aMessage);
MessageQueue *queue = static_cast<MessageQueue *>(aQueue);
VerifyOrExit(message != NULL, next = NULL); VerifyOrExit(aMessage != NULL, next = NULL);
VerifyOrExit(message->GetMessageQueue() == queue, next = NULL);
next = message->GetNext(); {
const Message &message = *static_cast<const Message *>(aMessage);
MessageQueue &queue = *static_cast<MessageQueue *>(aQueue);
VerifyOrExit(message.GetMessageQueue() == &queue, next = NULL);
next = message.GetNext();
}
exit: exit:
return next; return next;
@@ -161,39 +165,40 @@ exit:
void otMessageGetBufferInfo(otInstance *aInstance, otBufferInfo *aBufferInfo) void otMessageGetBufferInfo(otInstance *aInstance, otBufferInfo *aBufferInfo)
{ {
uint16_t messages, buffers; uint16_t messages, buffers;
Instance &instance = *static_cast<Instance *>(aInstance);
aBufferInfo->mTotalBuffers = OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS; aBufferInfo->mTotalBuffers = OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS;
aBufferInfo->mFreeBuffers = aInstance->mMessagePool.GetFreeBufferCount(); aBufferInfo->mFreeBuffers = instance.GetMessagePool().GetFreeBufferCount();
aInstance->mThreadNetif.GetMeshForwarder().GetSendQueue().GetInfo(aBufferInfo->m6loSendMessages, instance.GetThreadNetif().GetMeshForwarder().GetSendQueue().GetInfo(aBufferInfo->m6loSendMessages,
aBufferInfo->m6loSendBuffers); aBufferInfo->m6loSendBuffers);
aInstance->mThreadNetif.GetMeshForwarder().GetReassemblyQueue().GetInfo(aBufferInfo->m6loReassemblyMessages, instance.GetThreadNetif().GetMeshForwarder().GetReassemblyQueue().GetInfo(aBufferInfo->m6loReassemblyMessages,
aBufferInfo->m6loReassemblyBuffers); aBufferInfo->m6loReassemblyBuffers);
aInstance->mThreadNetif.GetMeshForwarder().GetResolvingQueue().GetInfo(aBufferInfo->mArpMessages, instance.GetThreadNetif().GetMeshForwarder().GetResolvingQueue().GetInfo(aBufferInfo->mArpMessages,
aBufferInfo->mArpBuffers); aBufferInfo->mArpBuffers);
aInstance->mThreadNetif.GetIp6().GetSendQueue().GetInfo(aBufferInfo->mIp6Messages, instance.GetThreadNetif().GetIp6().GetSendQueue().GetInfo(aBufferInfo->mIp6Messages,
aBufferInfo->mIp6Buffers); aBufferInfo->mIp6Buffers);
aInstance->mThreadNetif.GetIp6().GetMpl().GetBufferedMessageSet().GetInfo(aBufferInfo->mMplMessages, instance.GetThreadNetif().GetIp6().GetMpl().GetBufferedMessageSet().GetInfo(aBufferInfo->mMplMessages,
aBufferInfo->mMplBuffers); aBufferInfo->mMplBuffers);
aInstance->mThreadNetif.GetMle().GetMessageQueue().GetInfo(aBufferInfo->mMleMessages, instance.GetThreadNetif().GetMle().GetMessageQueue().GetInfo(aBufferInfo->mMleMessages,
aBufferInfo->mMleBuffers); aBufferInfo->mMleBuffers);
aInstance->mThreadNetif.GetCoap().GetRequestMessages().GetInfo(aBufferInfo->mCoapMessages, instance.GetThreadNetif().GetCoap().GetRequestMessages().GetInfo(aBufferInfo->mCoapMessages,
aBufferInfo->mCoapBuffers); aBufferInfo->mCoapBuffers);
aInstance->mThreadNetif.GetCoap().GetCachedResponses().GetInfo(messages, buffers); instance.GetThreadNetif().GetCoap().GetCachedResponses().GetInfo(messages, buffers);
aBufferInfo->mCoapMessages += messages; aBufferInfo->mCoapMessages += messages;
aBufferInfo->mCoapBuffers += buffers; aBufferInfo->mCoapBuffers += buffers;
#if OPENTHREAD_ENABLE_DTLS #if OPENTHREAD_ENABLE_DTLS
aInstance->mThreadNetif.GetCoapSecure().GetRequestMessages().GetInfo(aBufferInfo->mCoapSecureMessages, instance.GetThreadNetif().GetCoapSecure().GetRequestMessages().GetInfo(aBufferInfo->mCoapSecureMessages,
aBufferInfo->mCoapSecureBuffers); aBufferInfo->mCoapSecureBuffers);
aInstance->mThreadNetif.GetCoapSecure().GetCachedResponses().GetInfo(messages, buffers); instance.GetThreadNetif().GetCoapSecure().GetCachedResponses().GetInfo(messages, buffers);
aBufferInfo->mCoapSecureMessages += messages; aBufferInfo->mCoapSecureMessages += messages;
aBufferInfo->mCoapSecureBuffers += buffers; aBufferInfo->mCoapSecureBuffers += buffers;
#else #else
@@ -202,9 +207,9 @@ void otMessageGetBufferInfo(otInstance *aInstance, otBufferInfo *aBufferInfo)
#endif #endif
#if OPENTHREAD_ENABLE_APPLICATION_COAP #if OPENTHREAD_ENABLE_APPLICATION_COAP
aInstance->mApplicationCoap.GetRequestMessages().GetInfo(aBufferInfo->mApplicationCoapMessages, instance.GetApplicationCoap().GetRequestMessages().GetInfo(aBufferInfo->mApplicationCoapMessages,
aBufferInfo->mApplicationCoapBuffers); aBufferInfo->mApplicationCoapBuffers);
aInstance->mApplicationCoap.GetCachedResponses().GetInfo(messages, buffers); instance.GetApplicationCoap().GetCachedResponses().GetInfo(messages, buffers);
aBufferInfo->mApplicationCoapMessages += messages; aBufferInfo->mApplicationCoapMessages += messages;
aBufferInfo->mApplicationCoapBuffers += buffers; aBufferInfo->mApplicationCoapBuffers += buffers;
#else #else
+13 -6
View File
@@ -35,17 +35,18 @@
#include <openthread/netdata.h> #include <openthread/netdata.h>
#include "openthread-instance.h" #include "common/instance.hpp"
using namespace ot; using namespace ot;
otError otNetDataGet(otInstance *aInstance, bool aStable, uint8_t *aData, uint8_t *aDataLength) otError otNetDataGet(otInstance *aInstance, bool aStable, uint8_t *aData, uint8_t *aDataLength)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aData != NULL && aDataLength != NULL, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aData != NULL && aDataLength != NULL, error = OT_ERROR_INVALID_ARGS);
error = aInstance->mThreadNetif.GetNetworkDataLeader().GetNetworkData(aStable, aData, *aDataLength); error = instance.GetThreadNetif().GetNetworkDataLeader().GetNetworkData(aStable, aData, *aDataLength);
exit: exit:
return error; return error;
@@ -55,10 +56,11 @@ otError otNetDataGetNextOnMeshPrefix(otInstance *aInstance, otNetworkDataIterato
otBorderRouterConfig *aConfig) otBorderRouterConfig *aConfig)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aIterator && aConfig, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aIterator && aConfig, error = OT_ERROR_INVALID_ARGS);
error = aInstance->mThreadNetif.GetNetworkDataLeader().GetNextOnMeshPrefix(aIterator, aConfig); error = instance.GetThreadNetif().GetNetworkDataLeader().GetNextOnMeshPrefix(aIterator, aConfig);
exit: exit:
return error; return error;
@@ -68,10 +70,11 @@ otError otNetDataGetNextRoute(otInstance *aInstance, otNetworkDataIterator *aIte
otExternalRouteConfig *aConfig) otExternalRouteConfig *aConfig)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aIterator && aConfig, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aIterator && aConfig, error = OT_ERROR_INVALID_ARGS);
error = aInstance->mThreadNetif.GetNetworkDataLeader().GetNextExternalRoute(aIterator, aConfig); error = instance.GetThreadNetif().GetNetworkDataLeader().GetNextExternalRoute(aIterator, aConfig);
exit: exit:
return error; return error;
@@ -79,10 +82,14 @@ exit:
uint8_t otNetDataGetVersion(otInstance *aInstance) uint8_t otNetDataGetVersion(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMle().GetLeaderDataTlv().GetDataVersion(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().GetLeaderDataTlv().GetDataVersion();
} }
uint8_t otNetDataGetStableVersion(otInstance *aInstance) uint8_t otNetDataGetStableVersion(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMle().GetLeaderDataTlv().GetStableDataVersion(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().GetLeaderDataTlv().GetStableDataVersion();
} }
+15 -6
View File
@@ -37,17 +37,18 @@
#include <openthread/server.h> #include <openthread/server.h>
#include "openthread-instance.h" #include "common/instance.hpp"
using namespace ot; using namespace ot;
otError otServerGetNetDataLocal(otInstance *aInstance, bool aStable, uint8_t *aData, uint8_t *aDataLength) otError otServerGetNetDataLocal(otInstance *aInstance, bool aStable, uint8_t *aData, uint8_t *aDataLength)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aData != NULL && aDataLength != NULL, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aData != NULL && aDataLength != NULL, error = OT_ERROR_INVALID_ARGS);
error = aInstance->mThreadNetif.GetNetworkDataLocal().GetNetworkData(aStable, aData, *aDataLength); error = instance.GetThreadNetif().GetNetworkDataLocal().GetNetworkData(aStable, aData, *aDataLength);
exit: exit:
return error; return error;
@@ -55,7 +56,9 @@ exit:
otError otServerAddService(otInstance *aInstance, const otServiceConfig *aConfig) otError otServerAddService(otInstance *aInstance, const otServiceConfig *aConfig)
{ {
return aInstance->mThreadNetif.GetNetworkDataLocal().AddService( Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetNetworkDataLocal().AddService(
aConfig->mEnterpriseNumber, &aConfig->mServiceData[0], aConfig->mServiceDataLength, aConfig->mEnterpriseNumber, &aConfig->mServiceData[0], aConfig->mServiceDataLength,
aConfig->mServerConfig.mStable, &aConfig->mServerConfig.mServerData[0], aConfig->mServerConfig.mServerDataLength aConfig->mServerConfig.mStable, &aConfig->mServerConfig.mServerData[0], aConfig->mServerConfig.mServerDataLength
); );
@@ -64,17 +67,21 @@ otError otServerAddService(otInstance *aInstance, const otServiceConfig *aConfig
otError otServerRemoveService(otInstance *aInstance, uint32_t aEnterpriseNumber, uint8_t *aServiceData, otError otServerRemoveService(otInstance *aInstance, uint32_t aEnterpriseNumber, uint8_t *aServiceData,
uint8_t aServiceDataLength) uint8_t aServiceDataLength)
{ {
return aInstance->mThreadNetif.GetNetworkDataLocal().RemoveService(aEnterpriseNumber, aServiceData, aServiceDataLength); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetNetworkDataLocal().RemoveService(aEnterpriseNumber, aServiceData,
aServiceDataLength);
} }
otError otServerGetNextService(otInstance *aInstance, otNetworkDataIterator *aIterator, otError otServerGetNextService(otInstance *aInstance, otNetworkDataIterator *aIterator,
otServiceConfig *aConfig) otServiceConfig *aConfig)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aIterator && aConfig, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aIterator && aConfig, error = OT_ERROR_INVALID_ARGS);
error = aInstance->mThreadNetif.GetNetworkDataLocal().GetNextService(aIterator, aConfig); error = instance.GetThreadNetif().GetNetworkDataLocal().GetNextService(aIterator, aConfig);
exit: exit:
return error; return error;
@@ -82,7 +89,9 @@ exit:
otError otServerRegister(otInstance *aInstance) otError otServerRegister(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetNetworkDataLocal().SendServerDataNotification(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetNetworkDataLocal().SendServerDataNotification();
} }
#endif // OPENTHREAD_ENABLE_SERVICE #endif // OPENTHREAD_ENABLE_SERVICE
+6 -3
View File
@@ -37,17 +37,19 @@
#include <openthread/tasklet.h> #include <openthread/tasklet.h>
#include "openthread-instance.h"
#include "common/code_utils.hpp" #include "common/code_utils.hpp"
#include "common/instance.hpp"
#include "common/logging.hpp" #include "common/logging.hpp"
using namespace ot; using namespace ot;
void otTaskletsProcess(otInstance *aInstance) void otTaskletsProcess(otInstance *aInstance)
{ {
Instance &instance = *static_cast<Instance *>(aInstance);
otLogFuncEntry(); otLogFuncEntry();
VerifyOrExit(otInstanceIsInitialized(aInstance)); VerifyOrExit(otInstanceIsInitialized(aInstance));
aInstance->mTaskletScheduler.ProcessQueuedTasklets(); instance.GetTaskletScheduler().ProcessQueuedTasklets();
exit: exit:
otLogFuncExit(); otLogFuncExit();
@@ -56,9 +58,10 @@ exit:
bool otTaskletsArePending(otInstance *aInstance) bool otTaskletsArePending(otInstance *aInstance)
{ {
bool retval = false; bool retval = false;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(otInstanceIsInitialized(aInstance)); VerifyOrExit(otInstanceIsInitialized(aInstance));
retval = aInstance->mTaskletScheduler.AreTaskletsPending(); retval = instance.GetTaskletScheduler().AreTaskletsPending();
exit: exit:
return retval; return retval;
+127 -62
View File
@@ -38,7 +38,7 @@
#include <openthread/thread.h> #include <openthread/thread.h>
#include <openthread/platform/settings.h> #include <openthread/platform/settings.h>
#include "openthread-instance.h" #include "common/instance.hpp"
#include "common/logging.hpp" #include "common/logging.hpp"
#include "common/settings.hpp" #include "common/settings.hpp"
@@ -46,37 +46,44 @@ using namespace ot;
uint32_t otThreadGetChildTimeout(otInstance *aInstance) uint32_t otThreadGetChildTimeout(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMle().GetTimeout(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().GetTimeout();
} }
void otThreadSetChildTimeout(otInstance *aInstance, uint32_t aTimeout) void otThreadSetChildTimeout(otInstance *aInstance, uint32_t aTimeout)
{ {
aInstance->mThreadNetif.GetMle().SetTimeout(aTimeout); Instance &instance = *static_cast<Instance *>(aInstance);
instance.GetThreadNetif().GetMle().SetTimeout(aTimeout);
} }
const uint8_t *otThreadGetExtendedPanId(otInstance *aInstance) const uint8_t *otThreadGetExtendedPanId(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMac().GetExtendedPanId(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMac().GetExtendedPanId();
} }
otError otThreadSetExtendedPanId(otInstance *aInstance, const uint8_t *aExtendedPanId) otError otThreadSetExtendedPanId(otInstance *aInstance, const uint8_t *aExtendedPanId)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
uint8_t mlPrefix[8]; uint8_t mlPrefix[8];
VerifyOrExit(aInstance->mThreadNetif.GetMle().GetRole() == OT_DEVICE_ROLE_DISABLED, VerifyOrExit(instance.GetThreadNetif().GetMle().GetRole() == OT_DEVICE_ROLE_DISABLED,
error = OT_ERROR_INVALID_STATE); error = OT_ERROR_INVALID_STATE);
aInstance->mThreadNetif.GetMac().SetExtendedPanId(aExtendedPanId); instance.GetThreadNetif().GetMac().SetExtendedPanId(aExtendedPanId);
mlPrefix[0] = 0xfd; mlPrefix[0] = 0xfd;
memcpy(mlPrefix + 1, aExtendedPanId, 5); memcpy(mlPrefix + 1, aExtendedPanId, 5);
mlPrefix[6] = 0x00; mlPrefix[6] = 0x00;
mlPrefix[7] = 0x00; mlPrefix[7] = 0x00;
aInstance->mThreadNetif.GetMle().SetMeshLocalPrefix(mlPrefix); instance.GetThreadNetif().GetMle().SetMeshLocalPrefix(mlPrefix);
aInstance->mThreadNetif.GetActiveDataset().Clear(); instance.GetThreadNetif().GetActiveDataset().Clear();
aInstance->mThreadNetif.GetPendingDataset().Clear(); instance.GetThreadNetif().GetPendingDataset().Clear();
exit: exit:
return error; return error;
@@ -85,10 +92,11 @@ exit:
otError otThreadGetLeaderRloc(otInstance *aInstance, otIp6Address *aAddress) otError otThreadGetLeaderRloc(otInstance *aInstance, otIp6Address *aAddress)
{ {
otError error; otError error;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aAddress != NULL, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aAddress != NULL, error = OT_ERROR_INVALID_ARGS);
error = aInstance->mThreadNetif.GetMle().GetLeaderAddress(*static_cast<Ip6::Address *>(aAddress)); error = instance.GetThreadNetif().GetMle().GetLeaderAddress(*static_cast<Ip6::Address *>(aAddress));
exit: exit:
return error; return error;
@@ -97,7 +105,8 @@ exit:
otLinkModeConfig otThreadGetLinkMode(otInstance *aInstance) otLinkModeConfig otThreadGetLinkMode(otInstance *aInstance)
{ {
otLinkModeConfig config; otLinkModeConfig config;
uint8_t mode = aInstance->mThreadNetif.GetMle().GetDeviceMode(); Instance &instance = *static_cast<Instance *>(aInstance);
uint8_t mode = instance.GetThreadNetif().GetMle().GetDeviceMode();
memset(&config, 0, sizeof(otLinkModeConfig)); memset(&config, 0, sizeof(otLinkModeConfig));
@@ -127,6 +136,7 @@ otLinkModeConfig otThreadGetLinkMode(otInstance *aInstance)
otError otThreadSetLinkMode(otInstance *aInstance, otLinkModeConfig aConfig) otError otThreadSetLinkMode(otInstance *aInstance, otLinkModeConfig aConfig)
{ {
uint8_t mode = 0; uint8_t mode = 0;
Instance &instance = *static_cast<Instance *>(aInstance);
if (aConfig.mRxOnWhenIdle) if (aConfig.mRxOnWhenIdle)
{ {
@@ -148,25 +158,28 @@ otError otThreadSetLinkMode(otInstance *aInstance, otLinkModeConfig aConfig)
mode |= Mle::ModeTlv::kModeFullNetworkData; mode |= Mle::ModeTlv::kModeFullNetworkData;
} }
return aInstance->mThreadNetif.GetMle().SetDeviceMode(mode); return instance.GetThreadNetif().GetMle().SetDeviceMode(mode);
} }
const otMasterKey *otThreadGetMasterKey(otInstance *aInstance) const otMasterKey *otThreadGetMasterKey(otInstance *aInstance)
{ {
return &aInstance->mThreadNetif.GetKeyManager().GetMasterKey(); Instance &instance = *static_cast<Instance *>(aInstance);
return &instance.GetThreadNetif().GetKeyManager().GetMasterKey();
} }
otError otThreadSetMasterKey(otInstance *aInstance, const otMasterKey *aKey) otError otThreadSetMasterKey(otInstance *aInstance, const otMasterKey *aKey)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aKey != NULL, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aKey != NULL, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aInstance->mThreadNetif.GetMle().GetRole() == OT_DEVICE_ROLE_DISABLED, VerifyOrExit(instance.GetThreadNetif().GetMle().GetRole() == OT_DEVICE_ROLE_DISABLED,
error = OT_ERROR_INVALID_STATE); error = OT_ERROR_INVALID_STATE);
error = aInstance->mThreadNetif.GetKeyManager().SetMasterKey(*aKey); error = instance.GetThreadNetif().GetKeyManager().SetMasterKey(*aKey);
aInstance->mThreadNetif.GetActiveDataset().Clear(); instance.GetThreadNetif().GetActiveDataset().Clear();
aInstance->mThreadNetif.GetPendingDataset().Clear(); instance.GetThreadNetif().GetPendingDataset().Clear();
exit: exit:
return error; return error;
@@ -174,24 +187,29 @@ exit:
const otIp6Address *otThreadGetMeshLocalEid(otInstance *aInstance) const otIp6Address *otThreadGetMeshLocalEid(otInstance *aInstance)
{ {
return &aInstance->mThreadNetif.GetMle().GetMeshLocal64(); Instance &instance = *static_cast<Instance *>(aInstance);
return &instance.GetThreadNetif().GetMle().GetMeshLocal64();
} }
const uint8_t *otThreadGetMeshLocalPrefix(otInstance *aInstance) const uint8_t *otThreadGetMeshLocalPrefix(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMle().GetMeshLocalPrefix(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().GetMeshLocalPrefix();
} }
otError otThreadSetMeshLocalPrefix(otInstance *aInstance, const uint8_t *aMeshLocalPrefix) otError otThreadSetMeshLocalPrefix(otInstance *aInstance, const uint8_t *aMeshLocalPrefix)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aInstance->mThreadNetif.GetMle().GetRole() == OT_DEVICE_ROLE_DISABLED, VerifyOrExit(instance.GetThreadNetif().GetMle().GetRole() == OT_DEVICE_ROLE_DISABLED,
error = OT_ERROR_INVALID_STATE); error = OT_ERROR_INVALID_STATE);
error = aInstance->mThreadNetif.GetMle().SetMeshLocalPrefix(aMeshLocalPrefix); error = instance.GetThreadNetif().GetMle().SetMeshLocalPrefix(aMeshLocalPrefix);
aInstance->mThreadNetif.GetActiveDataset().Clear(); instance.GetThreadNetif().GetActiveDataset().Clear();
aInstance->mThreadNetif.GetPendingDataset().Clear(); instance.GetThreadNetif().GetPendingDataset().Clear();
exit: exit:
return error; return error;
@@ -199,24 +217,29 @@ exit:
const otIp6Address *otThreadGetLinkLocalIp6Address(otInstance *aInstance) const otIp6Address *otThreadGetLinkLocalIp6Address(otInstance *aInstance)
{ {
return &aInstance->mThreadNetif.GetMle().GetLinkLocalAddress(); Instance &instance = *static_cast<Instance *>(aInstance);
return &instance.GetThreadNetif().GetMle().GetLinkLocalAddress();
} }
const char *otThreadGetNetworkName(otInstance *aInstance) const char *otThreadGetNetworkName(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMac().GetNetworkName(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMac().GetNetworkName();
} }
otError otThreadSetNetworkName(otInstance *aInstance, const char *aNetworkName) otError otThreadSetNetworkName(otInstance *aInstance, const char *aNetworkName)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aInstance->mThreadNetif.GetMle().GetRole() == OT_DEVICE_ROLE_DISABLED, VerifyOrExit(instance.GetThreadNetif().GetMle().GetRole() == OT_DEVICE_ROLE_DISABLED,
error = OT_ERROR_INVALID_STATE); error = OT_ERROR_INVALID_STATE);
error = aInstance->mThreadNetif.GetMac().SetNetworkName(aNetworkName); error = instance.GetThreadNetif().GetMac().SetNetworkName(aNetworkName);
aInstance->mThreadNetif.GetActiveDataset().Clear(); instance.GetThreadNetif().GetActiveDataset().Clear();
aInstance->mThreadNetif.GetPendingDataset().Clear(); instance.GetThreadNetif().GetPendingDataset().Clear();
exit: exit:
return error; return error;
@@ -224,41 +247,54 @@ exit:
uint32_t otThreadGetKeySequenceCounter(otInstance *aInstance) uint32_t otThreadGetKeySequenceCounter(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetKeyManager().GetCurrentKeySequence(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetKeyManager().GetCurrentKeySequence();
} }
void otThreadSetKeySequenceCounter(otInstance *aInstance, uint32_t aKeySequenceCounter) void otThreadSetKeySequenceCounter(otInstance *aInstance, uint32_t aKeySequenceCounter)
{ {
aInstance->mThreadNetif.GetKeyManager().SetCurrentKeySequence(aKeySequenceCounter); Instance &instance = *static_cast<Instance *>(aInstance);
instance.GetThreadNetif().GetKeyManager().SetCurrentKeySequence(aKeySequenceCounter);
} }
uint32_t otThreadGetKeySwitchGuardTime(otInstance *aInstance) uint32_t otThreadGetKeySwitchGuardTime(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetKeyManager().GetKeySwitchGuardTime(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetKeyManager().GetKeySwitchGuardTime();
} }
void otThreadSetKeySwitchGuardTime(otInstance *aInstance, uint32_t aKeySwitchGuardTime) void otThreadSetKeySwitchGuardTime(otInstance *aInstance, uint32_t aKeySwitchGuardTime)
{ {
aInstance->mThreadNetif.GetKeyManager().SetKeySwitchGuardTime(aKeySwitchGuardTime); Instance &instance = *static_cast<Instance *>(aInstance);
instance.GetThreadNetif().GetKeyManager().SetKeySwitchGuardTime(aKeySwitchGuardTime);
} }
otError otThreadBecomeDetached(otInstance *aInstance) otError otThreadBecomeDetached(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMle().BecomeDetached(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().BecomeDetached();
} }
otError otThreadBecomeChild(otInstance *aInstance) otError otThreadBecomeChild(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMle().BecomeChild(Mle::kAttachAny); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().BecomeChild(Mle::kAttachAny);
} }
otError otThreadGetNextNeighborInfo(otInstance *aInstance, otNeighborInfoIterator *aIterator, otNeighborInfo *aInfo) otError otThreadGetNextNeighborInfo(otInstance *aInstance, otNeighborInfoIterator *aIterator, otNeighborInfo *aInfo)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit((aInfo != NULL) && (aIterator != NULL), error = OT_ERROR_INVALID_ARGS); VerifyOrExit((aInfo != NULL) && (aIterator != NULL), error = OT_ERROR_INVALID_ARGS);
error = aInstance->mThreadNetif.GetMle().GetNextNeighborInfo(*aIterator, *aInfo); error = instance.GetThreadNetif().GetMle().GetNextNeighborInfo(*aIterator, *aInfo);
exit: exit:
return error; return error;
@@ -266,16 +302,19 @@ exit:
otDeviceRole otThreadGetDeviceRole(otInstance *aInstance) otDeviceRole otThreadGetDeviceRole(otInstance *aInstance)
{ {
return static_cast<otDeviceRole>(aInstance->mThreadNetif.GetMle().GetRole()); Instance &instance = *static_cast<Instance *>(aInstance);
return static_cast<otDeviceRole>(instance.GetThreadNetif().GetMle().GetRole());
} }
otError otThreadGetLeaderData(otInstance *aInstance, otLeaderData *aLeaderData) otError otThreadGetLeaderData(otInstance *aInstance, otLeaderData *aLeaderData)
{ {
otError error; otError error;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aLeaderData != NULL, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aLeaderData != NULL, error = OT_ERROR_INVALID_ARGS);
error = aInstance->mThreadNetif.GetMle().GetLeaderData(*aLeaderData); error = instance.GetThreadNetif().GetMle().GetLeaderData(*aLeaderData);
exit: exit:
return error; return error;
@@ -283,32 +322,41 @@ exit:
uint8_t otThreadGetLeaderRouterId(otInstance *aInstance) uint8_t otThreadGetLeaderRouterId(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMle().GetLeaderDataTlv().GetLeaderRouterId(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().GetLeaderDataTlv().GetLeaderRouterId();
} }
uint8_t otThreadGetLeaderWeight(otInstance *aInstance) uint8_t otThreadGetLeaderWeight(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMle().GetLeaderDataTlv().GetWeighting(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().GetLeaderDataTlv().GetWeighting();
} }
uint32_t otThreadGetPartitionId(otInstance *aInstance) uint32_t otThreadGetPartitionId(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMle().GetLeaderDataTlv().GetPartitionId(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().GetLeaderDataTlv().GetPartitionId();
} }
uint16_t otThreadGetRloc16(otInstance *aInstance) uint16_t otThreadGetRloc16(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMle().GetRloc16(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().GetRloc16();
} }
otError otThreadGetParentInfo(otInstance *aInstance, otRouterInfo *aParentInfo) otError otThreadGetParentInfo(otInstance *aInstance, otRouterInfo *aParentInfo)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
Router *parent; Router *parent;
VerifyOrExit(aParentInfo != NULL, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aParentInfo != NULL, error = OT_ERROR_INVALID_ARGS);
parent = aInstance->mThreadNetif.GetMle().GetParent(); parent = instance.GetThreadNetif().GetMle().GetParent();
memcpy(aParentInfo->mExtAddress.m8, &parent->GetExtAddress(), sizeof(aParentInfo->mExtAddress)); memcpy(aParentInfo->mExtAddress.m8, &parent->GetExtAddress(), sizeof(aParentInfo->mExtAddress));
aParentInfo->mRloc16 = parent->GetRloc16(); aParentInfo->mRloc16 = parent->GetRloc16();
@@ -329,11 +377,12 @@ exit:
otError otThreadGetParentAverageRssi(otInstance *aInstance, int8_t *aParentRssi) otError otThreadGetParentAverageRssi(otInstance *aInstance, int8_t *aParentRssi)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
Router *parent; Router *parent;
VerifyOrExit(aParentRssi != NULL, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aParentRssi != NULL, error = OT_ERROR_INVALID_ARGS);
parent = aInstance->mThreadNetif.GetMle().GetParent(); parent = instance.GetThreadNetif().GetMle().GetParent();
*aParentRssi = parent->GetLinkInfo().GetAverageRss(); *aParentRssi = parent->GetLinkInfo().GetAverageRss();
VerifyOrExit(*aParentRssi != OT_RADIO_RSSI_INVALID, error = OT_ERROR_FAILED); VerifyOrExit(*aParentRssi != OT_RADIO_RSSI_INVALID, error = OT_ERROR_FAILED);
@@ -345,11 +394,12 @@ exit:
otError otThreadGetParentLastRssi(otInstance *aInstance, int8_t *aLastRssi) otError otThreadGetParentLastRssi(otInstance *aInstance, int8_t *aLastRssi)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
Router *parent; Router *parent;
VerifyOrExit(aLastRssi != NULL, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aLastRssi != NULL, error = OT_ERROR_INVALID_ARGS);
parent = aInstance->mThreadNetif.GetMle().GetParent(); parent = instance.GetThreadNetif().GetMle().GetParent();
*aLastRssi = parent->GetLinkInfo().GetLastRss(); *aLastRssi = parent->GetLinkInfo().GetLastRss();
VerifyOrExit(*aLastRssi != OT_RADIO_RSSI_INVALID, error = OT_ERROR_FAILED); VerifyOrExit(*aLastRssi != OT_RADIO_RSSI_INVALID, error = OT_ERROR_FAILED);
@@ -398,43 +448,50 @@ const char *otGetVersionString(void)
void otThreadSetReceiveDiagnosticGetCallback(otInstance *aInstance, otReceiveDiagnosticGetCallback aCallback, void otThreadSetReceiveDiagnosticGetCallback(otInstance *aInstance, otReceiveDiagnosticGetCallback aCallback,
void *aCallbackContext) void *aCallbackContext)
{ {
aInstance->mThreadNetif.GetNetworkDiagnostic().SetReceiveDiagnosticGetCallback(aCallback, aCallbackContext); Instance &instance = *static_cast<Instance *>(aInstance);
instance.GetThreadNetif().GetNetworkDiagnostic().SetReceiveDiagnosticGetCallback(aCallback, aCallbackContext);
} }
otError otThreadSendDiagnosticGet(otInstance *aInstance, const otIp6Address *aDestination, otError otThreadSendDiagnosticGet(otInstance *aInstance, const otIp6Address *aDestination,
const uint8_t aTlvTypes[], uint8_t aCount) const uint8_t aTlvTypes[], uint8_t aCount)
{ {
return aInstance->mThreadNetif.GetNetworkDiagnostic().SendDiagnosticGet(*static_cast<const Ip6::Address *> Instance &instance = *static_cast<Instance *>(aInstance);
(aDestination),
aTlvTypes, return instance.GetThreadNetif().GetNetworkDiagnostic().SendDiagnosticGet(*static_cast<const Ip6::Address *>
aCount); (aDestination),
aTlvTypes,
aCount);
} }
otError otThreadSendDiagnosticReset(otInstance *aInstance, const otIp6Address *aDestination, otError otThreadSendDiagnosticReset(otInstance *aInstance, const otIp6Address *aDestination,
const uint8_t aTlvTypes[], uint8_t aCount) const uint8_t aTlvTypes[], uint8_t aCount)
{ {
return aInstance->mThreadNetif.GetNetworkDiagnostic().SendDiagnosticReset(*static_cast<const Ip6::Address *> Instance &instance = *static_cast<Instance *>(aInstance);
(aDestination),
aTlvTypes, return instance.GetThreadNetif().GetNetworkDiagnostic().SendDiagnosticReset(*static_cast<const Ip6::Address *>
aCount); (aDestination),
aTlvTypes,
aCount);
} }
#endif // OPENTHREAD_FTD || OPENTHREAD_ENABLE_MTD_NETWORK_DIAGNOSTIC #endif // OPENTHREAD_FTD || OPENTHREAD_ENABLE_MTD_NETWORK_DIAGNOSTIC
otError otThreadSetEnabled(otInstance *aInstance, bool aEnabled) otError otThreadSetEnabled(otInstance *aInstance, bool aEnabled)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
otLogFuncEntry(); otLogFuncEntry();
if (aEnabled) if (aEnabled)
{ {
VerifyOrExit(aInstance->mThreadNetif.GetMac().GetPanId() != Mac::kPanIdBroadcast, VerifyOrExit(instance.GetThreadNetif().GetMac().GetPanId() != Mac::kPanIdBroadcast,
error = OT_ERROR_INVALID_STATE); error = OT_ERROR_INVALID_STATE);
error = aInstance->mThreadNetif.GetMle().Start(true, false); error = instance.GetThreadNetif().GetMle().Start(true, false);
} }
else else
{ {
error = aInstance->mThreadNetif.GetMle().Stop(true); error = instance.GetThreadNetif().GetMle().Stop(true);
} }
exit: exit:
@@ -475,22 +532,30 @@ otError otThreadSetAutoStart(otInstance *aInstance, bool aStartAutomatically)
bool otThreadIsSingleton(otInstance *aInstance) bool otThreadIsSingleton(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMle().IsSingleton(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().IsSingleton();
} }
otError otThreadDiscover(otInstance *aInstance, uint32_t aScanChannels, uint16_t aPanId, bool aJoiner, otError otThreadDiscover(otInstance *aInstance, uint32_t aScanChannels, uint16_t aPanId, bool aJoiner,
bool aEnableEui64Filtering, otHandleActiveScanResult aCallback, void *aCallbackContext) bool aEnableEui64Filtering, otHandleActiveScanResult aCallback, void *aCallbackContext)
{ {
return aInstance->mThreadNetif.GetMle().Discover(aScanChannels, aPanId, aJoiner, aEnableEui64Filtering, aCallback, Instance &instance = *static_cast<Instance *>(aInstance);
aCallbackContext);
return instance.GetThreadNetif().GetMle().Discover(aScanChannels, aPanId, aJoiner, aEnableEui64Filtering, aCallback,
aCallbackContext);
} }
bool otThreadIsDiscoverInProgress(otInstance *aInstance) bool otThreadIsDiscoverInProgress(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMle().IsDiscoverInProgress(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().IsDiscoverInProgress();
} }
const otIpCounters *otThreadGetIp6Counters(otInstance *aInstance) const otIpCounters *otThreadGetIp6Counters(otInstance *aInstance)
{ {
return &aInstance->mThreadNetif.GetMeshForwarder().GetCounters(); Instance &instance = *static_cast<Instance *>(aInstance);
return &instance.GetThreadNetif().GetMeshForwarder().GetCounters();
} }
+108 -42
View File
@@ -38,7 +38,8 @@
#if OPENTHREAD_FTD #if OPENTHREAD_FTD
#include <openthread/thread_ftd.h> #include <openthread/thread_ftd.h>
#include "openthread-instance.h"
#include "common/instance.hpp"
#include "thread/mle_constants.hpp" #include "thread/mle_constants.hpp"
using namespace ot; using namespace ot;
@@ -46,109 +47,145 @@ using namespace ot;
uint8_t otThreadGetMaxAllowedChildren(otInstance *aInstance) uint8_t otThreadGetMaxAllowedChildren(otInstance *aInstance)
{ {
uint8_t aNumChildren; uint8_t aNumChildren;
Instance &instance = *static_cast<Instance *>(aInstance);
(void)aInstance->mThreadNetif.GetMle().GetChildren(&aNumChildren); (void)instance.GetThreadNetif().GetMle().GetChildren(&aNumChildren);
return aNumChildren; return aNumChildren;
} }
otError otThreadSetMaxAllowedChildren(otInstance *aInstance, uint8_t aMaxChildren) otError otThreadSetMaxAllowedChildren(otInstance *aInstance, uint8_t aMaxChildren)
{ {
return aInstance->mThreadNetif.GetMle().SetMaxAllowedChildren(aMaxChildren); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().SetMaxAllowedChildren(aMaxChildren);
} }
bool otThreadIsRouterRoleEnabled(otInstance *aInstance) bool otThreadIsRouterRoleEnabled(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMle().IsRouterRoleEnabled(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().IsRouterRoleEnabled();
} }
void otThreadSetRouterRoleEnabled(otInstance *aInstance, bool aEnabled) void otThreadSetRouterRoleEnabled(otInstance *aInstance, bool aEnabled)
{ {
aInstance->mThreadNetif.GetMle().SetRouterRoleEnabled(aEnabled); Instance &instance = *static_cast<Instance *>(aInstance);
instance.GetThreadNetif().GetMle().SetRouterRoleEnabled(aEnabled);
} }
otError otThreadSetPreferredRouterId(otInstance *aInstance, uint8_t aRouterId) otError otThreadSetPreferredRouterId(otInstance *aInstance, uint8_t aRouterId)
{ {
return aInstance->mThreadNetif.GetMle().SetPreferredRouterId(aRouterId); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().SetPreferredRouterId(aRouterId);
} }
uint8_t otThreadGetLocalLeaderWeight(otInstance *aInstance) uint8_t otThreadGetLocalLeaderWeight(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMle().GetLeaderWeight(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().GetLeaderWeight();
} }
void otThreadSetLocalLeaderWeight(otInstance *aInstance, uint8_t aWeight) void otThreadSetLocalLeaderWeight(otInstance *aInstance, uint8_t aWeight)
{ {
aInstance->mThreadNetif.GetMle().SetLeaderWeight(aWeight); Instance &instance = *static_cast<Instance *>(aInstance);
instance.GetThreadNetif().GetMle().SetLeaderWeight(aWeight);
} }
uint32_t otThreadGetLocalLeaderPartitionId(otInstance *aInstance) uint32_t otThreadGetLocalLeaderPartitionId(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMle().GetLeaderPartitionId(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().GetLeaderPartitionId();
} }
void otThreadSetLocalLeaderPartitionId(otInstance *aInstance, uint32_t aPartitionId) void otThreadSetLocalLeaderPartitionId(otInstance *aInstance, uint32_t aPartitionId)
{ {
return aInstance->mThreadNetif.GetMle().SetLeaderPartitionId(aPartitionId); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().SetLeaderPartitionId(aPartitionId);
} }
uint16_t otThreadGetJoinerUdpPort(otInstance *aInstance) uint16_t otThreadGetJoinerUdpPort(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetJoinerRouter().GetJoinerUdpPort(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetJoinerRouter().GetJoinerUdpPort();
} }
otError otThreadSetJoinerUdpPort(otInstance *aInstance, uint16_t aJoinerUdpPort) otError otThreadSetJoinerUdpPort(otInstance *aInstance, uint16_t aJoinerUdpPort)
{ {
return aInstance->mThreadNetif.GetJoinerRouter().SetJoinerUdpPort(aJoinerUdpPort); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetJoinerRouter().SetJoinerUdpPort(aJoinerUdpPort);
} }
uint32_t otThreadGetContextIdReuseDelay(otInstance *aInstance) uint32_t otThreadGetContextIdReuseDelay(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetNetworkDataLeader().GetContextIdReuseDelay(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetNetworkDataLeader().GetContextIdReuseDelay();
} }
void otThreadSetContextIdReuseDelay(otInstance *aInstance, uint32_t aDelay) void otThreadSetContextIdReuseDelay(otInstance *aInstance, uint32_t aDelay)
{ {
aInstance->mThreadNetif.GetNetworkDataLeader().SetContextIdReuseDelay(aDelay); Instance &instance = *static_cast<Instance *>(aInstance);
instance.GetThreadNetif().GetNetworkDataLeader().SetContextIdReuseDelay(aDelay);
} }
uint8_t otThreadGetNetworkIdTimeout(otInstance *aInstance) uint8_t otThreadGetNetworkIdTimeout(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMle().GetNetworkIdTimeout(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().GetNetworkIdTimeout();
} }
void otThreadSetNetworkIdTimeout(otInstance *aInstance, uint8_t aTimeout) void otThreadSetNetworkIdTimeout(otInstance *aInstance, uint8_t aTimeout)
{ {
aInstance->mThreadNetif.GetMle().SetNetworkIdTimeout((uint8_t)aTimeout); Instance &instance = *static_cast<Instance *>(aInstance);
instance.GetThreadNetif().GetMle().SetNetworkIdTimeout((uint8_t)aTimeout);
} }
uint8_t otThreadGetRouterUpgradeThreshold(otInstance *aInstance) uint8_t otThreadGetRouterUpgradeThreshold(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMle().GetRouterUpgradeThreshold(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().GetRouterUpgradeThreshold();
} }
void otThreadSetRouterUpgradeThreshold(otInstance *aInstance, uint8_t aThreshold) void otThreadSetRouterUpgradeThreshold(otInstance *aInstance, uint8_t aThreshold)
{ {
aInstance->mThreadNetif.GetMle().SetRouterUpgradeThreshold(aThreshold); Instance &instance = *static_cast<Instance *>(aInstance);
instance.GetThreadNetif().GetMle().SetRouterUpgradeThreshold(aThreshold);
} }
otError otThreadReleaseRouterId(otInstance *aInstance, uint8_t aRouterId) otError otThreadReleaseRouterId(otInstance *aInstance, uint8_t aRouterId)
{ {
return aInstance->mThreadNetif.GetMle().ReleaseRouterId(aRouterId); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().ReleaseRouterId(aRouterId);
} }
otError otThreadBecomeRouter(otInstance *aInstance) otError otThreadBecomeRouter(otInstance *aInstance)
{ {
otError error = OT_ERROR_INVALID_STATE; otError error = OT_ERROR_INVALID_STATE;
Instance &instance = *static_cast<Instance *>(aInstance);
switch (aInstance->mThreadNetif.GetMle().GetRole()) switch (instance.GetThreadNetif().GetMle().GetRole())
{ {
case OT_DEVICE_ROLE_DISABLED: case OT_DEVICE_ROLE_DISABLED:
case OT_DEVICE_ROLE_DETACHED: case OT_DEVICE_ROLE_DETACHED:
break; break;
case OT_DEVICE_ROLE_CHILD: case OT_DEVICE_ROLE_CHILD:
error = aInstance->mThreadNetif.GetMle().BecomeRouter(ThreadStatusTlv::kHaveChildIdRequest); error = instance.GetThreadNetif().GetMle().BecomeRouter(ThreadStatusTlv::kHaveChildIdRequest);
break; break;
case OT_DEVICE_ROLE_ROUTER: case OT_DEVICE_ROLE_ROUTER:
@@ -162,36 +199,47 @@ otError otThreadBecomeRouter(otInstance *aInstance)
otError otThreadBecomeLeader(otInstance *aInstance) otError otThreadBecomeLeader(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMle().BecomeLeader(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().BecomeLeader();
} }
uint8_t otThreadGetRouterDowngradeThreshold(otInstance *aInstance) uint8_t otThreadGetRouterDowngradeThreshold(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMle().GetRouterDowngradeThreshold(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().GetRouterDowngradeThreshold();
} }
void otThreadSetRouterDowngradeThreshold(otInstance *aInstance, uint8_t aThreshold) void otThreadSetRouterDowngradeThreshold(otInstance *aInstance, uint8_t aThreshold)
{ {
aInstance->mThreadNetif.GetMle().SetRouterDowngradeThreshold(aThreshold); Instance &instance = *static_cast<Instance *>(aInstance);
instance.GetThreadNetif().GetMle().SetRouterDowngradeThreshold(aThreshold);
} }
uint8_t otThreadGetRouterSelectionJitter(otInstance *aInstance) uint8_t otThreadGetRouterSelectionJitter(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMle().GetRouterSelectionJitter(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().GetRouterSelectionJitter();
} }
void otThreadSetRouterSelectionJitter(otInstance *aInstance, uint8_t aRouterJitter) void otThreadSetRouterSelectionJitter(otInstance *aInstance, uint8_t aRouterJitter)
{ {
aInstance->mThreadNetif.GetMle().SetRouterSelectionJitter(aRouterJitter); Instance &instance = *static_cast<Instance *>(aInstance);
instance.GetThreadNetif().GetMle().SetRouterSelectionJitter(aRouterJitter);
} }
otError otThreadGetChildInfoById(otInstance *aInstance, uint16_t aChildId, otChildInfo *aChildInfo) otError otThreadGetChildInfoById(otInstance *aInstance, uint16_t aChildId, otChildInfo *aChildInfo)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aChildInfo != NULL, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aChildInfo != NULL, error = OT_ERROR_INVALID_ARGS);
error = aInstance->mThreadNetif.GetMle().GetChildInfoById(aChildId, *aChildInfo); error = instance.GetThreadNetif().GetMle().GetChildInfoById(aChildId, *aChildInfo);
exit: exit:
return error; return error;
@@ -200,10 +248,11 @@ exit:
otError otThreadGetChildInfoByIndex(otInstance *aInstance, uint8_t aChildIndex, otChildInfo *aChildInfo) otError otThreadGetChildInfoByIndex(otInstance *aInstance, uint8_t aChildIndex, otChildInfo *aChildInfo)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aChildInfo != NULL, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aChildInfo != NULL, error = OT_ERROR_INVALID_ARGS);
error = aInstance->mThreadNetif.GetMle().GetChildInfoByIndex(aChildIndex, *aChildInfo); error = instance.GetThreadNetif().GetMle().GetChildInfoByIndex(aChildIndex, *aChildInfo);
exit: exit:
return error; return error;
@@ -211,7 +260,9 @@ exit:
uint8_t otThreadGetRouterIdSequence(otInstance *aInstance) uint8_t otThreadGetRouterIdSequence(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMle().GetRouterIdSequence(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().GetRouterIdSequence();
} }
uint8_t otThreadGetMaxRouterId(otInstance *aInstance) uint8_t otThreadGetMaxRouterId(otInstance *aInstance)
@@ -223,10 +274,11 @@ uint8_t otThreadGetMaxRouterId(otInstance *aInstance)
otError otThreadGetRouterInfo(otInstance *aInstance, uint16_t aRouterId, otRouterInfo *aRouterInfo) otError otThreadGetRouterInfo(otInstance *aInstance, uint16_t aRouterId, otRouterInfo *aRouterInfo)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aRouterInfo != NULL, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aRouterInfo != NULL, error = OT_ERROR_INVALID_ARGS);
error = aInstance->mThreadNetif.GetMle().GetRouterInfo(aRouterId, *aRouterInfo); error = instance.GetThreadNetif().GetMle().GetRouterInfo(aRouterId, *aRouterInfo);
exit: exit:
return error; return error;
@@ -235,9 +287,10 @@ exit:
otError otThreadGetEidCacheEntry(otInstance *aInstance, uint8_t aIndex, otEidCacheEntry *aEntry) otError otThreadGetEidCacheEntry(otInstance *aInstance, uint8_t aIndex, otEidCacheEntry *aEntry)
{ {
otError error; otError error;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aEntry != NULL, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aEntry != NULL, error = OT_ERROR_INVALID_ARGS);
error = aInstance->mThreadNetif.GetAddressResolver().GetEntry(aIndex, *aEntry); error = instance.GetThreadNetif().GetAddressResolver().GetEntry(aIndex, *aEntry);
exit: exit:
return error; return error;
@@ -248,32 +301,37 @@ otError otThreadSetSteeringData(otInstance *aInstance, const otExtAddress *aExtA
otError error; otError error;
#if OPENTHREAD_CONFIG_ENABLE_STEERING_DATA_SET_OOB #if OPENTHREAD_CONFIG_ENABLE_STEERING_DATA_SET_OOB
error = aInstance->mThreadNetif.GetMle().SetSteeringData(aExtAddress); Instance &instance = *static_cast<Instance *>(aInstance);
error = instance.GetThreadNetif().GetMle().SetSteeringData(aExtAddress);
#else #else
OT_UNUSED_VARIABLE(aInstance); OT_UNUSED_VARIABLE(aInstance);
OT_UNUSED_VARIABLE(aExtAddress); OT_UNUSED_VARIABLE(aExtAddress);
error = OT_ERROR_DISABLED_FEATURE; error = OT_ERROR_DISABLED_FEATURE;
#endif // OPENTHREAD_CONFIG_ENABLE_STEERING_DATA_SET_OOB #endif
return error; return error;
} }
const uint8_t *otThreadGetPSKc(otInstance *aInstance) const uint8_t *otThreadGetPSKc(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetKeyManager().GetPSKc(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetKeyManager().GetPSKc();
} }
otError otThreadSetPSKc(otInstance *aInstance, const uint8_t *aPSKc) otError otThreadSetPSKc(otInstance *aInstance, const uint8_t *aPSKc)
{ {
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
VerifyOrExit(aInstance->mThreadNetif.GetMle().GetRole() == OT_DEVICE_ROLE_DISABLED, VerifyOrExit(instance.GetThreadNetif().GetMle().GetRole() == OT_DEVICE_ROLE_DISABLED,
error = OT_ERROR_INVALID_STATE); error = OT_ERROR_INVALID_STATE);
aInstance->mThreadNetif.GetKeyManager().SetPSKc(aPSKc); instance.GetThreadNetif().GetKeyManager().SetPSKc(aPSKc);
aInstance->mThreadNetif.GetActiveDataset().Clear(); instance.GetThreadNetif().GetActiveDataset().Clear();
aInstance->mThreadNetif.GetPendingDataset().Clear(); instance.GetThreadNetif().GetPendingDataset().Clear();
exit: exit:
return error; return error;
@@ -281,22 +339,30 @@ exit:
int8_t otThreadGetParentPriority(otInstance *aInstance) int8_t otThreadGetParentPriority(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMle().GetAssignParentPriority(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().GetAssignParentPriority();
} }
otError otThreadSetParentPriority(otInstance *aInstance, const int8_t aParentPriority) otError otThreadSetParentPriority(otInstance *aInstance, const int8_t aParentPriority)
{ {
return aInstance->mThreadNetif.GetMle().SetAssignParentPriority(aParentPriority); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().SetAssignParentPriority(aParentPriority);
} }
otThreadChildTableCallback otThreadGetChildTableCallback(otInstance *aInstance) otThreadChildTableCallback otThreadGetChildTableCallback(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetMle().GetChildTableChangedCallback(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().GetChildTableChangedCallback();
} }
void otThreadSetChildTableCallback(otInstance *aInstance, otThreadChildTableCallback aCallback) void otThreadSetChildTableCallback(otInstance *aInstance, otThreadChildTableCallback aCallback)
{ {
aInstance->mThreadNetif.GetMle().SetChildTableChangedCallback(aCallback); Instance &instance = *static_cast<Instance *>(aInstance);
instance.GetThreadNetif().GetMle().SetChildTableChangedCallback(aCallback);
} }
#endif // OPENTHREAD_FTD #endif // OPENTHREAD_FTD
+15 -5
View File
@@ -35,28 +35,38 @@
#include <openthread/tmf_proxy.h> #include <openthread/tmf_proxy.h>
#include "openthread-instance.h" #include "common/instance.hpp"
#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_TMF_PROXY #if OPENTHREAD_FTD && OPENTHREAD_ENABLE_TMF_PROXY
using namespace ot;
otError otTmfProxyStart(otInstance *aInstance, otTmfProxyStreamHandler aTmfProxyCallback, void *aContext) otError otTmfProxyStart(otInstance *aInstance, otTmfProxyStreamHandler aTmfProxyCallback, void *aContext)
{ {
return aInstance->mThreadNetif.GetTmfProxy().Start(aTmfProxyCallback, aContext); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetTmfProxy().Start(aTmfProxyCallback, aContext);
} }
otError otTmfProxyStop(otInstance *aInstance) otError otTmfProxyStop(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetTmfProxy().Stop(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetTmfProxy().Stop();
} }
otError otTmfProxySend(otInstance *aInstance, otMessage *aMessage, uint16_t aLocator, uint16_t aPort) otError otTmfProxySend(otInstance *aInstance, otMessage *aMessage, uint16_t aLocator, uint16_t aPort)
{ {
return aInstance->mThreadNetif.GetTmfProxy().Send(*static_cast<ot::Message *>(aMessage), aLocator, aPort); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetTmfProxy().Send(*static_cast<ot::Message *>(aMessage), aLocator, aPort);
} }
bool otTmfProxyIsEnabled(otInstance *aInstance) bool otTmfProxyIsEnabled(otInstance *aInstance)
{ {
return aInstance->mThreadNetif.GetTmfProxy().IsEnabled(); Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetTmfProxy().IsEnabled();
} }
#endif // OPENTHREAD_FTD && OPENTHREAD_ENABLE_TMF_PROXY #endif // OPENTHREAD_FTD && OPENTHREAD_ENABLE_TMF_PROXY
+19 -17
View File
@@ -35,13 +35,14 @@
#include <openthread/udp.h> #include <openthread/udp.h>
#include "openthread-instance.h" #include "common/instance.hpp"
using namespace ot; using namespace ot;
otMessage *otUdpNewMessage(otInstance *aInstance, bool aLinkSecurityEnabled) otMessage *otUdpNewMessage(otInstance *aInstance, bool aLinkSecurityEnabled)
{ {
Message *message = aInstance->mIp6.GetUdp().NewMessage(0); Instance &instance = *static_cast<Instance *>(aInstance);
Message *message = instance.GetIp6().GetUdp().NewMessage(0);
if (message) if (message)
{ {
@@ -54,12 +55,13 @@ otMessage *otUdpNewMessage(otInstance *aInstance, bool aLinkSecurityEnabled)
otError otUdpOpen(otInstance *aInstance, otUdpSocket *aSocket, otUdpReceive aCallback, void *aCallbackContext) otError otUdpOpen(otInstance *aInstance, otUdpSocket *aSocket, otUdpReceive aCallback, void *aCallbackContext)
{ {
otError error = OT_ERROR_INVALID_ARGS; otError error = OT_ERROR_INVALID_ARGS;
Ip6::UdpSocket *socket = static_cast<Ip6::UdpSocket *>(aSocket); Instance &instance = *static_cast<Instance *>(aInstance);
Ip6::UdpSocket &socket = *static_cast<Ip6::UdpSocket *>(aSocket);
if (socket->mTransport == NULL) if (socket.mTransport == NULL)
{ {
socket->mTransport = &aInstance->mIp6.GetUdp(); socket.mTransport = &instance.GetIp6().GetUdp();
error = socket->Open(aCallback, aCallbackContext); error = socket.Open(aCallback, aCallbackContext);
} }
return error; return error;
@@ -68,15 +70,15 @@ otError otUdpOpen(otInstance *aInstance, otUdpSocket *aSocket, otUdpReceive aCal
otError otUdpClose(otUdpSocket *aSocket) otError otUdpClose(otUdpSocket *aSocket)
{ {
otError error = OT_ERROR_INVALID_STATE; otError error = OT_ERROR_INVALID_STATE;
Ip6::UdpSocket *socket = static_cast<Ip6::UdpSocket *>(aSocket); Ip6::UdpSocket &socket = *static_cast<Ip6::UdpSocket *>(aSocket);
if (socket->mTransport != NULL) if (socket.mTransport != NULL)
{ {
error = socket->Close(); error = socket.Close();
if (error == OT_ERROR_NONE) if (error == OT_ERROR_NONE)
{ {
socket->mTransport = NULL; socket.mTransport = NULL;
} }
} }
@@ -85,19 +87,19 @@ otError otUdpClose(otUdpSocket *aSocket)
otError otUdpBind(otUdpSocket *aSocket, otSockAddr *aSockName) otError otUdpBind(otUdpSocket *aSocket, otSockAddr *aSockName)
{ {
Ip6::UdpSocket *socket = static_cast<Ip6::UdpSocket *>(aSocket); Ip6::UdpSocket &socket = *static_cast<Ip6::UdpSocket *>(aSocket);
return socket->Bind(*static_cast<const Ip6::SockAddr *>(aSockName)); return socket.Bind(*static_cast<const Ip6::SockAddr *>(aSockName));
} }
otError otUdpConnect(otUdpSocket *aSocket, otSockAddr *aSockName) otError otUdpConnect(otUdpSocket *aSocket, otSockAddr *aSockName)
{ {
Ip6::UdpSocket *socket = static_cast<Ip6::UdpSocket *>(aSocket); Ip6::UdpSocket &socket = *static_cast<Ip6::UdpSocket *>(aSocket);
return socket->Connect(*static_cast<const Ip6::SockAddr *>(aSockName)); return socket.Connect(*static_cast<const Ip6::SockAddr *>(aSockName));
} }
otError otUdpSend(otUdpSocket *aSocket, otMessage *aMessage, const otMessageInfo *aMessageInfo) otError otUdpSend(otUdpSocket *aSocket, otMessage *aMessage, const otMessageInfo *aMessageInfo)
{ {
Ip6::UdpSocket *socket = static_cast<Ip6::UdpSocket *>(aSocket); Ip6::UdpSocket &socket = *static_cast<Ip6::UdpSocket *>(aSocket);
return socket->SendTo(*static_cast<Message *>(aMessage), return socket.SendTo(*static_cast<Message *>(aMessage),
*static_cast<const Ip6::MessageInfo *>(aMessageInfo)); *static_cast<const Ip6::MessageInfo *>(aMessageInfo));
} }
+8 -8
View File
@@ -32,9 +32,9 @@
#include <openthread/platform/random.h> #include <openthread/platform/random.h>
#include "openthread-instance.h"
#include "common/code_utils.hpp" #include "common/code_utils.hpp"
#include "common/debug.hpp" #include "common/debug.hpp"
#include "common/instance.hpp"
#include "common/logging.hpp" #include "common/logging.hpp"
#include "net/ip6.hpp" #include "net/ip6.hpp"
#include "net/udp6.hpp" #include "net/udp6.hpp"
@@ -48,10 +48,10 @@
namespace ot { namespace ot {
namespace Coap { namespace Coap {
CoapBase::CoapBase(otInstance &aInstance, Timer::Handler aRetransmissionTimerHandler, CoapBase::CoapBase(Instance &aInstance, Timer::Handler aRetransmissionTimerHandler,
Timer::Handler aResponsesQueueTimerHandler): Timer::Handler aResponsesQueueTimerHandler):
InstanceLocator(aInstance), InstanceLocator(aInstance),
mSocket(aInstance.mThreadNetif.GetIp6().GetUdp()), mSocket(aInstance.GetThreadNetif().GetIp6().GetUdp()),
mRetransmissionTimer(aInstance, aRetransmissionTimerHandler, this), mRetransmissionTimer(aInstance, aRetransmissionTimerHandler, this),
mResources(NULL), mResources(NULL),
mContext(NULL), mContext(NULL),
@@ -744,7 +744,7 @@ CoapMetadata::CoapMetadata(bool aConfirmable, const Ip6::MessageInfo &aMessageIn
mConfirmable = aConfirmable; mConfirmable = aConfirmable;
} }
ResponsesQueue::ResponsesQueue(otInstance &aInstance, Timer::Handler aHandler, void *aContext): ResponsesQueue::ResponsesQueue(Instance &aInstance, Timer::Handler aHandler, void *aContext):
mQueue(), mQueue(),
mTimer(aInstance, aHandler, aContext) mTimer(aInstance, aHandler, aContext)
{ {
@@ -911,7 +911,7 @@ uint32_t EnqueuedResponseHeader::GetRemainingTime(void) const
return remainingTime >= 0 ? static_cast<uint32_t>(remainingTime) : 0; return remainingTime >= 0 ? static_cast<uint32_t>(remainingTime) : 0;
} }
Coap::Coap(otInstance &aInstance): Coap::Coap(Instance &aInstance):
CoapBase(aInstance, &Coap::HandleRetransmissionTimer, &Coap::HandleResponsesQueueTimer) CoapBase(aInstance, &Coap::HandleRetransmissionTimer, &Coap::HandleResponsesQueueTimer)
{ {
} }
@@ -921,7 +921,7 @@ Coap &Coap::GetOwner(const Context &aContext)
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
Coap &coap = *static_cast<Coap *>(aContext.GetContext()); Coap &coap = *static_cast<Coap *>(aContext.GetContext());
#else #else
Coap &coap = otGetThreadNetif().GetCoap(); Coap &coap = Instance::Get().GetThreadNetif().GetCoap();
OT_UNUSED_VARIABLE(aContext); OT_UNUSED_VARIABLE(aContext);
#endif #endif
return coap; return coap;
@@ -939,7 +939,7 @@ void Coap::HandleResponsesQueueTimer(Timer &aTimer)
#if OPENTHREAD_ENABLE_APPLICATION_COAP #if OPENTHREAD_ENABLE_APPLICATION_COAP
ApplicationCoap::ApplicationCoap(otInstance &aInstance): ApplicationCoap::ApplicationCoap(Instance &aInstance):
CoapBase(aInstance, &ApplicationCoap::HandleRetransmissionTimer, &ApplicationCoap::HandleResponsesQueueTimer) CoapBase(aInstance, &ApplicationCoap::HandleRetransmissionTimer, &ApplicationCoap::HandleResponsesQueueTimer)
{ {
} }
@@ -949,7 +949,7 @@ ApplicationCoap &ApplicationCoap::GetOwner(const Context &aContext)
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
ApplicationCoap &coap = *static_cast<ApplicationCoap *>(aContext.GetContext()); ApplicationCoap &coap = *static_cast<ApplicationCoap *>(aContext.GetContext());
#else #else
ApplicationCoap &coap = otGetInstance()->mApplicationCoap; ApplicationCoap &coap = Instance::Get().GetApplicationCoap();
OT_UNUSED_VARIABLE(aContext); OT_UNUSED_VARIABLE(aContext);
#endif #endif
return coap; return coap;
+4 -4
View File
@@ -337,7 +337,7 @@ public:
* @param[in] aContext A pointer to arbitrary context information (used along with timer handler). * @param[in] aContext A pointer to arbitrary context information (used along with timer handler).
* *
*/ */
ResponsesQueue(otInstance &aInstance, Timer::Handler aHandler, void *aContext); ResponsesQueue(Instance &aInstance, Timer::Handler aHandler, void *aContext);
/** /**
* Add given response to the cache. * Add given response to the cache.
@@ -656,7 +656,7 @@ protected:
* @param[in] aResponsesQueueTimerHandler A timer handler provided by sub-class for `mReponsesQueue` timer. * @param[in] aResponsesQueueTimerHandler A timer handler provided by sub-class for `mReponsesQueue` timer.
* *
*/ */
CoapBase(otInstance &aInstance, Timer::Handler aRetransmissionTimerHandler, CoapBase(Instance &aInstance, Timer::Handler aRetransmissionTimerHandler,
Timer::Handler aResponsesQueueTimerHandler); Timer::Handler aResponsesQueueTimerHandler);
/** /**
@@ -747,7 +747,7 @@ public:
* @param[in] aInstance A reference to the OpenThread instance. * @param[in] aInstance A reference to the OpenThread instance.
* *
*/ */
Coap(otInstance &aInstance); Coap(Instance &aInstance);
private: private:
static Coap &GetOwner(const Context &aContext); static Coap &GetOwner(const Context &aContext);
@@ -770,7 +770,7 @@ public:
* @param[in] aInstance A reference to the OpenThread instance. * @param[in] aInstance A reference to the OpenThread instance.
* *
*/ */
ApplicationCoap(otInstance &aInstance); ApplicationCoap(Instance &aInstance);
private: private:
static ApplicationCoap &GetOwner(const Context &aContext); static ApplicationCoap &GetOwner(const Context &aContext);
+1
View File
@@ -39,6 +39,7 @@
#include "common/code_utils.hpp" #include "common/code_utils.hpp"
#include "common/debug.hpp" #include "common/debug.hpp"
#include "common/encoding.hpp" #include "common/encoding.hpp"
#include "common/instance.hpp"
namespace ot { namespace ot {
namespace Coap { namespace Coap {
+4 -4
View File
@@ -30,9 +30,9 @@
#include "coap_secure.hpp" #include "coap_secure.hpp"
#include "common/instance.hpp"
#include "common/logging.hpp" #include "common/logging.hpp"
#include "meshcop/dtls.hpp" #include "meshcop/dtls.hpp"
#include "openthread-instance.h"
#include "thread/thread_netif.hpp" #include "thread/thread_netif.hpp"
#if OPENTHREAD_ENABLE_DTLS #if OPENTHREAD_ENABLE_DTLS
@@ -45,7 +45,7 @@
namespace ot { namespace ot {
namespace Coap { namespace Coap {
CoapSecure::CoapSecure(otInstance &aInstance): CoapSecure::CoapSecure(Instance &aInstance):
CoapBase(aInstance, &CoapSecure::HandleRetransmissionTimer, &CoapSecure::HandleResponsesQueueTimer), CoapBase(aInstance, &CoapSecure::HandleRetransmissionTimer, &CoapSecure::HandleResponsesQueueTimer),
mConnectedCallback(NULL), mConnectedCallback(NULL),
mConnectedContext(NULL), mConnectedContext(NULL),
@@ -219,7 +219,7 @@ void CoapSecure::HandleDtlsReceive(uint8_t *aBuf, uint16_t aLength)
otLogFuncEntry(); otLogFuncEntry();
VerifyOrExit((message = GetInstance().mMessagePool.New(Message::kTypeIp6, 0)) != NULL); VerifyOrExit((message = GetInstance().GetMessagePool().New(Message::kTypeIp6, 0)) != NULL);
SuccessOrExit(message->Append(aBuf, aLength)); SuccessOrExit(message->Append(aBuf, aLength));
CoapBase::Receive(*message, mPeerAddress); CoapBase::Receive(*message, mPeerAddress);
@@ -314,7 +314,7 @@ CoapSecure &CoapSecure::GetOwner(const Context &aContext)
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
CoapSecure &coap = *static_cast<CoapSecure *>(aContext.GetContext()); CoapSecure &coap = *static_cast<CoapSecure *>(aContext.GetContext());
#else #else
CoapSecure &coap = otGetThreadNetif().GetCoapSecure(); CoapSecure &coap = Instance::Get().GetThreadNetif().GetCoapSecure();
OT_UNUSED_VARIABLE(aContext); OT_UNUSED_VARIABLE(aContext);
#endif #endif
return coap; return coap;
+1 -1
View File
@@ -73,7 +73,7 @@ public:
* @param[in] aInstance A reference to the OpenThread instance. * @param[in] aInstance A reference to the OpenThread instance.
* *
*/ */
CoapSecure(otInstance &aInstance); CoapSecure(Instance &aInstance);
/** /**
* This method starts the secure CoAP agent. * This method starts the secure CoAP agent.
+242
View File
@@ -0,0 +1,242 @@
/*
* Copyright (c) 2016-2017, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file implements the OpenThread Instance class.
*/
#define WPP_NAME "instance.tmh"
#include "instance.hpp"
#include <openthread/platform/misc.h>
#include <openthread/platform/settings.h>
#include "common/logging.hpp"
#include "common/new.hpp"
namespace ot {
#if !OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
// Define the raw storage used for OpenThread instance (in single-instance case).
static otDEFINE_ALIGNED_VAR(sInstanceRaw, sizeof(Instance), uint64_t);
#endif
Instance::Instance(void) :
mActiveScanCallback(NULL),
mActiveScanCallbackContext(NULL),
mEnergyScanCallback(NULL),
mEnergyScanCallbackContext(NULL),
mTimerMilliScheduler(*this),
#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER
mTimerMicroScheduler(*this),
#endif
mIp6(*this),
mThreadNetif(*this),
#if OPENTHREAD_ENABLE_RAW_LINK_API
mLinkRaw(*this),
#endif
#if OPENTHREAD_ENABLE_APPLICATION_COAP
mApplicationCoap(*this),
#endif
#if OPENTHREAD_CONFIG_ENABLE_DYNAMIC_LOG_LEVEL
mLogLevel(static_cast<otLogLevel>(OPENTHREAD_CONFIG_LOG_LEVEL)),
#endif
mMessagePool(*this),
mIsInitialized(false)
{
}
#if !OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
Instance &Instance::InitSingle(void)
{
Instance *instance = &Get();
VerifyOrExit(instance->mIsInitialized == false);
instance = new(&sInstanceRaw)Instance();
instance->AfterInit();
exit:
return *instance;
}
Instance &Instance::Get(void)
{
return *reinterpret_cast<Instance *>(&sInstanceRaw);
}
#else // #if !OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
Instance *Instance::Init(void *aBuffer, size_t *aBufferSize)
{
Instance *instance = NULL;
VerifyOrExit(aBufferSize != NULL);
// Make sure the input buffer is big enough
VerifyOrExit(sizeof(Instance) <= *aBufferSize, *aBufferSize = sizeof(Instance));
VerifyOrExit(aBuffer != NULL);
instance = new(aBuffer)Instance();
instance->AfterInit();
exit:
return instance;
}
#endif // OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
void Instance::AfterInit(void)
{
mIsInitialized = true;
// Restore datasets and network information
otPlatSettingsInit(this);
mThreadNetif.GetMle().Restore();
#if OPENTHREAD_CONFIG_ENABLE_AUTO_START_SUPPORT
if (otThreadGetAutoStart(this))
{
if (otIp6SetEnabled(this, true) == OT_ERROR_NONE)
{
// Only try to start Thread if we could bring up the interface
if (otThreadSetEnabled(this, true) != OT_ERROR_NONE)
{
// Bring the interface down if Thread failed to start
otIp6SetEnabled(this, false);
}
}
}
#endif
}
void Instance::Finalize(void)
{
VerifyOrExit(mIsInitialized == true);
mIsInitialized = false;
IgnoreReturnValue(otThreadSetEnabled(this, false));
IgnoreReturnValue(otIp6SetEnabled(this, false));
exit:
return;
}
otError Instance::RegisterStateChangedCallback(otStateChangedCallback aCallback, void *aContext)
{
otError error = OT_ERROR_NO_BUFS;
for (size_t i = 0; i < kMaxNetifCallbacks; i++)
{
if (mNetifCallback[i].IsFree())
{
mNetifCallback[i].Set(aCallback, aContext);
error = mThreadNetif.RegisterCallback(mNetifCallback[i]);
break;
}
}
return error;
}
void Instance::RemoveStateChangedCallback(otStateChangedCallback aCallback, void *aContext)
{
for (size_t i = 0; i < kMaxNetifCallbacks; i++)
{
if (mNetifCallback[i].IsServing(aCallback, aContext))
{
mThreadNetif.RemoveCallback(mNetifCallback[i]);
mNetifCallback[i].Free();
break;
}
}
}
void Instance::Reset(void)
{
otPlatReset(this);
}
void Instance::FactoryReset(void)
{
otPlatSettingsWipe(this);
otPlatReset(this);
}
otError Instance::ErasePersistentInfo(void)
{
otError error = OT_ERROR_NONE;
VerifyOrExit(mThreadNetif.GetMle().GetRole() == OT_DEVICE_ROLE_DISABLED, error = OT_ERROR_INVALID_STATE);
otPlatSettingsWipe(this);
exit:
return error;
}
void Instance::RegisterActiveScanCallback(otHandleActiveScanResult aCallback, void *aContext)
{
mActiveScanCallback = aCallback;
mActiveScanCallbackContext = aContext;
}
void Instance::InvokeActiveScanCallback(otActiveScanResult *aResult) const
{
if (mActiveScanCallback != NULL)
{
mActiveScanCallback(aResult, mActiveScanCallbackContext);
}
}
void Instance::RegisterEnergyScanCallback(otHandleEnergyScanResult aCallback, void *aContext)
{
mEnergyScanCallback = aCallback;
mEnergyScanCallbackContext = aContext;
}
void Instance::InvokeEnergyScanCallback(otEnergyScanResult *aResult) const
{
if (mEnergyScanCallback != NULL)
{
mEnergyScanCallback(aResult, mEnergyScanCallbackContext);
}
}
} // namespance ot
+377
View File
@@ -0,0 +1,377 @@
/*
* Copyright (c) 2016-2017, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file defines OpenThread instance class.
*/
#ifndef INSTANCE_HPP_
#define INSTANCE_HPP_
#include "openthread-core-config.h"
#include "utils/wrap_stdint.h"
#include "utils/wrap_stdbool.h"
#include <openthread/types.h>
#include <openthread/platform/logging.h>
#if OPENTHREAD_ENABLE_RAW_LINK_API
#include "api/link_raw.hpp"
#endif
#include "common/code_utils.hpp"
#include "coap/coap.hpp"
#if !OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
#include "crypto/heap.hpp"
#include "crypto/mbedtls.hpp"
#endif
#include "net/ip6.hpp"
#include "thread/thread_netif.hpp"
/**
* @addtogroup core-instance
*
* @brief
* This module includes definitions for OpenThread instance.
*
* @{
*
*/
/**
* This struct represents an opaque (and empty) type corresponding to an OpenThread instance object.
*
*/
typedef struct otInstance
{
} otInstance;
namespace ot {
/**
* This class represents an OpenThread instance.
*
* This class contains all the components used by OpenThread.
*
*/
class Instance : public otInstance
{
public:
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
/**
* This static method initializes the OpenThread instance.
*
* This function must be called before any other calls on OpenThread instance.
*
* @param[in] aBuffer The buffer for OpenThread to use for allocating the Instance.
* @param[inout] aBufferSize On input, the size of `aBuffer`. On output, if not enough space for `Instance`, the
number of bytes required for `Instance`.
*
* @returns A pointer to the new OpenThread instance.
*
*/
static Instance *Init(void *aBuffer, size_t *aBufferSize);
#else // OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
/**
* This static method initializes the single OpenThread instance.
*
* This method initializes OpenThread and prepares it for subsequent OpenThread API calls. This function must be
* called before any other calls to OpenThread.
*
* @returns A reference to the single OpenThread instance.
*
*/
static Instance &InitSingle(void);
/**
* This static method returns a reference to the single OpenThread instance.
*
* @returns A reference to the single OpenThread instance.
*
*/
static Instance &Get(void);
#endif
/**
* This method indicates whether or not the instance is valid/initialized and not yet finalized.
*
* @returns TRUE if the instance is valid/initialized, FALSE otherwise.
*
*/
bool IsInitialized(void) const { return mIsInitialized; }
/**
* This method finalizes the OpenThread instance.
*
* This method should be called when OpenThread instance is no longer in use.
*
*/
void Finalize(void);
/**
* This method registers a callback to indicate when certain configuration or state changes within OpenThread.
*
* @param[in] aCallback A pointer to a function that is called with certain configuration or state changes.
* @param[in] aContext A pointer to application-specific context.
*
* @retval OT_ERROR_NONE Added the callback to the list of callbacks and registered it with OpenThread.
* @retval OT_ERROR_NO_BUFS Could not add the callback due to resource constraints.
*
*/
otError RegisterStateChangedCallback(otStateChangedCallback aCallback, void *aContext);
/**
* This method removes/unregisters a previously registered "state changed" callback.
*
* @param[in] aCallback A pointer to the callback function pointer.
* @param[in] aCallbackContext A pointer to application-specific context.
*
*/
void RemoveStateChangedCallback(otStateChangedCallback aCallback, void *aCallbackContext);
/**
* This method triggers a platform reset.
*
* The reset process ensures that all the OpenThread state/info (stored in volatile memory) is erased. Note that
* this method does not erase any persistent state/info saved in non-volatile memory.
*
*/
void Reset(void);
/**
* This method deletes all the settings stored in non-volatile memory, and then triggers a platform reset.
*
*/
void FactoryReset(void);
/**
* This method erases all the OpenThread persistent info (network settings) stored in non-volatile memory.
*
* Erase is successful/allowed only if the device is in `disabled` state/role.
*
* @retval OT_ERROR_NONE All persistent info/state was erased successfully.
* @retval OT_ERROR_INVALID_STATE Device is not in `disabled` state/role.
*
*/
otError ErasePersistentInfo(void);
#if OPENTHREAD_CONFIG_ENABLE_DYNAMIC_LOG_LEVEL
/**
* This method returns the current dynamic log level.
*
* @returns the currently set dynamic log level.
*
*/
otLogLevel GetDynamicLogLevel(void) const { return mLogLevel; }
/**
* This method sets the dynamic log level.
*
* @param[in] aLogLevel The dynamic log level.
*
*/
void SetDynamicLogLevel(otLogLevel aLogLevel) { mLogLevel = aLogLevel; }
#endif
/**
* This method registers the active scan callback.
*
* Subsequent calls to this method will overwrite the previous callback handler.
*
* @param[in] aCallback A pointer to the callback function pointer.
* @param[in] aContext A pointer to application-specific context.
*
*/
void RegisterActiveScanCallback(otHandleActiveScanResult aCallback, void *aContext);
/**
* This method invokes the previously registered active scan callback with a given scan result.
*
* @param[in] aResult A pointer to active scan result.
*
*/
void InvokeActiveScanCallback(otActiveScanResult *aResult) const;
/**
* This method registers the energy scan callback.
*
* Subsequent calls to this method will overwrite the previous callback handler.
*
* @param[in] aCallback A pointer to the callback function pointer.
* @param[in] aContext A pointer to application-specific context.
*
*/
void RegisterEnergyScanCallback(otHandleEnergyScanResult aCallback, void *aContext);
/**
* This method invokes the previously registered energy scan callback with a given result.
*
* @param[in] aResult A pointer to energy scan result.
*
*/
void InvokeEnergyScanCallback(otEnergyScanResult *aResult) const;
/**
* This method returns a reference to the tasklet scheduler object.
*
* @returns A reference to the tasklet scheduler object.
*
*/
TaskletScheduler &GetTaskletScheduler(void) { return mTaskletScheduler; }
/**
* This method returns a reference to the timer milli scheduler object.
*
* @returns A reference to the timer milli scheduler object.
*
*/
TimerMilliScheduler &GetTimerMilliScheduler(void) { return mTimerMilliScheduler; }
#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER
/**
* This method returns a reference to the timer micro scheduler object.
*
* @returns A reference to the timer micro scheduler object.
*
*/
TimerMicroScheduler &GetTimerMicroScheduler(void) { return mTimerMicroScheduler; }
#endif
#if !OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
/**
* This method returns a reference to the MbedTlsHeap object.
*
* @returns A reference to the MbedTlsHeap object.
*
*/
Crypto::Heap &GetMbedTlsHeap(void) { return mMbedTlsHeap; }
#endif
/**
* This method returns a reference to the Ip6 object.
*
* @returns A reference to the Ip6 object.
*
*/
Ip6::Ip6 &GetIp6(void) { return mIp6; }
/**
* This method returns a reference to the Thread Netif object.
*
* @returns A reference to the Thread Netif object.
*
*/
ThreadNetif &GetThreadNetif(void) { return mThreadNetif; }
#if OPENTHREAD_ENABLE_RAW_LINK_API
/**
* This method returns a reference to LinkRaw object.
*
* @returns A reference to the LinkRaw object.
*
*/
LinkRaw &GetLinkRaw(void) { return mLinkRaw; }
#endif
#if OPENTHREAD_ENABLE_APPLICATION_COAP
/**
* This method returns a reference to application COAP object.
*
* @returns A reference to the application COAP object.
*
*/
Coap::ApplicationCoap &GetApplicationCoap(void) { return mApplicationCoap; }
#endif
/**
* This method returns a reference to message pool object.
*
* @returns A reference to the message pool object.
*
*/
MessagePool &GetMessagePool(void) { return mMessagePool; }
private:
Instance(void);
void AfterInit(void);
enum
{
kMaxNetifCallbacks = OPENTHREAD_CONFIG_MAX_STATECHANGE_HANDLERS,
};
Ip6::NetifCallback mNetifCallback[kMaxNetifCallbacks];
otHandleActiveScanResult mActiveScanCallback;
void *mActiveScanCallbackContext;
otHandleEnergyScanResult mEnergyScanCallback;
void *mEnergyScanCallbackContext;
TaskletScheduler mTaskletScheduler;
TimerMilliScheduler mTimerMilliScheduler;
#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER
TimerMicroScheduler mTimerMicroScheduler;
#endif
#if !OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
Crypto::MbedTls mMbedTls;
Crypto::Heap mMbedTlsHeap;
#endif
Ip6::Ip6 mIp6;
ThreadNetif mThreadNetif;
#if OPENTHREAD_ENABLE_RAW_LINK_API
LinkRaw mLinkRaw;
#endif
#if OPENTHREAD_ENABLE_APPLICATION_COAP
Coap::ApplicationCoap mApplicationCoap;
#endif
#if OPENTHREAD_CONFIG_ENABLE_DYNAMIC_LOG_LEVEL
otLogLevel mLogLevel;
#endif
MessagePool mMessagePool;
bool mIsInitialized;
};
/**
* @}
*
*/
} // namespace ot
#endif // INSTANCE_HPP_
+10 -3
View File
@@ -35,19 +35,26 @@
#include "locator.hpp" #include "locator.hpp"
#include "openthread-instance.h" #include "common/instance.hpp"
#include "net/ip6.hpp" #include "net/ip6.hpp"
namespace ot { namespace ot {
#if !OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
Instance &InstanceLocator::GetInstance(void) const
{
return Instance::Get();
}
#endif
Ip6::Ip6 &InstanceLocator::GetIp6(void) const Ip6::Ip6 &InstanceLocator::GetIp6(void) const
{ {
return GetInstance().mIp6; return GetInstance().GetIp6();
} }
ThreadNetif &InstanceLocator::GetNetif(void) const ThreadNetif &InstanceLocator::GetNetif(void) const
{ {
return GetInstance().mThreadNetif; return GetInstance().GetThreadNetif();
} }
} // namespace ot } // namespace ot
+16 -9
View File
@@ -38,13 +38,13 @@
#include <openthread/types.h> #include <openthread/types.h>
#include "openthread-single-instance.h"
namespace ot { namespace ot {
class Instance;
class ThreadNetif; class ThreadNetif;
namespace Ip6 { class Ip6; } namespace Ip6 { class Ip6; }
/** /**
* @addtogroup core-locator * @addtogroup core-locator
* *
@@ -57,22 +57,29 @@ namespace Ip6 { class Ip6; }
/** /**
* This class implements locator for otInstance object. * This class implements a locator for an OpenThread Instance object.
*
* The `InstanceLocator` is used as base class of almost all other OpenThread classes. It provides a way for an object
* to get to its owning/parent OpenThread `Instance` and other objects within the OpenTread hierarchy (e.g. the
* `ThreadNetif` or `Ip6::Ip6` objects).
*
* If multiple-instance feature is supported, the owning/parent OpenThread `Instance` is tracked as a reference. In the
* single-instance case, this class becomes an empty base class.
* *
*/ */
class InstanceLocator class InstanceLocator
{ {
public: public:
/** /**
* This method returns a reference to the parent otInstance structure. * This method returns a reference to the parent OpenThread Instance.
* *
* @returns A reference to the parent otInstance structure. * @returns A reference to the parent otInstance.
* *
*/ */
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
otInstance &GetInstance(void) const { return mInstance; } Instance &GetInstance(void) const { return mInstance; }
#else #else
otInstance &GetInstance(void) const { return *otGetInstance(); } Instance &GetInstance(void) const;
#endif #endif
/** /**
@@ -98,7 +105,7 @@ protected:
* @param[in] aInstance A pointer to the otInstance. * @param[in] aInstance A pointer to the otInstance.
* *
*/ */
InstanceLocator(otInstance &aInstance) InstanceLocator(Instance &aInstance)
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
: mInstance(aInstance) : mInstance(aInstance)
#endif #endif
@@ -108,7 +115,7 @@ protected:
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
private: private:
otInstance &mInstance; Instance &mInstance;
#endif #endif
}; };
+2
View File
@@ -37,6 +37,8 @@
#include <openthread/openthread.h> #include <openthread/openthread.h>
#include "common/instance.hpp"
/* /*
* Verify debug uart dependency. * Verify debug uart dependency.
* *
+1 -1
View File
@@ -1517,7 +1517,7 @@ const char *otLogRegionToString(otLogRegion aRegion);
/** /**
* Local/private macro to format the log message * Local/private macro to format the log message
*/ */
#define _otLogFormatter(aInstance, aLogLevel, aRegion, aFormat, ...) \ #define _otLogFormatter(aInstance, aLogLevel, aRegion, aFormat, ...) \
_otDynamicLog( \ _otDynamicLog( \
aInstance, \ aInstance, \
aLogLevel, \ aLogLevel, \
+10 -3
View File
@@ -35,15 +35,15 @@
#include "message.hpp" #include "message.hpp"
#include "openthread-instance.h"
#include "common/code_utils.hpp" #include "common/code_utils.hpp"
#include "common/debug.hpp" #include "common/debug.hpp"
#include "common/instance.hpp"
#include "common/logging.hpp" #include "common/logging.hpp"
#include "net/ip6.hpp" #include "net/ip6.hpp"
namespace ot { namespace ot {
MessagePool::MessagePool(otInstance &aInstance) : MessagePool::MessagePool(Instance &aInstance) :
InstanceLocator(aInstance), InstanceLocator(aInstance),
mAllQueue() mAllQueue()
{ {
@@ -149,7 +149,7 @@ otError MessagePool::ReclaimBuffers(int aNumBuffers)
{ {
while (aNumBuffers > GetFreeBufferCount()) while (aNumBuffers > GetFreeBufferCount())
{ {
MeshForwarder &meshForwarder = GetInstance().mThreadNetif.GetMeshForwarder(); MeshForwarder &meshForwarder = GetInstance().GetThreadNetif().GetMeshForwarder();
SuccessOrExit(meshForwarder.EvictIndirectMessage()); SuccessOrExit(meshForwarder.EvictIndirectMessage());
} }
@@ -168,6 +168,13 @@ exit:
} }
} }
#if OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT
uint16_t MessagePool::GetFreeBufferCount(void) const
{
return otPlatMessagePoolNumFreeBuffers(&GetInstance());
}
#endif
Message *MessagePool::Iterator::Next(void) const Message *MessagePool::Iterator::Next(void) const
{ {
Message *next; Message *next;
+2 -2
View File
@@ -1140,7 +1140,7 @@ public:
* This constructor initializes the object. * This constructor initializes the object.
* *
*/ */
MessagePool(otInstance &aInstance); MessagePool(Instance &aInstance);
/** /**
* This method is used to obtain a new message. The default priority `kDefaultMessagePriority` * This method is used to obtain a new message. The default priority `kDefaultMessagePriority`
@@ -1187,7 +1187,7 @@ public:
* *
*/ */
#if OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT #if OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT
uint16_t GetFreeBufferCount(void) const { return otPlatMessagePoolNumFreeBuffers(&GetInstance()); } uint16_t GetFreeBufferCount(void) const;
#else #else
uint16_t GetFreeBufferCount(void) const { return mNumFreeBuffers; } uint16_t GetFreeBufferCount(void) const { return mNumFreeBuffers; }
#endif #endif
+3 -3
View File
@@ -35,14 +35,14 @@
#include <openthread/openthread.h> #include <openthread/openthread.h>
#include "openthread-instance.h"
#include "common/code_utils.hpp" #include "common/code_utils.hpp"
#include "common/debug.hpp" #include "common/debug.hpp"
#include "common/instance.hpp"
#include "net/ip6.hpp" #include "net/ip6.hpp"
namespace ot { namespace ot {
Tasklet::Tasklet(otInstance &aInstance, Handler aHandler, void *aContext): Tasklet::Tasklet(Instance &aInstance, Handler aHandler, void *aContext):
InstanceLocator(aInstance), InstanceLocator(aInstance),
Context(aContext), Context(aContext),
mHandler(aHandler), mHandler(aHandler),
@@ -52,7 +52,7 @@ Tasklet::Tasklet(otInstance &aInstance, Handler aHandler, void *aContext):
otError Tasklet::Post(void) otError Tasklet::Post(void)
{ {
return GetInstance().mTaskletScheduler.Post(*this); return GetInstance().GetTaskletScheduler().Post(*this);
} }
TaskletScheduler::TaskletScheduler(void): TaskletScheduler::TaskletScheduler(void):
+1 -1
View File
@@ -82,7 +82,7 @@ public:
* @param[in] aContext A pointer to arbitrary context information. * @param[in] aContext A pointer to arbitrary context information.
* *
*/ */
Tasklet(otInstance &aInstance, Handler aHandler, void *aContext); Tasklet(Instance &aInstance, Handler aHandler, void *aContext);
/** /**
* This method puts the tasklet on the run queue. * This method puts the tasklet on the run queue.
+9 -5
View File
@@ -35,9 +35,9 @@
#include "timer.hpp" #include "timer.hpp"
#include "openthread-instance.h"
#include "common/code_utils.hpp" #include "common/code_utils.hpp"
#include "common/debug.hpp" #include "common/debug.hpp"
#include "common/instance.hpp"
#include "common/logging.hpp" #include "common/logging.hpp"
namespace ot { namespace ot {
@@ -87,7 +87,7 @@ void TimerMilli::Stop(void)
TimerMilliScheduler &TimerMilli::GetTimerMilliScheduler(void) const TimerMilliScheduler &TimerMilli::GetTimerMilliScheduler(void) const
{ {
return GetInstance().mTimerMilliScheduler; return GetInstance().GetTimerMilliScheduler();
} }
void TimerScheduler::Add(Timer &aTimer, const AlarmApi &aAlarmApi) void TimerScheduler::Add(Timer &aTimer, const AlarmApi &aAlarmApi)
@@ -213,10 +213,12 @@ bool TimerScheduler::IsStrictlyBefore(uint32_t aTimeA, uint32_t aTimeB)
extern "C" void otPlatAlarmMilliFired(otInstance *aInstance) extern "C" void otPlatAlarmMilliFired(otInstance *aInstance)
{ {
Instance *instance = static_cast<Instance *>(aInstance);
otLogFuncEntry(); otLogFuncEntry();
VerifyOrExit(otInstanceIsInitialized(aInstance)); VerifyOrExit(otInstanceIsInitialized(aInstance));
aInstance->mTimerMilliScheduler.ProcessTimers(); instance->GetTimerMilliScheduler().ProcessTimers();
exit: exit:
otLogFuncExit(); otLogFuncExit();
@@ -244,15 +246,17 @@ void TimerMicro::Stop(void)
TimerMicroScheduler &TimerMicro::GetTimerMicroScheduler(void) const TimerMicroScheduler &TimerMicro::GetTimerMicroScheduler(void) const
{ {
return GetInstance().mTimerMicroScheduler; return GetInstance().GetTimerMicroScheduler();
} }
extern "C" void otPlatAlarmMicroFired(otInstance *aInstance) extern "C" void otPlatAlarmMicroFired(otInstance *aInstance)
{ {
Instance *instance = static_cast<Instance *>(aInstance);
otLogFuncEntry(); otLogFuncEntry();
VerifyOrExit(otInstanceIsInitialized(aInstance)); VerifyOrExit(otInstanceIsInitialized(aInstance));
aInstance->mTimerMicroScheduler.ProcessTimers(); instance->GetTimerMicroScheduler().ProcessTimers();
exit: exit:
otLogFuncExit(); otLogFuncExit();
+6 -6
View File
@@ -93,7 +93,7 @@ public:
* @param[in] aContext A pointer to arbitrary context information. * @param[in] aContext A pointer to arbitrary context information.
* *
*/ */
Timer(otInstance &aInstance, Handler aHandler, void *aContext): Timer(Instance &aInstance, Handler aHandler, void *aContext):
InstanceLocator(aInstance), InstanceLocator(aInstance),
Context(aContext), Context(aContext),
mHandler(aHandler), mHandler(aHandler),
@@ -153,7 +153,7 @@ public:
* @param[in] aContext A pointer to arbitrary context information. * @param[in] aContext A pointer to arbitrary context information.
* *
*/ */
TimerMilli(otInstance &aInstance, Handler aHandler, void *aContext): TimerMilli(Instance &aInstance, Handler aHandler, void *aContext):
Timer(aInstance, aHandler, aContext) { Timer(aInstance, aHandler, aContext) {
} }
@@ -243,7 +243,7 @@ protected:
* @param[in] aInstance A reference to the instance object. * @param[in] aInstance A reference to the instance object.
* *
*/ */
TimerScheduler(otInstance &aInstance): TimerScheduler(Instance &aInstance):
InstanceLocator(aInstance), InstanceLocator(aInstance),
mHead(NULL) { mHead(NULL) {
} }
@@ -313,7 +313,7 @@ public:
* @param[in] aInstance A reference to the instance object. * @param[in] aInstance A reference to the instance object.
* *
*/ */
TimerMilliScheduler(otInstance &aInstance): TimerMilliScheduler(Instance &aInstance):
TimerScheduler(aInstance) { TimerScheduler(aInstance) {
} }
@@ -361,7 +361,7 @@ public:
* @param[in] aContext A pointer to arbitrary context information. * @param[in] aContext A pointer to arbitrary context information.
* *
*/ */
TimerMicro(otInstance &aInstance, Handler aHandler, void *aContext): TimerMicro(Instance &aInstance, Handler aHandler, void *aContext):
Timer(aInstance, aHandler, aContext) { Timer(aInstance, aHandler, aContext) {
} }
@@ -421,7 +421,7 @@ public:
* @param[in] aInstance A reference to the instance object. * @param[in] aInstance A reference to the instance object.
* *
*/ */
TimerMicroScheduler(otInstance &aInstance): TimerMicroScheduler(Instance &aInstance):
TimerScheduler(aInstance) { TimerScheduler(aInstance) {
} }
+1 -1
View File
@@ -41,7 +41,7 @@
namespace ot { namespace ot {
TrickleTimer::TrickleTimer( TrickleTimer::TrickleTimer(
otInstance &aInstance, Instance &aInstance,
#ifdef ENABLE_TRICKLE_TIMER_SUPPRESSION_SUPPORT #ifdef ENABLE_TRICKLE_TIMER_SUPPRESSION_SUPPORT
uint32_t aRedundancyConstant, uint32_t aRedundancyConstant,
#endif #endif
+1 -1
View File
@@ -89,7 +89,7 @@ public:
* @param[in] aContext A pointer to arbitrary context information. * @param[in] aContext A pointer to arbitrary context information.
* *
*/ */
TrickleTimer(otInstance &aInstance, TrickleTimer(Instance &aInstance,
#ifdef ENABLE_TRICKLE_TIMER_SUPPRESSION_SUPPORT #ifdef ENABLE_TRICKLE_TIMER_SUPPRESSION_SUPPORT
uint32_t aRedundancyConstant, uint32_t aRedundancyConstant,
#endif #endif
+3 -4
View File
@@ -36,8 +36,7 @@
#include <mbedtls/platform.h> #include <mbedtls/platform.h>
#include "heap.hpp" #include "heap.hpp"
#include "openthread-instance.h" #include "common/instance.hpp"
#include "openthread-single-instance.h"
#if !OPENTHREAD_ENABLE_MULTIPLE_INSTANCES #if !OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
@@ -46,12 +45,12 @@ namespace Crypto {
static void *CAlloc(size_t aCount, size_t aSize) static void *CAlloc(size_t aCount, size_t aSize)
{ {
return otGetInstance()->mMbedTlsHeap.CAlloc(aCount, aSize); return Instance::Get().GetMbedTlsHeap().CAlloc(aCount, aSize);
} }
static void Free(void *aPointer) static void Free(void *aPointer)
{ {
otGetInstance()->mMbedTlsHeap.Free(aPointer); Instance::Get().GetMbedTlsHeap().Free(aPointer);
} }
MbedTls::MbedTls(void) MbedTls::MbedTls(void)
+32 -19
View File
@@ -39,10 +39,10 @@
#include <openthread/platform/random.h> #include <openthread/platform/random.h>
#include "openthread-instance.h"
#include "common/code_utils.hpp" #include "common/code_utils.hpp"
#include "common/debug.hpp" #include "common/debug.hpp"
#include "common/encoding.hpp" #include "common/encoding.hpp"
#include "common/instance.hpp"
#include "common/logging.hpp" #include "common/logging.hpp"
#include "crypto/aes_ccm.hpp" #include "crypto/aes_ccm.hpp"
#include "crypto/sha256.hpp" #include "crypto/sha256.hpp"
@@ -136,7 +136,7 @@ void Mac::StartCsmaBackoff(void)
} }
} }
Mac::Mac(otInstance &aInstance): Mac::Mac(Instance &aInstance):
InstanceLocator(aInstance), InstanceLocator(aInstance),
mOperation(kOperationIdle), mOperation(kOperationIdle),
mPendingActiveScan(false), mPendingActiveScan(false),
@@ -335,18 +335,20 @@ void Mac::StartEnergyScan(void)
extern "C" void otPlatRadioEnergyScanDone(otInstance *aInstance, int8_t aEnergyScanMaxRssi) extern "C" void otPlatRadioEnergyScanDone(otInstance *aInstance, int8_t aEnergyScanMaxRssi)
{ {
VerifyOrExit(otInstanceIsInitialized(aInstance)); Instance *instance = static_cast<Instance *>(aInstance);
VerifyOrExit(instance->IsInitialized());
#if OPENTHREAD_ENABLE_RAW_LINK_API #if OPENTHREAD_ENABLE_RAW_LINK_API
if (aInstance->mLinkRaw.IsEnabled()) if (instance->GetLinkRaw().IsEnabled())
{ {
aInstance->mLinkRaw.InvokeEnergyScanDone(aEnergyScanMaxRssi); instance->GetLinkRaw().InvokeEnergyScanDone(aEnergyScanMaxRssi);
} }
else else
#endif // OPENTHREAD_ENABLE_RAW_LINK_API #endif // OPENTHREAD_ENABLE_RAW_LINK_API
{ {
aInstance->mThreadNetif.GetMac().EnergyScanDone(aEnergyScanMaxRssi); instance->GetThreadNetif().GetMac().EnergyScanDone(aEnergyScanMaxRssi);
} }
exit: exit:
@@ -935,9 +937,11 @@ exit:
extern "C" void otPlatRadioTxStarted(otInstance *aInstance, otRadioFrame *aFrame) extern "C" void otPlatRadioTxStarted(otInstance *aInstance, otRadioFrame *aFrame)
{ {
Instance *instance = static_cast<Instance *>(aInstance);
otLogFuncEntry(); otLogFuncEntry();
VerifyOrExit(otInstanceIsInitialized(aInstance)); VerifyOrExit(instance->IsInitialized());
aInstance->mThreadNetif.GetMac().TransmitStartedTask(aFrame); instance->GetThreadNetif().GetMac().TransmitStartedTask(aFrame);
exit: exit:
otLogFuncExit(); otLogFuncExit();
} }
@@ -956,19 +960,21 @@ void Mac::TransmitStartedTask(otRadioFrame *aFrame)
extern "C" void otPlatRadioTxDone(otInstance *aInstance, otRadioFrame *aFrame, otRadioFrame *aAckFrame, extern "C" void otPlatRadioTxDone(otInstance *aInstance, otRadioFrame *aFrame, otRadioFrame *aAckFrame,
otError aError) otError aError)
{ {
Instance *instance = static_cast<Instance *>(aInstance);
otLogFuncEntryMsg("%!otError!", aError); otLogFuncEntryMsg("%!otError!", aError);
VerifyOrExit(otInstanceIsInitialized(aInstance)); VerifyOrExit(instance->IsInitialized());
#if OPENTHREAD_ENABLE_RAW_LINK_API #if OPENTHREAD_ENABLE_RAW_LINK_API
if (aInstance->mLinkRaw.IsEnabled()) if (instance->GetLinkRaw().IsEnabled())
{ {
aInstance->mLinkRaw.InvokeTransmitDone(aFrame, aAckFrame, aError); instance->GetLinkRaw().InvokeTransmitDone(aFrame, aAckFrame, aError);
} }
else else
#endif // OPENTHREAD_ENABLE_RAW_LINK_API #endif // OPENTHREAD_ENABLE_RAW_LINK_API
{ {
aInstance->mThreadNetif.GetMac().TransmitDoneTask(aFrame, aAckFrame, aError); instance->GetThreadNetif().GetMac().TransmitDoneTask(aFrame, aAckFrame, aError);
} }
exit: exit:
@@ -1040,9 +1046,9 @@ void Mac::TransmitDoneTask(otRadioFrame *aFrame, otRadioFrame *aAckFrame, otErro
default: default:
#if OPENTHREAD_ENABLE_RAW_LINK_API #if OPENTHREAD_ENABLE_RAW_LINK_API
if (GetInstance().mLinkRaw.IsEnabled()) if (GetInstance().GetLinkRaw().IsEnabled())
{ {
GetInstance().mLinkRaw.InvokeTransmitDone(mTxFrame, NULL, OT_ERROR_NO_ACK); GetInstance().GetLinkRaw().InvokeTransmitDone(mTxFrame, NULL, OT_ERROR_NO_ACK);
} }
else else
#endif #endif
@@ -1501,19 +1507,21 @@ exit:
extern "C" void otPlatRadioReceiveDone(otInstance *aInstance, otRadioFrame *aFrame, otError aError) extern "C" void otPlatRadioReceiveDone(otInstance *aInstance, otRadioFrame *aFrame, otError aError)
{ {
Instance *instance = static_cast<Instance *>(aInstance);
otLogFuncEntryMsg("%!otError!", aError); otLogFuncEntryMsg("%!otError!", aError);
VerifyOrExit(otInstanceIsInitialized(aInstance)); VerifyOrExit(instance->IsInitialized());
#if OPENTHREAD_ENABLE_RAW_LINK_API #if OPENTHREAD_ENABLE_RAW_LINK_API
if (aInstance->mLinkRaw.IsEnabled()) if (instance->GetLinkRaw().IsEnabled())
{ {
aInstance->mLinkRaw.InvokeReceiveDone(aFrame, aError); instance->GetLinkRaw().InvokeReceiveDone(aFrame, aError);
} }
else else
#endif // OPENTHREAD_ENABLE_RAW_LINK_API #endif // OPENTHREAD_ENABLE_RAW_LINK_API
{ {
aInstance->mThreadNetif.GetMac().ReceiveDoneTask(static_cast<Frame *>(aFrame), aError); instance->GetThreadNetif().GetMac().ReceiveDoneTask(static_cast<Frame *>(aFrame), aError);
} }
exit: exit:
@@ -1896,6 +1904,11 @@ void Mac::ResetCounters(void)
memset(&mCounters, 0, sizeof(mCounters)); memset(&mCounters, 0, sizeof(mCounters));
} }
int8_t Mac::GetNoiseFloor(void)
{
return otPlatRadioGetReceiveSensitivity(&GetInstance());
}
#if OPENTHREAD_CONFIG_ENABLE_BEACON_RSP_WHEN_JOINABLE #if OPENTHREAD_CONFIG_ENABLE_BEACON_RSP_WHEN_JOINABLE
bool Mac::IsBeaconJoinable(void) bool Mac::IsBeaconJoinable(void)
{ {
@@ -1922,7 +1935,7 @@ Mac &Mac::GetOwner(const Context &aContext)
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
Mac &mac = *static_cast<Mac *>(aContext.GetContext()); Mac &mac = *static_cast<Mac *>(aContext.GetContext());
#else #else
Mac &mac = otGetInstance()->mThreadNetif.GetMac(); Mac &mac = Instance::Get().GetThreadNetif().GetMac();
OT_UNUSED_VARIABLE(aContext); OT_UNUSED_VARIABLE(aContext);
#endif #endif
return mac; return mac;
+2 -2
View File
@@ -220,7 +220,7 @@ public:
* @param[in] aInstance A reference to the OpenThread instance. * @param[in] aInstance A reference to the OpenThread instance.
* *
*/ */
explicit Mac(otInstance &aInstance); explicit Mac(Instance &aInstance);
/** /**
* This function pointer is called on receiving an IEEE 802.15.4 Beacon during an Active Scan. * This function pointer is called on receiving an IEEE 802.15.4 Beacon during an Active Scan.
@@ -602,7 +602,7 @@ public:
* @returns The noise floor value in dBm. * @returns The noise floor value in dBm.
* *
*/ */
int8_t GetNoiseFloor(void) { return otPlatRadioGetReceiveSensitivity(&GetInstance()); } int8_t GetNoiseFloor(void);
/** /**
* This method indicates whether or not CSMA backoff is supported by the radio layer. * This method indicates whether or not CSMA backoff is supported by the radio layer.
+1 -1
View File
@@ -33,7 +33,7 @@
#include "mac_filter.hpp" #include "mac_filter.hpp"
#include "openthread/types.h" #include <openthread/types.h>
#include "utils/wrap_string.h" #include "utils/wrap_string.h"
#include "common/code_utils.hpp" #include "common/code_utils.hpp"
+1
View File
@@ -38,6 +38,7 @@
#include "common/code_utils.hpp" #include "common/code_utils.hpp"
#include "common/debug.hpp" #include "common/debug.hpp"
#include "common/instance.hpp"
namespace ot { namespace ot {
namespace Mac { namespace Mac {
+2 -2
View File
@@ -37,10 +37,10 @@
#include <openthread/platform/random.h> #include <openthread/platform/random.h>
#include "openthread-instance.h"
#include "coap/coap_header.hpp" #include "coap/coap_header.hpp"
#include "common/code_utils.hpp" #include "common/code_utils.hpp"
#include "common/debug.hpp" #include "common/debug.hpp"
#include "common/instance.hpp"
#include "common/logging.hpp" #include "common/logging.hpp"
#include "meshcop/meshcop.hpp" #include "meshcop/meshcop.hpp"
#include "meshcop/meshcop_tlvs.hpp" #include "meshcop/meshcop_tlvs.hpp"
@@ -51,7 +51,7 @@
namespace ot { namespace ot {
AnnounceBeginClient::AnnounceBeginClient(otInstance &aInstance): AnnounceBeginClient::AnnounceBeginClient(Instance &aInstance):
InstanceLocator(aInstance) InstanceLocator(aInstance)
{ {
} }
+1 -1
View File
@@ -54,7 +54,7 @@ public:
* This constructor initializes the object. * This constructor initializes the object.
* *
*/ */
AnnounceBeginClient(otInstance &aInstance); AnnounceBeginClient(Instance &aInstance);
/** /**
* This method sends a Announce Begin message. * This method sends a Announce Begin message.
+3 -3
View File
@@ -41,9 +41,9 @@
#include <openthread/types.h> #include <openthread/types.h>
#include <openthread/platform/random.h> #include <openthread/platform/random.h>
#include "openthread-instance.h"
#include "coap/coap_header.hpp" #include "coap/coap_header.hpp"
#include "common/encoding.hpp" #include "common/encoding.hpp"
#include "common/instance.hpp"
#include "common/logging.hpp" #include "common/logging.hpp"
#include "crypto/pbkdf2_cmac.h" #include "crypto/pbkdf2_cmac.h"
#include "meshcop/joiner_router.hpp" #include "meshcop/joiner_router.hpp"
@@ -60,7 +60,7 @@ using ot::Encoding::BigEndian::HostSwap64;
namespace ot { namespace ot {
namespace MeshCoP { namespace MeshCoP {
Commissioner::Commissioner(otInstance &aInstance): Commissioner::Commissioner(Instance &aInstance):
InstanceLocator(aInstance), InstanceLocator(aInstance),
mState(OT_COMMISSIONER_STATE_DISABLED), mState(OT_COMMISSIONER_STATE_DISABLED),
mJoinerPort(0), mJoinerPort(0),
@@ -1088,7 +1088,7 @@ Commissioner &Commissioner::GetOwner(const Context &aContext)
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
Commissioner &commissioner = *static_cast<Commissioner *>(aContext.GetContext()); Commissioner &commissioner = *static_cast<Commissioner *>(aContext.GetContext());
#else #else
Commissioner &commissioner = otGetThreadNetif().GetCommissioner(); Commissioner &commissioner = Instance::Get().GetThreadNetif().GetCommissioner();
OT_UNUSED_VARIABLE(aContext); OT_UNUSED_VARIABLE(aContext);
#endif #endif
return commissioner; return commissioner;
+1 -1
View File
@@ -65,7 +65,7 @@ public:
* @param[in] aInstance A reference to the OpenThread instance. * @param[in] aInstance A reference to the OpenThread instance.
* *
*/ */
Commissioner(otInstance &aInstance); Commissioner(Instance &aInstance);
/** /**
* This method starts the Commissioner service. * This method starts the Commissioner service.
+1 -1
View File
@@ -36,8 +36,8 @@
#include <stdio.h> #include <stdio.h>
#include "openthread-instance.h"
#include "common/code_utils.hpp" #include "common/code_utils.hpp"
#include "common/instance.hpp"
#include "common/settings.hpp" #include "common/settings.hpp"
#include "meshcop/meshcop_tlvs.hpp" #include "meshcop/meshcop_tlvs.hpp"
#include "thread/mle_tlvs.hpp" #include "thread/mle_tlvs.hpp"
+2 -1
View File
@@ -42,6 +42,7 @@
#include "common/code_utils.hpp" #include "common/code_utils.hpp"
#include "common/logging.hpp" #include "common/logging.hpp"
#include "common/instance.hpp"
#include "common/settings.hpp" #include "common/settings.hpp"
#include "meshcop/dataset.hpp" #include "meshcop/dataset.hpp"
#include "meshcop/meshcop_tlvs.hpp" #include "meshcop/meshcop_tlvs.hpp"
@@ -50,7 +51,7 @@
namespace ot { namespace ot {
namespace MeshCoP { namespace MeshCoP {
DatasetLocal::DatasetLocal(otInstance &aInstance, const Tlv::Type aType) : DatasetLocal::DatasetLocal(Instance &aInstance, const Tlv::Type aType) :
InstanceLocator(aInstance), InstanceLocator(aInstance),
mUpdateTime(0), mUpdateTime(0),
mType(aType) mType(aType)
+1 -1
View File
@@ -54,7 +54,7 @@ public:
* @param[in] aType The type of the dataset, active or pending. * @param[in] aType The type of the dataset, active or pending.
* *
*/ */
DatasetLocal(otInstance &aInstance, const Tlv::Type aType); DatasetLocal(Instance &aInstance, const Tlv::Type aType);
/** /**
* This method indicates whether this is an Active or Pending Dataset. * This method indicates whether this is an Active or Pending Dataset.
+6 -5
View File
@@ -46,6 +46,7 @@
#include "common/code_utils.hpp" #include "common/code_utils.hpp"
#include "common/code_utils.hpp" #include "common/code_utils.hpp"
#include "common/debug.hpp" #include "common/debug.hpp"
#include "common/instance.hpp"
#include "common/logging.hpp" #include "common/logging.hpp"
#include "common/timer.hpp" #include "common/timer.hpp"
#include "meshcop/dataset.hpp" #include "meshcop/dataset.hpp"
@@ -59,7 +60,7 @@
namespace ot { namespace ot {
namespace MeshCoP { namespace MeshCoP {
DatasetManager::DatasetManager(otInstance &aInstance, const Tlv::Type aType, const char *aUriSet, DatasetManager::DatasetManager(Instance &aInstance, const Tlv::Type aType, const char *aUriSet,
const char *aUriGet, Timer::Handler aTimerHandler): const char *aUriGet, Timer::Handler aTimerHandler):
InstanceLocator(aInstance), InstanceLocator(aInstance),
mNetwork(aType), mNetwork(aType),
@@ -953,13 +954,13 @@ static ActiveDatasetBase &GetActiveDatasetOwner(const Context &aContext)
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
ActiveDatasetBase &activeDataset = *static_cast<ActiveDatasetBase *>(aContext.GetContext()); ActiveDatasetBase &activeDataset = *static_cast<ActiveDatasetBase *>(aContext.GetContext());
#else #else
ActiveDatasetBase &activeDataset = otGetThreadNetif().GetActiveDataset(); ActiveDatasetBase &activeDataset = Instance::Get().GetThreadNetif().GetActiveDataset();
OT_UNUSED_VARIABLE(aContext); OT_UNUSED_VARIABLE(aContext);
#endif #endif
return activeDataset; return activeDataset;
} }
ActiveDatasetBase::ActiveDatasetBase(otInstance &aInstance): ActiveDatasetBase::ActiveDatasetBase(Instance &aInstance):
DatasetManager(aInstance, Tlv::kActiveTimestamp, OT_URI_PATH_ACTIVE_SET, OT_URI_PATH_ACTIVE_GET, DatasetManager(aInstance, Tlv::kActiveTimestamp, OT_URI_PATH_ACTIVE_SET, OT_URI_PATH_ACTIVE_GET,
&ActiveDatasetBase::HandleTimer), &ActiveDatasetBase::HandleTimer),
mResourceGet(OT_URI_PATH_ACTIVE_GET, &ActiveDatasetBase::HandleGet, this) mResourceGet(OT_URI_PATH_ACTIVE_GET, &ActiveDatasetBase::HandleGet, this)
@@ -1051,13 +1052,13 @@ static PendingDatasetBase &GetPendingDatasetOwner(const Context &aContext)
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
PendingDatasetBase &pendingDataset = *static_cast<PendingDatasetBase *>(aContext.GetContext()); PendingDatasetBase &pendingDataset = *static_cast<PendingDatasetBase *>(aContext.GetContext());
#else #else
PendingDatasetBase &pendingDataset = otGetThreadNetif().GetPendingDataset(); PendingDatasetBase &pendingDataset = Instance::Get().GetThreadNetif().GetPendingDataset();
OT_UNUSED_VARIABLE(aContext); OT_UNUSED_VARIABLE(aContext);
#endif #endif
return pendingDataset; return pendingDataset;
} }
PendingDatasetBase::PendingDatasetBase(otInstance &aInstance): PendingDatasetBase::PendingDatasetBase(Instance &aInstance):
DatasetManager(aInstance, Tlv::kPendingTimestamp, OT_URI_PATH_PENDING_SET, OT_URI_PATH_PENDING_GET, DatasetManager(aInstance, Tlv::kPendingTimestamp, OT_URI_PATH_PENDING_SET, OT_URI_PATH_PENDING_GET,
&PendingDatasetBase::HandleTimer), &PendingDatasetBase::HandleTimer),
mDelayTimer(aInstance, &PendingDatasetBase::HandleDelayTimer, this), mDelayTimer(aInstance, &PendingDatasetBase::HandleDelayTimer, this),
+3 -3
View File
@@ -132,7 +132,7 @@ protected:
* @param[in] aTimerHandler The registration timer handler. * @param[in] aTimerHandler The registration timer handler.
* *
*/ */
DatasetManager(otInstance &aInstance, const Tlv::Type aType, const char *aUriSet, const char *aUriGet, DatasetManager(Instance &aInstance, const Tlv::Type aType, const char *aUriSet, const char *aUriGet,
TimerMilli::Handler aTimerHandler); TimerMilli::Handler aTimerHandler);
/** /**
@@ -282,7 +282,7 @@ public:
* @param[in] aInstance A reference to the OpenThread instance. * @param[in] aInstance A reference to the OpenThread instance.
* *
*/ */
ActiveDatasetBase(otInstance &aInstance); ActiveDatasetBase(Instance &aInstance);
/** /**
* This method restores the Active Operational Dataset from non-volatile memory. * This method restores the Active Operational Dataset from non-volatile memory.
@@ -364,7 +364,7 @@ public:
* @param[in] The Thread network interface. * @param[in] The Thread network interface.
* *
*/ */
PendingDatasetBase(otInstance &aInstance); PendingDatasetBase(Instance &aInstance);
/** /**
* This method restores the Operational Dataset from non-volatile memory. * This method restores the Operational Dataset from non-volatile memory.
+4 -5
View File
@@ -42,11 +42,10 @@
#include <openthread/platform/random.h> #include <openthread/platform/random.h>
#include <openthread/platform/radio.h> #include <openthread/platform/radio.h>
#include "common/code_utils.hpp"
#include "common/debug.hpp"
#include "coap/coap_header.hpp" #include "coap/coap_header.hpp"
#include "common/debug.hpp"
#include "common/code_utils.hpp" #include "common/code_utils.hpp"
#include "common/debug.hpp"
#include "common/instance.hpp"
#include "common/logging.hpp" #include "common/logging.hpp"
#include "common/timer.hpp" #include "common/timer.hpp"
#include "meshcop/dataset.hpp" #include "meshcop/dataset.hpp"
@@ -60,7 +59,7 @@
namespace ot { namespace ot {
namespace MeshCoP { namespace MeshCoP {
ActiveDataset::ActiveDataset(otInstance &aInstance): ActiveDataset::ActiveDataset(Instance &aInstance):
ActiveDatasetBase(aInstance), ActiveDatasetBase(aInstance),
mResourceSet(OT_URI_PATH_ACTIVE_SET, &ActiveDataset::HandleSet, this) mResourceSet(OT_URI_PATH_ACTIVE_SET, &ActiveDataset::HandleSet, this)
{ {
@@ -207,7 +206,7 @@ exit:
return; return;
} }
PendingDataset::PendingDataset(otInstance &aInstance): PendingDataset::PendingDataset(Instance &aInstance):
PendingDatasetBase(aInstance), PendingDatasetBase(aInstance),
mResourceSet(OT_URI_PATH_PENDING_SET, &PendingDataset::HandleSet, this) mResourceSet(OT_URI_PATH_PENDING_SET, &PendingDataset::HandleSet, this)
{ {
+2 -2
View File
@@ -53,7 +53,7 @@ namespace MeshCoP {
class ActiveDataset: public ActiveDatasetBase class ActiveDataset: public ActiveDatasetBase
{ {
public: public:
ActiveDataset(otInstance &aInstance); ActiveDataset(Instance &aInstance);
otError GenerateLocal(void); otError GenerateLocal(void);
@@ -74,7 +74,7 @@ private:
class PendingDataset: public PendingDatasetBase class PendingDataset: public PendingDatasetBase
{ {
public: public:
PendingDataset(otInstance &aInstance); PendingDataset(Instance &aInstance);
void StartLeader(void); void StartLeader(void);
+2 -2
View File
@@ -48,7 +48,7 @@ namespace MeshCoP {
class ActiveDataset: public ActiveDatasetBase class ActiveDataset: public ActiveDatasetBase
{ {
public: public:
ActiveDataset(otInstance &aInstance) : ActiveDatasetBase(aInstance) { } ActiveDataset(Instance &aInstance) : ActiveDatasetBase(aInstance) { }
otError GenerateLocal(void) { return OT_ERROR_NOT_IMPLEMENTED; } otError GenerateLocal(void) { return OT_ERROR_NOT_IMPLEMENTED; }
}; };
@@ -56,7 +56,7 @@ public:
class PendingDataset: public PendingDatasetBase class PendingDataset: public PendingDatasetBase
{ {
public: public:
PendingDataset(otInstance &aInstance) : PendingDatasetBase(aInstance) { } PendingDataset(Instance &aInstance) : PendingDatasetBase(aInstance) { }
}; };
} // namespace MeshCoP } // namespace MeshCoP
+3 -3
View File
@@ -38,10 +38,10 @@
#include <mbedtls/debug.h> #include <mbedtls/debug.h>
#include <openthread/platform/radio.h> #include <openthread/platform/radio.h>
#include "openthread-instance.h"
#include "common/code_utils.hpp" #include "common/code_utils.hpp"
#include "common/debug.hpp" #include "common/debug.hpp"
#include "common/encoding.hpp" #include "common/encoding.hpp"
#include "common/instance.hpp"
#include "common/logging.hpp" #include "common/logging.hpp"
#include "common/timer.hpp" #include "common/timer.hpp"
#include "crypto/sha256.hpp" #include "crypto/sha256.hpp"
@@ -52,7 +52,7 @@
namespace ot { namespace ot {
namespace MeshCoP { namespace MeshCoP {
Dtls::Dtls(otInstance &aInstance): Dtls::Dtls(Instance &aInstance):
InstanceLocator(aInstance), InstanceLocator(aInstance),
mPskLength(0), mPskLength(0),
mStarted(false), mStarted(false),
@@ -520,7 +520,7 @@ Dtls &Dtls::GetOwner(const Context &aContext)
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
Dtls &dtls = *static_cast<Dtls *>(aContext.GetContext()); Dtls &dtls = *static_cast<Dtls *>(aContext.GetContext());
#else #else
Dtls &dtls = otGetThreadNetif().GetDtls(); Dtls &dtls = Instance::Get().GetThreadNetif().GetDtls();
OT_UNUSED_VARIABLE(aContext); OT_UNUSED_VARIABLE(aContext);
#endif #endif
return dtls; return dtls;
+1 -1
View File
@@ -72,7 +72,7 @@ public:
* @param[in] aNetif A reference to the Thread network interface. * @param[in] aNetif A reference to the Thread network interface.
* *
*/ */
Dtls(otInstance &aInstance); Dtls(Instance &aInstance);
/** /**
* This function pointer is called when a connection is established or torn down. * This function pointer is called when a connection is established or torn down.
+2 -1
View File
@@ -41,6 +41,7 @@
#include "common/code_utils.hpp" #include "common/code_utils.hpp"
#include "common/debug.hpp" #include "common/debug.hpp"
#include "common/encoding.hpp" #include "common/encoding.hpp"
#include "coap/coap_header.hpp"
#include "common/logging.hpp" #include "common/logging.hpp"
#include "meshcop/meshcop.hpp" #include "meshcop/meshcop.hpp"
#include "meshcop/meshcop_tlvs.hpp" #include "meshcop/meshcop_tlvs.hpp"
@@ -54,7 +55,7 @@ using ot::Encoding::BigEndian::HostSwap32;
namespace ot { namespace ot {
EnergyScanClient::EnergyScanClient(otInstance &aInstance) : EnergyScanClient::EnergyScanClient(Instance &aInstance) :
InstanceLocator(aInstance), InstanceLocator(aInstance),
mEnergyScan(OT_URI_PATH_ENERGY_REPORT, &EnergyScanClient::HandleReport, this) mEnergyScan(OT_URI_PATH_ENERGY_REPORT, &EnergyScanClient::HandleReport, this)
{ {
+1 -1
View File
@@ -58,7 +58,7 @@ public:
* This constructor initializes the object. * This constructor initializes the object.
* *
*/ */
EnergyScanClient(otInstance &aInstance); EnergyScanClient(Instance &aInstance);
/** /**
* This method sends an Energy Scan Query message. * This method sends an Energy Scan Query message.
+3 -2
View File
@@ -44,6 +44,7 @@
#include "common/crc16.hpp" #include "common/crc16.hpp"
#include "common/debug.hpp" #include "common/debug.hpp"
#include "common/encoding.hpp" #include "common/encoding.hpp"
#include "common/instance.hpp"
#include "common/logging.hpp" #include "common/logging.hpp"
#include "mac/mac_frame.hpp" #include "mac/mac_frame.hpp"
#include "meshcop/meshcop.hpp" #include "meshcop/meshcop.hpp"
@@ -58,7 +59,7 @@ using ot::Encoding::BigEndian::HostSwap64;
namespace ot { namespace ot {
namespace MeshCoP { namespace MeshCoP {
Joiner::Joiner(otInstance &aInstance): Joiner::Joiner(Instance &aInstance):
InstanceLocator(aInstance), InstanceLocator(aInstance),
mState(OT_JOINER_STATE_IDLE), mState(OT_JOINER_STATE_IDLE),
mCallback(NULL), mCallback(NULL),
@@ -618,7 +619,7 @@ Joiner &Joiner::GetOwner(const Context &aContext)
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
Joiner &joiner = *static_cast<Joiner *>(aContext.GetContext()); Joiner &joiner = *static_cast<Joiner *>(aContext.GetContext());
#else #else
Joiner &joiner = otGetThreadNetif().GetJoiner(); Joiner &joiner = Instance::Get().GetThreadNetif().GetJoiner();
OT_UNUSED_VARIABLE(aContext); OT_UNUSED_VARIABLE(aContext);
#endif #endif
return joiner; return joiner;
+1 -1
View File
@@ -63,7 +63,7 @@ public:
* @param[in] aInstance A reference to the OpenThread instance. * @param[in] aInstance A reference to the OpenThread instance.
* *
*/ */
Joiner(otInstance &aInstance); Joiner(Instance &aInstance);
/** /**
* This method starts the Joiner service. * This method starts the Joiner service.
+4 -4
View File
@@ -39,9 +39,9 @@
#include <stdio.h> #include <stdio.h>
#include "openthread-instance.h"
#include "common/code_utils.hpp" #include "common/code_utils.hpp"
#include "common/encoding.hpp" #include "common/encoding.hpp"
#include "common/instance.hpp"
#include "common/logging.hpp" #include "common/logging.hpp"
#include "meshcop/meshcop.hpp" #include "meshcop/meshcop.hpp"
#include "meshcop/meshcop_tlvs.hpp" #include "meshcop/meshcop_tlvs.hpp"
@@ -55,9 +55,9 @@ using ot::Encoding::BigEndian::HostSwap64;
namespace ot { namespace ot {
namespace MeshCoP { namespace MeshCoP {
JoinerRouter::JoinerRouter(otInstance &aInstance): JoinerRouter::JoinerRouter(Instance &aInstance):
InstanceLocator(aInstance), InstanceLocator(aInstance),
mSocket(aInstance.mThreadNetif.GetIp6().GetUdp()), mSocket(aInstance.GetThreadNetif().GetIp6().GetUdp()),
mRelayTransmit(OT_URI_PATH_RELAY_TX, &JoinerRouter::HandleRelayTransmit, this), mRelayTransmit(OT_URI_PATH_RELAY_TX, &JoinerRouter::HandleRelayTransmit, this),
mTimer(aInstance, &JoinerRouter::HandleTimer, this), mTimer(aInstance, &JoinerRouter::HandleTimer, this),
mJoinerUdpPort(0), mJoinerUdpPort(0),
@@ -534,7 +534,7 @@ JoinerRouter &JoinerRouter::GetOwner(const Context &aContext)
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
JoinerRouter &joiner = *static_cast<JoinerRouter *>(aContext.GetContext()); JoinerRouter &joiner = *static_cast<JoinerRouter *>(aContext.GetContext());
#else #else
JoinerRouter &joiner = otGetThreadNetif().GetJoinerRouter(); JoinerRouter &joiner = Instance::Get().GetThreadNetif().GetJoinerRouter();
OT_UNUSED_VARIABLE(aContext); OT_UNUSED_VARIABLE(aContext);
#endif #endif
return joiner; return joiner;
+1 -1
View File
@@ -63,7 +63,7 @@ public:
* @param[in] aInstance A reference to the OpenThread instance. * @param[in] aInstance A reference to the OpenThread instance.
* *
*/ */
JoinerRouter(otInstance &aInstance); JoinerRouter(Instance &aInstance);
/** /**
* This method returns the Joiner UDP Port. * This method returns the Joiner UDP Port.
+3 -3
View File
@@ -41,9 +41,9 @@
#include <openthread/platform/random.h> #include <openthread/platform/random.h>
#include "openthread-instance.h"
#include "coap/coap_header.hpp" #include "coap/coap_header.hpp"
#include "common/code_utils.hpp" #include "common/code_utils.hpp"
#include "common/instance.hpp"
#include "common/logging.hpp" #include "common/logging.hpp"
#include "meshcop/meshcop.hpp" #include "meshcop/meshcop.hpp"
#include "meshcop/meshcop_tlvs.hpp" #include "meshcop/meshcop_tlvs.hpp"
@@ -54,7 +54,7 @@
namespace ot { namespace ot {
namespace MeshCoP { namespace MeshCoP {
Leader::Leader(otInstance &aInstance): Leader::Leader(Instance &aInstance):
InstanceLocator(aInstance), InstanceLocator(aInstance),
mPetition(OT_URI_PATH_LEADER_PETITION, Leader::HandlePetition, this), mPetition(OT_URI_PATH_LEADER_PETITION, Leader::HandlePetition, this),
mKeepAlive(OT_URI_PATH_LEADER_KEEP_ALIVE, Leader::HandleKeepAlive, this), mKeepAlive(OT_URI_PATH_LEADER_KEEP_ALIVE, Leader::HandleKeepAlive, this),
@@ -323,7 +323,7 @@ Leader &Leader::GetOwner(const Context &aContext)
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
Leader &leader = *static_cast<Leader *>(aContext.GetContext()); Leader &leader = *static_cast<Leader *>(aContext.GetContext());
#else #else
Leader &leader = otGetThreadNetif().GetLeader(); Leader &leader = Instance::Get().GetThreadNetif().GetLeader();
OT_UNUSED_VARIABLE(aContext); OT_UNUSED_VARIABLE(aContext);
#endif #endif
return leader; return leader;
+1 -1
View File
@@ -70,7 +70,7 @@ public:
* @param[in] aInstance A reference to the OpenThread instance. * @param[in] aInstance A reference to the OpenThread instance.
* *
*/ */
Leader(otInstance &aInstance); Leader(Instance &aInstance);
/** /**
* This method sends a MGMT_DATASET_CHANGED message to commissioner. * This method sends a MGMT_DATASET_CHANGED message to commissioner.
+2 -1
View File
@@ -40,6 +40,7 @@
#include "coap/coap_header.hpp" #include "coap/coap_header.hpp"
#include "common/code_utils.hpp" #include "common/code_utils.hpp"
#include "common/debug.hpp" #include "common/debug.hpp"
#include "common/instance.hpp"
#include "common/logging.hpp" #include "common/logging.hpp"
#include "meshcop/meshcop.hpp" #include "meshcop/meshcop.hpp"
#include "meshcop/meshcop_tlvs.hpp" #include "meshcop/meshcop_tlvs.hpp"
@@ -50,7 +51,7 @@
namespace ot { namespace ot {
PanIdQueryClient::PanIdQueryClient(otInstance &aInstance) : PanIdQueryClient::PanIdQueryClient(Instance &aInstance) :
InstanceLocator(aInstance), InstanceLocator(aInstance),
mCallback(NULL), mCallback(NULL),
mContext(NULL), mContext(NULL),
+1 -1
View File
@@ -58,7 +58,7 @@ public:
* This constructor initializes the object. * This constructor initializes the object.
* *
*/ */
PanIdQueryClient(otInstance &aInstance); PanIdQueryClient(Instance &aInstance);
/** /**
* This method sends a PAN ID Query message. * This method sends a PAN ID Query message.
+4 -4
View File
@@ -38,9 +38,9 @@
#include <openthread/types.h> #include <openthread/types.h>
#include <openthread/platform/random.h> #include <openthread/platform/random.h>
#include "openthread-instance.h"
#include "common/code_utils.hpp" #include "common/code_utils.hpp"
#include "common/encoding.hpp" #include "common/encoding.hpp"
#include "common/instance.hpp"
#include "common/logging.hpp" #include "common/logging.hpp"
#include "mac/mac.hpp" #include "mac/mac.hpp"
#include "net/dhcp6.hpp" #include "net/dhcp6.hpp"
@@ -56,9 +56,9 @@ namespace ot {
namespace Dhcp6 { namespace Dhcp6 {
Dhcp6Client::Dhcp6Client(otInstance &aInstance) : Dhcp6Client::Dhcp6Client(Instance &aInstance) :
InstanceLocator(aInstance), InstanceLocator(aInstance),
mSocket(aInstance.mThreadNetif.GetIp6().GetUdp()), mSocket(aInstance.GetThreadNetif().GetIp6().GetUdp()),
mTrickleTimer(aInstance, &Dhcp6Client::HandleTrickleTimer, NULL, this), mTrickleTimer(aInstance, &Dhcp6Client::HandleTrickleTimer, NULL, this),
mStartTime(0), mStartTime(0),
mAddresses(NULL), mAddresses(NULL),
@@ -721,7 +721,7 @@ Dhcp6Client &Dhcp6Client::GetOwner(const Context &aContext)
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
Dhcp6Client &client = *static_cast<Dhcp6Client *>(aContext.GetContext()); Dhcp6Client &client = *static_cast<Dhcp6Client *>(aContext.GetContext());
#else #else
Dhcp6Client &client = otGetThreadNetif().GetDhcp6Client(); Dhcp6Client &client = Instance::Get().GetThreadNetif().GetDhcp6Client();
OT_UNUSED_VARIABLE(aContext); OT_UNUSED_VARIABLE(aContext);
#endif #endif
return client; return client;
+1 -1
View File
@@ -179,7 +179,7 @@ public:
* @param[in] aInstance A reference to the OpenThread instance. * @param[in] aInstance A reference to the OpenThread instance.
* *
*/ */
explicit Dhcp6Client(otInstance &aInstance); explicit Dhcp6Client(Instance &aInstance);
/** /**
* This method update addresses that shall be automatically created using DHCP. * This method update addresses that shall be automatically created using DHCP.
+2 -1
View File
@@ -39,6 +39,7 @@
#include "common/code_utils.hpp" #include "common/code_utils.hpp"
#include "common/encoding.hpp" #include "common/encoding.hpp"
#include "common/instance.hpp"
#include "common/logging.hpp" #include "common/logging.hpp"
#include "thread/mle.hpp" #include "thread/mle.hpp"
#include "thread/thread_netif.hpp" #include "thread/thread_netif.hpp"
@@ -51,7 +52,7 @@ using ot::Encoding::BigEndian::HostSwap32;
namespace ot { namespace ot {
namespace Dhcp6 { namespace Dhcp6 {
Dhcp6Server::Dhcp6Server(otInstance &aInstance): Dhcp6Server::Dhcp6Server(Instance &aInstance):
InstanceLocator(aInstance), InstanceLocator(aInstance),
mSocket(GetNetif().GetIp6().GetUdp()) mSocket(GetNetif().GetIp6().GetUdp())
{ {
+1 -1
View File
@@ -111,7 +111,7 @@ public:
* @param[in] aInstance A reference to the OpenThread instance. * @param[in] aInstance A reference to the OpenThread instance.
* *
*/ */
explicit Dhcp6Server(otInstance &aInstance); explicit Dhcp6Server(Instance &aInstance);
/** /**
* This method updates DHCP Agents and DHCP Alocs. * This method updates DHCP Agents and DHCP Alocs.
+2 -1
View File
@@ -32,6 +32,7 @@
#include "common/code_utils.hpp" #include "common/code_utils.hpp"
#include "common/debug.hpp" #include "common/debug.hpp"
#include "common/instance.hpp"
#include "net/udp6.hpp" #include "net/udp6.hpp"
#include "thread/thread_netif.hpp" #include "thread/thread_netif.hpp"
@@ -523,7 +524,7 @@ Client &Client::GetOwner(const Context &aContext)
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
Client &client = *static_cast<Client *>(aContext.GetContext()); Client &client = *static_cast<Client *>(aContext.GetContext());
#else #else
Client &client = otGetThreadNetif().GetDnsClient(); Client &client = Instance::Get().GetThreadNetif().GetDnsClient();
OT_UNUSED_VARIABLE(aContext); OT_UNUSED_VARIABLE(aContext);
#endif #endif
return client; return client;
+2 -1
View File
@@ -39,6 +39,7 @@
#include "common/code_utils.hpp" #include "common/code_utils.hpp"
#include "common/debug.hpp" #include "common/debug.hpp"
#include "common/instance.hpp"
#include "common/logging.hpp" #include "common/logging.hpp"
#include "common/message.hpp" #include "common/message.hpp"
#include "net/ip6.hpp" #include "net/ip6.hpp"
@@ -48,7 +49,7 @@ using ot::Encoding::BigEndian::HostSwap16;
namespace ot { namespace ot {
namespace Ip6 { namespace Ip6 {
Icmp::Icmp(otInstance &aInstance): Icmp::Icmp(Instance &aInstance):
InstanceLocator(aInstance), InstanceLocator(aInstance),
mHandlers(NULL), mHandlers(NULL),
mEchoSequence(1), mEchoSequence(1),
+1 -1
View File
@@ -231,7 +231,7 @@ public:
* @param[in] aInstance A reference to the OpenThread instance. * @param[in] aInstance A reference to the OpenThread instance.
* *
*/ */
Icmp(otInstance &aInstance); Icmp(Instance &aInstance);
/** /**
* This method returns a new ICMP message with sufficient header space reserved. * This method returns a new ICMP message with sufficient header space reserved.
+6 -6
View File
@@ -35,9 +35,9 @@
#include "ip6.hpp" #include "ip6.hpp"
#include "openthread-instance.h"
#include "common/code_utils.hpp" #include "common/code_utils.hpp"
#include "common/debug.hpp" #include "common/debug.hpp"
#include "common/instance.hpp"
#include "common/logging.hpp" #include "common/logging.hpp"
#include "common/message.hpp" #include "common/message.hpp"
#include "net/icmp6.hpp" #include "net/icmp6.hpp"
@@ -50,7 +50,7 @@
namespace ot { namespace ot {
namespace Ip6 { namespace Ip6 {
Ip6::Ip6(otInstance &aInstance): Ip6::Ip6(Instance &aInstance):
InstanceLocator(aInstance), InstanceLocator(aInstance),
mForwardingEnabled(false), mForwardingEnabled(false),
mIsReceiveIp6FilterEnabled(false), mIsReceiveIp6FilterEnabled(false),
@@ -68,8 +68,8 @@ Ip6::Ip6(otInstance &aInstance):
Message *Ip6::NewMessage(uint16_t aReserved) Message *Ip6::NewMessage(uint16_t aReserved)
{ {
return GetInstance().mMessagePool.New(Message::kTypeIp6, return GetInstance().GetMessagePool().New(Message::kTypeIp6,
sizeof(Header) + sizeof(HopByHopHeader) + sizeof(OptionMpl) + aReserved); sizeof(Header) + sizeof(HopByHopHeader) + sizeof(OptionMpl) + aReserved);
} }
uint16_t Ip6::UpdateChecksum(uint16_t aChecksum, const Address &aAddress) uint16_t Ip6::UpdateChecksum(uint16_t aChecksum, const Address &aAddress)
@@ -613,7 +613,7 @@ otError Ip6::ProcessReceiveCallback(const Message &aMessage, const MessageInfo &
case kCoapUdpPort: case kCoapUdpPort:
// do not pass TMF messages // do not pass TMF messages
if (GetInstance().mThreadNetif.IsTmfMessage(aMessageInfo)) if (GetInstance().GetThreadNetif().IsTmfMessage(aMessageInfo))
{ {
ExitNow(error = OT_ERROR_NO_ROUTE); ExitNow(error = OT_ERROR_NO_ROUTE);
} }
@@ -1120,7 +1120,7 @@ Ip6 &Ip6::GetOwner(const Context &aContext)
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES #if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
Ip6 &ip6 = *static_cast<Ip6 *>(aContext.GetContext()); Ip6 &ip6 = *static_cast<Ip6 *>(aContext.GetContext());
#else #else
Ip6 &ip6 = otGetIp6(); Ip6 &ip6 = Instance::Get().GetIp6();
OT_UNUSED_VARIABLE(aContext); OT_UNUSED_VARIABLE(aContext);
#endif #endif
return ip6; return ip6;
+1 -1
View File
@@ -123,7 +123,7 @@ public:
* @param[in] aInstance A reference to the otInstance object. * @param[in] aInstance A reference to the otInstance object.
* *
*/ */
Ip6(otInstance &aInstance); Ip6(Instance &aInstance);
/** /**
* This method sends an IPv6 datagram. * This method sends an IPv6 datagram.
+1
View File
@@ -38,6 +38,7 @@
#include "common/code_utils.hpp" #include "common/code_utils.hpp"
#include "common/encoding.hpp" #include "common/encoding.hpp"
#include "common/instance.hpp"
#include "mac/mac_frame.hpp" #include "mac/mac_frame.hpp"
using ot::Encoding::BigEndian::HostSwap16; using ot::Encoding::BigEndian::HostSwap16;

Some files were not shown because too many files have changed in this diff Show More