Skip to content
Open
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
4 changes: 4 additions & 0 deletions doc/nrf-bm/release_notes/release_notes_changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ Libraries
* An issue where the :c:func:`ble_conn_params_phy_radio_mode_get` function would incorrectly return the PHY mode mask of a pending update rather than the currently active PHY mode if a PHY update initiated by the :c:func:`ble_conn_params_phy_radio_mode_set` function was still in progress.
* An issue where the SoftDevice define :c:macro:`BLE_GAP_PHYS_SUPPORTED` was used instead of the PHY preferences set with Kconfig when initiating or responding to a PHY update procedure.

* :ref:`lib_peer_manager` library:

* Fixed the :c:func:`pm_address_resolve` function to return ``false`` instead of ``NRF_ERROR_INVALID_STATE`` when Peer Manager is not initialized.

Bluetooth LE Services
---------------------

Expand Down
3 changes: 2 additions & 1 deletion lib/bluetooth/peer_manager/include/modules/pm_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define BUFFER_H__

#include <stdint.h>
#include <zephyr/toolchain.h>

#ifdef __cplusplus
extern "C" {
Expand All @@ -33,7 +34,7 @@ extern "C" {
*/
#define PM_BUFFER_INIT(buffer, n_blocks, block_size, nrf_err) \
do { \
__ALIGN(4) static uint8_t buffer_memory[(n_blocks) * (block_size)]; \
__aligned(4) static uint8_t buffer_memory[(n_blocks) * (block_size)]; \
static atomic_t mutex_memory[(n_blocks - 1) / (sizeof(atomic_t) * 8) + 1]; \
nrf_err = pm_buffer_init((buffer), buffer_memory, (n_blocks) * (block_size), \
mutex_memory, (n_blocks), (block_size)); \
Expand Down
22 changes: 11 additions & 11 deletions lib/bluetooth/peer_manager/modules/gatt_cache_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,37 +48,37 @@ static atomic_t db_update_in_progress_mutex;
* @brief Flag ID for flag collection to keep track of which connections need a local DB update
* procedure.
*/
static int flag_local_db_update_pending;
static int flag_local_db_update_pending = PM_CONN_STATE_USER_FLAG_INVALID;
/**
* @brief Flag ID for flag collection to keep track of which connections need a local DB apply
* procedure.
*/
static int flag_local_db_apply_pending;
static int flag_local_db_apply_pending = PM_CONN_STATE_USER_FLAG_INVALID;
/**
* @brief Flag ID for flag collection to keep track of which connections need to be sent a service
* changed indication.
*/
static int flag_service_changed_pending;
static int flag_service_changed_pending = PM_CONN_STATE_USER_FLAG_INVALID;
/**
* @brief Flag ID for flag collection to keep track of which connections have been sent a service
* changed indication and are waiting for a handle value confirmation.
*/
static int flag_service_changed_sent;
static int flag_service_changed_sent = PM_CONN_STATE_USER_FLAG_INVALID;
/**
* @brief Flag ID for flag collection to keep track of which connections need to have their Central
* Address Resolution value stored.
*/
static int flag_car_update_pending;
static int flag_car_update_pending = PM_CONN_STATE_USER_FLAG_INVALID;
/**
* @brief Flag ID for flag collection to keep track of which connections are pending Central
* Address Resolution handle reply.
*/
static int flag_car_handle_queried;
static int flag_car_handle_queried = PM_CONN_STATE_USER_FLAG_INVALID;
/**
* @brief Flag ID for flag collection to keep track of which connections are pending Central
* Address Resolution value reply.
*/
static int flag_car_value_queried;
static int flag_car_value_queried = PM_CONN_STATE_USER_FLAG_INVALID;

/**
* @brief Function for resetting the module variable(s) of the GSCM module.
Expand Down Expand Up @@ -200,7 +200,7 @@ static void local_db_apply_in_evt(uint16_t conn_handle)
* @param[in] conn_handle The connection to perform the procedure on.
* @param[in] update Whether to perform the procedure.
*/
static __INLINE void local_db_update(uint16_t conn_handle, bool update)
static inline void local_db_update(uint16_t conn_handle, bool update)
{
pm_conn_state_user_flag_set(conn_handle, flag_local_db_update_pending, update);
}
Expand Down Expand Up @@ -379,7 +379,7 @@ static void apply_pending_handle(uint16_t conn_handle, void *context)
local_db_apply_in_evt(conn_handle);
}

static __INLINE void apply_pending_flags_check(void)
static inline void apply_pending_flags_check(void)
{
(void)pm_conn_state_for_each_set_user_flag(flag_local_db_apply_pending,
apply_pending_handle, NULL);
Expand Down Expand Up @@ -410,7 +410,7 @@ static void sc_send_pending_handle(uint16_t conn_handle, void *context)
}
}

static __INLINE void service_changed_pending_flags_check(void)
static inline void service_changed_pending_flags_check(void)
{
(void)(pm_conn_state_for_each_set_user_flag(flag_service_changed_pending,
sc_send_pending_handle, NULL));
Expand Down Expand Up @@ -459,7 +459,7 @@ static void car_update_needed(uint16_t conn_handle)
}
}

static __INLINE void update_pending_flags_check(void)
static inline void update_pending_flags_check(void)
{
uint32_t count = pm_conn_state_for_each_set_user_flag(flag_local_db_update_pending,
db_update_pending_handle, NULL);
Expand Down
21 changes: 8 additions & 13 deletions lib/bluetooth/peer_manager/modules/gatts_cache_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,29 +255,24 @@ uint32_t gscm_local_db_cache_apply(uint16_t conn_handle)
{
__ASSERT_NO_MSG(module_initialized);

uint16_t peer_id = im_peer_id_get_by_conn_handle(conn_handle);
uint32_t nrf_err;
struct pm_peer_data peer_data;
uint32_t sys_attr_flags = (SYS_ATTR_BOTH);
const uint8_t *sys_attr_data = NULL;
uint16_t sys_attr_len = 0;
uint32_t sys_attr_flags = (SYS_ATTR_BOTH);
uint16_t peer_id = im_peer_id_get_by_conn_handle(conn_handle);
uint8_t local_gatt_db_buf[PM_PEER_DATA_LOCAL_GATT_DB_MAX_SIZE] = {0};
uint32_t local_gatt_db_size = PM_PEER_DATA_LOCAL_GATT_DB_MAX_SIZE;
struct pm_peer_data peer_data;
bool all_attributes_applied = true;

if (peer_id != PM_PEER_ID_INVALID) {
uint8_t local_gatt_db_buf[PM_PEER_DATA_LOCAL_GATT_DB_MAX_SIZE] = { 0 };
uint32_t local_gatt_db_size = PM_PEER_DATA_LOCAL_GATT_DB_MAX_SIZE;
struct pm_peer_data_local_gatt_db *curr_local_gatt_db =
(struct pm_peer_data_local_gatt_db *)local_gatt_db_buf;
peer_data.all_data = &local_gatt_db_buf;
nrf_err = pds_peer_data_read(peer_id, PM_PEER_DATA_ID_GATT_LOCAL, &peer_data,
&local_gatt_db_size);
if (nrf_err == NRF_SUCCESS) {
const struct pm_peer_data_local_gatt_db *local_gatt_db;

local_gatt_db = curr_local_gatt_db;
sys_attr_data = local_gatt_db->data;
sys_attr_len = local_gatt_db->len;
sys_attr_flags = local_gatt_db->flags;
sys_attr_flags = peer_data.local_gatt_db->flags;
sys_attr_len = peer_data.local_gatt_db->len;
sys_attr_data = peer_data.local_gatt_db->data;
}
}

Expand Down
5 changes: 3 additions & 2 deletions lib/bluetooth/peer_manager/modules/nrf_ble_lesc.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <zephyr/sys/byteorder.h>
#include <zephyr/sys/util.h>
#include <zephyr/sys/printk.h>
#include <zephyr/toolchain.h>

#include <bm/bluetooth/peer_manager/nrf_ble_lesc.h>

Expand All @@ -36,9 +37,9 @@ struct lesc_peer_pub_key {
#define NRF_BLE_LESC_LINK_COUNT CONFIG_NRF_SDH_BLE_TOTAL_LINK_COUNT

/** LESC ECC Public Key. */
__ALIGN(4) static ble_gap_lesc_p256_pk_t lesc_public_key;
__aligned(4) static ble_gap_lesc_p256_pk_t lesc_public_key;
/** LESC ECC DH Key. */
__ALIGN(4) static ble_gap_lesc_dhkey_t lesc_dh_key;
__aligned(4) static ble_gap_lesc_dhkey_t lesc_dh_key;

/** Flag indicating that the module encountered an internal error. */
static bool ble_lesc_internal_error;
Expand Down
4 changes: 3 additions & 1 deletion lib/bluetooth/peer_manager/modules/peer_data_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ static void peer_ids_load(void)

peer_data.all_data = peer_data_buffer;

/* Search through existing bonds to look for a duplicate. */
/* Allocate peer IDs for already stored bonds. */
pds_peer_data_iterate_prepare(&peer_id_iter);

while (pds_peer_data_iterate(PM_PEER_DATA_ID_BONDING, &peer_id, &peer_data,
Expand Down Expand Up @@ -282,7 +282,9 @@ static void bm_zms_evt_handler(const struct bm_zms_evt *evt)
static void wait_for_init(void)
{
while (!fs.init_flags.initialized) {
#if !defined(CONFIG_UNITY)
k_cpu_idle();
#endif
}
}

Expand Down
8 changes: 7 additions & 1 deletion lib/bluetooth/peer_manager/modules/peer_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#include <string.h>
#include <limits.h>
#include <zephyr/sys/atomic.h>
#include <nrf_bitmask.h>
#if !defined(CONFIG_UNITY)
#include <nrfx.h>
#endif
#include <bm/bluetooth/peer_manager/peer_manager_types.h>
#include <modules/peer_id.h>

Expand Down Expand Up @@ -40,7 +42,11 @@ static uint32_t find_and_set_flag(atomic_t *pi_flags, uint32_t flag_count)

while (inverted) {
/* Find lowest zero bit */
#if defined(CONFIG_UNITY)
uint32_t first_zero = __builtin_ctz(inverted);
#else
uint32_t first_zero = NRF_CTZ(inverted);
#endif
uint32_t first_zero_global = first_zero + (i * 32);

if (first_zero_global >= flag_count) {
Expand Down
30 changes: 9 additions & 21 deletions lib/bluetooth/peer_manager/modules/security_dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@ static int flag_allow_repairing = PM_CONN_STATE_USER_FLAG_INVALID;

static ble_gap_lesc_p256_pk_t peer_pk;

static __INLINE bool sec_procedure(uint16_t conn_handle)
static inline bool sec_procedure(uint16_t conn_handle)
{
return pm_conn_state_user_flag_get(conn_handle, flag_sec_proc);
}

static __INLINE bool pairing(uint16_t conn_handle)
static inline bool pairing(uint16_t conn_handle)
{
return pm_conn_state_user_flag_get(conn_handle, flag_sec_proc_pairing);
}

static __INLINE bool bonding(uint16_t conn_handle)
static inline bool bonding(uint16_t conn_handle)
{
return pm_conn_state_user_flag_get(conn_handle, flag_sec_proc_bonding);
}

static __INLINE bool allow_repairing(uint16_t conn_handle)
static inline bool allow_repairing(uint16_t conn_handle)
{
return pm_conn_state_user_flag_get(conn_handle, flag_allow_repairing);
}
Expand Down Expand Up @@ -196,7 +196,7 @@ static void pairing_failure(uint16_t conn_handle, uint16_t error, uint8_t error_
* @param[in] error The error the procedure failed with. See @ref PM_SEC_ERRORS.
* @param[in] error_src The party that raised the error. See @ref BLE_GAP_SEC_STATUS_SOURCES.
*/
static __INLINE void encryption_failure(uint16_t conn_handle, uint16_t error, uint8_t error_src)
static inline void encryption_failure(uint16_t conn_handle, uint16_t error, uint8_t error_src)
{
conn_sec_failure(conn_handle, PM_CONN_SEC_PROCEDURE_ENCRYPTION, error, error_src);
}
Expand Down Expand Up @@ -716,26 +716,14 @@ static void conn_sec_update_process(const ble_gap_evt_t *gap_evt)
}
}

/**
* @brief Function for initializing a Bluetooth LE Connection State user flag.
*
* @param[out] flag_id The flag to initialize.
*/
static void flag_id_init(int *flag_id)
{
if (*flag_id == PM_CONN_STATE_USER_FLAG_INVALID) {
*flag_id = pm_conn_state_user_flag_acquire();
}
}

uint32_t smd_init(void)
{
__ASSERT_NO_MSG(!module_initialized);

flag_id_init(&flag_sec_proc);
flag_id_init(&flag_sec_proc_pairing);
flag_id_init(&flag_sec_proc_bonding);
flag_id_init(&flag_allow_repairing);
flag_sec_proc = pm_conn_state_user_flag_acquire();
flag_sec_proc_pairing = pm_conn_state_user_flag_acquire();
flag_sec_proc_bonding = pm_conn_state_user_flag_acquire();
flag_allow_repairing = pm_conn_state_user_flag_acquire();

if ((flag_sec_proc == PM_CONN_STATE_USER_FLAG_INVALID) ||
(flag_sec_proc_pairing == PM_CONN_STATE_USER_FLAG_INVALID) ||
Expand Down
39 changes: 18 additions & 21 deletions lib/bluetooth/peer_manager/modules/security_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ static void smd_params_reply_perform(uint16_t conn_handle,
*
* @param[in] event The @ref PM_EVT_CONN_SEC_PARAMS_REQ event.
*/
static __INLINE void params_req_process(const struct pm_evt *event)
static inline void params_req_process(const struct pm_evt *event)
{
smd_params_reply_perform(event->conn_handle,
event->conn_sec_params_req.peer_params);
Expand Down Expand Up @@ -406,7 +406,7 @@ static void sec_req_process(const struct pm_evt *event)
(void)link_secure(event->conn_handle, null_params, force_repairing, true);
/* The error code has been properly handled inside link_secure(). */
}
#endif
#endif /* CONFIG_SOFTDEVICE_CENTRAL */

/**
* @brief Function for translating an SMD event to an SM event and passing it on to SM event
Expand Down Expand Up @@ -434,7 +434,7 @@ void sm_smd_evt_handler(struct pm_evt *event)
case PM_EVT_PERIPHERAL_SECURITY_REQ:
#if defined(CONFIG_SOFTDEVICE_CENTRAL)
sec_req_process(event);
#endif
#endif /* CONFIG_SOFTDEVICE_CENTRAL */
/* fallthrough */
default:
/* Forward the event to all registered Security Manager event handlers. */
Expand Down Expand Up @@ -489,18 +489,6 @@ void sm_pdb_evt_handler(struct pm_evt *event)
}
}

/**
* @brief Function for initializing a Bluetooth LE Connection State user flag.
*
* @param[out] flag_id The flag to initialize.
*/
static void flag_id_init(int *flag_id)
{
if (*flag_id == PM_CONN_STATE_USER_FLAG_INVALID) {
*flag_id = pm_conn_state_user_flag_acquire();
}
}

uint32_t sm_init(void)
{
__ASSERT_NO_MSG(!module_initialized);
Expand All @@ -513,17 +501,26 @@ uint32_t sm_init(void)
}
#endif

flag_id_init(&flag_link_secure_pending_busy);
flag_id_init(&flag_link_secure_force_repairing);
flag_id_init(&flag_link_secure_null_params);
flag_id_init(&flag_params_reply_pending_busy);

if (flag_params_reply_pending_busy == PM_CONN_STATE_USER_FLAG_INVALID) {
flag_link_secure_pending_busy = pm_conn_state_user_flag_acquire();
flag_link_secure_force_repairing = pm_conn_state_user_flag_acquire();
flag_link_secure_null_params = pm_conn_state_user_flag_acquire();
flag_params_reply_pending_busy = pm_conn_state_user_flag_acquire();

/* If successfully acquiring the last set of flags,
* all sets of flags have been successfully acquired.
*/
if ((flag_link_secure_pending_busy == PM_CONN_STATE_USER_FLAG_INVALID) ||
(flag_link_secure_force_repairing == PM_CONN_STATE_USER_FLAG_INVALID) ||
(flag_link_secure_null_params == PM_CONN_STATE_USER_FLAG_INVALID) ||
(flag_params_reply_pending_busy == PM_CONN_STATE_USER_FLAG_INVALID)) {
LOG_ERR("Could not acquire conn_state user flags. Increase "
"PM_CONN_STATE_USER_FLAG_COUNT in the pm_conn_state module.");
return NRF_ERROR_INTERNAL;
}

default_sec_params = NULL;
default_sec_params_set = false;

module_initialized = true;

return NRF_SUCCESS;
Expand Down
Loading
Loading