diff --git a/components/openthread/CMakeLists.txt b/components/openthread/CMakeLists.txt index 53eb0e6078..7a40455ca5 100644 --- a/components/openthread/CMakeLists.txt +++ b/components/openthread/CMakeLists.txt @@ -67,6 +67,7 @@ if(CONFIG_OPENTHREAD_ENABLED) "openthread/src/core/api/icmp6_api.cpp" "openthread/src/core/api/ip6_api.cpp" "openthread/src/core/api/link_api.cpp" + "openthread/src/core/api/link_metrics_api.cpp" "openthread/src/core/api/message_api.cpp" "openthread/src/core/api/nat64_api.cpp" "openthread/src/core/api/netdata_api.cpp" @@ -91,6 +92,7 @@ if(CONFIG_OPENTHREAD_ENABLED) "openthread/src/core/thread/discover_scanner.cpp" "openthread/src/core/thread/energy_scan_server.cpp" "openthread/src/core/thread/key_manager.cpp" + "openthread/src/core/thread/link_metrics.cpp" "openthread/src/core/thread/lowpan.cpp" "openthread/src/core/thread/mesh_forwarder.cpp" "openthread/src/core/thread/mesh_forwarder_ftd.cpp" diff --git a/components/openthread/port/esp_openthread_alarm.c b/components/openthread/port/esp_openthread_alarm.c index 92596dcc96..f1e4a52d12 100644 --- a/components/openthread/port/esp_openthread_alarm.c +++ b/components/openthread/port/esp_openthread_alarm.c @@ -41,12 +41,7 @@ static inline uint32_t calculate_duration(uint32_t target, uint32_t now) uint64_t otPlatTimeGet(void) { - struct timeval tv_now; - - int err = gettimeofday(&tv_now, NULL); - assert(err == 0); - - return (uint64_t)tv_now.tv_sec * US_PER_S + tv_now.tv_usec; + return (uint64_t)esp_timer_get_time(); } void otPlatAlarmMilliStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt) @@ -68,7 +63,7 @@ void otPlatAlarmMilliStop(otInstance *aInstance) uint32_t inline otPlatAlarmMilliGetNow(void) { - return esp_timer_get_time() / US_PER_MS; + return otPlatTimeGet() / US_PER_MS; } void otPlatAlarmMicroStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt) @@ -89,7 +84,7 @@ void otPlatAlarmMicroStop(otInstance *aInstance) uint32_t inline otPlatAlarmMicroGetNow(void) { - return esp_timer_get_time(); + return otPlatTimeGet(); } esp_err_t esp_openthread_alarm_init(void) diff --git a/components/openthread/port/esp_openthread_radio.c b/components/openthread/port/esp_openthread_radio.c index 8020577214..892df41862 100644 --- a/components/openthread/port/esp_openthread_radio.c +++ b/components/openthread/port/esp_openthread_radio.c @@ -27,6 +27,7 @@ #include "openthread/link.h" #include "openthread/platform/diag.h" #include "openthread/platform/radio.h" +#include "openthread/platform/time.h" #include "utils/link_metrics.h" #include "utils/mac_frame.h" @@ -493,7 +494,7 @@ void otPlatRadioSetMacFrameCounter(otInstance *aInstance, uint32_t aMacFrameCoun uint64_t otPlatRadioGetNow(otInstance *aInstance) { OT_UNUSED_VARIABLE(aInstance); - return esp_timer_get_time(); + return otPlatTimeGet(); } #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE @@ -505,7 +506,7 @@ void otPlatRadioUpdateCslSampleTime(otInstance *aInstance, uint32_t aCslSampleTi static IRAM_ATTR uint16_t get_csl_phase() { - uint32_t cur_time = esp_timer_get_time(); + uint32_t cur_time = otPlatTimeGet(); uint32_t csl_period_us = s_csl_period * OT_US_PER_TEN_SYMBOLS; uint32_t diff = (csl_period_us - (cur_time % csl_period_us) + (s_csl_sample_time % csl_period_us)) % csl_period_us; @@ -578,7 +579,7 @@ static void IRAM_ATTR convert_to_ot_frame(uint8_t *data, esp_ieee802154_frame_in radio_frame->mInfo.mRxInfo.mRssi = frame_info->rssi; radio_frame->mInfo.mRxInfo.mLqi = frame_info->lqi; radio_frame->mInfo.mRxInfo.mAckedWithFramePending = frame_info->pending; - radio_frame->mInfo.mRxInfo.mTimestamp = esp_timer_get_time(); + radio_frame->mInfo.mRxInfo.mTimestamp = otPlatTimeGet(); #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE radio_frame->mInfo.mRxInfo.mTimestamp = frame_info->timestamp; @@ -677,6 +678,8 @@ void IRAM_ATTR esp_ieee802154_receive_done(uint8_t *data, esp_ieee802154_frame_i s_receive_frame[s_recv_queue.tail].mInfo.mRxInfo.mAckedWithSecEnhAck = s_with_security_enh_ack; s_receive_frame[s_recv_queue.tail].mInfo.mRxInfo.mAckFrameCounter = s_ack_frame_counter; s_receive_frame[s_recv_queue.tail].mInfo.mRxInfo.mAckKeyId = s_ack_key_id; + } else { + s_receive_frame[s_recv_queue.tail].mInfo.mRxInfo.mAckedWithSecEnhAck = false; } s_with_security_enh_ack = false; #endif // OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2 diff --git a/components/openthread/port/esp_openthread_radio_spinel.cpp b/components/openthread/port/esp_openthread_radio_spinel.cpp index 392aee4307..1ea69d5867 100644 --- a/components/openthread/port/esp_openthread_radio_spinel.cpp +++ b/components/openthread/port/esp_openthread_radio_spinel.cpp @@ -321,3 +321,32 @@ const char *otPlatRadioGetVersionString(otInstance *aInstance) } #endif // OPENTHREAD_CONFIG_DIAG_ENABLE + +uint64_t otPlatRadioGetNow(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + return s_radio.GetNow(); +} + +#if OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE +uint8_t otPlatRadioGetCslAccuracy(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + return s_radio.GetCslAccuracy(); + +} + +uint8_t otPlatRadioGetCslUncertainty(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + return s_radio.GetCslUncertainty(); +} +#endif + +#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE +otError otPlatRadioConfigureEnhAckProbing(otInstance *aInstance, otLinkMetrics aLinkMetrics, const otShortAddress aShortAddress, const otExtAddress *aExtAddress) +{ + OT_UNUSED_VARIABLE(aInstance); + return s_radio.ConfigureEnhAckProbing(aLinkMetrics, aShortAddress, *aExtAddress); +} +#endif diff --git a/components/openthread/private_include/openthread-core-esp32x-ftd-config.h b/components/openthread/private_include/openthread-core-esp32x-ftd-config.h index 5b1b97ef01..040453a84c 100644 --- a/components/openthread/private_include/openthread-core-esp32x-ftd-config.h +++ b/components/openthread/private_include/openthread-core-esp32x-ftd-config.h @@ -446,16 +446,6 @@ #define OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE 1 #endif -/** - * @def OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE - * - * Define as 1 to set the ahead time for CSL transmit timing. - * - */ -#ifndef OPENTHREAD_CONFIG_MAC_CSL_REQUEST_AHEAD_US -#define OPENTHREAD_CONFIG_MAC_CSL_REQUEST_AHEAD_US 20000 -#endif - /** * @def OPENTHREAD_CONFIG_MAC_CSL_DEBUG_ENABLE * @@ -468,6 +458,16 @@ #endif // CONFIG_OPENTHREAD_CSL_ENABLE +/** + * @def OPENTHREAD_CONFIG_MAC_CSL_REQUEST_AHEAD_US + * + * Define as 1 to set the ahead time for CSL transmit timing. + * + */ +#ifndef OPENTHREAD_CONFIG_MAC_CSL_REQUEST_AHEAD_US +#define OPENTHREAD_CONFIG_MAC_CSL_REQUEST_AHEAD_US 20000 +#endif + #if CONFIG_OPENTHREAD_LINK_METRICS /** diff --git a/components/openthread/private_include/openthread-core-esp32x-radio-config.h b/components/openthread/private_include/openthread-core-esp32x-radio-config.h index 2d5424c378..f58432903b 100644 --- a/components/openthread/private_include/openthread-core-esp32x-radio-config.h +++ b/components/openthread/private_include/openthread-core-esp32x-radio-config.h @@ -206,3 +206,13 @@ #endif #define OPENTHREAD_RADIO 1 + +/** + * @def OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE + * + * Define as 1 to support Thread 1.2 Link Metrics Subject feature. + * + */ +#ifndef OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE +#define OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE 1 +#endif