mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
fix(802.15.4): fixed security frame configuration
This commit is contained in:
@@ -122,7 +122,6 @@ static IRAM_ATTR void event_end_process(void)
|
|||||||
{
|
{
|
||||||
ieee802154_etm_channel_clear(IEEE802154_ETM_CHANNEL0);
|
ieee802154_etm_channel_clear(IEEE802154_ETM_CHANNEL0);
|
||||||
ieee802154_etm_channel_clear(IEEE802154_ETM_CHANNEL1);
|
ieee802154_etm_channel_clear(IEEE802154_ETM_CHANNEL1);
|
||||||
ieee802154_ll_set_transmit_security(false);
|
|
||||||
ieee802154_timer0_stop();
|
ieee802154_timer0_stop();
|
||||||
ieee802154_timer1_stop();
|
ieee802154_timer1_stop();
|
||||||
}
|
}
|
||||||
@@ -301,6 +300,7 @@ IEEE802154_NOINLINE static bool stop_rx(void)
|
|||||||
IEEE802154_NOINLINE static bool stop_tx_ack(void)
|
IEEE802154_NOINLINE static bool stop_tx_ack(void)
|
||||||
{
|
{
|
||||||
ieee802154_set_cmd(IEEE802154_CMD_STOP);
|
ieee802154_set_cmd(IEEE802154_CMD_STOP);
|
||||||
|
ieee802154_sec_clear();
|
||||||
|
|
||||||
ieee802154_receive_done((uint8_t *)s_rx_frame[s_rx_index], &s_rx_frame_info[s_rx_index]);
|
ieee802154_receive_done((uint8_t *)s_rx_frame[s_rx_index], &s_rx_frame_info[s_rx_index]);
|
||||||
|
|
||||||
@@ -314,6 +314,7 @@ IEEE802154_NOINLINE static bool stop_tx(void)
|
|||||||
ieee802154_ll_events events;
|
ieee802154_ll_events events;
|
||||||
|
|
||||||
ieee802154_set_cmd(IEEE802154_CMD_STOP);
|
ieee802154_set_cmd(IEEE802154_CMD_STOP);
|
||||||
|
ieee802154_sec_clear();
|
||||||
|
|
||||||
events = ieee802154_ll_get_events();
|
events = ieee802154_ll_get_events();
|
||||||
|
|
||||||
@@ -468,6 +469,7 @@ static IRAM_ATTR void next_operation(void)
|
|||||||
|
|
||||||
static IRAM_ATTR void isr_handle_tx_done(void)
|
static IRAM_ATTR void isr_handle_tx_done(void)
|
||||||
{
|
{
|
||||||
|
ieee802154_sec_clear();
|
||||||
event_end_process();
|
event_end_process();
|
||||||
#if !CONFIG_IEEE802154_TEST
|
#if !CONFIG_IEEE802154_TEST
|
||||||
if (!ieee802154_is_supported_frame_type(ieee802154_frame_get_type(s_tx_frame))) {
|
if (!ieee802154_is_supported_frame_type(ieee802154_frame_get_type(s_tx_frame))) {
|
||||||
@@ -528,7 +530,6 @@ static IRAM_ATTR void isr_handle_rx_done(void)
|
|||||||
// Send the Enh-Ack frame if generator succeeds.
|
// Send the Enh-Ack frame if generator succeeds.
|
||||||
ieee802154_ll_set_tx_addr(s_enh_ack_frame);
|
ieee802154_ll_set_tx_addr(s_enh_ack_frame);
|
||||||
s_tx_frame = s_enh_ack_frame;
|
s_tx_frame = s_enh_ack_frame;
|
||||||
ieee802154_sec_update();
|
|
||||||
ieee802154_ll_enhack_generate_done_notify();
|
ieee802154_ll_enhack_generate_done_notify();
|
||||||
ieee802154_set_state(IEEE802154_STATE_TX_ENH_ACK);
|
ieee802154_set_state(IEEE802154_STATE_TX_ENH_ACK);
|
||||||
#endif
|
#endif
|
||||||
@@ -548,6 +549,7 @@ static IRAM_ATTR void isr_handle_rx_done(void)
|
|||||||
|
|
||||||
static IRAM_ATTR void isr_handle_ack_tx_done(void)
|
static IRAM_ATTR void isr_handle_ack_tx_done(void)
|
||||||
{
|
{
|
||||||
|
ieee802154_sec_clear();
|
||||||
extcoex_rx_stage_start();
|
extcoex_rx_stage_start();
|
||||||
ieee802154_receive_done((uint8_t *)s_rx_frame[s_rx_index], &s_rx_frame_info[s_rx_index]);
|
ieee802154_receive_done((uint8_t *)s_rx_frame[s_rx_index], &s_rx_frame_info[s_rx_index]);
|
||||||
NEEDS_NEXT_OPT(true);
|
NEEDS_NEXT_OPT(true);
|
||||||
@@ -602,13 +604,17 @@ static IRAM_ATTR void isr_handle_rx_phase_rx_abort(ieee802154_ll_rx_abort_reason
|
|||||||
|
|
||||||
static IRAM_ATTR void isr_handle_tx_ack_phase_rx_abort(ieee802154_ll_rx_abort_reason_t rx_abort_reason)
|
static IRAM_ATTR void isr_handle_tx_ack_phase_rx_abort(ieee802154_ll_rx_abort_reason_t rx_abort_reason)
|
||||||
{
|
{
|
||||||
|
ieee802154_sec_clear();
|
||||||
event_end_process();
|
event_end_process();
|
||||||
#if CONFIG_IEEE802154_TEST
|
#if CONFIG_IEEE802154_TEST
|
||||||
uint32_t rx_status = ieee802154_ll_get_rx_status();
|
uint32_t rx_status = ieee802154_ll_get_rx_status();
|
||||||
#endif
|
#endif
|
||||||
switch (rx_abort_reason) {
|
switch (rx_abort_reason) {
|
||||||
case IEEE802154_RX_ABORT_BY_RX_STOP:
|
|
||||||
case IEEE802154_RX_ABORT_BY_TX_ACK_STOP:
|
case IEEE802154_RX_ABORT_BY_TX_ACK_STOP:
|
||||||
|
#if CONFIG_IEEE802154_TEST
|
||||||
|
ieee802154_receive_done((uint8_t *)s_rx_frame[s_rx_index], &s_rx_frame_info[s_rx_index]);
|
||||||
|
#endif
|
||||||
|
case IEEE802154_RX_ABORT_BY_RX_STOP:
|
||||||
case IEEE802154_RX_ABORT_BY_ED_STOP:
|
case IEEE802154_RX_ABORT_BY_ED_STOP:
|
||||||
case IEEE802154_RX_ABORT_BY_SFD_TIMEOUT:
|
case IEEE802154_RX_ABORT_BY_SFD_TIMEOUT:
|
||||||
case IEEE802154_RX_ABORT_BY_CRC_ERROR:
|
case IEEE802154_RX_ABORT_BY_CRC_ERROR:
|
||||||
@@ -652,11 +658,19 @@ static IRAM_ATTR void isr_handle_tx_ack_phase_rx_abort(ieee802154_ll_rx_abort_re
|
|||||||
|
|
||||||
static IRAM_ATTR void isr_handle_tx_abort(ieee802154_ll_tx_abort_reason_t tx_abort_reason)
|
static IRAM_ATTR void isr_handle_tx_abort(ieee802154_ll_tx_abort_reason_t tx_abort_reason)
|
||||||
{
|
{
|
||||||
|
ieee802154_sec_clear();
|
||||||
event_end_process();
|
event_end_process();
|
||||||
switch (tx_abort_reason) {
|
switch (tx_abort_reason) {
|
||||||
case IEEE802154_TX_ABORT_BY_RX_ACK_STOP:
|
case IEEE802154_TX_ABORT_BY_RX_ACK_STOP:
|
||||||
|
#if CONFIG_IEEE802154_TEST
|
||||||
|
ieee802154_inner_transmit_failed(s_tx_frame, ESP_IEEE802154_TX_ERR_NO_ACK);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
case IEEE802154_TX_ABORT_BY_TX_STOP:
|
case IEEE802154_TX_ABORT_BY_TX_STOP:
|
||||||
// do nothing
|
// do nothing
|
||||||
|
#if CONFIG_IEEE802154_TEST
|
||||||
|
ieee802154_inner_transmit_failed(s_tx_frame, ESP_IEEE802154_TX_ERR_ABORT);
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
case IEEE802154_TX_ABORT_BY_RX_ACK_SFD_TIMEOUT:
|
case IEEE802154_TX_ABORT_BY_RX_ACK_SFD_TIMEOUT:
|
||||||
case IEEE802154_TX_ABORT_BY_RX_ACK_CRC_ERROR:
|
case IEEE802154_TX_ABORT_BY_RX_ACK_CRC_ERROR:
|
||||||
@@ -734,7 +748,6 @@ IEEE802154_NOINLINE static void ieee802154_isr(void *arg)
|
|||||||
ieee802154_ll_events events = ieee802154_ll_get_events();
|
ieee802154_ll_events events = ieee802154_ll_get_events();
|
||||||
ieee802154_ll_rx_abort_reason_t rx_abort_reason = ieee802154_ll_get_rx_abort_reason();
|
ieee802154_ll_rx_abort_reason_t rx_abort_reason = ieee802154_ll_get_rx_abort_reason();
|
||||||
ieee802154_ll_tx_abort_reason_t tx_abort_reason = ieee802154_ll_get_tx_abort_reason();
|
ieee802154_ll_tx_abort_reason_t tx_abort_reason = ieee802154_ll_get_tx_abort_reason();
|
||||||
|
|
||||||
IEEE802154_PROBE(events);
|
IEEE802154_PROBE(events);
|
||||||
|
|
||||||
ieee802154_ll_clear_events(events);
|
ieee802154_ll_clear_events(events);
|
||||||
@@ -923,7 +936,6 @@ IEEE802154_STATIC void tx_init(const uint8_t *frame)
|
|||||||
s_tx_frame = (uint8_t *)frame;
|
s_tx_frame = (uint8_t *)frame;
|
||||||
stop_current_operation();
|
stop_current_operation();
|
||||||
ieee802154_pib_update();
|
ieee802154_pib_update();
|
||||||
ieee802154_sec_update();
|
|
||||||
|
|
||||||
ieee802154_ll_set_tx_addr(s_tx_frame);
|
ieee802154_ll_set_tx_addr(s_tx_frame);
|
||||||
|
|
||||||
@@ -967,6 +979,7 @@ esp_err_t ieee802154_transmit(const uint8_t *frame, bool cca)
|
|||||||
} else {
|
} else {
|
||||||
ieee802154_inner_transmit_failed(frame, ESP_IEEE802154_TX_ERR_ABORT);
|
ieee802154_inner_transmit_failed(frame, ESP_IEEE802154_TX_ERR_ABORT);
|
||||||
}
|
}
|
||||||
|
ieee802154_sec_clear();
|
||||||
IEEE802154_TX_DEFERRED_NUMS_UPDATE();
|
IEEE802154_TX_DEFERRED_NUMS_UPDATE();
|
||||||
ieee802154_exit_critical();
|
ieee802154_exit_critical();
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
#include "esp_ieee802154_frame.h"
|
#include "esp_ieee802154_frame.h"
|
||||||
#include "esp_ieee802154_util.h"
|
#include "esp_ieee802154_util.h"
|
||||||
|
|
||||||
IEEE802154_STATIC IEEE802154_INLINE bool is_security_enabled(const uint8_t *frame)
|
bool ieee802154_frame_is_security_enabled(const uint8_t *frame)
|
||||||
{
|
{
|
||||||
return frame[IEEE802154_FRAME_SECURITY_OFFSET] & IEEE802154_FRAME_SECURITY_BIT;
|
return frame[IEEE802154_FRAME_SECURITY_OFFSET] & IEEE802154_FRAME_SECURITY_BIT;
|
||||||
}
|
}
|
||||||
@@ -269,7 +269,7 @@ IEEE802154_STATIC uint8_t ieee802154_frame_get_ie_field_len(const uint8_t *frame
|
|||||||
IEEE802154_STATIC IRAM_ATTR uint8_t ieee802154_frame_payload_offset(const uint8_t *frame)
|
IEEE802154_STATIC IRAM_ATTR uint8_t ieee802154_frame_payload_offset(const uint8_t *frame)
|
||||||
{
|
{
|
||||||
uint8_t offset = ieee802154_frame_security_header_offset(frame);
|
uint8_t offset = ieee802154_frame_security_header_offset(frame);
|
||||||
if (is_security_enabled(frame)) {
|
if (ieee802154_frame_is_security_enabled(frame)) {
|
||||||
// skip security field.
|
// skip security field.
|
||||||
offset += ieee802154_frame_get_security_field_len(frame);
|
offset += ieee802154_frame_get_security_field_len(frame);
|
||||||
}
|
}
|
||||||
@@ -296,7 +296,7 @@ bool ieee802154_is_data_request(const uint8_t *frame)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
uint8_t offset = ieee802154_frame_security_header_offset(frame);
|
uint8_t offset = ieee802154_frame_security_header_offset(frame);
|
||||||
if (is_security_enabled(frame)) {
|
if (ieee802154_frame_is_security_enabled(frame)) {
|
||||||
// skip security field.
|
// skip security field.
|
||||||
offset += ieee802154_frame_get_security_field_len(frame);
|
offset += ieee802154_frame_get_security_field_len(frame);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,31 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "sdkconfig.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "esp_err.h"
|
#include "esp_err.h"
|
||||||
#include "hal/ieee802154_ll.h"
|
#include "hal/ieee802154_ll.h"
|
||||||
#include "esp_ieee802154_frame.h"
|
#include "esp_ieee802154_frame.h"
|
||||||
#include "esp_ieee802154_sec.h"
|
#include "esp_ieee802154_sec.h"
|
||||||
|
#include "esp_ieee802154_util.h"
|
||||||
|
|
||||||
#include "esp_ieee802154.h"
|
#include "esp_ieee802154.h"
|
||||||
static bool s_is_security = false;
|
|
||||||
|
|
||||||
void ieee802154_transmit_security_config(uint8_t *frame, uint8_t *key, uint8_t *addr)
|
void ieee802154_transmit_security_config(uint8_t *frame, uint8_t *key, uint8_t *addr)
|
||||||
{
|
{
|
||||||
|
#if !CONFIG_IEEE802154_TEST
|
||||||
|
IEEE802154_ASSERT(ieee802154_frame_is_security_enabled(frame));
|
||||||
|
#endif
|
||||||
ieee802154_ll_set_security_addr(addr);
|
ieee802154_ll_set_security_addr(addr);
|
||||||
ieee802154_ll_set_security_key(key);
|
ieee802154_ll_set_security_key(key);
|
||||||
ieee802154_ll_set_security_offset(ieee802154_frame_get_security_payload_offset(frame));
|
ieee802154_ll_set_security_offset(ieee802154_frame_get_security_payload_offset(frame));
|
||||||
s_is_security = true;
|
ieee802154_ll_set_transmit_security(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ieee802154_sec_update(void)
|
void ieee802154_sec_clear(void)
|
||||||
{
|
{
|
||||||
ieee802154_ll_set_transmit_security(s_is_security);
|
ieee802154_ll_set_transmit_security(false);
|
||||||
s_is_security = false;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,12 +20,12 @@ entries:
|
|||||||
esp_ieee802154_frame: ieee802154_frame_get_dest_panid (noflash)
|
esp_ieee802154_frame: ieee802154_frame_get_dest_panid (noflash)
|
||||||
esp_ieee802154_frame: ieee802154_frame_get_dst_addr (noflash)
|
esp_ieee802154_frame: ieee802154_frame_get_dst_addr (noflash)
|
||||||
esp_ieee802154_frame: ieee802154_frame_get_src_panid (noflash)
|
esp_ieee802154_frame: ieee802154_frame_get_src_panid (noflash)
|
||||||
|
esp_ieee802154_frame: ieee802154_frame_is_security_enabled(noflash)
|
||||||
esp_ieee802154_frame: ieee802154_is_data_request (noflash)
|
esp_ieee802154_frame: ieee802154_is_data_request (noflash)
|
||||||
esp_ieee802154_frame: is_dst_panid_present (noflash)
|
esp_ieee802154_frame: is_dst_panid_present (noflash)
|
||||||
esp_ieee802154_frame: is_src_panid_present (noflash)
|
esp_ieee802154_frame: is_src_panid_present (noflash)
|
||||||
esp_ieee802154_pib: ieee802154_pib_get_pending_mode (noflash)
|
esp_ieee802154_pib: ieee802154_pib_get_pending_mode (noflash)
|
||||||
esp_ieee802154_pib: ieee802154_pib_get_rx_when_idle (noflash)
|
esp_ieee802154_pib: ieee802154_pib_get_rx_when_idle (noflash)
|
||||||
esp_ieee802154_sec: ieee802154_sec_update (noflash)
|
|
||||||
esp_ieee802154_sec: ieee802154_transmit_security_config (noflash)
|
esp_ieee802154_sec: ieee802154_transmit_security_config (noflash)
|
||||||
esp_ieee802154_timer: ieee802154_timer0_set_threshold (noflash)
|
esp_ieee802154_timer: ieee802154_timer0_set_threshold (noflash)
|
||||||
esp_ieee802154_timer: ieee802154_timer0_start (noflash)
|
esp_ieee802154_timer: ieee802154_timer0_start (noflash)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -141,6 +141,16 @@ uint8_t ieee802154_frame_get_version(const uint8_t *frame);
|
|||||||
*/
|
*/
|
||||||
bool ieee802154_frame_is_ack_required(const uint8_t *frame);
|
bool ieee802154_frame_is_ack_required(const uint8_t *frame);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Is the frame security enabled.
|
||||||
|
*
|
||||||
|
* @param[in] frame The pointer to the frame.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* - True if the frame is security enabled, otherwise false.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
bool ieee802154_frame_is_security_enabled(const uint8_t *frame);
|
||||||
/**
|
/**
|
||||||
* @brief Get the destination address of the frame.
|
* @brief Get the destination address of the frame.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -25,11 +25,10 @@ extern "C" {
|
|||||||
void ieee802154_transmit_security_config(uint8_t *frame, uint8_t *key, uint8_t *addr);
|
void ieee802154_transmit_security_config(uint8_t *frame, uint8_t *key, uint8_t *addr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Update the encryption enabled configuration of the next transmission.
|
* @brief Clear the encryption enabled configuration.
|
||||||
*
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void ieee802154_sec_update(void);
|
void ieee802154_sec_clear(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user