Imported more library files
Not compiling currently
This commit is contained in:
580
Libs/protocol/openthread/platform-abstraction/efr32/alarm.c
Normal file
580
Libs/protocol/openthread/platform-abstraction/efr32/alarm.c
Normal file
@@ -0,0 +1,580 @@
|
||||
/*
|
||||
* Copyright (c) 2023, 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 platform abstraction for the alarm.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <openthread-core-config.h>
|
||||
#include <openthread-system.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <openthread/platform/alarm-micro.h>
|
||||
#include <openthread/platform/alarm-milli.h>
|
||||
#include <openthread/platform/diag.h>
|
||||
#include "common/debug.hpp"
|
||||
#include "common/logging.hpp"
|
||||
|
||||
#include "alarm.h"
|
||||
#include "platform-efr32.h"
|
||||
#include "utils/code_utils.h"
|
||||
|
||||
#include "rail.h"
|
||||
#include "sl_core.h"
|
||||
#include "sl_multipan.h"
|
||||
#include "sl_sleeptimer.h"
|
||||
|
||||
#ifndef TESTING
|
||||
#define STATIC static
|
||||
#else
|
||||
#define STATIC
|
||||
#endif
|
||||
|
||||
// timer data for handling wrapping
|
||||
typedef struct wrap_timer_data wrap_timer_data_t;
|
||||
struct wrap_timer_data
|
||||
{
|
||||
uint16_t overflow_counter;
|
||||
uint16_t overflow_max;
|
||||
};
|
||||
|
||||
// millisecond timer (sleeptimer)
|
||||
static sl_sleeptimer_timer_handle_t sl_handle[OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_NUM];
|
||||
|
||||
// microsecond timer (RAIL timer)
|
||||
static RAIL_MultiTimer_t rail_timer[OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_NUM];
|
||||
|
||||
// forward declare generic alarm handle
|
||||
struct AlarmHandle;
|
||||
|
||||
// function pointers for timer operations
|
||||
typedef void (*timerStartFunc)(struct AlarmHandle *, uint32_t);
|
||||
typedef uint32_t (*timerMaxFunc)(void);
|
||||
typedef uint32_t (*timerGetTimeFunc)(void);
|
||||
typedef void (*timerStopFunc)(struct AlarmHandle *);
|
||||
|
||||
// alarm handle structure
|
||||
typedef struct AlarmHandle AlarmHandle;
|
||||
struct AlarmHandle
|
||||
{
|
||||
otInstance *mThreadInstance;
|
||||
void *mTimerHandle;
|
||||
timerStartFunc mTimerStart;
|
||||
timerMaxFunc mTimerGetMax;
|
||||
timerGetTimeFunc mTimerGetNow;
|
||||
timerStopFunc mTimerStop;
|
||||
wrap_timer_data_t mWrapData;
|
||||
volatile bool mIsRunning;
|
||||
volatile int mFiredCount;
|
||||
};
|
||||
|
||||
// callback function for the stack
|
||||
typedef void (*StackAlarmCallback)(otInstance *);
|
||||
|
||||
// alarm handle instances
|
||||
static AlarmHandle sMsAlarmHandles[OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_NUM];
|
||||
static AlarmHandle sUsAlarmHandles[OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_NUM];
|
||||
|
||||
static uint64_t sPendingTimeMs[OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_NUM];
|
||||
|
||||
// millisecond-alarm callback
|
||||
STATIC void msAlarmCallback(sl_sleeptimer_timer_handle_t *aHandle, void *aData);
|
||||
|
||||
// microsecond-alarm callback
|
||||
STATIC void usAlarmCallback(struct RAIL_MultiTimer *tmr, RAIL_Time_t expectedTimeOfEvent, void *cbArg);
|
||||
|
||||
// timer specific operations
|
||||
static void msTimerStart(AlarmHandle *aMsAlarm, uint32_t aAlarmDuration);
|
||||
static uint32_t msTimerGetMaxTime(void);
|
||||
static uint32_t msTimerGetNow(void);
|
||||
static void msTimerStop(AlarmHandle *aMsAlarm);
|
||||
|
||||
static void usTimerStart(AlarmHandle *aUsAlarm, uint32_t aAlarmDuration);
|
||||
static uint32_t usTimerGetMaxTime(void);
|
||||
static uint32_t usTimerGetNow(void);
|
||||
static void usTimerStop(AlarmHandle *aUsAlarm);
|
||||
|
||||
// overflow utility functions
|
||||
static inline bool isAlarmOverflowInProgress(AlarmHandle *aAlarm);
|
||||
|
||||
// common timer operations
|
||||
static void FireAlarm(AlarmHandle *aAlarm);
|
||||
static void StartAlarmAt(AlarmHandle *aAlarm, uint32_t aT0, uint32_t aDt);
|
||||
static void StopActiveAlarm(AlarmHandle *aAlarm);
|
||||
static void AlarmCallback(AlarmHandle *aAlarm);
|
||||
|
||||
// pending time utility functions
|
||||
static inline uint64_t GetPendingTime(otInstance *aInstance);
|
||||
static inline void SetPendingTime(otInstance *aInstance, uint64_t aPendingTime);
|
||||
|
||||
// alarm handle utility functions
|
||||
static inline AlarmHandle *GetAlarmHandle(AlarmHandle *aHandleList, otInstance *aInstance);
|
||||
static AlarmHandle *GetFirstFiredAlarm(AlarmHandle *aAlarm);
|
||||
static AlarmHandle *GetNextFiredAlarm(AlarmHandle *aAlarm, const AlarmHandle *aAlarmEnd);
|
||||
static inline bool HasAnyAlarmFired(void);
|
||||
static inline uint32_t SetAlarmWrappedDuration(AlarmHandle *aAlarm, uint64_t aRemainingTime);
|
||||
|
||||
static void msTimerStart(AlarmHandle *aMsAlarm, uint32_t aAlarmDuration)
|
||||
{
|
||||
OT_ASSERT(aMsAlarm != NULL);
|
||||
OT_ASSERT(aMsAlarm->mIsRunning == false);
|
||||
sl_status_t status = sl_sleeptimer_start_timer_ms(aMsAlarm->mTimerHandle,
|
||||
aAlarmDuration,
|
||||
msAlarmCallback,
|
||||
(void *)aMsAlarm,
|
||||
0,
|
||||
SL_SLEEPTIMER_NO_HIGH_PRECISION_HF_CLOCKS_REQUIRED_FLAG);
|
||||
#if OPENTHREAD_CONFIG_ASSERT_ENABLE
|
||||
OT_ASSERT(status == SL_STATUS_OK);
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(status);
|
||||
#endif
|
||||
}
|
||||
|
||||
static uint32_t msTimerGetMaxTime(void)
|
||||
{
|
||||
return sl_sleeptimer_get_max_ms32_conversion();
|
||||
}
|
||||
|
||||
static uint32_t msTimerGetNow(void)
|
||||
{
|
||||
uint64_t ticks;
|
||||
uint64_t now;
|
||||
sl_status_t status;
|
||||
|
||||
ticks = sl_sleeptimer_get_tick_count64();
|
||||
status = sl_sleeptimer_tick64_to_ms(ticks, &now);
|
||||
|
||||
#if OPENTHREAD_CONFIG_ASSERT_ENABLE
|
||||
OT_ASSERT(status == SL_STATUS_OK);
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(status);
|
||||
#endif
|
||||
|
||||
return (uint32_t)now;
|
||||
}
|
||||
|
||||
static void msTimerStop(AlarmHandle *aMsAlarm)
|
||||
{
|
||||
OT_ASSERT(aMsAlarm != NULL);
|
||||
sl_sleeptimer_stop_timer((sl_sleeptimer_timer_handle_t *)aMsAlarm->mTimerHandle);
|
||||
}
|
||||
|
||||
static void usTimerStart(AlarmHandle *aUsAlarm, uint32_t aAlarmDuration)
|
||||
{
|
||||
OT_ASSERT(aUsAlarm != NULL);
|
||||
OT_ASSERT(aUsAlarm->mIsRunning == false);
|
||||
RAIL_Status_t status =
|
||||
RAIL_SetMultiTimer(aUsAlarm->mTimerHandle, aAlarmDuration, RAIL_TIME_DELAY, usAlarmCallback, (void *)aUsAlarm);
|
||||
#if OPENTHREAD_CONFIG_ASSERT_ENABLE
|
||||
OT_ASSERT(status == RAIL_STATUS_NO_ERROR);
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(status);
|
||||
#endif
|
||||
}
|
||||
|
||||
static uint32_t usTimerGetMaxTime(void)
|
||||
{
|
||||
return UINT32_MAX;
|
||||
}
|
||||
|
||||
static uint32_t usTimerGetNow(void)
|
||||
{
|
||||
return RAIL_GetTime();
|
||||
}
|
||||
|
||||
static void usTimerStop(AlarmHandle *aUsAlarm)
|
||||
{
|
||||
OT_ASSERT(aUsAlarm != NULL);
|
||||
RAIL_CancelMultiTimer((struct RAIL_MultiTimer *)aUsAlarm->mTimerHandle);
|
||||
}
|
||||
|
||||
static inline bool isAlarmOverflowInProgress(AlarmHandle *aAlarm)
|
||||
{
|
||||
OT_ASSERT(aAlarm != NULL);
|
||||
return aAlarm->mWrapData.overflow_counter < aAlarm->mWrapData.overflow_max;
|
||||
}
|
||||
|
||||
static void FireAlarm(AlarmHandle *aAlarm)
|
||||
{
|
||||
OT_ASSERT(aAlarm != NULL);
|
||||
aAlarm->mFiredCount++;
|
||||
StopActiveAlarm(aAlarm);
|
||||
|
||||
otSysEventSignalPending();
|
||||
}
|
||||
|
||||
static void ProcessAlarm(AlarmHandle *aAlarm, StackAlarmCallback aCallback)
|
||||
{
|
||||
OT_ASSERT(aAlarm != NULL);
|
||||
otInstance *instance = aAlarm->mThreadInstance;
|
||||
|
||||
CORE_DECLARE_IRQ_STATE;
|
||||
CORE_ENTER_ATOMIC();
|
||||
|
||||
int numCallbacks = aAlarm->mFiredCount;
|
||||
aAlarm->mFiredCount = 0;
|
||||
|
||||
CORE_EXIT_ATOMIC();
|
||||
|
||||
while (numCallbacks > 0)
|
||||
{
|
||||
numCallbacks--;
|
||||
aCallback(instance);
|
||||
}
|
||||
}
|
||||
|
||||
static inline uint32_t SetAlarmWrappedDuration(AlarmHandle *aAlarm, uint64_t aRemainingTime)
|
||||
{
|
||||
OT_ASSERT(aAlarm != NULL);
|
||||
uint64_t initial_wrap_time = aRemainingTime;
|
||||
wrap_timer_data_t wrapData = {0};
|
||||
|
||||
if (initial_wrap_time > aAlarm->mTimerGetMax())
|
||||
{
|
||||
initial_wrap_time %= aAlarm->mTimerGetMax();
|
||||
wrapData.overflow_max = (uint16_t)(aRemainingTime / aAlarm->mTimerGetMax());
|
||||
wrapData.overflow_counter = 0;
|
||||
}
|
||||
aAlarm->mWrapData = wrapData;
|
||||
return (uint32_t)initial_wrap_time;
|
||||
}
|
||||
|
||||
static void StartAlarmAt(AlarmHandle *aAlarm, uint32_t aT0, uint32_t aDt)
|
||||
{
|
||||
OT_ASSERT(aAlarm != NULL);
|
||||
otEXPECT(sl_ot_rtos_task_can_access_pal());
|
||||
StopActiveAlarm(aAlarm);
|
||||
|
||||
uint64_t requested_time = (uint64_t)aT0 + (uint64_t)aDt;
|
||||
int64_t remaining = (int64_t)requested_time - (int64_t)aAlarm->mTimerGetNow();
|
||||
|
||||
if (remaining <= 0)
|
||||
{
|
||||
FireAlarm(aAlarm);
|
||||
}
|
||||
else
|
||||
{
|
||||
aAlarm->mTimerStart(aAlarm, SetAlarmWrappedDuration(aAlarm, (uint64_t)remaining));
|
||||
aAlarm->mIsRunning = true;
|
||||
}
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
static void StopActiveAlarm(AlarmHandle *aAlarm)
|
||||
{
|
||||
OT_ASSERT(aAlarm != NULL);
|
||||
otEXPECT(aAlarm->mIsRunning);
|
||||
otEXPECT(sl_ot_rtos_task_can_access_pal());
|
||||
aAlarm->mTimerStop(aAlarm);
|
||||
aAlarm->mIsRunning = false;
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
static void AlarmCallback(AlarmHandle *aAlarm)
|
||||
{
|
||||
OT_ASSERT(aAlarm != NULL);
|
||||
if (isAlarmOverflowInProgress(aAlarm))
|
||||
{
|
||||
aAlarm->mIsRunning = false;
|
||||
aAlarm->mWrapData.overflow_counter++;
|
||||
aAlarm->mTimerStart(aAlarm, aAlarm->mTimerGetMax());
|
||||
}
|
||||
else
|
||||
{
|
||||
FireAlarm(aAlarm);
|
||||
}
|
||||
}
|
||||
|
||||
static inline uint64_t GetPendingTime(otInstance *aInstance)
|
||||
{
|
||||
#if OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
|
||||
efr32Iid_t currentIid = (efr32Iid_t)efr32GetIidFromInstance(aInstance);
|
||||
OT_ASSERT(currentIid <= OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_NUM);
|
||||
return sPendingTimeMs[currentIid - 1];
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
return sPendingTimeMs[0];
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void SetPendingTime(otInstance *aInstance, uint64_t aPendingTime)
|
||||
{
|
||||
#if OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
|
||||
efr32Iid_t currentIid = (efr32Iid_t)efr32GetIidFromInstance(aInstance);
|
||||
OT_ASSERT(currentIid <= OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_NUM);
|
||||
sPendingTimeMs[currentIid - 1] = aPendingTime;
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
sPendingTimeMs[0] = aPendingTime;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline AlarmHandle *GetAlarmHandle(AlarmHandle *aHandleList, otInstance *aInstance)
|
||||
{
|
||||
AlarmHandle *alarmHandle = aHandleList;
|
||||
#if OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
|
||||
efr32Iid_t currentIid = (efr32Iid_t)efr32GetIidFromInstance(aInstance);
|
||||
OT_ASSERT(currentIid <= OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_NUM);
|
||||
alarmHandle = aHandleList + ((uint8_t)(currentIid - 1));
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
#endif
|
||||
return alarmHandle;
|
||||
}
|
||||
|
||||
static AlarmHandle *GetFirstFiredAlarm(AlarmHandle *aHandleList)
|
||||
{
|
||||
return GetNextFiredAlarm(aHandleList, aHandleList + OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_NUM);
|
||||
}
|
||||
|
||||
static AlarmHandle *GetNextFiredAlarm(AlarmHandle *aAlarm, const AlarmHandle *aAlarmEnd)
|
||||
{
|
||||
AlarmHandle *nextAlarm = aAlarm;
|
||||
|
||||
while (nextAlarm && nextAlarm->mFiredCount == 0 && nextAlarm < aAlarmEnd)
|
||||
{
|
||||
nextAlarm++;
|
||||
}
|
||||
|
||||
if (nextAlarm >= aAlarmEnd)
|
||||
{
|
||||
nextAlarm = NULL;
|
||||
}
|
||||
|
||||
return nextAlarm;
|
||||
}
|
||||
|
||||
static inline bool HasAnyAlarmFired(void)
|
||||
{
|
||||
return (GetFirstFiredAlarm(sMsAlarmHandles) != NULL) || (GetFirstFiredAlarm(sUsAlarmHandles) != NULL);
|
||||
}
|
||||
|
||||
// millisecond-alarm callback
|
||||
SL_CODE_CLASSIFY(SL_CODE_COMPONENT_OT_PLATFORM_ABSTRACTION, SL_CODE_CLASS_TIME_CRITICAL)
|
||||
STATIC void msAlarmCallback(sl_sleeptimer_timer_handle_t *aHandle, void *aData)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aHandle);
|
||||
|
||||
AlarmCallback((AlarmHandle *)aData);
|
||||
}
|
||||
|
||||
// microsecond-alarm callback
|
||||
SL_CODE_CLASSIFY(SL_CODE_COMPONENT_OT_PLATFORM_ABSTRACTION, SL_CODE_CLASS_TIME_CRITICAL)
|
||||
STATIC void usAlarmCallback(struct RAIL_MultiTimer *tmr, RAIL_Time_t expectedTimeOfEvent, void *cbArg)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(tmr);
|
||||
OT_UNUSED_VARIABLE(expectedTimeOfEvent);
|
||||
|
||||
AlarmCallback((AlarmHandle *)cbArg);
|
||||
}
|
||||
|
||||
void efr32AlarmInit(void)
|
||||
{
|
||||
memset(&sl_handle, 0, sizeof sl_handle);
|
||||
memset(&rail_timer, 0, sizeof rail_timer);
|
||||
|
||||
for (uint8_t i = 0; i < OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_NUM; i++)
|
||||
{
|
||||
sPendingTimeMs[i] = 0;
|
||||
|
||||
sMsAlarmHandles[i].mThreadInstance = NULL;
|
||||
sMsAlarmHandles[i].mTimerHandle = &sl_handle[i];
|
||||
sMsAlarmHandles[i].mTimerStart = msTimerStart;
|
||||
sMsAlarmHandles[i].mTimerGetMax = msTimerGetMaxTime;
|
||||
sMsAlarmHandles[i].mTimerGetNow = msTimerGetNow;
|
||||
sMsAlarmHandles[i].mTimerStop = msTimerStop;
|
||||
sMsAlarmHandles[i].mIsRunning = false;
|
||||
sMsAlarmHandles[i].mFiredCount = 0;
|
||||
memset(&sMsAlarmHandles[i].mWrapData, 0, sizeof(wrap_timer_data_t));
|
||||
|
||||
sUsAlarmHandles[i].mThreadInstance = NULL;
|
||||
sUsAlarmHandles[i].mTimerHandle = &rail_timer[i];
|
||||
sUsAlarmHandles[i].mTimerStart = usTimerStart;
|
||||
sUsAlarmHandles[i].mTimerGetMax = usTimerGetMaxTime;
|
||||
sUsAlarmHandles[i].mTimerGetNow = usTimerGetNow;
|
||||
sUsAlarmHandles[i].mTimerStop = usTimerStop;
|
||||
sUsAlarmHandles[i].mIsRunning = false;
|
||||
sUsAlarmHandles[i].mFiredCount = 0;
|
||||
memset(&sUsAlarmHandles[i].mWrapData, 0, sizeof(wrap_timer_data_t));
|
||||
}
|
||||
}
|
||||
|
||||
void efr32AlarmProcess(otInstance *aInstance)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
otEXPECT(HasAnyAlarmFired());
|
||||
|
||||
AlarmHandle *msAlarm = GetFirstFiredAlarm(sMsAlarmHandles);
|
||||
const AlarmHandle *msAlarmEnd = sMsAlarmHandles + OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_NUM;
|
||||
|
||||
StackAlarmCallback alarmCb;
|
||||
|
||||
while (msAlarm != NULL)
|
||||
{
|
||||
#if OPENTHREAD_CONFIG_DIAG_ENABLE
|
||||
if (otPlatDiagModeGet())
|
||||
{
|
||||
alarmCb = otPlatDiagAlarmFired;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
alarmCb = otPlatAlarmMilliFired;
|
||||
}
|
||||
ProcessAlarm(msAlarm, alarmCb);
|
||||
msAlarm = GetNextFiredAlarm(msAlarm, msAlarmEnd);
|
||||
}
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE
|
||||
AlarmHandle *usAlarm = GetFirstFiredAlarm(sUsAlarmHandles);
|
||||
const AlarmHandle *usAlarmEnd = sUsAlarmHandles + OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_NUM;
|
||||
|
||||
while (usAlarm != NULL)
|
||||
{
|
||||
alarmCb = otPlatAlarmMicroFired;
|
||||
ProcessAlarm(usAlarm, alarmCb);
|
||||
usAlarm = GetNextFiredAlarm(usAlarm, usAlarmEnd);
|
||||
}
|
||||
#endif
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
uint64_t efr32AlarmPendingTime(otInstance *aInstance)
|
||||
{
|
||||
uint64_t remaining = GetPendingTime(aInstance);
|
||||
uint32_t now = otPlatAlarmMilliGetNow();
|
||||
|
||||
otEXPECT_ACTION(GetAlarmHandle(sMsAlarmHandles, aInstance)->mIsRunning, remaining = 0);
|
||||
|
||||
if (remaining > now)
|
||||
{
|
||||
remaining -= (uint64_t)now;
|
||||
}
|
||||
|
||||
exit:
|
||||
return remaining;
|
||||
}
|
||||
|
||||
bool efr32AlarmIsRunning(otInstance *aInstance)
|
||||
{
|
||||
return (otInstanceIsInitialized(aInstance) ? GetAlarmHandle(sMsAlarmHandles, aInstance)->mIsRunning : false);
|
||||
}
|
||||
|
||||
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
|
||||
// Callback to determine if the system can sleep after an interrupt has fired
|
||||
bool efr32AlarmIsReady(void)
|
||||
{
|
||||
return HasAnyAlarmFired();
|
||||
}
|
||||
#endif // SL_CATALOG_POWER_MANAGER_PRESENT
|
||||
|
||||
uint32_t otPlatAlarmMilliGetNow(void)
|
||||
{
|
||||
return sMsAlarmHandles[0].mTimerGetNow();
|
||||
}
|
||||
|
||||
uint16_t otPlatTimeGetXtalAccuracy(void)
|
||||
{
|
||||
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
|
||||
// For sleepies, we need to account for the low-frequency crystal
|
||||
// accuracy when they go to sleep. Accounting for that as well,
|
||||
// for the worst case.
|
||||
if (efr32AllowSleepCallback())
|
||||
{
|
||||
return SL_OPENTHREAD_HFXO_ACCURACY + SL_OPENTHREAD_LFXO_ACCURACY;
|
||||
}
|
||||
#endif
|
||||
return SL_OPENTHREAD_HFXO_ACCURACY;
|
||||
}
|
||||
|
||||
void otPlatAlarmMilliStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt)
|
||||
{
|
||||
AlarmHandle *alarm = GetAlarmHandle(sMsAlarmHandles, aInstance);
|
||||
if (alarm->mThreadInstance == NULL)
|
||||
{
|
||||
alarm->mThreadInstance = aInstance;
|
||||
}
|
||||
|
||||
SetPendingTime(aInstance, (uint64_t)aT0 + (uint64_t)aDt);
|
||||
CORE_ATOMIC_SECTION(StartAlarmAt(alarm, aT0, aDt);)
|
||||
}
|
||||
|
||||
void otPlatAlarmMilliStop(otInstance *aInstance)
|
||||
{
|
||||
CORE_ATOMIC_SECTION(StopActiveAlarm(GetAlarmHandle(sMsAlarmHandles, aInstance));)
|
||||
}
|
||||
|
||||
uint32_t otPlatAlarmMicroGetNow(void)
|
||||
{
|
||||
return sUsAlarmHandles[0].mTimerGetNow();
|
||||
}
|
||||
|
||||
// Note: This function should be called at least once per wrap
|
||||
// period for the wrap-around logic to work below
|
||||
uint64_t otPlatTimeGet(void)
|
||||
{
|
||||
static uint32_t timerWraps = 0U;
|
||||
static uint32_t prev32TimeUs = 0U;
|
||||
uint32_t now32TimeUs;
|
||||
uint64_t now64TimeUs;
|
||||
CORE_DECLARE_IRQ_STATE;
|
||||
CORE_ENTER_CRITICAL();
|
||||
now32TimeUs = RAIL_GetTime();
|
||||
if (now32TimeUs < prev32TimeUs)
|
||||
{
|
||||
timerWraps += 1U;
|
||||
}
|
||||
prev32TimeUs = now32TimeUs;
|
||||
now64TimeUs = ((uint64_t)timerWraps << 32) + now32TimeUs;
|
||||
CORE_EXIT_CRITICAL();
|
||||
return now64TimeUs;
|
||||
}
|
||||
|
||||
void otPlatAlarmMicroStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt)
|
||||
{
|
||||
AlarmHandle *alarm = GetAlarmHandle(sUsAlarmHandles, aInstance);
|
||||
if (alarm->mThreadInstance == NULL)
|
||||
{
|
||||
alarm->mThreadInstance = aInstance;
|
||||
}
|
||||
|
||||
CORE_ATOMIC_SECTION(StartAlarmAt(alarm, aT0, aDt);)
|
||||
}
|
||||
|
||||
void otPlatAlarmMicroStop(otInstance *aInstance)
|
||||
{
|
||||
CORE_ATOMIC_SECTION(StopActiveAlarm(GetAlarmHandle(sUsAlarmHandles, aInstance));)
|
||||
}
|
||||
86
Libs/protocol/openthread/platform-abstraction/efr32/alarm.h
Normal file
86
Libs/protocol/openthread/platform-abstraction/efr32/alarm.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (c) 2024, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file defines platform specific alarm methods.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _ALARM_H
|
||||
#define _ALARM_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "openthread/instance.h"
|
||||
|
||||
#ifdef SL_COMPONENT_CATALOG_PRESENT
|
||||
#include "sl_component_catalog.h"
|
||||
#endif // SL_COMPONENT_CATALOG_PRESENT
|
||||
|
||||
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
|
||||
#include "sl_power_manager.h"
|
||||
|
||||
/**
|
||||
* This function determines whether the device should sleep after an alarm triggers.
|
||||
*/
|
||||
bool efr32AlarmIsReady(void);
|
||||
|
||||
#endif // SL_CATALOG_POWER_MANAGER_PRESENT
|
||||
|
||||
/**
|
||||
* This function initializes the alarm service used by OpenThread.
|
||||
*
|
||||
*/
|
||||
void efr32AlarmInit(void);
|
||||
|
||||
/**
|
||||
* This function provides the remaining time (in milliseconds) on an alarm service.
|
||||
*
|
||||
* @param[in] aInstance The OpenThread instance structure.
|
||||
*
|
||||
*/
|
||||
uint64_t efr32AlarmPendingTime(otInstance *aInstance);
|
||||
|
||||
/**
|
||||
* This function checks if the alarm service is running.
|
||||
*
|
||||
* @param[in] aInstance The OpenThread instance structure.
|
||||
*
|
||||
*/
|
||||
bool efr32AlarmIsRunning(otInstance *aInstance);
|
||||
|
||||
/**
|
||||
* This function performs alarm driver processing.
|
||||
*
|
||||
* @param[in] aInstance The OpenThread instance structure.
|
||||
*
|
||||
*/
|
||||
void efr32AlarmProcess(otInstance *aInstance);
|
||||
|
||||
#endif // _ALARM_H
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2023, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file includes compile-time configuration constants for efr32.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __BOARD_CONFIG_H__
|
||||
#define __BOARD_CONFIG_H__
|
||||
|
||||
#if (!defined(RADIO_CONFIG_SUBGHZ_SUPPORT) || !RADIO_CONFIG_SUBGHZ_SUPPORT)
|
||||
#define RADIO_CONFIG_2P4GHZ_OQPSK_SUPPORT 1 /// Enable OQPSK modulation in 2.4GHz band
|
||||
#define RADIO_CONFIG_915MHZ_OQPSK_SUPPORT 0 /// Dev board doesn't support OQPSK modulation in 915MHz band.
|
||||
#endif
|
||||
|
||||
#ifndef RADIO_CONFIG_DEBUG_COUNTERS_SUPPORT
|
||||
#define RADIO_CONFIG_DEBUG_COUNTERS_SUPPORT 0 /// Set to 1 to enable debug counters in radio.c
|
||||
#endif
|
||||
|
||||
#ifndef RADIO_CONFIG_ENABLE_CUSTOM_EUI_SUPPORT
|
||||
#define RADIO_CONFIG_ENABLE_CUSTOM_EUI_SUPPORT 1 /// Set to 1 to enable custom EUI support (enabled by default)
|
||||
#endif
|
||||
|
||||
#ifndef RADIO_CONFIG_DMP_SUPPORT
|
||||
#define RADIO_CONFIG_DMP_SUPPORT 0 /// Set to 1 to enable Dynamic Multi-Protocol support in radio.c
|
||||
#endif
|
||||
|
||||
#endif // __BOARD_CONFIG_H__
|
||||
796
Libs/protocol/openthread/platform-abstraction/efr32/crypto.c
Normal file
796
Libs/protocol/openthread/platform-abstraction/efr32/crypto.c
Normal file
@@ -0,0 +1,796 @@
|
||||
/*
|
||||
* Copyright (c) 2023, 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 platform abstraction for PSA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <openthread-core-config.h>
|
||||
#include <openthread/error.h>
|
||||
#include <openthread/platform/crypto.h>
|
||||
|
||||
#if OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_PSA
|
||||
#include "security_manager.h"
|
||||
#include "common/debug.hpp"
|
||||
#include "utils/code_utils.h"
|
||||
|
||||
#include "em_device.h"
|
||||
#include <mbedtls/ecdsa.h>
|
||||
#include <mbedtls/md.h>
|
||||
#include <mbedtls/pk.h>
|
||||
#include "mbedtls/psa_util.h"
|
||||
#if defined(_SILICON_LABS_32B_SERIES_2)
|
||||
#include "em_system.h"
|
||||
#else
|
||||
#include "sl_hal_system.h"
|
||||
#endif
|
||||
#include "sl_psa_crypto.h"
|
||||
|
||||
#if defined(_SILICON_LABS_32B_SERIES_2)
|
||||
#define GET_SECURITY_CAPABILITY SYSTEM_GetSecurityCapability
|
||||
#define VAULT_ENABLED securityCapabilityVault
|
||||
#else
|
||||
#define GET_SECURITY_CAPABILITY sl_hal_system_get_security_capability
|
||||
#define VAULT_ENABLED SL_SYSTEM_SECURITY_CAPABILITY_VAULT
|
||||
#endif
|
||||
|
||||
#define PERSISTENCE_KEY_ID_USED_MAX (7)
|
||||
#define MAX_HMAC_KEY_SIZE (32)
|
||||
|
||||
// Helper function to convert otCryptoKeyType to psa_key_type_t
|
||||
static psa_key_type_t getPsaKeyType(otCryptoKeyType aKeyType)
|
||||
{
|
||||
psa_key_type_t aPsaKeyType = 0;
|
||||
|
||||
switch (aKeyType)
|
||||
{
|
||||
case OT_CRYPTO_KEY_TYPE_RAW:
|
||||
aPsaKeyType = PSA_KEY_TYPE_RAW_DATA;
|
||||
break;
|
||||
|
||||
case OT_CRYPTO_KEY_TYPE_AES:
|
||||
aPsaKeyType = PSA_KEY_TYPE_AES;
|
||||
break;
|
||||
|
||||
case OT_CRYPTO_KEY_TYPE_HMAC:
|
||||
aPsaKeyType = PSA_KEY_TYPE_HMAC;
|
||||
break;
|
||||
|
||||
case OT_CRYPTO_KEY_TYPE_ECDSA:
|
||||
aPsaKeyType = PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1);
|
||||
break;
|
||||
}
|
||||
|
||||
return aPsaKeyType;
|
||||
}
|
||||
|
||||
// Helper function to convert aKeyAlgorithm to psa_algorithm_t
|
||||
static psa_algorithm_t getPsaAlgorithm(otCryptoKeyAlgorithm aKeyAlgorithm)
|
||||
{
|
||||
psa_algorithm_t aPsaKeyAlgorithm = 0;
|
||||
|
||||
switch (aKeyAlgorithm)
|
||||
{
|
||||
case OT_CRYPTO_KEY_ALG_VENDOR:
|
||||
aPsaKeyAlgorithm = PSA_ALG_VENDOR_FLAG;
|
||||
break;
|
||||
|
||||
case OT_CRYPTO_KEY_ALG_AES_ECB:
|
||||
aPsaKeyAlgorithm = PSA_ALG_ECB_NO_PADDING;
|
||||
break;
|
||||
|
||||
case OT_CRYPTO_KEY_ALG_HMAC_SHA_256:
|
||||
aPsaKeyAlgorithm = PSA_ALG_HMAC(PSA_ALG_SHA_256);
|
||||
break;
|
||||
|
||||
case OT_CRYPTO_KEY_ALG_ECDSA:
|
||||
aPsaKeyAlgorithm = PSA_ALG_ECDSA(PSA_ALG_ANY_HASH);
|
||||
break;
|
||||
}
|
||||
|
||||
return aPsaKeyAlgorithm;
|
||||
}
|
||||
|
||||
// Helper function to convert aKeyUsage to psa_key_usage_t
|
||||
static psa_key_usage_t getPsaKeyUsage(int aKeyUsage)
|
||||
{
|
||||
psa_key_usage_t aPsaKeyUsage = 0;
|
||||
|
||||
if (aKeyUsage & OT_CRYPTO_KEY_USAGE_EXPORT)
|
||||
{
|
||||
aPsaKeyUsage |= PSA_KEY_USAGE_EXPORT;
|
||||
}
|
||||
|
||||
if (aKeyUsage & OT_CRYPTO_KEY_USAGE_ENCRYPT)
|
||||
{
|
||||
aPsaKeyUsage |= PSA_KEY_USAGE_ENCRYPT;
|
||||
}
|
||||
|
||||
if (aKeyUsage & OT_CRYPTO_KEY_USAGE_DECRYPT)
|
||||
{
|
||||
aPsaKeyUsage |= PSA_KEY_USAGE_DECRYPT;
|
||||
}
|
||||
|
||||
if (aKeyUsage & OT_CRYPTO_KEY_USAGE_SIGN_HASH)
|
||||
{
|
||||
aPsaKeyUsage |= PSA_KEY_USAGE_SIGN_HASH;
|
||||
}
|
||||
|
||||
if (aKeyUsage & OT_CRYPTO_KEY_USAGE_VERIFY_HASH)
|
||||
{
|
||||
aPsaKeyUsage |= PSA_KEY_USAGE_VERIFY_HASH;
|
||||
}
|
||||
|
||||
return aPsaKeyUsage;
|
||||
}
|
||||
|
||||
// Helper function to convert otCryptoKeyStorage to psa_key_persistence_t
|
||||
static psa_key_persistence_t getPsaKeyPersistence(otCryptoKeyStorage aKeyPersistence)
|
||||
{
|
||||
psa_key_persistence_t aPsaKeyPersistence = 0;
|
||||
|
||||
switch (aKeyPersistence)
|
||||
{
|
||||
case OT_CRYPTO_KEY_STORAGE_VOLATILE:
|
||||
aPsaKeyPersistence = PSA_KEY_PERSISTENCE_VOLATILE;
|
||||
break;
|
||||
|
||||
case OT_CRYPTO_KEY_STORAGE_PERSISTENT:
|
||||
aPsaKeyPersistence = PSA_KEY_PERSISTENCE_DEFAULT;
|
||||
break;
|
||||
}
|
||||
|
||||
return aPsaKeyPersistence;
|
||||
}
|
||||
|
||||
#if defined(SEMAILBOX_PRESENT) && !defined(SL_TRUSTZONE_NONSECURE)
|
||||
static bool shouldWrap(psa_key_attributes_t *key_attr)
|
||||
{
|
||||
psa_key_location_t keyLocation = PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(key_attr));
|
||||
psa_key_type_t keyType = psa_get_key_type(key_attr);
|
||||
|
||||
return ((keyLocation != SL_PSA_KEY_LOCATION_WRAPPED) && (keyType != PSA_KEY_TYPE_HMAC));
|
||||
}
|
||||
|
||||
static void checkAndWrapKeys(void)
|
||||
{
|
||||
for (int index = 1; index <= PERSISTENCE_KEY_ID_USED_MAX; index++)
|
||||
{
|
||||
otCryptoKeyRef key_ref = OPENTHREAD_CONFIG_PSA_ITS_NVM_OFFSET + index;
|
||||
psa_key_attributes_t key_attr = PSA_KEY_ATTRIBUTES_INIT;
|
||||
|
||||
// If there is a key present in the location..
|
||||
if (sl_sec_man_get_key_attributes(key_ref, &key_attr) == PSA_SUCCESS)
|
||||
{
|
||||
if (shouldWrap(&key_attr))
|
||||
{
|
||||
// Wrap the key..
|
||||
otCryptoKeyRef dst_key_ref = key_ref;
|
||||
psa_key_lifetime_t key_lifetime =
|
||||
PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(PSA_KEY_PERSISTENCE_DEFAULT,
|
||||
SL_PSA_KEY_LOCATION_WRAPPED);
|
||||
|
||||
psa_set_key_lifetime(&key_attr, key_lifetime);
|
||||
sl_sec_man_copy_key(key_ref, &key_attr, &dst_key_ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // SEMAILBOX_PRESENT && !SL_TRUSTZONE_NONSECURE
|
||||
|
||||
void otPlatCryptoInit(void)
|
||||
{
|
||||
#if defined(SEMAILBOX_PRESENT) && !defined(SL_TRUSTZONE_NONSECURE)
|
||||
if (GET_SECURITY_CAPABILITY() == VAULT_ENABLED)
|
||||
{
|
||||
checkAndWrapKeys();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static otError extractPrivateKeyFromDer(uint8_t *aPrivateKey, const uint8_t *aDer, uint8_t aDerLen)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
mbedtls_pk_context pk;
|
||||
mbedtls_ecp_keypair *keyPair;
|
||||
|
||||
mbedtls_pk_init(&pk);
|
||||
|
||||
otEXPECT_ACTION(mbedtls_pk_setup(&pk, mbedtls_pk_info_from_type(MBEDTLS_PK_ECKEY)) == 0, error = OT_ERROR_FAILED);
|
||||
|
||||
#if (MBEDTLS_VERSION_NUMBER >= 0x03000000)
|
||||
otEXPECT_ACTION(mbedtls_pk_parse_key(&pk, aDer, aDerLen, NULL, 0, mbedtls_psa_get_random, MBEDTLS_PSA_RANDOM_STATE)
|
||||
== 0,
|
||||
error = OT_ERROR_PARSE);
|
||||
#else
|
||||
otEXPECT_ACTION(mbedtls_pk_parse_key(&pk, aDer, aDerLen, NULL, 0) == 0, error = OT_ERROR_PARSE);
|
||||
#endif
|
||||
|
||||
keyPair = mbedtls_pk_ec(pk);
|
||||
mbedtls_mpi_write_binary(&keyPair->MBEDTLS_PRIVATE(d), aPrivateKey, SL_OPENTHREAD_ECDSA_PRIVATE_KEY_SIZE);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatCryptoImportKey(otCryptoKeyRef *aKeyId,
|
||||
otCryptoKeyType aKeyType,
|
||||
otCryptoKeyAlgorithm aKeyAlgorithm,
|
||||
int aKeyUsage,
|
||||
otCryptoKeyStorage aKeyPersistence,
|
||||
const uint8_t *aKey,
|
||||
size_t aKeyLen)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
psa_status_t status;
|
||||
uint8_t aPrivateKey[SL_OPENTHREAD_ECDSA_PRIVATE_KEY_SIZE];
|
||||
const uint8_t *keyToImport = aKey;
|
||||
size_t keySize = aKeyLen;
|
||||
|
||||
if (aKeyType == OT_CRYPTO_KEY_TYPE_ECDSA)
|
||||
{
|
||||
error = extractPrivateKeyFromDer(aPrivateKey, aKey, aKeyLen);
|
||||
keyToImport = aPrivateKey;
|
||||
keySize = SL_OPENTHREAD_ECDSA_PRIVATE_KEY_SIZE;
|
||||
}
|
||||
|
||||
status = sl_sec_man_import_key(aKeyId,
|
||||
getPsaKeyType(aKeyType),
|
||||
getPsaAlgorithm(aKeyAlgorithm),
|
||||
getPsaKeyUsage(aKeyUsage),
|
||||
getPsaKeyPersistence(aKeyPersistence),
|
||||
keyToImport,
|
||||
keySize);
|
||||
|
||||
otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatCryptoExportKey(otCryptoKeyRef aKeyId, uint8_t *aBuffer, size_t aBufferLen, size_t *aKeyLen)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
psa_status_t status;
|
||||
|
||||
status = sl_sec_man_export_key(aKeyId, aBuffer, aBufferLen, aKeyLen);
|
||||
|
||||
otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatCryptoDestroyKey(otCryptoKeyRef aKeyId)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
psa_status_t status;
|
||||
|
||||
status = sl_sec_man_destroy_key(aKeyId);
|
||||
|
||||
otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
bool otPlatCryptoHasKey(otCryptoKeyRef aKeyRef)
|
||||
{
|
||||
psa_key_attributes_t aAttr = PSA_KEY_ATTRIBUTES_INIT;
|
||||
|
||||
return (sl_sec_man_get_key_attributes(aKeyRef, &aAttr) == PSA_SUCCESS);
|
||||
}
|
||||
|
||||
// AES Implementation
|
||||
otError otPlatCryptoAesInit(otCryptoContext *aContext)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
(void)aContext;
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatCryptoAesSetKey(otCryptoContext *aContext, const otCryptoKey *aKey)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
otCryptoKeyRef *mKeyRef = NULL;
|
||||
|
||||
otEXPECT_ACTION((aContext != NULL) && (aContext->mContext != NULL), error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
mKeyRef = (otCryptoKeyRef *)aContext->mContext;
|
||||
*mKeyRef = aKey->mKeyRef;
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatCryptoAesEncrypt(otCryptoContext *aContext, const uint8_t *aInput, uint8_t *aOutput)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
psa_status_t status;
|
||||
otCryptoKeyRef *mKeyRef = NULL;
|
||||
|
||||
otEXPECT_ACTION(((aContext != NULL) && (aContext->mContext != NULL) && (aOutput != NULL) && (aInput != NULL)),
|
||||
error = OT_ERROR_INVALID_ARGS);
|
||||
mKeyRef = (otCryptoKeyRef *)aContext->mContext;
|
||||
status = sl_sec_man_aes_encrypt(*mKeyRef, PSA_ALG_ECB_NO_PADDING, aInput, aOutput);
|
||||
|
||||
otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatCryptoAesFree(otCryptoContext *aContext)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
(void)aContext;
|
||||
return error;
|
||||
}
|
||||
|
||||
// HMAC implementations
|
||||
otError otPlatCryptoHmacSha256Init(otCryptoContext *aContext)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
psa_mac_operation_t *mMacOperation = (psa_mac_operation_t *)aContext->mContext;
|
||||
*mMacOperation = psa_mac_operation_init();
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatCryptoHmacSha256Deinit(otCryptoContext *aContext)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
psa_mac_operation_t *mMacOperation = (psa_mac_operation_t *)aContext->mContext;
|
||||
psa_status_t status;
|
||||
|
||||
status = sl_sec_man_hmac_deinit(mMacOperation);
|
||||
|
||||
otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
static psa_status_t reImportUnwrapped(const otCryptoKey *aKey, otCryptoKeyRef *aHmacKeyRef)
|
||||
{
|
||||
psa_status_t status = PSA_SUCCESS;
|
||||
|
||||
#if defined(SEMAILBOX_PRESENT)
|
||||
uint8_t hmacKeyBytes[MAX_HMAC_KEY_SIZE];
|
||||
size_t key_size;
|
||||
psa_key_attributes_t key_attr = PSA_KEY_ATTRIBUTES_INIT;
|
||||
|
||||
status = sl_sec_man_get_key_attributes(aKey->mKeyRef, &key_attr);
|
||||
|
||||
otEXPECT(status == PSA_SUCCESS);
|
||||
|
||||
status = sl_sec_man_export_key(aKey->mKeyRef, hmacKeyBytes, sizeof(hmacKeyBytes), &key_size);
|
||||
|
||||
otEXPECT(status == PSA_SUCCESS);
|
||||
|
||||
status = sl_sec_man_import_key(aHmacKeyRef,
|
||||
psa_get_key_type(&key_attr),
|
||||
psa_get_key_algorithm(&key_attr),
|
||||
psa_get_key_usage_flags(&key_attr),
|
||||
PSA_KEY_PERSISTENCE_VOLATILE,
|
||||
hmacKeyBytes,
|
||||
key_size);
|
||||
|
||||
memset(hmacKeyBytes, 0, sizeof(hmacKeyBytes));
|
||||
|
||||
otEXPECT(status == PSA_SUCCESS);
|
||||
|
||||
exit:
|
||||
#else
|
||||
*aHmacKeyRef = aKey->mKeyRef;
|
||||
#endif
|
||||
return status;
|
||||
}
|
||||
|
||||
otError otPlatCryptoHmacSha256Start(otCryptoContext *aContext, const otCryptoKey *aKey)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
psa_mac_operation_t *mMacOperation = (psa_mac_operation_t *)aContext->mContext;
|
||||
psa_status_t status;
|
||||
otCryptoKeyRef hmacKeyRef;
|
||||
|
||||
status = reImportUnwrapped(aKey, &hmacKeyRef);
|
||||
otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
status = sl_sec_man_hmac_start(mMacOperation, hmacKeyRef);
|
||||
otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
#if defined(SEMAILBOX_PRESENT)
|
||||
sl_sec_man_destroy_key(hmacKeyRef);
|
||||
#else
|
||||
hmacKeyRef = 0;
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatCryptoHmacSha256Update(otCryptoContext *aContext, const void *aBuf, uint16_t aBufLength)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
psa_mac_operation_t *mMacOperation = (psa_mac_operation_t *)aContext->mContext;
|
||||
psa_status_t status;
|
||||
|
||||
status = sl_sec_man_hmac_update(mMacOperation, (const uint8_t *)aBuf, (size_t)aBufLength);
|
||||
|
||||
otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatCryptoHmacSha256Finish(otCryptoContext *aContext, uint8_t *aBuf, size_t aBufLength)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
psa_mac_operation_t *mMacOperation = (psa_mac_operation_t *)aContext->mContext;
|
||||
psa_status_t status;
|
||||
|
||||
status = sl_sec_man_hmac_finish(mMacOperation, aBuf, aBufLength);
|
||||
|
||||
otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
// HKDF platform implementations
|
||||
// As the HKDF does not actually use mbedTLS APIs but uses HMAC module, this feature is not implemented.
|
||||
otError otPlatCryptoHkdfExpand(otCryptoContext *aContext,
|
||||
const uint8_t *aInfo,
|
||||
uint16_t aInfoLength,
|
||||
uint8_t *aOutputKey,
|
||||
uint16_t aOutputKeyLength)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
psa_status_t status;
|
||||
|
||||
otEXPECT_ACTION(((aContext != NULL) && (aContext->mContext != NULL) && (aInfo != NULL) && (aOutputKey != NULL)),
|
||||
error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
status = sl_sec_man_key_derivation_expand(aContext->mContext, aInfo, aInfoLength, aOutputKey, aOutputKeyLength);
|
||||
|
||||
otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatCryptoHkdfExtract(otCryptoContext *aContext,
|
||||
const uint8_t *aSalt,
|
||||
uint16_t aSaltLength,
|
||||
const otCryptoKey *aKey)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
psa_status_t status;
|
||||
|
||||
otEXPECT_ACTION(
|
||||
((aContext != NULL) && (aContext->mContext != NULL) && (aKey != NULL) && (aSalt != NULL) && (aSaltLength != 0)),
|
||||
error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
status = sl_sec_man_key_derivation_extract(aContext->mContext, PSA_ALG_SHA_256, aKey->mKeyRef, aSalt, aSaltLength);
|
||||
|
||||
otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
// SHA256 platform implementations
|
||||
otError otPlatCryptoSha256Init(otCryptoContext *aContext)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
otEXPECT_ACTION((aContext != NULL), error = OT_ERROR_INVALID_ARGS);
|
||||
psa_hash_operation_t *ctx = (psa_hash_operation_t *)aContext->mContext;
|
||||
|
||||
otEXPECT_ACTION((ctx != NULL), error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
*ctx = sl_sec_man_hash_init();
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatCryptoSha256Deinit(otCryptoContext *aContext)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
otEXPECT_ACTION((aContext != NULL), error = OT_ERROR_INVALID_ARGS);
|
||||
psa_hash_operation_t *ctx = (psa_hash_operation_t *)aContext->mContext;
|
||||
|
||||
otEXPECT_ACTION((ctx != NULL), error = OT_ERROR_INVALID_ARGS);
|
||||
otEXPECT_ACTION((sl_sec_man_hash_deinit(ctx) == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatCryptoSha256Start(otCryptoContext *aContext)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
otEXPECT_ACTION((aContext != NULL), error = OT_ERROR_INVALID_ARGS);
|
||||
psa_hash_operation_t *ctx = (psa_hash_operation_t *)aContext->mContext;
|
||||
|
||||
otEXPECT_ACTION((ctx != NULL), error = OT_ERROR_INVALID_ARGS);
|
||||
otEXPECT_ACTION((sl_sec_man_hash_start(ctx, PSA_ALG_SHA_256) == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatCryptoSha256Update(otCryptoContext *aContext, const void *aBuf, uint16_t aBufLength)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
otEXPECT_ACTION((aContext != NULL), error = OT_ERROR_INVALID_ARGS);
|
||||
psa_hash_operation_t *ctx = (psa_hash_operation_t *)aContext->mContext;
|
||||
|
||||
otEXPECT_ACTION(((ctx != NULL) && (aBuf != NULL)), error = OT_ERROR_INVALID_ARGS);
|
||||
otEXPECT_ACTION((sl_sec_man_hash_update(ctx, (uint8_t *)aBuf, aBufLength) == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatCryptoSha256Finish(otCryptoContext *aContext, uint8_t *aHash, uint16_t aHashSize)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
size_t aHashLength = 0;
|
||||
otEXPECT_ACTION((aContext != NULL), error = OT_ERROR_INVALID_ARGS);
|
||||
psa_hash_operation_t *ctx = (psa_hash_operation_t *)aContext->mContext;
|
||||
|
||||
otEXPECT_ACTION(((ctx != NULL) && (aHash != NULL)), error = OT_ERROR_INVALID_ARGS);
|
||||
otEXPECT_ACTION((sl_sec_man_hash_finish(ctx, aHash, aHashSize, &aHashLength) == PSA_SUCCESS),
|
||||
error = OT_ERROR_FAILED);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatCryptoEcdsaGenerateAndImportKey(otCryptoKeyRef aKeyRef)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
size_t aKeyLength = 256;
|
||||
psa_status_t status;
|
||||
|
||||
status = sl_sec_man_generate_key(&aKeyRef,
|
||||
PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1),
|
||||
PSA_ALG_ECDSA(PSA_ALG_ANY_HASH),
|
||||
(PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_VERIFY_HASH),
|
||||
PSA_KEY_LIFETIME_PERSISTENT,
|
||||
aKeyLength);
|
||||
|
||||
otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatCryptoEcdsaExportPublicKey(otCryptoKeyRef aKeyRef, otPlatCryptoEcdsaPublicKey *aPublicKey)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
size_t aKeyLength;
|
||||
psa_status_t status;
|
||||
uint8_t aByteArray[OT_CRYPTO_ECDSA_PUBLIC_KEY_SIZE + 1];
|
||||
|
||||
otEXPECT_ACTION((aPublicKey != NULL), error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
// Use byte array to get the public key because PSA adds a encoding header at the beginning of the array.
|
||||
// It is easier to export it to a byte array and copy only the public key to output array.
|
||||
status = sl_sec_man_export_public_key(aKeyRef, aByteArray, sizeof(aByteArray), &aKeyLength);
|
||||
|
||||
memcpy(aPublicKey->m8, &aByteArray[1], OT_CRYPTO_ECDSA_PUBLIC_KEY_SIZE);
|
||||
otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatCryptoEcdsaSignUsingKeyRef(otCryptoKeyRef aKeyRef,
|
||||
const otPlatCryptoSha256Hash *aHash,
|
||||
otPlatCryptoEcdsaSignature *aSignature)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
size_t aSignatureLength;
|
||||
psa_status_t status;
|
||||
bool aIsHash = true;
|
||||
|
||||
otEXPECT_ACTION(((aHash != NULL) && (aSignature != NULL)), error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
status = sl_sec_man_sign(aKeyRef,
|
||||
PSA_ALG_ECDSA(PSA_ALG_SHA_256),
|
||||
aHash->m8,
|
||||
sizeof(aHash->m8),
|
||||
aSignature->m8,
|
||||
sizeof(aSignature->m8),
|
||||
&aSignatureLength,
|
||||
aIsHash);
|
||||
|
||||
otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatCryptoEcdsaVerifyUsingKeyRef(otCryptoKeyRef aKeyRef,
|
||||
const otPlatCryptoSha256Hash *aHash,
|
||||
const otPlatCryptoEcdsaSignature *aSignature)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
psa_status_t status;
|
||||
bool aIsHash = true;
|
||||
|
||||
otEXPECT_ACTION(((aHash != NULL) && (aSignature != NULL)), error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
// Verify the signature.
|
||||
status = sl_sec_man_verify(aKeyRef,
|
||||
PSA_ALG_ECDSA(PSA_ALG_SHA_256),
|
||||
aHash->m8,
|
||||
sizeof(aHash->m8),
|
||||
aSignature->m8,
|
||||
sizeof(aSignature->m8),
|
||||
aIsHash);
|
||||
|
||||
otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatCryptoPbkdf2GenerateKey(const uint8_t *aPassword,
|
||||
uint16_t aPasswordLen,
|
||||
const uint8_t *aSalt,
|
||||
uint16_t aSaltLen,
|
||||
uint32_t aIterationCounter,
|
||||
uint16_t aKeyLen,
|
||||
uint8_t *aKey)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
psa_status_t status;
|
||||
size_t outSize;
|
||||
psa_key_id_t passwordKeyId = 0;
|
||||
psa_key_id_t saltKeyId = 0;
|
||||
psa_key_id_t keyId = 0;
|
||||
|
||||
// Algorithm is PBKDF2-AES-CMAC-PRF-128
|
||||
psa_algorithm_t algo = PSA_ALG_PBKDF2_AES_CMAC_PRF_128;
|
||||
|
||||
// Initialize key derivation
|
||||
psa_key_derivation_operation_t operation = psa_key_derivation_operation_init();
|
||||
status = psa_key_derivation_setup(&operation, algo);
|
||||
otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
// Set capacity
|
||||
status = psa_key_derivation_set_capacity(&operation, aKeyLen);
|
||||
otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
// Set iteration count as cost
|
||||
status = psa_key_derivation_input_integer(&operation, PSA_KEY_DERIVATION_INPUT_COST, aIterationCounter);
|
||||
otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
// Create salt as a key
|
||||
psa_key_attributes_t saltKeyAttr = psa_key_attributes_init();
|
||||
psa_set_key_usage_flags(&saltKeyAttr, PSA_KEY_USAGE_DERIVE);
|
||||
psa_set_key_type(&saltKeyAttr, PSA_KEY_TYPE_RAW_DATA);
|
||||
psa_set_key_algorithm(&saltKeyAttr, algo);
|
||||
otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
status = psa_import_key(&saltKeyAttr, aSalt, aSaltLen, &saltKeyId);
|
||||
otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
// Provide salt
|
||||
status = psa_key_derivation_input_key(&operation, PSA_KEY_DERIVATION_INPUT_SALT, saltKeyId);
|
||||
otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
// Create key for password (key)
|
||||
psa_key_attributes_t passwordKeyAttr = psa_key_attributes_init();
|
||||
psa_set_key_usage_flags(&passwordKeyAttr, PSA_KEY_USAGE_DERIVE);
|
||||
psa_set_key_type(&passwordKeyAttr, PSA_KEY_TYPE_PASSWORD);
|
||||
psa_set_key_algorithm(&passwordKeyAttr, algo);
|
||||
|
||||
status = psa_import_key(&passwordKeyAttr, aPassword, aPasswordLen, &passwordKeyId);
|
||||
otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
// Provide password (key)
|
||||
status = psa_key_derivation_input_key(&operation, PSA_KEY_DERIVATION_INPUT_PASSWORD, passwordKeyId);
|
||||
otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
// Configure output as a key
|
||||
psa_key_attributes_t keyAttrResult = psa_key_attributes_init();
|
||||
psa_set_key_bits(&keyAttrResult, (8 * aKeyLen));
|
||||
psa_set_key_usage_flags(&keyAttrResult, PSA_KEY_USAGE_EXPORT);
|
||||
psa_set_key_type(&keyAttrResult, PSA_KEY_TYPE_RAW_DATA);
|
||||
psa_set_key_algorithm(&keyAttrResult, PSA_ALG_CTR);
|
||||
|
||||
status = psa_key_derivation_output_key(&keyAttrResult, &operation, &keyId);
|
||||
otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
// Export output key
|
||||
status = psa_export_key(keyId, aKey, aKeyLen, &outSize);
|
||||
otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
// Release keys used
|
||||
psa_destroy_key(keyId);
|
||||
psa_destroy_key(saltKeyId);
|
||||
psa_destroy_key(passwordKeyId);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatCryptoEcdsaVerify(const otPlatCryptoEcdsaPublicKey *aPublicKey,
|
||||
const otPlatCryptoSha256Hash *aHash,
|
||||
const otPlatCryptoEcdsaSignature *aSignature)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
psa_status_t status;
|
||||
bool aIsHash = true;
|
||||
uint8_t aByteArray[OT_CRYPTO_ECDSA_PUBLIC_KEY_SIZE + 1];
|
||||
otCryptoKeyRef aKeyId;
|
||||
|
||||
otEXPECT_ACTION(((aPublicKey != NULL) && (aHash != NULL) && (aSignature != NULL)), error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
// Public key needs a extra byt of encoding header, which has a value of 0x04, to be included for PSA to validate
|
||||
// and process the publc key. Copy the key into a new temp array and append the encoding header to it.
|
||||
aByteArray[0] = 0x04;
|
||||
memcpy(&aByteArray[1], aPublicKey, OT_CRYPTO_ECDSA_PUBLIC_KEY_SIZE);
|
||||
|
||||
// Import the public key into a temp slot.
|
||||
status = sl_sec_man_import_key(&aKeyId,
|
||||
PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_FAMILY_SECP_R1),
|
||||
PSA_ALG_ECDSA(PSA_ALG_ANY_HASH),
|
||||
PSA_KEY_USAGE_VERIFY_HASH,
|
||||
PSA_KEY_PERSISTENCE_VOLATILE,
|
||||
aByteArray,
|
||||
OT_CRYPTO_ECDSA_PUBLIC_KEY_SIZE + 1); // To account for the padded byte.
|
||||
|
||||
// If key import fails, assert, as we cannot proceed
|
||||
OT_ASSERT(status == PSA_SUCCESS);
|
||||
|
||||
// Verify the signature.
|
||||
status = sl_sec_man_verify(aKeyId,
|
||||
PSA_ALG_ECDSA(PSA_ALG_SHA_256),
|
||||
aHash->m8,
|
||||
sizeof(aHash->m8),
|
||||
aSignature->m8,
|
||||
sizeof(aSignature->m8),
|
||||
aIsHash);
|
||||
|
||||
// Destroy the temp key.
|
||||
sl_sec_man_destroy_key(aKeyId);
|
||||
|
||||
otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_PSA
|
||||
473
Libs/protocol/openthread/platform-abstraction/efr32/diag.c
Normal file
473
Libs/protocol/openthread/platform-abstraction/efr32/diag.c
Normal file
@@ -0,0 +1,473 @@
|
||||
/*
|
||||
* Copyright (c) 2023, 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 platform abstraction for the diagnostics.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#ifdef SL_COMPONENT_CATALOG_PRESENT
|
||||
#include "sl_component_catalog.h"
|
||||
#endif // SL_COMPONENT_CATALOG_PRESENT
|
||||
|
||||
#include <openthread-core-config.h>
|
||||
#include <utils/code_utils.h>
|
||||
#include <openthread/cli.h>
|
||||
#include <openthread/platform/alarm-milli.h>
|
||||
#include <openthread/platform/diag.h>
|
||||
#include <openthread/platform/radio.h>
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
#include "common/logging.hpp"
|
||||
|
||||
#include "diag.h"
|
||||
|
||||
#include "sl_gpio.h"
|
||||
#include "sl_hal_gpio.h"
|
||||
|
||||
#include "platform-band.h"
|
||||
#include "platform-efr32.h"
|
||||
#include "rail_ieee802154.h"
|
||||
|
||||
#include "sl_status.h"
|
||||
|
||||
#if OPENTHREAD_CONFIG_DIAG_ENABLE
|
||||
|
||||
#ifdef SL_COMPONENT_CATALOG_PRESENT
|
||||
#include "sl_component_catalog.h"
|
||||
#endif // SL_COMPONENT_CATALOG_PRESENT
|
||||
|
||||
#ifdef SL_CATALOG_RAIL_UTIL_ANT_DIV_PRESENT
|
||||
#include "sl_rail_util_ant_div.h"
|
||||
#endif
|
||||
|
||||
#define GPIO_PIN_BITMASK 0xFFFFUL
|
||||
#define GPIO_PORT_BITMASK (0xFFFFUL << 16)
|
||||
#define GET_GPIO_PIN(x) (x & GPIO_PIN_BITMASK)
|
||||
#define GET_GPIO_PORT(x) ((x & GPIO_PORT_BITMASK) >> 16)
|
||||
|
||||
// To cache the transmit power, so that we don't override it while loading the
|
||||
// channel config or setting the channel.
|
||||
static int8_t sTxPower = OPENTHREAD_CONFIG_DEFAULT_TRANSMIT_POWER;
|
||||
|
||||
struct PlatformDiagCommand
|
||||
{
|
||||
const char *mName;
|
||||
otError (*mCommand)(otInstance *aInstance, uint8_t aArgsLength, char *aArgs[]);
|
||||
};
|
||||
|
||||
// Diagnostics mode variables.
|
||||
static bool sDiagMode = false;
|
||||
|
||||
static otPlatDiagOutputCallback sDiagOutputCallback = NULL;
|
||||
static void *sDiagCallbackContext = NULL;
|
||||
|
||||
static void diagOutput(const char *aFormat, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, aFormat);
|
||||
|
||||
if (sDiagOutputCallback != NULL)
|
||||
{
|
||||
sDiagOutputCallback(aFormat, args, sDiagCallbackContext);
|
||||
}
|
||||
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
static void appendErrorResult(otError aError)
|
||||
{
|
||||
if (aError != OT_ERROR_NONE)
|
||||
{
|
||||
diagOutput("failed\r\nstatus %#x\r\n", aError);
|
||||
}
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// CLI functions
|
||||
// *****************************************************************************
|
||||
static otError processAddressMatch(otInstance *aInstance, uint8_t aArgsLength, char *aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
otError error = OT_ERROR_INVALID_ARGS;
|
||||
|
||||
VerifyOrExit(otPlatDiagModeGet(), error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(aArgsLength > 0, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
if (strcmp(aArgs[0], "enable") == 0)
|
||||
{
|
||||
error = otPlatDiagRadioAddressMatch(true);
|
||||
}
|
||||
else if (strcmp(aArgs[0], "disable") == 0)
|
||||
{
|
||||
error = otPlatDiagRadioAddressMatch(false);
|
||||
}
|
||||
|
||||
exit:
|
||||
appendErrorResult(error);
|
||||
return error;
|
||||
}
|
||||
|
||||
static otError processAutoAck(otInstance *aInstance, uint8_t aArgsLength, char *aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
otError error = OT_ERROR_INVALID_ARGS;
|
||||
|
||||
VerifyOrExit(otPlatDiagModeGet(), error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(aArgsLength > 0, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
if (strcmp(aArgs[0], "enable") == 0)
|
||||
{
|
||||
error = otPlatDiagRadioAutoAck(true);
|
||||
}
|
||||
else if (strcmp(aArgs[0], "disable") == 0)
|
||||
{
|
||||
error = otPlatDiagRadioAutoAck(false);
|
||||
}
|
||||
|
||||
exit:
|
||||
appendErrorResult(error);
|
||||
return error;
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// Add more platform specific diagnostic's CLI features here.
|
||||
// *****************************************************************************
|
||||
const struct PlatformDiagCommand sCommands[] = {
|
||||
{"addr-match", &processAddressMatch},
|
||||
{"auto-ack", &processAutoAck},
|
||||
};
|
||||
|
||||
otError otPlatDiagProcess(otInstance *aInstance, uint8_t aArgsLength, char *aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_COMMAND;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < otARRAY_LENGTH(sCommands); i++)
|
||||
{
|
||||
if (strcmp(aArgs[0], sCommands[i].mName) == 0)
|
||||
{
|
||||
error = sCommands[i].mCommand(aInstance, aArgsLength - 1, aArgsLength > 1 ? &aArgs[1] : NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// Implement platform specific diagnostic's APIs.
|
||||
// *****************************************************************************
|
||||
|
||||
void otPlatDiagSetOutputCallback(otInstance *aInstance, otPlatDiagOutputCallback aCallback, void *aContext)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
sDiagOutputCallback = aCallback;
|
||||
sDiagCallbackContext = aContext;
|
||||
}
|
||||
|
||||
void otPlatDiagModeSet(bool aMode)
|
||||
{
|
||||
sDiagMode = aMode;
|
||||
}
|
||||
|
||||
bool otPlatDiagModeGet()
|
||||
{
|
||||
return sDiagMode;
|
||||
}
|
||||
|
||||
static RAIL_Status_t startTxStream(RAIL_StreamMode_t aMode)
|
||||
{
|
||||
uint16_t txChannel;
|
||||
RAIL_Status_t status;
|
||||
|
||||
SuccessOrExit(status = RAIL_GetChannel(gRailHandle, &txChannel));
|
||||
|
||||
#ifdef SL_CATALOG_RAIL_UTIL_ANT_DIV_PRESENT
|
||||
RAIL_TxOptions_t txOptions = RAIL_TX_OPTIONS_DEFAULT;
|
||||
// Translate Tx antenna diversity mode into RAIL Tx Antenna options:
|
||||
// If enabled, use the currently-selected antenna, otherwise leave
|
||||
// both options 0 so Tx antenna tracks Rx antenna.
|
||||
if (sl_rail_util_ant_div_get_tx_antenna_mode() != SL_RAIL_UTIL_ANTENNA_MODE_DISABLED)
|
||||
{
|
||||
txOptions |= ((sl_rail_util_ant_div_get_tx_antenna_selected() == SL_RAIL_UTIL_ANTENNA_SELECT_ANTENNA1)
|
||||
? RAIL_TX_OPTION_ANTENNA0
|
||||
: RAIL_TX_OPTION_ANTENNA1);
|
||||
}
|
||||
|
||||
status = RAIL_StartTxStreamAlt(gRailHandle, txChannel, aMode, txOptions);
|
||||
#else // !SL_CATALOG_RAIL_UTIL_ANT_DIV_PRESENT
|
||||
status = RAIL_StartTxStream(gRailHandle, txChannel, aMode);
|
||||
#endif // SL_CATALOG_RAIL_UTIL_ANT_DIV_PRESENT
|
||||
|
||||
exit:
|
||||
return status;
|
||||
}
|
||||
|
||||
static RAIL_Status_t stopTxStream(void)
|
||||
{
|
||||
RAIL_Status_t status;
|
||||
uint16_t currentChannel;
|
||||
RAIL_SchedulerInfo_t rxSchedulerInfo = {
|
||||
.priority = SL_802154_RADIO_PRIO_BACKGROUND_RX_VALUE,
|
||||
};
|
||||
|
||||
SuccessOrExit(status = RAIL_StopTxStream(gRailHandle));
|
||||
// Since start transmit stream turn off the radio state,
|
||||
// call the RAIL_StartRx to turn on radio
|
||||
IgnoreError(RAIL_GetChannel(gRailHandle, ¤tChannel));
|
||||
|
||||
status = RAIL_StartRx(gRailHandle, currentChannel, &rxSchedulerInfo);
|
||||
OT_ASSERT(status == RAIL_STATUS_NO_ERROR);
|
||||
|
||||
exit:
|
||||
return status;
|
||||
}
|
||||
|
||||
otError otPlatDiagRadioTransmitCarrier(otInstance *aInstance, bool aEnable)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
RAIL_Status_t status;
|
||||
|
||||
if (aEnable)
|
||||
{
|
||||
otLogInfoPlat("Diag CARRIER-WAVE/Tone start");
|
||||
status = startTxStream(RAIL_STREAM_CARRIER_WAVE);
|
||||
}
|
||||
else
|
||||
{
|
||||
otLogInfoPlat("Diag CARRIER-WAVE/Tone stop");
|
||||
status = stopTxStream();
|
||||
}
|
||||
return (status != RAIL_STATUS_NO_ERROR ? OT_ERROR_FAILED : OT_ERROR_NONE);
|
||||
}
|
||||
|
||||
otError otPlatDiagRadioTransmitStream(otInstance *aInstance, bool aEnable)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
RAIL_Status_t status;
|
||||
|
||||
if (aEnable)
|
||||
{
|
||||
otLogInfoPlat("Diag Stream PN9 start");
|
||||
status = startTxStream(RAIL_STREAM_PN9_STREAM);
|
||||
}
|
||||
else
|
||||
{
|
||||
otLogInfoPlat("Diag Stream stop");
|
||||
status = stopTxStream();
|
||||
}
|
||||
return (status != RAIL_STATUS_NO_ERROR ? OT_ERROR_FAILED : OT_ERROR_NONE);
|
||||
}
|
||||
|
||||
otError otPlatDiagRadioAddressMatch(bool aEnable)
|
||||
{
|
||||
RAIL_Status_t status;
|
||||
|
||||
otLogInfoPlat("Diag address-match %s", aEnable ? "enable" : "disable");
|
||||
|
||||
status = RAIL_IEEE802154_SetPromiscuousMode(gRailHandle, !aEnable);
|
||||
return (status != RAIL_STATUS_NO_ERROR ? OT_ERROR_FAILED : OT_ERROR_NONE);
|
||||
}
|
||||
|
||||
otError otPlatDiagRadioAutoAck(bool aAutoAckEnabled)
|
||||
{
|
||||
otLogInfoPlat("Diag auto-ack %s", aAutoAckEnabled ? "enable" : "disable");
|
||||
|
||||
RAIL_PauseRxAutoAck(gRailHandle, !aAutoAckEnabled);
|
||||
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
void otPlatDiagChannelSet(uint8_t aChannel)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
RAIL_Status_t status;
|
||||
|
||||
RAIL_SchedulerInfo_t bgRxSchedulerInfo = {
|
||||
.priority = SL_802154_RADIO_PRIO_BACKGROUND_RX_VALUE,
|
||||
// sliptime/transaction time is not used for bg rx
|
||||
};
|
||||
|
||||
error = efr32RadioLoadChannelConfig(aChannel, sTxPower);
|
||||
OT_ASSERT(error == OT_ERROR_NONE);
|
||||
|
||||
status = RAIL_StartRx(gRailHandle, aChannel, &bgRxSchedulerInfo);
|
||||
OT_ASSERT(status == RAIL_STATUS_NO_ERROR);
|
||||
}
|
||||
|
||||
void otPlatDiagTxPowerSet(int8_t aTxPower)
|
||||
{
|
||||
RAIL_Status_t status;
|
||||
|
||||
// RAIL_SetTxPowerDbm() takes power in units of deci-dBm (0.1dBm)
|
||||
// Multiply by 10 because aPower is supposed be in units dBm
|
||||
status = RAIL_SetTxPowerDbm(gRailHandle, ((RAIL_TxPower_t)aTxPower) * 10);
|
||||
OT_ASSERT(status == RAIL_STATUS_NO_ERROR);
|
||||
sTxPower = aTxPower;
|
||||
}
|
||||
|
||||
void otPlatDiagRadioReceived(otInstance *aInstance, otRadioFrame *aFrame, otError aError)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
OT_UNUSED_VARIABLE(aFrame);
|
||||
OT_UNUSED_VARIABLE(aError);
|
||||
}
|
||||
|
||||
void otPlatDiagAlarmCallback(otInstance *aInstance)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
}
|
||||
|
||||
static otError getGpioPortAndPin(uint32_t aGpio, uint16_t *aPort, uint16_t *aPin)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
*aPort = GET_GPIO_PORT(aGpio);
|
||||
*aPin = GET_GPIO_PIN(aGpio);
|
||||
|
||||
#if defined(SL_CATALOG_GPIO_PRESENT)
|
||||
if (*aPort > SL_HAL_GPIO_PORT_MAX || *aPin > SL_HAL_GPIO_PIN_MAX)
|
||||
#else
|
||||
if (*aPort > GPIO_PORT_MAX || *aPin > GPIO_PIN_MAX)
|
||||
#endif
|
||||
{
|
||||
ExitNow(error = OT_ERROR_INVALID_ARGS);
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatDiagGpioSet(uint32_t aGpio, bool aValue)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint16_t port;
|
||||
uint16_t pin;
|
||||
|
||||
SuccessOrExit(error = getGpioPortAndPin(aGpio, &port, &pin));
|
||||
|
||||
sl_gpio_t gpio;
|
||||
|
||||
gpio.port = (uint8_t)port;
|
||||
gpio.pin = (uint8_t)pin;
|
||||
|
||||
if (aValue)
|
||||
{
|
||||
VerifyOrExit(sl_gpio_set_pin(&gpio) == SL_STATUS_OK, error = OT_ERROR_INVALID_ARGS);
|
||||
}
|
||||
else
|
||||
{
|
||||
VerifyOrExit(sl_gpio_clear_pin(&gpio) == SL_STATUS_OK, error = OT_ERROR_INVALID_ARGS);
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatDiagGpioGet(uint32_t aGpio, bool *aValue)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint16_t port;
|
||||
uint16_t pin;
|
||||
|
||||
SuccessOrExit(error = getGpioPortAndPin(aGpio, &port, &pin));
|
||||
|
||||
sl_gpio_t gpio;
|
||||
|
||||
gpio.port = (uint8_t)port;
|
||||
gpio.pin = (uint8_t)pin;
|
||||
|
||||
VerifyOrExit(sl_gpio_get_pin_input(&gpio, aValue) == SL_STATUS_OK, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatDiagGpioSetMode(uint32_t aGpio, otGpioMode aMode)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint16_t port;
|
||||
uint16_t pin;
|
||||
sl_gpio_mode_t mode;
|
||||
|
||||
SuccessOrExit(error = getGpioPortAndPin(aGpio, &port, &pin));
|
||||
|
||||
mode = (aMode == OT_GPIO_MODE_INPUT) ? SL_GPIO_MODE_INPUT : SL_GPIO_MODE_PUSH_PULL;
|
||||
|
||||
sl_gpio_t gpio;
|
||||
|
||||
gpio.port = (uint8_t)port;
|
||||
gpio.pin = (uint8_t)pin;
|
||||
|
||||
error = sl_gpio_set_pin_mode(&gpio, mode, 0 /*out*/);
|
||||
|
||||
// Convert to otError.
|
||||
VerifyOrExit(error == SL_STATUS_OK,
|
||||
error = (error == SL_STATUS_INVALID_STATE ? OT_ERROR_INVALID_STATE : OT_ERROR_INVALID_ARGS));
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatDiagGpioGetMode(uint32_t aGpio, otGpioMode *aMode)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint16_t port;
|
||||
uint16_t pin;
|
||||
sl_gpio_mode_t mode;
|
||||
|
||||
SuccessOrExit(error = getGpioPortAndPin(aGpio, &port, &pin));
|
||||
|
||||
sl_gpio_t gpio;
|
||||
sl_gpio_pin_config_t pin_config;
|
||||
|
||||
gpio.port = (uint8_t)port;
|
||||
gpio.pin = (uint8_t)pin;
|
||||
|
||||
VerifyOrExit(sl_gpio_get_pin_config(&gpio, &pin_config) == SL_STATUS_OK, error = OT_ERROR_INVALID_ARGS);
|
||||
mode = pin_config.mode;
|
||||
|
||||
*aMode = (mode == SL_GPIO_MODE_INPUT) ? OT_GPIO_MODE_INPUT : OT_GPIO_MODE_OUTPUT;
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
#endif // OPENTHREAD_CONFIG_DIAG_ENABLE
|
||||
56
Libs/protocol/openthread/platform-abstraction/efr32/diag.h
Normal file
56
Libs/protocol/openthread/platform-abstraction/efr32/diag.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2023, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file includes the platform-specific diagnostic's API declarations.
|
||||
*
|
||||
*/
|
||||
#ifndef DIAG_H_
|
||||
#define DIAG_H_
|
||||
/**
|
||||
* Enable/disable the address match filtering.
|
||||
*
|
||||
* @param[in] aEnable TRUE to Enable or FALSE to disable address match filtering.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully enabled/disabled, asserts otherwise.
|
||||
*
|
||||
*/
|
||||
otError otPlatDiagRadioAddressMatch(bool aEnable);
|
||||
|
||||
/**
|
||||
* Enable/disable the RX auto-ACK functionality.
|
||||
*
|
||||
* @param[in] aAutoAckEnabled TRUE to Enable or FALSE to disable the RX auto-ACK functionality.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully enabled/disabled .
|
||||
*
|
||||
*/
|
||||
otError otPlatDiagRadioAutoAck(bool aAutoAckEnabled);
|
||||
|
||||
#endif // DIAG_H_
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2023, 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 platform abstraction for random number generator.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <openthread-core-config.h>
|
||||
#include <stddef.h>
|
||||
#include <openthread/platform/entropy.h>
|
||||
#include "utils/code_utils.h"
|
||||
|
||||
#if OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_PSA
|
||||
|
||||
#include "security_manager.h"
|
||||
|
||||
void otPlatCryptoRandomInit(void)
|
||||
{
|
||||
}
|
||||
|
||||
void otPlatCryptoRandomDeinit(void)
|
||||
{
|
||||
// Intentionally left blank, nothing to deinit
|
||||
}
|
||||
|
||||
otError otPlatCryptoRandomGet(uint8_t *aBuffer, uint16_t aSize)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
psa_status_t status;
|
||||
|
||||
status = sl_sec_man_get_random(aBuffer, aSize);
|
||||
|
||||
otEXPECT_ACTION((status == PSA_SUCCESS), error = OT_ERROR_FAILED);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
#else
|
||||
// The mbedtls_hardware_poll() function is meant for internal use by Mbed TLS
|
||||
// and is not declared in any external header files. We will therefore declare
|
||||
// it as an extern function here.
|
||||
extern int mbedtls_hardware_poll(void *data, unsigned char *output, size_t len, size_t *olen);
|
||||
|
||||
otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
size_t outputLen = 0;
|
||||
|
||||
otEXPECT_ACTION(aOutput, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
for (size_t partialLen = 0; outputLen < aOutputLength; outputLen += partialLen)
|
||||
{
|
||||
const uint16_t remaining = aOutputLength - outputLen;
|
||||
partialLen = 0;
|
||||
|
||||
// Non-zero return values for mbedtls_hardware_poll() signify an error has occurred
|
||||
otEXPECT_ACTION(0 == mbedtls_hardware_poll(NULL, &aOutput[outputLen], remaining, &partialLen),
|
||||
error = OT_ERROR_FAILED);
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
#endif
|
||||
438
Libs/protocol/openthread/platform-abstraction/efr32/flash.c
Normal file
438
Libs/protocol/openthread/platform-abstraction/efr32/flash.c
Normal file
@@ -0,0 +1,438 @@
|
||||
/*
|
||||
* Copyright (c) 2023, 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 platform abstraction for the non-volatile storage.
|
||||
*/
|
||||
|
||||
#include <openthread-core-config.h>
|
||||
#include "common/debug.hpp"
|
||||
#include "utils/code_utils.h"
|
||||
|
||||
#include "platform-efr32.h"
|
||||
|
||||
#ifdef SL_COMPONENT_CATALOG_PRESENT
|
||||
#include "sl_component_catalog.h"
|
||||
#endif // SL_COMPONENT_CATALOG_PRESENT
|
||||
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE // Use OT NV system
|
||||
|
||||
#include "em_msc.h"
|
||||
#include <string.h>
|
||||
#include <openthread/instance.h>
|
||||
|
||||
#define FLASH_PAGE_NUM 2
|
||||
#define FLASH_DATA_END_ADDR (FLASH_BASE + FLASH_SIZE)
|
||||
#define FLASH_DATA_START_ADDR (FLASH_DATA_END_ADDR - (FLASH_PAGE_SIZE * FLASH_PAGE_NUM))
|
||||
#define FLASH_SWAP_PAGE_NUM (FLASH_PAGE_NUM / 2)
|
||||
#define FLASH_SWAP_SIZE (FLASH_PAGE_SIZE * FLASH_SWAP_PAGE_NUM)
|
||||
|
||||
static inline uint32_t mapAddress(uint8_t aSwapIndex, uint32_t aOffset)
|
||||
{
|
||||
uint32_t address;
|
||||
|
||||
address = FLASH_DATA_START_ADDR + aOffset;
|
||||
|
||||
if (aSwapIndex)
|
||||
{
|
||||
address += FLASH_SWAP_SIZE;
|
||||
}
|
||||
|
||||
return address;
|
||||
}
|
||||
|
||||
void otPlatFlashInit(otInstance *aInstance)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
}
|
||||
|
||||
uint32_t otPlatFlashGetSwapSize(otInstance *aInstance)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
return FLASH_SWAP_SIZE;
|
||||
}
|
||||
|
||||
void otPlatFlashErase(otInstance *aInstance, uint8_t aSwapIndex)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
uint32_t address = mapAddress(aSwapIndex, 0);
|
||||
|
||||
for (uint32_t n = 0; n < FLASH_SWAP_PAGE_NUM; n++, address += FLASH_PAGE_SIZE)
|
||||
{
|
||||
MSC_ErasePage((uint32_t *)address);
|
||||
}
|
||||
}
|
||||
|
||||
void otPlatFlashWrite(otInstance *aInstance, uint8_t aSwapIndex, uint32_t aOffset, const void *aData, uint32_t aSize)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
MSC_WriteWord((uint32_t *)mapAddress(aSwapIndex, aOffset), aData, aSize);
|
||||
}
|
||||
|
||||
void otPlatFlashRead(otInstance *aInstance, uint8_t aSwapIndex, uint32_t aOffset, void *aData, uint32_t aSize)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
memcpy(aData, (const uint8_t *)mapAddress(aSwapIndex, aOffset), aSize);
|
||||
}
|
||||
|
||||
#elif defined(SL_CATALOG_NVM3_PRESENT) // Defaults to Silabs nvm3 system
|
||||
|
||||
#include "nvm3_default.h"
|
||||
#include "sl_memory_manager.h"
|
||||
#include <string.h>
|
||||
#include <openthread/platform/settings.h>
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/logging.hpp"
|
||||
|
||||
#define NVM3KEY_DOMAIN_OPENTHREAD 0x20000U
|
||||
#define NUM_INDEXED_SETTINGS \
|
||||
OPENTHREAD_CONFIG_MLE_MAX_CHILDREN // Indexed key types are only supported for kKeyChildInfo (=='child table').
|
||||
#define ENUM_NVM3_KEY_LIST_SIZE 4 // List size used when enumerating nvm3 keys.
|
||||
|
||||
static otError addSetting(uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength);
|
||||
static nvm3_ObjectKey_t makeNvm3ObjKey(uint16_t otSettingsKey, int index);
|
||||
static otError mapNvm3Error(Ecode_t nvm3Res);
|
||||
static bool nvmOpenedByOT;
|
||||
|
||||
void otPlatSettingsInit(otInstance *aInstance, const uint16_t *aSensitiveKeys, uint16_t aSensitiveKeysLength)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
OT_UNUSED_VARIABLE(aSensitiveKeys);
|
||||
OT_UNUSED_VARIABLE(aSensitiveKeysLength);
|
||||
|
||||
otEXPECT(sl_ot_rtos_task_can_access_pal());
|
||||
|
||||
// Only call nmv3_open if it has not been opened yet.
|
||||
if (nvm3_defaultHandle->hasBeenOpened)
|
||||
{
|
||||
nvmOpenedByOT = false; // OT is not allowed to close NVM
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mapNvm3Error(nvm3_open(nvm3_defaultHandle, nvm3_defaultInit)) != OT_ERROR_NONE)
|
||||
{
|
||||
otLogDebgPlat("Error initializing nvm3 instance");
|
||||
}
|
||||
else
|
||||
{
|
||||
nvmOpenedByOT = true;
|
||||
}
|
||||
}
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void otPlatSettingsDeinit(otInstance *aInstance)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
otEXPECT(sl_ot_rtos_task_can_access_pal());
|
||||
|
||||
if (nvmOpenedByOT && nvm3_defaultHandle->hasBeenOpened)
|
||||
{
|
||||
nvm3_close(nvm3_defaultHandle);
|
||||
nvmOpenedByOT = false;
|
||||
}
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
otError otPlatSettingsGet(otInstance *aInstance, uint16_t aKey, int aIndex, uint8_t *aValue, uint16_t *aValueLength)
|
||||
{
|
||||
// Searches through all matching nvm3 keys to find the one with the required
|
||||
// 'index', then reads the nvm3 data into the destination buffer.
|
||||
// (Repeatedly enumerates a list of matching keys from the nvm3 until the
|
||||
// required index is found).
|
||||
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
otError err;
|
||||
uint16_t valueLength = 0;
|
||||
|
||||
otEXPECT_ACTION(sl_ot_rtos_task_can_access_pal(), err = OT_ERROR_REJECTED);
|
||||
|
||||
nvm3_ObjectKey_t nvm3Key = makeNvm3ObjKey(aKey, 0); // The base nvm3 key value.
|
||||
bool idxFound = false;
|
||||
int idx = 0;
|
||||
err = OT_ERROR_NOT_FOUND;
|
||||
while ((idx <= NUM_INDEXED_SETTINGS) && (!idxFound))
|
||||
{
|
||||
// Get the next nvm3 key list.
|
||||
nvm3_ObjectKey_t keys[ENUM_NVM3_KEY_LIST_SIZE]; // List holds the next set of nvm3 keys.
|
||||
size_t objCnt = nvm3_enumObjects(nvm3_defaultHandle,
|
||||
keys,
|
||||
ENUM_NVM3_KEY_LIST_SIZE,
|
||||
nvm3Key,
|
||||
makeNvm3ObjKey(aKey, NUM_INDEXED_SETTINGS));
|
||||
for (size_t i = 0; i < objCnt; ++i)
|
||||
{
|
||||
nvm3Key = keys[i];
|
||||
if (idx == aIndex)
|
||||
{
|
||||
uint32_t objType;
|
||||
size_t objLen;
|
||||
err = mapNvm3Error(nvm3_getObjectInfo(nvm3_defaultHandle, nvm3Key, &objType, &objLen));
|
||||
if (err == OT_ERROR_NONE)
|
||||
{
|
||||
valueLength = objLen;
|
||||
|
||||
// Only perform read if an input buffer was passed in.
|
||||
if ((aValue != NULL) && (aValueLength != NULL))
|
||||
{
|
||||
sl_status_t status;
|
||||
// Read all nvm3 obj bytes into a tmp buffer, then copy the required
|
||||
// number of bytes to the read destination buffer.
|
||||
uint8_t *buf = NULL;
|
||||
|
||||
status = sl_memory_alloc(valueLength, BLOCK_TYPE_LONG_TERM, (void **)&buf);
|
||||
VerifyOrExit(status == SL_STATUS_OK, err = OT_ERROR_FAILED);
|
||||
|
||||
err = mapNvm3Error(nvm3_readData(nvm3_defaultHandle, nvm3Key, buf, valueLength));
|
||||
if (err == OT_ERROR_NONE)
|
||||
{
|
||||
memcpy(aValue, buf, (valueLength < *aValueLength) ? valueLength : *aValueLength);
|
||||
}
|
||||
sl_free(buf);
|
||||
SuccessOrExit(err);
|
||||
}
|
||||
}
|
||||
idxFound = true;
|
||||
break;
|
||||
}
|
||||
++idx;
|
||||
}
|
||||
if (objCnt < ENUM_NVM3_KEY_LIST_SIZE)
|
||||
{
|
||||
// Stop searching (there are no more matching nvm3 objects).
|
||||
break;
|
||||
}
|
||||
++nvm3Key; // Inc starting value for next nvm3 key list enumeration.
|
||||
}
|
||||
|
||||
exit:
|
||||
if (aValueLength != NULL)
|
||||
{
|
||||
*aValueLength = valueLength; // always return actual nvm3 object length.
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
otError otPlatSettingsSet(otInstance *aInstance, uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
otError err;
|
||||
|
||||
otEXPECT_ACTION(sl_ot_rtos_task_can_access_pal(), err = OT_ERROR_REJECTED);
|
||||
|
||||
// Delete all nvm3 objects matching the input key (i.e. the 'setting indexes' of the key).
|
||||
err = otPlatSettingsDelete(aInstance, aKey, -1);
|
||||
if ((err == OT_ERROR_NONE) || (err == OT_ERROR_NOT_FOUND))
|
||||
{
|
||||
// Add new setting object (i.e. 'index0' of the key).
|
||||
err = addSetting(aKey, aValue, aValueLength);
|
||||
SuccessOrExit(err);
|
||||
}
|
||||
|
||||
exit:
|
||||
return err;
|
||||
}
|
||||
|
||||
otError otPlatSettingsAdd(otInstance *aInstance, uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
otEXPECT_ACTION(sl_ot_rtos_task_can_access_pal(), error = OT_ERROR_REJECTED);
|
||||
|
||||
error = addSetting(aKey, aValue, aValueLength);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatSettingsDelete(otInstance *aInstance, uint16_t aKey, int aIndex)
|
||||
{
|
||||
// Searches through all matching nvm3 keys to find the one with the required
|
||||
// 'index' (or index = -1 to delete all), then deletes the nvm3 object.
|
||||
// (Repeatedly enumerates a list of matching keys from the nvm3 until the
|
||||
// required index is found).
|
||||
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
otError err;
|
||||
nvm3_ObjectKey_t nvm3Key = makeNvm3ObjKey(aKey, 0); // The base nvm3 key value.
|
||||
bool idxFound = false;
|
||||
int idx = 0;
|
||||
err = OT_ERROR_NOT_FOUND;
|
||||
|
||||
otEXPECT_ACTION(sl_ot_rtos_task_can_access_pal(), err = OT_ERROR_REJECTED);
|
||||
|
||||
while ((idx <= NUM_INDEXED_SETTINGS) && (!idxFound))
|
||||
{
|
||||
// Get the next nvm3 key list.
|
||||
nvm3_ObjectKey_t keys[ENUM_NVM3_KEY_LIST_SIZE]; // List holds the next set of nvm3 keys.
|
||||
size_t objCnt = nvm3_enumObjects(nvm3_defaultHandle,
|
||||
keys,
|
||||
ENUM_NVM3_KEY_LIST_SIZE,
|
||||
nvm3Key,
|
||||
makeNvm3ObjKey(aKey, NUM_INDEXED_SETTINGS));
|
||||
for (size_t i = 0; i < objCnt; ++i)
|
||||
{
|
||||
nvm3Key = keys[i];
|
||||
if ((idx == aIndex) || (aIndex == -1))
|
||||
{
|
||||
uint32_t objType;
|
||||
size_t objLen;
|
||||
err = mapNvm3Error(nvm3_getObjectInfo(nvm3_defaultHandle, nvm3Key, &objType, &objLen));
|
||||
if (err == OT_ERROR_NONE)
|
||||
{
|
||||
// Delete the nvm3 object.
|
||||
err = mapNvm3Error(nvm3_deleteObject(nvm3_defaultHandle, nvm3Key));
|
||||
SuccessOrExit(err);
|
||||
}
|
||||
if (aIndex != -1)
|
||||
{
|
||||
idxFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
++idx;
|
||||
}
|
||||
if (objCnt < ENUM_NVM3_KEY_LIST_SIZE)
|
||||
{
|
||||
// Stop searching (there are no more matching nvm3 objects).
|
||||
break;
|
||||
}
|
||||
++nvm3Key; // Inc starting value for next nvm3 key list enumeration.
|
||||
}
|
||||
|
||||
exit:
|
||||
return err;
|
||||
}
|
||||
|
||||
void otPlatSettingsWipe(otInstance *aInstance)
|
||||
{
|
||||
nvm3_ObjectKey_t firstNvm3Key = makeNvm3ObjKey(1, 0);
|
||||
nvm3_ObjectKey_t LastNvm3Key = makeNvm3ObjKey(0xFF, 0xFF);
|
||||
nvm3_ObjectKey_t keys[ENUM_NVM3_KEY_LIST_SIZE];
|
||||
size_t objCnt;
|
||||
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
otEXPECT(sl_ot_rtos_task_can_access_pal());
|
||||
|
||||
objCnt = nvm3_enumObjects(nvm3_defaultHandle, keys, ENUM_NVM3_KEY_LIST_SIZE, firstNvm3Key, LastNvm3Key);
|
||||
|
||||
while (objCnt > 0)
|
||||
{
|
||||
for (size_t i = 0; i < objCnt; ++i)
|
||||
{
|
||||
nvm3_deleteObject(nvm3_defaultHandle, keys[i]);
|
||||
}
|
||||
|
||||
objCnt = nvm3_enumObjects(nvm3_defaultHandle, keys, ENUM_NVM3_KEY_LIST_SIZE, firstNvm3Key, LastNvm3Key);
|
||||
}
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
// Local functions..
|
||||
|
||||
static otError addSetting(uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength)
|
||||
{
|
||||
// Helper function- writes input buffer data to a NEW nvm3 object.
|
||||
// nvm3 object is created at the first available Key + index.
|
||||
|
||||
otError err;
|
||||
|
||||
if ((aValueLength == 0) || (aValue == NULL))
|
||||
{
|
||||
err = OT_ERROR_INVALID_ARGS;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int idx = 0; idx <= NUM_INDEXED_SETTINGS; ++idx)
|
||||
{
|
||||
nvm3_ObjectKey_t nvm3Key;
|
||||
nvm3Key = makeNvm3ObjKey(aKey, idx);
|
||||
|
||||
uint32_t objType;
|
||||
size_t objLen;
|
||||
err = mapNvm3Error(nvm3_getObjectInfo(nvm3_defaultHandle, nvm3Key, &objType, &objLen));
|
||||
if (err == OT_ERROR_NOT_FOUND)
|
||||
{
|
||||
// Use this index for the new nvm3 object.
|
||||
// Write the binary data to nvm3 (Creates nvm3 object if required).
|
||||
err = mapNvm3Error(nvm3_writeData(nvm3_defaultHandle, nvm3Key, aValue, aValueLength));
|
||||
break;
|
||||
}
|
||||
else if (err != OT_ERROR_NONE)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static nvm3_ObjectKey_t makeNvm3ObjKey(uint16_t otSettingsKey, int index)
|
||||
{
|
||||
return (NVM3KEY_DOMAIN_OPENTHREAD | (otSettingsKey << 8) | (index & 0xFF));
|
||||
}
|
||||
|
||||
static otError mapNvm3Error(Ecode_t nvm3Res)
|
||||
{
|
||||
otError err;
|
||||
|
||||
switch (nvm3Res)
|
||||
{
|
||||
case ECODE_NVM3_OK:
|
||||
err = OT_ERROR_NONE;
|
||||
break;
|
||||
|
||||
case ECODE_NVM3_ERR_KEY_NOT_FOUND:
|
||||
err = OT_ERROR_NOT_FOUND;
|
||||
break;
|
||||
|
||||
default:
|
||||
err = OT_ERROR_FAILED;
|
||||
break;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE
|
||||
@@ -0,0 +1,365 @@
|
||||
/*
|
||||
* Copyright (c) 2023, 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 utility functions needed for 802.15.4 frame processing
|
||||
*
|
||||
*/
|
||||
|
||||
#include "ieee802154-packet-utils.hpp"
|
||||
#include "em_device.h"
|
||||
#include "sl_core.h"
|
||||
#include "sl_packet_utils.h"
|
||||
#if defined(RADIOAES_PRESENT)
|
||||
#include "sli_protocol_crypto.h"
|
||||
#else
|
||||
#include "sli_crypto.h"
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
#include "crypto/aes_ccm.hpp"
|
||||
#include "mac/mac_frame.hpp"
|
||||
|
||||
using namespace ot;
|
||||
using namespace Crypto;
|
||||
|
||||
#if defined(RADIOAES_PRESENT)
|
||||
void TxSecurityProcessing::Init(uint32_t aHeaderLength,
|
||||
uint32_t aPlainTextLength,
|
||||
uint8_t aTagLength,
|
||||
const void *aNonce,
|
||||
uint8_t aNonceLength)
|
||||
{
|
||||
const uint8_t *nonceBytes = reinterpret_cast<const uint8_t *>(aNonce);
|
||||
uint8_t blockLength = 0;
|
||||
uint32_t len;
|
||||
uint8_t L;
|
||||
uint8_t i;
|
||||
|
||||
// Tag length must be even and within [kMinTagLength, kMaxTagLength]
|
||||
OT_ASSERT(((aTagLength & 0x1) == 0) && (Crypto::AesCcm::kMinTagLength <= aTagLength)
|
||||
&& (aTagLength <= Crypto::AesCcm::kMaxTagLength));
|
||||
|
||||
L = 0;
|
||||
|
||||
for (len = aPlainTextLength; len; len >>= 8)
|
||||
{
|
||||
L++;
|
||||
}
|
||||
|
||||
if (L <= 1)
|
||||
{
|
||||
L = 2;
|
||||
}
|
||||
|
||||
if (aNonceLength > 13)
|
||||
{
|
||||
aNonceLength = 13;
|
||||
}
|
||||
|
||||
// increase L to match nonce len
|
||||
if (L < (15 - aNonceLength))
|
||||
{
|
||||
L = 15 - aNonceLength;
|
||||
}
|
||||
|
||||
// decrease nonceLength to match L
|
||||
if (aNonceLength > (15 - L))
|
||||
{
|
||||
aNonceLength = 15 - L;
|
||||
}
|
||||
|
||||
// setup initial block
|
||||
|
||||
// write flags
|
||||
mBlock[0] = (static_cast<uint8_t>((aHeaderLength != 0) << 6) | static_cast<uint8_t>(((aTagLength - 2) >> 1) << 3)
|
||||
| static_cast<uint8_t>(L - 1));
|
||||
|
||||
// write nonce
|
||||
memcpy(&mBlock[1], nonceBytes, aNonceLength);
|
||||
|
||||
// write len
|
||||
len = aPlainTextLength;
|
||||
|
||||
for (i = sizeof(mBlock) - 1; i > aNonceLength; i--)
|
||||
{
|
||||
mBlock[i] = len & 0xff;
|
||||
len >>= 8;
|
||||
}
|
||||
|
||||
// encrypt initial block
|
||||
sli_aes_crypt_ecb_radio(true, mKey, kKeyBits, mBlock, mBlock);
|
||||
|
||||
// process header
|
||||
if (aHeaderLength > 0)
|
||||
{
|
||||
// process length
|
||||
if (aHeaderLength < (65536U - 256U))
|
||||
{
|
||||
mBlock[blockLength++] ^= aHeaderLength >> 8;
|
||||
mBlock[blockLength++] ^= aHeaderLength >> 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
mBlock[blockLength++] ^= 0xff;
|
||||
mBlock[blockLength++] ^= 0xfe;
|
||||
mBlock[blockLength++] ^= aHeaderLength >> 24;
|
||||
mBlock[blockLength++] ^= aHeaderLength >> 16;
|
||||
mBlock[blockLength++] ^= aHeaderLength >> 8;
|
||||
mBlock[blockLength++] ^= aHeaderLength >> 0;
|
||||
}
|
||||
}
|
||||
|
||||
// init counter
|
||||
mCtr[0] = L - 1;
|
||||
memcpy(&mCtr[1], nonceBytes, aNonceLength);
|
||||
memset(&mCtr[aNonceLength + 1], 0, sizeof(mCtr) - aNonceLength - 1);
|
||||
|
||||
mNonceLength = aNonceLength;
|
||||
mHeaderLength = aHeaderLength;
|
||||
mHeaderCur = 0;
|
||||
mPlainTextLength = aPlainTextLength;
|
||||
mPlainTextCur = 0;
|
||||
mBlockLength = blockLength;
|
||||
mCtrLength = sizeof(mCtrPad);
|
||||
mTagLength = aTagLength;
|
||||
}
|
||||
|
||||
void TxSecurityProcessing::Header(const void *aHeader, uint32_t aHeaderLength)
|
||||
{
|
||||
const uint8_t *headerBytes = reinterpret_cast<const uint8_t *>(aHeader);
|
||||
|
||||
OT_ASSERT(mHeaderCur + aHeaderLength <= mHeaderLength);
|
||||
|
||||
// process header
|
||||
for (unsigned i = 0; i < aHeaderLength; i++)
|
||||
{
|
||||
if (mBlockLength == sizeof(mBlock))
|
||||
{
|
||||
sli_aes_crypt_ecb_radio(true, mKey, kKeyBits, mBlock, mBlock);
|
||||
|
||||
mBlockLength = 0;
|
||||
}
|
||||
|
||||
mBlock[mBlockLength++] ^= headerBytes[i];
|
||||
}
|
||||
|
||||
mHeaderCur += aHeaderLength;
|
||||
|
||||
if (mHeaderCur == mHeaderLength)
|
||||
{
|
||||
// process remainder
|
||||
if (mBlockLength != 0)
|
||||
{
|
||||
sli_aes_crypt_ecb_radio(true, mKey, kKeyBits, mBlock, mBlock);
|
||||
}
|
||||
|
||||
mBlockLength = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void TxSecurityProcessing::Payload(void *aPlainText, void *aCipherText, uint32_t aLength)
|
||||
{
|
||||
uint8_t *plaintextBytes = reinterpret_cast<uint8_t *>(aPlainText);
|
||||
uint8_t *ciphertextBytes = reinterpret_cast<uint8_t *>(aCipherText);
|
||||
uint8_t byte;
|
||||
|
||||
OT_ASSERT(mPlainTextCur + aLength <= mPlainTextLength);
|
||||
|
||||
for (unsigned i = 0; i < aLength; i++)
|
||||
{
|
||||
if (mCtrLength == 16)
|
||||
{
|
||||
for (int j = sizeof(mCtr) - 1; j > mNonceLength; j--)
|
||||
{
|
||||
if (++mCtr[j])
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
sli_aes_crypt_ecb_radio(true, mKey, kKeyBits, mCtr, mCtrPad);
|
||||
|
||||
mCtrLength = 0;
|
||||
}
|
||||
|
||||
byte = plaintextBytes[i];
|
||||
ciphertextBytes[i] = byte ^ mCtrPad[mCtrLength++];
|
||||
|
||||
if (mBlockLength == sizeof(mBlock))
|
||||
{
|
||||
sli_aes_crypt_ecb_radio(true, mKey, kKeyBits, mBlock, mBlock);
|
||||
|
||||
mBlockLength = 0;
|
||||
}
|
||||
|
||||
mBlock[mBlockLength++] ^= byte;
|
||||
}
|
||||
|
||||
mPlainTextCur += aLength;
|
||||
|
||||
if (mPlainTextCur >= mPlainTextLength)
|
||||
{
|
||||
if (mBlockLength != 0)
|
||||
{
|
||||
sli_aes_crypt_ecb_radio(true, mKey, kKeyBits, mBlock, mBlock);
|
||||
}
|
||||
|
||||
// reset counter
|
||||
memset(&mCtr[mNonceLength + 1], 0, sizeof(mCtr) - mNonceLength - 1);
|
||||
}
|
||||
}
|
||||
|
||||
void TxSecurityProcessing::Finalize(void *aTag)
|
||||
{
|
||||
uint8_t *tagBytes = reinterpret_cast<uint8_t *>(aTag);
|
||||
|
||||
OT_ASSERT(mPlainTextCur == mPlainTextLength);
|
||||
|
||||
sli_aes_crypt_ecb_radio(true, mKey, kKeyBits, mCtr, mCtrPad);
|
||||
|
||||
for (int i = 0; i < mTagLength; i++)
|
||||
{
|
||||
tagBytes[i] = mBlock[i] ^ mCtrPad[i];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(LPWAES_PRESENT)
|
||||
static inline void efr32CreateKeyDesc(const otMacKeyMaterial *key, sli_crypto_descriptor_t *key_desc)
|
||||
{
|
||||
key_desc->location = SLI_CRYPTO_KEY_LOCATION_PLAINTEXT;
|
||||
key_desc->engine = SLI_CRYPTO_LPWAES;
|
||||
key_desc->key.plaintext_key.buffer.pointer = (uint8_t *)key->mKeyMaterial.mKey.m8;
|
||||
key_desc->key.plaintext_key.buffer.size = OT_MAC_KEY_SIZE;
|
||||
key_desc->key.plaintext_key.key_size = OT_MAC_KEY_SIZE;
|
||||
}
|
||||
#endif
|
||||
|
||||
void efr32PlatProcessTransmitAesCcm(otRadioFrame *aFrame, const otExtAddress *aExtAddress)
|
||||
{
|
||||
#if (OPENTHREAD_RADIO && (OPENTHREAD_CONFIG_THREAD_VERSION < OT_THREAD_VERSION_1_2))
|
||||
OT_UNUSED_VARIABLE(aFrame);
|
||||
OT_UNUSED_VARIABLE(aExtAddress);
|
||||
#else
|
||||
|
||||
uint32_t frameCounter = 0;
|
||||
uint8_t tagLength;
|
||||
uint8_t securityLevel;
|
||||
uint8_t nonce[Crypto::AesCcm::kNonceSize];
|
||||
Mac::TxFrame *aTxFrame = static_cast<Mac::TxFrame *>(aFrame);
|
||||
|
||||
VerifyOrExit(aTxFrame->GetSecurityEnabled());
|
||||
|
||||
SuccessOrExit(aTxFrame->GetSecurityLevel(securityLevel));
|
||||
SuccessOrExit(aTxFrame->GetFrameCounter(frameCounter));
|
||||
|
||||
Crypto::AesCcm::GenerateNonce(*static_cast<const Mac::ExtAddress *>(aExtAddress),
|
||||
frameCounter,
|
||||
securityLevel,
|
||||
nonce);
|
||||
|
||||
tagLength = aTxFrame->GetFooterLength() - aTxFrame->GetFcsSize();
|
||||
|
||||
#if defined(RADIOAES_PRESENT)
|
||||
TxSecurityProcessing packetSecurityHandler;
|
||||
|
||||
packetSecurityHandler.SetKey(aFrame->mInfo.mTxInfo.mAesKey->mKeyMaterial.mKey.m8);
|
||||
packetSecurityHandler.Init(aTxFrame->GetHeaderLength(),
|
||||
aTxFrame->GetPayloadLength(),
|
||||
tagLength,
|
||||
nonce,
|
||||
sizeof(nonce));
|
||||
packetSecurityHandler.Header(aTxFrame->GetHeader(), aTxFrame->GetHeaderLength());
|
||||
packetSecurityHandler.Payload(aTxFrame->GetPayload(), aTxFrame->GetPayload(), aTxFrame->GetPayloadLength());
|
||||
packetSecurityHandler.Finalize(aTxFrame->GetFooter());
|
||||
|
||||
#elif defined(LPWAES_PRESENT)
|
||||
sli_crypto_descriptor_t key_desc;
|
||||
sl_status_t ret;
|
||||
|
||||
efr32CreateKeyDesc(aFrame->mInfo.mTxInfo.mAesKey, &key_desc);
|
||||
|
||||
ret =
|
||||
sli_crypto_ccm(&key_desc,
|
||||
true,
|
||||
((securityLevel >= Mac::Frame::SecurityLevel::kSecurityEnc) ? aTxFrame->GetPayload() : NULL),
|
||||
((securityLevel >= Mac::Frame::SecurityLevel::kSecurityEnc) ? aTxFrame->GetPayloadLength() : 0),
|
||||
aTxFrame->GetPayload(),
|
||||
nonce,
|
||||
sizeof(nonce),
|
||||
aTxFrame->GetHeader(),
|
||||
aTxFrame->GetHeaderLength(),
|
||||
aTxFrame->GetPayload() + aTxFrame->GetPayloadLength(),
|
||||
tagLength);
|
||||
|
||||
OT_ASSERT(ret == SL_STATUS_OK);
|
||||
#endif
|
||||
|
||||
aTxFrame->SetIsSecurityProcessed(true);
|
||||
|
||||
exit:
|
||||
return;
|
||||
#endif // OPENTHREAD_RADIO && (OPENTHREAD_CONFIG_THREAD_VERSION < OT_THREAD_VERSION_1_2))
|
||||
}
|
||||
|
||||
bool efr32IsFramePending(otRadioFrame *aFrame)
|
||||
{
|
||||
return static_cast<Mac::RxFrame *>(aFrame)->GetFramePending();
|
||||
}
|
||||
|
||||
otPanId efr32GetDstPanId(otRadioFrame *aFrame)
|
||||
{
|
||||
otPanId aPanId = 0xFFFF;
|
||||
|
||||
if (static_cast<Mac::RxFrame *>(aFrame)->IsDstPanIdPresent())
|
||||
{
|
||||
static_cast<Mac::RxFrame *>(aFrame)->GetDstPanId(aPanId);
|
||||
}
|
||||
|
||||
return aPanId;
|
||||
}
|
||||
|
||||
uint8_t *efr32GetPayload(otRadioFrame *aFrame)
|
||||
{
|
||||
uint8_t *payload = static_cast<Mac::RxFrame *>(aFrame)->GetPayload();
|
||||
return payload;
|
||||
}
|
||||
|
||||
bool efr32FrameIsPanIdCompressed(otRadioFrame *aFrame)
|
||||
{
|
||||
return static_cast<Mac::RxFrame *>(aFrame)->IsPanIdCompressed();
|
||||
}
|
||||
|
||||
uint16_t efr32GetFrameVersion(otRadioFrame *aFrame)
|
||||
{
|
||||
return static_cast<Mac::RxFrame *>(aFrame)->GetVersion();
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Copyright (c) 2023, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file includes definitions for 802.15.4 frame processing.
|
||||
*/
|
||||
|
||||
#ifndef IEEE802154_PACKET_UTILS_HPP_
|
||||
#define IEEE802154_PACKET_UTILS_HPP_
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
|
||||
#include <openthread/platform/crypto.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include "common/error.hpp"
|
||||
#include "crypto/aes_ecb.hpp"
|
||||
#include "mac/mac_types.hpp"
|
||||
|
||||
/**
|
||||
* This class implements Packet Processing.
|
||||
*
|
||||
*/
|
||||
class TxSecurityProcessing
|
||||
{
|
||||
public:
|
||||
enum
|
||||
{
|
||||
kBlockSize = 16, ///< AES-128 block size (bytes).
|
||||
kKeyBits = 128
|
||||
};
|
||||
|
||||
/**
|
||||
* This method sets the key.
|
||||
*
|
||||
* @param[in] aKey Pointer to the AES Key to use.
|
||||
*
|
||||
*/
|
||||
void SetKey(const uint8_t *aKey) { mKey = aKey; }
|
||||
|
||||
/**
|
||||
* This method initializes the AES CCM computation.
|
||||
*
|
||||
* @param[in] aHeaderLength Length of header in bytes.
|
||||
* @param[in] aPlainTextLength Length of plaintext in bytes.
|
||||
* @param[in] aTagLength Length of tag in bytes (must be even and in `[kMinTagLength, kMaxTagLength]`).
|
||||
* @param[in] aNonce A pointer to the nonce.
|
||||
* @param[in] aNonceLength Length of nonce in bytes.
|
||||
*
|
||||
*/
|
||||
void Init(uint32_t aHeaderLength,
|
||||
uint32_t aPlainTextLength,
|
||||
uint8_t aTagLength,
|
||||
const void *aNonce,
|
||||
uint8_t aNonceLength);
|
||||
|
||||
/**
|
||||
* This method processes the header.
|
||||
*
|
||||
* @param[in] aHeader A pointer to the header.
|
||||
* @param[in] aHeaderLength Length of header in bytes.
|
||||
*
|
||||
*/
|
||||
void Header(const void *aHeader, uint32_t aHeaderLength);
|
||||
|
||||
/**
|
||||
* This method processes the payload.
|
||||
*
|
||||
* @param[inout] aPlainText A pointer to the plaintext.
|
||||
* @param[inout] aCipherText A pointer to the ciphertext.
|
||||
* @param[in] aLength Payload length in bytes.
|
||||
* @param[in] aMode Mode to indicate whether to encrypt (`kEncrypt`) or decrypt (`kDecrypt`).
|
||||
*
|
||||
*/
|
||||
void Payload(void *aPlainText, void *aCipherText, uint32_t aLength);
|
||||
|
||||
/**
|
||||
* This method returns the tag length in bytes.
|
||||
*
|
||||
* @returns The tag length in bytes.
|
||||
*
|
||||
*/
|
||||
uint8_t GetTagLength(void) const { return mTagLength; }
|
||||
|
||||
/**
|
||||
* This method generates the tag.
|
||||
*
|
||||
* @param[out] aTag A pointer to the tag (must have `GetTagLength()` bytes).
|
||||
*
|
||||
*/
|
||||
void Finalize(void *aTag);
|
||||
|
||||
private:
|
||||
uint8_t mBlock[kBlockSize];
|
||||
uint8_t mCtr[kBlockSize];
|
||||
uint8_t mCtrPad[kBlockSize];
|
||||
const uint8_t *mKey;
|
||||
uint32_t mHeaderLength;
|
||||
uint32_t mHeaderCur;
|
||||
uint32_t mPlainTextLength;
|
||||
uint32_t mPlainTextCur;
|
||||
uint16_t mBlockLength;
|
||||
uint16_t mCtrLength;
|
||||
uint8_t mNonceLength;
|
||||
uint8_t mTagLength;
|
||||
};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*
|
||||
*/
|
||||
|
||||
#endif // IEEE802154_PACKET_UTILS_HPP_
|
||||
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
* Copyright (c) 2023, 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 holds required 802.15.4 definitions
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __IEEE802154IEEE802154_H__
|
||||
#define __IEEE802154IEEE802154_H__
|
||||
|
||||
#define IEEE802154_MIN_LENGTH \
|
||||
4 // Technically, a version 2 packet / ACK
|
||||
// can be 4 bytes with seq# suppression
|
||||
#define IEEE802154_MAX_LENGTH 127
|
||||
#define IEEE802154_MIN_DATA_LENGTH 5
|
||||
|
||||
// FCF + DSN + dest PANID + dest addr + src PANID + src addr (without security header)
|
||||
#define IEEE802154_MAX_MHR_LENGTH (2 + 1 + 2 + 8 + 2 + 8)
|
||||
|
||||
#define IEEE802154_DSN_OFFSET 2
|
||||
#define IEEE802154_FCF_OFFSET 0
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// 802.15.4 Frame Control Field definitions for Beacon, Ack, Data, Command
|
||||
|
||||
#define IEEE802154_FRAME_TYPE_BEACON ((uint16_t)0x0000U) // Beacon
|
||||
#define IEEE802154_FRAME_TYPE_DATA ((uint16_t)0x0001U) // Data
|
||||
#define IEEE802154_FRAME_TYPE_ACK ((uint16_t)0x0002U) // ACK
|
||||
#define IEEE802154_FRAME_TYPE_COMMAND ((uint16_t)0x0003U) // Command
|
||||
#define IEEE802154_FRAME_TYPE_CONTROL IEEE802154_FRAME_TYPE_COMMAND // (synonym)
|
||||
// 802.15.4E-2012 introduced MultiPurpose with different Frame Control Field
|
||||
// layout described in the MultiPurpose section below.
|
||||
#define IEEE802154_FRAME_TYPE_MULTIPURPOSE ((uint16_t)0x0005U) // MultiPurpose
|
||||
#define IEEE802154_FRAME_TYPE_RESERVED_1 ((uint16_t)0x0004U)
|
||||
#define IEEE802154_FRAME_TYPE_RESERVED_2 ((uint16_t)0x0006U)
|
||||
#define IEEE802154_FRAME_TYPE_RESERVED_3 ((uint16_t)0x0007U)
|
||||
#define IEEE802154_FRAME_TYPE_MASK ((uint16_t)0x0007U) // Bits 0..2
|
||||
// Use a reserved flag internally to check whether outgoing enh-ACK was secure
|
||||
#define IEEE802154_SECURED_OUTGOING_ENHANCED_ACK IEEE802154_FRAME_TYPE_RESERVED_1
|
||||
|
||||
#define IEEE802154_FRAME_FLAG_SECURITY_ENABLED ((uint16_t)0x0008U) // Bit 3
|
||||
#define IEEE802154_FRAME_FLAG_FRAME_PENDING ((uint16_t)0x0010U) // Bit 4
|
||||
#define IEEE802154_FRAME_FLAG_ACK_REQUIRED ((uint16_t)0x0020U) // Bit 5
|
||||
#define IEEE802154_FRAME_FLAG_INTRA_PAN ((uint16_t)0x0040U) // Bit 6
|
||||
// 802.15.4-2006 renamed the Intra-Pan flag PanId-Compression
|
||||
#define IEEE802154_FRAME_FLAG_PANID_COMPRESSION IEEE802154_FRAME_FLAG_INTRA_PAN
|
||||
#define IEEE802154_FRAME_FLAG_RESERVED ((uint16_t)0x0080U) // Bit 7 reserved
|
||||
// Use the reserved flag internally to check whether frame pending bit was set in outgoing ACK
|
||||
#define IEEE802154_FRAME_PENDING_SET_IN_OUTGOING_ACK IEEE802154_FRAME_FLAG_RESERVED
|
||||
// 802.15.4E-2012 introduced these flags for Frame Version 2 frames
|
||||
// which are reserved bit positions in earlier Frame Version frames:
|
||||
#define IEEE802154_FRAME_FLAG_SEQ_SUPPRESSION ((uint16_t)0x0100U) // Bit 8
|
||||
#define IEEE802154_FRAME_FLAG_IE_LIST_PRESENT ((uint16_t)0x0200U) // Bit 9
|
||||
|
||||
#define IEEE802154_FRAME_DESTINATION_MODE_MASK ((uint16_t)0x0C00U) // Bits 10..11
|
||||
#define IEEE802154_FRAME_DESTINATION_MODE_NONE ((uint16_t)0x0000U) // Mode 0
|
||||
#define IEEE802154_FRAME_DESTINATION_MODE_RESERVED ((uint16_t)0x0400U) // Mode 1
|
||||
#define IEEE802154_FRAME_DESTINATION_MODE_SHORT ((uint16_t)0x0800U) // Mode 2
|
||||
#define IEEE802154_FRAME_DESTINATION_MODE_LONG ((uint16_t)0x0C00U) // Mode 3
|
||||
// 802.15.4e-2012 only (not adopted into 802.15.4-2015)
|
||||
#define IEEE802154_FRAME_DESTINATION_MODE_BYTE IEEE802154_FRAME_DESTINATION_MODE_RESERVED
|
||||
|
||||
#define IEEE802154_FRAME_VERSION_MASK ((uint16_t)0x3000U) // Bits 12..13
|
||||
#define IEEE802154_FRAME_VERSION_2003 ((uint16_t)0x0000U) // Version 0
|
||||
#define IEEE802154_FRAME_VERSION_2006 ((uint16_t)0x1000U) // Version 1
|
||||
// In 802.15.4-2015, Version 2 is just called "IEEE STD 802.15.4"
|
||||
// which can be rather confusing. It was introduced in 802.15.4E-2012.
|
||||
#define IEEE802154_FRAME_VERSION_2012 ((uint16_t)0x2000U) // Version 2
|
||||
#define IEEE802154_FRAME_VERSION_2015 ((uint16_t)0x2000U) // Version 2
|
||||
#define IEEE802154_FRAME_VERSION_RESERVED ((uint16_t)0x3000U) // Version 3
|
||||
|
||||
#define IEEE802154_FRAME_SOURCE_MODE_MASK ((uint16_t)0xC000U) // Bits 14..15
|
||||
#define IEEE802154_FRAME_SOURCE_MODE_NONE ((uint16_t)0x0000U) // Mode 0
|
||||
#define IEEE802154_FRAME_SOURCE_MODE_RESERVED ((uint16_t)0x4000U) // Mode 1
|
||||
#define IEEE802154_FRAME_SOURCE_MODE_SHORT ((uint16_t)0x8000U) // Mode 2
|
||||
#define IEEE802154_FRAME_SOURCE_MODE_LONG ((uint16_t)0xC000U) // Mode 3
|
||||
// 802.15.4e-2012 only (not adopted into 802.15.4-2015)
|
||||
#define IEEE802154_FRAME_SOURCE_MODE_BYTE IEEE802154_FRAME_SOURCE_MODE_RESERVED
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// 802.15.4E-2012 Frame Control Field definitions for MultiPurpose
|
||||
|
||||
#define IEEE802154_MP_FRAME_TYPE_MASK IEEE802154_FRAME_TYPE_MASK // Bits 0..2
|
||||
#define IEEE802154_MP_FRAME_TYPE_MULTIPURPOSE IEEE802154_FRAME_TYPE_MULTIPURPOSE
|
||||
|
||||
#define IEEE802154_MP_FRAME_FLAG_LONG_FCF ((uint16_t)0x0008U) // Bit 3
|
||||
|
||||
#define IEEE802154_MP_FRAME_DESTINATION_MODE_MASK ((uint16_t)0x0030U) // Bits 4..5
|
||||
#define IEEE802154_MP_FRAME_DESTINATION_MODE_NONE ((uint16_t)0x0000U) // Mode 0
|
||||
#define IEEE802154_MP_FRAME_DESTINATION_MODE_RESERVED ((uint16_t)0x0010U) // Mode 1
|
||||
#define IEEE802154_MP_FRAME_DESTINATION_MODE_SHORT ((uint16_t)0x0020U) // Mode 2
|
||||
#define IEEE802154_MP_FRAME_DESTINATION_MODE_LONG ((uint16_t)0x0030U) // Mode 3
|
||||
// 802.15.4e-2012 only (not adopted into 802.15.4-2015)
|
||||
#define IEEE802154_MP_FRAME_DESTINATION_MODE_BYTE IEEE802154_MP_FRAME_DESTINATION_MODE_RESERVED
|
||||
|
||||
#define IEEE802154_MP_FRAME_SOURCE_MODE_MASK ((uint16_t)0x00C0U) // Bits 6..7
|
||||
#define IEEE802154_MP_FRAME_SOURCE_MODE_NONE ((uint16_t)0x0000U) // Mode 0
|
||||
#define IEEE802154_MP_FRAME_SOURCE_MODE_RESERVED ((uint16_t)0x0040U) // Mode 1
|
||||
#define IEEE802154_MP_FRAME_SOURCE_MODE_SHORT ((uint16_t)0x0080U) // Mode 2
|
||||
#define IEEE802154_MP_FRAME_SOURCE_MODE_LONG ((uint16_t)0x00C0U) // Mode 3
|
||||
// 802.15.4e-2012 only (not adopted into 802.15.4-2015)
|
||||
#define IEEE802154_MP_FRAME_SOURCE_MODE_BYTE IEEE802154_MP_FRAME_SOURCE_MODE_RESERVED
|
||||
|
||||
#define IEEE802154_MP_FRAME_FLAG_PANID_PRESENT ((uint16_t)0x0100U) // Bit 8
|
||||
#define IEEE802154_MP_FRAME_FLAG_SECURITY_ENABLED ((uint16_t)0x0200U) // Bit 9
|
||||
#define IEEE802154_MP_FRAME_FLAG_SEQ_SUPPRESSION ((uint16_t)0x0400U) // Bit 10
|
||||
#define IEEE802154_MP_FRAME_FLAG_FRAME_PENDING ((uint16_t)0x0800U) // Bit 11
|
||||
|
||||
#define IEEE802154_MP_FRAME_VERSION_MASK IEEE802154_FRAME_VERSION_MASK // Bits 12..13
|
||||
#define IEEE802154_MP_FRAME_VERSION_2012 ((uint16_t)0x0000U) // Zeroed out
|
||||
#define IEEE802154_MP_FRAME_VERSION_2015 ((uint16_t)0x0000U) // Zeroed out
|
||||
// All other MultiPurpose Frame Versions are reserved
|
||||
|
||||
#define IEEE802154_MP_FRAME_FLAG_ACK_REQUIRED ((uint16_t)0x4000U) // Bit 14
|
||||
#define IEEE802154_MP_FRAME_FLAG_IE_LIST_PRESENT ((uint16_t)0x8000U) // Bit 15
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Information Elements fields
|
||||
|
||||
#define IEEE802154_KEYID_MODE_0 ((uint8_t)0x0000U)
|
||||
#define IEEE802154_KEYID_MODE_0_SIZE 0
|
||||
|
||||
#define IEEE802154_KEYID_MODE_1 ((uint8_t)0x0008U)
|
||||
#define IEEE802154_KEYID_MODE_1_SIZE 0
|
||||
|
||||
#define IEEE802154_KEYID_MODE_2 ((uint8_t)0x0010U)
|
||||
#define IEEE802154_KEYID_MODE_2_SIZE 4
|
||||
|
||||
#define IEEE802154_KEYID_MODE_3 ((uint8_t)0x0018U)
|
||||
#define IEEE802154_KEYID_MODE_3_SIZE 8
|
||||
|
||||
#define IEEE802154_KEYID_MODE_MASK ((uint8_t)0x0018U)
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Information Elements fields
|
||||
|
||||
// There are Header IEs and Payload IEs. Header IEs are authenticated
|
||||
// if MAC Security is enabled. Payload IEs are both authenticated and
|
||||
// encrypted if MAC security is enabled.
|
||||
|
||||
// Header and Payload IEs have slightly different formats and different
|
||||
// contents based on the 802.15.4 spec.
|
||||
|
||||
// Both are actually a list of IEs that continues until a termination
|
||||
// IE is seen.
|
||||
|
||||
#define IEEE802154_FRAME_HEADER_INFO_ELEMENT_LENGTH_MASK 0x007F // bits 0-6
|
||||
#define IEEE802154_FRAME_HEADER_INFO_ELEMENT_ID_MASK 0x7F80 // bits 7-14
|
||||
#define IEEE802154_FRAME_HEADER_INFO_ELEMENT_TYPE_MASK 0x8000 // bit 15
|
||||
|
||||
#define IEEE802154_FRAME_HEADER_INFO_ELEMENT_ID_SHIFT 7
|
||||
|
||||
#define IEEE802154_FRAME_PAYLOAD_INFO_ELEMENT_LENGTH_MASK 0x07FF // bits 0 -10
|
||||
#define IEEE802154_FRAME_PAYLOAD_INFO_ELEMENT_GROUP_ID_MASK 0x7800 // bits 11-14
|
||||
#define IEEE802154_FRAME_PAYLOAD_INFO_ELEMENT_TYPE_MASK 0x8000 // bit 15
|
||||
|
||||
#define IEEE802154_FRAME_PAYLOAD_INFO_ELEMENT_ID_SHIFT 11
|
||||
|
||||
// This "type" field indicates header vs. payload IE. However there is
|
||||
// also a Header IE List terminator which would imply the IE list
|
||||
// that follows is only payload IEs.
|
||||
#define IEEE802154_FRAME_INFO_ELEMENT_TYPE_MASK 0x8000
|
||||
|
||||
// Header Termination ID 1 is used when there are Payload IEs that follow.
|
||||
// Header Termination ID 2 is used when there are no Payload IEs and the
|
||||
// next field is the MAC payload.
|
||||
#define IEEE802154_FRAME_HEADER_TERMINATION_ID_1 0x7E
|
||||
#define IEEE802154_FRAME_HEADER_TERMINATION_ID_2 0x7F
|
||||
#define IEEE802154_FRAME_PAYLOAD_TERMINATION_ID 0x0F
|
||||
|
||||
#endif //__IEEE802154IEEE802154_H__
|
||||
46
Libs/protocol/openthread/platform-abstraction/efr32/memory.c
Normal file
46
Libs/protocol/openthread/platform-abstraction/efr32/memory.c
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2023, 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.
|
||||
*/
|
||||
|
||||
#include "platform-efr32.h"
|
||||
#include <openthread-core-config.h>
|
||||
|
||||
#if OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
|
||||
#include <openthread/platform/memory.h>
|
||||
|
||||
#include "sl_memory_manager.h"
|
||||
|
||||
void *otPlatCAlloc(size_t aNum, size_t aSize)
|
||||
{
|
||||
return sl_calloc(aNum, aSize);
|
||||
}
|
||||
|
||||
void otPlatFree(void *aPtr)
|
||||
{
|
||||
sl_free(aPtr);
|
||||
}
|
||||
#endif
|
||||
256
Libs/protocol/openthread/platform-abstraction/efr32/misc.c
Normal file
256
Libs/protocol/openthread/platform-abstraction/efr32/misc.c
Normal file
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
* Copyright (c) 2023, 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 platform abstraction for miscellaneous behaviors.
|
||||
*/
|
||||
|
||||
#include <openthread-core-config.h>
|
||||
#include <openthread/platform/misc.h>
|
||||
|
||||
#if defined(SL_COMPONENT_CATALOG_PRESENT)
|
||||
#include "sl_component_catalog.h"
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_GECKO_BOOTLOADER_INTERFACE_PRESENT)
|
||||
#include "btl_interface.h"
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_EMLIB_RMU_PRESENT)
|
||||
#include "em_rmu.h"
|
||||
#else
|
||||
#include "sl_hal_emu.h"
|
||||
#endif
|
||||
#include "platform-efr32.h"
|
||||
|
||||
#if SL_OPENTHREAD_ENABLE_HOST_WAKE_GPIO
|
||||
#include "sl_gpio.h"
|
||||
#include "sl_sleeptimer.h"
|
||||
|
||||
static sl_sleeptimer_timer_handle_t wake_timer;
|
||||
extern sl_gpio_t host_wakeup_gpio;
|
||||
#endif
|
||||
|
||||
static uint32_t sResetCause;
|
||||
|
||||
void efr32MiscInit(void)
|
||||
{
|
||||
#if defined(_SILICON_LABS_32B_SERIES_2)
|
||||
// Read the cause of last reset.
|
||||
sResetCause = RMU_ResetCauseGet();
|
||||
|
||||
// Clear the register, as the causes cumulate over resets.
|
||||
RMU_ResetCauseClear();
|
||||
#else
|
||||
// Read the cause of last reset.
|
||||
sResetCause = sl_hal_emu_get_reset_cause();
|
||||
|
||||
// Clear the register, as the causes cumulate over resets.
|
||||
sl_hal_emu_clear_reset_cause();
|
||||
#endif
|
||||
}
|
||||
|
||||
void otPlatReset(otInstance *aInstance)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
OT_TOOL_WEAK void bootloader_rebootAndInstall(void)
|
||||
{
|
||||
// Weak stub function
|
||||
// This should be discarded in favor of the function definition in bootloader_interface code, when that component is
|
||||
// used
|
||||
}
|
||||
|
||||
otError otPlatResetToBootloader(otInstance *aInstance)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
bootloader_rebootAndInstall();
|
||||
|
||||
// This should only be reached if the bootloader_interface component is not present.
|
||||
// When it is present, the stubbed bootloader_rebootAndInstall above is not used.
|
||||
// Instead, the non-weak definition of the function in the component is used, causing
|
||||
// the device to reset.
|
||||
return OT_ERROR_NOT_CAPABLE;
|
||||
}
|
||||
|
||||
otPlatResetReason otPlatGetResetReason(otInstance *aInstance)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
otPlatResetReason reason = OT_PLAT_RESET_REASON_UNKNOWN;
|
||||
|
||||
#if defined(_EMU_RSTCAUSE_MASK)
|
||||
if (sResetCause & EMU_RSTCAUSE_POR)
|
||||
{
|
||||
reason = OT_PLAT_RESET_REASON_POWER_ON;
|
||||
}
|
||||
else if (sResetCause & EMU_RSTCAUSE_SYSREQ)
|
||||
{
|
||||
reason = OT_PLAT_RESET_REASON_SOFTWARE;
|
||||
}
|
||||
else if ((sResetCause & EMU_RSTCAUSE_WDOG0) || (sResetCause & EMU_RSTCAUSE_WDOG1))
|
||||
{
|
||||
reason = OT_PLAT_RESET_REASON_WATCHDOG;
|
||||
}
|
||||
else if (sResetCause & EMU_RSTCAUSE_PIN)
|
||||
{
|
||||
reason = OT_PLAT_RESET_REASON_EXTERNAL;
|
||||
}
|
||||
else if (sResetCause & EMU_RSTCAUSE_LOCKUP)
|
||||
{
|
||||
reason = OT_PLAT_RESET_REASON_FAULT;
|
||||
}
|
||||
/* clang-format off */
|
||||
else if ((sResetCause & EMU_RSTCAUSE_AVDDBOD)
|
||||
|| (sResetCause & EMU_RSTCAUSE_DECBOD)
|
||||
|| (sResetCause & EMU_RSTCAUSE_DVDDBOD)
|
||||
|| (sResetCause & EMU_RSTCAUSE_DVDDLEBOD)
|
||||
|| (sResetCause & EMU_RSTCAUSE_EM4))
|
||||
/* clang-format on */
|
||||
{
|
||||
reason = OT_PLAT_RESET_REASON_OTHER;
|
||||
}
|
||||
#endif
|
||||
#if defined(_RMU_RSTCAUSE_MASK)
|
||||
if (sResetCause & RMU_RSTCAUSE_PORST)
|
||||
{
|
||||
reason = OT_PLAT_RESET_REASON_POWER_ON;
|
||||
}
|
||||
else if (sResetCause & RMU_RSTCAUSE_SYSREQRST)
|
||||
{
|
||||
reason = OT_PLAT_RESET_REASON_SOFTWARE;
|
||||
}
|
||||
else if (sResetCause & RMU_RSTCAUSE_WDOGRST)
|
||||
{
|
||||
reason = OT_PLAT_RESET_REASON_WATCHDOG;
|
||||
}
|
||||
else if (sResetCause & RMU_RSTCAUSE_EXTRST)
|
||||
{
|
||||
reason = OT_PLAT_RESET_REASON_EXTERNAL;
|
||||
}
|
||||
else if (sResetCause & RMU_RSTCAUSE_LOCKUPRST)
|
||||
{
|
||||
reason = OT_PLAT_RESET_REASON_FAULT;
|
||||
}
|
||||
/* clang-format off */
|
||||
else if ((sResetCause & RMU_RSTCAUSE_AVDDBOD)
|
||||
|| (sResetCause & RMU_RSTCAUSE_DECBOD)
|
||||
|| (sResetCause & RMU_RSTCAUSE_DVDDBOD)
|
||||
|| (sResetCause & RMU_RSTCAUSE_EM4RST))
|
||||
/* clang-format on */
|
||||
{
|
||||
reason = OT_PLAT_RESET_REASON_OTHER;
|
||||
}
|
||||
#endif
|
||||
return reason;
|
||||
}
|
||||
|
||||
// Timer callback function to clear the GPIO pin
|
||||
#if SL_OPENTHREAD_ENABLE_HOST_WAKE_GPIO
|
||||
static void clearWakeHostPin(sl_sleeptimer_timer_handle_t *handle, void *data)
|
||||
{
|
||||
(void)handle;
|
||||
(void)data;
|
||||
|
||||
// Clear the GPIO pin
|
||||
sl_gpio_clear_pin(&host_wakeup_gpio);
|
||||
}
|
||||
#endif
|
||||
|
||||
OT_TOOL_WEAK void otPlatEfrWakeHost(void)
|
||||
{
|
||||
// Set the GPIO pin to wake up the host
|
||||
#if SL_OPENTHREAD_ENABLE_HOST_WAKE_GPIO
|
||||
sl_gpio_set_pin(&host_wakeup_gpio);
|
||||
// Start a timer to clear the GPIO pin after the timeout
|
||||
sl_sleeptimer_start_timer_ms(&wake_timer, SL_OPENTHREAD_HOST_CLEAR_PIN_TIMEOUT_MS, clearWakeHostPin, NULL, 0, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void otPlatWakeHost(void)
|
||||
{
|
||||
otPlatEfrWakeHost();
|
||||
}
|
||||
|
||||
OT_TOOL_WEAK void otCliOutputFormat(const char *aFmt, ...)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aFmt);
|
||||
|
||||
// do nothing
|
||||
}
|
||||
|
||||
OT_TOOL_WEAK void otCliPlatLogv(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, va_list aArgs)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aLogLevel);
|
||||
OT_UNUSED_VARIABLE(aLogRegion);
|
||||
OT_UNUSED_VARIABLE(aFormat);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
// do nothing
|
||||
}
|
||||
|
||||
OT_TOOL_WEAK void efr32UartProcess(void)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
otError railStatusToOtError(RAIL_Status_t status)
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
case RAIL_STATUS_NO_ERROR:
|
||||
return OT_ERROR_NONE;
|
||||
case RAIL_STATUS_INVALID_PARAMETER:
|
||||
return OT_ERROR_INVALID_ARGS;
|
||||
case RAIL_STATUS_INVALID_STATE:
|
||||
return OT_ERROR_INVALID_STATE;
|
||||
case RAIL_STATUS_INVALID_CALL:
|
||||
case RAIL_STATUS_SUSPENDED:
|
||||
case RAIL_STATUS_SCHED_ERROR:
|
||||
default:
|
||||
return OT_ERROR_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_LOG_CRASH_DUMP_ENABLE
|
||||
otError otPlatLogCrashDump(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
#if defined(SL_CATALOG_OT_CRASH_HANDLER_PRESENT)
|
||||
efr32PrintResetInfo();
|
||||
#else
|
||||
error = OT_ERROR_NOT_CAPABLE;
|
||||
#endif
|
||||
|
||||
return error;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2023, 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.
|
||||
*/
|
||||
|
||||
#ifndef OPENTHREAD_CORE_EFR32_CONFIG_CHECK_H_
|
||||
#define OPENTHREAD_CORE_EFR32_CONFIG_CHECK_H_
|
||||
|
||||
#include "board_config.h"
|
||||
#ifndef RADIO_CONFIG_915MHZ_OQPSK_SUPPORT
|
||||
#if OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT
|
||||
#error "Platform not configured to support configuration option: OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef RADIO_CONFIG_915MHZ_2GFSK_SUPPORT
|
||||
#if OPENTHREAD_CONFIG_RADIO_915MHZ_2GFSK_SUPPORT
|
||||
#error "Platform not configured to support configuration option: OPENTHREAD_CONFIG_RADIO_915MHZ_2GFSK_SUPPORT"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(RADIO_CONFIG_915MHZ_OQPSK_SUPPORT) && !defined(RADIO_CONFIG_SUBGHZ_SUPPORT) \
|
||||
&& !defined(RADIO_CONFIG_2P4GHZ_OQPSK_SUPPORT)
|
||||
#error \
|
||||
"One of the following must be defined: RADIO_CONFIG_915MHZ_OQPSK_SUPPORT, RADIO_CONFIG_SUBGHZ_SUPPORT or RADIO_CONFIG_2P4GHZ_OQPSK_SUPPORT"
|
||||
#endif
|
||||
|
||||
#if defined(_SILICON_LABS_32B_SERIES_1)
|
||||
#error "EFR32 Series 1 parts are not supported."
|
||||
#endif
|
||||
|
||||
#endif /* OPENTHREAD_CORE_EFR32_CONFIG_CHECK_H_ */
|
||||
@@ -0,0 +1,625 @@
|
||||
/*
|
||||
* Copyright (c) 2023, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file includes all compile-time configuration constants used by
|
||||
* efr32 applications for OpenThread.
|
||||
*/
|
||||
|
||||
#ifndef OPENTHREAD_CORE_EFR32_CONFIG_H_
|
||||
#define OPENTHREAD_CORE_EFR32_CONFIG_H_
|
||||
|
||||
#ifdef SL_COMPONENT_CATALOG_PRESENT
|
||||
#include "sl_component_catalog.h"
|
||||
#endif
|
||||
|
||||
#ifdef SL_CATALOG_CLOCK_MANAGER_PRESENT
|
||||
#include "sl_clock_manager_oscillator_config.h"
|
||||
#else
|
||||
#include "sl_device_init_hfxo.h"
|
||||
#include "sl_device_init_hfxo_config.h"
|
||||
#endif
|
||||
|
||||
#if defined(HARDWARE_BOARD_HAS_LFXO) && !defined(SL_CATALOG_CLOCK_MANAGER_PRESENT)
|
||||
#include "sl_device_init_lfxo.h"
|
||||
#include "sl_device_init_lfxo_config.h"
|
||||
#endif
|
||||
|
||||
// Use (user defined) application config file to define OpenThread configurations
|
||||
#ifdef SL_OPENTHREAD_APPLICATION_CONFIG_FILE
|
||||
#include SL_OPENTHREAD_APPLICATION_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
// Use (pre-defined) stack features config file available for applications built
|
||||
// with Simplicity Studio
|
||||
#ifdef SL_OPENTHREAD_STACK_FEATURES_CONFIG_FILE
|
||||
#include SL_OPENTHREAD_STACK_FEATURES_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#include "board_config.h"
|
||||
#include "em_device.h"
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_PLATFORM_BOOTLOADER_MODE_ENABLE
|
||||
*
|
||||
* Allow triggering a platform reset to bootloader mode, if supported.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_PLATFORM_BOOTLOADER_MODE_ENABLE
|
||||
#if defined(SL_CATALOG_GECKO_BOOTLOADER_INTERFACE_PRESENT)
|
||||
#define OPENTHREAD_CONFIG_PLATFORM_BOOTLOADER_MODE_ENABLE 1
|
||||
#else
|
||||
#define OPENTHREAD_CONFIG_PLATFORM_BOOTLOADER_MODE_ENABLE 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_PLATFORM_MAC_KEYS_EXPORTABLE_ENABLE
|
||||
*
|
||||
* Calling crypto functions in interrupt context when another operation is running
|
||||
* causes issues in Series-2 devices. To safeguard enhanced ACK encryption, it is
|
||||
* better to use RADIOAES and not rely on SE. For series-2 devices, this means we
|
||||
* make MAC keys exportable and copy the literal keys in radio.c (instead of using
|
||||
* key references)
|
||||
*
|
||||
*/
|
||||
#define OPENTHREAD_CONFIG_PLATFORM_MAC_KEYS_EXPORTABLE_ENABLE 1
|
||||
|
||||
/*
|
||||
* @def OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT
|
||||
*
|
||||
* Define to 1 if you want to enable physical layer to support OQPSK modulation in 915MHz band.
|
||||
* (currently not supported).
|
||||
*
|
||||
*/
|
||||
#if RADIO_CONFIG_915MHZ_OQPSK_SUPPORT
|
||||
#define OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT 1
|
||||
#else
|
||||
#define OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
* @def OPENTHREAD_CONFIG_RADIO_2P4GHZ_OQPSK_SUPPORT
|
||||
*
|
||||
* Define to 1 if you want to enable physical layer to support OQPSK modulation in 2.4GHz band.
|
||||
*
|
||||
*/
|
||||
#if RADIO_CONFIG_2P4GHZ_OQPSK_SUPPORT
|
||||
#define OPENTHREAD_CONFIG_RADIO_2P4GHZ_OQPSK_SUPPORT 1
|
||||
#else
|
||||
#define OPENTHREAD_CONFIG_RADIO_2P4GHZ_OQPSK_SUPPORT 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
* @def OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_SUPPORT
|
||||
*
|
||||
* Define to 1 if you want to enable physical layer to support proprietary radio configurations.
|
||||
*
|
||||
* This configuration option is used by the Sub-GHz feature to specify proprietary radio parameters,
|
||||
* currently not defined by the Thread spec.
|
||||
*/
|
||||
#if RADIO_CONFIG_SUBGHZ_SUPPORT
|
||||
#define OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_SUPPORT 1
|
||||
#else
|
||||
#define OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_SUPPORT 0
|
||||
#endif
|
||||
|
||||
#if RADIO_CONFIG_SUBGHZ_SUPPORT
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_PAGE
|
||||
*
|
||||
* Channel Page value for (proprietary) Sub-GHz PHY using 2GFSK modulation in 915MHz band.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_PAGE
|
||||
#define OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_PAGE 23
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MIN
|
||||
*
|
||||
* Minimum Channel number supported with (proprietary) Sub-GHz PHY using 2GFSK modulation in 915MHz band.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MIN
|
||||
#define OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MIN 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MAX
|
||||
*
|
||||
* Maximum Channel number supported with (proprietary) Sub-GHz PHY using 2GFSK modulation in 915MHz band.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MAX
|
||||
#define OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MAX 24
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MASK
|
||||
*
|
||||
* Default Channel Mask for (proprietary) Sub-GHz PHY using 2GFSK modulation in 915MHz band.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MASK
|
||||
#define OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MASK 0x1ffffff
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_DEFAULT_CHANNEL
|
||||
*
|
||||
* Default channel to use when working with proprietary radio configurations.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_DEFAULT_CHANNEL
|
||||
#define OPENTHREAD_CONFIG_DEFAULT_CHANNEL OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MIN
|
||||
#endif
|
||||
#endif // RADIO_CONFIG_SUBGHZ_SUPPORT
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_PLATFORM_INFO
|
||||
*
|
||||
* The platform-specific string to insert into the OpenThread version string.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_PLATFORM_INFO
|
||||
#define OPENTHREAD_CONFIG_PLATFORM_INFO "EFR32"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
*
|
||||
* (For FTDs only) Define to 1 to enable tracking the uptime of OpenThread instance.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
#define OPENTHREAD_CONFIG_UPTIME_ENABLE OPENTHREAD_FTD
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_CHILD_SUPERVISION_CHECK_TIMEOUT
|
||||
*
|
||||
* The default supervision check timeout interval (in seconds) used by a device in child state. Set to zero to disable
|
||||
* the supervision check process on the child.
|
||||
*
|
||||
* The check timeout interval can be changed using `otChildSupervisionSetCheckTimeout()`.
|
||||
*
|
||||
* If the sleepy child does not hear from its parent within the specified timeout interval, it initiates the re-attach
|
||||
* process (MLE Child Update Request/Response exchange with its parent).
|
||||
*
|
||||
* Setting to zero by default as this is an optional feature that can lead to unexpected detach behavior.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_CHILD_SUPERVISION_CHECK_TIMEOUT
|
||||
#define OPENTHREAD_CONFIG_CHILD_SUPERVISION_CHECK_TIMEOUT 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_MAC_CSL_REQUEST_AHEAD_US
|
||||
*
|
||||
* Define how many microseconds ahead should MAC deliver CSL frame to SubMac.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_MAC_CSL_REQUEST_AHEAD_US
|
||||
#if defined(_SILICON_LABS_32B_SERIES_3)
|
||||
#define OPENTHREAD_CONFIG_MAC_CSL_REQUEST_AHEAD_US 15000
|
||||
#else
|
||||
#define OPENTHREAD_CONFIG_MAC_CSL_REQUEST_AHEAD_US 2000
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_CSL_RECEIVE_TIME_AHEAD
|
||||
*
|
||||
* Reception scheduling and ramp up time needed for the CSL receiver to be ready, in units of microseconds.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_CSL_RECEIVE_TIME_AHEAD
|
||||
#define OPENTHREAD_CONFIG_CSL_RECEIVE_TIME_AHEAD 600
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_MIN_RECEIVE_ON_AHEAD
|
||||
*
|
||||
* The minimum time (in microseconds) before the MHR start that the radio should be in receive state and ready to
|
||||
* properly receive in order to properly receive any IEEE 802.15.4 frame. Defaults to the duration of SHR + PHR.
|
||||
*
|
||||
* 802.15.4 2.4GHz OQPSK:
|
||||
* SHR: 4 bytes of preamble, 1 byte of sync word
|
||||
* PHR: 1 byte
|
||||
* Total (6 * 32) = 192 us.
|
||||
*
|
||||
* Proprietary SubGhz (2GFSK in 915MHz):
|
||||
* SHR: 4 bytes preamble, 2 bytes SFD = 6 bytes
|
||||
* PHR: 2 bytes
|
||||
* Total (8 * 32) = 256 us.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_MIN_RECEIVE_ON_AHEAD
|
||||
#if RADIO_CONFIG_SUBGHZ_SUPPORT
|
||||
#define OPENTHREAD_CONFIG_MIN_RECEIVE_ON_AHEAD 256
|
||||
#else
|
||||
#define OPENTHREAD_CONFIG_MIN_RECEIVE_ON_AHEAD 192
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_MIN_RECEIVE_ON_AFTER
|
||||
*
|
||||
* The minimum time (in microseconds) after the MHR start that the radio should be in receive state in order
|
||||
* to properly receive any IEEE 802.15.4 frame. Defaults to the duration of a maximum size frame, plus AIFS,
|
||||
* plus the duration of maximum enh-ack frame. Platforms are encouraged to improve this value for energy
|
||||
* efficiency purposes.
|
||||
*
|
||||
* In theory, RAIL should automatically extend the duration of the receive window once the SHR has been
|
||||
* detected, so we should be able to set this to zero.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_MIN_RECEIVE_ON_AFTER
|
||||
#define OPENTHREAD_CONFIG_MIN_RECEIVE_ON_AFTER 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
* @def OPENTHREAD_CONFIG_MAC_SOFTWARE_RETRANSMIT_ENABLE
|
||||
*
|
||||
* Define to 1 if you want to enable software retransmission logic.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_MAC_SOFTWARE_RETRANSMIT_ENABLE
|
||||
#define OPENTHREAD_CONFIG_MAC_SOFTWARE_RETRANSMIT_ENABLE OPENTHREAD_RADIO
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_MAC_SOFTWARE_CSMA_BACKOFF_ENABLE
|
||||
*
|
||||
* Define to 1 if you want to enable software CSMA-CA backoff logic.
|
||||
* RCPs only.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_MAC_SOFTWARE_CSMA_BACKOFF_ENABLE
|
||||
#define OPENTHREAD_CONFIG_MAC_SOFTWARE_CSMA_BACKOFF_ENABLE 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE
|
||||
*
|
||||
* Define to 1 if you want to enable software transmission security logic.
|
||||
* RCPs only.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE
|
||||
#define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE \
|
||||
(OPENTHREAD_RADIO && (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE
|
||||
*
|
||||
* Define to 1 to enable software transmission target time logic.
|
||||
* RCPs only.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE
|
||||
#define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_MAC_SOFTWARE_RX_TIMING_ENABLE
|
||||
*
|
||||
* Define to 1 to enable software reception target time logic.
|
||||
* RCPs only.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_MAC_SOFTWARE_RX_TIMING_ENABLE
|
||||
#define OPENTHREAD_CONFIG_MAC_SOFTWARE_RX_TIMING_ENABLE 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_MAC_SOFTWARE_ENERGY_SCAN_ENABLE
|
||||
*
|
||||
* Define to 1 if you want to enable software energy scanning logic.
|
||||
* RCPs only.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_MAC_SOFTWARE_ENERGY_SCAN_ENABLE
|
||||
#define OPENTHREAD_CONFIG_MAC_SOFTWARE_ENERGY_SCAN_ENABLE 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE
|
||||
*
|
||||
* Define to 1 if you want to support microsecond timer in platform.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE
|
||||
#define OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE
|
||||
*
|
||||
* Define to 1 to enable otPlatFlash* APIs to support non-volatile storage.
|
||||
*
|
||||
* When defined to 1, the platform MUST implement the otPlatFlash* APIs instead of the otPlatSettings* APIs.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE
|
||||
#define OPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_TCP_ENABLE
|
||||
*
|
||||
* Define as 1 to enable OpenThread TCP API
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_TCP_ENABLE
|
||||
#define OPENTHREAD_CONFIG_TCP_ENABLE 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_NCP_HDLC_ENABLE
|
||||
*
|
||||
* Define to 1 to enable the NCP HDLC interface.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_NCP_HDLC_ENABLE
|
||||
#define OPENTHREAD_CONFIG_NCP_HDLC_ENABLE 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_NCP_CPC_ENABLE
|
||||
*
|
||||
* Define to 1 to enable NCP CPC support.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_NCP_CPC_ENABLE
|
||||
#define OPENTHREAD_CONFIG_NCP_CPC_ENABLE 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_NCP_SPI_ENABLE
|
||||
*
|
||||
* Define to 1 to enable NCP SPI support.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_NCP_SPI_ENABLE
|
||||
#define OPENTHREAD_CONFIG_NCP_SPI_ENABLE 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_MIN_SLEEP_DURATION_MS
|
||||
*
|
||||
* Minimum duration in ms below which the platform will not
|
||||
* enter a deep sleep (EM2) mode.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_MIN_SLEEP_DURATION_MS
|
||||
#define OPENTHREAD_CONFIG_MIN_SLEEP_DURATION_MS 5
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_EFR32_UART_TX_FLUSH_TIMEOUT_MS
|
||||
*
|
||||
* Maximum time to wait for a flush to complete in otPlatUartFlush().
|
||||
*
|
||||
* Value is in milliseconds
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_EFR32_UART_TX_FLUSH_TIMEOUT_MS
|
||||
#define OPENTHREAD_CONFIG_EFR32_UART_TX_FLUSH_TIMEOUT_MS 500
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_PSA_ITS_NVM_OFFSET
|
||||
*
|
||||
* This is the offset in ITS where the persistent keys are stored.
|
||||
* For Silabs OT applications, this needs to be in the range of
|
||||
* 0x20000 to 0x2ffff.
|
||||
*
|
||||
*/
|
||||
#define OPENTHREAD_CONFIG_PSA_ITS_NVM_OFFSET 0x20000
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
|
||||
*
|
||||
* This config enables key references to be used in Openthread stack instead of
|
||||
* literal keys.
|
||||
*
|
||||
* Platform needs to support PSA Crypto to enable this option.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
|
||||
#if OPENTHREAD_RADIO
|
||||
#define OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE 0
|
||||
#else
|
||||
#define OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_CRYPTO_LIB
|
||||
*
|
||||
* Selects the crypto backend library for OpenThread.
|
||||
*
|
||||
* There are several options available, but we enable PSA if key references are
|
||||
* available. Otherwise, mbedTLS is used as default (see src/core/config/crypto.h)
|
||||
*
|
||||
* - @sa OPENTHREAD_CONFIG_CRYPTO_LIB_MBEDTLS
|
||||
* - @sa OPENTHREAD_CONFIG_CRYPTO_LIB_PSA
|
||||
* - @sa OPENTHREAD_CONFIG_CRYPTO_LIB_PLATFORM
|
||||
*
|
||||
*/
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
|
||||
#define OPENTHREAD_CONFIG_CRYPTO_LIB OPENTHREAD_CONFIG_CRYPTO_LIB_PSA
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def SL_OPENTHREAD_CSL_TX_UNCERTAINTY
|
||||
*
|
||||
* Uncertainty of scheduling a CSL transmission, in ±10 us units.
|
||||
*
|
||||
* Note: This value was carefully configured to meet Thread certification
|
||||
* requirements for Silicon Labs devices.
|
||||
*
|
||||
*/
|
||||
#ifndef SL_OPENTHREAD_CSL_TX_UNCERTAINTY
|
||||
#if OPENTHREAD_RADIO || OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
#define SL_OPENTHREAD_CSL_TX_UNCERTAINTY 175
|
||||
#elif OPENTHREAD_FTD
|
||||
// Approx. ~128 us. for single CCA + some additional tx uncertainty in testing
|
||||
#define SL_OPENTHREAD_CSL_TX_UNCERTAINTY 20
|
||||
#else
|
||||
// Approx. ~128 us. for single CCA
|
||||
//
|
||||
// Note: Our SSEDs "schedule" transmissions to their parent in order to know
|
||||
// exactly when in the future the data packets go out so they can calculate
|
||||
// the accurate CSL phase to send to their parent.
|
||||
//
|
||||
// The receive windows on the SSEDs scale with this value, so increasing this
|
||||
// uncertainty to account for full CCA/CSMA with 0..7 backoffs
|
||||
// (see RAIL_CSMA_CONFIG_802_15_4_2003_2p4_GHz_OQPSK_CSMA) will mean that the
|
||||
// receive windows can get very long (~ 5ms.)
|
||||
//
|
||||
// We have updated SSEDs to use a single CCA (RAIL_CSMA_CONFIG_SINGLE_CCA)
|
||||
// instead. If they are in very busy channels, CSL won't be reliable anyway.
|
||||
#define SL_OPENTHREAD_CSL_TX_UNCERTAINTY 12
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def SL_OPENTHREAD_HFXO_ACCURACY
|
||||
*
|
||||
* Worst case XTAL accuracy in units of ± ppm. Also used for calculations during CSL operations.
|
||||
*
|
||||
* @note Platforms may optimize this value based on operational conditions (i.e.: temperature).
|
||||
*
|
||||
*/
|
||||
#ifndef SL_OPENTHREAD_HFXO_ACCURACY
|
||||
#ifdef SL_CATALOG_CLOCK_MANAGER_PRESENT
|
||||
#define SL_OPENTHREAD_HFXO_ACCURACY SL_CLOCK_MANAGER_HFXO_PRECISION
|
||||
#else
|
||||
#define SL_OPENTHREAD_HFXO_ACCURACY SL_DEVICE_INIT_HFXO_PRECISION
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def SL_OPENTHREAD_LFXO_ACCURACY
|
||||
*
|
||||
* Worst case XTAL accuracy in units of ± ppm. Also used for calculations during CSL operations.
|
||||
*
|
||||
* @note Platforms may optimize this value based on operational conditions (i.e.: temperature).
|
||||
*/
|
||||
#ifndef SL_OPENTHREAD_LFXO_ACCURACY
|
||||
#if defined(HARDWARE_BOARD_HAS_LFXO)
|
||||
#if SL_CATALOG_CLOCK_MANAGER_PRESENT
|
||||
#define SL_OPENTHREAD_LFXO_ACCURACY SL_CLOCK_MANAGER_LFXO_PRECISION
|
||||
#else
|
||||
#define SL_OPENTHREAD_LFXO_ACCURACY SL_DEVICE_INIT_LFXO_PRECISION
|
||||
#endif // SL_CATALOG_CLOCK_MANAGER_PRESENT
|
||||
#else
|
||||
#define SL_OPENTHREAD_LFXO_ACCURACY 0
|
||||
#endif // HARDWARE_BOARD_HAS_LFXO
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def SL_OPENTHREAD_RADIO_CCA_MODE
|
||||
*
|
||||
* Defines the CCA mode to be used by the platform.
|
||||
*
|
||||
*/
|
||||
#ifndef SL_OPENTHREAD_RADIO_CCA_MODE
|
||||
#define SL_OPENTHREAD_RADIO_CCA_MODE RAIL_IEEE802154_CCA_MODE_RSSI
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def SL_OPENTHREAD_ECDSA_PRIVATE_KEY_SIZE
|
||||
*
|
||||
* Max Private key size supported by ECDSA Crypto handler.
|
||||
*
|
||||
*/
|
||||
#ifndef SL_OPENTHREAD_ECDSA_PRIVATE_KEY_SIZE
|
||||
#define SL_OPENTHREAD_ECDSA_PRIVATE_KEY_SIZE 32
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def SL_OPENTHREAD_ENABLE_HOST_WAKE_GPIO
|
||||
*
|
||||
* Define to 1 to enable the host wakeup GPIO functionality.
|
||||
* This feature allows the platform to wake up the host using a GPIO pin.
|
||||
*
|
||||
* Default value is 0 (disabled).
|
||||
*/
|
||||
#ifndef SL_OPENTHREAD_ENABLE_HOST_WAKE_GPIO
|
||||
#define SL_OPENTHREAD_ENABLE_HOST_WAKE_GPIO 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def SL_OPENTHREAD_HOST_WAKEUP_GPIO_PORT
|
||||
*
|
||||
* Defines the GPIO port for host wakeup.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SL_OPENTHREAD_HOST_WAKEUP_GPIO_PORT
|
||||
#define SL_OPENTHREAD_HOST_WAKEUP_GPIO_PORT SL_GPIO_PORT_C
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def SL_OPENTHREAD_HOST_WAKEUP_GPIO_PIN
|
||||
*
|
||||
* Defines the GPIO pin for host wakeup.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SL_OPENTHREAD_HOST_WAKEUP_GPIO_PIN
|
||||
#define SL_OPENTHREAD_HOST_WAKEUP_GPIO_PIN 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def SL_OPENTHREAD_HOST_CLEAR_PIN_TIMEOUT_MS
|
||||
*
|
||||
* Defines the timeout duration (in milliseconds) for clearing the host wakeup GPIO pin.
|
||||
*
|
||||
* This value specifies the amount of time the system will wait before clearing the host wakeup GPIO pin.
|
||||
*
|
||||
*/
|
||||
#ifndef SL_OPENTHREAD_HOST_CLEAR_PIN_TIMEOUT_MS
|
||||
#define SL_OPENTHREAD_HOST_CLEAR_PIN_TIMEOUT_MS 10
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_PLATFORM_POWER_CALIBRATION_ENABLE
|
||||
*
|
||||
* Power Calibration (SPINEL) Module (Host and RCP configuration)
|
||||
*
|
||||
*/
|
||||
#define OPENTHREAD_CONFIG_PLATFORM_POWER_CALIBRATION_ENABLE OPENTHREAD_CONFIG_POWER_CALIBRATION_ENABLE
|
||||
|
||||
#endif // OPENTHREAD_CORE_EFR32_CONFIG_H_
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2023, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file defines the frequency band configuration structure for efr32.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PLATFORM_BAND_H_
|
||||
#define PLATFORM_BAND_H_
|
||||
|
||||
#include <openthread/platform/radio.h>
|
||||
|
||||
#include "radio_counters.h"
|
||||
#include "rail.h"
|
||||
#include "rail_config.h"
|
||||
#include "rail_ieee802154.h"
|
||||
#include "sl_802154_radio_priority_config.h"
|
||||
|
||||
#define RAIL_TX_FIFO_SIZE (OT_RADIO_FRAME_MAX_SIZE + 1)
|
||||
|
||||
#define RADIO_SCHEDULER_CHANNEL_SLIP_TIME 500000UL
|
||||
|
||||
#define RADIO_TIMING_CSMA_OVERHEAD_US 500
|
||||
#define RADIO_TIMING_DEFAULT_BYTETIME_US 32 // only used if RAIL_GetBitRate returns 0
|
||||
#define RADIO_TIMING_DEFAULT_SYMBOLTIME_US 16 // only used if RAIL_GetSymbolRate returns 0
|
||||
typedef struct efr32CommonConfig
|
||||
{
|
||||
RAIL_Config_t mRailConfig;
|
||||
#if RADIO_CONFIG_DMP_SUPPORT
|
||||
RAILSched_Config_t mRailSchedState;
|
||||
#endif
|
||||
union
|
||||
{
|
||||
// Used to align this buffer as needed
|
||||
RAIL_FIFO_ALIGNMENT_TYPE align[RAIL_TX_FIFO_SIZE / RAIL_FIFO_ALIGNMENT];
|
||||
uint8_t fifo[RAIL_TX_FIFO_SIZE]; // must be 2 power between 64 and 4096, and bigger than OT_RADIO_FRAME_MAX_SIZE
|
||||
} mRailTxFifo;
|
||||
} efr32CommonConfig;
|
||||
|
||||
typedef struct efr32BandConfig
|
||||
{
|
||||
const RAIL_ChannelConfig_t *mChannelConfig;
|
||||
uint8_t mChannelMin;
|
||||
uint8_t mChannelMax;
|
||||
} efr32BandConfig;
|
||||
|
||||
#endif // PLATFORM_BAND_H_
|
||||
@@ -0,0 +1,194 @@
|
||||
/*
|
||||
* Copyright (c) 2023, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file includes the platform-specific initializers.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PLATFORM_EFR32_H_
|
||||
#define PLATFORM_EFR32_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <openthread/instance.h>
|
||||
|
||||
#include "em_device.h"
|
||||
#if defined(_SILICON_LABS_32B_SERIES_2)
|
||||
#include "em_system.h"
|
||||
#else
|
||||
#include "sl_hal_system.h"
|
||||
#endif
|
||||
|
||||
#include "rail.h"
|
||||
|
||||
#include "alarm.h"
|
||||
#include "uart.h"
|
||||
|
||||
// Global OpenThread instance structure
|
||||
extern otInstance *sInstance;
|
||||
|
||||
#ifdef SL_COMPONENT_CATALOG_PRESENT
|
||||
#include "sl_component_catalog.h"
|
||||
#endif // SL_COMPONENT_CATALOG_PRESENT
|
||||
|
||||
#ifndef SL_CATALOG_KERNEL_PRESENT
|
||||
#define sl_ot_rtos_task_can_access_pal() (true)
|
||||
#else
|
||||
#include "sl_ot_rtos_adaptation.h"
|
||||
#endif
|
||||
|
||||
// Global reference to rail handle
|
||||
#ifndef SL_CATALOG_RAIL_MULTIPLEXER_PRESENT
|
||||
#define gRailHandle emPhyRailHandle // use gRailHandle in the OpenThread PAL.
|
||||
#endif
|
||||
|
||||
extern RAIL_Handle_t gRailHandle; // coex needs the emPhyRailHandle symbol.
|
||||
|
||||
/**
|
||||
* This function performs all platform-specific initialization of
|
||||
* OpenThread's drivers.
|
||||
*
|
||||
*/
|
||||
void sl_ot_sys_init(void);
|
||||
|
||||
/**
|
||||
* This function initializes the radio service used by OpenThead.
|
||||
*
|
||||
*/
|
||||
void efr32RadioInit(void);
|
||||
|
||||
/**
|
||||
* This function deinitializes the radio service used by OpenThead.
|
||||
*
|
||||
*/
|
||||
void efr32RadioDeinit(void);
|
||||
|
||||
/**
|
||||
* This function performs radio driver processing.
|
||||
*
|
||||
* @param[in] aInstance The OpenThread instance structure.
|
||||
*
|
||||
*/
|
||||
void efr32RadioProcess(otInstance *aInstance);
|
||||
|
||||
/**
|
||||
* This function performs CPC driver processing.
|
||||
*
|
||||
*/
|
||||
void efr32CpcProcess(void);
|
||||
|
||||
/**
|
||||
* This function performs SPI driver processing.
|
||||
*
|
||||
*/
|
||||
void efr32SpiProcess(void);
|
||||
|
||||
/**
|
||||
* Initialization of Misc module.
|
||||
*
|
||||
*/
|
||||
void efr32MiscInit(void);
|
||||
|
||||
/**
|
||||
* Initialization of ADC module for random number generator.
|
||||
*
|
||||
*/
|
||||
void efr32RandomInit(void);
|
||||
|
||||
/**
|
||||
* Initialization of Logger driver.
|
||||
*
|
||||
*/
|
||||
void efr32LogInit(void);
|
||||
|
||||
/**
|
||||
* Deinitialization of Logger driver.
|
||||
*
|
||||
*/
|
||||
void efr32LogDeinit(void);
|
||||
|
||||
/**
|
||||
* Print reset info.
|
||||
*
|
||||
*/
|
||||
void efr32PrintResetInfo(void);
|
||||
|
||||
/**
|
||||
* Set 802.15.4 CCA mode
|
||||
*
|
||||
* A call to this function should be made after RAIL has been
|
||||
* initialized and a valid handle is available. On platforms that
|
||||
* don't support different CCA modes, a call to this function with
|
||||
* non-Default CCA mode (i.e. with any value except
|
||||
* RAIL_IEEE802154_CCA_MODE_RSSI) will return a failure.
|
||||
*
|
||||
* @param[in] aMode Mode of CCA operation.
|
||||
* @return RAIL Status code indicating success of the function call.
|
||||
*/
|
||||
RAIL_Status_t efr32RadioSetCcaMode(uint8_t aMode);
|
||||
|
||||
/**
|
||||
* This callback is used to check if is safe to put the EFR32 into a
|
||||
* low energy sleep mode.
|
||||
*
|
||||
* The callback should return true if it is ok to enter sleep mode.
|
||||
* Note that the callback must add an EM1 requirement if it intends
|
||||
* to idle (EM1) instead of entering a deep sleep (EM2) mode.
|
||||
*/
|
||||
|
||||
bool efr32AllowSleepCallback(void);
|
||||
|
||||
/**
|
||||
* Load the channel configurations.
|
||||
*
|
||||
* @param[in] aChannel The radio channel.
|
||||
* @param[in] aTxPower The radio transmit power in dBm.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully enabled/disabled .
|
||||
* @retval OT_ERROR_INVALID_ARGS Invalid channel.
|
||||
*
|
||||
*/
|
||||
otError efr32RadioLoadChannelConfig(uint8_t aChannel, int8_t aTxPower);
|
||||
|
||||
otError railStatusToOtError(RAIL_Status_t status);
|
||||
|
||||
/**
|
||||
* This function performs Serial processing.
|
||||
*
|
||||
*/
|
||||
void efr32SerialProcess(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // PLATFORM_EFR32_H_
|
||||
3858
Libs/protocol/openthread/platform-abstraction/efr32/radio.c
Normal file
3858
Libs/protocol/openthread/platform-abstraction/efr32/radio.c
Normal file
File diff suppressed because it is too large
Load Diff
192
Libs/protocol/openthread/platform-abstraction/efr32/radio_coex.c
Normal file
192
Libs/protocol/openthread/platform-abstraction/efr32/radio_coex.c
Normal file
@@ -0,0 +1,192 @@
|
||||
/*
|
||||
* Copyright (c) 2024, 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 platform abstraction for radio coex metrics
|
||||
* collection.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "radio_coex.h"
|
||||
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
|
||||
|
||||
static sl_ot_coex_counter_t sl_coex_counter;
|
||||
|
||||
#define SL_INCREMENT_IF_NO_OVERFLOW(var, val, incr) \
|
||||
do \
|
||||
{ \
|
||||
uint32_t temp = val + incr; \
|
||||
otEXPECT_ACTION(temp >= var, sl_coex_counter.metrics.mStopped = true); \
|
||||
var = temp; \
|
||||
} while (0)
|
||||
|
||||
void sl_rail_util_coex_ot_events(sl_rail_util_coex_ot_event_t event)
|
||||
{
|
||||
bool isTxEvent = (event & SL_RAIL_UTIL_COEX_OT_TX_REQUEST);
|
||||
sl_rail_util_coex_ot_event_t coexEvent =
|
||||
(event & ~(SL_RAIL_UTIL_COEX_OT_TX_REQUEST | SL_RAIL_UTIL_COEX_OT_RX_REQUEST));
|
||||
uint32_t *metrics = (isTxEvent) ? &sl_coex_counter.metrics.mNumTxRequest : &sl_coex_counter.metrics.mNumRxRequest;
|
||||
uint64_t *totalReqToGrantDuration =
|
||||
(isTxEvent) ? &sl_coex_counter.totalTxReqToGrantDuration : &sl_coex_counter.totalRxReqToGrantDuration;
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
// uint32_t mNumGrantGlitch; ///< Not available.
|
||||
|
||||
// mNumTxRequest = mNumTxGrantImmediate + mNumTxGrantWait
|
||||
// mNumTxGrantWait = mNumTxGrantWaitActivated + mNumTxGrantWaitTimeout
|
||||
// Same applies for Rx counters.
|
||||
|
||||
/* Tx Events*/
|
||||
// uint32_t mNumTxRequest; ///< Number of Tx Requested = mNumTxGrantImmediate + mNumTxGrantWait.
|
||||
// uint32_t mNumTxGrantImmediate; ///< Not Available.
|
||||
// uint32_t mNumTxGrantWait; ///< Number of tx requests while grant was inactive.
|
||||
// uint32_t mNumTxGrantWaitActivated; ///< Number of tx requests while grant was inactive that were ultimately granted.
|
||||
// uint32_t mNumTxGrantWaitTimeout; ///< Number of tx requests while grant was inactive that timed out.
|
||||
// uint32_t mNumTxGrantDeactivatedDuringRequest; ///< Number of tx that were in progress when grant was deactivated.
|
||||
// uint32_t mNumTxDelayedGrant; ///< Number of tx requests that were not granted within 50us.
|
||||
// uint32_t mAvgTxRequestToGrantTime; ///< Average time in usec from tx request to grant.
|
||||
|
||||
/* Rx Events*/
|
||||
// uint32_t mNumRxRequest; ///< Number of rx requests.
|
||||
// uint32_t mNumRxGrantImmediate; ///< Number of rx requests while grant was active.
|
||||
// uint32_t mNumRxGrantWait; ///< Number of rx requests while grant was inactive.
|
||||
// uint32_t mNumRxGrantWaitActivated; ///< Number of rx requests while grant was inactive that were ultimately granted.
|
||||
// uint32_t mNumRxGrantWaitTimeout; ///< Number of rx requests while grant was inactive that timed out.
|
||||
// uint32_t mNumRxGrantDeactivatedDuringRequest; ///< Number of rx that were in progress when grant was deactivated.
|
||||
// uint32_t mNumRxDelayedGrant; ///< Number of rx requests that were not granted within 50us.
|
||||
// uint32_t mAvgRxRequestToGrantTime; ///< Average time in usec from rx request to grant.
|
||||
|
||||
// uint32_t mNumRxGrantNone; ///< Number of rx requests that completed without receiving grant.
|
||||
// bool mStopped;
|
||||
|
||||
/* clang-format on */
|
||||
|
||||
otEXPECT(sl_coex_counter.metrics.mStopped == false);
|
||||
|
||||
switch (coexEvent)
|
||||
{
|
||||
case SL_RAIL_UTIL_COEX_OT_EVENT_GRANTED_IMMEDIATE:
|
||||
{
|
||||
SL_INCREMENT_IF_NO_OVERFLOW(metrics[SL_OT_COEX_EVENT_GRANT_IMMEDIATE_COUNT],
|
||||
metrics[SL_OT_COEX_EVENT_GRANT_IMMEDIATE_COUNT],
|
||||
1);
|
||||
}
|
||||
break;
|
||||
|
||||
case SL_RAIL_UTIL_COEX_OT_EVENT_REQUESTED:
|
||||
{
|
||||
sl_coex_counter.timestamp = otPlatAlarmMicroGetNow();
|
||||
SL_INCREMENT_IF_NO_OVERFLOW(metrics[SL_OT_COEX_EVENT_REQUEST_COUNT],
|
||||
metrics[SL_OT_COEX_EVENT_REQUEST_COUNT],
|
||||
1);
|
||||
}
|
||||
break;
|
||||
|
||||
case SL_RAIL_UTIL_COEX_OT_EVENT_GRANTED:
|
||||
{
|
||||
uint32_t reqToGrantDuration = otPlatAlarmMicroGetNow() - sl_coex_counter.timestamp;
|
||||
SL_INCREMENT_IF_NO_OVERFLOW(metrics[SL_OT_COEX_EVENT_GRANT_WAIT_ACTIVATED_COUNT],
|
||||
metrics[SL_OT_COEX_EVENT_GRANT_WAIT_ACTIVATED_COUNT],
|
||||
1);
|
||||
|
||||
if (reqToGrantDuration > 50)
|
||||
{
|
||||
SL_INCREMENT_IF_NO_OVERFLOW(metrics[SL_OT_COEX_EVENT_DELAYED_GRANT_COUNT],
|
||||
metrics[SL_OT_COEX_EVENT_DELAYED_GRANT_COUNT],
|
||||
1);
|
||||
}
|
||||
|
||||
*totalReqToGrantDuration += reqToGrantDuration;
|
||||
}
|
||||
break;
|
||||
|
||||
case SL_RAIL_UTIL_COEX_OT_EVENT_DENIED:
|
||||
{
|
||||
SL_INCREMENT_IF_NO_OVERFLOW(metrics[SL_OT_COEX_EVENT_GRANT_WAIT_TIMEOUT_COUNT],
|
||||
metrics[SL_OT_COEX_EVENT_GRANT_WAIT_TIMEOUT_COUNT],
|
||||
1);
|
||||
}
|
||||
break;
|
||||
|
||||
case SL_RAIL_UTIL_COEX_OT_EVENT_GRANT_ABORTED:
|
||||
{
|
||||
SL_INCREMENT_IF_NO_OVERFLOW(metrics[SL_OT_COEX_EVENT_GRANT_DEACTIVATED_DURING_REQUEST_COUNT],
|
||||
metrics[SL_OT_COEX_EVENT_GRANT_DEACTIVATED_DURING_REQUEST_COUNT],
|
||||
1);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
SL_INCREMENT_IF_NO_OVERFLOW(metrics[SL_OT_COEX_EVENT_GRANT_WAIT_COUNT],
|
||||
metrics[SL_OT_COEX_EVENT_GRANT_WAIT_TIMEOUT_COUNT],
|
||||
metrics[SL_OT_COEX_EVENT_GRANT_WAIT_ACTIVATED_COUNT]);
|
||||
metrics[SL_OT_COEX_EVENT_AVG_REQUEST_TO_GRANT_TIME] =
|
||||
*totalReqToGrantDuration / metrics[SL_OT_COEX_EVENT_REQUEST_COUNT];
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
otError otPlatRadioGetCoexMetrics(otInstance *aInstance, otRadioCoexMetrics *aCoexMetrics)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
otEXPECT_ACTION(aCoexMetrics != NULL, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
memcpy(aCoexMetrics, &sl_coex_counter.metrics, sizeof(otRadioCoexMetrics));
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void sli_radio_coex_reset(void)
|
||||
{
|
||||
memset(&sl_coex_counter, 0, sizeof(sl_coex_counter));
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
otError otPlatRadioGetCoexMetrics(otInstance *aInstance, otRadioCoexMetrics *aCoexMetrics)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
OT_UNUSED_VARIABLE(aCoexMetrics);
|
||||
return OT_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
#endif // OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
|
||||
@@ -0,0 +1,523 @@
|
||||
/*
|
||||
* Copyright (c) 2023, 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 platform abstraction for vendor additions to radio communication.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "radio_extension.h"
|
||||
|
||||
#ifdef SL_COMPONENT_CATALOG_PRESENT
|
||||
#include "sl_component_catalog.h"
|
||||
#endif // SL_COMPONENT_CATALOG_PRESENT
|
||||
|
||||
#ifndef SL_CATALOG_OT_SIMULATION_PRESENT
|
||||
|
||||
#ifdef SL_CATALOG_RAIL_UTIL_COEX_PRESENT
|
||||
#include "coexistence-802154.h"
|
||||
#include "coexistence.h"
|
||||
#endif // SL_CATALOG_RAIL_UTIL_COEX_PRESENT
|
||||
|
||||
#ifdef SL_CATALOG_RAIL_UTIL_ANT_DIV_PRESENT
|
||||
#include "sl_rail_util_ant_div.h"
|
||||
#endif // SL_CATALOG_RAIL_UTIL_ANT_DIV_PRESENT
|
||||
|
||||
#ifdef SL_CATALOG_RAIL_UTIL_IEEE802154_PHY_SELECT_PRESENT
|
||||
#include "sl_rail_util_ieee802154_phy_select.h"
|
||||
#endif // SL_CATALOG_RAIL_UTIL_IEEE802154_PHY_SELECT
|
||||
|
||||
#ifdef SL_CATALOG_OPENTHREAD_TEST_CLI_PRESENT
|
||||
#include "rail_ieee802154.h"
|
||||
#endif // SL_CATALOG_OPENTHREAD_TEST_CLI_PRESENT
|
||||
|
||||
#else // SL_CATALOG_OT_SIMULATION_PRESENT
|
||||
|
||||
#include "rail_util_simulation.h"
|
||||
|
||||
#endif // SL_CATALOG_OT_SIMULATION_PRESENT
|
||||
|
||||
#include "common/code_utils.hpp"
|
||||
|
||||
#ifdef SL_CATALOG_OPENTHREAD_ANT_DIV_PRESENT
|
||||
otError otPlatRadioExtensionGetTxAntennaMode(uint8_t *aMode)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
#ifdef SL_CATALOG_RAIL_UTIL_ANT_DIV_PRESENT
|
||||
VerifyOrExit(aMode != NULL, error = OT_ERROR_INVALID_ARGS);
|
||||
*aMode = (uint8_t)sl_rail_util_ant_div_get_tx_antenna_mode();
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(aMode);
|
||||
ExitNow(error = OT_ERROR_NOT_IMPLEMENTED);
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatRadioExtensionSetTxAntennaMode(uint8_t aMode)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
#ifdef SL_CATALOG_RAIL_UTIL_ANT_DIV_PRESENT
|
||||
sl_status_t status = sl_rail_util_ant_div_set_tx_antenna_mode(aMode);
|
||||
VerifyOrExit(status == SL_STATUS_OK, error = OT_ERROR_FAILED);
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(aMode);
|
||||
ExitNow(error = OT_ERROR_NOT_IMPLEMENTED);
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatRadioExtensionGetRxAntennaMode(uint8_t *aMode)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
#ifdef SL_CATALOG_RAIL_UTIL_ANT_DIV_PRESENT
|
||||
VerifyOrExit(aMode != NULL, error = OT_ERROR_INVALID_ARGS);
|
||||
*aMode = (uint8_t)sl_rail_util_ant_div_get_rx_antenna_mode();
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(aMode);
|
||||
ExitNow(error = OT_ERROR_NOT_IMPLEMENTED);
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatRadioExtensionSetRxAntennaMode(uint8_t aMode)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
#ifdef SL_CATALOG_RAIL_UTIL_ANT_DIV_PRESENT
|
||||
sl_status_t status = sl_rail_util_ant_div_set_rx_antenna_mode(aMode);
|
||||
VerifyOrExit(status == SL_STATUS_OK, error = OT_ERROR_FAILED);
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(aMode);
|
||||
ExitNow(error = OT_ERROR_NOT_IMPLEMENTED);
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatRadioExtensionGetActivePhy(uint8_t *aActivePhy)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
#ifdef SL_CATALOG_RAIL_UTIL_ANT_DIV_PRESENT
|
||||
VerifyOrExit(aActivePhy != NULL, error = OT_ERROR_INVALID_ARGS);
|
||||
*aActivePhy = (uint8_t)sl_rail_util_ieee802154_get_active_radio_config();
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(aActivePhy);
|
||||
ExitNow(error = OT_ERROR_NOT_IMPLEMENTED);
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
#endif // SL_CATALOG_OPENTHREAD_ANT_DIV_PRESENT
|
||||
|
||||
#ifdef SL_CATALOG_OPENTHREAD_COEX_PRESENT
|
||||
|
||||
otError otPlatRadioExtensionGetDpState(uint8_t *aDpPulse)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
#ifdef SL_CATALOG_RAIL_UTIL_COEX_PRESENT
|
||||
VerifyOrExit(aDpPulse != NULL, error = OT_ERROR_INVALID_ARGS);
|
||||
*aDpPulse = (uint8_t)sl_rail_util_coex_get_directional_priority_pulse_width();
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(aDpPulse);
|
||||
ExitNow(error = OT_ERROR_NOT_IMPLEMENTED);
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatRadioExtensionSetDpState(uint8_t aDpPulse)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
#ifdef SL_CATALOG_RAIL_UTIL_COEX_PRESENT
|
||||
sl_status_t status = sl_rail_util_coex_set_directional_priority_pulse_width(aDpPulse);
|
||||
VerifyOrExit(status == SL_STATUS_OK, error = OT_ERROR_FAILED);
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(aDpPulse);
|
||||
ExitNow(error = OT_ERROR_NOT_IMPLEMENTED);
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatRadioExtensionGetGpioInputOverride(uint8_t aGpioIndex, bool *aEnabled)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
#ifdef SL_CATALOG_RAIL_UTIL_COEX_PRESENT
|
||||
VerifyOrExit((COEX_GpioIndex_t)aGpioIndex < COEX_GPIO_INDEX_COUNT, error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(aEnabled != NULL, error = OT_ERROR_INVALID_ARGS);
|
||||
*aEnabled = sl_rail_util_coex_get_gpio_input_override(aGpioIndex);
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(aGpioIndex);
|
||||
OT_UNUSED_VARIABLE(aEnabled);
|
||||
ExitNow(error = OT_ERROR_NOT_IMPLEMENTED);
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatRadioExtensionSetGpioInputOverride(uint8_t aGpioIndex, bool aEnabled)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
#ifdef SL_CATALOG_RAIL_UTIL_COEX_PRESENT
|
||||
sl_status_t status;
|
||||
VerifyOrExit((COEX_GpioIndex_t)aGpioIndex < COEX_GPIO_INDEX_COUNT, error = OT_ERROR_INVALID_ARGS);
|
||||
status = sl_rail_util_coex_set_gpio_input_override((COEX_GpioIndex_t)aGpioIndex, aEnabled);
|
||||
VerifyOrExit(status == SL_STATUS_OK, error = OT_ERROR_FAILED);
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(aGpioIndex);
|
||||
OT_UNUSED_VARIABLE(aEnabled);
|
||||
ExitNow(error = OT_ERROR_NOT_IMPLEMENTED);
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatRadioExtensionGetActiveRadio(uint8_t *aActivePhy)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
#ifdef SL_CATALOG_RAIL_UTIL_COEX_PRESENT
|
||||
VerifyOrExit(aActivePhy != NULL, error = OT_ERROR_INVALID_ARGS);
|
||||
*aActivePhy = (uint8_t)sl_rail_util_ieee802154_get_active_radio_config();
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(aActivePhy);
|
||||
ExitNow(error = OT_ERROR_NOT_IMPLEMENTED);
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatRadioExtensionGetPhySelectTimeout(uint8_t *aTimeout)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
#ifdef SL_CATALOG_RAIL_UTIL_COEX_PRESENT
|
||||
VerifyOrExit(aTimeout != NULL, error = OT_ERROR_INVALID_ARGS);
|
||||
*aTimeout = sl_rail_util_coex_get_phy_select_timeout();
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(aTimeout);
|
||||
ExitNow(error = OT_ERROR_NOT_IMPLEMENTED);
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatRadioExtensionSetPhySelectTimeout(uint8_t aTimeout)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
#ifdef SL_CATALOG_RAIL_UTIL_COEX_PRESENT
|
||||
sl_status_t status = sl_rail_util_coex_set_phy_select_timeout(aTimeout);
|
||||
VerifyOrExit(status == SL_STATUS_OK, error = OT_ERROR_FAILED);
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(aTimeout);
|
||||
ExitNow(error = OT_ERROR_NOT_IMPLEMENTED);
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatRadioExtensionGetCoexOptions(uint32_t *aPtaOptions)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
#ifdef SL_CATALOG_RAIL_UTIL_COEX_PRESENT
|
||||
VerifyOrExit(aPtaOptions != NULL, error = OT_ERROR_INVALID_ARGS);
|
||||
*aPtaOptions = (uint32_t)sl_rail_util_coex_get_options();
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(aPtaOptions);
|
||||
ExitNow(error = OT_ERROR_NOT_IMPLEMENTED);
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatRadioExtensionSetCoexOptions(uint32_t aPtaOptions)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
#ifdef SL_CATALOG_RAIL_UTIL_COEX_PRESENT
|
||||
sl_status_t status = sl_rail_util_coex_set_options(aPtaOptions);
|
||||
VerifyOrExit(status != SL_STATUS_INVALID_PARAMETER, error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(status == SL_STATUS_OK, error = OT_ERROR_FAILED);
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(aPtaOptions);
|
||||
ExitNow(error = OT_ERROR_NOT_IMPLEMENTED);
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatRadioExtensionGetCoexConstantOptions(uint32_t *aPtaOptions)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
#ifdef SL_CATALOG_RAIL_UTIL_COEX_PRESENT
|
||||
VerifyOrExit(aPtaOptions != NULL, error = OT_ERROR_INVALID_ARGS);
|
||||
*aPtaOptions = (uint32_t)sl_rail_util_coex_get_constant_options();
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(aPtaOptions);
|
||||
ExitNow(error = OT_ERROR_NOT_IMPLEMENTED);
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatRadioExtensionIsCoexEnabled(bool *aPtaState)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
#ifdef SL_CATALOG_RAIL_UTIL_COEX_PRESENT
|
||||
VerifyOrExit(aPtaState != NULL, error = OT_ERROR_INVALID_ARGS);
|
||||
*aPtaState = sl_rail_util_coex_is_enabled();
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(aPtaState);
|
||||
ExitNow(error = OT_ERROR_NOT_IMPLEMENTED);
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatRadioExtensionSetCoexEnable(bool aPtaState)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
#ifdef SL_CATALOG_RAIL_UTIL_COEX_PRESENT
|
||||
sl_status_t status = sl_rail_util_coex_set_enable(aPtaState);
|
||||
VerifyOrExit(status == SL_STATUS_OK, error = OT_ERROR_FAILED);
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(aPtaState);
|
||||
ExitNow(error = OT_ERROR_NOT_IMPLEMENTED);
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatRadioExtensionGetRequestPwmArgs(uint8_t *aPwmReq, uint8_t *aPwmDutyCycle, uint8_t *aPwmPeriodHalfMs)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
#ifdef SL_CATALOG_RAIL_UTIL_COEX_PRESENT
|
||||
const sl_rail_util_coex_pwm_args_t *p;
|
||||
VerifyOrExit(aPwmReq != NULL, error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(aPwmDutyCycle != NULL, error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(aPwmPeriodHalfMs != NULL, error = OT_ERROR_INVALID_ARGS);
|
||||
p = sl_rail_util_coex_get_request_pwm_args();
|
||||
VerifyOrExit(p != NULL, error = OT_ERROR_FAILED);
|
||||
*aPwmReq = p->req;
|
||||
*aPwmDutyCycle = p->dutyCycle;
|
||||
*aPwmPeriodHalfMs = p->periodHalfMs;
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(aPwmReq);
|
||||
OT_UNUSED_VARIABLE(aPwmDutyCycle);
|
||||
OT_UNUSED_VARIABLE(aPwmPeriodHalfMs);
|
||||
ExitNow(error = OT_ERROR_NOT_IMPLEMENTED);
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatRadioExtensionSetRequestPwmArgs(uint8_t aPwmReq, uint8_t aPwmDutyCycle, uint8_t aPwmPeriodHalfMs)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
#ifdef SL_CATALOG_RAIL_UTIL_COEX_PRESENT
|
||||
sl_status_t status = sl_rail_util_coex_set_request_pwm(aPwmReq, NULL, aPwmDutyCycle, aPwmPeriodHalfMs);
|
||||
VerifyOrExit(status == SL_STATUS_OK, error = OT_ERROR_FAILED);
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(aPwmReq);
|
||||
OT_UNUSED_VARIABLE(aPwmDutyCycle);
|
||||
OT_UNUSED_VARIABLE(aPwmPeriodHalfMs);
|
||||
ExitNow(error = OT_ERROR_NOT_IMPLEMENTED);
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
#if defined(SL_CATALOG_RAIL_UTIL_COEX_PRESENT) && SL_OPENTHREAD_COEX_COUNTER_ENABLE
|
||||
extern uint32_t efr32RadioCoexCounters[SL_RAIL_UTIL_COEX_EVENT_COUNT];
|
||||
extern void efr32RadioClearCoexCounters(void);
|
||||
#endif
|
||||
|
||||
otError otPlatRadioExtensionClearCoexCounters(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
#if defined(SL_CATALOG_RAIL_UTIL_COEX_PRESENT) && SL_OPENTHREAD_COEX_COUNTER_ENABLE
|
||||
efr32RadioClearCoexCounters();
|
||||
#else
|
||||
error = OT_ERROR_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatRadioExtensionGetCoexCounters(uint8_t aNumEntries, uint32_t aCoexCounters[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
#if defined(SL_CATALOG_RAIL_UTIL_COEX_PRESENT) && SL_OPENTHREAD_COEX_COUNTER_ENABLE
|
||||
VerifyOrExit(aNumEntries == OT_PLAT_RADIO_EXTENSION_COEX_EVENT_COUNT, error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(aCoexCounters != NULL, error = OT_ERROR_INVALID_ARGS);
|
||||
_Static_assert((uint8_t)OT_PLAT_RADIO_EXTENSION_COEX_EVENT_COUNT == (uint8_t)SL_RAIL_UTIL_COEX_EVENT_COUNT,
|
||||
"Coex counter mismatch. OT_PLAT_RADIO_EXTENSION_COEX_EVENT_COUNT != SL_RAIL_UTIL_COEX_EVENT_COUNT");
|
||||
#define COPY_COEX_COUNTER(counter) \
|
||||
aCoexCounters[OT_PLAT_RADIO_EXTENSION_COEX_EVENT_##counter] = \
|
||||
efr32RadioCoexCounters[SL_RAIL_UTIL_COEX_EVENT_##counter]
|
||||
COPY_COEX_COUNTER(LO_PRI_REQUESTED);
|
||||
COPY_COEX_COUNTER(HI_PRI_REQUESTED);
|
||||
COPY_COEX_COUNTER(LO_PRI_DENIED);
|
||||
COPY_COEX_COUNTER(HI_PRI_DENIED);
|
||||
COPY_COEX_COUNTER(LO_PRI_TX_ABORTED);
|
||||
COPY_COEX_COUNTER(HI_PRI_TX_ABORTED);
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(aNumEntries);
|
||||
OT_UNUSED_VARIABLE(aCoexCounters);
|
||||
ExitNow(error = OT_ERROR_NOT_IMPLEMENTED);
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatRadioExtensionSetRadioHoldoff(bool aEnabled)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
#ifdef SL_CATALOG_RAIL_UTIL_COEX_PRESENT
|
||||
sl_status_t status = sl_rail_util_coex_set_radio_holdoff(aEnabled);
|
||||
VerifyOrExit(status == SL_STATUS_OK, error = OT_ERROR_FAILED);
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(aEnabled);
|
||||
ExitNow(error = OT_ERROR_NOT_IMPLEMENTED);
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
#endif // SL_CATALOG_OPENTHREAD_COEX_PRESENT
|
||||
|
||||
#ifdef SL_CATALOG_OPENTHREAD_TEST_CLI_PRESENT
|
||||
extern RAIL_IEEE802154_PtiRadioConfig_t efr32GetPtiRadioConfig(void);
|
||||
extern RAIL_Status_t efr32RadioSetCcaMode(uint8_t aMode);
|
||||
|
||||
otError otPlatRadioExtensionGetPtiRadioConfig(uint16_t *radioConfig)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
VerifyOrExit(radioConfig != NULL, error = OT_ERROR_INVALID_ARGS);
|
||||
*radioConfig = (uint16_t)efr32GetPtiRadioConfig();
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatRadioExtensionSetCcaMode(uint8_t aMode)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
RAIL_Status_t status = efr32RadioSetCcaMode(aMode);
|
||||
VerifyOrExit(status != RAIL_STATUS_INVALID_PARAMETER, error = OT_ERROR_INVALID_ARGS);
|
||||
VerifyOrExit(status == RAIL_STATUS_NO_ERROR, error = OT_ERROR_FAILED);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
#endif // SL_CATALOG_OPENTHREAD_TEST_CLI_PRESENT
|
||||
|
||||
#ifdef SL_CATALOG_OPENTHREAD_EFR32_EXT_PRESENT
|
||||
extern otError efr32GetRadioCounters(efr32RadioCounters *aRadioCounters);
|
||||
extern otError efr32ClearRadioCounters(void);
|
||||
|
||||
#if RADIO_CONFIG_DEBUG_COUNTERS_SUPPORT
|
||||
extern efr32RadioCounters railDebugCounters;
|
||||
#endif
|
||||
|
||||
otError otPlatRadioExtensionGetRadioCounters(efr32RadioCounters *aRadioCounters)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
#if RADIO_CONFIG_DEBUG_COUNTERS_SUPPORT
|
||||
VerifyOrExit(aRadioCounters != NULL, error = OT_ERROR_INVALID_ARGS);
|
||||
*aRadioCounters = railDebugCounters;
|
||||
#else
|
||||
ExitNow(error = OT_ERROR_NOT_IMPLEMENTED);
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatRadioExtensionClearRadioCounters(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
#if RADIO_CONFIG_DEBUG_COUNTERS_SUPPORT
|
||||
efr32ClearRadioCounters();
|
||||
#else
|
||||
error = OT_ERROR_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
#endif // SL_CATALOG_OPENTHREAD_EFR32_EXT_PRESENT
|
||||
@@ -0,0 +1,290 @@
|
||||
/*
|
||||
* Copyright (c) 2023, 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 platform abstraction for radio communication.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <openthread-core-config.h>
|
||||
|
||||
#include "pa_conversions_efr32.h"
|
||||
#include "platform-band.h"
|
||||
#include "platform-efr32.h"
|
||||
#include "radio_multi_channel.h"
|
||||
#include "radio_power_manager.h"
|
||||
#include "rail_config.h"
|
||||
#include "rail_ieee802154.h"
|
||||
#include "sl_multipan.h"
|
||||
|
||||
#ifdef SL_CATALOG_RAIL_MULTIPLEXER_PRESENT
|
||||
#include "sl_rail_mux_rename.h"
|
||||
#endif // SL_CATALOG_RAIL_MULTIPLEXER_PRESENT
|
||||
|
||||
#ifdef SL_CATALOG_RAIL_UTIL_IEEE802154_FAST_CHANNEL_SWITCHING_PRESENT
|
||||
#include "sl_rail_util_ieee802154_fast_channel_switching_config.h"
|
||||
#endif // SL_CATALOG_RAIL_UTIL_IEEE802154_FAST_CHANNEL_SWITCHING_PRESENT
|
||||
|
||||
#if !OPENTHREAD_CONFIG_POWER_CALIBRATION_ENABLE
|
||||
|
||||
static int8_t sli_max_channel_power[RADIO_INTERFACE_COUNT][SL_MAX_CHANNELS_SUPPORTED];
|
||||
static int8_t sli_default_tx_power[RADIO_INTERFACE_COUNT];
|
||||
|
||||
/**
|
||||
* This function gets the lowest value for the max_tx_power for a channel, from the max_tx_powerTable set
|
||||
* across all interfaces. It also gets the highest default_tx_power set across all interfaces.
|
||||
*
|
||||
* @param[out] default_tx_power A pointer to update the derived default_tx_power across all IIDs.
|
||||
* @param[out] tx_power_from_table A pointer to update the Tx Power derived from the MaxChannelPowerTable.
|
||||
* @param[in] channel Channel of interest
|
||||
*
|
||||
*/
|
||||
static void sli_get_default_and_max_powers_across_iids(int8_t *default_tx_power,
|
||||
int8_t *tx_power_from_table,
|
||||
uint16_t channel)
|
||||
{
|
||||
OT_ASSERT(tx_power_from_table != NULL);
|
||||
OT_ASSERT(default_tx_power != NULL);
|
||||
|
||||
for (uint8_t iid = 0U; iid < RADIO_INTERFACE_COUNT; iid++)
|
||||
{
|
||||
// Obtain the minimum Tx power set by different iids, for `channel`
|
||||
// If there is an interface using lower Tx power than the one we have
|
||||
// in tx_power_from_table..
|
||||
// Update tx_power_from_table.
|
||||
*tx_power_from_table = SL_MIN(*tx_power_from_table, sli_max_channel_power[iid][channel - SL_CHANNEL_MIN]);
|
||||
|
||||
// If the default Tx Power set is not invalid..
|
||||
if (sli_default_tx_power[iid] != SL_INVALID_TX_POWER)
|
||||
{
|
||||
// Obtain the Max value between local default_tx_power and sli_default_tx_power.
|
||||
// If selected default Tx Power is Invalid, initialise it to sli_default_tx_power.
|
||||
// We have already validated that sli_default_tx_power holds a valid value.
|
||||
*default_tx_power = (*default_tx_power == SL_INVALID_TX_POWER)
|
||||
? sli_default_tx_power[iid]
|
||||
: SL_MAX(*default_tx_power, sli_default_tx_power[iid]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function returns the tx power to be used based on the default and max tx power table, for a given channel.
|
||||
*
|
||||
* @param[in] channel Channel of interest
|
||||
*
|
||||
* @returns The radio Tx Power for the given channel, in dBm.
|
||||
*
|
||||
*/
|
||||
|
||||
static int8_t sli_get_max_tx_power_across_iids(uint16_t channel)
|
||||
{
|
||||
int8_t max_channel_tx_power = SL_INVALID_TX_POWER;
|
||||
int8_t max_default_tx_power = SL_INVALID_TX_POWER;
|
||||
int8_t selected_tx_power = SL_INVALID_TX_POWER;
|
||||
|
||||
#if FAST_CHANNEL_SWITCHING_SUPPORT && OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
|
||||
|
||||
if (sl_is_multi_channel_enabled())
|
||||
{
|
||||
RAIL_IEEE802154_RxChannelSwitchingCfg_t channel_switching_cfg;
|
||||
|
||||
// Get switching config
|
||||
sl_get_channel_switching_cfg(&channel_switching_cfg);
|
||||
|
||||
// Find the max_channel_tx_power, to be minimum of Max channel power for the
|
||||
// channels infast channel config, accross all iids. This is because, if a iid_1
|
||||
// sets the max tx power of the channel to be less than the max tx power set by
|
||||
// iid_2, we will need to work with the lower tx power to be compliant on both
|
||||
// interfaces.
|
||||
|
||||
// Find the max_default_tx_power, to be maximum of the default Tx power accross all
|
||||
// the interfaces.
|
||||
|
||||
for (uint8_t i = 0U; i < RAIL_IEEE802154_RX_CHANNEL_SWITCHING_NUM_CHANNELS; i++)
|
||||
{
|
||||
channel = channel_switching_cfg.channels[i];
|
||||
sli_get_default_and_max_powers_across_iids(&max_default_tx_power, &max_channel_tx_power, channel);
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
sli_get_default_and_max_powers_across_iids(&max_default_tx_power, &max_channel_tx_power, channel);
|
||||
}
|
||||
|
||||
// Return the minimum of max_channel_tx_power and max_default_tx_power.
|
||||
selected_tx_power = SL_MIN(max_channel_tx_power, max_default_tx_power);
|
||||
return (selected_tx_power == SL_INVALID_TX_POWER) ? OPENTHREAD_CONFIG_DEFAULT_TRANSMIT_POWER : selected_tx_power;
|
||||
}
|
||||
|
||||
#endif //! OPENTHREAD_CONFIG_POWER_CALIBRATION_ENABLE
|
||||
|
||||
void sli_set_tx_power_in_rail(int8_t power_in_dbm)
|
||||
{
|
||||
RAIL_Status_t status;
|
||||
|
||||
// RAIL_SetTxPowerDbm() takes power in units of deci-dBm (0.1dBm)
|
||||
// Multiply by 10 because power_in_dbm is supposed be in units dBm
|
||||
status = RAIL_SetTxPowerDbm(gRailHandle, ((RAIL_TxPower_t)power_in_dbm) * 10);
|
||||
|
||||
OT_ASSERT(status == RAIL_STATUS_NO_ERROR);
|
||||
}
|
||||
|
||||
void sli_init_power_manager(void)
|
||||
{
|
||||
#if !OPENTHREAD_CONFIG_POWER_CALIBRATION_ENABLE
|
||||
memset(sli_max_channel_power, SL_INVALID_TX_POWER, sizeof(sli_max_channel_power));
|
||||
memset(sli_default_tx_power, SL_INVALID_TX_POWER, sizeof(sli_default_tx_power));
|
||||
#endif //! OPENTHREAD_CONFIG_POWER_CALIBRATION_ENABLE
|
||||
}
|
||||
|
||||
void sli_update_tx_power_after_config_update(const RAIL_TxPowerConfig_t *tx_pwr_config, int8_t tx_power)
|
||||
{
|
||||
RAIL_Status_t status;
|
||||
RAIL_TxPowerLevel_t tx_power_lvl;
|
||||
RAIL_TxPower_t tx_power_dbm = tx_power * 10;
|
||||
|
||||
tx_power_lvl = RAIL_GetTxPower(gRailHandle);
|
||||
|
||||
// Always need to call RAIL_SetTxPowerDbm after RAIL_ConfigTxPower
|
||||
// First need to get existing power setting and reassert value after config
|
||||
|
||||
if (tx_power_lvl != RAIL_TX_POWER_LEVEL_INVALID)
|
||||
{
|
||||
tx_power_dbm = RAIL_GetTxPowerDbm(gRailHandle);
|
||||
}
|
||||
|
||||
status = RAIL_ConfigTxPower(gRailHandle, tx_pwr_config);
|
||||
OT_ASSERT(status == RAIL_STATUS_NO_ERROR);
|
||||
|
||||
status = RAIL_SetTxPowerDbm(gRailHandle, tx_power_dbm);
|
||||
OT_ASSERT(status == RAIL_STATUS_NO_ERROR);
|
||||
}
|
||||
|
||||
otError sli_set_channel_max_tx_power(otInstance *instance, uint8_t channel, int8_t max_power)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
#if !OPENTHREAD_CONFIG_POWER_CALIBRATION_ENABLE
|
||||
int8_t tx_power;
|
||||
uint8_t iid = efr32GetIidFromInstance(instance);
|
||||
|
||||
otEXPECT_ACTION(channel >= SL_CHANNEL_MIN && channel <= SL_CHANNEL_MAX, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
sli_max_channel_power[iid][channel - SL_CHANNEL_MIN] = max_power;
|
||||
tx_power = sl_get_tx_power_for_current_channel(instance);
|
||||
sli_set_tx_power_in_rail(tx_power);
|
||||
|
||||
exit:
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(instance);
|
||||
OT_UNUSED_VARIABLE(channel);
|
||||
OT_UNUSED_VARIABLE(max_power);
|
||||
error = OT_ERROR_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
return error;
|
||||
}
|
||||
|
||||
otError sli_set_default_tx_power(otInstance *instance, int8_t tx_power)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
#if !OPENTHREAD_CONFIG_POWER_CALIBRATION_ENABLE
|
||||
int8_t max_tx_power;
|
||||
uint8_t iid = efr32GetIidFromInstance(instance);
|
||||
|
||||
sli_default_tx_power[iid] = tx_power;
|
||||
max_tx_power = sl_get_tx_power_for_current_channel(instance);
|
||||
|
||||
sli_set_tx_power_in_rail(max_tx_power);
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(instance);
|
||||
OT_UNUSED_VARIABLE(tx_power);
|
||||
error = OT_ERROR_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
int8_t sl_get_tx_power_for_current_channel(otInstance *instance)
|
||||
{
|
||||
int8_t tx_power;
|
||||
uint16_t channel;
|
||||
|
||||
RAIL_GetChannel(gRailHandle, &channel);
|
||||
|
||||
#if OPENTHREAD_CONFIG_POWER_CALIBRATION_ENABLE
|
||||
uint8_t raw_power_calibration[SL_OPENTHREAD_RAW_POWER_CALIBRATION_LENGTH];
|
||||
uint8_t fem_setting[SL_OPENTHREAD_FEM_SETTING_LENGTH];
|
||||
uint16_t raw_calibration_length = SL_OPENTHREAD_RAW_POWER_CALIBRATION_LENGTH;
|
||||
uint16_t fem_setting_length = SL_OPENTHREAD_FEM_SETTING_LENGTH;
|
||||
otError error;
|
||||
|
||||
error = otPlatRadioGetRawPowerSetting(instance, channel, raw_power_calibration, &raw_calibration_length);
|
||||
|
||||
error = sl_parse_raw_power_calibration_cb(raw_power_calibration,
|
||||
raw_calibration_length,
|
||||
&tx_power,
|
||||
fem_setting,
|
||||
&fem_setting_length);
|
||||
OT_ASSERT(error == OT_ERROR_NONE);
|
||||
|
||||
sl_configure_fem_cb(fem_setting, fem_setting_length);
|
||||
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(instance);
|
||||
tx_power = sli_get_max_tx_power_across_iids(channel);
|
||||
#endif
|
||||
|
||||
return tx_power;
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_POWER_CALIBRATION_ENABLE
|
||||
SL_WEAK otError sl_parse_raw_power_calibration_cb(uint8_t *raw_power_calibration,
|
||||
uint16_t raw_setting_length,
|
||||
int8_t *radio_power,
|
||||
uint8_t *fem_setting,
|
||||
uint16_t *fem_setting_length)
|
||||
{
|
||||
OT_ASSERT(raw_power_calibration != NULL);
|
||||
OT_ASSERT(radio_power != NULL);
|
||||
OT_UNUSED_VARIABLE(raw_setting_length);
|
||||
OT_UNUSED_VARIABLE(fem_setting);
|
||||
OT_UNUSED_VARIABLE(fem_setting_length);
|
||||
|
||||
*radio_power = raw_power_calibration[0];
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
SL_WEAK void sl_configure_fem_cb(uint8_t *fem_setting, uint16_t fem_setting_length)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(fem_setting);
|
||||
OT_UNUSED_VARIABLE(fem_setting_length);
|
||||
}
|
||||
#endif // OPENTHREAD_CONFIG_POWER_CALIBRATION_ENABLE
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2023, 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.
|
||||
*/
|
||||
|
||||
#ifndef __RAIL_CONFIG_H__
|
||||
#define __RAIL_CONFIG_H__
|
||||
|
||||
#include "board_config.h"
|
||||
#include "rail_types.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#if RADIO_CONFIG_SUBGHZ_SUPPORT
|
||||
extern const RAIL_ChannelConfig_t *channelConfigs[];
|
||||
#endif
|
||||
|
||||
#endif // __RAIL_CONFIG_H__
|
||||
@@ -0,0 +1,339 @@
|
||||
/*
|
||||
* Copyright (c) 2023, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* @file
|
||||
* @brief This file implements Green Power interface.
|
||||
******************************************************************************/
|
||||
|
||||
#include "sl_gp_interface.h"
|
||||
#include "ieee802154mac.h"
|
||||
#include "rail_ieee802154.h"
|
||||
#include "sl_gp_interface_config.h"
|
||||
#include "sl_packet_utils.h"
|
||||
#include "sl_status.h"
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <openthread/platform/diag.h>
|
||||
#include <openthread/platform/time.h>
|
||||
#include "common/debug.hpp"
|
||||
#include "common/logging.hpp"
|
||||
#include "utils/code_utils.h"
|
||||
#include "utils/mac_frame.h"
|
||||
|
||||
// This implements mechanism to buffer outgoing Channel Configuration (0xF3) and
|
||||
// Commissioning Reply (0xF0) GPDF commands on the RCP to sent out on request
|
||||
// from GPD with bidirectional capability with in a certain time window, i.e.
|
||||
// between 20 and 25 msec.
|
||||
// The mechanism works following way -
|
||||
// The zigbeed submits the outgoing GPDF command, this code on rcp intercepts the
|
||||
// packet from transmit API and buffers the packet, does not send it out.
|
||||
// The GPD sends request indicating its RX capability, this again intercept the
|
||||
// rx message and based on the request, it sends out the above buffered message
|
||||
// with in a time window of 20-25 msec from the time it received the message.
|
||||
|
||||
#define GP_MIN_MAINTENANCE_FRAME_LENGTH 10
|
||||
#define GP_MIN_DATA_FRAME_LENGTH 14
|
||||
|
||||
#define GP_ADDRESSING_MODE_SRC_ID 0
|
||||
#define GP_ADDRESSING_MODE_EUI64 2
|
||||
|
||||
// Check the GP Frame Type field to ensure it is either a maintenance frame (1) or a data frame (0).
|
||||
#define GP_NWK_PROTOCOL_VERSION_CHECK(nwkFc) ((((nwkFc >> 2) & 0x0F) == 3) && ((nwkFc & 0x3) <= 1))
|
||||
#define GP_NWK_FRAME_TYPE_MAINTENANCE_WITHOUT_EXTD_FC(nwkFc) ((nwkFc & 0xC3) == 0x01)
|
||||
#define GP_NWK_FRAME_TYPE_DATA_WITH_EXTD_FC(nwkFc) ((nwkFc & 0xC3) == 0x80)
|
||||
|
||||
#define GP_NWK_UNSECURED_RX_DATA_FRAME(nwkExntdFc) ((nwkExntdFc & 0xF8) == 0x40)
|
||||
#define GP_NWK_UNSECURED_TX_DATA_FRAME(nwkExntdFc) ((nwkExntdFc & 0xF8) == 0x80)
|
||||
#define GP_NWK_ADDRESSING_APP_ID(nwkExntdFc) ((nwkExntdFc & 0x07))
|
||||
|
||||
#define GP_CHANNEL_REQUEST_CMD_ID 0xE3
|
||||
#define GP_CHANNEL_CONFIGURATION_CMD_ID 0xF3
|
||||
#define GP_COMMISSIONINGING_CMD_ID 0xE0
|
||||
#define GP_COMMISSIONING_REPLY_CMD_ID 0xF0
|
||||
|
||||
#define GP_EXND_FC_INDEX 1
|
||||
#define GP_COMMAND_INDEX_FOR_MAINT_FRAME 1
|
||||
#define GP_SRC_ID_INDEX_WITH_APP_MODE_0 2
|
||||
#define GP_APP_EP_INDEX_WITH_APP_MODE_1 2
|
||||
#define GP_COMMAND_INDEX_WITH_APP_MODE_1 3
|
||||
#define GP_COMMAND_INDEX_WITH_APP_MODE_0 6
|
||||
|
||||
#define BUFFERED_PSDU_GP_SRC_ID_INDEX_WITH_APP_MODE_0 9
|
||||
#define BUFFERED_PSDU_GP_APP_EP_INDEX_WITH_APP_MODE_1 15
|
||||
|
||||
#if OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
|
||||
static volatile sl_gp_state_t gp_state = SL_GP_STATE_INIT;
|
||||
static volatile uint64_t gpStateTimeOut;
|
||||
|
||||
// Needed to retrieve buffered transmit frame present in global memory.
|
||||
static otInstance *sBufferedTxInstance = NULL;
|
||||
|
||||
sl_gp_state_t sl_gp_intf_get_state(void)
|
||||
{
|
||||
return gp_state;
|
||||
}
|
||||
|
||||
void efr32GpProcess(void)
|
||||
{
|
||||
switch (gp_state)
|
||||
{
|
||||
case SL_GP_STATE_INIT:
|
||||
{
|
||||
gp_state = SL_GP_STATE_IDLE;
|
||||
otLogDebgPlat("GP RCP INTF: GP Frame init!!");
|
||||
}
|
||||
break;
|
||||
case SL_GP_STATE_SEND_RESPONSE:
|
||||
{
|
||||
if (otPlatTimeGet() >= gpStateTimeOut)
|
||||
{
|
||||
OT_ASSERT(sBufferedTxInstance != NULL);
|
||||
// Get the tx frame and send it without csma.
|
||||
otRadioFrame *aTxFrame = otPlatRadioGetTransmitBuffer(sBufferedTxInstance);
|
||||
aTxFrame->mInfo.mTxInfo.mCsmaCaEnabled = false;
|
||||
aTxFrame->mInfo.mTxInfo.mMaxCsmaBackoffs = 0;
|
||||
// On successful transmit, this will call the transmit complete callback for the GP packet,
|
||||
// and go up to the CGP Send Handler and eventually the green power client.
|
||||
otPlatRadioTransmit(sBufferedTxInstance, aTxFrame);
|
||||
|
||||
gp_state = SL_GP_STATE_IDLE;
|
||||
sBufferedTxInstance = NULL;
|
||||
otLogDebgPlat("GP RCP INTF: Sending Response!!");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SL_GP_STATE_WAITING_FOR_PKT:
|
||||
{
|
||||
if (otPlatTimeGet() >= gpStateTimeOut)
|
||||
{
|
||||
OT_ASSERT(sBufferedTxInstance != NULL);
|
||||
// This is a timeout call for the case when the GPD did not poll the response with in 5 seconds.
|
||||
otPlatRadioTxDone(sBufferedTxInstance,
|
||||
otPlatRadioGetTransmitBuffer(sBufferedTxInstance),
|
||||
NULL,
|
||||
OT_ERROR_ABORT);
|
||||
gp_state = SL_GP_STATE_IDLE;
|
||||
sBufferedTxInstance = NULL;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
// For all other states don't do anything
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void sl_gp_intf_buffer_pkt(otInstance *aInstance)
|
||||
{
|
||||
gpStateTimeOut = otPlatTimeGet() + GP_TX_MAX_TIMEOUT_IN_MICRO_SECONDS;
|
||||
gp_state = SL_GP_STATE_WAITING_FOR_PKT;
|
||||
OT_ASSERT(aInstance != NULL);
|
||||
sBufferedTxInstance = aInstance;
|
||||
otLogDebgPlat("GP RCP INTF: buffered!!");
|
||||
}
|
||||
|
||||
bool sl_gp_intf_should_buffer_pkt(otInstance *aInstance, otRadioFrame *aFrame, bool isRxFrame)
|
||||
{
|
||||
bool shouldBufferPacket = false;
|
||||
|
||||
#if OPENTHREAD_CONFIG_DIAG_ENABLE
|
||||
// Exit immediately if diag mode is enabled.
|
||||
otEXPECT_ACTION(!otPlatDiagModeGet(), shouldBufferPacket = false);
|
||||
#endif
|
||||
|
||||
uint8_t *gpFrameStartIndex = efr32GetPayload(aFrame);
|
||||
otEXPECT_ACTION(gpFrameStartIndex != NULL, shouldBufferPacket = false);
|
||||
|
||||
// A Typical MAC Frame with GP NWK Frame in it
|
||||
/* clang-format off */
|
||||
// MAC Frame : [<---------------MAC Header------------->||<------------------------------------NWK Frame----------------------------------->]
|
||||
// FC(2) | Seq(1) | DstPan(2) | DstAddr(2) || FC(1) | ExtFC(0/1) | SrcId(0/4) | SecFc(0/4) | MIC(0/4) | <------GPDF(1/n)------>
|
||||
// The Green Power NWK FC and Ext FC are described as :
|
||||
// FC : ExtFC Present(b7)=1| AC(b6)=0| Protocol Ver(b5-b2)=3 GP frames| Frame Type(b1-b0) = 0
|
||||
// ExtFC : rxAfteTX (b6) = 1 | AppId(b2-b0) = 0
|
||||
/* clang-format on */
|
||||
|
||||
uint8_t fc = *gpFrameStartIndex;
|
||||
|
||||
otLogDebgPlat("GP RCP INTF : (%s) PL Index = %d Channel = %d Length = %d FC = %0X",
|
||||
isRxFrame ? "Rx" : "Tx",
|
||||
(gpFrameStartIndex - aFrame->mPsdu),
|
||||
aFrame->mChannel,
|
||||
aFrame->mLength,
|
||||
fc);
|
||||
|
||||
// Check if packet is a GP packet
|
||||
otEXPECT_ACTION(sl_gp_intf_is_gp_pkt(aFrame), shouldBufferPacket = false);
|
||||
|
||||
otLogDebgPlat("GP RCP INTF : (%s) Length and Version Matched", isRxFrame ? "Rx" : "Tx");
|
||||
// For GP Maintenance Frame type without extended FC, the FC is exactly same for both RX and TX directions with
|
||||
// auto commissioning bit = 0, does not have a ExtFC field, only the command Id (which is the next byte in
|
||||
// frame) indicates the direction.
|
||||
if (GP_NWK_FRAME_TYPE_MAINTENANCE_WITHOUT_EXTD_FC(fc))
|
||||
{
|
||||
otLogDebgPlat("GP RCP INTF : (%s) Maintenance Frame match", isRxFrame ? "Rx" : "Tx");
|
||||
uint8_t cmdId = *(gpFrameStartIndex + GP_COMMAND_INDEX_FOR_MAINT_FRAME);
|
||||
if (cmdId == GP_CHANNEL_REQUEST_CMD_ID && isRxFrame && gp_state == SL_GP_STATE_WAITING_FOR_PKT)
|
||||
{
|
||||
// Send out the buffered frame
|
||||
gp_state = SL_GP_STATE_SEND_RESPONSE;
|
||||
gpStateTimeOut = aFrame->mInfo.mRxInfo.mTimestamp + GP_RX_OFFSET_IN_MICRO_SECONDS;
|
||||
otLogDebgPlat("GP RCP INTF : (%s) Received GP_CHANNEL_REQUEST_CMD_ID - Send the Channel configuration",
|
||||
isRxFrame ? "Rx" : "Tx");
|
||||
}
|
||||
else if (cmdId == GP_CHANNEL_CONFIGURATION_CMD_ID && !isRxFrame)
|
||||
{
|
||||
// Buffer the frame
|
||||
shouldBufferPacket = true;
|
||||
otLogDebgPlat("GP RCP INTF : (%s) Buffer GP_CHANNEL_CONFIGURATION_CMD_ID command", isRxFrame ? "Rx" : "Tx");
|
||||
}
|
||||
}
|
||||
else if (
|
||||
// Data frame with EXT FC present, extract the App Id, SrcId, direction and command Id
|
||||
GP_NWK_FRAME_TYPE_DATA_WITH_EXTD_FC(fc) &&
|
||||
// Minimum Data frame length with extended header and address
|
||||
aFrame->mLength >= GP_MIN_DATA_FRAME_LENGTH)
|
||||
{
|
||||
uint8_t extFc = *(gpFrameStartIndex + GP_EXND_FC_INDEX);
|
||||
|
||||
// Process only unsecured commissioning frames for Tx/Rx with correct direction and RxAfterTx fields
|
||||
// A.3.9.1, step 12: the proxies (also in combos) receiving a Commissioning GPDF (0xE3), Application Description
|
||||
// GPDF (0xE4), any other GPD command from the GPD CommandID range 0xE5 – 0xEF, any GPD command from the GPD
|
||||
// CommandID range 0xB0 – 0xBF
|
||||
|
||||
if ((!isRxFrame && GP_NWK_UNSECURED_TX_DATA_FRAME(extFc))
|
||||
|| (isRxFrame && GP_NWK_UNSECURED_RX_DATA_FRAME(extFc)))
|
||||
{
|
||||
if (GP_NWK_ADDRESSING_APP_ID(extFc) == GP_ADDRESSING_MODE_SRC_ID)
|
||||
{
|
||||
uint8_t cmdId = *(gpFrameStartIndex + GP_COMMAND_INDEX_WITH_APP_MODE_0);
|
||||
if (cmdId == GP_COMMISSIONING_REPLY_CMD_ID && !isRxFrame)
|
||||
{
|
||||
// Buffer the frame
|
||||
shouldBufferPacket = true;
|
||||
}
|
||||
else if ((cmdId == GP_COMMISSIONINGING_CMD_ID || (0xE4 <= cmdId && cmdId <= 0xEF)
|
||||
|| (0xB0 <= cmdId && cmdId <= 0xBF))
|
||||
&& isRxFrame && gp_state == SL_GP_STATE_WAITING_FOR_PKT)
|
||||
{
|
||||
otRadioFrame *aTxFrame = otPlatRadioGetTransmitBuffer(aInstance);
|
||||
// Match the gpd src Id ?
|
||||
if (!memcmp((const void *)(gpFrameStartIndex + GP_SRC_ID_INDEX_WITH_APP_MODE_0),
|
||||
(const void *)((aTxFrame->mPsdu) + BUFFERED_PSDU_GP_SRC_ID_INDEX_WITH_APP_MODE_0),
|
||||
sizeof(uint32_t)))
|
||||
{
|
||||
// Send out the buffered frame
|
||||
gp_state = SL_GP_STATE_SEND_RESPONSE;
|
||||
gpStateTimeOut = aFrame->mInfo.mRxInfo.mTimestamp + GP_RX_OFFSET_IN_MICRO_SECONDS;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (GP_NWK_ADDRESSING_APP_ID(extFc) == GP_ADDRESSING_MODE_EUI64)
|
||||
{
|
||||
uint8_t cmdId = *(gpFrameStartIndex + GP_COMMAND_INDEX_WITH_APP_MODE_1);
|
||||
if (cmdId == GP_COMMISSIONING_REPLY_CMD_ID && !isRxFrame)
|
||||
{
|
||||
// Buffer the frame
|
||||
shouldBufferPacket = true;
|
||||
}
|
||||
else if ((cmdId == GP_COMMISSIONINGING_CMD_ID || (0xE4 <= cmdId && cmdId <= 0xEF)
|
||||
|| (0xB0 <= cmdId && cmdId <= 0xBF))
|
||||
&& isRxFrame && gp_state == SL_GP_STATE_WAITING_FOR_PKT)
|
||||
{
|
||||
otRadioFrame *aTxFrame = otPlatRadioGetTransmitBuffer(aInstance);
|
||||
// Check the eui64 and app endpoint to send out the buffer packet.
|
||||
otMacAddress aSrcAddress;
|
||||
otMacAddress aDstAddress;
|
||||
otMacFrameGetDstAddr(aTxFrame, &aDstAddress);
|
||||
otMacFrameGetSrcAddr(aFrame, &aSrcAddress);
|
||||
if (!memcmp(&(aDstAddress.mAddress.mExtAddress),
|
||||
&(aSrcAddress.mAddress.mExtAddress),
|
||||
sizeof(otExtAddress))
|
||||
&& (gpFrameStartIndex[GP_APP_EP_INDEX_WITH_APP_MODE_1]
|
||||
== (aTxFrame->mPsdu)[BUFFERED_PSDU_GP_APP_EP_INDEX_WITH_APP_MODE_1]))
|
||||
{
|
||||
gp_state = SL_GP_STATE_SEND_RESPONSE;
|
||||
gpStateTimeOut = aFrame->mInfo.mRxInfo.mTimestamp + GP_RX_OFFSET_IN_MICRO_SECONDS;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldBufferPacket)
|
||||
{
|
||||
otLogDebgPlat("GP RCP INTF: GP filter passed!!");
|
||||
}
|
||||
|
||||
exit:
|
||||
return shouldBufferPacket;
|
||||
}
|
||||
#endif // OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
|
||||
|
||||
bool sl_gp_intf_is_gp_pkt(otRadioFrame *aFrame)
|
||||
{
|
||||
/* clang-format off */
|
||||
|
||||
// A Typical MAC Frame with GP NWK Frame in it
|
||||
// MAC Frame : [<---------------MAC Header------------->||<------------------------------------NWK Frame----------------------------------->]
|
||||
// FC(2) | Seq(1) | DstPan(2) | DstAddr(2) || FC(1) | ExtFC(0/1) | SrcId(0/4) | SecFc(0/4) | MIC(0/4) | <------GPDF(1/n)------>
|
||||
|
||||
/* clang-format on */
|
||||
|
||||
bool isGpPkt = false;
|
||||
uint8_t *gpFrameStartIndex = efr32GetPayload(aFrame);
|
||||
otEXPECT_ACTION(gpFrameStartIndex != NULL, isGpPkt = false);
|
||||
uint8_t fc = *gpFrameStartIndex;
|
||||
|
||||
// Criteria:
|
||||
// - The basic Identification of a GPDF Frame : The minimum GPDF length need to be 10 in this case for any
|
||||
// direction
|
||||
// - Network layer FC containing the Protocol Version field as 3.
|
||||
// - The frame version should be 2003.
|
||||
|
||||
bool lengthCheck = (aFrame->mLength >= GP_MIN_MAINTENANCE_FRAME_LENGTH);
|
||||
bool networkVersionCheck = GP_NWK_PROTOCOL_VERSION_CHECK(fc);
|
||||
bool frameVersionCheck = (efr32GetFrameVersion(aFrame) == IEEE802154_FRAME_VERSION_2003);
|
||||
|
||||
isGpPkt = (lengthCheck && networkVersionCheck && frameVersionCheck);
|
||||
#if 0 // Debugging
|
||||
if (!isGpPkt)
|
||||
{
|
||||
otLogCritPlat("GP RCP INTF checks: Length = %d, NWK Version = %d, PanId Compression = %d, Frame Version = %d",
|
||||
lengthCheck,
|
||||
networkVersionCheck,
|
||||
panIdCompressionCheck,
|
||||
frameVersionCheck);
|
||||
}
|
||||
#endif
|
||||
exit:
|
||||
return isGpPkt;
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2023, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* @file
|
||||
* @brief This file implements Green Power interface.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SL_GP_INTERFACE_H_
|
||||
#define SL_GP_INTERFACE_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <openthread/platform/radio.h>
|
||||
|
||||
// GP state-machine states
|
||||
typedef enum
|
||||
{
|
||||
SL_GP_STATE_INIT,
|
||||
SL_GP_STATE_IDLE,
|
||||
SL_GP_STATE_WAITING_FOR_PKT,
|
||||
SL_GP_STATE_SEND_RESPONSE,
|
||||
SL_GP_STATE_MAX
|
||||
} sl_gp_state_t;
|
||||
|
||||
/**
|
||||
* This function returns current state of GP state machine.
|
||||
*
|
||||
* @retval Status of GP state machine.
|
||||
*/
|
||||
sl_gp_state_t sl_gp_intf_get_state(void);
|
||||
|
||||
/**
|
||||
* This function performs GP RCP processing.
|
||||
*
|
||||
*/
|
||||
void efr32GpProcess(void);
|
||||
|
||||
/**
|
||||
* This function stores the provided packet in global memory, to be sent as
|
||||
* a response for specific incoming packet.
|
||||
*
|
||||
* @param[in] aInstance A pointer to the OpenThread instance structure.
|
||||
*/
|
||||
void sl_gp_intf_buffer_pkt(otInstance *aInstance);
|
||||
|
||||
/**
|
||||
* This function returns if the given frame is a GP frame and should be buffered
|
||||
*
|
||||
* @param[in] aInstance A pointer to the OpenThread instance structure.
|
||||
* @param[in] aFrame A pointer to the MAC frame buffer.
|
||||
* @param[in] isRxFrame If the give frame is a incoming or outgoing frame.
|
||||
*
|
||||
* @retval true Frame should be buffered
|
||||
* @retval false Frame should not be buffered
|
||||
*/
|
||||
bool sl_gp_intf_should_buffer_pkt(otInstance *aInstance, otRadioFrame *aFrame, bool isRxFrame);
|
||||
|
||||
/**
|
||||
* This function returns if the given frame is a GP frame.
|
||||
*
|
||||
* @param[in] aFrame A pointer to the MAC frame buffer.
|
||||
*
|
||||
* @retval true Frame is a GP packet.
|
||||
* @retval false Frame is not a GP packet.
|
||||
*/
|
||||
bool sl_gp_intf_is_gp_pkt(otRadioFrame *aFrame);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright (c) 2023, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief
|
||||
* Helper functions for Silicon Labs Multipan implementation.
|
||||
*/
|
||||
|
||||
#ifndef SL_MULTIPAN_H_
|
||||
#define SL_MULTIPAN_H_
|
||||
|
||||
#if OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
|
||||
#include <openthread/platform/multipan.h>
|
||||
#endif
|
||||
#include "utils/code_utils.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
|
||||
#define RADIO_INTERFACE_COUNT (OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_NUM + 1)
|
||||
#else
|
||||
#define RADIO_INTERFACE_COUNT 1
|
||||
extern otInstance *sInstance;
|
||||
#endif
|
||||
|
||||
#define INVALID_INTERFACE_INDEX (0xFF)
|
||||
|
||||
typedef enum
|
||||
{
|
||||
EFR32_IID_BCAST = 0,
|
||||
EFR32_IID_1 = 1,
|
||||
EFR32_IID_2 = 2,
|
||||
EFR32_IID_3 = 3,
|
||||
EFR32_IID_INVALID = 0xFF
|
||||
} efr32Iid_t;
|
||||
|
||||
/*
|
||||
* RAIL accepts 3 pan indices 0, 1 or 2. But valid IIDs are 1, 2 and 3 (0 is reserved for bcast).
|
||||
* This API validates the passed IID and converts it into usable PanIndex.
|
||||
*/
|
||||
|
||||
static inline uint8_t efr32GetPanIndexFromIid(uint8_t iid)
|
||||
{
|
||||
uint8_t panIndex = 0;
|
||||
|
||||
#if OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
|
||||
otEXPECT_ACTION(((iid < RADIO_INTERFACE_COUNT) && (iid != 0)), panIndex = INVALID_INTERFACE_INDEX);
|
||||
panIndex = iid - 1;
|
||||
exit:
|
||||
#else
|
||||
panIndex = iid;
|
||||
#endif
|
||||
|
||||
return panIndex;
|
||||
}
|
||||
|
||||
static inline otInstance *efr32GetInstanceFromIid(efr32Iid_t aIid)
|
||||
{
|
||||
#if OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
|
||||
return otPlatMultipanIidToInstance((uint8_t)aIid);
|
||||
#else
|
||||
OT_UNUSED_VARIABLE(aIid);
|
||||
return sInstance;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint8_t efr32GetIidFromInstance(otInstance *aInstance)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
#if OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
|
||||
return otPlatMultipanInstanceToIid(aInstance);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // SL_MULTIPAN_H_
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (c) 2023, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file includes the initializers for supporting Security manager.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SL_PACKET_HANDLER_H
|
||||
#define SL_PACKET_HANDLER_H
|
||||
|
||||
#include <openthread/platform/radio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function performs AES CCM on the frame which is going to be sent.
|
||||
*
|
||||
* @param[in] aFrame A pointer to the MAC frame buffer that is going to be sent.
|
||||
* @param[in] aExtAddress A pointer to the extended address, which will be used to generate nonce
|
||||
* for AES CCM computation.
|
||||
*
|
||||
*/
|
||||
void efr32PlatProcessTransmitAesCcm(otRadioFrame *aFrame, const otExtAddress *aExtAddress);
|
||||
|
||||
/**
|
||||
* This function returns if the Frame Pending bit is set in any given frame.
|
||||
*
|
||||
* @param[in] aFrame A pointer to the MAC frame buffer.
|
||||
*
|
||||
* @retval true Frame Pending is set.
|
||||
* @retval false Frame Pending is not set.
|
||||
*/
|
||||
bool efr32IsFramePending(otRadioFrame *aFrame);
|
||||
|
||||
/**
|
||||
* This function returns the Destination PanId, if present.
|
||||
*
|
||||
* @param[in] aFrame A pointer to the MAC frame buffer.
|
||||
*
|
||||
* @retval DstPanId If present.
|
||||
* @retval BcastPanId If Dest PanId is compressed.
|
||||
*/
|
||||
otPanId efr32GetDstPanId(otRadioFrame *aFrame);
|
||||
|
||||
/**
|
||||
* This function returns the start of payload pointer.
|
||||
*
|
||||
* @param[in] aFrame A pointer to the MAC frame buffer.
|
||||
*
|
||||
* @retval Pointer to start of 802.15.4 payload.
|
||||
*/
|
||||
uint8_t *efr32GetPayload(otRadioFrame *aFrame);
|
||||
|
||||
/**
|
||||
* This function checks if the PAN ID Compression bit is set in the given MAC frame.
|
||||
*
|
||||
* @param[in] aFrame A pointer to the MAC frame buffer.
|
||||
*
|
||||
* @return true if the PAN ID Compression bit is set, false otherwise.
|
||||
*/
|
||||
bool efr32FrameIsPanIdCompressed(otRadioFrame *aFrame);
|
||||
|
||||
/**
|
||||
* This function returns the frame version.
|
||||
*
|
||||
* @param[in] aFrame A pointer to the MAC frame buffer.
|
||||
*
|
||||
* @retval Frame version.
|
||||
*/
|
||||
uint16_t efr32GetFrameVersion(otRadioFrame *aFrame);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif /* SL_PACKET_HANDLER_H */
|
||||
226
Libs/protocol/openthread/platform-abstraction/efr32/sleep.c
Normal file
226
Libs/protocol/openthread/platform-abstraction/efr32/sleep.c
Normal file
@@ -0,0 +1,226 @@
|
||||
/*
|
||||
* Copyright (c) 2023, 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 platform abstraction for power (sleep)
|
||||
* management.
|
||||
*
|
||||
*/
|
||||
|
||||
#define CURRENT_MODULE_NAME "OPENTHREAD"
|
||||
|
||||
#ifdef SL_COMPONENT_CATALOG_PRESENT
|
||||
#include "sl_component_catalog.h"
|
||||
#endif // SL_COMPONENT_CATALOG_PRESENT
|
||||
|
||||
#include "alarm.h"
|
||||
#include "sl_core.h"
|
||||
#include "sleep.h"
|
||||
|
||||
#include "platform-efr32.h"
|
||||
#include <assert.h>
|
||||
#include <openthread-core-config.h>
|
||||
#include <openthread/tasklet.h>
|
||||
#include <openthread/platform/toolchain.h>
|
||||
|
||||
#include "sl_multipan.h"
|
||||
|
||||
#include "utils/code_utils.h"
|
||||
|
||||
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
|
||||
#include "sl_power_manager.h"
|
||||
#endif // SL_CATALOG_POWER_MANAGER_PRESENT
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
|
||||
#if (defined(SL_CATALOG_POWER_MANAGER_PRESENT))
|
||||
|
||||
static void setWakeRequirement(bool aShouldWake);
|
||||
static bool isPlatformEventPending(void);
|
||||
static bool shouldStayAwake(void);
|
||||
static bool instanceShouldInterruptSleep(otInstance *aInstance);
|
||||
static bool shouldInterruptSleep(void);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Static variables
|
||||
|
||||
static bool sWakeRequirementSet = false;
|
||||
|
||||
#endif // SL_CATALOG_POWER_MANAGER_PRESENT
|
||||
|
||||
extern otInstance *sInstance;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Internal APIs and callbacks
|
||||
|
||||
void sl_ot_sleep_init(void)
|
||||
{
|
||||
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
|
||||
setWakeRequirement(true);
|
||||
#else
|
||||
sWakeRequirementSet = true;
|
||||
#endif // SL_CATALOG_POWER_MANAGER_PRESENT
|
||||
}
|
||||
|
||||
SL_CODE_CLASSIFY(SL_CODE_COMPONENT_OT_PLATFORM_ABSTRACTION, SL_CODE_CLASS_TIME_CRITICAL)
|
||||
OT_TOOL_WEAK bool efr32AllowSleepCallback(void)
|
||||
{
|
||||
return !sWakeRequirementSet;
|
||||
}
|
||||
|
||||
#if (defined(SL_CATALOG_POWER_MANAGER_PRESENT))
|
||||
|
||||
// This is invoked only the bare metal case.
|
||||
bool sl_ot_is_ok_to_sleep(void)
|
||||
{
|
||||
return !(sWakeRequirementSet || shouldInterruptSleep());
|
||||
}
|
||||
|
||||
// This is invoked only the bare metal case.
|
||||
sl_power_manager_on_isr_exit_t sl_ot_sleep_on_isr_exit(void)
|
||||
{
|
||||
return (isPlatformEventPending() ? SL_POWER_MANAGER_WAKEUP : SL_POWER_MANAGER_IGNORE);
|
||||
}
|
||||
|
||||
void sl_ot_sleep_update(void)
|
||||
{
|
||||
setWakeRequirement(shouldStayAwake());
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Static functions
|
||||
|
||||
/**
|
||||
* @brief Set the wake requirement for the system.
|
||||
*
|
||||
* @param[in] aShouldWake True if the system should wake up.
|
||||
*
|
||||
*/
|
||||
static void setWakeRequirement(bool aShouldWake)
|
||||
{
|
||||
otEXPECT(aShouldWake != sWakeRequirementSet);
|
||||
void (*em_operation)(sl_power_manager_em_t) =
|
||||
aShouldWake ? &sl_power_manager_add_em_requirement : &sl_power_manager_remove_em_requirement;
|
||||
(*em_operation)(SL_POWER_MANAGER_EM1);
|
||||
sWakeRequirementSet = aShouldWake;
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if there is any platform event pending.
|
||||
*
|
||||
* @return True if there is a platform event pending.
|
||||
*
|
||||
*/
|
||||
static bool isPlatformEventPending(void)
|
||||
{
|
||||
bool isPending = efr32AlarmIsReady();
|
||||
|
||||
#if defined(SL_CATALOG_IOSTREAM_EUSART_PRESENT) || defined(SL_CATALOG_IOSTREAM_USART_PRESENT)
|
||||
isPending = isPending || efr32UartIsDataReady();
|
||||
#endif
|
||||
|
||||
return isPending;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if the system should stay awake.
|
||||
*
|
||||
* @return True if the system should stay awake.
|
||||
*
|
||||
*/
|
||||
static bool shouldStayAwake(void)
|
||||
{
|
||||
bool shouldWake = (!(efr32AllowSleepCallback()) || isPlatformEventPending());
|
||||
|
||||
#if defined SL_CATALOG_KERNEL_PRESENT
|
||||
shouldWake = shouldWake || shouldInterruptSleep();
|
||||
#endif
|
||||
|
||||
return shouldWake;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if individual instance should interrupt sleep.
|
||||
*
|
||||
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||
*
|
||||
* @return True if the system should interrupt sleep.
|
||||
*
|
||||
*/
|
||||
static bool instanceShouldInterruptSleep(otInstance *aInstance)
|
||||
{
|
||||
bool shouldWake = true;
|
||||
|
||||
otEXPECT(aInstance != NULL);
|
||||
|
||||
shouldWake = otTaskletsArePending(aInstance);
|
||||
|
||||
shouldWake = shouldWake
|
||||
|| (efr32AlarmIsRunning(aInstance)
|
||||
&& efr32AlarmPendingTime(aInstance) < OPENTHREAD_CONFIG_MIN_SLEEP_DURATION_MS);
|
||||
|
||||
exit:
|
||||
return shouldWake;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if the system should interrupt sleep.
|
||||
*
|
||||
* @details This function should be used to prevent power manager from entering sleep mode
|
||||
* based on events that happen after the OpenThread power manager module complete.
|
||||
*
|
||||
* @return True if the system should interrupt sleep.
|
||||
*
|
||||
*/
|
||||
static bool shouldInterruptSleep(void)
|
||||
{
|
||||
CORE_ATOMIC_IRQ_DISABLE();
|
||||
|
||||
otInstance *instance;
|
||||
bool shouldWake = false;
|
||||
|
||||
uint8_t instanceIndex = 0;
|
||||
|
||||
while ((!shouldWake) && instanceIndex < OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_NUM)
|
||||
{
|
||||
// Use instance offset from multipan index for multipan configuration
|
||||
// or sInstance for non-multipan configuration
|
||||
instance = efr32GetInstanceFromIid((efr32Iid_t)(instanceIndex + 1));
|
||||
shouldWake = instanceShouldInterruptSleep(instance);
|
||||
instanceIndex++;
|
||||
}
|
||||
|
||||
CORE_ATOMIC_IRQ_ENABLE();
|
||||
|
||||
return shouldWake;
|
||||
}
|
||||
#endif // SL_CATALOG_POWER_MANAGER_PRESENT
|
||||
88
Libs/protocol/openthread/platform-abstraction/efr32/sleep.h
Normal file
88
Libs/protocol/openthread/platform-abstraction/efr32/sleep.h
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (c) 2023, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file includes the initializers for supporting OpenThread with
|
||||
* power manager.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SLEEP_H_
|
||||
#define SLEEP_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef SL_COMPONENT_CATALOG_PRESENT
|
||||
#include "sl_component_catalog.h"
|
||||
#endif
|
||||
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
|
||||
#include "sl_power_manager.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function initializes the sleep interface
|
||||
* and starts the platform in an active state.
|
||||
*
|
||||
*/
|
||||
void sl_ot_sleep_init(void);
|
||||
|
||||
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
|
||||
/**
|
||||
* This function notifies the platform to refresh sleep requirements.
|
||||
*
|
||||
*/
|
||||
void sl_ot_sleep_update(void);
|
||||
|
||||
/**
|
||||
* This function notifies power manager whether OpenThread will
|
||||
* prevent the system from sleeping when sleep is requested.
|
||||
*
|
||||
* This function is only used for bare metal applications.
|
||||
*
|
||||
* @retval true The OpenThread power manager module will not prevent app from sleeping.
|
||||
* false The OpenThread power manager module will prevent app from sleeping.
|
||||
*
|
||||
*/
|
||||
bool sl_ot_is_ok_to_sleep(void);
|
||||
|
||||
/**
|
||||
* This function notifies power manager whether OpenThread will
|
||||
* prevent the system from sleeping when an ISR that interrupt sleep exits.
|
||||
*
|
||||
* This function is only used for bare metal applications.
|
||||
*
|
||||
* @retval SL_POWER_MANAGER_IGNORE The OpenThread power manager module will not influence
|
||||
* power manager when deciding to sleep after ISR exit
|
||||
* SL_POWER_MANAGER_WAKEUP The OpenThread power manager module will prevent
|
||||
* power manager from entering sleep after ISR exit.
|
||||
*/
|
||||
sl_power_manager_on_isr_exit_t sl_ot_sleep_on_isr_exit(void);
|
||||
#endif
|
||||
|
||||
#endif // SLEEP_H_
|
||||
@@ -0,0 +1,406 @@
|
||||
/*
|
||||
* Copyright (c) 2023, 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 a software Source Match table, for radios that don't have
|
||||
* such hardware acceleration. It supports only the single-instance build of
|
||||
* OpenThread.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "soft_source_match_table.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openthread/logging.h>
|
||||
#if OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
|
||||
#include <openthread/platform/multipan.h>
|
||||
#endif
|
||||
#include "sl_multipan.h"
|
||||
#include "common/debug.hpp"
|
||||
#include "utils/code_utils.h"
|
||||
|
||||
// Print entire source match tables when
|
||||
#define PRINT_MULTIPAN_SOURCE_MATCH_TABLES 0
|
||||
|
||||
#if RADIO_CONFIG_SRC_MATCH_SHORT_ENTRY_NUM || RADIO_CONFIG_SRC_MATCH_EXT_ENTRY_NUM
|
||||
static uint16_t sPanId[RADIO_CONFIG_SRC_MATCH_PANID_NUM] = {0};
|
||||
|
||||
#if PRINT_MULTIPAN_SOURCE_MATCH_TABLES
|
||||
static void printPanIdTable(void)
|
||||
{
|
||||
for (uint8_t panIndex = 0; panIndex < RADIO_CONFIG_SRC_MATCH_PANID_NUM; panIndex++)
|
||||
{
|
||||
otLogDebgPlat("sPanId[panIndex=%d] = 0x%04x", panIndex, sPanId[panIndex]);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define printPanIdTable()
|
||||
#endif
|
||||
|
||||
void utilsSoftSrcMatchSetPanId(uint8_t iid, uint16_t aPanId)
|
||||
{
|
||||
const uint8_t panIndex = efr32GetPanIndexFromIid(iid);
|
||||
sPanId[panIndex] = aPanId;
|
||||
otLogInfoPlat("Setting panIndex=%d to 0x%04x", panIndex, aPanId);
|
||||
|
||||
printPanIdTable();
|
||||
}
|
||||
#endif // RADIO_CONFIG_SRC_MATCH_SHORT_ENTRY_NUM || RADIO_CONFIG_SRC_MATCH_EXT_ENTRY_NUM
|
||||
|
||||
#if RADIO_CONFIG_SRC_MATCH_SHORT_ENTRY_NUM
|
||||
typedef struct srcMatchShortEntry
|
||||
{
|
||||
uint16_t checksum;
|
||||
bool allocated;
|
||||
} sSrcMatchShortEntry;
|
||||
|
||||
static sSrcMatchShortEntry srcMatchShortEntry[RADIO_CONFIG_SRC_MATCH_PANID_NUM][RADIO_CONFIG_SRC_MATCH_SHORT_ENTRY_NUM];
|
||||
|
||||
#if PRINT_MULTIPAN_SOURCE_MATCH_TABLES
|
||||
static void printShortEntryTable(uint8_t iid)
|
||||
{
|
||||
const uint8_t panIndex = efr32GetPanIndexFromIid(iid);
|
||||
|
||||
otLogDebgPlat("================================|============|===========");
|
||||
otLogDebgPlat("ShortEntry[panIndex][entry] | .allocated | .checksum ");
|
||||
otLogDebgPlat("================================|============|===========");
|
||||
for (int16_t i = 0; i < RADIO_CONFIG_SRC_MATCH_SHORT_ENTRY_NUM; i++)
|
||||
{
|
||||
otLogDebgPlat("ShortEntry[panIndex=%d][entry=%d] | %d | 0x%04x",
|
||||
panIndex,
|
||||
i,
|
||||
srcMatchShortEntry[panIndex][i].allocated,
|
||||
srcMatchShortEntry[panIndex][i].checksum);
|
||||
}
|
||||
otLogDebgPlat("================================|============|===========");
|
||||
}
|
||||
#else
|
||||
#define printShortEntryTable(iid)
|
||||
#endif
|
||||
|
||||
int16_t utilsSoftSrcMatchShortFindEntry(uint8_t iid, uint16_t aShortAddress)
|
||||
{
|
||||
int16_t entry = -1;
|
||||
|
||||
#if OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
|
||||
if (iid == 0)
|
||||
{
|
||||
return entry;
|
||||
}
|
||||
#endif
|
||||
|
||||
const uint8_t panIndex = efr32GetPanIndexFromIid(iid);
|
||||
uint16_t checksum = aShortAddress + sPanId[panIndex];
|
||||
|
||||
for (int16_t i = 0; i < RADIO_CONFIG_SRC_MATCH_SHORT_ENTRY_NUM; i++)
|
||||
{
|
||||
if (checksum == srcMatchShortEntry[panIndex][i].checksum && srcMatchShortEntry[panIndex][i].allocated)
|
||||
{
|
||||
entry = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
static int16_t findSrcMatchShortAvailEntry(uint8_t iid)
|
||||
{
|
||||
int16_t entry = -1;
|
||||
const uint8_t panIndex = efr32GetPanIndexFromIid(iid);
|
||||
|
||||
for (int16_t i = 0; i < RADIO_CONFIG_SRC_MATCH_SHORT_ENTRY_NUM; i++)
|
||||
{
|
||||
if (!srcMatchShortEntry[panIndex][i].allocated)
|
||||
{
|
||||
entry = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
static inline void addToSrcMatchShortIndirect(uint8_t iid, uint16_t entry, uint16_t aShortAddress)
|
||||
{
|
||||
const uint8_t panIndex = efr32GetPanIndexFromIid(iid);
|
||||
uint16_t checksum = aShortAddress + sPanId[panIndex];
|
||||
|
||||
srcMatchShortEntry[panIndex][entry].checksum = checksum;
|
||||
srcMatchShortEntry[panIndex][entry].allocated = true;
|
||||
|
||||
printShortEntryTable(iid);
|
||||
}
|
||||
|
||||
static inline void removeFromSrcMatchShortIndirect(uint8_t iid, uint16_t entry)
|
||||
{
|
||||
const uint8_t panIndex = efr32GetPanIndexFromIid(iid);
|
||||
|
||||
srcMatchShortEntry[panIndex][entry].allocated = false;
|
||||
srcMatchShortEntry[panIndex][entry].checksum = 0;
|
||||
|
||||
printShortEntryTable(iid);
|
||||
}
|
||||
|
||||
otError otPlatRadioAddSrcMatchShortEntry(otInstance *aInstance, uint16_t aShortAddress)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
otError error = OT_ERROR_NONE;
|
||||
int8_t iid = efr32GetIidFromInstance(aInstance);
|
||||
int16_t entry = -1;
|
||||
|
||||
#if OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
|
||||
entry = utilsSoftSrcMatchShortFindEntry(iid, aShortAddress);
|
||||
// Prevent duplicate entries in multipan use case.
|
||||
otEXPECT(!(entry >= 0 && entry < RADIO_CONFIG_SRC_MATCH_SHORT_ENTRY_NUM));
|
||||
#endif
|
||||
|
||||
entry = findSrcMatchShortAvailEntry(iid);
|
||||
|
||||
otLogDebgPlat("Add ShortAddr: iid=%d, entry=%d, addr=0x%04x", iid, entry, aShortAddress);
|
||||
|
||||
otEXPECT_ACTION(entry >= 0 && entry < RADIO_CONFIG_SRC_MATCH_SHORT_ENTRY_NUM, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
addToSrcMatchShortIndirect(iid, (uint16_t)entry, aShortAddress);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatRadioClearSrcMatchShortEntry(otInstance *aInstance, uint16_t aShortAddress)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
otError error = OT_ERROR_NONE;
|
||||
int8_t iid = efr32GetIidFromInstance(aInstance);
|
||||
int16_t entry = utilsSoftSrcMatchShortFindEntry(iid, aShortAddress);
|
||||
|
||||
otLogDebgPlat("Clear ShortAddr: iid=%d, entry=%d, addr=0x%04x", iid, entry, aShortAddress);
|
||||
|
||||
otEXPECT_ACTION(entry >= 0 && entry < RADIO_CONFIG_SRC_MATCH_SHORT_ENTRY_NUM, error = OT_ERROR_NO_ADDRESS);
|
||||
|
||||
removeFromSrcMatchShortIndirect(iid, (uint16_t)entry);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void otPlatRadioClearSrcMatchShortEntries(otInstance *aInstance)
|
||||
{
|
||||
uint8_t iid = efr32GetIidFromInstance(aInstance);
|
||||
|
||||
const uint8_t panIndex = efr32GetPanIndexFromIid(iid);
|
||||
|
||||
otLogDebgPlat("Clear ShortAddr entries (iid: %d)", iid);
|
||||
|
||||
memset(srcMatchShortEntry[panIndex], 0, sizeof(srcMatchShortEntry[panIndex]));
|
||||
|
||||
printShortEntryTable(iid);
|
||||
}
|
||||
#endif // RADIO_CONFIG_SRC_MATCH_SHORT_ENTRY_NUM
|
||||
|
||||
#if RADIO_CONFIG_SRC_MATCH_EXT_ENTRY_NUM
|
||||
typedef struct srcMatchExtEntry
|
||||
{
|
||||
uint16_t checksum;
|
||||
bool allocated;
|
||||
} sSrcMatchExtEntry;
|
||||
|
||||
static sSrcMatchExtEntry srcMatchExtEntry[RADIO_CONFIG_SRC_MATCH_PANID_NUM][RADIO_CONFIG_SRC_MATCH_EXT_ENTRY_NUM];
|
||||
|
||||
#if PRINT_MULTIPAN_SOURCE_MATCH_TABLES
|
||||
static void printExtEntryTable(uint8_t iid)
|
||||
{
|
||||
const uint8_t panIndex = efr32GetPanIndexFromIid(iid);
|
||||
|
||||
otLogDebgPlat("==============================|============|===========");
|
||||
otLogDebgPlat("ExtEntry[panIndex][entry] | .allocated | .checksum ");
|
||||
otLogDebgPlat("==============================|============|===========");
|
||||
for (int16_t i = 0; i < RADIO_CONFIG_SRC_MATCH_EXT_ENTRY_NUM; i++)
|
||||
{
|
||||
otLogDebgPlat("ExtEntry[panIndex=%d][entry=%d] | %d | 0x%04x",
|
||||
panIndex,
|
||||
i,
|
||||
srcMatchExtEntry[panIndex][i].allocated,
|
||||
srcMatchExtEntry[panIndex][i].checksum);
|
||||
}
|
||||
otLogDebgPlat("==============================|============|===========");
|
||||
}
|
||||
#else
|
||||
#define printExtEntryTable(iid)
|
||||
#endif
|
||||
|
||||
int16_t utilsSoftSrcMatchExtFindEntry(uint8_t iid, const otExtAddress *aExtAddress)
|
||||
{
|
||||
int16_t entry = -1;
|
||||
|
||||
#if OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
|
||||
if (iid == 0)
|
||||
{
|
||||
return entry;
|
||||
}
|
||||
#endif
|
||||
|
||||
const uint8_t panIndex = efr32GetPanIndexFromIid(iid);
|
||||
uint16_t checksum = sPanId[panIndex];
|
||||
|
||||
checksum += (uint16_t)aExtAddress->m8[0] | (uint16_t)(aExtAddress->m8[1] << 8);
|
||||
checksum += (uint16_t)aExtAddress->m8[2] | (uint16_t)(aExtAddress->m8[3] << 8);
|
||||
checksum += (uint16_t)aExtAddress->m8[4] | (uint16_t)(aExtAddress->m8[5] << 8);
|
||||
checksum += (uint16_t)aExtAddress->m8[6] | (uint16_t)(aExtAddress->m8[7] << 8);
|
||||
|
||||
for (int16_t i = 0; i < RADIO_CONFIG_SRC_MATCH_EXT_ENTRY_NUM; i++)
|
||||
{
|
||||
if (checksum == srcMatchExtEntry[panIndex][i].checksum && srcMatchExtEntry[panIndex][i].allocated)
|
||||
{
|
||||
entry = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
static int16_t findSrcMatchExtAvailEntry(uint8_t iid)
|
||||
{
|
||||
int16_t entry = -1;
|
||||
const uint8_t panIndex = efr32GetPanIndexFromIid(iid);
|
||||
|
||||
for (int16_t i = 0; i < RADIO_CONFIG_SRC_MATCH_EXT_ENTRY_NUM; i++)
|
||||
{
|
||||
if (!srcMatchExtEntry[panIndex][i].allocated)
|
||||
{
|
||||
entry = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
static inline void addToSrcMatchExtIndirect(uint8_t iid, uint16_t entry, const otExtAddress *aExtAddress)
|
||||
{
|
||||
const uint8_t panIndex = efr32GetPanIndexFromIid(iid);
|
||||
uint16_t checksum = sPanId[panIndex];
|
||||
|
||||
checksum += (uint16_t)aExtAddress->m8[0] | (uint16_t)(aExtAddress->m8[1] << 8);
|
||||
checksum += (uint16_t)aExtAddress->m8[2] | (uint16_t)(aExtAddress->m8[3] << 8);
|
||||
checksum += (uint16_t)aExtAddress->m8[4] | (uint16_t)(aExtAddress->m8[5] << 8);
|
||||
checksum += (uint16_t)aExtAddress->m8[6] | (uint16_t)(aExtAddress->m8[7] << 8);
|
||||
|
||||
srcMatchExtEntry[panIndex][entry].checksum = checksum;
|
||||
srcMatchExtEntry[panIndex][entry].allocated = true;
|
||||
|
||||
printExtEntryTable(iid);
|
||||
}
|
||||
|
||||
static inline void removeFromSrcMatchExtIndirect(uint8_t iid, uint16_t entry)
|
||||
{
|
||||
const uint8_t panIndex = efr32GetPanIndexFromIid(iid);
|
||||
|
||||
srcMatchExtEntry[panIndex][entry].allocated = false;
|
||||
srcMatchExtEntry[panIndex][entry].checksum = 0;
|
||||
|
||||
printExtEntryTable(iid);
|
||||
}
|
||||
|
||||
otError otPlatRadioAddSrcMatchExtEntry(otInstance *aInstance, const otExtAddress *aExtAddress)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint8_t iid = efr32GetIidFromInstance(aInstance);
|
||||
int16_t entry = -1;
|
||||
|
||||
#if OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
|
||||
entry = utilsSoftSrcMatchExtFindEntry(iid, aExtAddress);
|
||||
// Prevent duplicate entries in multipan use case.
|
||||
otEXPECT(!(entry >= 0 && entry < RADIO_CONFIG_SRC_MATCH_EXT_ENTRY_NUM));
|
||||
#endif
|
||||
|
||||
entry = findSrcMatchExtAvailEntry(iid);
|
||||
|
||||
otLogDebgPlat("Add ExtAddr: iid=%d, entry=%d, addr %p", iid, entry, (void *)aExtAddress->m8);
|
||||
|
||||
otEXPECT_ACTION(entry >= 0 && entry < RADIO_CONFIG_SRC_MATCH_EXT_ENTRY_NUM, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
addToSrcMatchExtIndirect(iid, (uint16_t)entry, aExtAddress);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatRadioClearSrcMatchExtEntry(otInstance *aInstance, const otExtAddress *aExtAddress)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint8_t iid = efr32GetIidFromInstance(aInstance);
|
||||
int16_t entry = utilsSoftSrcMatchExtFindEntry(iid, aExtAddress);
|
||||
|
||||
otLogDebgPlat("Clear ExtAddr: iid=%d, entry=%d", iid, entry);
|
||||
|
||||
otEXPECT_ACTION(entry >= 0 && entry < RADIO_CONFIG_SRC_MATCH_EXT_ENTRY_NUM, error = OT_ERROR_NO_ADDRESS);
|
||||
|
||||
removeFromSrcMatchExtIndirect(iid, (uint16_t)entry);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void otPlatRadioClearSrcMatchExtEntries(otInstance *aInstance)
|
||||
{
|
||||
uint8_t iid = efr32GetIidFromInstance(aInstance);
|
||||
|
||||
otLogDebgPlat("Clear ExtAddr entries (iid: %d)", iid);
|
||||
const uint8_t panIndex = efr32GetPanIndexFromIid(iid);
|
||||
|
||||
memset(srcMatchExtEntry[panIndex], 0, sizeof(srcMatchExtEntry[panIndex]));
|
||||
|
||||
printExtEntryTable(iid);
|
||||
}
|
||||
#endif // RADIO_CONFIG_SRC_MATCH_EXT_ENTRY_NUM
|
||||
|
||||
uint8_t utilsSoftSrcMatchFindIidFromPanId(otPanId panId)
|
||||
{
|
||||
uint8_t iid = INVALID_INTERFACE_INDEX;
|
||||
|
||||
for (uint8_t index = 0; index < RADIO_CONFIG_SRC_MATCH_PANID_NUM; index++)
|
||||
{
|
||||
if (sPanId[index] == panId)
|
||||
{
|
||||
iid = index + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return iid;
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2023, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief
|
||||
* This file defines the software source match table interfaces used by
|
||||
* soft_source_match_table.c.
|
||||
*/
|
||||
|
||||
#ifndef SOFT_SOURCE_MATCH_TABLE_H
|
||||
#define SOFT_SOURCE_MATCH_TABLE_H
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
#if OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
|
||||
#include "spinel/openthread-spinel-config.h"
|
||||
#endif
|
||||
#include <openthread/platform/radio.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef RADIO_CONFIG_SRC_MATCH_SHORT_ENTRY_NUM
|
||||
#if OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
|
||||
#define RADIO_CONFIG_SRC_MATCH_SHORT_ENTRY_NUM OPENTHREAD_SPINEL_CONFIG_MAX_SRC_MATCH_ENTRIES
|
||||
#else
|
||||
#define RADIO_CONFIG_SRC_MATCH_SHORT_ENTRY_NUM OPENTHREAD_CONFIG_MLE_MAX_CHILDREN
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef RADIO_CONFIG_SRC_MATCH_EXT_ENTRY_NUM
|
||||
#if OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
|
||||
#define RADIO_CONFIG_SRC_MATCH_EXT_ENTRY_NUM OPENTHREAD_SPINEL_CONFIG_MAX_SRC_MATCH_ENTRIES
|
||||
#else
|
||||
#define RADIO_CONFIG_SRC_MATCH_EXT_ENTRY_NUM OPENTHREAD_CONFIG_MLE_MAX_CHILDREN
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef RADIO_CONFIG_SRC_MATCH_PANID_NUM
|
||||
#if OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
|
||||
#define RADIO_CONFIG_SRC_MATCH_PANID_NUM 3
|
||||
#else
|
||||
#define RADIO_CONFIG_SRC_MATCH_PANID_NUM 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if RADIO_CONFIG_SRC_MATCH_SHORT_ENTRY_NUM || RADIO_CONFIG_SRC_MATCH_EXT_ENTRY_NUM
|
||||
void utilsSoftSrcMatchSetPanId(uint8_t iid, uint16_t aPanId);
|
||||
#endif // RADIO_CONFIG_SRC_MATCH_SHORT_ENTRY_NUM || RADIO_CONFIG_SRC_MATCH_EXT_ENTRY_NUM
|
||||
|
||||
#if RADIO_CONFIG_SRC_MATCH_SHORT_ENTRY_NUM
|
||||
int16_t utilsSoftSrcMatchShortFindEntry(uint8_t iid, uint16_t aShortAddress);
|
||||
#endif // RADIO_CONFIG_SRC_MATCH_SHORT_ENTRY_NUM
|
||||
|
||||
#if RADIO_CONFIG_SRC_MATCH_EXT_ENTRY_NUM
|
||||
int16_t utilsSoftSrcMatchExtFindEntry(uint8_t iid, const otExtAddress *aExtAddress);
|
||||
#endif // RADIO_CONFIG_SRC_MATCH_EXT_ENTRY_NUM
|
||||
|
||||
uint8_t utilsSoftSrcMatchFindIidFromPanId(otPanId panId);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // SOFT_SOURCE_MATCH_TABLE_H
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2023, 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 gcc-specific startup code for the efr32.
|
||||
*/
|
||||
|
||||
__extension__ typedef int __guard __attribute__((mode(__DI__)));
|
||||
|
||||
int __cxa_guard_acquire(__guard *g)
|
||||
{
|
||||
return !*(char *)(g);
|
||||
}
|
||||
|
||||
void __cxa_guard_release(__guard *g)
|
||||
{
|
||||
*(char *)g = 1;
|
||||
}
|
||||
|
||||
void __cxa_guard_abort(__guard *g)
|
||||
{
|
||||
(void)g;
|
||||
}
|
||||
|
||||
void __cxa_pure_virtual(void)
|
||||
{
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
185
Libs/protocol/openthread/platform-abstraction/efr32/system.c
Normal file
185
Libs/protocol/openthread/platform-abstraction/efr32/system.c
Normal file
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* Copyright (c) 2023, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief
|
||||
* This file includes the platform-specific initializers.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(SL_COMPONENT_CATALOG_PRESENT)
|
||||
#include "sl_component_catalog.h"
|
||||
#endif
|
||||
|
||||
#include <openthread-core-config.h>
|
||||
#include <openthread-system.h>
|
||||
#include <openthread/platform/toolchain.h>
|
||||
|
||||
#include "utils/uart.h"
|
||||
|
||||
#include "rail.h"
|
||||
#include "common/logging.hpp"
|
||||
|
||||
#if defined(SL_CATALOG_MPU_PRESENT)
|
||||
#include "sl_mpu.h"
|
||||
#endif
|
||||
|
||||
#include "sl_memory_manager.h"
|
||||
#include "sl_sleeptimer.h"
|
||||
|
||||
#if OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
|
||||
#include "sl_gp_interface.h"
|
||||
#endif
|
||||
|
||||
#include "alarm.h"
|
||||
#include "platform-efr32.h"
|
||||
|
||||
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
|
||||
#include "sleep.h"
|
||||
#endif
|
||||
|
||||
#define USE_EFR32_LOG (OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED)
|
||||
|
||||
#if defined(SL_CATALOG_OPENTHREAD_CLI_PRESENT) && defined(SL_CATALOG_KERNEL_PRESENT)
|
||||
#define SERIAL_TASK_ENABLED (SL_OPENTHREAD_ENABLE_SERIAL_TASK)
|
||||
#else
|
||||
#define SERIAL_TASK_ENABLED (0)
|
||||
#endif
|
||||
|
||||
otInstance *sInstance;
|
||||
|
||||
#if (OPENTHREAD_RADIO)
|
||||
static void efr32NcpProcess(void);
|
||||
#else
|
||||
static void efr32CliProcess(void);
|
||||
#endif
|
||||
|
||||
#ifndef SL_COMPONENT_CATALOG_PRESENT
|
||||
OT_TOOL_WEAK void sl_openthread_init(void)
|
||||
{
|
||||
// Placeholder for enabling Silabs specific features available only through Simplicity Studio
|
||||
}
|
||||
#else
|
||||
void sl_openthread_init(void);
|
||||
#endif // SL_COMPONENT_CATALOG_PRESENT
|
||||
|
||||
void otSysInit(int argc, char *argv[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(argc);
|
||||
OT_UNUSED_VARIABLE(argv);
|
||||
sl_ot_sys_init();
|
||||
}
|
||||
|
||||
void sl_ot_sys_init(void)
|
||||
{
|
||||
sl_openthread_init();
|
||||
|
||||
#if USE_EFR32_LOG
|
||||
efr32LogInit();
|
||||
#endif
|
||||
efr32AlarmInit();
|
||||
efr32RadioInit();
|
||||
efr32MiscInit();
|
||||
}
|
||||
|
||||
bool otSysPseudoResetWasRequested(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void otSysDeinit(void)
|
||||
{
|
||||
efr32RadioDeinit();
|
||||
|
||||
#if USE_EFR32_LOG
|
||||
efr32LogDeinit();
|
||||
#endif
|
||||
}
|
||||
|
||||
void otSysProcessDrivers(otInstance *aInstance)
|
||||
{
|
||||
sInstance = aInstance;
|
||||
|
||||
// should sleep and wait for interrupts here
|
||||
#if OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
|
||||
efr32GpProcess();
|
||||
#endif
|
||||
|
||||
#if (SERIAL_TASK_ENABLED == 0)
|
||||
// Serial task is not enabled, process serial events here
|
||||
efr32SerialProcess();
|
||||
#endif
|
||||
|
||||
efr32RadioProcess(aInstance);
|
||||
|
||||
// See alarm.c: Wrapped in a critical section
|
||||
efr32AlarmProcess(aInstance);
|
||||
|
||||
#if !defined(SL_CATALOG_KERNEL_PRESENT)
|
||||
otSysEventSignalPending();
|
||||
#endif
|
||||
}
|
||||
|
||||
OT_TOOL_WEAK void otSysEventSignalPending(void)
|
||||
{
|
||||
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
|
||||
sl_ot_sleep_update();
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Serial process helper functions */
|
||||
|
||||
void efr32SerialProcess(void)
|
||||
{
|
||||
#if (OPENTHREAD_RADIO)
|
||||
efr32NcpProcess();
|
||||
#else
|
||||
efr32CliProcess();
|
||||
#endif // OPENTHREAD_RADIO
|
||||
}
|
||||
|
||||
#if (OPENTHREAD_RADIO)
|
||||
static void efr32NcpProcess(void)
|
||||
{
|
||||
#if OPENTHREAD_CONFIG_NCP_HDLC_ENABLE
|
||||
efr32UartProcess();
|
||||
#elif OPENTHREAD_CONFIG_NCP_CPC_ENABLE
|
||||
efr32CpcProcess();
|
||||
#elif OPENTHREAD_CONFIG_NCP_SPI_ENABLE
|
||||
efr32SpiProcess();
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
static void efr32CliProcess(void)
|
||||
{
|
||||
efr32UartProcess();
|
||||
}
|
||||
#endif
|
||||
32
Libs/protocol/openthread/platform-abstraction/efr32/uart.h
Normal file
32
Libs/protocol/openthread/platform-abstraction/efr32/uart.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef _UART_H
|
||||
#define _UART_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
/**
|
||||
* The size of the receive buffer
|
||||
*
|
||||
*/
|
||||
#define RECEIVE_BUFFER_SIZE 128
|
||||
|
||||
/**
|
||||
* This function initializes the UART interface.
|
||||
*
|
||||
*/
|
||||
void efr32UartInit(void);
|
||||
|
||||
/**
|
||||
* This function performs UART processing.
|
||||
*
|
||||
*/
|
||||
void efr32UartProcess(void);
|
||||
|
||||
/**
|
||||
* This function informs the caller whether UART
|
||||
* operations are ready to process
|
||||
*
|
||||
* @return true if RX or TX data is ready to process.
|
||||
*/
|
||||
bool efr32UartIsDataReady(void);
|
||||
|
||||
#endif // _UART_H
|
||||
Reference in New Issue
Block a user