fix(802.15.4) added some error checks to make the code more robust

This commit is contained in:
zwx
2026-04-22 02:35:02 +00:00
committed by Zhang Wen Xu
parent 0bed60db48
commit 7adeb08b02
15 changed files with 299 additions and 159 deletions
+23 -10
View File
@@ -257,10 +257,11 @@ esp_err_t esp_ieee802154_set_short_address(uint16_t short_address);
/**
* @brief Get the device extended address.
*
* @param[out] ext_addr The pointer to the device extended address.
* @param[out] ext_addr The pointer to the device extended address. Must not be NULL.
*
* @return
* - ESP_OK on success.
* - ESP_ERR_INVALID_ARG if ext_addr is NULL.
* - ESP_FAIL on failure.
*/
esp_err_t esp_ieee802154_get_extended_address(uint8_t *ext_addr);
@@ -268,10 +269,11 @@ esp_err_t esp_ieee802154_get_extended_address(uint8_t *ext_addr);
/**
* @brief Set the device extended address.
*
* @param[in] ext_addr The pointer to the device extended address.
* @param[in] ext_addr The pointer to the device extended address. Must not be NULL.
*
* @return
* - ESP_OK on success.
* - ESP_ERR_INVALID_ARG if ext_addr is NULL.
* - ESP_FAIL on failure.
*/
esp_err_t esp_ieee802154_set_extended_address(const uint8_t *ext_addr);
@@ -324,10 +326,11 @@ esp_err_t esp_ieee802154_set_multipan_short_address(esp_ieee802154_multipan_inde
* @brief Get the device extended address for specific interface.
*
* @param[in] index The interface index.
* @param[out] ext_addr The pointer to the device extended address.
* @param[out] ext_addr The pointer to the device extended address. Must not be NULL.
*
* @return
* - ESP_OK on success.
* - ESP_ERR_INVALID_ARG if ext_addr is NULL.
* - ESP_FAIL on failure.
*/
esp_err_t esp_ieee802154_get_multipan_extended_address(esp_ieee802154_multipan_index_t index, uint8_t *ext_addr);
@@ -336,10 +339,11 @@ esp_err_t esp_ieee802154_get_multipan_extended_address(esp_ieee802154_multipan_i
* @brief Set the device extended address for specific interface.
*
* @param[in] index The interface index.
* @param[in] ext_addr The pointer to the device extended address.
* @param[in] ext_addr The pointer to the device extended address. Must not be NULL.
*
* @return
* - ESP_OK on success.
* - ESP_ERR_INVALID_ARG if addr is NULL.
* - ESP_FAIL on failure.
*/
esp_err_t esp_ieee802154_set_multipan_extended_address(esp_ieee802154_multipan_index_t index, const uint8_t *ext_addr);
@@ -409,12 +413,13 @@ esp_err_t esp_ieee802154_set_pending_mode(esp_ieee802154_pending_mode_t pending_
/**
* @brief Add address to the source matching table.
*
* @param[in] addr The pointer to the address.
* @param[in] addr The pointer to the address. Must not be NULL.
* @param[in] is_short Short address or Extended address.
*
* @return
* - ESP_OK on success.
* - ESP_ERR_NO_MEM if the pending table is full.
* - ESP_ERR_INVALID_ARG if addr is NULL.
*
*/
esp_err_t esp_ieee802154_add_pending_addr(const uint8_t *addr, bool is_short);
@@ -422,12 +427,13 @@ esp_err_t esp_ieee802154_add_pending_addr(const uint8_t *addr, bool is_short);
/**
* @brief Remove address from the source matching table.
*
* @param[in] addr The pointer to the address.
* @param[in] addr The pointer to the address. Must not be NULL.
* @param[in] is_short Short address or Extended address.
*
* @return
* - ESP_OK on success.
* - ESP_ERR_NOT_FOUND if the address was not found from the source matching table.
* - ESP_ERR_INVALID_ARG if addr is NULL.
*
*/
esp_err_t esp_ieee802154_clear_pending_addr(const uint8_t *addr, bool is_short);
@@ -440,6 +446,7 @@ esp_err_t esp_ieee802154_clear_pending_addr(const uint8_t *addr, bool is_short);
* @return
* - ESP_OK on success.
* - ESP_FAIL on failure.
*
*/
esp_err_t esp_ieee802154_reset_pending_table(bool is_short);
@@ -459,6 +466,7 @@ int8_t esp_ieee802154_get_cca_threshold(void);
* @return
* - ESP_OK on success.
* - ESP_FAIL on failure.
*
*/
esp_err_t esp_ieee802154_set_cca_threshold(int8_t cca_threshold);
@@ -478,6 +486,7 @@ esp_ieee802154_cca_mode_t esp_ieee802154_get_cca_mode(void);
* @return
* - ESP_OK on success.
* - ESP_FAIL on failure.
*
*/
esp_err_t esp_ieee802154_set_cca_mode(esp_ieee802154_cca_mode_t cca_mode);
@@ -489,6 +498,7 @@ esp_err_t esp_ieee802154_set_cca_mode(esp_ieee802154_cca_mode_t cca_mode);
* @return
* - ESP_OK on success.
* - ESP_FAIL on failure.
*
*/
esp_err_t esp_ieee802154_set_rx_when_idle(bool enable);
@@ -643,12 +653,13 @@ uint8_t esp_ieee802154_get_recent_lqi(void);
/**
* @brief Set the key and addr for a frame needs to be encrypted by HW.
*
* @param[in] frame A frame needs to be encrypted. Refer to `esp_ieee802154_transmit()`.
* @param[in] key A 16-bytes key for encryption.
* @param[in] addr An 8-bytes addr for HW to generate nonce, in general, is the device extended address.
* @param[in] frame A frame needs to be encrypted. Refer to `esp_ieee802154_transmit()`. Must not be NULL.
* @param[in] key A 16-bytes key for encryption. Must not be NULL.
* @param[in] addr An 8-bytes addr for HW to generate nonce, in general, is the device extended address. Must not be NULL.
*
* @return
* - ESP_OK on success.
* - ESP_ERR_INVALID_ARG if frame, key, or addr is NULL.
* - ESP_FAIL on failure.
*/
esp_err_t esp_ieee802154_set_transmit_security(uint8_t *frame, uint8_t *key, uint8_t *addr);
@@ -657,7 +668,7 @@ esp_err_t esp_ieee802154_set_transmit_security(uint8_t *frame, uint8_t *key, uin
* @brief This function will be called when a received frame needs to be acked with Enh-Ack, the upper
* layer should generate the Enh-Ack frame in this callback function.
*
* @param[in] frame The received frame.
* @param[in] frame The received frame. Must not be NULL.
* @param[in] frame_info The frame information. Refer to `esp_ieee802154_frame_info_t`.
* @param[out] enhack_frame The Enh-ack frame need to be generated via this function, HW will send it back after AIFS.
*
@@ -741,6 +752,7 @@ esp_ieee802154_coex_config_t esp_ieee802154_get_coex_config(void);
* @return
* - ESP_OK on success.
* - ESP_FAIL on failure.
*
*/
esp_err_t esp_ieee802154_event_callback_list_register(esp_ieee802154_event_cb_list_t cb_list);
@@ -753,6 +765,7 @@ esp_err_t esp_ieee802154_event_callback_list_register(esp_ieee802154_event_cb_li
* @return
* - ESP_OK on success.
* - ESP_FAIL on failure.
*
*/
esp_err_t esp_ieee802154_event_callback_list_unregister(void);
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -10,7 +10,7 @@
#include <stdbool.h>
#include "esp_err.h"
#define US_PER_SYMBLE 16
#define US_PER_SYMBOL 16
#ifdef __cplusplus
extern "C" {
@@ -61,8 +61,8 @@ typedef enum {
} esp_ieee802154_pending_mode_t;
/**
* @brief The four groups of mac filter interface index.
*/
* @brief The four groups of mac filter interface index.
*/
typedef enum {
ESP_IEEE802154_MULTIPAN_0 = 0,
ESP_IEEE802154_MULTIPAN_1 = 1,
@@ -143,13 +143,13 @@ typedef esp_err_t (*esp_ieee802154_enh_ack_generator_cb_t)(uint8_t *frame, esp_i
*
*/
typedef struct {
esp_ieee802154_receive_done_cb_t rx_done_cb; /*!<The callback to process Rx Done event */
esp_ieee802154_receive_sfd_done_cb_t rx_sfd_done_cb; /*!<The callback to process Rx SFD Done event */
esp_ieee802154_transmit_done_cb_t tx_done_cb; /*!<The callback to process Tx Done event */
esp_ieee802154_transmit_failed_cb_t tx_failed_cb; /*!<The callback to process Tx Failed event */
esp_ieee802154_transmit_sfd_done_cb_t tx_sfd_done_cb; /*!<The callback to process Tx SFD Done event */
esp_ieee802154_energy_detect_done_cb_t ed_done_cb; /*!<The callback to process ED Done event */
esp_ieee802154_enh_ack_generator_cb_t enh_ack_generator_cb; /*!<The callback to process enh-ack generating */
esp_ieee802154_receive_done_cb_t rx_done_cb; /*!< The callback to process Rx Done event */
esp_ieee802154_receive_sfd_done_cb_t rx_sfd_done_cb; /*!< The callback to process Rx SFD Done event */
esp_ieee802154_transmit_done_cb_t tx_done_cb; /*!< The callback to process Tx Done event */
esp_ieee802154_transmit_failed_cb_t tx_failed_cb; /*!< The callback to process Tx Failed event */
esp_ieee802154_transmit_sfd_done_cb_t tx_sfd_done_cb; /*!< The callback to process Tx SFD Done event */
esp_ieee802154_energy_detect_done_cb_t ed_done_cb; /*!< The callback to process ED Done event */
esp_ieee802154_enh_ack_generator_cb_t enh_ack_generator_cb; /*!< The callback to process Enh-ack generating */
} esp_ieee802154_event_cb_list_t;
#ifdef __cplusplus