Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions nrf_802154/common/include/nrf_802154.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,29 @@ void nrf_802154_extended_address_set(const uint8_t * p_extended_address);
*/
void nrf_802154_short_address_set(const uint8_t * p_short_address);

/**
* @brief Sets the alternate short address of the device.
*
* The alternate short address should be used when you need to change the
* device short address without loss of connectivity.
* The API addresses a race condition, where a remote peer sends a frame destined
* to the old device address, but this device has already changed the short address
* to a new one. The alternate address should be cleared after a while, after the new
* short address becomes known to the peers.
*
* The API is meant to be used as follows:
* 1. Set the alternate short address to the current old address.
* 2. Set the primary short address (@ref nrf_802154_short_address_set) to the new address.
* 3. Wait until the new short address becomes known among the peers.
* 4. Clear the alternate short address.
*
* @param[in] p_short_address Pointer to the short address (2 bytes, little-endian).
* Setting this value to NULL clears the alternate address.
*
* This function makes a copy of the address.
*/
void nrf_802154_alternate_short_address_set(const uint8_t * p_short_address);

#if !NRF_802154_SERIALIZATION_HOST || defined(DOXYGEN)
/**
* @}
Expand Down
8 changes: 8 additions & 0 deletions nrf_802154/doc/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ 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
***************************************

Added
=====

* Added the :c:func:`nrf_802154_alternate_short_address_set` function, which allows for setting the secondary short address that will be accepted by the frame filter. (KRKNWK-20051)

nRF Connect SDK v3.0.0 - nRF 802.15.4 Radio Driver
**************************************************

Expand Down
13 changes: 7 additions & 6 deletions nrf_802154/driver/src/mac_features/nrf_802154_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,19 +337,20 @@ static bool dst_pan_id_check(const uint8_t * p_panid, uint8_t frame_type)
*/
static bool dst_short_addr_check(const uint8_t * p_dst_addr)
{
bool result;

if ((0 == memcmp(p_dst_addr, nrf_802154_pib_short_address_get(), SHORT_ADDRESS_SIZE)) ||
(0 == memcmp(p_dst_addr, BROADCAST_ADDRESS, SHORT_ADDRESS_SIZE)))
{
result = true;
return true;
}
else

const uint8_t * alternate_address = nrf_802154_pib_alternate_short_address_get();

if (alternate_address && (0 == memcmp(p_dst_addr, alternate_address, SHORT_ADDRESS_SIZE)))
{
result = false;
return true;
}

return result;
return false;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions nrf_802154/driver/src/nrf_802154.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ void nrf_802154_short_address_set(const uint8_t * p_short_address)
nrf_802154_pib_short_address_set(p_short_address);
}

void nrf_802154_alternate_short_address_set(const uint8_t * p_short_address)
{
nrf_802154_pib_alternate_short_address_set(p_short_address);
}

void nrf_802154_init(void)
{
static const nrf_802154_sl_crit_sect_interface_t crit_sect_int =
Expand Down
27 changes: 27 additions & 0 deletions nrf_802154/driver/src/nrf_802154_pib.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

#include "nrf_802154_config.h"
#include "nrf_802154_const.h"
#include "nrf_802154_sl_atomics.h"

#define CSMACA_BE_MAXIMUM 8 ///< The maximum allowed CSMA-CA backoff exponent (BE) that results from the implementation

Expand Down Expand Up @@ -89,6 +90,7 @@ typedef struct
int8_t tx_power; ///< Transmit power.
uint8_t pan_id[PAN_ID_SIZE]; ///< Pan Id of this node.
uint8_t short_addr[SHORT_ADDRESS_SIZE]; ///< Short Address of this node.
uint8_t alt_short_addr[SHORT_ADDRESS_SIZE]; ///< Alternate short address of this node.
uint8_t extended_addr[EXTENDED_ADDRESS_SIZE]; ///< Extended Address of this node.
nrf_802154_cca_cfg_t cca; ///< CCA mode and thresholds.
bool promiscuous : 1; ///< Indicating if radio is in promiscuous mode.
Expand All @@ -97,6 +99,7 @@ typedef struct
uint8_t channel : 5; ///< Channel on which the node receives messages.
bool rx_on_when_idle; ///< Indicating if radio is in RxOnWhenIdle mode.
nrf_802154_pib_coex_t coex; ///< Coex-related fields.
uint8_t alt_short_addr_present; ///< Indicates if the alternate short address is configured.

#if NRF_802154_CSMA_CA_ENABLED
nrf_802154_pib_csmaca_t csmaca; ///< CSMA-CA related fields.
Expand Down Expand Up @@ -212,6 +215,7 @@ void nrf_802154_pib_init(void)
m_data.test_modes.csmaca_backoff = NRF_802154_TEST_MODE_CSMACA_BACKOFF_RANDOM;
#endif

nrf_802154_sl_atomic_store_u8(&m_data.alt_short_addr_present, false);
}

bool nrf_802154_pib_promiscuous_get(void)
Expand Down Expand Up @@ -304,6 +308,29 @@ void nrf_802154_pib_short_address_set(const uint8_t * p_short_address)
memcpy(m_data.short_addr, p_short_address, SHORT_ADDRESS_SIZE);
}

const uint8_t * nrf_802154_pib_alternate_short_address_get(void)
{
if (false == nrf_802154_sl_atomic_load_u8(&m_data.alt_short_addr_present))
{
return NULL;
}

return m_data.alt_short_addr;
}

void nrf_802154_pib_alternate_short_address_set(const uint8_t * p_short_address)
{
if (p_short_address)
{
memcpy(m_data.alt_short_addr, p_short_address, SHORT_ADDRESS_SIZE);
nrf_802154_sl_atomic_store_u8(&m_data.alt_short_addr_present, true);
}
else
{
nrf_802154_sl_atomic_store_u8(&m_data.alt_short_addr_present, false);
}
}

void nrf_802154_pib_cca_cfg_set(const nrf_802154_cca_cfg_t * p_cca_cfg)
{
switch (p_cca_cfg->mode)
Expand Down
18 changes: 18 additions & 0 deletions nrf_802154/driver/src/nrf_802154_pib.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,24 @@ const uint8_t * nrf_802154_pib_short_address_get(void);
*/
void nrf_802154_pib_short_address_set(const uint8_t * p_short_address);

/**
* @brief Gets the alternate short address of this device.
*
* @returns Pointer to the buffer containing the short address (2 bytes, little-endian)
* or NULL if the alternate address is cleared.
*/
const uint8_t * nrf_802154_pib_alternate_short_address_get(void);

/**
* @brief Sets the alternate short address of the device.
*
* @param[in] p_short_address Pointer to the short address (2 bytes, little-endian).
* Setting this value to NULL clears the alternate address.
*
* This function makes a copy of the address.
*/
void nrf_802154_pib_alternate_short_address_set(const uint8_t * p_short_address);

/**
* @brief Sets the radio CCA mode and threshold.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,11 @@ typedef enum
SPINEL_PROP_VENDOR_NORDIC_NRF_802154_RECEIVE_AT_SCHEDULED_CANCEL =
SPINEL_PROP_VENDOR_NORDIC_NRF_802154__BEGIN + 69,

/**
* Vendor property for nrf_802154_alternate_short_address_set serialization.
*/
SPINEL_PROP_VENDOR_NORDIC_NRF_802154_ALTERNATE_SHORT_ADDRESS_SET =
SPINEL_PROP_VENDOR_NORDIC_NRF_802154__BEGIN + 70,
} spinel_prop_vendor_key_t;

/**
Expand Down Expand Up @@ -879,110 +884,117 @@ typedef enum
*/
#define SPINEL_DATATYPE_NRF_802154_SHORT_ADDRESS_SET SPINEL_DATATYPE_DATA_S

/**
* @brief Spinel data type description for nrf_802154_short_address_set.
*/
#define SPINEL_DATATYPE_NRF_802154_ALTERNATE_SHORT_ADDRESS_SET\
SPINEL_DATATYPE_BOOL_S /* Data valid flag */ \
SPINEL_DATATYPE_DATA_S /* Alternative short address */ \

/**
* @brief Spinel data type description for nrf_802154_extended_address_set.
*/
#define SPINEL_DATATYPE_NRF_802154_EXTENDED_ADDRESS_SET SPINEL_DATATYPE_DATA_S
#define SPINEL_DATATYPE_NRF_802154_EXTENDED_ADDRESS_SET SPINEL_DATATYPE_DATA_S

/**
* @brief Spinel data type description for nrf_802154_pan_coord_set.
*/
#define SPINEL_DATATYPE_NRF_802154_PAN_COORD_SET SPINEL_DATATYPE_BOOL_S
#define SPINEL_DATATYPE_NRF_802154_PAN_COORD_SET SPINEL_DATATYPE_BOOL_S

/**
* @brief Spinel data type description for nrf_802154_pan_coord_get result.
*/
#define SPINEL_DATATYPE_NRF_802154_PAN_COORD_GET_RET SPINEL_DATATYPE_BOOL_S
#define SPINEL_DATATYPE_NRF_802154_PAN_COORD_GET_RET SPINEL_DATATYPE_BOOL_S

/**
* @brief Spinel data type description for nrf_802154_pan_coord_get.
*/
#define SPINEL_DATATYPE_NRF_802154_PAN_COORD_GET SPINEL_DATATYPE_NULL_S
#define SPINEL_DATATYPE_NRF_802154_PAN_COORD_GET SPINEL_DATATYPE_NULL_S

/**
* @brief Spinel data type description for nrf_802154_promiscuous_set.
*/
#define SPINEL_DATATYPE_NRF_802154_PROMISCUOUS_SET SPINEL_DATATYPE_BOOL_S
#define SPINEL_DATATYPE_NRF_802154_PROMISCUOUS_SET SPINEL_DATATYPE_BOOL_S

/**
* @brief Spinel data type description for nrf_802154_rx_on_when_idle_set.
*/
#define SPINEL_DATATYPE_NRF_802154_RX_ON_WHEN_IDLE_SET SPINEL_DATATYPE_BOOL_S
#define SPINEL_DATATYPE_NRF_802154_RX_ON_WHEN_IDLE_SET SPINEL_DATATYPE_BOOL_S

/**
* @brief Spinel data type description for nrf_802154_cca.
*/
#define SPINEL_DATATYPE_NRF_802154_CCA SPINEL_DATATYPE_NULL_S
#define SPINEL_DATATYPE_NRF_802154_CCA SPINEL_DATATYPE_NULL_S

/**
* @brief Spinel data type description for nrf_802154_cca result.
*/
#define SPINEL_DATATYPE_NRF_802154_CCA_RET SPINEL_DATATYPE_BOOL_S
#define SPINEL_DATATYPE_NRF_802154_CCA_RET SPINEL_DATATYPE_BOOL_S

/**
* @brief Spinel data type description for nrf_802154_cca_done.
*/
#define SPINEL_DATATYPE_NRF_802154_CCA_DONE SPINEL_DATATYPE_BOOL_S
#define SPINEL_DATATYPE_NRF_802154_CCA_DONE SPINEL_DATATYPE_BOOL_S

/**
* @brief Spinel data type description for nrf_802154_cca_failed.
*/
#define SPINEL_DATATYPE_NRF_802154_CCA_FAILED SPINEL_DATATYPE_UINT8_S
#define SPINEL_DATATYPE_NRF_802154_CCA_FAILED SPINEL_DATATYPE_UINT8_S

/**
* @brief Spinel data type description for nrf_802154_energy_detection.
*/
#define SPINEL_DATATYPE_NRF_802154_ENERGY_DETECTION SPINEL_DATATYPE_UINT32_S
#define SPINEL_DATATYPE_NRF_802154_ENERGY_DETECTION SPINEL_DATATYPE_UINT32_S

/**
* @brief Spinel data type description for nrf_802154_energy_detection result.
*/
#define SPINEL_DATATYPE_NRF_802154_ENERGY_DETECTION_RET SPINEL_DATATYPE_BOOL_S
#define SPINEL_DATATYPE_NRF_802154_ENERGY_DETECTION_RET SPINEL_DATATYPE_BOOL_S

/**
* @brief Spinel data type description for nrf_802154_energy_detected.
*/
#define SPINEL_DATATYPE_NRF_802154_ENERGY_DETECTED SPINEL_DATATYPE_INT8_S
#define SPINEL_DATATYPE_NRF_802154_ENERGY_DETECTED SPINEL_DATATYPE_INT8_S

/**
* @brief Spinel data type description for nrf_802154_energy_detection_failed.
*/
#define SPINEL_DATATYPE_NRF_802154_ENERGY_DETECTION_FAILED SPINEL_DATATYPE_UINT8_S
#define SPINEL_DATATYPE_NRF_802154_ENERGY_DETECTION_FAILED SPINEL_DATATYPE_UINT8_S

/**
* @brief Spinel data type description for nrf_802154_continuous_carrier.
*/
#define SPINEL_DATATYPE_NRF_802154_CONTINUOUS_CARRIER SPINEL_DATATYPE_NULL_S
#define SPINEL_DATATYPE_NRF_802154_CONTINUOUS_CARRIER SPINEL_DATATYPE_NULL_S

/**
* @brief Spinel data type description for nrf_802154_nrf_802154_continuous_carrier result.
*/
#define SPINEL_DATATYPE_NRF_802154_CONTINUOUS_CARRIER_RET SPINEL_DATATYPE_BOOL_S
#define SPINEL_DATATYPE_NRF_802154_CONTINUOUS_CARRIER_RET SPINEL_DATATYPE_BOOL_S

/**
* @brief Spinel data type description for nrf_802154_modulated_carrier.
*/
#define SPINEL_DATATYPE_NRF_802154_MODULATED_CARRIER SPINEL_DATATYPE_DATA_S
#define SPINEL_DATATYPE_NRF_802154_MODULATED_CARRIER SPINEL_DATATYPE_DATA_S

/**
* @brief Spinel data type description for nrf_802154_nrf_802154_modulated_carrier result.
*/
#define SPINEL_DATATYPE_NRF_802154_MODULATED_CARRIER_RET SPINEL_DATATYPE_BOOL_S
#define SPINEL_DATATYPE_NRF_802154_MODULATED_CARRIER_RET SPINEL_DATATYPE_BOOL_S

/**
* @brief Spinel data type description for nrf_802154_tx_power_get.
*/
#define SPINEL_DATATYPE_NRF_802154_TX_POWER_GET SPINEL_DATATYPE_NULL_S
#define SPINEL_DATATYPE_NRF_802154_TX_POWER_GET SPINEL_DATATYPE_NULL_S

/**
* @brief Spinel data type description for nrf_802154_tx_power_get result.
*/
#define SPINEL_DATATYPE_NRF_802154_TX_POWER_GET_RET SPINEL_DATATYPE_INT8_S
#define SPINEL_DATATYPE_NRF_802154_TX_POWER_GET_RET SPINEL_DATATYPE_INT8_S

/**
* @brief Spinel data type description for nrf_802154_tx_power_set.
*/
#define SPINEL_DATATYPE_NRF_802154_TX_POWER_SET SPINEL_DATATYPE_INT8_S
#define SPINEL_DATATYPE_NRF_802154_TX_POWER_SET SPINEL_DATATYPE_INT8_S

/**
* @brief Spinel data type description for nrf_802154_received_timestamp_raw
Expand Down
37 changes: 37 additions & 0 deletions nrf_802154/serialization/src/nrf_802154_spinel_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,43 @@ void nrf_802154_short_address_set(const uint8_t * p_short_address)
return;
}

void nrf_802154_alternate_short_address_set(const uint8_t * p_short_address)
{
nrf_802154_ser_err_t res;

bool data_valid = p_short_address != NULL;
uint8_t invalid_addr[2] = {0xff, 0xff};

if (!data_valid)
{
p_short_address = invalid_addr;
}

SERIALIZATION_ERROR_INIT(error);

NRF_802154_SPINEL_LOG_BANNER_CALLING();
NRF_802154_SPINEL_LOG_BUFF(p_short_address, SHORT_ADDRESS_SIZE);

nrf_802154_spinel_response_notifier_lock_before_request(SPINEL_PROP_LAST_STATUS);

res = nrf_802154_spinel_send_cmd_prop_value_set(
SPINEL_PROP_VENDOR_NORDIC_NRF_802154_ALTERNATE_SHORT_ADDRESS_SET,
SPINEL_DATATYPE_NRF_802154_ALTERNATE_SHORT_ADDRESS_SET,
data_valid,
p_short_address,
SHORT_ADDRESS_SIZE);

SERIALIZATION_ERROR_CHECK(res, error, bail);

res = status_ok_await(CONFIG_NRF_802154_SER_DEFAULT_RESPONSE_TIMEOUT);
SERIALIZATION_ERROR_CHECK(res, error, bail);

bail:
SERIALIZATION_ERROR_RAISE_IF_FAILED(error);

return;
}

void nrf_802154_extended_address_set(const uint8_t * p_extended_address)
{
nrf_802154_ser_err_t res;
Expand Down
Loading