otInstance Declarations (#473)

* Add otInstance type declaration and update ot APIs to take it as input.
This commit is contained in:
Nick Banks
2016-09-12 14:29:43 -07:00
committed by Jonathan Hui
parent 9b1de7bbb2
commit ffbe65c6dd
67 changed files with 1560 additions and 1099 deletions
+4
View File
@@ -0,0 +1,4 @@
* text=lf
*.vcxproj eol=crlf
*.vcxproj.filters eol=crlf
*.sln eol=crlf
-92
View File
@@ -1,92 +0,0 @@
#
# Copyright (c) 2016, Nest Labs, Inc.
# 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.
#
XML2RFC_CACHE_DIR ?= $(HOME)/.cache/xml2rfc
TOOL_PREFIX = $(DOCKER) run --rm --user=`id -u`:`id -g` -v `pwd`:/rfc -v $(XML2RFC_CACHE_DIR):/var/cache/xml2rfc paulej/rfctools
DOCKER ?= docker
MD2RFC ?= $(TOOL_PREFIX) md2rfc
XML2RFC ?= $(TOOL_PREFIX) xml2rfc
MMARK ?= $(TOOL_PREFIX) mmark
SED ?= sed
RM_F ?= rm -f
MKDIR_P ?= mkdir -p
SOURCE_DATE := $(shell (TZ=UTC git log -n 1 --date=iso-strict-local --pretty=format:%ad 2> /dev/null || date -u +"%Y-%m-%dT%H:%M:%SZ" ) | sed 's/+00:00$$/Z/')
SOURCE_VERSION := $(shell git describe --dirty --always --match "--PoIsOn--" 2> /dev/null)
# -------------
SRC := $(wildcard draft-*.md) $(wildcard draft-*.md.in)
XML := $(patsubst %.md,%.xml,$(patsubst %.md.in,%.xml,$(SRC)))
TXT := $(patsubst %.md,%.txt,$(patsubst %.md.in,%.txt,$(SRC)))
HTML := $(patsubst %.md,%.html,$(patsubst %.md.in,%.html,$(SRC)))
all: $(XML) $(TXT) $(HTML)
clean:
$(RM_F) $(XML) $(TXT) $(HTML) $(patsubst %.md.in,%.md,$(wildcard draft-*.md.in))
$(XML2RFC_CACHE_DIR):
$(MKDIR_P) "$(XML2RFC_CACHE_DIR)"
%.md: %.md.in
$(SED) 's/@SOURCE_VERSION@/$(SOURCE_VERSION)/g;s/@SOURCE_DATE@/$(SOURCE_DATE)/g' < $< > $@
%.xml: %.md
$(MMARK) -xml2 -page $< $@
%.html: %.xml $(XML2RFC_CACHE_DIR)
$(XML2RFC) --html $<
%.txt: %.xml $(XML2RFC_CACHE_DIR)
$(XML2RFC) --text $<
# -------------
draft-spinel-protocol-bis.xml: \
draft-spinel-protocol-bis.md \
spinel-commands.md \
spinel-data-packing.md \
spinel-example-sessions.md \
spinel-feature-host-buffer-offload.md \
spinel-feature-network-save.md \
spinel-frame-format.md \
spinel-framing.md \
spinel-prop-core.md \
spinel-prop-ipv6.md \
spinel-prop-mac.md \
spinel-prop-net.md \
spinel-prop-phy.md \
spinel-prop.md \
spinel-status-codes.md \
spinel-tech-thread.md \
spinel-test-vectors.md \
$(NULL)
+1
View File
@@ -34,6 +34,7 @@ bin_PROGRAMS = \
ot_cli_CPPFLAGS = \
-I$(top_srcdir)/include \
-I$(top_srcdir)/src/core \
-I$(top_srcdir)/examples/platforms \
$(NULL)
+36 -6
View File
@@ -26,31 +26,61 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <openthread-core-config.h>
#include <openthread.h>
#include <openthread-config.h>
#include <openthread-diag.h>
#include <cli/cli-uart.h>
#include <platform/platform.h>
#include <assert.h>
void otSignalTaskletPending(void)
void otSignalTaskletPending(otInstance *aInstance)
{
(void)aInstance;
}
int main(int argc, char *argv[])
{
otInstance *sInstance;
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
uint64_t otInstanceBufferLength = 0;
uint8_t *otInstanceBuffer = NULL;
#endif
PlatformInit(argc, argv);
otEnable();
otCliUartInit();
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
// Call to query the buffer size
(void)otInstanceInit(NULL, &otInstanceBufferLength);
// Call to allocate the buffer
otInstanceBuffer = (uint8_t *)malloc(otInstanceBufferLength);
assert(otInstanceBuffer);
// Initialize Openthread with the buffer
sInstance = otInstanceInit(otInstanceBuffer, &otInstanceBufferLength);
#else
sInstance = otInstanceInit();
#endif
assert(sInstance);
otCliUartInit(sInstance);
#if OPENTHREAD_ENABLE_DIAG
diagInit();
diagInit(sInstance);
#endif
while (1)
{
otProcessNextTasklet();
PlatformProcessDrivers();
otProcessNextTasklet(sInstance);
PlatformProcessDrivers(sInstance);
}
// otInstanceFinalize(sInstance);
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
// free(otInstanceBuffer);
#endif
return 0;
}
+1
View File
@@ -34,6 +34,7 @@ bin_PROGRAMS = \
ot_ncp_CPPFLAGS = \
-I$(top_srcdir)/include \
-I$(top_srcdir)/src/core \
-I$(top_srcdir)/examples/platforms \
$(NULL)
+36 -6
View File
@@ -26,31 +26,61 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <openthread-core-config.h>
#include <openthread.h>
#include <openthread-config.h>
#include <openthread-diag.h>
#include <common/debug.hpp>
#include <ncp/ncp.h>
#include <platform/platform.h>
void otSignalTaskletPending(void)
void otSignalTaskletPending(otInstance *aInstance)
{
(void)aInstance;
}
int main(int argc, char *argv[])
{
otInstance *sInstance;
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
uint64_t otInstanceBufferLength = 0;
uint8_t *otInstanceBuffer = NULL;
#endif
PlatformInit(argc, argv);
otEnable();
otNcpInit();
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
// Call to query the buffer size
(void)otInstanceInit(NULL, &otInstanceBufferLength);
// Call to allocate the buffer
otInstanceBuffer = (uint8_t *)malloc(otInstanceBufferLength);
assert(otInstanceBuffer);
// Initialize Openthread with the buffer
sInstance = otInstanceInit(otInstanceBuffer, &otInstanceBufferLength);
#else
sInstance = otInstanceInit();
#endif
assert(sInstance);
otNcpInit(sInstance);
#if OPENTHREAD_ENABLE_DIAG
diagInit();
diagInit(sInstance);
#endif
while (1)
{
otProcessNextTasklet();
PlatformProcessDrivers();
otProcessNextTasklet(sInstance);
PlatformProcessDrivers(sInstance);
}
// otInstanceFinalize(sInstance);
#ifdef OPENTHREAD_MULTIPLE_INSTANCE
// free(otInstanceBuffer);
#endif
return 0;
}
+1
View File
@@ -32,6 +32,7 @@ lib_LIBRARIES = libopenthread-cc2538.a
libopenthread_cc2538_a_CPPFLAGS = \
-I$(top_srcdir)/include \
-I$(top_srcdir)/examples/platforms \
-I$(top_srcdir)/src/core \
$(NULL)
+10 -5
View File
@@ -36,6 +36,9 @@
#include <stdint.h>
#include <openthread-config.h>
#include <openthread.h>
#include <platform/platform.h>
#include <platform/alarm.h>
#include <platform/diag.h>
#include "platform-cc2538.h"
@@ -62,19 +65,21 @@ uint32_t otPlatAlarmGetNow(void)
return sCounter;
}
void otPlatAlarmStartAt(uint32_t t0, uint32_t dt)
void otPlatAlarmStartAt(otInstance *aInstance, uint32_t t0, uint32_t dt)
{
(void)aInstance;
sAlarmT0 = t0;
sAlarmDt = dt;
sIsRunning = true;
}
void otPlatAlarmStop(void)
void otPlatAlarmStop(otInstance *aInstance)
{
(void)aInstance;
sIsRunning = false;
}
void cc2538AlarmProcess(void)
void cc2538AlarmProcess(otInstance *aInstance)
{
uint32_t expires;
bool fire = false;
@@ -106,12 +111,12 @@ void cc2538AlarmProcess(void)
if (otPlatDiagModeGet())
{
otPlatDiagAlarmFired();
otPlatDiagAlarmFired(aInstance);
}
else
#endif
{
otPlatAlarmFired();
otPlatAlarmFired(aInstance);
}
}
}
+3
View File
@@ -31,6 +31,9 @@
#include <string.h>
#include <sys/time.h>
#include <openthread-config.h>
#include <openthread.h>
#include <platform/alarm.h>
#include "platform-cc2538.h"
+5 -2
View File
@@ -26,16 +26,19 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <openthread-types.h>
#include <platform/misc.h>
#include "platform-cc2538.h"
void otPlatReset(void)
void otPlatReset(otInstance *aInstance)
{
(void)aInstance;
HWREG(SYS_CTRL_PWRDBG) = SYS_CTRL_PWRDBG_FORCE_WARM_RESET;
}
otPlatResetReason otPlatGetResetReason(void)
otPlatResetReason otPlatGetResetReason(otInstance *aInstance)
{
(void)aInstance;
// TODO: Write me!
return kPlatResetReason_PowerOn;
}
+10 -2
View File
@@ -36,9 +36,13 @@
#define PLATFORM_CC2538_H_
#include <stdint.h>
#include <openthread-types.h>
#include "cc2538-reg.h"
// Global OpenThread instance structure
extern otInstance *sInstance;
/**
* This function initializes the alarm service used by OpenThread.
*
@@ -48,8 +52,10 @@ void cc2538AlarmInit(void);
/**
* This function performs alarm driver processing.
*
* @param[in] aInstance The OpenThread instance structure.
*
*/
void cc2538AlarmProcess(void);
void cc2538AlarmProcess(otInstance *aInstance);
/**
* This function initializes the radio service used by OpenThread.
@@ -60,8 +66,10 @@ void cc2538RadioInit(void);
/**
* This function performs radio driver processing.
*
* @param[in] aInstance The OpenThread instance structure.
*
*/
void cc2538RadioProcess(void);
void cc2538RadioProcess(otInstance *aInstance);
/**
* This function initializes the random number service used by OpenThread.
+7 -3
View File
@@ -35,6 +35,8 @@
#include <platform/uart.h>
#include "platform-cc2538.h"
otInstance *sInstance;
void PlatformInit(int argc, char *argv[])
{
cc2538AlarmInit();
@@ -46,11 +48,13 @@ void PlatformInit(int argc, char *argv[])
(void)argv;
}
void PlatformProcessDrivers(void)
void PlatformProcessDrivers(otInstance *aInstance)
{
sInstance = aInstance;
// should sleep and wait for interrupts here
cc2538UartProcess();
cc2538RadioProcess();
cc2538AlarmProcess();
cc2538RadioProcess(aInstance);
cc2538AlarmProcess(aInstance);
}
+38 -21
View File
@@ -33,9 +33,11 @@
*/
#include <openthread-types.h>
#include <openthread.h>
#include <openthread-config.h>
#include <common/code_utils.hpp>
#include <platform/platform.h>
#include <platform/radio.h>
#include <platform/diag.h>
#include "platform-cc2538.h"
@@ -109,9 +111,10 @@ void setChannel(uint8_t channel)
HWREG(RFCORE_XREG_FREQCTRL) = 11 + (channel - 11) * 5;
}
ThreadError otPlatRadioSetPanId(uint16_t panid)
ThreadError otPlatRadioSetPanId(otInstance *aInstance, uint16_t panid)
{
ThreadError error = kThreadError_Busy;
(void)aInstance;
if (sState != kStateTransmit)
{
@@ -123,9 +126,10 @@ ThreadError otPlatRadioSetPanId(uint16_t panid)
return error;
}
ThreadError otPlatRadioSetExtendedAddress(uint8_t *address)
ThreadError otPlatRadioSetExtendedAddress(otInstance *aInstance, uint8_t *address)
{
ThreadError error = kThreadError_Busy;
(void)aInstance;
if (sState != kStateTransmit)
{
@@ -142,9 +146,10 @@ ThreadError otPlatRadioSetExtendedAddress(uint8_t *address)
return error;
}
ThreadError otPlatRadioSetShortAddress(uint16_t address)
ThreadError otPlatRadioSetShortAddress(otInstance *aInstance, uint16_t address)
{
ThreadError error = kThreadError_Busy;
(void)aInstance;
if (sState != kStateTransmit)
{
@@ -183,9 +188,10 @@ void cc2538RadioInit(void)
HWREG(RFCORE_XREG_SRCMATCH) = 0;
}
ThreadError otPlatRadioEnable(void)
ThreadError otPlatRadioEnable(otInstance *aInstance)
{
ThreadError error = kThreadError_Busy;
(void)aInstance;
if (sState == kStateSleep || sState == kStateDisabled)
{
@@ -196,9 +202,10 @@ ThreadError otPlatRadioEnable(void)
return error;
}
ThreadError otPlatRadioDisable(void)
ThreadError otPlatRadioDisable(otInstance *aInstance)
{
ThreadError error = kThreadError_Busy;
(void)aInstance;
if (sState == kStateDisabled || sState == kStateSleep)
{
@@ -209,14 +216,16 @@ ThreadError otPlatRadioDisable(void)
return error;
}
bool otPlatRadioIsEnabled(void)
bool otPlatRadioIsEnabled(otInstance *aInstance)
{
(void)aInstance;
return (sState != kStateDisabled) ? true : false;
}
ThreadError otPlatRadioSleep(void)
ThreadError otPlatRadioSleep(otInstance *aInstance)
{
ThreadError error = kThreadError_Busy;
(void)aInstance;
if (sState == kStateSleep || sState == kStateReceive)
{
@@ -228,9 +237,10 @@ ThreadError otPlatRadioSleep(void)
return error;
}
ThreadError otPlatRadioReceive(uint8_t aChannel)
ThreadError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel)
{
ThreadError error = kThreadError_Busy;
(void)aInstance;
if (sState != kStateDisabled)
{
@@ -244,9 +254,10 @@ ThreadError otPlatRadioReceive(uint8_t aChannel)
return error;
}
ThreadError otPlatRadioTransmit(void)
ThreadError otPlatRadioTransmit(otInstance *aInstance)
{
ThreadError error = kThreadError_Busy;
(void)aInstance;
if (sState == kStateReceive)
{
@@ -291,28 +302,34 @@ exit:
return error;
}
RadioPacket *otPlatRadioGetTransmitBuffer(void)
RadioPacket *otPlatRadioGetTransmitBuffer(otInstance *aInstance)
{
(void)aInstance;
return &sTransmitFrame;
}
int8_t otPlatRadioGetRssi(void)
int8_t otPlatRadioGetRssi(otInstance *aInstance)
{
(void)aInstance;
return 0;
}
otRadioCaps otPlatRadioGetCaps(void)
otRadioCaps otPlatRadioGetCaps(otInstance *aInstance)
{
(void)aInstance;
return kRadioCapsNone;
}
bool otPlatRadioGetPromiscuous(void)
bool otPlatRadioGetPromiscuous(otInstance *aInstance)
{
(void)aInstance;
return (HWREG(RFCORE_XREG_FRMFILT0) & RFCORE_XREG_FRMFILT0_FRAME_FILTER_EN) == 0;
}
void otPlatRadioSetPromiscuous(bool aEnable)
void otPlatRadioSetPromiscuous(otInstance *aInstance, bool aEnable)
{
(void)aInstance;
if (aEnable)
{
HWREG(RFCORE_XREG_FRMFILT0) &= ~RFCORE_XREG_FRMFILT0_FRAME_FILTER_EN;
@@ -363,7 +380,7 @@ exit:
return;
}
void cc2538RadioProcess(void)
void cc2538RadioProcess(otInstance *aInstance)
{
readFrame();
@@ -373,12 +390,12 @@ void cc2538RadioProcess(void)
if (otPlatDiagModeGet())
{
otPlatDiagRadioReceiveDone(&sReceiveFrame, sReceiveError);
otPlatDiagRadioReceiveDone(aInstance, &sReceiveFrame, sReceiveError);
}
else
#endif
{
otPlatRadioReceiveDone(&sReceiveFrame, sReceiveError);
otPlatRadioReceiveDone(aInstance, &sReceiveFrame, sReceiveError);
}
}
@@ -392,12 +409,12 @@ void cc2538RadioProcess(void)
if (otPlatDiagModeGet())
{
otPlatDiagRadioTransmitDone(false, sTransmitError);
otPlatDiagRadioTransmitDone(aInstance, false, sTransmitError);
}
else
#endif
{
otPlatRadioTransmitDone(false, sTransmitError);
otPlatRadioTransmitDone(aInstance, false, sTransmitError);
}
}
else if (sReceiveFrame.mLength == IEEE802154_ACK_LENGTH &&
@@ -410,12 +427,12 @@ void cc2538RadioProcess(void)
if (otPlatDiagModeGet())
{
otPlatDiagRadioTransmitDone((sReceiveFrame.mPsdu[0] & IEEE802154_FRAME_PENDING) != 0, sTransmitError);
otPlatDiagRadioTransmitDone(aInstance, (sReceiveFrame.mPsdu[0] & IEEE802154_FRAME_PENDING) != 0, sTransmitError);
}
else
#endif
{
otPlatRadioTransmitDone((sReceiveFrame.mPsdu[0] & IEEE802154_FRAME_PENDING) != 0, sTransmitError);
otPlatRadioTransmitDone(aInstance, (sReceiveFrame.mPsdu[0] & IEEE802154_FRAME_PENDING) != 0, sTransmitError);
}
}
}
+5 -5
View File
@@ -103,11 +103,11 @@ ThreadError otPlatRandomSecureGet(uint16_t aInputLength, uint8_t *aOutput, uint1
VerifyOrExit(aOutput && aOutputLength, error = kThreadError_InvalidArgs);
if (otPlatRadioIsEnabled())
if (otPlatRadioIsEnabled(sInstance))
{
channel = 11 + (HWREG(RFCORE_XREG_FREQCTRL) - 11) / 5;
otPlatRadioSleep();
otPlatRadioDisable();
otPlatRadioSleep(sInstance);
otPlatRadioDisable(sInstance);
}
generateRandom(aInputLength, aOutput, aOutputLength);
@@ -115,8 +115,8 @@ ThreadError otPlatRandomSecureGet(uint16_t aInputLength, uint8_t *aOutput, uint1
if (channel)
{
cc2538RadioInit();
otPlatRadioEnable();
otPlatRadioReceive(channel);
otPlatRadioEnable(sInstance);
otPlatRadioReceive(sInstance, channel);
}
exit:
+1
View File
@@ -32,6 +32,7 @@ lib_LIBRARIES = libopenthread-posix.a
libopenthread_posix_a_CPPFLAGS = \
-I$(top_srcdir)/include \
-I$(top_srcdir)/examples/platforms \
-I$(top_srcdir)/src/core \
-D_GNU_SOURCE \
$(NULL)
+9 -5
View File
@@ -31,7 +31,9 @@
#include <string.h>
#include <sys/time.h>
#include <openthread.h>
#include <openthread-config.h>
#include <platform/alarm.h>
#include <platform/diag.h>
#include "platform-posix.h"
@@ -55,14 +57,16 @@ uint32_t otPlatAlarmGetNow(void)
return (uint32_t)((tv.tv_sec * 1000) + (tv.tv_usec / 1000));
}
void otPlatAlarmStartAt(uint32_t t0, uint32_t dt)
void otPlatAlarmStartAt(otInstance *aInstance, uint32_t t0, uint32_t dt)
{
(void)aInstance;
s_alarm = t0 + dt;
s_is_running = true;
}
void otPlatAlarmStop(void)
void otPlatAlarmStop(otInstance *aInstance)
{
(void)aInstance;
s_is_running = false;
}
@@ -97,7 +101,7 @@ void posixAlarmUpdateTimeout(struct timeval *aTimeout)
}
}
void posixAlarmProcess(void)
void posixAlarmProcess(otInstance *aInstance)
{
int32_t remaining;
@@ -113,12 +117,12 @@ void posixAlarmProcess(void)
if (otPlatDiagModeGet())
{
otPlatDiagAlarmFired();
otPlatDiagAlarmFired(aInstance);
}
else
#endif
{
otPlatAlarmFired();
otPlatAlarmFired(aInstance);
}
}
}
+3
View File
@@ -31,6 +31,9 @@
#include <string.h>
#include <sys/time.h>
#include <openthread-config.h>
#include <openthread.h>
#include <platform/alarm.h>
#include "platform-posix.h"
+5 -2
View File
@@ -26,15 +26,18 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <openthread-types.h>
#include <platform/misc.h>
#include "platform-posix.h"
void otPlatReset(void)
void otPlatReset(otInstance *aInstance)
{
// This function does nothing on the Posix platform.
(void)aInstance;
}
otPlatResetReason otPlatGetResetReason(void)
otPlatResetReason otPlatGetResetReason(otInstance *aInstance)
{
(void)aInstance;
return kPlatResetReason_PowerOn;
}
+8 -2
View File
@@ -39,6 +39,8 @@
#include <sys/select.h>
#include <sys/time.h>
#include <openthread-types.h>
/**
* Unique node ID.
*
@@ -68,8 +70,10 @@ void posixAlarmUpdateTimeout(struct timeval *tv);
/**
* This function performs alarm driver processing.
*
* @param[in] aInstance The OpenThread instance structure.
*
*/
void posixAlarmProcess(void);
void posixAlarmProcess(otInstance *aInstance);
/**
* This function initializes the radio service used by OpenThread.
@@ -90,8 +94,10 @@ void posixRadioUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMaxFd)
/**
* This function performs radio driver processing.
*
* @param[in] aInstance The OpenThread instance structure.
*
*/
void posixRadioProcess(void);
void posixRadioProcess(otInstance *aInstance);
/**
* This function initializes the random number service used by OpenThread.
+4 -4
View File
@@ -71,7 +71,7 @@ void PlatformInit(int argc, char *argv[])
otPlatUartEnable();
}
void PlatformProcessDrivers(void)
void PlatformProcessDrivers(otInstance *aInstance)
{
fd_set read_fds;
fd_set write_fds;
@@ -88,7 +88,7 @@ void PlatformProcessDrivers(void)
posixRadioUpdateFdSet(&read_fds, &write_fds, &max_fd);
posixAlarmUpdateTimeout(&timeout);
if (!otAreTaskletsPending())
if (!otAreTaskletsPending(aInstance))
{
rval = select(max_fd + 1, &read_fds, &write_fds, &error_fds, &timeout);
@@ -100,7 +100,7 @@ void PlatformProcessDrivers(void)
}
posixUartProcess();
posixRadioProcess();
posixAlarmProcess();
posixRadioProcess(aInstance);
posixAlarmProcess(aInstance);
}
+45 -29
View File
@@ -39,7 +39,9 @@
#include <sys/stat.h>
#include <unistd.h>
#include <openthread.h>
#include <openthread-config.h>
#include <platform/radio.h>
#include <platform/diag.h>
@@ -95,9 +97,9 @@ struct OT_TOOL_PACKED_BEGIN RadioMessage
} OT_TOOL_PACKED_END;
static void radioTransmit(const struct RadioMessage *msg, const struct RadioPacket *pkt);
static void radioSendMessage(void);
static void radioSendMessage(otInstance *aInstance);
static void radioSendAck(void);
static void radioProcessFrame(void);
static void radioProcessFrame(otInstance *aInstance);
static PhyState sState = kStateDisabled;
static struct RadioMessage sReceiveMessage;
@@ -258,9 +260,10 @@ static inline void getExtAddress(const uint8_t *frame, otExtAddress *address)
}
}
ThreadError otPlatRadioSetPanId(uint16_t panid)
ThreadError otPlatRadioSetPanId(otInstance *aInstance, uint16_t panid)
{
ThreadError error = kThreadError_Busy;
(void)aInstance;
if (sState != kStateTransmit)
{
@@ -271,9 +274,10 @@ ThreadError otPlatRadioSetPanId(uint16_t panid)
return error;
}
ThreadError otPlatRadioSetExtendedAddress(uint8_t *address)
ThreadError otPlatRadioSetExtendedAddress(otInstance *aInstance, uint8_t *address)
{
ThreadError error = kThreadError_Busy;
(void)aInstance;
if (sState != kStateTransmit)
{
@@ -290,9 +294,10 @@ ThreadError otPlatRadioSetExtendedAddress(uint8_t *address)
return error;
}
ThreadError otPlatRadioSetShortAddress(uint16_t address)
ThreadError otPlatRadioSetShortAddress(otInstance *aInstance, uint16_t address)
{
ThreadError error = kThreadError_Busy;
(void)aInstance;
if (sState != kStateTransmit)
{
@@ -303,8 +308,9 @@ ThreadError otPlatRadioSetShortAddress(uint16_t address)
return error;
}
void otPlatRadioSetPromiscuous(bool aEnable)
void otPlatRadioSetPromiscuous(otInstance *aInstance, bool aEnable)
{
(void)aInstance;
sPromiscuous = aEnable;
}
@@ -351,9 +357,10 @@ void posixRadioInit(void)
sAckFrame.mPsdu = sAckMessage.mPsdu;
}
ThreadError otPlatRadioEnable(void)
ThreadError otPlatRadioEnable(otInstance *aInstance)
{
ThreadError error = kThreadError_Busy;
(void)aInstance;
if (sState == kStateSleep || sState == kStateDisabled)
{
@@ -364,9 +371,10 @@ ThreadError otPlatRadioEnable(void)
return error;
}
ThreadError otPlatRadioDisable(void)
ThreadError otPlatRadioDisable(otInstance *aInstance)
{
ThreadError error = kThreadError_Busy;
(void)aInstance;
if (sState == kStateDisabled || sState == kStateSleep)
{
@@ -377,14 +385,16 @@ ThreadError otPlatRadioDisable(void)
return error;
}
bool otPlatRadioIsEnabled(void)
bool otPlatRadioIsEnabled(otInstance *aInstance)
{
(void)aInstance;
return (sState != kStateDisabled) ? true : false;
}
ThreadError otPlatRadioSleep(void)
ThreadError otPlatRadioSleep(otInstance *aInstance)
{
ThreadError error = kThreadError_Busy;
(void)aInstance;
if (sState == kStateSleep || sState == kStateReceive)
{
@@ -395,9 +405,10 @@ ThreadError otPlatRadioSleep(void)
return error;
}
ThreadError otPlatRadioReceive(uint8_t aChannel)
ThreadError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel)
{
ThreadError error = kThreadError_Busy;
(void)aInstance;
if (sState != kStateDisabled)
{
@@ -410,9 +421,10 @@ ThreadError otPlatRadioReceive(uint8_t aChannel)
return error;
}
ThreadError otPlatRadioTransmit(void)
ThreadError otPlatRadioTransmit(otInstance *aInstance)
{
ThreadError error = kThreadError_Busy;
(void)aInstance;
if ((sState == kStateTransmit && !sAckWait) || sState == kStateReceive)
{
@@ -423,27 +435,31 @@ ThreadError otPlatRadioTransmit(void)
return error;
}
RadioPacket *otPlatRadioGetTransmitBuffer(void)
RadioPacket *otPlatRadioGetTransmitBuffer(otInstance *aInstance)
{
(void)aInstance;
return &sTransmitFrame;
}
int8_t otPlatRadioGetRssi(void)
int8_t otPlatRadioGetRssi(otInstance *aInstance)
{
(void)aInstance;
return 0;
}
otRadioCaps otPlatRadioGetCaps(void)
otRadioCaps otPlatRadioGetCaps(otInstance *aInstance)
{
(void)aInstance;
return kRadioCapsNone;
}
bool otPlatRadioGetPromiscuous(void)
bool otPlatRadioGetPromiscuous(otInstance *aInstance)
{
(void)aInstance;
return sPromiscuous;
}
void radioReceive(void)
void radioReceive(otInstance *aInstance)
{
ssize_t rval = recvfrom(sSockFd, &sReceiveMessage, sizeof(sReceiveMessage), 0, NULL, NULL);
@@ -467,22 +483,22 @@ void radioReceive(void)
if (otPlatDiagModeGet())
{
otPlatDiagRadioTransmitDone(isFramePending(sReceiveFrame.mPsdu), kThreadError_None);
otPlatDiagRadioTransmitDone(aInstance, isFramePending(sReceiveFrame.mPsdu), kThreadError_None);
}
else
#endif
{
otPlatRadioTransmitDone(isFramePending(sReceiveFrame.mPsdu), kThreadError_None);
otPlatRadioTransmitDone(aInstance, isFramePending(sReceiveFrame.mPsdu), kThreadError_None);
}
}
else if ((sState == kStateReceive || sState == kStateTransmit) &&
(sReceiveFrame.mChannel == sReceiveMessage.mChannel))
{
radioProcessFrame();
radioProcessFrame(aInstance);
}
}
void radioSendMessage(void)
void radioSendMessage(otInstance *aInstance)
{
sTransmitMessage.mChannel = sTransmitFrame.mChannel;
@@ -498,12 +514,12 @@ void radioSendMessage(void)
if (otPlatDiagModeGet())
{
otPlatDiagRadioTransmitDone(false, kThreadError_None);
otPlatDiagRadioTransmitDone(aInstance, false, kThreadError_None);
}
else
#endif
{
otPlatRadioTransmitDone(false, kThreadError_None);
otPlatRadioTransmitDone(aInstance, false, kThreadError_None);
}
}
}
@@ -531,19 +547,19 @@ void posixRadioUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMaxFd)
}
}
void posixRadioProcess(void)
void posixRadioProcess(otInstance *aInstance)
{
const int flags = POLLIN | POLLRDNORM | POLLERR | POLLNVAL | POLLHUP;
struct pollfd pollfd = { sSockFd, flags, 0 };
if (poll(&pollfd, 1, 0) > 0 && (pollfd.revents & flags) != 0)
{
radioReceive();
radioReceive(aInstance);
}
if (sState == kStateTransmit && !sAckWait)
{
radioSendMessage();
radioSendMessage(aInstance);
}
}
@@ -595,7 +611,7 @@ void radioSendAck(void)
radioTransmit(&sAckMessage, &sAckFrame);
}
void radioProcessFrame(void)
void radioProcessFrame(otInstance *aInstance)
{
ThreadError error = kThreadError_None;
otPanId dstpan;
@@ -644,12 +660,12 @@ exit:
if (otPlatDiagModeGet())
{
otPlatDiagRadioReceiveDone(error == kThreadError_None ? &sReceiveFrame : NULL, error);
otPlatDiagRadioReceiveDone(aInstance, error == kThreadError_None ? &sReceiveFrame : NULL, error);
}
else
#endif
{
otPlatRadioReceiveDone(error == kThreadError_None ? &sReceiveFrame : NULL, error);
otPlatRadioReceiveDone(aInstance, error == kThreadError_None ? &sReceiveFrame : NULL, error);
}
}
+2 -1
View File
@@ -57,11 +57,12 @@ typedef int (*otCliConsoleOutputCallback)(const char *aBuf,
/**
* Initialize the CLI CONSOLE module.
*
* @param[in] aInstance The OpenThread instance structure.
* @param[in] aCallback A callback method called to process console output.
* @param[in] aContext A user context pointer.
*
*/
void otCliConsoleInit(otCliConsoleOutputCallback aCallback, void *aContext);
void otCliConsoleInit(otInstance *aInstance, otCliConsoleOutputCallback aCallback, void *aContext);
/**
* This method is called to feed in a console input line.
+3 -1
View File
@@ -42,8 +42,10 @@ extern "C" {
/**
* Initialize the CLI UART module.
*
* @param[in] aInstance The OpenThread instance structure.
*
*/
void otCliUartInit(void);
void otCliUartInit(otInstance *aInstance);
#ifdef __cplusplus
} // extern "C"
+6 -3
View File
@@ -49,19 +49,22 @@ extern "C" {
/**
* This function enables the Thread Commissioner role.
*
* @param[in] aPSKd A pointer to the PSKd.
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aPSKd A pointer to the PSKd.
*
* @retval kThreadError_None Successfully started the Commissioner role.
* @retval kThreadError_InvalidArgs @p aPSKd is invalid.
*
*/
ThreadError otCommissionerStart(const char *aPSKd);
ThreadError otCommissionerStart(otInstance *aInstance, const char *aPSKd);
/**
* This function disables the Thread Commissioner role.
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
*/
ThreadError otCommissionerStop(void);
ThreadError otCommissionerStop(otInstance *aInstance);
/**
* @}
+6 -3
View File
@@ -49,19 +49,22 @@ extern "C" {
/**
* This function enables the Thread Joiner role.
*
* @param[in] aPSKd A pointer to the PSKd.
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aPSKd A pointer to the PSKd.
*
* @retval kThreadError_None Successfully started the Commissioner role.
* @retval kThreadError_InvalidArgs @p aPSKd is invalid.
*
*/
ThreadError otJoinerStart(const char *aPSKd);
ThreadError otJoinerStart(otInstance *aInstance, const char *aPSKd);
/**
* This function disables the Thread Joiner role.
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
*/
ThreadError otJoinerStop(void);
ThreadError otJoinerStop(otInstance *aInstance);
/**
* @}
+4 -2
View File
@@ -35,7 +35,7 @@
#ifndef NCP_H_
#define NCP_H_
#include "../openthread-types.h"
#include <openthread-types.h>
#ifdef __cplusplus
extern "C" {
@@ -44,8 +44,10 @@ extern "C" {
/**
* Initialize the NCP.
*
* @param[in] aInstance The OpenThread instance structure.
*
*/
void otNcpInit(void);
void otNcpInit(otInstance *aInstance);
/**
* @brief Send data to the host via a specific stream.
+3 -1
View File
@@ -35,11 +35,13 @@
#ifndef OPENTHREAD_DIAG_H_
#define OPENTHREAD_DIAG_H_
#include <openthread-types.h>
#ifdef __cplusplus
extern "C" {
#endif
void diagInit();
void diagInit(otInstance *aInstance);
char *diagProcessCmd(int argc, char *argv[]);
+6
View File
@@ -37,12 +37,18 @@
#include <stdint.h>
#include <stdbool.h>
#include <platform/toolchain.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* This type represents the OpenThread instance structure.
*/
typedef struct otInstance otInstance;
/**
* This enumeration represents error codes used throughout OpenThread.
*/
+369 -164
View File
File diff suppressed because it is too large Load Diff
+13 -6
View File
@@ -55,15 +55,18 @@ extern "C" {
/**
* Set the alarm to fire at @p aDt milliseconds after @p aT0.
*
* @param[in] aT0 The reference time.
* @param[in] aDt The time delay in milliseconds from @p aT0.
* @param[in] aInstance The OpenThread instance structure.
* @param[in] aT0 The reference time.
* @param[in] aDt The time delay in milliseconds from @p aT0.
*/
void otPlatAlarmStartAt(uint32_t aT0, uint32_t aDt);
void otPlatAlarmStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt);
/**
* Stop the alarm.
*
* @param[in] aInstance The OpenThread instance structure.
*/
void otPlatAlarmStop(void);
void otPlatAlarmStop(otInstance *aInstance);
/**
* Get the current time.
@@ -74,13 +77,17 @@ uint32_t otPlatAlarmGetNow(void);
/**
* Signal that the alarm has fired.
*
* @param[in] aInstance The OpenThread instance structure.
*/
extern void otPlatAlarmFired(void);
extern void otPlatAlarmFired(otInstance *aInstance);
/**
* Signal diagnostics module that the alarm has fired.
*
* @param[in] aInstance The OpenThread instance structure.
*/
extern void otPlatDiagAlarmFired(void);
extern void otPlatDiagAlarmFired(otInstance *aInstance);
/**
* @}
+6 -2
View File
@@ -44,8 +44,10 @@ extern "C" {
/**
* This function performs a software reset on the platform, if supported.
*
* @param[in] aInstance The OpenThread instance structure.
*
*/
void otPlatReset(void);
void otPlatReset(otInstance *aInstance);
/**
* Enumeration of possible reset reason codes.
@@ -71,8 +73,10 @@ typedef enum
/**
* This function returns the reason for the last platform reset.
*
* @param[in] aInstance The OpenThread instance structure.
*
*/
otPlatResetReason otPlatGetResetReason(void);
otPlatResetReason otPlatGetResetReason(otInstance *aInstance);
#ifdef __cplusplus
} // extern "C"
+3 -2
View File
@@ -39,7 +39,6 @@
extern "C" {
#endif
/**
* This function performs all platform-specific initialization.
*
@@ -49,8 +48,10 @@ void PlatformInit(int argc, char *argv[]);
/**
* This function performs all platform-specific processing.
*
* @param[in] aInstance The OpenThread instance structure.
*
*/
void PlatformProcessDrivers(void);
void PlatformProcessDrivers(otInstance *aInstance);
#ifdef __cplusplus
} // end of extern "C"
+57 -27
View File
@@ -147,29 +147,34 @@ typedef enum PhyState
/**
* Set the PAN ID for address filtering.
*
* @param[in] aPanId The IEEE 802.15.4 PAN ID.
* @param[in] aInstance The OpenThread instance structure.
* @param[in] aPanId The IEEE 802.15.4 PAN ID.
*
* @retval ::kThreadError_None If the PAN ID was set properly.
*/
ThreadError otPlatRadioSetPanId(uint16_t aPanId);
ThreadError otPlatRadioSetPanId(otInstance *aInstance, uint16_t aPanId);
/**
* Set the Extended Address for address filtering.
*
*
* @param[in] aInstance The OpenThread instance structure.
* @param[in] aExtendedAddress A pointer to the IEEE 802.15.4 Extended Address.
*
* @retval ::kThreadError_None If the Extended Address was set properly.
*/
ThreadError otPlatRadioSetExtendedAddress(uint8_t *aExtendedAddress);
ThreadError otPlatRadioSetExtendedAddress(otInstance *aInstance, uint8_t *aExtendedAddress);
/**
* Set the Short Address for address filtering.
*
*
* @param[in] aInstance The OpenThread instance structure.
* @param[in] aShortAddress The IEEE 802.15.4 Short Address.
*
* @retval ::kThreadError_None If the Short Address was set properly.
*/
ThreadError otPlatRadioSetShortAddress(uint16_t aShortAddress);
ThreadError otPlatRadioSetShortAddress(otInstance *aInstance, uint16_t aShortAddress);
/**
* @}
@@ -189,55 +194,66 @@ ThreadError otPlatRadioSetShortAddress(uint16_t aShortAddress);
/**
* Enable the radio.
*
* @param[in] aInstance The OpenThread instance structure.
*
* @retval ::kThreadError_None Successfully transitioned to Sleep.
* @retval ::kThreadError_Busy The radio was already enabled.
*/
ThreadError otPlatRadioEnable(void);
ThreadError otPlatRadioEnable(otInstance *aInstance);
/**
* Disable the radio.
*
* @param[in] aInstance The OpenThread instance structure.
*
* @retval ::kThreadError_None Successfully transitioned to Disabled.
*/
ThreadError otPlatRadioDisable(void);
ThreadError otPlatRadioDisable(otInstance *aInstance);
/**
* Check whether radio is enabled or not.
*
* @param[in] aInstance The OpenThread instance structure.
*
* @retval ::true radio is enabled.
* @retval ::false radio is disabled.
*/
bool otPlatRadioIsEnabled(void);
bool otPlatRadioIsEnabled(otInstance *aInstance);
/**
* Transition the radio from Receive to Sleep.
* Turn off the radio.
*
* @param[in] aInstance The OpenThread instance structure.
*
* @retval ::kThreadError_None Successfully transitioned to Sleep.
* @retval ::kThreadError_Busy The radio was not in the Receive state.
*/
ThreadError otPlatRadioSleep(void);
ThreadError otPlatRadioSleep(otInstance *aInstance);
/**
* Transitioning the radio from Sleep to Receive.
* Turn on the radio.
*
* @param[in] aChannel The channel to use for receiving.
* @param[in] aInstance The OpenThread instance structure.
* @param[in] aChannel The channel to use for receiving.
*
* @retval ::kThreadError_None Successfully transitioned to Receive.
* @retval ::kThreadError_Busy The radio was not in the Sleep state.
*/
ThreadError otPlatRadioReceive(uint8_t aChannel);
ThreadError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel);
/**
* The radio driver calls this method to notify OpenThread of a received packet.
*
* @param[in] aPacket A pointer to the received packet or NULL if the receive operation was aborted.
* @param[in] aError ::kThreadError_None when successfully received a frame, ::kThreadError_Abort when reception
* was aborted and a frame was not received.
*
* @param[in] aInstance The OpenThread instance structure.
* @param[in] aPacket A pointer to the received packet or NULL if the receive operation was aborted.
* @param[in] aError ::kThreadError_None when successfully received a frame, ::kThreadError_Abort when reception
* was aborted and a frame was not received.
*
*/
extern void otPlatRadioReceiveDone(RadioPacket *aPacket, ThreadError aError);
extern void otPlatRadioReceiveDone(otInstance *aInstance, RadioPacket *aPacket, ThreadError aError);
/**
* The radio transitions from Transmit to Receive.
@@ -245,10 +261,12 @@ extern void otPlatRadioReceiveDone(RadioPacket *aPacket, ThreadError aError);
*
* The caller forms the IEEE 802.15.4 frame in this buffer then calls otPlatRadioTransmit() to request transmission.
*
* @param[in] aInstance The OpenThread instance structure.
*
* @returns A pointer to the transmit buffer.
*
*/
RadioPacket *otPlatRadioGetTransmitBuffer(void);
RadioPacket *otPlatRadioGetTransmitBuffer(otInstance *aInstance);
/**
* This method begins the transmit sequence on the radio.
@@ -260,14 +278,17 @@ RadioPacket *otPlatRadioGetTransmitBuffer(void);
* 1. Transitioning the radio to Transmit from Receive.
* 2. Transmits the psdu on the given channel and at the given transmit power.
*
* @param[in] aInstance The OpenThread instance structure.
*
* @retval ::kThreadError_None Successfully transitioned to Transmit.
* @retval ::kThreadError_Busy The radio was not in the Receive state.
*/
ThreadError otPlatRadioTransmit(void);
ThreadError otPlatRadioTransmit(otInstance *aInstance);
/**
* The radio driver calls this method to notify OpenThread that the transmission has completed.
*
* @param[in] aInstance The OpenThread instance structure.
* @param[in] aFramePending TRUE if an ACK frame was received and the Frame Pending bit was set.
* @param[in] aError ::kThreadError_None when the frame was transmitted, ::kThreadError_NoAck when the frame was
* transmitted but no ACK was received, ::kThreadError_ChannelAccessFailure when the transmission
@@ -275,40 +296,48 @@ ThreadError otPlatRadioTransmit(void);
* aborted for other reasons.
*
*/
extern void otPlatRadioTransmitDone(bool aFramePending, ThreadError aError);
extern void otPlatRadioTransmitDone(otInstance *aInstance, bool aFramePending, ThreadError aError);
/**
* Get the most recent RSSI measurement.
*
* @param[in] aInstance The OpenThread instance structure.
*
* @returns The RSSI in dBm when it is valid. 127 when RSSI is invalid.
*/
int8_t otPlatRadioGetRssi(void);
int8_t otPlatRadioGetRssi(otInstance *aInstance);
/**
* Get the radio capabilities.
*
* @param[in] aInstance The OpenThread instance structure.
*
* @returns The radio capability bit vector. The stack enables or disables some functions based on this value.
*/
otRadioCaps otPlatRadioGetCaps(void);
otRadioCaps otPlatRadioGetCaps(otInstance *aInstance);
/**
* Get the status of promiscuous mode.
*
* @param[in] aInstance The OpenThread instance structure.
*
* @retval true Promiscuous mode is enabled.
* @retval false Promiscuous mode is disabled.
*/
bool otPlatRadioGetPromiscuous(void);
bool otPlatRadioGetPromiscuous(otInstance *aInstance);
/**
* Enable or disable promiscuous mode.
*
* @param[in] aEnable A value to enable or disable promiscuous mode.
* @param[in] aInstance The OpenThread instance structure.
* @param[in] aEnable A value to enable or disable promiscuous mode.
*/
void otPlatRadioSetPromiscuous(bool aEnable);
void otPlatRadioSetPromiscuous(otInstance *aInstance, bool aEnable);
/**
* The radio driver calls this method to notify OpenThread diagnostics module that the transmission has completed.
*
* @param[in] aInstance The OpenThread instance structure.
* @param[in] aFramePending TRUE if an ACK frame was received and the Frame Pending bit was set.
* @param[in] aError ::kThreadError_None when the frame was transmitted, ::kThreadError_NoAck when the frame was
* transmitted but no ACK was received, ::kThreadError_ChannelAccessFailure when the transmission
@@ -316,17 +345,18 @@ void otPlatRadioSetPromiscuous(bool aEnable);
* aborted for other reasons.
*
*/
extern void otPlatDiagRadioTransmitDone(bool aFramePending, ThreadError aError);
extern void otPlatDiagRadioTransmitDone(otInstance *aInstance, bool aFramePending, ThreadError aError);
/**
* The radio driver calls this method to notify OpenThread diagnostics module of a received packet.
*
* @param[in] aPacket A pointer to the received packet or NULL if the receive operation was aborted.
* @param[in] aError ::kThreadError_None when successfully received a frame, ::kThreadError_Abort when reception
* was aborted and a frame was not received.
* @param[in] aInstance The OpenThread instance structure.
* @param[in] aPacket A pointer to the received packet or NULL if the receive operation was aborted.
* @param[in] aError ::kThreadError_None when successfully received a frame, ::kThreadError_Abort when reception
* was aborted and a frame was not received.
*
*/
extern void otPlatDiagRadioReceiveDone(RadioPacket *aPacket, ThreadError aError);
extern void otPlatDiagRadioReceiveDone(otInstance *aInstance, RadioPacket *aPacket, ThreadError aError);
/**
* @}
+194 -185
View File
@@ -36,12 +36,14 @@
#include <string.h>
#include <openthread.h>
#include <openthread-config.h>
#include <openthread-diag.h>
#include <commissioning/commissioner.h>
#include <commissioning/joiner.h>
#include "cli.hpp"
#include "cli_dataset.hpp"
#include "cli_uart.hpp"
#include <common/encoding.hpp>
#include <common/new.hpp>
#include <net/ip6.hpp>
@@ -59,84 +61,73 @@ namespace Cli {
const struct Command Interpreter::sCommands[] =
{
{ "help", &ProcessHelp },
{ "blacklist", &ProcessBlacklist },
{ "channel", &ProcessChannel },
{ "child", &ProcessChild },
{ "childmax", &ProcessChildMax },
{ "childtimeout", &ProcessChildTimeout },
{ "help", &Interpreter::ProcessHelp },
{ "blacklist", &Interpreter::ProcessBlacklist },
{ "channel", &Interpreter::ProcessChannel },
{ "child", &Interpreter::ProcessChild },
{ "childmax", &Interpreter::ProcessChildMax },
{ "childtimeout", &Interpreter::ProcessChildTimeout },
#if OPENTHREAD_ENABLE_COMMISSIONER
{ "commissioner", &ProcessCommissioner },
{ "commissioner", &Interpreter::ProcessCommissioner },
#endif
{ "contextreusedelay", &ProcessContextIdReuseDelay },
{ "counter", &ProcessCounters },
{ "dataset", &ProcessDataset },
{ "contextreusedelay", &Interpreter::ProcessContextIdReuseDelay },
{ "counter", &Interpreter::ProcessCounters },
{ "dataset", &Interpreter::ProcessDataset },
#if OPENTHREAD_ENABLE_DIAG
{ "diag", &ProcessDiag },
{ "diag", &Interpreter::ProcessDiag },
#endif
{ "discover", &ProcessDiscover },
{ "eidcache", &ProcessEidCache },
{ "discover", &Interpreter::ProcessDiscover },
{ "eidcache", &Interpreter::ProcessEidCache },
#ifdef OPENTHREAD_EXAMPLES_POSIX
{ "exit", &ProcessExit },
{ "exit", &Interpreter::ProcessExit },
#endif
{ "extaddr", &ProcessExtAddress },
{ "extpanid", &ProcessExtPanId },
{ "ifconfig", &ProcessIfconfig },
{ "ipaddr", &ProcessIpAddr },
{ "extaddr", &Interpreter::ProcessExtAddress },
{ "extpanid", &Interpreter::ProcessExtPanId },
{ "ifconfig", &Interpreter::ProcessIfconfig },
{ "ipaddr", &Interpreter::ProcessIpAddr },
#if OPENTHREAD_ENABLE_JOINER
{ "joiner", &ProcessJoiner },
{ "joiner", &Interpreter::ProcessJoiner },
#endif
{ "keysequence", &ProcessKeySequence },
{ "leaderdata", &ProcessLeaderData },
{ "leaderpartitionid", &ProcessLeaderPartitionId },
{ "leaderweight", &ProcessLeaderWeight },
{ "linkquality", &ProcessLinkQuality },
{ "masterkey", &ProcessMasterKey },
{ "mode", &ProcessMode },
{ "netdataregister", &ProcessNetworkDataRegister },
{ "networkidtimeout", &ProcessNetworkIdTimeout },
{ "networkname", &ProcessNetworkName },
{ "panid", &ProcessPanId },
{ "parent", &ProcessParent },
{ "ping", &ProcessPing },
{ "pollperiod", &ProcessPollPeriod },
{ "promiscuous", &ProcessPromiscuous },
{ "prefix", &ProcessPrefix },
{ "releaserouterid", &ProcessReleaseRouterId },
{ "reset", &ProcessReset },
{ "rloc16", &ProcessRloc16 },
{ "route", &ProcessRoute },
{ "router", &ProcessRouter },
{ "routerrole", &ProcessRouterRole },
{ "routerupgradethreshold", &ProcessRouterUpgradeThreshold },
{ "scan", &ProcessScan },
{ "singleton", &ProcessSingleton },
{ "state", &ProcessState },
{ "thread", &ProcessThread },
{ "version", &ProcessVersion },
{ "whitelist", &ProcessWhitelist },
{ "keysequence", &Interpreter::ProcessKeySequence },
{ "leaderdata", &Interpreter::ProcessLeaderData },
{ "leaderpartitionid", &Interpreter::ProcessLeaderPartitionId },
{ "leaderweight", &Interpreter::ProcessLeaderWeight },
{ "linkquality", &Interpreter::ProcessLinkQuality },
{ "masterkey", &Interpreter::ProcessMasterKey },
{ "mode", &Interpreter::ProcessMode },
{ "netdataregister", &Interpreter::ProcessNetworkDataRegister },
{ "networkidtimeout", &Interpreter::ProcessNetworkIdTimeout },
{ "networkname", &Interpreter::ProcessNetworkName },
{ "panid", &Interpreter::ProcessPanId },
{ "parent", &Interpreter::ProcessParent },
{ "ping", &Interpreter::ProcessPing },
{ "pollperiod", &Interpreter::ProcessPollPeriod },
{ "promiscuous", &Interpreter::ProcessPromiscuous },
{ "prefix", &Interpreter::ProcessPrefix },
{ "releaserouterid", &Interpreter::ProcessReleaseRouterId },
{ "reset", &Interpreter::ProcessReset },
{ "rloc16", &Interpreter::ProcessRloc16 },
{ "route", &Interpreter::ProcessRoute },
{ "router", &Interpreter::ProcessRouter },
{ "routerrole", &Interpreter::ProcessRouterRole },
{ "routerupgradethreshold", &Interpreter::ProcessRouterUpgradeThreshold },
{ "scan", &Interpreter::ProcessScan },
{ "singleton", &Interpreter::ProcessSingleton },
{ "state", &Interpreter::ProcessState },
{ "thread", &Interpreter::ProcessThread },
{ "version", &Interpreter::ProcessVersion },
{ "whitelist", &Interpreter::ProcessWhitelist },
};
static otDEFINE_ALIGNED_VAR(sPingTimerBuf, sizeof(Timer), uint64_t);
Timer *Interpreter::sPingTimer;
Ip6::MessageInfo Interpreter::sMessageInfo;
Server *Interpreter::sServer;
uint8_t Interpreter::sEchoRequest[1500];
uint16_t Interpreter::sLength;
uint16_t Interpreter::sCount;
uint32_t Interpreter::sInterval;
static otNetifAddress sAutoAddresses[8];
void Interpreter::Init(void)
Interpreter::Interpreter(otInstance *aInstance):
sLength(8),
sCount(1),
sInterval(1000),
sPingTimer(sIp6->mTimerScheduler, &Interpreter::s_HandlePingTimer, this),
mInstance(aInstance)
{
sIp6->mIcmp.SetEchoReplyHandler(&HandleEchoResponse, NULL);
sPingTimer = new(&sPingTimerBuf) Timer(sIp6->mTimerScheduler, &HandlePingTimer, NULL);
sLength = 8;
sCount = 1;
sInterval = 1000;
otSetStateChangedCallback(&HandleNetifStateChanged, NULL);
sIp6->mIcmp.SetEchoReplyHandler(&s_HandleEchoResponse, this);
otSetStateChangedCallback(mInstance, &Interpreter::s_HandleNetifStateChanged, this);
}
int Interpreter::Hex2Bin(const char *aHex, uint8_t *aBin, uint16_t aBinLength)
@@ -243,7 +234,7 @@ void Interpreter::ProcessBlacklist(int argc, char *argv[])
if (argcur >= argc)
{
if (otIsMacBlacklistEnabled())
if (otIsMacBlacklistEnabled(mInstance))
{
sServer->OutputFormat("Enabled\r\n");
}
@@ -254,7 +245,7 @@ void Interpreter::ProcessBlacklist(int argc, char *argv[])
for (uint8_t i = 0; ; i++)
{
if (otGetMacBlacklistEntry(i, &entry) != kThreadError_None)
if (otGetMacBlacklistEntry(mInstance, i, &entry) != kThreadError_None)
{
break;
}
@@ -274,26 +265,26 @@ void Interpreter::ProcessBlacklist(int argc, char *argv[])
VerifyOrExit(++argcur < argc, error = kThreadError_Parse);
VerifyOrExit(Hex2Bin(argv[argcur], extAddr, sizeof(extAddr)) == sizeof(extAddr), error = kThreadError_Parse);
otAddMacBlacklist(extAddr);
VerifyOrExit(otAddMacBlacklist(extAddr) == kThreadError_None, error = kThreadError_Parse);
otAddMacBlacklist(mInstance, extAddr);
VerifyOrExit(otAddMacBlacklist(mInstance, extAddr) == kThreadError_None, error = kThreadError_Parse);
}
else if (strcmp(argv[argcur], "clear") == 0)
{
otClearMacBlacklist();
otClearMacBlacklist(mInstance);
}
else if (strcmp(argv[argcur], "disable") == 0)
{
otDisableMacBlacklist();
otDisableMacBlacklist(mInstance);
}
else if (strcmp(argv[argcur], "enable") == 0)
{
otEnableMacBlacklist();
otEnableMacBlacklist(mInstance);
}
else if (strcmp(argv[argcur], "remove") == 0)
{
VerifyOrExit(++argcur < argc, error = kThreadError_Parse);
VerifyOrExit(Hex2Bin(argv[argcur], extAddr, sizeof(extAddr)) == sizeof(extAddr), error = kThreadError_Parse);
otRemoveMacBlacklist(extAddr);
otRemoveMacBlacklist(mInstance, extAddr);
}
exit:
@@ -307,12 +298,12 @@ void Interpreter::ProcessChannel(int argc, char *argv[])
if (argc == 0)
{
sServer->OutputFormat("%d\r\n", otGetChannel());
sServer->OutputFormat("%d\r\n", otGetChannel(mInstance));
}
else
{
SuccessOrExit(error = ParseLong(argv[0], value));
otSetChannel(static_cast<uint8_t>(value));
otSetChannel(mInstance, static_cast<uint8_t>(value));
}
exit:
@@ -331,7 +322,7 @@ void Interpreter::ProcessChild(int argc, char *argv[])
{
for (uint8_t i = 0; ; i++)
{
if (otGetChildInfoByIndex(i, &childInfo) != kThreadError_None)
if (otGetChildInfoByIndex(mInstance, i, &childInfo) != kThreadError_None)
{
sServer->OutputFormat("\r\n");
ExitNow();
@@ -345,7 +336,7 @@ void Interpreter::ProcessChild(int argc, char *argv[])
}
SuccessOrExit(error = ParseLong(argv[0], value));
SuccessOrExit(error = otGetChildInfoById(static_cast<uint16_t>(value), &childInfo));
SuccessOrExit(error = otGetChildInfoById(mInstance, static_cast<uint16_t>(value), &childInfo));
sServer->OutputFormat("Child ID: %d\r\n", childInfo.mChildId);
sServer->OutputFormat("Rloc: %04x\r\n", childInfo.mRloc16);
@@ -398,12 +389,12 @@ void Interpreter::ProcessChildMax(int argc, char *argv[])
if (argc == 0)
{
sServer->OutputFormat("%d\r\n", otGetMaxAllowedChildren());
sServer->OutputFormat("%d\r\n", otGetMaxAllowedChildren(mInstance));
}
else
{
SuccessOrExit(error = ParseLong(argv[0], value));
SuccessOrExit(error = otSetMaxAllowedChildren(static_cast<uint8_t>(value)));
SuccessOrExit(error = otSetMaxAllowedChildren(mInstance, static_cast<uint8_t>(value)));
}
exit:
@@ -417,12 +408,12 @@ void Interpreter::ProcessChildTimeout(int argc, char *argv[])
if (argc == 0)
{
sServer->OutputFormat("%d\r\n", otGetChildTimeout());
sServer->OutputFormat("%d\r\n", otGetChildTimeout(mInstance));
}
else
{
SuccessOrExit(error = ParseLong(argv[0], value));
otSetChildTimeout(static_cast<uint32_t>(value));
otSetChildTimeout(mInstance, static_cast<uint32_t>(value));
}
exit:
@@ -436,12 +427,12 @@ void Interpreter::ProcessContextIdReuseDelay(int argc, char *argv[])
if (argc == 0)
{
sServer->OutputFormat("%d\r\n", otGetContextIdReuseDelay());
sServer->OutputFormat("%d\r\n", otGetContextIdReuseDelay(mInstance));
}
else
{
SuccessOrExit(ParseLong(argv[0], value));
otSetContextIdReuseDelay(static_cast<uint32_t>(value));
otSetContextIdReuseDelay(mInstance, static_cast<uint32_t>(value));
}
exit:
@@ -459,7 +450,7 @@ void Interpreter::ProcessCounters(int argc, char *argv[])
{
if (strcmp(argv[0], "mac") == 0)
{
const otMacCounters *counters = otGetMacCounters();
const otMacCounters *counters = otGetMacCounters(mInstance);
sServer->OutputFormat("TxTotal: %d\r\n", counters->mTxTotal);
sServer->OutputFormat(" TxAckRequested: %d\r\n", counters->mTxAckRequested);
sServer->OutputFormat(" TxAcked: %d\r\n", counters->mTxAcked);
@@ -492,7 +483,7 @@ void Interpreter::ProcessCounters(int argc, char *argv[])
void Interpreter::ProcessDataset(int argc, char *argv[])
{
ThreadError error;
error = Dataset::Process(argc, argv, *sServer);
error = Dataset::Process(mInstance, argc, argv, *sServer);
AppendResult(error);
}
@@ -508,7 +499,8 @@ void Interpreter::ProcessDiscover(int argc, char *argv[])
scanChannels = 1 << value;
}
SuccessOrExit(error = otDiscover(scanChannels, 0, OT_PANID_BROADCAST, &HandleActiveScanResult, NULL));
SuccessOrExit(error = otDiscover(mInstance, scanChannels, 0, OT_PANID_BROADCAST,
&Interpreter::s_HandleActiveScanResult, this));
sServer->OutputFormat("| J | Network Name | Extended PAN | PAN | MAC Address | Ch | dBm | LQI |\r\n");
sServer->OutputFormat("+---+------------------+------------------+------+------------------+----+-----+-----+\r\n");
@@ -524,7 +516,7 @@ void Interpreter::ProcessEidCache(int argc, char *argv[])
for (uint8_t i = 0; ; i++)
{
SuccessOrExit(otGetEidCacheEntry(i, &entry));
SuccessOrExit(otGetEidCacheEntry(mInstance, i, &entry));
if (entry.mValid == false)
{
@@ -555,7 +547,7 @@ void Interpreter::ProcessExtAddress(int argc, char *argv[])
if (argc == 0)
{
OutputBytes(otGetExtendedAddress(), OT_EXT_ADDRESS_SIZE);
OutputBytes(otGetExtendedAddress(mInstance), OT_EXT_ADDRESS_SIZE);
sServer->OutputFormat("\r\n");
}
else
@@ -564,7 +556,7 @@ void Interpreter::ProcessExtAddress(int argc, char *argv[])
VerifyOrExit(Hex2Bin(argv[0], extAddress.m8, sizeof(otExtAddress)) >= 0, error = kThreadError_Parse);
otSetExtendedAddress(&extAddress);
otSetExtendedAddress(mInstance, &extAddress);
}
exit:
@@ -586,7 +578,7 @@ void Interpreter::ProcessExtPanId(int argc, char *argv[])
if (argc == 0)
{
OutputBytes(otGetExtendedPanId(), OT_EXT_PAN_ID_SIZE);
OutputBytes(otGetExtendedPanId(mInstance), OT_EXT_PAN_ID_SIZE);
sServer->OutputFormat("\r\n");
}
else
@@ -595,7 +587,7 @@ void Interpreter::ProcessExtPanId(int argc, char *argv[])
VerifyOrExit(Hex2Bin(argv[0], extPanId, sizeof(extPanId)) >= 0, error = kThreadError_Parse);
otSetExtendedPanId(extPanId);
otSetExtendedPanId(mInstance, extPanId);
}
exit:
@@ -608,7 +600,7 @@ void Interpreter::ProcessIfconfig(int argc, char *argv[])
if (argc == 0)
{
if (otIsInterfaceUp())
if (otIsInterfaceUp(mInstance))
{
sServer->OutputFormat("up\r\n");
}
@@ -619,11 +611,11 @@ void Interpreter::ProcessIfconfig(int argc, char *argv[])
}
else if (strcmp(argv[0], "up") == 0)
{
SuccessOrExit(error = otInterfaceUp());
SuccessOrExit(error = otInterfaceUp(mInstance));
}
else if (strcmp(argv[0], "down") == 0)
{
SuccessOrExit(error = otInterfaceDown());
SuccessOrExit(error = otInterfaceDown(mInstance));
}
exit:
@@ -641,7 +633,7 @@ ThreadError Interpreter::ProcessIpAddrAdd(int argc, char *argv[])
aAddress.mPrefixLength = 64;
aAddress.mPreferredLifetime = 0xffffffff;
aAddress.mValidLifetime = 0xffffffff;
error = otAddUnicastAddress(&aAddress);
error = otAddUnicastAddress(mInstance, &aAddress);
exit:
return error;
@@ -655,7 +647,7 @@ ThreadError Interpreter::ProcessIpAddrDel(int argc, char *argv[])
VerifyOrExit(argc > 0, error = kThreadError_Parse);
SuccessOrExit(error = otIp6AddressFromString(argv[0], &address));
error = otRemoveUnicastAddress(&address);
error = otRemoveUnicastAddress(mInstance, &address);
exit:
return error;
@@ -667,7 +659,7 @@ void Interpreter::ProcessIpAddr(int argc, char *argv[])
if (argc == 0)
{
for (const otNetifAddress *addr = otGetUnicastAddresses(); addr; addr = addr->mNext)
for (const otNetifAddress *addr = otGetUnicastAddresses(mInstance); addr; addr = addr->mNext)
{
sServer->OutputFormat("%x:%x:%x:%x:%x:%x:%x:%x\r\n",
HostSwap16(addr->mAddress.mFields.m16[0]),
@@ -703,12 +695,12 @@ void Interpreter::ProcessKeySequence(int argc, char *argv[])
if (argc == 0)
{
sServer->OutputFormat("%d\r\n", otGetKeySequenceCounter());
sServer->OutputFormat("%d\r\n", otGetKeySequenceCounter(mInstance));
}
else
{
SuccessOrExit(error = ParseLong(argv[0], value));
otSetKeySequenceCounter(static_cast<uint32_t>(value));
otSetKeySequenceCounter(mInstance, static_cast<uint32_t>(value));
}
exit:
@@ -720,7 +712,7 @@ void Interpreter::ProcessLeaderData(int argc, char *argv[])
ThreadError error;
otLeaderData leaderData;
SuccessOrExit(error = otGetLeaderData(&leaderData));
SuccessOrExit(error = otGetLeaderData(mInstance, &leaderData));
sServer->OutputFormat("Partition ID: %u\r\n", leaderData.mPartitionId);
sServer->OutputFormat("Weighting: %d\r\n", leaderData.mWeighting);
@@ -741,12 +733,12 @@ void Interpreter::ProcessLeaderPartitionId(int argc, char *argv[])
if (argc == 0)
{
sServer->OutputFormat("%u\r\n", otGetLocalLeaderPartitionId());
sServer->OutputFormat("%u\r\n", otGetLocalLeaderPartitionId(mInstance));
}
else
{
SuccessOrExit(error = ParseUnsignedLong(argv[0], value));
otSetLocalLeaderPartitionId(static_cast<uint32_t>(value));
otSetLocalLeaderPartitionId(mInstance, static_cast<uint32_t>(value));
}
exit:
@@ -760,12 +752,12 @@ void Interpreter::ProcessLeaderWeight(int argc, char *argv[])
if (argc == 0)
{
sServer->OutputFormat("%d\r\n", otGetLocalLeaderWeight());
sServer->OutputFormat("%d\r\n", otGetLocalLeaderWeight(mInstance));
}
else
{
SuccessOrExit(error = ParseLong(argv[0], value));
otSetLocalLeaderWeight(static_cast<uint8_t>(value));
otSetLocalLeaderWeight(mInstance, static_cast<uint8_t>(value));
}
exit:
@@ -783,14 +775,14 @@ void Interpreter::ProcessLinkQuality(int argc, char *argv[])
if (argc == 1)
{
VerifyOrExit(otGetAssignLinkQuality(extAddress, &linkQuality) == kThreadError_None,
VerifyOrExit(otGetAssignLinkQuality(mInstance, extAddress, &linkQuality) == kThreadError_None,
error = kThreadError_InvalidArgs);
sServer->OutputFormat("%d\r\n", linkQuality);
}
else
{
SuccessOrExit(error = ParseLong(argv[1], value));
otSetAssignLinkQuality(extAddress, static_cast<uint8_t>(value));
otSetAssignLinkQuality(mInstance, extAddress, static_cast<uint8_t>(value));
}
exit:
@@ -804,7 +796,7 @@ void Interpreter::ProcessMasterKey(int argc, char *argv[])
if (argc == 0)
{
uint8_t keyLength;
const uint8_t *key = otGetMasterKey(&keyLength);
const uint8_t *key = otGetMasterKey(mInstance, &keyLength);
for (int i = 0; i < keyLength; i++)
{
@@ -819,7 +811,7 @@ void Interpreter::ProcessMasterKey(int argc, char *argv[])
uint8_t key[OT_MASTER_KEY_SIZE];
VerifyOrExit((keyLength = Hex2Bin(argv[0], key, sizeof(key))) == OT_MASTER_KEY_SIZE, error = kThreadError_Parse);
SuccessOrExit(error = otSetMasterKey(key, static_cast<uint8_t>(keyLength)));
SuccessOrExit(error = otSetMasterKey(mInstance, key, static_cast<uint8_t>(keyLength)));
}
exit:
@@ -835,7 +827,7 @@ void Interpreter::ProcessMode(int argc, char *argv[])
if (argc == 0)
{
linkMode = otGetLinkMode();
linkMode = otGetLinkMode(mInstance);
if (linkMode.mRxOnWhenIdle)
{
@@ -886,7 +878,7 @@ void Interpreter::ProcessMode(int argc, char *argv[])
}
}
SuccessOrExit(error = otSetLinkMode(linkMode));
SuccessOrExit(error = otSetLinkMode(mInstance, linkMode));
}
exit:
@@ -896,7 +888,7 @@ exit:
void Interpreter::ProcessNetworkDataRegister(int argc, char *argv[])
{
ThreadError error = kThreadError_None;
SuccessOrExit(error = otSendServerData());
SuccessOrExit(error = otSendServerData(mInstance));
exit:
(void)argc;
@@ -911,12 +903,12 @@ void Interpreter::ProcessNetworkIdTimeout(int argc, char *argv[])
if (argc == 0)
{
sServer->OutputFormat("%d\r\n", otGetNetworkIdTimeout());
sServer->OutputFormat("%d\r\n", otGetNetworkIdTimeout(mInstance));
}
else
{
SuccessOrExit(error = ParseLong(argv[0], value));
otSetNetworkIdTimeout(static_cast<uint8_t>(value));
otSetNetworkIdTimeout(mInstance, static_cast<uint8_t>(value));
}
exit:
@@ -929,11 +921,11 @@ void Interpreter::ProcessNetworkName(int argc, char *argv[])
if (argc == 0)
{
sServer->OutputFormat("%.*s\r\n", OT_NETWORK_NAME_MAX_SIZE, otGetNetworkName());
sServer->OutputFormat("%.*s\r\n", OT_NETWORK_NAME_MAX_SIZE, otGetNetworkName(mInstance));
}
else
{
SuccessOrExit(error = otSetNetworkName(argv[0]));
SuccessOrExit(error = otSetNetworkName(mInstance, argv[0]));
}
exit:
@@ -947,12 +939,12 @@ void Interpreter::ProcessPanId(int argc, char *argv[])
if (argc == 0)
{
sServer->OutputFormat("%d\r\n", otGetPanId());
sServer->OutputFormat("%d\r\n", otGetPanId(mInstance));
}
else
{
SuccessOrExit(error = ParseLong(argv[0], value));
otSetPanId(static_cast<otPanId>(value));
otSetPanId(mInstance, static_cast<otPanId>(value));
}
exit:
@@ -964,7 +956,7 @@ void Interpreter::ProcessParent(int argc, char *argv[])
ThreadError error = kThreadError_None;
otRouterInfo parentInfo;
SuccessOrExit(error = otGetParentInfo(&parentInfo));
SuccessOrExit(error = otGetParentInfo(mInstance, &parentInfo));
sServer->OutputFormat("Ext Addr: ");
for (size_t i = 0; i < sizeof(parentInfo.mExtAddress); i++)
@@ -982,7 +974,12 @@ exit:
AppendResult(error);
}
void Interpreter::HandleEchoResponse(void *aContext, Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
void Interpreter::s_HandleEchoResponse(void *aContext, Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
static_cast<Interpreter *>(aContext)->HandleEchoResponse(aMessage, aMessageInfo);
}
void Interpreter::HandleEchoResponse(Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
Ip6::IcmpHeader icmp6Header;
uint32_t timestamp = 0;
@@ -1008,8 +1005,6 @@ void Interpreter::HandleEchoResponse(void *aContext, Message &aMessage, const Ip
}
sServer->OutputFormat("\r\n");
(void)aContext;
}
void Interpreter::ProcessPing(int argc, char *argv[])
@@ -1019,7 +1014,7 @@ void Interpreter::ProcessPing(int argc, char *argv[])
long value;
VerifyOrExit(argc > 0, error = kThreadError_Parse);
VerifyOrExit(!sPingTimer->IsRunning(), error = kThreadError_Busy);
VerifyOrExit(!sPingTimer.IsRunning(), error = kThreadError_Busy);
memset(&sMessageInfo, 0, sizeof(sMessageInfo));
SuccessOrExit(error = sMessageInfo.GetPeerAddr().FromString(argv[0]));
@@ -1055,7 +1050,7 @@ void Interpreter::ProcessPing(int argc, char *argv[])
index++;
}
HandlePingTimer(NULL);
HandlePingTimer();
return;
@@ -1063,7 +1058,12 @@ exit:
AppendResult(error);
}
void Interpreter::HandlePingTimer(void *aContext)
void Interpreter::s_HandlePingTimer(void *aContext)
{
static_cast<Interpreter *>(aContext)->HandlePingTimer();
}
void Interpreter::HandlePingTimer()
{
ThreadError error = kThreadError_None;
uint32_t timestamp = HostSwap32(Timer::GetNow());
@@ -1085,10 +1085,8 @@ exit:
if (sCount)
{
sPingTimer->Start(sInterval);
sPingTimer.Start(sInterval);
}
(void)aContext;
}
void Interpreter::ProcessPollPeriod(int argc, char *argv[])
@@ -1098,12 +1096,12 @@ void Interpreter::ProcessPollPeriod(int argc, char *argv[])
if (argc == 0)
{
sServer->OutputFormat("%d\r\n", (otGetPollPeriod() / 1000)); // ms->s
sServer->OutputFormat("%d\r\n", (otGetPollPeriod(mInstance) / 1000)); // ms->s
}
else
{
SuccessOrExit(error = ParseLong(argv[0], value));
otSetPollPeriod(static_cast<uint32_t>(value * 1000)); // s->ms
otSetPollPeriod(mInstance, static_cast<uint32_t>(value * 1000)); // s->ms
}
exit:
@@ -1116,7 +1114,7 @@ void Interpreter::ProcessPromiscuous(int argc, char *argv[])
if (argc == 0)
{
if (otIsLinkPromiscuous() && otPlatRadioGetPromiscuous())
if (otIsLinkPromiscuous(mInstance) && otPlatRadioGetPromiscuous(mInstance))
{
sServer->OutputFormat("Enabled\r\n");
}
@@ -1129,13 +1127,13 @@ void Interpreter::ProcessPromiscuous(int argc, char *argv[])
{
if (strcmp(argv[0], "enable") == 0)
{
otSetLinkPcapCallback(&HandleLinkPcapReceive, NULL);
SuccessOrExit(error = otSetLinkPromiscuous(true));
otSetLinkPcapCallback(mInstance, &s_HandleLinkPcapReceive, this);
SuccessOrExit(error = otSetLinkPromiscuous(mInstance, true));
}
else if (strcmp(argv[0], "disable") == 0)
{
otSetLinkPcapCallback(NULL, NULL);
SuccessOrExit(error = otSetLinkPromiscuous(false));
otSetLinkPcapCallback(mInstance, NULL, NULL);
SuccessOrExit(error = otSetLinkPromiscuous(mInstance, false));
}
}
@@ -1143,7 +1141,12 @@ exit:
AppendResult(error);
}
void Interpreter::HandleLinkPcapReceive(const RadioPacket *aFrame, void *aContext)
void Interpreter::s_HandleLinkPcapReceive(const RadioPacket *aFrame, void *aContext)
{
static_cast<Interpreter *>(aContext)->HandleLinkPcapReceive(aFrame);
}
void Interpreter::HandleLinkPcapReceive(const RadioPacket *aFrame)
{
sServer->OutputFormat("\r\n");
@@ -1207,8 +1210,6 @@ void Interpreter::HandleLinkPcapReceive(const RadioPacket *aFrame, void *aContex
}
sServer->OutputFormat("\r\n");
(void) aContext;
}
ThreadError Interpreter::ProcessPrefixAdd(int argc, char *argv[])
@@ -1295,7 +1296,7 @@ ThreadError Interpreter::ProcessPrefixAdd(int argc, char *argv[])
}
}
error = otAddBorderRouter(&config);
error = otAddBorderRouter(mInstance, &config);
exit:
return error;
@@ -1328,7 +1329,7 @@ ThreadError Interpreter::ProcessPrefixRemove(int argc, char *argv[])
ExitNow(error = kThreadError_Parse);
}
error = otRemoveBorderRouter(&prefix);
error = otRemoveBorderRouter(mInstance, &prefix);
exit:
(void)argc;
@@ -1340,7 +1341,7 @@ ThreadError Interpreter::ProcessPrefixList(void)
otNetworkDataIterator iterator = OT_NETWORK_DATA_ITERATOR_INIT;
otBorderRouterConfig config;
while (otGetNextOnMeshPrefix(true, &iterator, &config) == kThreadError_None)
while (otGetNextOnMeshPrefix(mInstance, true, &iterator, &config) == kThreadError_None)
{
sServer->OutputFormat("%x:%x:%x:%x::/%d ",
HostSwap16(config.mPrefix.mPrefix.mFields.m16[0]),
@@ -1436,7 +1437,7 @@ void Interpreter::ProcessReleaseRouterId(int argc, char *argv[])
VerifyOrExit(argc > 0, error = kThreadError_Parse);
SuccessOrExit(error = ParseLong(argv[0], value));
SuccessOrExit(error = otReleaseRouterId(static_cast<uint8_t>(value)));
SuccessOrExit(error = otReleaseRouterId(mInstance, static_cast<uint8_t>(value)));
exit:
AppendResult(error);
@@ -1444,14 +1445,14 @@ exit:
void Interpreter::ProcessReset(int argc, char *argv[])
{
otPlatformReset();
otPlatformReset(mInstance);
(void)argc;
(void)argv;
}
void Interpreter::ProcessRloc16(int argc, char *argv[])
{
sServer->OutputFormat("%04x\r\n", otGetRloc16());
sServer->OutputFormat("%04x\r\n", otGetRloc16(mInstance));
sServer->OutputFormat("Done\r\n");
(void)argc;
(void)argv;
@@ -1512,7 +1513,7 @@ ThreadError Interpreter::ProcessRouteAdd(int argc, char *argv[])
}
}
error = otAddExternalRoute(&config);
error = otAddExternalRoute(mInstance, &config);
exit:
return error;
@@ -1546,7 +1547,7 @@ ThreadError Interpreter::ProcessRouteRemove(int argc, char *argv[])
ExitNow(error = kThreadError_Parse);
}
error = otRemoveExternalRoute(&prefix);
error = otRemoveExternalRoute(mInstance, &prefix);
exit:
return error;
@@ -1587,7 +1588,7 @@ void Interpreter::ProcessRouter(int argc, char *argv[])
{
for (uint8_t i = 0; ; i++)
{
if (otGetRouterInfo(i, &routerInfo) != kThreadError_None)
if (otGetRouterInfo(mInstance, i, &routerInfo) != kThreadError_None)
{
sServer->OutputFormat("\r\n");
ExitNow();
@@ -1601,7 +1602,7 @@ void Interpreter::ProcessRouter(int argc, char *argv[])
}
SuccessOrExit(error = ParseLong(argv[0], value));
SuccessOrExit(error = otGetRouterInfo(static_cast<uint16_t>(value), &routerInfo));
SuccessOrExit(error = otGetRouterInfo(mInstance, static_cast<uint16_t>(value), &routerInfo));
sServer->OutputFormat("Alloc: %d\r\n", routerInfo.mAllocated);
@@ -1639,7 +1640,7 @@ void Interpreter::ProcessRouterRole(int argc, char *argv[])
if (argc == 0)
{
if (otIsRouterRoleEnabled())
if (otIsRouterRoleEnabled(mInstance))
{
sServer->OutputFormat("Enabled\r\n");
}
@@ -1650,11 +1651,11 @@ void Interpreter::ProcessRouterRole(int argc, char *argv[])
}
else if (strcmp(argv[0], "enable") == 0)
{
otSetRouterRoleEnabled(true);
otSetRouterRoleEnabled(mInstance, true);
}
else if (strcmp(argv[0], "disable") == 0)
{
otSetRouterRoleEnabled(false);
otSetRouterRoleEnabled(mInstance, false);
}
else
{
@@ -1672,12 +1673,12 @@ void Interpreter::ProcessRouterUpgradeThreshold(int argc, char *argv[])
if (argc == 0)
{
sServer->OutputFormat("%d\r\n", otGetRouterUpgradeThreshold());
sServer->OutputFormat("%d\r\n", otGetRouterUpgradeThreshold(mInstance));
}
else
{
SuccessOrExit(error = ParseLong(argv[0], value));
otSetRouterUpgradeThreshold(static_cast<uint8_t>(value));
otSetRouterUpgradeThreshold(mInstance, static_cast<uint8_t>(value));
}
exit:
@@ -1696,7 +1697,7 @@ void Interpreter::ProcessScan(int argc, char *argv[])
scanChannels = 1 << value;
}
SuccessOrExit(error = otActiveScan(scanChannels, 0, &HandleActiveScanResult, NULL));
SuccessOrExit(error = otActiveScan(mInstance, scanChannels, 0, &Interpreter::s_HandleActiveScanResult, this));
sServer->OutputFormat("| J | Network Name | Extended PAN | PAN | MAC Address | Ch | dBm | LQI |\r\n");
sServer->OutputFormat("+---+------------------+------------------+------+------------------+----+-----+-----+\r\n");
@@ -1706,7 +1707,12 @@ exit:
AppendResult(error);
}
void Interpreter::HandleActiveScanResult(otActiveScanResult *aResult, void *aContext)
void Interpreter::s_HandleActiveScanResult(otActiveScanResult *aResult, void *aContext)
{
static_cast<Interpreter *>(aContext)->HandleActiveScanResult(aResult);
}
void Interpreter::HandleActiveScanResult(otActiveScanResult *aResult)
{
if (aResult == NULL)
{
@@ -1729,7 +1735,6 @@ void Interpreter::HandleActiveScanResult(otActiveScanResult *aResult, void *aCon
sServer->OutputFormat("| %3d |\r\n", aResult->mLqi);
exit:
(void)aContext;
return;
}
@@ -1737,7 +1742,7 @@ void Interpreter::ProcessSingleton(int argc, char *argv[])
{
ThreadError error = kThreadError_None;
if (otIsSingleton())
if (otIsSingleton(mInstance))
{
sServer->OutputFormat("true\r\n");
}
@@ -1758,7 +1763,7 @@ void Interpreter::ProcessState(int argc, char *argv[])
if (argc == 0)
{
switch (otGetDeviceRole())
switch (otGetDeviceRole(mInstance))
{
case kDeviceRoleDisabled:
sServer->OutputFormat("disabled\r\n");
@@ -1785,19 +1790,19 @@ void Interpreter::ProcessState(int argc, char *argv[])
{
if (strcmp(argv[0], "detached") == 0)
{
SuccessOrExit(error = otBecomeDetached());
SuccessOrExit(error = otBecomeDetached(mInstance));
}
else if (strcmp(argv[0], "child") == 0)
{
SuccessOrExit(error = otBecomeChild(kMleAttachSamePartition));
SuccessOrExit(error = otBecomeChild(mInstance, kMleAttachSamePartition));
}
else if (strcmp(argv[0], "router") == 0)
{
SuccessOrExit(error = otBecomeRouter());
SuccessOrExit(error = otBecomeRouter(mInstance));
}
else if (strcmp(argv[0], "leader") == 0)
{
SuccessOrExit(error = otBecomeLeader());
SuccessOrExit(error = otBecomeLeader(mInstance));
}
else
{
@@ -1817,11 +1822,11 @@ void Interpreter::ProcessThread(int argc, char *argv[])
if (strcmp(argv[0], "start") == 0)
{
SuccessOrExit(error = otThreadStart());
SuccessOrExit(error = otThreadStart(mInstance));
}
else if (strcmp(argv[0], "stop") == 0)
{
SuccessOrExit(error = otThreadStop());
SuccessOrExit(error = otThreadStop(mInstance));
}
exit:
@@ -1849,11 +1854,11 @@ void Interpreter::ProcessCommissioner(int argc, char *argv[])
if (strcmp(argv[0], "start") == 0)
{
VerifyOrExit(argc > 1, error = kThreadError_Parse);
otCommissionerStart(argv[1]);
otCommissionerStart(mInstance, argv[1]);
}
else if (strcmp(argv[0], "stop") == 0)
{
otCommissionerStop();
otCommissionerStop(mInstance);
}
exit:
@@ -1873,11 +1878,11 @@ void Interpreter::ProcessJoiner(int argc, char *argv[])
if (strcmp(argv[0], "start") == 0)
{
VerifyOrExit(argc > 1, error = kThreadError_Parse);
otJoinerStart(argv[1]);
otJoinerStart(mInstance, argv[1]);
}
else if (strcmp(argv[0], "stop") == 0)
{
otJoinerStop();
otJoinerStop(mInstance);
}
exit:
@@ -1896,7 +1901,7 @@ void Interpreter::ProcessWhitelist(int argc, char *argv[])
if (argcur >= argc)
{
if (otIsMacWhitelistEnabled())
if (otIsMacWhitelistEnabled(mInstance))
{
sServer->OutputFormat("Enabled\r\n");
}
@@ -1907,7 +1912,7 @@ void Interpreter::ProcessWhitelist(int argc, char *argv[])
for (uint8_t i = 0; ; i++)
{
if (otGetMacWhitelistEntry(i, &entry) != kThreadError_None)
if (otGetMacWhitelistEntry(mInstance, i, &entry) != kThreadError_None)
{
break;
}
@@ -1935,31 +1940,31 @@ void Interpreter::ProcessWhitelist(int argc, char *argv[])
if (++argcur < argc)
{
rssi = static_cast<int8_t>(strtol(argv[argcur], NULL, 0));
VerifyOrExit(otAddMacWhitelistRssi(extAddr, rssi) == kThreadError_None, error = kThreadError_Parse);
VerifyOrExit(otAddMacWhitelistRssi(mInstance, extAddr, rssi) == kThreadError_None, error = kThreadError_Parse);
}
else
{
otAddMacWhitelist(extAddr);
VerifyOrExit(otAddMacWhitelist(extAddr) == kThreadError_None, error = kThreadError_Parse);
otAddMacWhitelist(mInstance, extAddr);
VerifyOrExit(otAddMacWhitelist(mInstance, extAddr) == kThreadError_None, error = kThreadError_Parse);
}
}
else if (strcmp(argv[argcur], "clear") == 0)
{
otClearMacWhitelist();
otClearMacWhitelist(mInstance);
}
else if (strcmp(argv[argcur], "disable") == 0)
{
otDisableMacWhitelist();
otDisableMacWhitelist(mInstance);
}
else if (strcmp(argv[argcur], "enable") == 0)
{
otEnableMacWhitelist();
otEnableMacWhitelist(mInstance);
}
else if (strcmp(argv[argcur], "remove") == 0)
{
VerifyOrExit(++argcur < argc, error = kThreadError_Parse);
VerifyOrExit(Hex2Bin(argv[argcur], extAddr, sizeof(extAddr)) == sizeof(extAddr), error = kThreadError_Parse);
otRemoveMacWhitelist(extAddr);
otRemoveMacWhitelist(mInstance, extAddr);
}
exit:
@@ -2013,7 +2018,7 @@ void Interpreter::ProcessLine(char *aBuf, uint16_t aBufLength, Server &aServer)
{
if (strcmp(cmd, sCommands[i].mName) == 0)
{
sCommands[i].mCommand(argc, argv);
(this->*sCommands[i].mCommand)(argc, argv);
break;
}
}
@@ -2022,7 +2027,12 @@ exit:
return;
}
void Interpreter::HandleNetifStateChanged(uint32_t aFlags, void *aContext)
void Interpreter::s_HandleNetifStateChanged(uint32_t aFlags, void *aContext)
{
static_cast<Interpreter *>(aContext)->HandleNetifStateChanged(aFlags);
}
void Interpreter::HandleNetifStateChanged(uint32_t aFlags)
{
otNetworkDataIterator iterator;
otBorderRouterConfig config;
@@ -2042,7 +2052,7 @@ void Interpreter::HandleNetifStateChanged(uint32_t aFlags, void *aContext)
iterator = OT_NETWORK_DATA_ITERATOR_INIT;
while (otGetNextOnMeshPrefix(false, &iterator, &config) == kThreadError_None)
while (otGetNextOnMeshPrefix(mInstance, false, &iterator, &config) == kThreadError_None)
{
if (config.mSlaac == false)
{
@@ -2059,7 +2069,7 @@ void Interpreter::HandleNetifStateChanged(uint32_t aFlags, void *aContext)
if (!found)
{
otRemoveUnicastAddress(&address->mAddress);
otRemoveUnicastAddress(mInstance, &address->mAddress);
address->mValidLifetime = 0;
}
}
@@ -2067,7 +2077,7 @@ void Interpreter::HandleNetifStateChanged(uint32_t aFlags, void *aContext)
// add addresses
iterator = OT_NETWORK_DATA_ITERATOR_INIT;
while (otGetNextOnMeshPrefix(false, &iterator, &config) == kThreadError_None)
while (otGetNextOnMeshPrefix(mInstance, false, &iterator, &config) == kThreadError_None)
{
bool found = false;
@@ -2115,14 +2125,13 @@ void Interpreter::HandleNetifStateChanged(uint32_t aFlags, void *aContext)
address->mPrefixLength = config.mPrefix.mLength;
address->mPreferredLifetime = config.mPreferred ? 0xffffffff : 0;
address->mValidLifetime = 0xffffffff;
otAddUnicastAddress(address);
otAddUnicastAddress(mInstance, address);
break;
}
}
}
exit:
(void)aContext;
return;
}
+85 -74
View File
@@ -53,6 +53,8 @@ namespace Thread {
*/
namespace Cli {
class Interpreter;
/**
* This structure represents a CLI command.
*
@@ -60,7 +62,7 @@ namespace Cli {
struct Command
{
const char *mName; ///< A pointer to the command string.
void (*mCommand)(int argc, char *argv[]); ///< A function pointer to process the command.
void (Interpreter::*mCommand)(int argc, char *argv[]); ///< A function pointer to process the command.
};
/**
@@ -70,11 +72,11 @@ struct Command
class Interpreter
{
public:
/**
* This method initializes the CLI interpreter.
*
* Constructor
*/
static void Init(void);
Interpreter(otInstance *aInstance);
/**
* This method interprets a CLI command.
@@ -84,7 +86,7 @@ public:
* @param[in] aServer A reference to the CLI server.
*
*/
static void ProcessLine(char *aBuf, uint16_t aBufLength, Server &aServer);
void ProcessLine(char *aBuf, uint16_t aBufLength, Server &aServer);
/**
* This method parses an ASCII string as a long.
@@ -127,88 +129,97 @@ private:
kMaxArgs = 32,
};
static void AppendResult(ThreadError error);
static void OutputBytes(const uint8_t *aBytes, uint8_t aLength);
void AppendResult(ThreadError error);
void OutputBytes(const uint8_t *aBytes, uint8_t aLength);
static void ProcessHelp(int argc, char *argv[]);
static void ProcessBlacklist(int argc, char *argv[]);
static void ProcessChannel(int argc, char *argv[]);
static void ProcessChild(int argc, char *argv[]);
static void ProcessChildTimeout(int argc, char *argv[]);
static void ProcessChildMax(int argc, char *argv[]);
void ProcessHelp(int argc, char *argv[]);
void ProcessBlacklist(int argc, char *argv[]);
void ProcessChannel(int argc, char *argv[]);
void ProcessChild(int argc, char *argv[]);
void ProcessChildTimeout(int argc, char *argv[]);
void ProcessChildMax(int argc, char *argv[]);
#if OPENTHREAD_ENABLE_COMMISSIONER
static void ProcessCommissioner(int argc, char *argv[]);
void ProcessCommissioner(int argc, char *argv[]);
#endif // OPENTHREAD_ENABLE_COMMISSIONER
static void ProcessContextIdReuseDelay(int argc, char *argv[]);
static void ProcessCounters(int argc, char *argv[]);
static void ProcessDataset(int argc, char *argv[]);
void ProcessContextIdReuseDelay(int argc, char *argv[]);
void ProcessCounters(int argc, char *argv[]);
void ProcessDataset(int argc, char *argv[]);
#if OPENTHREAD_ENABLE_DIAG
static void ProcessDiag(int argc, char *argv[]);
void ProcessDiag(int argc, char *argv[]);
#endif // OPENTHREAD_ENABLE_DIAG
static void ProcessDiscover(int argc, char *argv[]);
static void ProcessEidCache(int argc, char *argv[]);
void ProcessDiscover(int argc, char *argv[]);
void ProcessEidCache(int argc, char *argv[]);
#ifdef OPENTHREAD_EXAMPLES_POSIX
static void ProcessExit(int argc, char *argv[]);
void ProcessExit(int argc, char *argv[]);
#endif
static void ProcessExtAddress(int argc, char *argv[]);
static void ProcessExtPanId(int argc, char *argv[]);
static void ProcessIfconfig(int argc, char *argv[]);
static void ProcessIpAddr(int argc, char *argv[]);
static ThreadError ProcessIpAddrAdd(int argc, char *argv[]);
static ThreadError ProcessIpAddrDel(int argc, char *argv[]);
void ProcessExtAddress(int argc, char *argv[]);
void ProcessExtPanId(int argc, char *argv[]);
void ProcessIfconfig(int argc, char *argv[]);
void ProcessIpAddr(int argc, char *argv[]);
ThreadError ProcessIpAddrAdd(int argc, char *argv[]);
ThreadError ProcessIpAddrDel(int argc, char *argv[]);
#if OPENTHREAD_ENABLE_JOINER
static void ProcessJoiner(int argc, char *argv[]);
void ProcessJoiner(int argc, char *argv[]);
#endif // OPENTHREAD_ENABLE_JOINER
static void ProcessKeySequence(int argc, char *argv[]);
static void ProcessLeaderData(int argc, char *argv[]);
static void ProcessLeaderPartitionId(int argc, char *argv[]);
static void ProcessLeaderWeight(int argc, char *argv[]);
static void ProcessLinkQuality(int argc, char *argv[]);
static void ProcessMasterKey(int argc, char *argv[]);
static void ProcessMode(int argc, char *argv[]);
static void ProcessNetworkDataRegister(int argc, char *argv[]);
static void ProcessNetworkIdTimeout(int argc, char *argv[]);
static void ProcessNetworkName(int argc, char *argv[]);
static void ProcessPanId(int argc, char *argv[]);
static void ProcessParent(int argc, char *argv[]);
static void ProcessPing(int argc, char *argv[]);
static void ProcessPollPeriod(int argc, char *argv[]);
static void ProcessPrefix(int argc, char *argv[]);
static ThreadError ProcessPrefixAdd(int argc, char *argv[]);
static ThreadError ProcessPrefixRemove(int argc, char *argv[]);
static ThreadError ProcessPrefixList(void);
static void ProcessPromiscuous(int argc, char *argv[]);
static void ProcessReleaseRouterId(int argc, char *argv[]);
static void ProcessReset(int argc, char *argv[]);
static void ProcessRoute(int argc, char *argv[]);
static void ProcessRouter(int argc, char *argv[]);
static void ProcessRouterRole(int argc, char *argv[]);
static ThreadError ProcessRouteAdd(int argc, char *argv[]);
static ThreadError ProcessRouteRemove(int argc, char *argv[]);
static void ProcessRouterUpgradeThreshold(int argc, char *argv[]);
static void ProcessRloc16(int argc, char *argv[]);
static void ProcessScan(int argc, char *argv[]);
static void ProcessSingleton(int argc, char *argv[]);
static void ProcessState(int argc, char *argv[]);
static void ProcessThread(int argc, char *argv[]);
static void ProcessVersion(int argc, char *argv[]);
static void ProcessWhitelist(int argc, char *argv[]);
void ProcessKeySequence(int argc, char *argv[]);
void ProcessLeaderData(int argc, char *argv[]);
void ProcessLeaderPartitionId(int argc, char *argv[]);
void ProcessLeaderWeight(int argc, char *argv[]);
void ProcessLinkQuality(int argc, char *argv[]);
void ProcessMasterKey(int argc, char *argv[]);
void ProcessMode(int argc, char *argv[]);
void ProcessNetworkDataRegister(int argc, char *argv[]);
void ProcessNetworkIdTimeout(int argc, char *argv[]);
void ProcessNetworkName(int argc, char *argv[]);
void ProcessPanId(int argc, char *argv[]);
void ProcessParent(int argc, char *argv[]);
void ProcessPing(int argc, char *argv[]);
void ProcessPollPeriod(int argc, char *argv[]);
void ProcessPrefix(int argc, char *argv[]);
ThreadError ProcessPrefixAdd(int argc, char *argv[]);
ThreadError ProcessPrefixRemove(int argc, char *argv[]);
ThreadError ProcessPrefixList(void);
void ProcessPromiscuous(int argc, char *argv[]);
void ProcessReleaseRouterId(int argc, char *argv[]);
void ProcessReset(int argc, char *argv[]);
void ProcessRoute(int argc, char *argv[]);
void ProcessRouter(int argc, char *argv[]);
void ProcessRouterRole(int argc, char *argv[]);
ThreadError ProcessRouteAdd(int argc, char *argv[]);
ThreadError ProcessRouteRemove(int argc, char *argv[]);
void ProcessRouterUpgradeThreshold(int argc, char *argv[]);
void ProcessRloc16(int argc, char *argv[]);
void ProcessScan(int argc, char *argv[]);
void ProcessSingleton(int argc, char *argv[]);
void ProcessState(int argc, char *argv[]);
void ProcessThread(int argc, char *argv[]);
void ProcessVersion(int argc, char *argv[]);
void ProcessWhitelist(int argc, char *argv[]);
static void HandleEchoResponse(void *aContext, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
static void HandlePingTimer(void *aContext);
static void HandleActiveScanResult(otActiveScanResult *aResult, void *aContext);
static void HandleNetifStateChanged(uint32_t aFlags, void *aContext);
static void HandleLinkPcapReceive(const RadioPacket *aFrame, void *aContext);
static void s_HandleEchoResponse(void *aContext, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
static void s_HandlePingTimer(void *aContext);
static void s_HandleActiveScanResult(otActiveScanResult *aResult, void *aContext);
static void s_HandleNetifStateChanged(uint32_t aFlags, void *aContext);
static void s_HandleLinkPcapReceive(const RadioPacket *aFrame, void *aContext);
void HandleEchoResponse(Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
void HandlePingTimer();
void HandleActiveScanResult(otActiveScanResult *aResult);
void HandleNetifStateChanged(uint32_t aFlags);
void HandleLinkPcapReceive(const RadioPacket *aFrame);
static const struct Command sCommands[];
static Ip6::MessageInfo sMessageInfo;
static Server *sServer;
static uint8_t sEchoRequest[];
static uint16_t sLength;
static uint16_t sCount;
static uint32_t sInterval;
static Timer *sPingTimer;
Ip6::MessageInfo sMessageInfo;
Server *sServer;
uint16_t sLength;
uint16_t sCount;
uint32_t sInterval;
Timer sPingTimer;
otNetifAddress sAutoAddresses[8];
otInstance *mInstance;
};
} // namespace Cli
+6 -7
View File
@@ -47,13 +47,11 @@ static Console *sServer;
static otDEFINE_ALIGNED_VAR(sCliConsoleRaw, sizeof(Console), uint64_t);
extern "C" void otCliConsoleInit(otCliConsoleOutputCallback aCallback,
void *aContext)
extern "C" void otCliConsoleInit(otInstance *aInstance, otCliConsoleOutputCallback aCallback, void *aContext)
{
sServer = new(&sCliConsoleRaw) Console;
sServer = new(&sCliConsoleRaw) Console(aInstance);
sServer->SetOutputCallback(aCallback);
sServer->SetContext(aContext);
Interpreter::Init();
}
extern "C" void otCliConsoleInputLine(char *aBuf, uint16_t aBufLength)
@@ -61,8 +59,9 @@ extern "C" void otCliConsoleInputLine(char *aBuf, uint16_t aBufLength)
sServer->ReceiveTask(aBuf, aBufLength);
}
Console::Console(void)
: mCallback(NULL)
Console::Console(otInstance *aInstance)
: mCallback(NULL),
mInterpreter(aInstance)
{
}
@@ -79,7 +78,7 @@ void Console::SetOutputCallback(otCliConsoleOutputCallback aCallback)
void Console::ReceiveTask(char *aBuf, uint16_t aBufLength)
{
Interpreter::ProcessLine(aBuf, aBufLength, *this);
mInterpreter.ProcessLine(aBuf, aBufLength, *this);
}
int Console::Output(const char *aBuf, uint16_t aBufLength)
+9 -1
View File
@@ -48,7 +48,13 @@ namespace Cli {
class Console: public Server
{
public:
Console(void);
/**
* Constructor
*
* @param[in] aInstance The OpenThread instance structure.
*
*/
Console(otInstance *aInstance);
/**
* This method delivers raw characters to the client.
@@ -99,6 +105,8 @@ private:
otCliConsoleOutputCallback mCallback;
void *mContext;
Interpreter mInterpreter;
};
} // namespace Cli
+56 -28
View File
@@ -176,7 +176,7 @@ ThreadError Dataset::Print(otOperationalDataset &aDataset)
return kThreadError_None;
}
ThreadError Dataset::Process(int argc, char *argv[], Server &aServer)
ThreadError Dataset::Process(otInstance *aInstance, int argc, char *argv[], Server &aServer)
{
ThreadError error = kThreadError_None;
@@ -191,7 +191,7 @@ ThreadError Dataset::Process(int argc, char *argv[], Server &aServer)
{
if (strcmp(argv[0], sCommands[i].mName) == 0)
{
error = sCommands[i].mCommand(argc - 1, argv + 1);
error = sCommands[i].mCommand(aInstance, argc - 1, argv + 1);
break;
}
}
@@ -200,29 +200,30 @@ exit:
return error;
}
ThreadError Dataset::ProcessHelp(int argc, char *argv[])
ThreadError Dataset::ProcessHelp(otInstance *aInstance, int argc, char *argv[])
{
for (unsigned int i = 0; i < sizeof(sCommands) / sizeof(sCommands[0]); i++)
{
sServer->OutputFormat("%s\r\n", sCommands[i].mName);
}
(void)aInstance;
(void)argc;
(void)argv;
return kThreadError_None;
}
ThreadError Dataset::ProcessActive(int argc, char *argv[])
ThreadError Dataset::ProcessActive(otInstance *aInstance, int argc, char *argv[])
{
otOperationalDataset dataset;
otGetActiveDataset(&dataset);
otGetActiveDataset(aInstance, &dataset);
(void)argc;
(void)argv;
return Print(dataset);
}
ThreadError Dataset::ProcessActiveTimestamp(int argc, char *argv[])
ThreadError Dataset::ProcessActiveTimestamp(otInstance *aInstance, int argc, char *argv[])
{
ThreadError error = kThreadError_None;
long value;
@@ -233,11 +234,13 @@ ThreadError Dataset::ProcessActiveTimestamp(int argc, char *argv[])
sDataset.mActiveTimestamp = static_cast<uint64_t>(value);
sDataset.mIsActiveTimestampSet = true;
(void)aInstance;
exit:
return error;
}
ThreadError Dataset::ProcessChannel(int argc, char *argv[])
ThreadError Dataset::ProcessChannel(otInstance *aInstance, int argc, char *argv[])
{
ThreadError error = kThreadError_None;
long value;
@@ -247,19 +250,22 @@ ThreadError Dataset::ProcessChannel(int argc, char *argv[])
sDataset.mChannel = static_cast<uint16_t>(value);
sDataset.mIsChannelSet = true;
(void)aInstance;
exit:
return error;
}
ThreadError Dataset::ProcessClear(int argc, char *argv[])
ThreadError Dataset::ProcessClear(otInstance *aInstance, int argc, char *argv[])
{
memset(&sDataset, 0, sizeof(sDataset));
(void)aInstance;
(void)argc;
(void)argv;
return kThreadError_None;
}
ThreadError Dataset::ProcessCommit(int argc, char *argv[])
ThreadError Dataset::ProcessCommit(otInstance *aInstance, int argc, char *argv[])
{
ThreadError error = kThreadError_None;
@@ -267,22 +273,24 @@ ThreadError Dataset::ProcessCommit(int argc, char *argv[])
if (strcmp(argv[0], "active") == 0)
{
SuccessOrExit(error = otSetActiveDataset(&sDataset));
SuccessOrExit(error = otSetActiveDataset(aInstance, &sDataset));
}
else if (strcmp(argv[0], "pending") == 0)
{
SuccessOrExit(error = otSetPendingDataset(&sDataset));
SuccessOrExit(error = otSetPendingDataset(aInstance, &sDataset));
}
else
{
ExitNow(error = kThreadError_Parse);
}
(void)aInstance;
exit:
return error;
}
ThreadError Dataset::ProcessDelay(int argc, char *argv[])
ThreadError Dataset::ProcessDelay(otInstance *aInstance, int argc, char *argv[])
{
ThreadError error = kThreadError_None;
long value;
@@ -292,11 +300,13 @@ ThreadError Dataset::ProcessDelay(int argc, char *argv[])
sDataset.mDelay = static_cast<uint32_t>(value);
sDataset.mIsDelaySet = true;
(void)aInstance;
exit:
return error;
}
ThreadError Dataset::ProcessExtPanId(int argc, char *argv[])
ThreadError Dataset::ProcessExtPanId(otInstance *aInstance, int argc, char *argv[])
{
ThreadError error = kThreadError_None;
uint8_t extPanId[OT_EXT_PAN_ID_SIZE];
@@ -307,11 +317,13 @@ ThreadError Dataset::ProcessExtPanId(int argc, char *argv[])
memcpy(sDataset.mExtendedPanId.m8, extPanId, sizeof(sDataset.mExtendedPanId));
sDataset.mIsExtendedPanIdSet = true;
(void)aInstance;
exit:
return error;
}
ThreadError Dataset::ProcessMasterKey(int argc, char *argv[])
ThreadError Dataset::ProcessMasterKey(otInstance *aInstance, int argc, char *argv[])
{
ThreadError error = kThreadError_None;
int keyLength;
@@ -324,11 +336,13 @@ ThreadError Dataset::ProcessMasterKey(int argc, char *argv[])
memcpy(sDataset.mMasterKey.m8, key, sizeof(sDataset.mMasterKey));
sDataset.mIsMasterKeySet = true;
(void)aInstance;
exit:
return error;
}
ThreadError Dataset::ProcessMeshLocalPrefix(int argc, char *argv[])
ThreadError Dataset::ProcessMeshLocalPrefix(otInstance *aInstance, int argc, char *argv[])
{
ThreadError error = kThreadError_None;
otIp6Address prefix;
@@ -339,11 +353,13 @@ ThreadError Dataset::ProcessMeshLocalPrefix(int argc, char *argv[])
memcpy(sDataset.mMeshLocalPrefix.m8, prefix.mFields.m8, sizeof(sDataset.mMeshLocalPrefix.m8));
sDataset.mIsMeshLocalPrefixSet = true;
(void)aInstance;
exit:
return error;
}
ThreadError Dataset::ProcessNetworkName(int argc, char *argv[])
ThreadError Dataset::ProcessNetworkName(otInstance *aInstance, int argc, char *argv[])
{
ThreadError error = kThreadError_None;
size_t length;
@@ -355,11 +371,13 @@ ThreadError Dataset::ProcessNetworkName(int argc, char *argv[])
memcpy(sDataset.mNetworkName.m8, argv[0], length);
sDataset.mIsNetworkNameSet = true;
(void)aInstance;
exit:
return error;
}
ThreadError Dataset::ProcessPanId(int argc, char *argv[])
ThreadError Dataset::ProcessPanId(otInstance *aInstance, int argc, char *argv[])
{
ThreadError error = kThreadError_None;
long value;
@@ -369,21 +387,23 @@ ThreadError Dataset::ProcessPanId(int argc, char *argv[])
sDataset.mPanId = static_cast<otPanId>(value);
sDataset.mIsPanIdSet = true;
(void)aInstance;
exit:
return error;
}
ThreadError Dataset::ProcessPending(int argc, char *argv[])
ThreadError Dataset::ProcessPending(otInstance *aInstance, int argc, char *argv[])
{
otOperationalDataset dataset;
otGetPendingDataset(&dataset);
otGetPendingDataset(aInstance, &dataset);
(void)argc;
(void)argv;
return Print(dataset);
}
ThreadError Dataset::ProcessPendingTimestamp(int argc, char *argv[])
ThreadError Dataset::ProcessPendingTimestamp(otInstance *aInstance, int argc, char *argv[])
{
ThreadError error = kThreadError_None;
long value;
@@ -393,11 +413,13 @@ ThreadError Dataset::ProcessPendingTimestamp(int argc, char *argv[])
sDataset.mPendingTimestamp = static_cast<uint64_t>(value);
sDataset.mIsPendingTimestampSet = true;
(void)aInstance;
exit:
return error;
}
ThreadError Dataset::ProcessMgmtSetCommand(int argc, char *argv[])
ThreadError Dataset::ProcessMgmtSetCommand(otInstance *aInstance, int argc, char *argv[])
{
ThreadError error = kThreadError_None;
otOperationalDataset dataset;
@@ -495,22 +517,24 @@ ThreadError Dataset::ProcessMgmtSetCommand(int argc, char *argv[])
if (strcmp(argv[0], "active") == 0)
{
SuccessOrExit(error = otSendActiveSet(&dataset, tlvs, static_cast<uint8_t>(length)));
SuccessOrExit(error = otSendActiveSet(aInstance, &dataset, tlvs, static_cast<uint8_t>(length)));
}
else if (strcmp(argv[0], "pending") == 0)
{
SuccessOrExit(error = otSendPendingSet(&dataset, tlvs, static_cast<uint8_t>(length)));
SuccessOrExit(error = otSendPendingSet(aInstance, &dataset, tlvs, static_cast<uint8_t>(length)));
}
else
{
ExitNow(error = kThreadError_Parse);
}
(void)aInstance;
exit:
return error;
}
ThreadError Dataset::ProcessMgmtGetCommand(int argc, char *argv[])
ThreadError Dataset::ProcessMgmtGetCommand(otInstance *aInstance, int argc, char *argv[])
{
ThreadError error = kThreadError_None;
otOperationalDataset dataset;
@@ -579,22 +603,24 @@ ThreadError Dataset::ProcessMgmtGetCommand(int argc, char *argv[])
if (strcmp(argv[0], "active") == 0)
{
SuccessOrExit(error = otSendActiveGet(tlvs, static_cast<uint8_t>(length)));
SuccessOrExit(error = otSendActiveGet(aInstance, tlvs, static_cast<uint8_t>(length)));
}
else if (strcmp(argv[0], "pending") == 0)
{
SuccessOrExit(error = otSendPendingGet(tlvs, static_cast<uint8_t>(length)));
SuccessOrExit(error = otSendPendingGet(aInstance, tlvs, static_cast<uint8_t>(length)));
}
else
{
ExitNow(error = kThreadError_Parse);
}
(void)aInstance;
exit:
return error;
}
ThreadError Dataset::ProcessPSKc(int argc, char *argv[])
ThreadError Dataset::ProcessPSKc(otInstance *aInstance, int argc, char *argv[])
{
ThreadError error = kThreadError_None;
uint16_t length;
@@ -607,12 +633,13 @@ ThreadError Dataset::ProcessPSKc(int argc, char *argv[])
== length, error = kThreadError_Parse);
sDataset.mIsPSKcSet = true;
(void)aInstance;
exit:
return error;
}
ThreadError Dataset::ProcessSecurityPolicy(int argc, char *argv[])
ThreadError Dataset::ProcessSecurityPolicy(otInstance *aInstance, int argc, char *argv[])
{
ThreadError error = kThreadError_None;
long value;
@@ -656,6 +683,7 @@ ThreadError Dataset::ProcessSecurityPolicy(int argc, char *argv[])
}
sDataset.mIsSecurityPolicySet = true;
(void)aInstance;
exit:
return error;
+22 -21
View File
@@ -48,8 +48,9 @@ namespace Cli {
*/
struct DatasetCommand
{
const char *mName; ///< A pointer to the command string.
ThreadError(*mCommand)(int argc, char *argv[]); ///< A function pointer to process the command.
const char *mName; ///< A pointer to the command string.
ThreadError(*mCommand)(otInstance *aInstance, int argc,
char *argv[]); ///< A function pointer to process the command.
};
/**
@@ -66,30 +67,30 @@ public:
* @param[in] argv A pointer to an array of command line arguments.
*
*/
static ThreadError Process(int argc, char *argv[], Server &aServer);
static ThreadError Process(otInstance *aInstance, int argc, char *argv[], Server &aServer);
private:
static void OutputBytes(const uint8_t *aBytes, uint8_t aLength);
static ThreadError Print(otOperationalDataset &aDataset);
static ThreadError ProcessHelp(int argc, char *argv[]);
static ThreadError ProcessActive(int argc, char *argv[]);
static ThreadError ProcessActiveTimestamp(int argc, char *argv[]);
static ThreadError ProcessChannel(int argc, char *argv[]);
static ThreadError ProcessClear(int argc, char *argv[]);
static ThreadError ProcessCommit(int argc, char *argv[]);
static ThreadError ProcessDelay(int argc, char *argv[]);
static ThreadError ProcessExtPanId(int argc, char *argv[]);
static ThreadError ProcessMasterKey(int argc, char *argv[]);
static ThreadError ProcessMeshLocalPrefix(int argc, char *argv[]);
static ThreadError ProcessNetworkName(int argc, char *argv[]);
static ThreadError ProcessPanId(int argc, char *argv[]);
static ThreadError ProcessPending(int argc, char *argv[]);
static ThreadError ProcessPendingTimestamp(int argc, char *argv[]);
static ThreadError ProcessMgmtSetCommand(int argc, char *argv[]);
static ThreadError ProcessMgmtGetCommand(int argc, char *argv[]);
static ThreadError ProcessPSKc(int argc, char *argv[]);
static ThreadError ProcessSecurityPolicy(int argc, char *argv[]);
static ThreadError ProcessHelp(otInstance *aInstance, int argc, char *argv[]);
static ThreadError ProcessActive(otInstance *aInstance, int argc, char *argv[]);
static ThreadError ProcessActiveTimestamp(otInstance *aInstance, int argc, char *argv[]);
static ThreadError ProcessChannel(otInstance *aInstance, int argc, char *argv[]);
static ThreadError ProcessClear(otInstance *aInstance, int argc, char *argv[]);
static ThreadError ProcessCommit(otInstance *aInstance, int argc, char *argv[]);
static ThreadError ProcessDelay(otInstance *aInstance, int argc, char *argv[]);
static ThreadError ProcessExtPanId(otInstance *aInstance, int argc, char *argv[]);
static ThreadError ProcessMasterKey(otInstance *aInstance, int argc, char *argv[]);
static ThreadError ProcessMeshLocalPrefix(otInstance *aInstance, int argc, char *argv[]);
static ThreadError ProcessNetworkName(otInstance *aInstance, int argc, char *argv[]);
static ThreadError ProcessPanId(otInstance *aInstance, int argc, char *argv[]);
static ThreadError ProcessPending(otInstance *aInstance, int argc, char *argv[]);
static ThreadError ProcessPendingTimestamp(otInstance *aInstance, int argc, char *argv[]);
static ThreadError ProcessMgmtSetCommand(otInstance *aInstance, int argc, char *argv[]);
static ThreadError ProcessMgmtGetCommand(otInstance *aInstance, int argc, char *argv[]);
static ThreadError ProcessPSKc(otInstance *aInstance, int argc, char *argv[]);
static ThreadError ProcessSecurityPolicy(otInstance *aInstance, int argc, char *argv[]);
static const DatasetCommand sCommands[];
static otOperationalDataset sDataset;
+8 -8
View File
@@ -51,17 +51,17 @@ namespace Cli {
static const char sCommandPrompt[] = {'>', ' '};
static const char sEraseString[] = {'\b', ' ', '\b'};
static const char CRNL[] = {'\r', '\n'};
static Uart *sServer;
Uart *Uart::sUartServer;
static otDEFINE_ALIGNED_VAR(sCliUartRaw, sizeof(Uart), uint64_t);
extern "C" void otCliUartInit(void)
extern "C" void otCliUartInit(otInstance *aInstance)
{
sServer = new(&sCliUartRaw) Uart;
Interpreter::Init();
Uart::sUartServer = new(&sCliUartRaw) Uart(aInstance);
}
Uart::Uart(void)
Uart::Uart(otInstance *aInstance):
mInterpreter(aInstance)
{
mRxLength = 0;
mTxHead = 0;
@@ -71,7 +71,7 @@ Uart::Uart(void)
extern "C" void otPlatUartReceived(const uint8_t *aBuf, uint16_t aBufLength)
{
sServer->ReceiveTask(aBuf, aBufLength);
Uart::sUartServer->ReceiveTask(aBuf, aBufLength);
}
void Uart::ReceiveTask(const uint8_t *aBuf, uint16_t aBufLength)
@@ -137,7 +137,7 @@ ThreadError Uart::ProcessCommand(void)
mRxBuffer[--mRxLength] = '\0';
}
Interpreter::ProcessLine(mRxBuffer, mRxLength, *this);
mInterpreter.ProcessLine(mRxBuffer, mRxLength, *this);
mRxLength = 0;
@@ -202,7 +202,7 @@ exit:
extern "C" void otPlatUartSendDone(void)
{
sServer->SendDoneTask();
Uart::sUartServer->SendDoneTask();
}
void Uart::SendDoneTask(void)
+13 -1
View File
@@ -48,7 +48,13 @@ namespace Cli {
class Uart: public Server
{
public:
Uart(void);
/**
* Constructor
*
* @param[in] aInstance The OpenThread instance structure.
*
*/
Uart(otInstance *aInstance);
/**
* This method delivers raw characters to the client.
@@ -75,6 +81,8 @@ public:
void ReceiveTask(const uint8_t *aBuf, uint16_t aBufLength);
void SendDoneTask(void);
static Uart *sUartServer;
private:
enum
{
@@ -94,6 +102,10 @@ private:
uint16_t mTxLength;
uint16_t mSendLength;
Interpreter mInterpreter;
friend class Interpreter;
};
} // namespace Cli
+9 -3
View File
@@ -42,6 +42,12 @@
namespace Thread {
namespace Cli {
Udp::Udp(otInstance *aInstance, Interpreter *aInterpreter):
mInstance(aInstance),
mInterpreter(aInterpreter)
{
}
ThreadError Udp::Start(void)
{
ThreadError error;
@@ -50,7 +56,7 @@ ThreadError Udp::Start(void)
memset(&sockaddr, 0, sizeof(otSockAddr));
sockaddr.mPort = 7335;
SuccessOrExit(error = otOpenUdpSocket(&mSocket, &HandleUdpReceive, this));
SuccessOrExit(error = otOpenUdpSocket(mInstance, &mSocket, &Udp::HandleUdpReceive, this));
SuccessOrExit(error = otBindUdpSocket(&mSocket, &sockaddr));
exit:
@@ -83,7 +89,7 @@ void Udp::HandleUdpReceive(otMessage aMessage, const otMessageInfo *aMessageInfo
mPeer = *aMessageInfo;
Interpreter::ProcessLine(buf, payloadLength, *this);
mInterpreter->ProcessLine(buf, payloadLength, *this);
exit:
{}
@@ -94,7 +100,7 @@ int Udp::Output(const char *aBuf, uint16_t aBufLength)
ThreadError error = kThreadError_None;
otMessage message;
VerifyOrExit((message = otNewUdpMessage()) != NULL, error = kThreadError_NoBufs);
VerifyOrExit((message = otNewUdpMessage(mInstance)) != NULL, error = kThreadError_NoBufs);
SuccessOrExit(error = otSetMessageLength(message, aBufLength));
otWriteMessage(message, 0, aBuf, aBufLength);
SuccessOrExit(error = otSendUdp(&mSocket, message, &mPeer));
+11
View File
@@ -47,6 +47,15 @@ namespace Cli {
class Udp: public Server
{
public:
/**
* Constructor
*
* @param[in] aInstance The OpenThread instance structure.
* @param[in] aInterpreter The Interpreter structure.
*
*/
Udp(otInstance *aInstance, Interpreter *aInterpreter);
/**
* This method starts the CLI server.
*
@@ -88,6 +97,8 @@ private:
otUdpSocket mSocket;
otMessageInfo mPeer;
otInstance *mInstance;
Interpreter *mInterpreter;
};
} // namespace Cli
+1 -1
View File
@@ -67,7 +67,7 @@ ThreadError TaskletScheduler::Post(Tasklet &aTasklet)
{
mHead = &aTasklet;
mTail = &aTasklet;
otSignalTaskletPending();
otSignalTaskletPending(NULL);
}
else
{
+3 -3
View File
@@ -136,18 +136,18 @@ void TimerScheduler::SetAlarm(void)
if (mHead == NULL)
{
otPlatAlarmStop();
otPlatAlarmStop(NULL);
}
else
{
elapsed = now - mHead->mT0;
remaining = (mHead->mDt > elapsed) ? mHead->mDt - elapsed : 0;
otPlatAlarmStartAt(now, remaining);
otPlatAlarmStartAt(NULL, now, remaining);
}
}
extern "C" void otPlatAlarmFired(void)
extern "C" void otPlatAlarmFired(otInstance *)
{
sTimerScheduler->FireTimers();
}
+19 -19
View File
@@ -126,7 +126,7 @@ Mac::Mac(ThreadNetif &aThreadNetif):
mPcapCallback = NULL;
mPcapCallbackContext = NULL;
otPlatRadioEnable();
otPlatRadioEnable(NULL);
}
ThreadError Mac::ActiveScan(uint32_t aScanChannels, uint16_t aScanDuration, ActiveScanHandler aHandler, void *aContext)
@@ -214,7 +214,7 @@ ThreadError Mac::SetExtAddress(const ExtAddress &aExtAddress)
buf[i] = aExtAddress.m8[7 - i];
}
SuccessOrExit(error = otPlatRadioSetExtendedAddress(buf));
SuccessOrExit(error = otPlatRadioSetExtendedAddress(NULL, buf));
mExtAddress = aExtAddress;
exit:
@@ -229,7 +229,7 @@ ShortAddress Mac::GetShortAddress(void) const
ThreadError Mac::SetShortAddress(ShortAddress aShortAddress)
{
mShortAddress = aShortAddress;
return otPlatRadioSetShortAddress(aShortAddress);
return otPlatRadioSetShortAddress(NULL, aShortAddress);
}
uint8_t Mac::GetChannel(void) const
@@ -279,7 +279,7 @@ PanId Mac::GetPanId(void) const
ThreadError Mac::SetPanId(PanId aPanId)
{
mPanId = aPanId;
return otPlatRadioSetPanId(mPanId);
return otPlatRadioSetPanId(NULL, mPanId);
}
const uint8_t *Mac::GetExtendedPanId(void) const
@@ -325,17 +325,17 @@ void Mac::NextOperation(void)
switch (mState)
{
case kStateActiveScan:
otPlatRadioReceive(mScanChannel);
otPlatRadioReceive(NULL, mScanChannel);
break;
default:
if (mRxOnWhenIdle || mReceiveTimer.IsRunning() || otPlatRadioGetPromiscuous())
if (mRxOnWhenIdle || mReceiveTimer.IsRunning() || otPlatRadioGetPromiscuous(NULL))
{
otPlatRadioReceive(mChannel);
otPlatRadioReceive(NULL, mChannel);
}
else
{
otPlatRadioSleep();
otPlatRadioSleep(NULL);
}
break;
@@ -498,10 +498,10 @@ exit:
void Mac::HandleBeginTransmit(void)
{
Frame &sendFrame(*static_cast<Frame *>(otPlatRadioGetTransmitBuffer()));
Frame &sendFrame(*static_cast<Frame *>(otPlatRadioGetTransmitBuffer(NULL)));
ThreadError error = kThreadError_None;
if (otPlatRadioReceive(mChannel) != kThreadError_None)
if (otPlatRadioReceive(NULL, mChannel) != kThreadError_None)
{
mBeginTransmit.Post();
ExitNow();
@@ -542,9 +542,9 @@ void Mac::HandleBeginTransmit(void)
sendFrame.SetPower(mMaxTransmitPower);
}
SuccessOrExit(error = otPlatRadioTransmit());
SuccessOrExit(error = otPlatRadioTransmit(NULL));
if (sendFrame.GetAckRequest() && !(otPlatRadioGetCaps() & kRadioCapsAckTimeout))
if (sendFrame.GetAckRequest() && !(otPlatRadioGetCaps(NULL) & kRadioCapsAckTimeout))
{
mAckTimer.Start(kAckTimeout);
otLogDebgMac("ack timer start\n");
@@ -558,7 +558,7 @@ exit:
}
}
extern "C" void otPlatRadioTransmitDone(bool aRxPending, ThreadError aError)
extern "C" void otPlatRadioTransmitDone(otInstance *, bool aRxPending, ThreadError aError)
{
sMac->TransmitDoneTask(aRxPending, aError);
}
@@ -618,7 +618,7 @@ void Mac::HandleAckTimer(void *aContext)
void Mac::HandleAckTimer(void)
{
otPlatRadioReceive(mChannel);
otPlatRadioReceive(NULL, mChannel);
switch (mState)
{
@@ -669,7 +669,7 @@ void Mac::HandleReceiveTimer(void)
void Mac::SentFrame(bool aAcked)
{
Frame &sendFrame(*static_cast<Frame *>(otPlatRadioGetTransmitBuffer()));
Frame &sendFrame(*static_cast<Frame *>(otPlatRadioGetTransmitBuffer(NULL)));
Address destination;
Sender *sender;
@@ -869,7 +869,7 @@ exit:
return error;
}
extern "C" void otPlatRadioReceiveDone(RadioPacket *aFrame, ThreadError aError)
extern "C" void otPlatRadioReceiveDone(otInstance *, RadioPacket *aFrame, ThreadError aError)
{
sMac->ReceiveDoneTask(static_cast<Frame *>(aFrame), aError);
}
@@ -1109,14 +1109,14 @@ void Mac::SetPcapCallback(otLinkPcapCallback aPcapCallback, void *aCallbackConte
bool Mac::IsPromiscuous(void)
{
return otPlatRadioGetPromiscuous();
return otPlatRadioGetPromiscuous(NULL);
}
void Mac::SetPromiscuous(bool aPromiscuous)
{
otPlatRadioSetPromiscuous(aPromiscuous);
otPlatRadioSetPromiscuous(NULL, aPromiscuous);
SuccessOrExit(otPlatRadioReceive(mChannel));
SuccessOrExit(otPlatRadioReceive(NULL, mChannel));
NextOperation();
exit:
+197 -167
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -184,7 +184,7 @@ ThreadError Mle::Start(void)
ThreadError error = kThreadError_None;
// cannot bring up the interface if IEEE 802.15.4 promiscuous mode is enabled
VerifyOrExit(otPlatRadioGetPromiscuous() == false, error = kThreadError_Busy);
VerifyOrExit(otPlatRadioGetPromiscuous(NULL) == false, error = kThreadError_Busy);
VerifyOrExit(mNetif.IsUp(), error = kThreadError_InvalidState);
mDeviceState = kDeviceStateDetached;
+28 -24
View File
@@ -61,9 +61,11 @@ uint8_t Diag::sChannel;
uint8_t Diag::sTxLen;
uint32_t Diag::sTxPeriod;
uint32_t Diag::sTxPackets;
otInstance *Diag::sContext;
void Diag::Init()
void Diag::Init(otInstance *aInstance)
{
sContext = aInstance;
sChannel = 20;
sTxPower = 0;
sTxPeriod = 0;
@@ -119,16 +121,16 @@ void Diag::ProcessStart(int argc, char *argv[], char *aOutput, size_t aOutputMax
ThreadError error = kThreadError_None;
// enable radio
otPlatRadioEnable();
otPlatRadioEnable(sContext);
// enable promiscuous mode
otPlatRadioSetPromiscuous(true);
otPlatRadioSetPromiscuous(sContext, true);
// stop timer
otPlatAlarmStop();
otPlatAlarmStop(sContext);
// start to listen on the default channel
SuccessOrExit(error = otPlatRadioReceive(sChannel));
SuccessOrExit(error = otPlatRadioReceive(sContext, sChannel));
// enable diagnostics mode
otPlatDiagModeSet(true);
@@ -149,9 +151,9 @@ void Diag::ProcessStop(int argc, char *argv[], char *aOutput, size_t aOutputMaxL
VerifyOrExit(otPlatDiagModeGet(), error = kThreadError_InvalidState);
otPlatAlarmStop();
otPlatAlarmStop(sContext);
otPlatDiagModeSet(false);
otPlatRadioSetPromiscuous(false);
otPlatRadioSetPromiscuous(sContext, false);
snprintf(aOutput, aOutputMaxLen, "received packets: %d\r\nsent packets: %d\r\nfirst received packet: rssi=%d, lqi=%d\r\n\nstop diagnostics mode\r\nstatus 0x%02x\r\n",
static_cast<int>(sStats.received_packets), static_cast<int>(sStats.sent_packets), static_cast<int>(sStats.first_rssi),
@@ -172,7 +174,7 @@ ThreadError Diag::ParseLong(char *argv, long &value)
void Diag::TxPacket()
{
RadioPacket *packet = otPlatRadioGetTransmitBuffer();
RadioPacket *packet = otPlatRadioGetTransmitBuffer(sContext);
if (sTxPackets > 0)
{
@@ -188,7 +190,7 @@ void Diag::TxPacket()
packet->mPsdu[i] = i;
}
otPlatRadioTransmit();
otPlatRadioTransmit(sContext);
}
void Diag::ProcessChannel(int argc, char *argv[], char *aOutput, size_t aOutputMaxLen)
@@ -210,7 +212,7 @@ void Diag::ProcessChannel(int argc, char *argv[], char *aOutput, size_t aOutputM
sChannel = static_cast<uint8_t>(value);
// listen on the set channel immediately
otPlatRadioReceive(sChannel);
otPlatRadioReceive(sContext, sChannel);
snprintf(aOutput, aOutputMaxLen, "set channel to %d\r\nstatus 0x%02x\r\n", sChannel, error);
}
@@ -272,7 +274,7 @@ void Diag::ProcessRepeat(int argc, char *argv[], char *aOutput, size_t aOutputMa
if (strcmp(argv[0], "stop") == 0)
{
otPlatAlarmStop();
otPlatAlarmStop(sContext);
snprintf(aOutput, aOutputMaxLen, "repeated packet transmission is stopped\r\nstatus 0x%02x\r\n", error);
}
else
@@ -289,7 +291,7 @@ void Diag::ProcessRepeat(int argc, char *argv[], char *aOutput, size_t aOutputMa
sTxLen = static_cast<uint8_t>(value);
uint32_t now = otPlatAlarmGetNow();
otPlatAlarmStartAt(now, sTxPeriod);
otPlatAlarmStartAt(sContext, now, sTxPeriod);
snprintf(aOutput, aOutputMaxLen, "sending packets of length %#x at the delay of %#x ms\r\nstatus 0x%02x\r\n", static_cast<int>(sTxLen), static_cast<int>(sTxPeriod), error);
}
@@ -303,7 +305,7 @@ void Diag::ProcessSleep(int argc, char *argv[], char *aOutput, size_t aOutputMax
VerifyOrExit(otPlatDiagModeGet(), error = kThreadError_InvalidState);
otPlatRadioSleep();
otPlatRadioSleep(sContext);
snprintf(aOutput, aOutputMaxLen, "sleeping now...\r\n");
exit:
@@ -328,8 +330,9 @@ exit:
AppendErrorResult(error, aOutput, aOutputMaxLen);
}
void Diag::DiagTransmitDone(bool aRxPending, ThreadError aError)
void Diag::DiagTransmitDone(otInstance *aInstance, bool aRxPending, ThreadError aError)
{
(void)aInstance;
if (!aRxPending && aError == kThreadError_None)
{
sStats.sent_packets++;
@@ -341,8 +344,9 @@ void Diag::DiagTransmitDone(bool aRxPending, ThreadError aError)
}
}
void Diag::DiagReceiveDone(RadioPacket *aFrame, ThreadError aError)
void Diag::DiagReceiveDone(otInstance *aInstance, RadioPacket *aFrame, ThreadError aError)
{
(void)aInstance;
if (aError == kThreadError_None)
{
// for sensitivity test, only record the rssi and lqi for the first packet
@@ -355,30 +359,30 @@ void Diag::DiagReceiveDone(RadioPacket *aFrame, ThreadError aError)
sStats.received_packets++;
}
otPlatRadioReceive(sChannel);
otPlatRadioReceive(aInstance, sChannel);
}
void Diag::AlarmFired()
void Diag::AlarmFired(otInstance *aInstance)
{
uint32_t now = otPlatAlarmGetNow();
TxPacket();
otPlatAlarmStartAt(now, sTxPeriod);
otPlatAlarmStartAt(aInstance, now, sTxPeriod);
}
extern "C" void otPlatDiagAlarmFired()
extern "C" void otPlatDiagAlarmFired(otInstance *aInstance)
{
Diag::AlarmFired();
Diag::AlarmFired(aInstance);
}
extern "C" void otPlatDiagRadioTransmitDone(bool aRxPending, ThreadError aError)
extern "C" void otPlatDiagRadioTransmitDone(otInstance *aInstance, bool aRxPending, ThreadError aError)
{
Diag::DiagTransmitDone(aRxPending, aError);
Diag::DiagTransmitDone(aInstance, aRxPending, aError);
}
extern "C" void otPlatDiagRadioReceiveDone(RadioPacket *aFrame, ThreadError aError)
extern "C" void otPlatDiagRadioReceiveDone(otInstance *aInstance, RadioPacket *aFrame, ThreadError aError)
{
Diag::DiagReceiveDone(aFrame, aError);
Diag::DiagReceiveDone(aInstance, aFrame, aError);
}
} // namespace Diagnostics
+6 -4
View File
@@ -35,6 +35,7 @@
#define DIAG_PROCESS_HPP_
#include <stdarg.h>
#include <openthread-types.h>
#include <platform/radio.h>
#include <platform/alarm.h>
#include <platform/diag.h>
@@ -62,13 +63,13 @@ struct DiagStats
class Diag
{
public:
static void Init();
static void Init(otInstance *aInstance);
static char *ProcessCmd(int argc, char *argv[]);
static bool isEnabled();
static void DiagTransmitDone(bool aRxPending, ThreadError aError);
static void DiagReceiveDone(RadioPacket *aFrame, ThreadError aError);
static void AlarmFired();
static void DiagTransmitDone(otInstance *aInstance, bool aRxPending, ThreadError aError);
static void DiagReceiveDone(otInstance *aInstance, RadioPacket *aFrame, ThreadError aError);
static void AlarmFired(otInstance *aInstance);
private:
static void AppendErrorResult(ThreadError error, char *aOutput, size_t aOutputMaxLen);
@@ -91,6 +92,7 @@ private:
static uint8_t sTxLen;
static uint32_t sTxPeriod;
static uint32_t sTxPackets;
static otInstance *sContext;
};
} // namespace Diagnostics
+2 -2
View File
@@ -46,9 +46,9 @@ namespace Diagnostics {
extern "C" {
#endif
void diagInit()
void diagInit(otInstance *aInstance)
{
Diag::Init();
Diag::Init(aInstance);
}
char *diagProcessCmd(int argc, char *argv[])
+117 -110
View File
@@ -406,9 +406,11 @@ static uint8_t BorderRouterConfigToFlagByte(const otBorderRouterConfig &config)
// MARK: Class Boilerplate
// ----------------------------------------------------------------------------
NcpBase::NcpBase():
mUpdateChangedPropsTask(sIp6->mTaskletScheduler, &UpdateChangedProps, this)
NcpBase::NcpBase(otInstance *aInstance):
mInstance(aInstance),
mUpdateChangedPropsTask(sIp6->mTaskletScheduler, &NcpBase::UpdateChangedProps, this)
{
assert(mInstance != NULL);
mSupportedChannelMask = kPhySupportedChannelMask;
mChannelMask = mSupportedChannelMask;
mScanPeriod = 200; // ms
@@ -428,9 +430,9 @@ NcpBase::NcpBase():
mDroppedOutboundIpFrameCounter = 0;
mDroppedInboundIpFrameCounter = 0;
otSetStateChangedCallback(&HandleNetifStateChanged, this);
otSetReceiveIp6DatagramCallback(&HandleDatagramFromStack, this);
otSetIcmpEchoEnabled(false);
otSetStateChangedCallback(mInstance, &NcpBase::HandleNetifStateChanged, this);
otSetReceiveIp6DatagramCallback(mInstance, &NcpBase::HandleDatagramFromStack, this);
otSetIcmpEchoEnabled(mInstance, false);
mUpdateChangedPropsTask.Post();
}
@@ -635,7 +637,7 @@ void NcpBase::UpdateChangedProps(void)
{
SuccessOrExit(SendLastStatus(
SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0,
ResetReasonToSpinelStatus(otPlatGetResetReason())
ResetReasonToSpinelStatus(otPlatGetResetReason(mInstance))
));
mChangedFlags &= ~static_cast<uint32_t>(NCP_PLAT_RESET_REASON);
}
@@ -661,11 +663,11 @@ void NcpBase::UpdateChangedProps(void)
{
mRequireJoinExistingNetwork = false;
if ( (otGetDeviceRole() == kDeviceRoleLeader)
&& otIsSingleton()
if ( (otGetDeviceRole(mInstance) == kDeviceRoleLeader)
&& otIsSingleton(mInstance)
) {
mChangedFlags &= ~static_cast<uint32_t>(OT_NET_PARTITION_ID);
otThreadStop();
otThreadStop(mInstance);
// TODO: It would be nice to be able to indicate
// something more specific than SPINEL_STATUS_JOIN_FAILURE
@@ -1136,13 +1138,14 @@ ThreadError NcpBase::CommandHandler_RESET(uint8_t header, unsigned int command,
// Signal a platform reset. If implemented, this function
// shouldn't return.
otPlatReset();
otPlatReset(mInstance);
// We only get to this point if the
// platform doesn't support resetting.
// In such a case we fake it.
otDisable();
otThreadStop(mInstance);
otInterfaceDown(mInstance);
errorCode = SendLastStatus(SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, SPINEL_STATUS_RESET_SOFTWARE);
@@ -1370,12 +1373,12 @@ ThreadError NcpBase::GetPropertyHandler_POWER_STATE(uint8_t header, spinel_prop_
ThreadError NcpBase::GetPropertyHandler_HWADDR(uint8_t header, spinel_prop_key_t key)
{
return SendPropertyUpdate(
header,
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_EUI64_S,
otGetExtendedAddress()
);
header,
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_EUI64_S,
otGetExtendedAddress(mInstance)
);
}
ThreadError NcpBase::GetPropertyHandler_LOCK(uint8_t header, spinel_prop_key_t key)
@@ -1397,7 +1400,7 @@ ThreadError NcpBase::GetPropertyHandler_PHY_ENABLED(uint8_t header, spinel_prop_
ThreadError NcpBase::GetPropertyHandler_PHY_FREQ(uint8_t header, spinel_prop_key_t key)
{
uint32_t freq_khz(0);
const uint8_t chan(otGetChannel());
const uint8_t chan(otGetChannel(mInstance));
if (chan == 0)
{
@@ -1433,7 +1436,7 @@ ThreadError NcpBase::GetPropertyHandler_PHY_CHAN(uint8_t header, spinel_prop_key
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_UINT8_S,
otGetChannel()
otGetChannel(mInstance)
);
}
@@ -1444,7 +1447,7 @@ ThreadError NcpBase::GetPropertyHandler_PHY_RSSI(uint8_t header, spinel_prop_key
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_INT8_S,
otPlatRadioGetRssi()
otPlatRadioGetRssi(mInstance)
);
}
@@ -1452,7 +1455,7 @@ ThreadError NcpBase::GetPropertyHandler_MAC_SCAN_STATE(uint8_t header, spinel_pr
{
ThreadError errorCode = kThreadError_None;
if (otIsActiveScanInProgress())
if (otIsActiveScanInProgress(mInstance))
{
errorCode = SendPropertyUpdate(
header,
@@ -1521,7 +1524,7 @@ ThreadError NcpBase::GetPropertyHandler_MAC_15_4_PANID(uint8_t header, spinel_pr
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_UINT16_S,
otGetPanId()
otGetPanId(mInstance)
);
}
@@ -1532,7 +1535,7 @@ ThreadError NcpBase::GetPropertyHandler_MAC_FILTER_MODE(uint8_t header, spinel_p
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_INT8_S,
otPlatRadioGetPromiscuous()
otPlatRadioGetPromiscuous(mInstance)
? SPINEL_MAC_FILTER_MODE_15_4_PROMISCUOUS
: SPINEL_MAC_FILTER_MODE_NORMAL
);
@@ -1545,7 +1548,7 @@ ThreadError NcpBase::GetPropertyHandler_MAC_15_4_LADDR(uint8_t header, spinel_pr
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_EUI64_S,
otGetExtendedAddress()
otGetExtendedAddress(mInstance)
);
}
@@ -1556,7 +1559,7 @@ ThreadError NcpBase::GetPropertyHandler_MAC_15_4_SADDR(uint8_t header, spinel_pr
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_UINT16_S,
otGetShortAddress()
otGetShortAddress(mInstance)
);
}
@@ -1567,7 +1570,7 @@ ThreadError NcpBase::GetPropertyHandler_NET_IF_UP(uint8_t header, spinel_prop_ke
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_BOOL_S,
otIsInterfaceUp()
otIsInterfaceUp(mInstance)
);
}
@@ -1578,7 +1581,7 @@ ThreadError NcpBase::GetPropertyHandler_NET_STACK_UP(uint8_t header, spinel_prop
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_BOOL_S,
otGetDeviceRole() != kDeviceRoleDisabled
otGetDeviceRole(mInstance) != kDeviceRoleDisabled
);
}
@@ -1586,7 +1589,7 @@ ThreadError NcpBase::GetPropertyHandler_NET_ROLE(uint8_t header, spinel_prop_key
{
spinel_net_role_t role(SPINEL_NET_ROLE_DETACHED);
switch (otGetDeviceRole())
switch (otGetDeviceRole(mInstance))
{
case kDeviceRoleDisabled:
case kDeviceRoleDetached:
@@ -1622,7 +1625,7 @@ ThreadError NcpBase::GetPropertyHandler_NET_NETWORK_NAME(uint8_t header, spinel_
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_UTF8_S,
otGetNetworkName()
otGetNetworkName(mInstance)
);
}
@@ -1633,7 +1636,7 @@ ThreadError NcpBase::GetPropertyHandler_NET_XPANID(uint8_t header, spinel_prop_k
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_DATA_S,
otGetExtendedPanId(),
otGetExtendedPanId(mInstance),
sizeof(spinel_net_xpanid_t)
);
}
@@ -1643,7 +1646,7 @@ ThreadError NcpBase::GetPropertyHandler_NET_MASTER_KEY(uint8_t header, spinel_pr
const uint8_t *ptr(NULL);
uint8_t len(0);
ptr = otGetMasterKey(&len);
ptr = otGetMasterKey(mInstance, &len);
return SendPropertyUpdate(
header,
@@ -1662,7 +1665,7 @@ ThreadError NcpBase::GetPropertyHandler_NET_KEY_SEQUENCE(uint8_t header, spinel_
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_UINT32_S,
otGetKeySequenceCounter()
otGetKeySequenceCounter(mInstance)
);
}
@@ -1673,7 +1676,7 @@ ThreadError NcpBase::GetPropertyHandler_NET_PARTITION_ID(uint8_t header, spinel_
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_UINT32_S,
otGetPartitionId()
otGetPartitionId(mInstance)
);
}
@@ -1684,7 +1687,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_NETWORK_DATA_VERSION(uint8_t head
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_UINT8_S,
otGetNetworkDataVersion()
otGetNetworkDataVersion(mInstance)
);
}
@@ -1695,7 +1698,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_STABLE_NETWORK_DATA_VERSION(uint8
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_UINT8_S,
otGetStableNetworkDataVersion()
otGetStableNetworkDataVersion(mInstance)
);
}
@@ -1708,6 +1711,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_NETWORK_DATA(uint8_t header, spin
SuccessOrExit(errorCode = OutboundFrameBegin());
SuccessOrExit(errorCode = OutboundFrameFeedPacked("Cii", header, SPINEL_CMD_PROP_VALUE_IS, key));
otGetNetworkDataLocal(
mInstance,
false, // Stable?
network_data,
&network_data_len
@@ -1730,6 +1734,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_STABLE_NETWORK_DATA(uint8_t heade
SuccessOrExit(errorCode = OutboundFrameFeedPacked("Cii", header, SPINEL_CMD_PROP_VALUE_IS, key));
otGetNetworkDataLocal(
mInstance,
true, // Stable?
network_data,
&network_data_len
@@ -1749,7 +1754,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_LEADER_RID(uint8_t header, spinel
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_UINT8_S,
otGetLeaderRouterId()
otGetLeaderRouterId(mInstance)
);
}
@@ -1760,7 +1765,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_LOCAL_LEADER_WEIGHT(uint8_t heade
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_UINT8_S,
otGetLocalLeaderWeight()
otGetLocalLeaderWeight(mInstance)
);
}
@@ -1771,7 +1776,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_LEADER_WEIGHT(uint8_t header, spi
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_UINT8_S,
otGetLeaderWeight()
otGetLeaderWeight(mInstance)
);
}
@@ -1780,7 +1785,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_LEADER_ADDR(uint8_t header, spine
ThreadError errorCode = kThreadError_None;
otIp6Address address;
errorCode = otGetLeaderRloc(&address);
errorCode = otGetLeaderRloc(mInstance, &address);
if (errorCode == kThreadError_None)
{
@@ -1822,7 +1827,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_CHILD_TABLE(uint8_t header, spine
index = 0;
while (otGetChildInfoByIndex(index, &childInfo) == kThreadError_None)
while (otGetChildInfoByIndex(mInstance, index, &childInfo) == kThreadError_None)
{
if (childInfo.mTimeout > 0)
{
@@ -1884,7 +1889,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_ASSISTING_PORTS(uint8_t header, s
{
ThreadError errorCode = kThreadError_None;
uint8_t num_entries = 0;
const uint16_t *ports = otGetUnsecurePorts(&num_entries);
const uint16_t *ports = otGetUnsecurePorts(mInstance, &num_entries);
SuccessOrExit(errorCode = OutboundFrameBegin());
@@ -1919,7 +1924,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_ROUTER_ROLE_ENABLED(uint8_t heade
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_BOOL_S,
otIsRouterRoleEnabled()
otIsRouterRoleEnabled(mInstance)
);
}
@@ -1936,7 +1941,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_ON_MESH_NETS(uint8_t header, spin
// Fill from non-local network data first
for (otNetworkDataIterator iter = OT_NETWORK_DATA_ITERATOR_INIT ;;)
{
errorCode = otGetNextOnMeshPrefix(false, &iter, &border_router_config);
errorCode = otGetNextOnMeshPrefix(mInstance, false, &iter, &border_router_config);
if (errorCode != kThreadError_None)
{
@@ -1964,7 +1969,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_ON_MESH_NETS(uint8_t header, spin
// Fill from local network data last
for (otNetworkDataIterator iter = OT_NETWORK_DATA_ITERATOR_INIT ;;)
{
errorCode = otGetNextOnMeshPrefix(true, &iter, &border_router_config);
errorCode = otGetNextOnMeshPrefix(mInstance, true, &iter, &border_router_config);
if (errorCode != kThreadError_None)
{
@@ -1999,7 +2004,7 @@ exit:
ThreadError NcpBase::GetPropertyHandler_IPV6_ML_PREFIX(uint8_t header, spinel_prop_key_t key)
{
ThreadError errorCode = kThreadError_None;
const uint8_t *ml_prefix = otGetMeshLocalPrefix();
const uint8_t *ml_prefix = otGetMeshLocalPrefix(mInstance);
if (ml_prefix)
{
@@ -2035,7 +2040,7 @@ ThreadError NcpBase::GetPropertyHandler_IPV6_ML_PREFIX(uint8_t header, spinel_pr
ThreadError NcpBase::GetPropertyHandler_IPV6_ML_ADDR(uint8_t header, spinel_prop_key_t key)
{
ThreadError errorCode = kThreadError_None;
const otIp6Address *ml64 = otGetMeshLocalEid();
const otIp6Address *ml64 = otGetMeshLocalEid(mInstance);
if (ml64)
{
@@ -2077,7 +2082,7 @@ ThreadError NcpBase::GetPropertyHandler_IPV6_ADDRESS_TABLE(uint8_t header, spine
SuccessOrExit(errorCode = OutboundFrameFeedPacked("Cii", header, SPINEL_CMD_PROP_VALUE_IS, key));
for (const otNetifAddress *address = otGetUnicastAddresses(); address; address = address->mNext)
for (const otNetifAddress *address = otGetUnicastAddresses(mInstance); address; address = address->mNext)
{
SuccessOrExit(errorCode = OutboundFrameFeedPacked(
@@ -2110,7 +2115,7 @@ ThreadError NcpBase::GetPropertyHandler_IPV6_ICMP_PING_OFFLOAD(uint8_t header, s
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_BOOL_S,
otIsIcmpEchoEnabled()
otIsIcmpEchoEnabled(mInstance)
);
}
@@ -2122,7 +2127,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_RLOC16_DEBUG_PASSTHRU(uint8_t hea
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_BOOL_S,
!otIsReceiveIp6DatagramFilterEnabled()
!otIsReceiveIp6DatagramFilterEnabled(mInstance)
);
}
@@ -2148,7 +2153,7 @@ ThreadError NcpBase::GetPropertyHandler_MAC_CNTR(uint8_t header, spinel_prop_key
const otMacCounters *macCounters;
ThreadError errorCode = kThreadError_None;
macCounters = otGetMacCounters();
macCounters = otGetMacCounters(mInstance);
assert(macCounters != NULL);
@@ -2344,7 +2349,7 @@ ThreadError NcpBase::GetPropertyHandler_MAC_WHITELIST(uint8_t header, spinel_pro
for (uint8_t i = 0; (i != 255) && (errorCode == kThreadError_None); i++)
{
errorCode = otGetMacWhitelistEntry(i, &entry);
errorCode = otGetMacWhitelistEntry(mInstance, i, &entry);
if (errorCode != kThreadError_None)
{
@@ -2375,14 +2380,14 @@ ThreadError NcpBase::GetPropertyHandler_MAC_WHITELIST_ENABLED(uint8_t header, sp
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_BOOL_S,
otIsMacWhitelistEnabled()
otIsMacWhitelistEnabled(mInstance)
);
}
ThreadError NcpBase::GetPropertyHandler_THREAD_MODE(uint8_t header, spinel_prop_key_t key)
{
uint8_t numeric_mode(0);
otLinkModeConfig mode_config(otGetLinkMode());
otLinkModeConfig mode_config(otGetLinkMode(mInstance));
if (mode_config.mRxOnWhenIdle)
{
@@ -2420,7 +2425,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_CHILD_TIMEOUT(uint8_t header, spi
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_UINT32_S,
otGetChildTimeout()
otGetChildTimeout(mInstance)
);
}
@@ -2431,7 +2436,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_RLOC16(uint8_t header, spinel_pro
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_UINT16_S,
otGetRloc16()
otGetRloc16(mInstance)
);
}
@@ -2442,7 +2447,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_ROUTER_UPGRADE_THRESHOLD(uint8_t
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_UINT8_S,
otGetRouterUpgradeThreshold()
otGetRouterUpgradeThreshold(mInstance)
);
}
@@ -2453,7 +2458,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_CONTEXT_REUSE_DELAY(uint8_t heade
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_UINT32_S,
otGetContextIdReuseDelay()
otGetContextIdReuseDelay(mInstance)
);
}
@@ -2464,7 +2469,7 @@ ThreadError NcpBase::GetPropertyHandler_THREAD_NETWORK_ID_TIMEOUT(uint8_t header
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_UINT8_S,
otGetNetworkIdTimeout()
otGetNetworkIdTimeout(mInstance)
);
}
@@ -2513,11 +2518,11 @@ ThreadError NcpBase::SetPropertyHandler_PHY_ENABLED(uint8_t header, spinel_prop_
{
if (value == false)
{
errorCode = otPlatRadioDisable();
errorCode = otPlatRadioDisable(mInstance);
}
else
{
errorCode = otPlatRadioEnable();
errorCode = otPlatRadioEnable(mInstance);
}
}
else
@@ -2564,7 +2569,7 @@ ThreadError NcpBase::SetPropertyHandler_PHY_CHAN(uint8_t header, spinel_prop_key
if (parsedLength > 0)
{
errorCode = otSetChannel(static_cast<uint8_t>(i));
errorCode = otSetChannel(mInstance, static_cast<uint8_t>(i));
if (errorCode == kThreadError_None)
{
@@ -2602,13 +2607,13 @@ ThreadError NcpBase::SetPropertyHandler_MAC_FILTER_MODE(uint8_t header, spinel_p
switch (i)
{
case SPINEL_MAC_FILTER_MODE_NORMAL:
otPlatRadioSetPromiscuous(false);
otPlatRadioSetPromiscuous(mInstance, false);
errorCode = kThreadError_None;
break;
case SPINEL_MAC_FILTER_MODE_PROMISCUOUS:
case SPINEL_MAC_FILTER_MODE_MONITOR:
otPlatRadioSetPromiscuous(true);
otPlatRadioSetPromiscuous(mInstance, true);
errorCode = kThreadError_None;
break;
}
@@ -2740,6 +2745,7 @@ ThreadError NcpBase::SetPropertyHandler_MAC_SCAN_STATE(uint8_t header, spinel_pr
case SPINEL_SCAN_STATE_BEACON:
errorCode = otActiveScan(
mInstance,
mChannelMask,
mScanPeriod,
&HandleActiveScanResult_Jump,
@@ -2755,6 +2761,7 @@ ThreadError NcpBase::SetPropertyHandler_MAC_SCAN_STATE(uint8_t header, spinel_pr
case SPINEL_SCAN_STATE_ENERGY:
errorCode = otEnergyScan(
mInstance,
mChannelMask,
mScanPeriod,
&HandleEnergyScanResult_Jump,
@@ -2806,7 +2813,7 @@ ThreadError NcpBase::SetPropertyHandler_MAC_15_4_PANID(uint8_t header, spinel_pr
if (parsedLength > 0)
{
errorCode = otSetPanId(tmp);
errorCode = otSetPanId(mInstance, tmp);
if (errorCode == kThreadError_None)
{
@@ -2843,11 +2850,11 @@ ThreadError NcpBase::SetPropertyHandler_NET_IF_UP(uint8_t header, spinel_prop_ke
{
if (value == false)
{
errorCode = otInterfaceDown();
errorCode = otInterfaceDown(mInstance);
}
else
{
errorCode = otInterfaceUp();
errorCode = otInterfaceUp(mInstance);
}
}
else
@@ -2884,15 +2891,15 @@ ThreadError NcpBase::SetPropertyHandler_NET_STACK_UP(uint8_t header, spinel_prop
if (parsedLength > 0)
{
// If the value has changed...
if ((value != false) != (otGetDeviceRole() != kDeviceRoleDisabled))
if ((value != false) != (otGetDeviceRole(mInstance) != kDeviceRoleDisabled))
{
if (value != false)
{
errorCode = otThreadStart();
errorCode = otThreadStart(mInstance);
}
else
{
errorCode = otThreadStop();
errorCode = otThreadStop(mInstance);
}
}
}
@@ -2936,15 +2943,15 @@ ThreadError NcpBase::SetPropertyHandler_NET_ROLE(uint8_t header, spinel_prop_key
break;
case SPINEL_NET_ROLE_ROUTER:
errorCode = otBecomeRouter();
errorCode = otBecomeRouter(mInstance);
break;
case SPINEL_NET_ROLE_LEADER:
errorCode = otBecomeLeader();
errorCode = otBecomeLeader(mInstance);
break;
case SPINEL_NET_ROLE_CHILD:
errorCode = otBecomeChild(kMleAttachAnyPartition);
errorCode = otBecomeChild(mInstance, kMleAttachAnyPartition);
break;
}
@@ -2982,7 +2989,7 @@ ThreadError NcpBase::SetPropertyHandler_NET_NETWORK_NAME(uint8_t header, spinel_
if ((parsedLength > 0) && (string != NULL))
{
errorCode = otSetNetworkName(string);
errorCode = otSetNetworkName(mInstance, string);
if (errorCode == kThreadError_None)
{
@@ -3019,7 +3026,7 @@ ThreadError NcpBase::SetPropertyHandler_NET_XPANID(uint8_t header, spinel_prop_k
if ((parsedLength > 0) && (len == sizeof(spinel_net_xpanid_t)))
{
otSetExtendedPanId(ptr);
otSetExtendedPanId(mInstance, ptr);
errorCode = HandleCommandPropertyGet(header, key);
}
else
@@ -3048,7 +3055,7 @@ ThreadError NcpBase::SetPropertyHandler_NET_MASTER_KEY(uint8_t header, spinel_pr
if ((parsedLength > 0) && (len < 100))
{
errorCode = otSetMasterKey(ptr, static_cast<uint8_t>(len));
errorCode = otSetMasterKey(mInstance, ptr, static_cast<uint8_t>(len));
if (errorCode == kThreadError_None)
{
@@ -3084,7 +3091,7 @@ ThreadError NcpBase::SetPropertyHandler_NET_KEY_SEQUENCE(uint8_t header, spinel_
if (parsedLength > 0)
{
otSetKeySequenceCounter(i);
otSetKeySequenceCounter(mInstance, i);
errorCode = HandleCommandPropertyGet(header, key);
}
else
@@ -3111,7 +3118,7 @@ ThreadError NcpBase::SetPropertyHandler_THREAD_LOCAL_LEADER_WEIGHT(uint8_t heade
if (parsedLength > 0)
{
otSetLocalLeaderWeight(value);
otSetLocalLeaderWeight(mInstance, value);
}
else
{
@@ -3173,7 +3180,7 @@ ThreadError NcpBase::SetPropertyHandler_STREAM_NET_INSECURE(uint8_t header, spin
if (errorCode == kThreadError_None)
{
errorCode = otSendIp6Datagram(message);
errorCode = otSendIp6Datagram(mInstance, message);
}
else if (message)
{
@@ -3244,7 +3251,7 @@ ThreadError NcpBase::SetPropertyHandler_STREAM_NET(uint8_t header, spinel_prop_k
if (errorCode == kThreadError_None)
{
errorCode = otSendIp6Datagram(message);
errorCode = otSendIp6Datagram(mInstance, message);
}
else if (message)
{
@@ -3282,7 +3289,7 @@ ThreadError NcpBase::SetPropertyHandler_IPV6_ML_PREFIX(uint8_t header, spinel_pr
if (value_len >= 8)
{
errorCode = otSetMeshLocalPrefix(value_ptr);
errorCode = otSetMeshLocalPrefix(mInstance, value_ptr);
HandleCommandPropertyGet(header, key);
}
else
@@ -3317,7 +3324,7 @@ ThreadError NcpBase::SetPropertyHandler_IPV6_ICMP_PING_OFFLOAD(uint8_t header, s
if (parsedLength > 0)
{
otSetIcmpEchoEnabled(isEnabled);
otSetIcmpEchoEnabled(mInstance, isEnabled);
errorCode = HandleCommandPropertyGet(header, key);
}
@@ -3345,7 +3352,7 @@ ThreadError NcpBase::SetPropertyHandler_THREAD_RLOC16_DEBUG_PASSTHRU(uint8_t hea
if (parsedLength > 0)
{
// Note reverse logic: passthru enabled = filter disabled
otSetReceiveIp6DatagramFilterEnabled(!isEnabled);
otSetReceiveIp6DatagramFilterEnabled(mInstance, !isEnabled);
errorCode = HandleCommandPropertyGet(header, key);
}
@@ -3362,14 +3369,14 @@ ThreadError NcpBase::SetPropertyHandler_THREAD_ASSISTING_PORTS(uint8_t header, s
{
ThreadError errorCode = kThreadError_None;
uint8_t num_entries = 0;
const uint16_t *ports = otGetUnsecurePorts(&num_entries);
const uint16_t *ports = otGetUnsecurePorts(mInstance, &num_entries);
spinel_ssize_t parsedLength = 1;
int ports_changed = 0;
// First, we need to remove all of the current assisting ports.
for (; num_entries != 0; ports++, num_entries--)
{
errorCode = otRemoveUnsecurePort(*ports);
errorCode = otRemoveUnsecurePort(mInstance, *ports);
if (errorCode != kThreadError_None)
{
@@ -3395,7 +3402,7 @@ ThreadError NcpBase::SetPropertyHandler_THREAD_ASSISTING_PORTS(uint8_t header, s
if (parsedLength > 0)
{
errorCode = otAddUnsecurePort(port);
errorCode = otAddUnsecurePort(mInstance, port);
}
else
{
@@ -3472,7 +3479,7 @@ ThreadError NcpBase::SetPropertyHandler_THREAD_ALLOW_LOCAL_NET_DATA_CHANGE(uint8
if (should_register_with_leader)
{
otSendServerData();
otSendServerData(mInstance);
}
return errorCode;
@@ -3494,7 +3501,7 @@ ThreadError NcpBase::SetPropertyHandler_THREAD_ROUTER_ROLE_ENABLED(uint8_t heade
if (parsedLength > 0)
{
otSetRouterRoleEnabled(isEnabled);
otSetRouterRoleEnabled(mInstance, isEnabled);
errorCode = HandleCommandPropertyGet(header, key);
}
@@ -3551,7 +3558,7 @@ ThreadError NcpBase::SetPropertyHandler_MAC_WHITELIST(uint8_t header, spinel_pro
spinel_ssize_t parsedLength = 1;
// First, clear the whitelist.
otClearMacWhitelist();
otClearMacWhitelist(mInstance);
while ((errorCode == kThreadError_None)
&& (parsedLength > 0)
@@ -3588,11 +3595,11 @@ ThreadError NcpBase::SetPropertyHandler_MAC_WHITELIST(uint8_t header, spinel_pro
if (rssi == RSSI_OVERRIDE_DISABLED)
{
errorCode = otAddMacWhitelist(ext_addr->m8);
errorCode = otAddMacWhitelist(mInstance, ext_addr->m8);
}
else
{
errorCode = otAddMacWhitelistRssi(ext_addr->m8, rssi);
errorCode = otAddMacWhitelistRssi(mInstance, ext_addr->m8, rssi);
}
value_ptr += parsedLength;
@@ -3634,11 +3641,11 @@ ThreadError NcpBase::SetPropertyHandler_MAC_WHITELIST_ENABLED(uint8_t header, sp
{
if (isEnabled)
{
otEnableMacWhitelist();
otEnableMacWhitelist(mInstance);
}
else
{
otDisableMacWhitelist();
otDisableMacWhitelist(mInstance);
}
errorCode = HandleCommandPropertyGet(header, key);
@@ -3672,7 +3679,7 @@ ThreadError NcpBase::SetPropertyHandler_THREAD_MODE(uint8_t header, spinel_prop_
mode_config.mDeviceType = ((numeric_mode & kThreadMode_FullFunctionDevice) == kThreadMode_FullFunctionDevice);
mode_config.mNetworkData = ((numeric_mode & kThreadMode_FullNetworkData) == kThreadMode_FullNetworkData);
errorCode = otSetLinkMode(mode_config);
errorCode = otSetLinkMode(mInstance, mode_config);
if (errorCode == kThreadError_None)
{
@@ -3706,7 +3713,7 @@ ThreadError NcpBase::SetPropertyHandler_THREAD_CHILD_TIMEOUT(uint8_t header, spi
if (parsedLength > 0)
{
otSetChildTimeout(i);
otSetChildTimeout(mInstance, i);
errorCode = HandleCommandPropertyGet(header, key);
}
@@ -3733,7 +3740,7 @@ ThreadError NcpBase::SetPropertyHandler_THREAD_ROUTER_UPGRADE_THRESHOLD(uint8_t
if (parsedLength > 0)
{
otSetRouterUpgradeThreshold(i);
otSetRouterUpgradeThreshold(mInstance, i);
errorCode = HandleCommandPropertyGet(header, key);
}
@@ -3760,7 +3767,7 @@ ThreadError NcpBase::SetPropertyHandler_THREAD_CONTEXT_REUSE_DELAY(uint8_t heade
if (parsedLength > 0)
{
otSetContextIdReuseDelay(i);
otSetContextIdReuseDelay(mInstance, i);
errorCode = HandleCommandPropertyGet(header, key);
}
@@ -3787,7 +3794,7 @@ ThreadError NcpBase::SetPropertyHandler_THREAD_NETWORK_ID_TIMEOUT(uint8_t header
if (parsedLength > 0)
{
otSetNetworkIdTimeout(i);
otSetNetworkIdTimeout(mInstance, i);
errorCode = HandleCommandPropertyGet(header, key);
}
@@ -3870,7 +3877,7 @@ ThreadError NcpBase::InsertPropertyHandler_IPV6_ADDRESS_TABLE(uint8_t header, sp
netif_addr.mPreferredLifetime = preferred_lifetime;
netif_addr.mValidLifetime = valid_lifetime;
errorCode = otAddUnicastAddress(&netif_addr);
errorCode = otAddUnicastAddress(mInstance, &netif_addr);
VerifyOrExit(errorCode == kThreadError_None,
errorStatus = ThreadErrorToSpinelStatus(errorCode));
@@ -3931,7 +3938,7 @@ ThreadError NcpBase::InsertPropertyHandler_THREAD_LOCAL_ROUTES(uint8_t header, s
ext_route_config.mPrefix.mPrefix = *addr_ptr;
ext_route_config.mStable = stable;
ext_route_config.mPreference = ((flags & kPreferenceMask) >> kPreferenceOffset);
errorCode = otAddExternalRoute(&ext_route_config);
errorCode = otAddExternalRoute(mInstance, &ext_route_config);
if (errorCode == kThreadError_None)
{
@@ -4006,7 +4013,7 @@ ThreadError NcpBase::InsertPropertyHandler_THREAD_ON_MESH_NETS(uint8_t header, s
border_router_config.mDefaultRoute = ((flags & kDefaultRouteFlag) == kDefaultRouteFlag);
border_router_config.mOnMesh = ((flags & kOnMeshFlag) == kOnMeshFlag);
errorCode = otAddBorderRouter(&border_router_config);
errorCode = otAddBorderRouter(mInstance, &border_router_config);
if (errorCode == kThreadError_None)
{
@@ -4048,7 +4055,7 @@ ThreadError NcpBase::InsertPropertyHandler_THREAD_ASSISTING_PORTS(uint8_t header
if (parsedLength > 0)
{
errorCode = otAddUnsecurePort(port);
errorCode = otAddUnsecurePort(mInstance, port);
if (errorCode == kThreadError_None)
{
@@ -4105,11 +4112,11 @@ ThreadError NcpBase::InsertPropertyHandler_MAC_WHITELIST(uint8_t header, spinel_
{
if (rssi == RSSI_OVERRIDE_DISABLED)
{
errorCode = otAddMacWhitelist(ext_addr->m8);
errorCode = otAddMacWhitelist(mInstance, ext_addr->m8);
}
else
{
errorCode = otAddMacWhitelistRssi(ext_addr->m8, rssi);
errorCode = otAddMacWhitelistRssi(mInstance, ext_addr->m8, rssi);
}
if (errorCode == kThreadError_None)
@@ -4159,7 +4166,7 @@ ThreadError NcpBase::RemovePropertyHandler_IPV6_ADDRESS_TABLE(uint8_t header, sp
if (parsedLength > 0)
{
errorCode = otRemoveUnicastAddress(addr_ptr);
errorCode = otRemoveUnicastAddress(mInstance, addr_ptr);
if (errorCode == kThreadError_None)
{
@@ -4210,7 +4217,7 @@ ThreadError NcpBase::RemovePropertyHandler_THREAD_LOCAL_ROUTES(uint8_t header, s
if (parsedLength > 0)
{
ip6_prefix.mPrefix = *addr_ptr;
errorCode = otRemoveExternalRoute(&ip6_prefix);
errorCode = otRemoveExternalRoute(mInstance, &ip6_prefix);
if (errorCode == kThreadError_None)
{
@@ -4262,7 +4269,7 @@ ThreadError NcpBase::RemovePropertyHandler_THREAD_ON_MESH_NETS(uint8_t header, s
if (parsedLength > 0)
{
ip6_prefix.mPrefix = *addr_ptr;
errorCode = otRemoveBorderRouter(&ip6_prefix);
errorCode = otRemoveBorderRouter(mInstance, &ip6_prefix);
if (errorCode == kThreadError_None)
{
@@ -4304,7 +4311,7 @@ ThreadError NcpBase::RemovePropertyHandler_THREAD_ASSISTING_PORTS(uint8_t header
if (parsedLength > 0)
{
errorCode = otRemoveUnsecurePort(port);
errorCode = otRemoveUnsecurePort(mInstance, port);
if (errorCode == kThreadError_None)
{
@@ -4345,7 +4352,7 @@ ThreadError NcpBase::RemovePropertyHandler_THREAD_ACTIVE_ROUTER_IDS(uint8_t head
if (parsedLength > 0)
{
errorCode = otReleaseRouterId(router_id);
errorCode = otReleaseRouterId(mInstance, router_id);
if (errorCode == kThreadError_None)
{
@@ -4385,7 +4392,7 @@ ThreadError NcpBase::RemovePropertyHandler_MAC_WHITELIST(uint8_t header, spinel_
if (parsedLength > 0)
{
otRemoveMacWhitelist(ext_addr.m8);
otRemoveMacWhitelist(mInstance, ext_addr.m8);
errorCode = SendPropertyUpdate(
header,
+9 -2
View File
@@ -45,12 +45,19 @@ namespace Thread {
class NcpBase
{
public:
/**
* This constructor creates and initializes an NcpBase instance.
*
* @param[in] aInstance The OpenThread instance structure.
*
*/
NcpBase(void);
NcpBase(otInstance *aInstance);
protected:
// The pointer to the OpenThread instance
otInstance* mInstance;
protected:
+8 -8
View File
@@ -50,9 +50,9 @@ static NcpSpi *sNcpSpi;
extern Ip6::Ip6 *sIp6;
extern "C" void otNcpInit(void)
extern "C" void otNcpInit(otInstance *aInstance)
{
sNcpSpi = new(&sNcpRaw) NcpSpi;
sNcpSpi = new(&sNcpRaw) NcpSpi(aInstance);
}
static void spi_header_set_flag_byte(uint8_t *header, uint8_t value)
@@ -87,11 +87,11 @@ static uint16_t spi_header_get_data_len(const uint8_t *header)
return ( header[3] + static_cast<uint16_t>(header[4] << 8) );
}
NcpSpi::NcpSpi():
NcpBase(),
mHandleRxFrameTask(sIp6->mTaskletScheduler, &HandleRxFrame, this),
mPrepareTxFrameTask(sIp6->mTaskletScheduler, &PrepareTxFrame, this),
mTxFrameBuffer(mTxBuffer, sizeof(mTxBuffer))
NcpSpi::NcpSpi(otInstance *aInstance):
NcpBase(aInstance),
mHandleRxFrame(sIp6->mTaskletScheduler, &NcpSpi::HandleRxFrame, this),
mHandleSendDone(sIp6->mTaskletScheduler, &NcpSpi::PrepareTxFrame, this),
mTxFrameBuffer(aInstance, mTxBuffer, sizeof(mTxBuffer))
{
memset(mEmptySendFrame, 0, kSpiHeaderLength);
memset(mSendFrame, 0, kSpiHeaderLength);
@@ -105,7 +105,7 @@ NcpSpi::NcpSpi():
spi_header_set_flag_byte(mSendFrame, SPI_RESET_FLAG|SPI_PATTERN_VALUE);
spi_header_set_flag_byte(mEmptySendFrame, SPI_RESET_FLAG|SPI_PATTERN_VALUE);
spi_header_set_accept_len(mSendFrame, sizeof(mReceiveFrame) - kSpiHeaderLength);
otPlatSpiSlaveEnable(&SpiTransactionComplete, (void*)this);
otPlatSpiSlaveEnable(&NcpSpi::SpiTransactionComplete, (void*)this);
// We signal an interrupt on this first transaction to
// make sure that the host processor knows that our
+7 -1
View File
@@ -43,7 +43,13 @@ class NcpSpi : public NcpBase
typedef NcpBase super_t;
public:
NcpSpi();
/**
* Constructor
*
* @param[in] aInstance The OpenThread instance structure.
*
*/
NcpSpi(otInstance *aInstance);
virtual ThreadError OutboundFrameBegin(void);
virtual ThreadError OutboundFrameFeedData(const uint8_t *frame, uint16_t frameLength);
+5 -5
View File
@@ -47,9 +47,9 @@ static NcpUart *sNcpUart;
extern Ip6::Ip6 *sIp6;
extern "C" void otNcpInit(void)
extern "C" void otNcpInit(otInstance *aInstance)
{
sNcpUart = new(&sNcpRaw) NcpUart;
sNcpUart = new(&sNcpRaw) NcpUart(aInstance);
}
NcpUart::UartTxBuffer::UartTxBuffer(void)
@@ -79,9 +79,9 @@ const uint8_t *NcpUart::UartTxBuffer::GetBuffer(void) const
return mBuffer;
}
NcpUart::NcpUart():
NcpBase(),
mFrameDecoder(mRxBuffer, sizeof(mRxBuffer), &HandleFrame, &HandleError, this),
NcpUart::NcpUart(otInstance *aInstance):
NcpBase(aInstance),
mFrameDecoder(mRxBuffer, sizeof(mRxBuffer), &NcpUart::HandleFrame, &NcpUart::HandleError, this),
mUartBuffer(),
mTxFrameBuffer(mTxBuffer, sizeof(mTxBuffer)),
mUartSendTask(sIp6->mTaskletScheduler, EncodeAndSendToUart, this)
+7 -1
View File
@@ -45,7 +45,13 @@ class NcpUart : public NcpBase
typedef NcpBase super_t;
public:
NcpUart();
/**
* Constructor
*
* @param[in] aInstance The OpenThread instance structure.
*
*/
NcpUart(otInstance *aInstance);
/**
* This method is called to start a new outbound frame.
+1 -1
View File
@@ -35,7 +35,7 @@
static Thread::Crypto::MbedTls mbedtls;
extern"C" void otSignalTaskletPending(void)
extern"C" void otSignalTaskletPending(otInstance *)
{
}
+6 -6
View File
@@ -32,11 +32,11 @@
#include <platform/platform.h>
#include <platform/radio.h>
extern "C" void otSignalTaskletPending(void)
extern "C" void otSignalTaskletPending(otInstance *)
{
}
extern "C" bool otAreTaskletsPending(void)
extern "C" bool otAreTaskletsPending(otInstance *)
{
return false;
}
@@ -51,17 +51,17 @@ extern "C" void otPlatUartReceived(const uint8_t *aBuf, uint16_t aBufLength)
(void)aBufLength;
}
extern "C" void otPlatAlarmFired()
extern "C" void otPlatAlarmFired(otInstance *)
{
}
extern "C" void otPlatRadioTransmitDone(bool aRxPending, ThreadError aError)
extern "C" void otPlatRadioTransmitDone(otInstance *, bool aRxPending, ThreadError aError)
{
(void)aRxPending;
(void)aError;
}
extern "C" void otPlatRadioReceiveDone(RadioPacket *aFrame, ThreadError aError)
extern "C" void otPlatRadioReceiveDone(otInstance *, RadioPacket *aFrame, ThreadError aError)
{
(void)aFrame;
(void)aError;
@@ -147,7 +147,7 @@ void TestDiag()
PlatformInit(argc, argv);
// initialize diagnostics module
diagInit();
diagInit(NULL);
// test diagnostics commands
VerifyOrQuit(!isDiagEnabled(), "diagnostics mode shoud be disabled as default\n");
+1 -1
View File
@@ -36,7 +36,7 @@
static Thread::Crypto::MbedTls mbedtls;
extern"C" void otSignalTaskletPending(void)
extern"C" void otSignalTaskletPending(otInstance *)
{
}
+1 -1
View File
@@ -34,7 +34,7 @@
namespace Thread {
extern"C" void otSignalTaskletPending(void)
extern"C" void otSignalTaskletPending(otInstance *)
{
}
+5 -5
View File
@@ -40,11 +40,11 @@ using namespace Thread;
namespace Thread {
extern "C" void otSignalTaskletPending(void)
extern "C" void otSignalTaskletPending(otInstance *)
{
}
extern "C" bool otAreTaskletsPending(void)
extern "C" bool otAreTaskletsPending(otInstance *)
{
return false;
}
@@ -59,17 +59,17 @@ extern "C" void otPlatUartReceived(const uint8_t *aBuf, uint16_t aBufLength)
(void)aBufLength;
}
extern "C" void otPlatDiagAlarmFired()
extern "C" void otPlatDiagAlarmFired(otInstance *)
{
}
extern "C" void otPlatDiagRadioTransmitDone(bool aRxPending, ThreadError aError)
extern "C" void otPlatDiagRadioTransmitDone(otInstance *, bool aRxPending, ThreadError aError)
{
(void)aRxPending;
(void)aError;
}
extern "C" void otPlatDiagRadioReceiveDone(RadioPacket *aFrame, ThreadError aError)
extern "C" void otPlatDiagRadioReceiveDone(otInstance *, RadioPacket *aFrame, ThreadError aError)
{
(void)aFrame;
(void)aError;
+1 -1
View File
@@ -34,7 +34,7 @@
namespace Thread {
extern"C" void otSignalTaskletPending(void)
extern"C" void otSignalTaskletPending(otInstance *)
{
}
+2 -2
View File
@@ -32,11 +32,11 @@
#include <common/message.hpp>
#include <string.h>
extern"C" void otSignalTaskletPending(void)
extern"C" void otSignalTaskletPending(otInstance *)
{
}
extern "C" void otPlatDiagAlarmFired(void)
extern "C" void otPlatDiagAlarmFired(otInstance *)
{
}
+2 -2
View File
@@ -36,11 +36,11 @@ namespace Thread {
// This module implements unit-test for NcpFrameBuffer class.
extern"C" void otSignalTaskletPending(void)
extern"C" void otSignalTaskletPending(otInstance *)
{
}
extern "C" void otPlatDiagAlarmFired()
extern "C" void otPlatDiagAlarmFired(otInstance *)
{
}
+8 -8
View File
@@ -51,13 +51,13 @@ static uint32_t sCallCount[kCallCountIndexMax];
extern "C" {
void otPlatAlarmStop(void)
void otPlatAlarmStop(otInstance *)
{
sTimerOn = false;
sCallCount[kCallCountIndexAlarmStop]++;
}
void otPlatAlarmStartAt(uint32_t aT0, uint32_t aDt)
void otPlatAlarmStartAt(otInstance *, uint32_t aT0, uint32_t aDt)
{
sTimerOn = true;
sCallCount[kCallCountIndexAlarmStart]++;
@@ -112,7 +112,7 @@ int TestOneTimer(void)
sNow += kTimerInterval;
otPlatAlarmFired();
otPlatAlarmFired(NULL);
VerifyOrQuit(sCallCount[kCallCountIndexAlarmStart] == 1, "TestOneTimer: Start CallCount Failed.\n");
VerifyOrQuit(sCallCount[kCallCountIndexAlarmStop] == 1, "TestOneTimer: Stop CallCount Failed.\n");
@@ -136,7 +136,7 @@ int TestOneTimer(void)
sNow += kTimerInterval;
otPlatAlarmFired();
otPlatAlarmFired(NULL);
VerifyOrQuit(sCallCount[kCallCountIndexAlarmStart] == 1, "TestOneTimer: Start CallCount Failed.\n");
VerifyOrQuit(sCallCount[kCallCountIndexAlarmStop] == 1, "TestOneTimer: Stop CallCount Failed.\n");
@@ -160,7 +160,7 @@ int TestOneTimer(void)
sNow += kTimerInterval + 5;
otPlatAlarmFired();
otPlatAlarmFired(NULL);
VerifyOrQuit(sCallCount[kCallCountIndexAlarmStart] == 1, "TestOneTimer: Start CallCount Failed.\n");
VerifyOrQuit(sCallCount[kCallCountIndexAlarmStop] == 1, "TestOneTimer: Stop CallCount Failed.\n");
@@ -184,7 +184,7 @@ int TestOneTimer(void)
sNow += kTimerInterval - 2;
otPlatAlarmFired();
otPlatAlarmFired(NULL);
VerifyOrQuit(sCallCount[kCallCountIndexAlarmStart] == 2, "TestOneTimer: Start CallCount Failed.\n");
VerifyOrQuit(sCallCount[kCallCountIndexAlarmStop] == 0, "TestOneTimer: Stop CallCount Failed.\n");
@@ -194,7 +194,7 @@ int TestOneTimer(void)
sNow += kTimerInterval;
otPlatAlarmFired();
otPlatAlarmFired(NULL);
VerifyOrQuit(sCallCount[kCallCountIndexAlarmStart] == 2, "TestOneTimer: Start CallCount Failed.\n");
VerifyOrQuit(sCallCount[kCallCountIndexAlarmStop] == 1, "TestOneTimer: Stop CallCount Failed.\n");
@@ -376,7 +376,7 @@ int TestTenTimers(void)
// timer is ready to be triggered by examining the aDt arg passed into otPlatAlarmStartAt(). If
// that value is 0, then otPlatAlarmFired should be fired immediately. This loop calls otPlatAlarmFired()
// the requisite number of times based on the aDt argument.
otPlatAlarmFired();
otPlatAlarmFired(NULL);
}
while (sPlatDt == 0);
Executable → Regular
View File