mirror of
https://github.com/espressif/openthread.git
synced 2026-07-30 23:57:47 +00:00
Jam detection API cleanup.
This commit is contained in:
@@ -67,7 +67,6 @@ include_HEADERS = \
|
||||
openthread-diag.h \
|
||||
openthread-icmp6.h \
|
||||
openthread-ip6.h \
|
||||
openthread-jam-detection.h \
|
||||
openthread-types.h \
|
||||
$(NULL)
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ include $(abs_top_nlbuild_autotools_dir)/automake/pre.am
|
||||
openthread_headers = \
|
||||
coap.h \
|
||||
crypto.h \
|
||||
jam_detection.h \
|
||||
message.h \
|
||||
tasklet.h \
|
||||
udp.h \
|
||||
|
||||
@@ -35,12 +35,20 @@
|
||||
#ifndef OPENTHREAD_JAM_DETECTION_H_
|
||||
#define OPENTHREAD_JAM_DETECTION_H_
|
||||
|
||||
#include <openthread-types.h>
|
||||
#ifdef OPENTHREAD_CONFIG_FILE
|
||||
#include OPENTHREAD_CONFIG_FILE
|
||||
#else
|
||||
#include <openthread-config.h>
|
||||
#endif
|
||||
|
||||
#include "openthread-types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_ENABLE_JAM_DETECTION
|
||||
|
||||
/**
|
||||
* @addtogroup jam-det Jamming Detection
|
||||
*
|
||||
@@ -69,7 +77,7 @@ typedef void (*otJamDetectionCallback)(bool aJamState, void *aContext);
|
||||
* @retval kThreadErrorNone Successfully set the threshold.
|
||||
*
|
||||
*/
|
||||
ThreadError otSetJamDetectionRssiThreshold(otInstance *aInstance, int8_t aRssiThreshold);
|
||||
ThreadError otJamDetectionSetRssiThreshold(otInstance *aInstance, int8_t aRssiThreshold);
|
||||
|
||||
/**
|
||||
* Get the Jam Detection RSSI Threshold (in dBm).
|
||||
@@ -78,7 +86,7 @@ ThreadError otSetJamDetectionRssiThreshold(otInstance *aInstance, int8_t aRssiTh
|
||||
*
|
||||
* @returns The Jam Detection RSSI Threshold.
|
||||
*/
|
||||
int8_t otGetJamDetectionRssiThreshold(otInstance *aInstance);
|
||||
int8_t otJamDetectionGetRssiThreshold(otInstance *aInstance);
|
||||
|
||||
/**
|
||||
* Set the Jam Detection Detection Window (in seconds).
|
||||
@@ -90,7 +98,7 @@ int8_t otGetJamDetectionRssiThreshold(otInstance *aInstance);
|
||||
* @retval kThreadErrorInvalidArgs The given input parameter not within valid range (1-63)
|
||||
*
|
||||
*/
|
||||
ThreadError otSetJamDetectionWindow(otInstance *aInstance, uint8_t aWindow);
|
||||
ThreadError otJamDetectionSetWindow(otInstance *aInstance, uint8_t aWindow);
|
||||
|
||||
/**
|
||||
* Get the Jam Detection Detection Window (in seconds).
|
||||
@@ -99,7 +107,7 @@ ThreadError otSetJamDetectionWindow(otInstance *aInstance, uint8_t aWindow);
|
||||
*
|
||||
* @returns The Jam Detection Window.
|
||||
*/
|
||||
uint8_t otGetJamDetectionWindow(otInstance *aInstance);
|
||||
uint8_t otJamDetectionGetWindow(otInstance *aInstance);
|
||||
|
||||
/**
|
||||
* Set the Jam Detection Busy Period (in seconds).
|
||||
@@ -115,7 +123,7 @@ uint8_t otGetJamDetectionWindow(otInstance *aInstance);
|
||||
* @retval kThreadErrorInvalidArgs The given input is not within the valid range.
|
||||
*
|
||||
*/
|
||||
ThreadError otSetJamDetectionBusyPeriod(otInstance *aInstance, uint8_t aBusyPeriod);
|
||||
ThreadError otJamDetectionSetBusyPeriod(otInstance *aInstance, uint8_t aBusyPeriod);
|
||||
|
||||
/**
|
||||
* Get the Jam Detection Busy Period (in seconds)
|
||||
@@ -124,7 +132,7 @@ ThreadError otSetJamDetectionBusyPeriod(otInstance *aInstance, uint8_t aBusyPeri
|
||||
*
|
||||
* @returns The Jam Detection Busy Period
|
||||
*/
|
||||
uint8_t otGetJamDetectionBusyPeriod(otInstance *aInstance);
|
||||
uint8_t otJamDetectionGetBusyPeriod(otInstance *aInstance);
|
||||
|
||||
/**
|
||||
* Start the jamming detection.
|
||||
@@ -137,7 +145,7 @@ uint8_t otGetJamDetectionBusyPeriod(otInstance *aInstance);
|
||||
* @retval kThreadErrorAlready Jam detection has been started before.
|
||||
*
|
||||
*/
|
||||
ThreadError otStartJamDetection(otInstance *aInstance, otJamDetectionCallback aCallback, void *aContext);
|
||||
ThreadError otJamDetectionStart(otInstance *aInstance, otJamDetectionCallback aCallback, void *aContext);
|
||||
|
||||
/**
|
||||
* Stop the jamming detection.
|
||||
@@ -148,7 +156,7 @@ ThreadError otStartJamDetection(otInstance *aInstance, otJamDetectionCallback aC
|
||||
* @retval kThreadErrorAlready Jam detection is already stopped.
|
||||
*
|
||||
*/
|
||||
ThreadError otStopJamDetection(otInstance *aInstance);
|
||||
ThreadError otJamDetectionStop(otInstance *aInstance);
|
||||
|
||||
/**
|
||||
* Get the Jam Detection Status (enabled/disabled)
|
||||
@@ -157,7 +165,7 @@ ThreadError otStopJamDetection(otInstance *aInstance);
|
||||
*
|
||||
* @returns The Jam Detection status (true if enabled, false otherwise).
|
||||
*/
|
||||
bool otIsJamDetectionEnabled(otInstance *aInstance);
|
||||
bool otJamDetectionIsEnabled(otInstance *aInstance);
|
||||
|
||||
/**
|
||||
* Get the Jam Detection State
|
||||
@@ -166,7 +174,7 @@ bool otIsJamDetectionEnabled(otInstance *aInstance);
|
||||
*
|
||||
* @returns The Jam Detection state (`true` jam is detected, `false' otherwise).
|
||||
*/
|
||||
bool otGetJamDetectionState(otInstance *aInstance);
|
||||
bool otJamDetectionGetState(otInstance *aInstance);
|
||||
|
||||
/**
|
||||
* Get the current history bitmap.
|
||||
@@ -182,13 +190,15 @@ bool otGetJamDetectionState(otInstance *aInstance);
|
||||
*
|
||||
* @returns The current history bitmap.
|
||||
*/
|
||||
uint64_t otGetJamDetectionHistoryBitmap(otInstance *aInstance);
|
||||
uint64_t otJamDetectionGetHistoryBitmap(otInstance *aInstance);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*
|
||||
*/
|
||||
|
||||
#endif // OPENTHREAD_ENABLE_JAM_DETECTION
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
@@ -139,6 +139,7 @@ endif # OPENTHREAD_ENABLE_DHCP6_SERVER
|
||||
|
||||
if OPENTHREAD_ENABLE_JAM_DETECTION
|
||||
SOURCES_COMMON += \
|
||||
api/jam_detection_api.cpp \
|
||||
utils/jam_detector.cpp \
|
||||
$(NULL)
|
||||
endif # OPENTHREAD_ENABLE_JAM_DETECTION
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (c) 2016, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file implements the OpenThread Jam Detection API.
|
||||
*/
|
||||
|
||||
#include "openthread/jam_detection.h"
|
||||
|
||||
#include "openthread-instance.h"
|
||||
|
||||
using namespace Thread;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_ENABLE_JAM_DETECTION
|
||||
|
||||
ThreadError otJamDetectionSetRssiThreshold(otInstance *aInstance, int8_t aRssiThreshold)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetJamDetector().SetRssiThreshold(aRssiThreshold);
|
||||
}
|
||||
|
||||
int8_t otJamDetectionGetRssiThreshold(otInstance *aInstance)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetJamDetector().GetRssiThreshold();
|
||||
}
|
||||
|
||||
ThreadError otJamDetectionSetWindow(otInstance *aInstance, uint8_t aWindow)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetJamDetector().SetWindow(aWindow);
|
||||
}
|
||||
|
||||
uint8_t otJamDetectionGetWindow(otInstance *aInstance)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetJamDetector().GetWindow();
|
||||
}
|
||||
|
||||
ThreadError otJamDetectionSetBusyPeriod(otInstance *aInstance, uint8_t aBusyPeriod)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetJamDetector().SetBusyPeriod(aBusyPeriod);
|
||||
}
|
||||
|
||||
uint8_t otJamDetectionGetBusyPeriod(otInstance *aInstance)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetJamDetector().GetBusyPeriod();
|
||||
}
|
||||
|
||||
ThreadError otJamDetectionStart(otInstance *aInstance, otJamDetectionCallback aCallback, void *aContext)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetJamDetector().Start(aCallback, aContext);
|
||||
}
|
||||
|
||||
ThreadError otJamDetectionStop(otInstance *aInstance)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetJamDetector().Stop();
|
||||
}
|
||||
|
||||
bool otJamDetectionIsEnabled(otInstance *aInstance)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetJamDetector().IsEnabled();
|
||||
}
|
||||
|
||||
bool otJamDetectionGetState(otInstance *aInstance)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetJamDetector().GetState();
|
||||
}
|
||||
|
||||
uint64_t otJamDetectionGetHistoryBitmap(otInstance *aInstance)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetJamDetector().GetHistoryBitmap();
|
||||
}
|
||||
|
||||
#endif // OPENTHREAD_ENABLE_JAM_DETECTION
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
@@ -41,10 +41,6 @@
|
||||
|
||||
#include <openthread.h>
|
||||
|
||||
#if OPENTHREAD_ENABLE_JAM_DETECTION
|
||||
#include <openthread-jam-detection.h>
|
||||
#endif
|
||||
|
||||
#include <common/code_utils.hpp>
|
||||
#include <common/debug.hpp>
|
||||
#include <common/logging.hpp>
|
||||
@@ -955,63 +951,6 @@ const otMacCounters *otGetMacCounters(otInstance *aInstance)
|
||||
return &aInstance->mThreadNetif.GetMac().GetCounters();
|
||||
}
|
||||
|
||||
#if OPENTHREAD_ENABLE_JAM_DETECTION
|
||||
ThreadError otSetJamDetectionRssiThreshold(otInstance *aInstance, int8_t aRssiThreshold)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetJamDetector().SetRssiThreshold(aRssiThreshold);
|
||||
}
|
||||
|
||||
int8_t otGetJamDetectionRssiThreshold(otInstance *aInstance)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetJamDetector().GetRssiThreshold();
|
||||
}
|
||||
|
||||
ThreadError otSetJamDetectionWindow(otInstance *aInstance, uint8_t aWindow)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetJamDetector().SetWindow(aWindow);
|
||||
}
|
||||
|
||||
uint8_t otGetJamDetectionWindow(otInstance *aInstance)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetJamDetector().GetWindow();
|
||||
}
|
||||
|
||||
ThreadError otSetJamDetectionBusyPeriod(otInstance *aInstance, uint8_t aBusyPeriod)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetJamDetector().SetBusyPeriod(aBusyPeriod);
|
||||
}
|
||||
|
||||
uint8_t otGetJamDetectionBusyPeriod(otInstance *aInstance)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetJamDetector().GetBusyPeriod();
|
||||
}
|
||||
|
||||
ThreadError otStartJamDetection(otInstance *aInstance, otJamDetectionCallback aCallback, void *aContext)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetJamDetector().Start(aCallback, aContext);
|
||||
}
|
||||
|
||||
ThreadError otStopJamDetection(otInstance *aInstance)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetJamDetector().Stop();
|
||||
}
|
||||
|
||||
bool otIsJamDetectionEnabled(otInstance *aInstance)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetJamDetector().IsEnabled();
|
||||
}
|
||||
|
||||
bool otGetJamDetectionState(otInstance *aInstance)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetJamDetector().GetState();
|
||||
}
|
||||
|
||||
uint64_t otGetJamDetectionHistoryBitmap(otInstance *aInstance)
|
||||
{
|
||||
return aInstance->mThreadNetif.GetJamDetector().GetHistoryBitmap();
|
||||
}
|
||||
#endif // OPENTHREAD_ENABLE_JAM_DETECTION
|
||||
|
||||
bool otIsIp6AddressEqual(const otIp6Address *a, const otIp6Address *b)
|
||||
{
|
||||
return *static_cast<const Ip6::Address *>(a) == *static_cast<const Ip6::Address *>(b);
|
||||
|
||||
+16
-15
@@ -40,6 +40,10 @@
|
||||
|
||||
#include "openthread/message.h"
|
||||
|
||||
#if OPENTHREAD_ENABLE_JAM_DETECTION
|
||||
#include "openthread/jam_detection.h"
|
||||
#endif
|
||||
|
||||
#include <common/code_utils.hpp>
|
||||
#include <common/debug.hpp>
|
||||
#include <ncp/ncp.h>
|
||||
@@ -48,9 +52,6 @@
|
||||
#include <openthread.h>
|
||||
#include <openthread-diag.h>
|
||||
#include <openthread-icmp6.h>
|
||||
#if OPENTHREAD_ENABLE_JAM_DETECTION
|
||||
#include <openthread-jam-detection.h>
|
||||
#endif
|
||||
#include <openthread-instance.h>
|
||||
#include <stdarg.h>
|
||||
#include <platform/radio.h>
|
||||
@@ -1225,7 +1226,7 @@ void NcpBase::HandleSpaceAvailableInTxBuffer(void)
|
||||
SPINEL_CMD_PROP_VALUE_IS,
|
||||
SPINEL_PROP_JAM_DETECTED,
|
||||
SPINEL_DATATYPE_BOOL_S,
|
||||
otGetJamDetectionState(mInstance)
|
||||
otJamDetectionGetState(mInstance)
|
||||
));
|
||||
|
||||
mShouldSignalJamStateChange = false;
|
||||
@@ -2797,7 +2798,7 @@ ThreadError NcpBase::GetPropertyHandler_JAM_DETECT_ENABLE(uint8_t header, spinel
|
||||
SPINEL_CMD_PROP_VALUE_IS,
|
||||
key,
|
||||
SPINEL_DATATYPE_BOOL_S,
|
||||
otIsJamDetectionEnabled(mInstance)
|
||||
otJamDetectionIsEnabled(mInstance)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2808,7 +2809,7 @@ ThreadError NcpBase::GetPropertyHandler_JAM_DETECTED(uint8_t header, spinel_prop
|
||||
SPINEL_CMD_PROP_VALUE_IS,
|
||||
key,
|
||||
SPINEL_DATATYPE_BOOL_S,
|
||||
otGetJamDetectionState(mInstance)
|
||||
otJamDetectionGetState(mInstance)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2819,7 +2820,7 @@ ThreadError NcpBase::GetPropertyHandler_JAM_DETECT_RSSI_THRESHOLD(uint8_t header
|
||||
SPINEL_CMD_PROP_VALUE_IS,
|
||||
key,
|
||||
SPINEL_DATATYPE_INT8_S,
|
||||
otGetJamDetectionRssiThreshold(mInstance)
|
||||
otJamDetectionGetRssiThreshold(mInstance)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2830,7 +2831,7 @@ ThreadError NcpBase::GetPropertyHandler_JAM_DETECT_WINDOW(uint8_t header, spinel
|
||||
SPINEL_CMD_PROP_VALUE_IS,
|
||||
key,
|
||||
SPINEL_DATATYPE_UINT8_S,
|
||||
otGetJamDetectionWindow(mInstance)
|
||||
otJamDetectionGetWindow(mInstance)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2841,13 +2842,13 @@ ThreadError NcpBase::GetPropertyHandler_JAM_DETECT_BUSY(uint8_t header, spinel_p
|
||||
SPINEL_CMD_PROP_VALUE_IS,
|
||||
key,
|
||||
SPINEL_DATATYPE_UINT8_S,
|
||||
otGetJamDetectionBusyPeriod(mInstance)
|
||||
otJamDetectionGetBusyPeriod(mInstance)
|
||||
);
|
||||
}
|
||||
|
||||
ThreadError NcpBase::GetPropertyHandler_JAM_DETECT_HISTORY_BITMAP(uint8_t header, spinel_prop_key_t key)
|
||||
{
|
||||
uint64_t historyBitmap = otGetJamDetectionHistoryBitmap(mInstance);
|
||||
uint64_t historyBitmap = otJamDetectionGetHistoryBitmap(mInstance);
|
||||
|
||||
return SendPropertyUpdate(
|
||||
header,
|
||||
@@ -5300,11 +5301,11 @@ ThreadError NcpBase::SetPropertyHandler_JAM_DETECT_ENABLE(uint8_t header, spinel
|
||||
{
|
||||
if (isEnabled)
|
||||
{
|
||||
otStartJamDetection(mInstance, &NcpBase::HandleJamStateChange_Jump, this);
|
||||
otJamDetectionStart(mInstance, &NcpBase::HandleJamStateChange_Jump, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
otStopJamDetection(mInstance);
|
||||
otJamDetectionStop(mInstance);
|
||||
}
|
||||
|
||||
errorCode = HandleCommandPropertyGet(header, key);
|
||||
@@ -5333,7 +5334,7 @@ ThreadError NcpBase::SetPropertyHandler_JAM_DETECT_RSSI_THRESHOLD(uint8_t header
|
||||
|
||||
if (parsedLength > 0)
|
||||
{
|
||||
errorCode = otSetJamDetectionRssiThreshold(mInstance, value);
|
||||
errorCode = otJamDetectionSetRssiThreshold(mInstance, value);
|
||||
|
||||
if (errorCode == kThreadError_None)
|
||||
{
|
||||
@@ -5368,7 +5369,7 @@ ThreadError NcpBase::SetPropertyHandler_JAM_DETECT_WINDOW(uint8_t header, spinel
|
||||
|
||||
if (parsedLength > 0)
|
||||
{
|
||||
errorCode = otSetJamDetectionWindow(mInstance, value);
|
||||
errorCode = otJamDetectionSetWindow(mInstance, value);
|
||||
|
||||
if (errorCode == kThreadError_None)
|
||||
{
|
||||
@@ -5403,7 +5404,7 @@ ThreadError NcpBase::SetPropertyHandler_JAM_DETECT_BUSY(uint8_t header, spinel_p
|
||||
|
||||
if (parsedLength > 0)
|
||||
{
|
||||
errorCode = otSetJamDetectionBusyPeriod(mInstance, value);
|
||||
errorCode = otJamDetectionSetBusyPeriod(mInstance, value);
|
||||
|
||||
if (errorCode == kThreadError_None)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user