diff --git a/nrf_802154/doc/CHANGELOG.rst b/nrf_802154/doc/CHANGELOG.rst index 585953ac6c..a17907915b 100644 --- a/nrf_802154/doc/CHANGELOG.rst +++ b/nrf_802154/doc/CHANGELOG.rst @@ -10,14 +10,16 @@ Changelog All notable changes to this project are documented in this file. See also :ref:`nrf_802154_limitations` for permanent limitations. -Main branch - nRF 802.15.4 Radio Driver -*************************************** +nRF Connect SDK v2.6.0 - nRF 802.15.4 Radio Driver +************************************************** Notable changes =============== * Added the :c:func:`nrf_802154_rx_on_when_idle_set` function which allows to choose between the receive and sleep states during radio idle periods. (KRKNWK-17962) * Added a safeguard in the :c:func:`nrf_802154_delayed_trx_receive` to disallow scheduling of two delayed reception windows with the same value of ``id`` parameter. (KRKNWK-18263) +* The encryption module for the nRF52 and nRF53 series' SoCs based on the ECB peripheral uses the :c:func:`nrf_802154_sl_ecb_block_encrypt` function. (KRKNWK-18576) + The :c:func:`nrf_802154_sl_ecb_block_encrypt` provided by the closed-source SL uses :ref:`mpsl` to share the ECB peripheral in the multiprotocol scenario. Added ===== diff --git a/nrf_802154/driver/src/nrf_802154_aes_ccm_acc_ecb.c b/nrf_802154/driver/src/nrf_802154_aes_ccm_acc_ecb.c index b7662bc19d..eb96628629 100644 --- a/nrf_802154/driver/src/nrf_802154_aes_ccm_acc_ecb.c +++ b/nrf_802154/driver/src/nrf_802154_aes_ccm_acc_ecb.c @@ -41,11 +41,10 @@ #include "nrf_802154_assert.h" #include -#include "hal/nrf_ecb.h" #include "nrf_802154_const.h" #include "nrf_802154_config.h" #include "nrf_802154_tx_work_buffer.h" -#include "platform/nrf_802154_irq.h" +#include "nrf_802154_sl_ecb.h" #ifndef MIN #define MIN(a, b) ((a) < (b) ? (a) : (b)) ///< Leaves the minimum of the two arguments @@ -63,6 +62,14 @@ #define NRF_802154_AES_CCM_AUTH_DATA_LENGTH_OCTET 0 // AnnnexB4.1.1b) - Position of octet for length of auth data in AddAuthData #define NRF_802154_AES_CCM_AUTH_DATA_OCTET 2 // AnnnexB4.1.1b) - Position of octet for data of auth data in AddAuthData +#if NRF_802154_AES_CCM_BLOCK_SIZE != NRF_802154_SL_ECB_CLEARTEXT_LENGTH +#error NRF_802154_AES_CCM_BLOCK_SIZE != NRF_802154_SL_ECB_CLEARTEXT_LENGTH +#endif + +#if NRF_802154_AES_CCM_BLOCK_SIZE != NRF_802154_SL_ECB_CIPHERTEXT_LENGTH +#error NRF_802154_AES_CCM_BLOCK_SIZE != NRF_802154_SL_ECB_CLEARTEXT_LENGTH +#endif + /** * @brief Steps of AES-CCM* algorithm. */ @@ -90,7 +97,6 @@ static uint8_t m_m[NRF_802154_AES_CCM_BLOCK_SIZE]; static uint8_t m_a[NRF_802154_AES_CCM_BLOCK_SIZE]; ///< A[i] octet for Encryption Transformation - Annex B4.1.3 b) static ccm_state_t m_state; ///< State of AES-CCM* transformation static uint8_t m_auth_tag[MIC_128_SIZE]; ///< Authorization Tag -static bool m_initialized; ///< Flag that indicates whether the module has been initialized. static uint8_t * mp_ciphertext; ///< Pointer to ciphertext destination buffer. static uint8_t * mp_work_buffer; ///< Pointer to work buffer that stores the frame being transformed. @@ -100,46 +106,22 @@ static const uint8_t m_mic_size[] = { 0, MIC_32_SIZE, MIC_64_SIZE, MIC_128_SIZE /******************************************************************************/ /******************************************************************************/ -static uint8_t m_ecb_data[48]; ///< ECB data structure for RNG peripheral to access. -static uint8_t * mp_ecb_key; ///< Key: Starts at ecb_data -static uint8_t * mp_ecb_cleartext; ///< Cleartext: Starts at ecb_data + 16 bytes. -static uint8_t * mp_ecb_ciphertext; ///< Ciphertext: Starts at ecb_data + 32 bytes. +static nrf_802154_sl_ecb_data_t m_ecb_hal_data; +static bool m_ecb_hal_req_run; -static void nrf_ecb_init(void) +static inline uint8_t * ecb_hal_cleartext_ptr_get(void) { - mp_ecb_key = m_ecb_data; - mp_ecb_cleartext = m_ecb_data + 16; - mp_ecb_ciphertext = m_ecb_data + 32; - - nrf_ecb_data_pointer_set(NRF_ECB, m_ecb_data); + return (uint8_t *)m_ecb_hal_data.cleartext; } -static void nrf_ecb_set_key(const uint8_t * p_key) +static inline uint8_t * ecb_hal_ciphertext_ptr_get(void) { - memcpy(mp_ecb_key, p_key, 16); + return (uint8_t *)m_ecb_hal_data.ciphertext; } -static void ecb_irq_handler(void); - -/** - * @brief Initializes the ECB peripheral. - */ -static void ecb_init(void) +static void ecb_hal_key_set(const uint8_t * p_key) { - if (!m_initialized) - { - nrf_802154_irq_init(nrfx_get_irq_number(NRF_ECB), NRF_802154_ECB_PRIORITY, ecb_irq_handler); - m_initialized = true; - } - - // TODO: ensure ECB initialization is handled by zephyr - // TODO: what about ECB initialization in baremetal scenario? - nrf_ecb_init(); - - nrf_802154_irq_clear_pending(nrfx_get_irq_number(NRF_ECB)); - nrf_802154_irq_enable(nrfx_get_irq_number(NRF_ECB)); - nrf_ecb_int_enable(NRF_ECB, NRF_ECB_INT_ENDECB_MASK); - nrf_ecb_int_enable(NRF_ECB, NRF_ECB_INT_ERRORECB_MASK); + memcpy(m_ecb_hal_data.key, p_key, NRF_802154_SL_ECB_KEY_LENGTH); } /******************************************************************************/ @@ -316,9 +298,11 @@ static bool plain_text_data_get(const nrf_802154_aes_ccm_data_t * p_frame, static inline void process_ecb_auth_iteration(void) { m_state.iteration++; - two_blocks_xor(mp_ecb_ciphertext, m_b, NRF_802154_AES_CCM_BLOCK_SIZE); - memcpy(mp_ecb_cleartext, mp_ecb_ciphertext, NRF_802154_AES_CCM_BLOCK_SIZE); - nrf_ecb_task_trigger(NRF_ECB, NRF_ECB_TASK_STARTECB); + two_blocks_xor(ecb_hal_ciphertext_ptr_get(), m_b, NRF_802154_AES_CCM_BLOCK_SIZE); + memcpy(ecb_hal_cleartext_ptr_get(), + ecb_hal_ciphertext_ptr_get(), + NRF_802154_AES_CCM_BLOCK_SIZE); + m_ecb_hal_req_run = true; } /** @@ -327,8 +311,8 @@ static inline void process_ecb_auth_iteration(void) static inline void process_ecb_encrypt_iteration(void) { ai_format(&m_aes_ccm_data, m_state.iteration, m_a); - memcpy(mp_ecb_cleartext, m_a, NRF_802154_AES_CCM_BLOCK_SIZE); - nrf_ecb_task_trigger(NRF_ECB, NRF_ECB_TASK_STARTECB); + memcpy(ecb_hal_cleartext_ptr_get(), m_a, NRF_802154_AES_CCM_BLOCK_SIZE); + m_ecb_hal_req_run = true; } /** @@ -336,7 +320,7 @@ static inline void process_ecb_encrypt_iteration(void) */ static void perform_plain_text_encryption(void) { - memcpy(m_auth_tag, mp_ecb_ciphertext, m_mic_size[m_aes_ccm_data.mic_level]); + memcpy(m_auth_tag, ecb_hal_ciphertext_ptr_get(), m_mic_size[m_aes_ccm_data.mic_level]); m_state.iteration = 0; m_state.transformation = PLAIN_TEXT_ENCRYPT; @@ -377,99 +361,72 @@ static void transformation_finished(void) m_aes_ccm_data.raw_frame = NULL; } -/** - * @brief Handler to ECB Interrupt Routine - * Performs AES-CCM* calculation in pipeline - */ -static void ecb_irq_handler(void) +static void ecb_hal_block_encrypted_handler(void) { uint8_t len = 0; uint8_t offset; - if (nrf_ecb_int_enable_check(NRF_ECB, NRF_ECB_INT_ENDECB_MASK) && - nrf_ecb_event_check(NRF_ECB, NRF_ECB_EVENT_ENDECB)) + switch (m_state.transformation) { - nrf_ecb_event_clear(NRF_ECB, NRF_ECB_EVENT_ENDECB); - - switch (m_state.transformation) - { - case ADD_AUTH_DATA_AUTH: - if (add_auth_data_get(&m_aes_ccm_data, m_state.iteration, m_b)) - { - process_ecb_auth_iteration(); - } - else - { - m_state.iteration = 0; - m_state.transformation = PLAIN_TEXT_AUTH; - perform_plain_text_authorization(); - } - break; - - case PLAIN_TEXT_AUTH: + case ADD_AUTH_DATA_AUTH: + if (add_auth_data_get(&m_aes_ccm_data, m_state.iteration, m_b)) + { + process_ecb_auth_iteration(); + } + else + { + m_state.iteration = 0; + m_state.transformation = PLAIN_TEXT_AUTH; perform_plain_text_authorization(); - break; - - case PLAIN_TEXT_ENCRYPT: - two_blocks_xor(m_m, mp_ecb_ciphertext, NRF_802154_AES_CCM_BLOCK_SIZE); - - offset = (m_state.iteration - 1) * NRF_802154_AES_CCM_BLOCK_SIZE; - len = MIN(m_aes_ccm_data.plain_text_data_len - offset, - NRF_802154_AES_CCM_BLOCK_SIZE); - memcpy(mp_ciphertext + offset, m_m, len); - if (plain_text_data_get(&m_aes_ccm_data, m_state.iteration, m_m)) + } + break; + + case PLAIN_TEXT_AUTH: + perform_plain_text_authorization(); + break; + + case PLAIN_TEXT_ENCRYPT: + two_blocks_xor(m_m, ecb_hal_ciphertext_ptr_get(), NRF_802154_AES_CCM_BLOCK_SIZE); + + offset = (m_state.iteration - 1) * NRF_802154_AES_CCM_BLOCK_SIZE; + len = MIN(m_aes_ccm_data.plain_text_data_len - offset, + NRF_802154_AES_CCM_BLOCK_SIZE); + memcpy(mp_ciphertext + offset, m_m, len); + if (plain_text_data_get(&m_aes_ccm_data, m_state.iteration, m_m)) + { + m_state.iteration++; + process_ecb_encrypt_iteration(); + } + else + { + if (m_mic_size[m_aes_ccm_data.mic_level] != 0) { - m_state.iteration++; + m_state.iteration = 0; + m_state.transformation = CALCULATE_ENCRYPTED_TAG; process_ecb_encrypt_iteration(); } else { - if (m_mic_size[m_aes_ccm_data.mic_level] != 0) - { - m_state.iteration = 0; - m_state.transformation = CALCULATE_ENCRYPTED_TAG; - process_ecb_encrypt_iteration(); - } - else - { - transformation_finished(); - } + transformation_finished(); } - break; - - case CALCULATE_ENCRYPTED_TAG: - two_blocks_xor(m_auth_tag, - mp_ecb_ciphertext, - m_mic_size[m_aes_ccm_data.mic_level]); - memcpy(mp_work_buffer + - (mp_work_buffer[PHR_OFFSET] - FCS_SIZE - - m_mic_size[m_aes_ccm_data.mic_level] + - PHR_SIZE), - m_auth_tag, - m_mic_size[m_aes_ccm_data.mic_level]); - transformation_finished(); - break; - - default: - break; - } - } - - if (nrf_ecb_int_enable_check(NRF_ECB, NRF_ECB_INT_ERRORECB_MASK) && - nrf_ecb_event_check(NRF_ECB, NRF_ECB_EVENT_ERRORECB)) - { - /* - * It is possible that the ERRORECB event is caused by the - * AAR and CCM peripherals, which share the same hardware resources. - * At this point it is assumed, that ECB, AAR and CCM peripherals - * are not used by anything, except the 802.15.4 driver and - * other MPSL clients and thus it is impossible that ECB was aborted - * for any other reason, than the TX failed event caused by a terminated - * 802.15.4 transmit operation or end of timeslot. - * - * Therefore no action is taken in this handler. - */ - nrf_ecb_event_clear(NRF_ECB, NRF_ECB_EVENT_ERRORECB); + } + break; + + case CALCULATE_ENCRYPTED_TAG: + two_blocks_xor(m_auth_tag, + ecb_hal_ciphertext_ptr_get(), + m_mic_size[m_aes_ccm_data.mic_level]); + memcpy(mp_work_buffer + + (mp_work_buffer[PHR_OFFSET] - FCS_SIZE - + m_mic_size[m_aes_ccm_data.mic_level] + + PHR_SIZE), + m_auth_tag, + m_mic_size[m_aes_ccm_data.mic_level]); + transformation_finished(); + break; + + default: + break; } } @@ -478,11 +435,18 @@ static void ecb_irq_handler(void) */ static void start_ecb_auth_transformation(void) { - memcpy((uint8_t *)nrf_ecb_data_pointer_get(NRF_ECB) + 16, m_x, 16); + ecb_hal_key_set(m_aes_ccm_data.key); + memcpy(ecb_hal_cleartext_ptr_get(), m_x, NRF_802154_SL_ECB_CLEARTEXT_LENGTH); m_state.iteration = 0; m_state.transformation = ADD_AUTH_DATA_AUTH; - nrf_ecb_event_clear(NRF_ECB, NRF_ECB_EVENT_ENDECB); - nrf_ecb_task_trigger(NRF_ECB, NRF_ECB_TASK_STARTECB); + m_ecb_hal_req_run = true; + + while (m_ecb_hal_req_run) + { + m_ecb_hal_req_run = false; + nrf_802154_sl_ecb_block_encrypt(&m_ecb_hal_data); + ecb_hal_block_encrypted_handler(); + } } void nrf_802154_aes_ccm_transform_reset(void) @@ -554,9 +518,6 @@ void nrf_802154_aes_ccm_transform_start(uint8_t * p_frame) b0_format(&m_aes_ccm_data, auth_flags, p_b); two_blocks_xor(p_x, p_b, NRF_802154_AES_CCM_BLOCK_SIZE); - ecb_init(); - memset(mp_ecb_key, 0, 48); - nrf_ecb_set_key(m_aes_ccm_data.key); start_ecb_auth_transformation(); } @@ -568,16 +529,6 @@ void nrf_802154_aes_ccm_transform_abort(uint8_t * p_frame) return; } - /* - * Temporarily disable ENDECB interrupt, trigger STOPECB task - * to stop encryption in case it is still running and clear - * the ENDECB event in case the encryption has completed. - */ - nrf_ecb_int_disable(NRF_ECB, NRF_ECB_INT_ENDECB_MASK); - nrf_ecb_task_trigger(NRF_ECB, NRF_ECB_TASK_STOPECB); - nrf_ecb_event_clear(NRF_ECB, NRF_ECB_EVENT_ENDECB); - nrf_ecb_int_enable(NRF_ECB, NRF_ECB_INT_ENDECB_MASK); - m_aes_ccm_data.raw_frame = NULL; } diff --git a/nrf_802154/driver/src/nrf_802154_core.c b/nrf_802154/driver/src/nrf_802154_core.c index 6c0d38dc54..bc0f01d1c1 100644 --- a/nrf_802154/driver/src/nrf_802154_core.c +++ b/nrf_802154/driver/src/nrf_802154_core.c @@ -2093,12 +2093,43 @@ void nrf_802154_trx_receive_frame_received(void) nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW); } +static bool fcf_is_security_enabled(const uint8_t * p_frame) +{ + return p_frame[SECURITY_ENABLED_OFFSET] & SECURITY_ENABLED_BIT; +} + +static inline bool tx_started_core_hooks_will_fit_within_timeslot(const uint8_t * p_frame) +{ + if (!fcf_is_security_enabled(p_frame)) + { + return true; + } + + uint32_t estimated_max_hook_time = nrf_802154_frame_duration_get(p_frame[0], false, true) / 2U; + + return nrf_802154_rsch_timeslot_us_left_get() >= estimated_max_hook_time; +} + void nrf_802154_trx_transmit_frame_started(void) { nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW); NRF_802154_ASSERT((m_state == RADIO_STATE_TX) || (m_state == RADIO_STATE_CCA_TX)); - transmit_started_notify(); + if (tx_started_core_hooks_will_fit_within_timeslot(mp_tx_data)) + { + transmit_started_notify(); + } + else + { + nrf_802154_trx_abort(); + switch_to_idle(); + + nrf_802154_transmit_done_metadata_t metadata = {}; + + nrf_802154_tx_work_buffer_original_frame_update(mp_tx_data, &metadata.frame_props); + + transmit_failed_notify(mp_tx_data, NRF_802154_TX_ERROR_TIMESLOT_ENDED, &metadata); + } nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW); } @@ -2108,7 +2139,21 @@ void nrf_802154_trx_transmit_ack_started(void) nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW); NRF_802154_ASSERT(m_state == RADIO_STATE_TX_ACK); - transmit_ack_started_notify(); + if (tx_started_core_hooks_will_fit_within_timeslot(mp_ack)) + { + transmit_ack_started_notify(); + } + else + { + uint8_t * p_received_data = mp_current_rx_buffer->data; + + nrf_802154_trx_abort(); + mp_current_rx_buffer->free = false; + + nrf_802154_core_hooks_tx_ack_failed(mp_ack, NRF_802154_RX_ERROR_TIMESLOT_ENDED); + switch_to_idle(); + received_frame_notify_and_nesting_allow(p_received_data); + } nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW); } diff --git a/nrf_802154/sl/include/nrf_802154_sl_ecb.h b/nrf_802154/sl/include/nrf_802154_sl_ecb.h new file mode 100644 index 0000000000..bcc4d062b4 --- /dev/null +++ b/nrf_802154/sl/include/nrf_802154_sl_ecb.h @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2024, Nordic Semiconductor ASA + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + * 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 Nordic Semiconductor ASA 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 NRF_802154_SL_ECB_H__ +#define NRF_802154_SL_ECB_H__ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup nrf_802154_sl_ecb ECB encryption + * @{ + * @ingroup nrf_802154_sl_ecb + * @brief The ECB encryption API for nRF 802.15.4 Radio Driver + */ + +#define NRF_802154_SL_ECB_KEY_LENGTH (16) /**< ECB key length in bytes. */ +#define NRF_802154_SL_ECB_CLEARTEXT_LENGTH (16) /**< ECB cleartext length in bytes. */ +#define NRF_802154_SL_ECB_CIPHERTEXT_LENGTH (16) /**< ECB ciphertext length in bytes. */ + +/**@brief AES ECB parameter typedefs */ +typedef uint32_t nrf_802154_sl_ecb_key_t[NRF_802154_SL_ECB_KEY_LENGTH / sizeof(uint32_t)]; /**< Encryption key type. */ +typedef uint8_t nrf_802154_sl_ecb_cleartext_t[NRF_802154_SL_ECB_CLEARTEXT_LENGTH]; /**< Cleartext data type. */ +typedef uint8_t nrf_802154_sl_ecb_ciphertext_t[NRF_802154_SL_ECB_CIPHERTEXT_LENGTH]; /**< Ciphertext data type. */ + +/**@brief AES ECB data structure */ +typedef struct +{ + nrf_802154_sl_ecb_key_t key; /**< Encryption key. */ + nrf_802154_sl_ecb_cleartext_t cleartext; /**< Cleartext data. */ + nrf_802154_sl_ecb_ciphertext_t ciphertext; /**< Ciphertext data. */ +} nrf_802154_sl_ecb_data_t; + +/**@brief Encrypts a block according to the specified parameters. + * + * @param[in, out] p_ecb_data Pointer to the ECB parameters' struct. + */ +void nrf_802154_sl_ecb_block_encrypt(nrf_802154_sl_ecb_data_t * p_ecb_data); + +/** + *@} + **/ + +#ifdef __cplusplus +} +#endif + +#endif // NRF_802154_SL_ECB_H__ diff --git a/nrf_802154/sl/sl/lib/nRF52833/hard-float/libnrf-802154-sl.a b/nrf_802154/sl/sl/lib/nRF52833/hard-float/libnrf-802154-sl.a index 1878cc122f..7ccc452937 100644 Binary files a/nrf_802154/sl/sl/lib/nRF52833/hard-float/libnrf-802154-sl.a and b/nrf_802154/sl/sl/lib/nRF52833/hard-float/libnrf-802154-sl.a differ diff --git a/nrf_802154/sl/sl/lib/nRF52833/soft-float/libnrf-802154-sl.a b/nrf_802154/sl/sl/lib/nRF52833/soft-float/libnrf-802154-sl.a index e78982d211..b8c751e64e 100644 Binary files a/nrf_802154/sl/sl/lib/nRF52833/soft-float/libnrf-802154-sl.a and b/nrf_802154/sl/sl/lib/nRF52833/soft-float/libnrf-802154-sl.a differ diff --git a/nrf_802154/sl/sl/lib/nRF52833/softfp-float/libnrf-802154-sl.a b/nrf_802154/sl/sl/lib/nRF52833/softfp-float/libnrf-802154-sl.a index 678afca5bb..dba62f9fc9 100644 Binary files a/nrf_802154/sl/sl/lib/nRF52833/softfp-float/libnrf-802154-sl.a and b/nrf_802154/sl/sl/lib/nRF52833/softfp-float/libnrf-802154-sl.a differ diff --git a/nrf_802154/sl/sl/lib/nRF52840/hard-float/libnrf-802154-sl.a b/nrf_802154/sl/sl/lib/nRF52840/hard-float/libnrf-802154-sl.a index 1878cc122f..7ccc452937 100644 Binary files a/nrf_802154/sl/sl/lib/nRF52840/hard-float/libnrf-802154-sl.a and b/nrf_802154/sl/sl/lib/nRF52840/hard-float/libnrf-802154-sl.a differ diff --git a/nrf_802154/sl/sl/lib/nRF52840/soft-float/libnrf-802154-sl.a b/nrf_802154/sl/sl/lib/nRF52840/soft-float/libnrf-802154-sl.a index e78982d211..b8c751e64e 100644 Binary files a/nrf_802154/sl/sl/lib/nRF52840/soft-float/libnrf-802154-sl.a and b/nrf_802154/sl/sl/lib/nRF52840/soft-float/libnrf-802154-sl.a differ diff --git a/nrf_802154/sl/sl/lib/nRF52840/softfp-float/libnrf-802154-sl.a b/nrf_802154/sl/sl/lib/nRF52840/softfp-float/libnrf-802154-sl.a index 678afca5bb..dba62f9fc9 100644 Binary files a/nrf_802154/sl/sl/lib/nRF52840/softfp-float/libnrf-802154-sl.a and b/nrf_802154/sl/sl/lib/nRF52840/softfp-float/libnrf-802154-sl.a differ diff --git a/nrf_802154/sl/sl/lib/nRF5340_CPUNET/soft-float/libnrf-802154-sl.a b/nrf_802154/sl/sl/lib/nRF5340_CPUNET/soft-float/libnrf-802154-sl.a index 9efcb61c56..f3e91b331e 100644 Binary files a/nrf_802154/sl/sl/lib/nRF5340_CPUNET/soft-float/libnrf-802154-sl.a and b/nrf_802154/sl/sl/lib/nRF5340_CPUNET/soft-float/libnrf-802154-sl.a differ diff --git a/nrf_802154/sl/sl/lib/nRF54H20_CPURAD/hard-float/libnrf-802154-sl.a b/nrf_802154/sl/sl/lib/nRF54H20_CPURAD/hard-float/libnrf-802154-sl.a index 1e95f0c432..f3636a2947 100644 Binary files a/nrf_802154/sl/sl/lib/nRF54H20_CPURAD/hard-float/libnrf-802154-sl.a and b/nrf_802154/sl/sl/lib/nRF54H20_CPURAD/hard-float/libnrf-802154-sl.a differ diff --git a/nrf_802154/sl/sl/lib/nRF54H20_CPURAD/soft-float/libnrf-802154-sl.a b/nrf_802154/sl/sl/lib/nRF54H20_CPURAD/soft-float/libnrf-802154-sl.a index 1e95f0c432..f3636a2947 100644 Binary files a/nrf_802154/sl/sl/lib/nRF54H20_CPURAD/soft-float/libnrf-802154-sl.a and b/nrf_802154/sl/sl/lib/nRF54H20_CPURAD/soft-float/libnrf-802154-sl.a differ diff --git a/nrf_802154/sl/sl/lib/nRF54H20_CPURAD/softfp-float/libnrf-802154-sl.a b/nrf_802154/sl/sl/lib/nRF54H20_CPURAD/softfp-float/libnrf-802154-sl.a index 1e95f0c432..f3636a2947 100644 Binary files a/nrf_802154/sl/sl/lib/nRF54H20_CPURAD/softfp-float/libnrf-802154-sl.a and b/nrf_802154/sl/sl/lib/nRF54H20_CPURAD/softfp-float/libnrf-802154-sl.a differ diff --git a/nrf_802154/sl/sl/lib/nRF54H20_CPURAD_SOC1/hard-float/libnrf-802154-sl.a b/nrf_802154/sl/sl/lib/nRF54H20_CPURAD_SOC1/hard-float/libnrf-802154-sl.a index 1e95f0c432..f3636a2947 100644 Binary files a/nrf_802154/sl/sl/lib/nRF54H20_CPURAD_SOC1/hard-float/libnrf-802154-sl.a and b/nrf_802154/sl/sl/lib/nRF54H20_CPURAD_SOC1/hard-float/libnrf-802154-sl.a differ diff --git a/nrf_802154/sl/sl/lib/nRF54H20_CPURAD_SOC1/soft-float/libnrf-802154-sl.a b/nrf_802154/sl/sl/lib/nRF54H20_CPURAD_SOC1/soft-float/libnrf-802154-sl.a index 1e95f0c432..f3636a2947 100644 Binary files a/nrf_802154/sl/sl/lib/nRF54H20_CPURAD_SOC1/soft-float/libnrf-802154-sl.a and b/nrf_802154/sl/sl/lib/nRF54H20_CPURAD_SOC1/soft-float/libnrf-802154-sl.a differ diff --git a/nrf_802154/sl/sl/lib/nRF54H20_CPURAD_SOC1/softfp-float/libnrf-802154-sl.a b/nrf_802154/sl/sl/lib/nRF54H20_CPURAD_SOC1/softfp-float/libnrf-802154-sl.a index 1e95f0c432..f3636a2947 100644 Binary files a/nrf_802154/sl/sl/lib/nRF54H20_CPURAD_SOC1/softfp-float/libnrf-802154-sl.a and b/nrf_802154/sl/sl/lib/nRF54H20_CPURAD_SOC1/softfp-float/libnrf-802154-sl.a differ diff --git a/nrf_802154/sl/sl/lib/nRF54L15_CPUAPP_SOC1/hard-float/libnrf-802154-sl.a b/nrf_802154/sl/sl/lib/nRF54L15_CPUAPP_SOC1/hard-float/libnrf-802154-sl.a index 1e95f0c432..f3636a2947 100644 Binary files a/nrf_802154/sl/sl/lib/nRF54L15_CPUAPP_SOC1/hard-float/libnrf-802154-sl.a and b/nrf_802154/sl/sl/lib/nRF54L15_CPUAPP_SOC1/hard-float/libnrf-802154-sl.a differ diff --git a/nrf_802154/sl/sl/lib/nRF54L15_CPUAPP_SOC1/soft-float/libnrf-802154-sl.a b/nrf_802154/sl/sl/lib/nRF54L15_CPUAPP_SOC1/soft-float/libnrf-802154-sl.a index 1e95f0c432..f3636a2947 100644 Binary files a/nrf_802154/sl/sl/lib/nRF54L15_CPUAPP_SOC1/soft-float/libnrf-802154-sl.a and b/nrf_802154/sl/sl/lib/nRF54L15_CPUAPP_SOC1/soft-float/libnrf-802154-sl.a differ diff --git a/nrf_802154/sl/sl/lib/nRF54L15_CPUAPP_SOC1/softfp-float/libnrf-802154-sl.a b/nrf_802154/sl/sl/lib/nRF54L15_CPUAPP_SOC1/softfp-float/libnrf-802154-sl.a index 1e95f0c432..f3636a2947 100644 Binary files a/nrf_802154/sl/sl/lib/nRF54L15_CPUAPP_SOC1/softfp-float/libnrf-802154-sl.a and b/nrf_802154/sl/sl/lib/nRF54L15_CPUAPP_SOC1/softfp-float/libnrf-802154-sl.a differ diff --git a/nrf_802154/sl/sl_opensource/CMakeLists.txt b/nrf_802154/sl/sl_opensource/CMakeLists.txt index 3a4a8c9c82..505435548d 100644 --- a/nrf_802154/sl/sl_opensource/CMakeLists.txt +++ b/nrf_802154/sl/sl_opensource/CMakeLists.txt @@ -48,6 +48,7 @@ target_sources(nrf-802154-sl src/nrf_802154_sl_capabilities.c src/nrf_802154_sl_coex.c src/nrf_802154_sl_crit_sect_if.c + src/nrf_802154_sl_ecb.c src/nrf_802154_sl_fem.c src/nrf_802154_sl_log.c src/nrf_802154_sl_rsch.c diff --git a/nrf_802154/sl/sl_opensource/src/nrf_802154_sl_ecb.c b/nrf_802154/sl/sl_opensource/src/nrf_802154_sl_ecb.c new file mode 100644 index 0000000000..8e67664fba --- /dev/null +++ b/nrf_802154/sl/sl_opensource/src/nrf_802154_sl_ecb.c @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2024, Nordic Semiconductor ASA + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + * 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 Nordic Semiconductor ASA 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 "nrf_802154_sl_ecb.h" + +#include + +#if defined(CONFIG_SOC_COMPATIBLE_NRF52X) || defined(CONFIG_SOC_COMPATIBLE_NRF53X) + +#include "hal/nrf_ecb.h" + +#define ECB_INST NRF_ECB + +static inline void sleep_wfe(void) +{ +#if defined(CONFIG_SOC_SERIES_BSIM_NRFXX) + void z_impl_k_busy_wait(); + z_impl_k_busy_wait(10); +#elif defined(CONFIG_SOC_COMPATIBLE_NRF52X) + __WFE(); +#else + /* Do-nothing. This includes nRF5340 series due multiple sleep-related anomalies (160, 165, 168) */ +#endif +} + +static void wait_for_ecb_end(void) +{ + while (!nrf_ecb_event_check(ECB_INST, NRF_ECB_EVENT_ENDECB) && + !nrf_ecb_event_check(ECB_INST, NRF_ECB_EVENT_ERRORECB)) + { +#if !defined(CONFIG_SOC_SERIES_BSIM_NRFXX) + if ((SCB->SCR & SCB_SCR_SEVONPEND_Msk) == SCB_SCR_SEVONPEND_Msk) +#endif + { + NVIC_ClearPendingIRQ(ECB_IRQn); + + uint32_t irq_was_masked = __get_PRIMASK(); + + __disable_irq(); + + nrf_ecb_int_enable(ECB_INST, NRF_ECB_INT_ENDECB_MASK | NRF_ECB_INT_ERRORECB_MASK); + if (!nrf_ecb_event_check(ECB_INST, NRF_ECB_EVENT_ENDECB) && + !nrf_ecb_event_check(ECB_INST, NRF_ECB_EVENT_ERRORECB)) + { + sleep_wfe(); + } + + if (!irq_was_masked) + { + __enable_irq(); + } + } + } +} + +void nrf_802154_sl_ecb_block_encrypt(nrf_802154_sl_ecb_data_t * p_ecb_data) +{ + nrf_ecb_int_disable(ECB_INST, NRF_ECB_INT_ENDECB_MASK | NRF_ECB_INT_ERRORECB_MASK); + + do + { + nrf_ecb_task_trigger(ECB_INST, NRF_ECB_TASK_STOPECB); + nrf_ecb_event_clear(ECB_INST, NRF_ECB_EVENT_ENDECB); + nrf_ecb_event_clear(ECB_INST, NRF_ECB_EVENT_ERRORECB); + nrf_ecb_data_pointer_set(ECB_INST, p_ecb_data); + + nrf_ecb_task_trigger(ECB_INST, NRF_ECB_TASK_STARTECB); + wait_for_ecb_end(); + } + while (nrf_ecb_event_check(ECB_INST, NRF_ECB_EVENT_ERRORECB)); + + nrf_ecb_int_disable(ECB_INST, NRF_ECB_INT_ENDECB_MASK | NRF_ECB_INT_ERRORECB_MASK); + nrf_ecb_event_clear(ECB_INST, NRF_ECB_EVENT_ERRORECB); + nrf_ecb_event_clear(ECB_INST, NRF_ECB_EVENT_ENDECB); + NVIC_ClearPendingIRQ(ECB_IRQn); +} + +#endif /* defined(CONFIG_SOC_COMPATIBLE_NRF52X) || defined(CONFIG_SOC_COMPATIBLE_NRF53X) */