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
57 changes: 28 additions & 29 deletions applications/firmware_loader/ble_mcumgr/src/main.c
Comment thread
anhmolt marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include <errno.h>
#include <nrf_error.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
Expand Down Expand Up @@ -50,9 +50,9 @@ static struct mgmt_callback os_mgmt_reboot_callback = {
*/
static void on_ble_evt(const ble_evt_t *evt, void *ctx)
{
int err;
uint32_t nrf_err;

__ASSERT(ble_evt, "BLE event is NULL");
__ASSERT(evt, "BLE event is NULL");

if (evt == NULL) {
return;
Expand All @@ -63,10 +63,10 @@ static void on_ble_evt(const ble_evt_t *evt, void *ctx)
{
LOG_INF("Peer connected");
conn_handle = evt->evt.gap_evt.conn_handle;
err = sd_ble_gatts_sys_attr_set(evt->evt.gap_evt.conn_handle, NULL, 0, 0);
nrf_err = sd_ble_gatts_sys_attr_set(evt->evt.gap_evt.conn_handle, NULL, 0, 0);

if (err) {
LOG_ERR("Failed to set system attributes, nrf_error %#x", err);
if (nrf_err) {
LOG_ERR("Failed to set system attributes, nrf_error %#x", nrf_err);
}
break;
}
Expand All @@ -92,11 +92,12 @@ static void on_ble_evt(const ble_evt_t *evt, void *ctx)
case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
{
/* Pairing not supported */
err = sd_ble_gap_sec_params_reply(evt->evt.gap_evt.conn_handle,
BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL);
nrf_err = sd_ble_gap_sec_params_reply(evt->evt.gap_evt.conn_handle,
BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP,
NULL, NULL);

if (err) {
LOG_ERR("Failed to reply with Security params, nrf_error %#x", err);
if (nrf_err) {
LOG_ERR("Failed to reply with Security params, nrf_error %#x", nrf_err);
}

break;
Expand All @@ -106,10 +107,10 @@ static void on_ble_evt(const ble_evt_t *evt, void *ctx)
{
LOG_INF("BLE_GATTS_EVT_SYS_ATTR_MISSING");
/* No system attributes have been stored */
err = sd_ble_gatts_sys_attr_set(evt->evt.gap_evt.conn_handle, NULL, 0, 0);
nrf_err = sd_ble_gatts_sys_attr_set(evt->evt.gap_evt.conn_handle, NULL, 0, 0);

if (err) {
LOG_ERR("Failed to set system attributes, nrf_error %#x", err);
if (nrf_err) {
LOG_ERR("Failed to set system attributes, nrf_error %#x", nrf_err);
}

break;
Expand Down Expand Up @@ -154,18 +155,16 @@ static enum mgmt_cb_return os_mgmt_reboot_hook(uint32_t event, enum mgmt_cb_retu

/**
* @brief Change Bluetooth address from the default random address
*
* @param[out] err Error code
*/
static int ble_change_address(void)
static uint32_t ble_change_address(void)
{
int err;
uint32_t nrf_err;
ble_gap_addr_t device_address;

err = sd_ble_gap_addr_get(&device_address);
nrf_err = sd_ble_gap_addr_get(&device_address);

if (err != 0) {
return err;
if (nrf_err) {
return nrf_err;
}

device_address.addr[0] ^= 0x1;
Expand Down Expand Up @@ -212,19 +211,19 @@ int main(void)

LOG_INF("Bluetooth enabled");

err = ble_mcumgr_init();
nrf_err = ble_mcumgr_init();

if (err) {
LOG_ERR("Failed to initialize MCUmgr service, err %d", err);
if (nrf_err) {
LOG_ERR("Failed to initialize MCUmgr service, nrf_error %#x", nrf_err);
return 0;
}

LOG_INF("Services initialized");

err = ble_change_address();
nrf_err = ble_change_address();

if (err) {
LOG_ERR("Failed to change Bluetooth address, err %d", err);
if (nrf_err) {
LOG_ERR("Failed to change Bluetooth address, nrf_error %#x", nrf_err);
}

/* Add MCUmgr Bluetooth service UUID to scan response */
Expand Down Expand Up @@ -259,10 +258,10 @@ int main(void)
}

if (device_disconnected == false) {
err = sd_ble_gap_disconnect(conn_handle,
BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
nrf_err = sd_ble_gap_disconnect(conn_handle,
BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);

if (err != NRF_SUCCESS) {
if (nrf_err) {
device_disconnected = true;
}

Expand Down
64 changes: 33 additions & 31 deletions doc/nrf-bm/libraries/bluetooth/ble_peer_manager.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ The following code example shows how the Peer Manager is initialized:

.. code-block:: c

static int peer_manager_init(bool erase_bonds)
static uint32_t peer_manager_init(bool erase_bonds)
{
uint32_t err;
uint32_t nrf_err;
ble_gap_sec_params_t sec_param;

err = pm_init();
if (err) {
return -EFAULT;
nrf_err = pm_init();
if (nrf_err) {
return nrf_err;
}

if (erase_bonds) {
Expand All @@ -179,17 +179,19 @@ The following code example shows how the Peer Manager is initialized:
.kdist_peer.id = 1,
};

err = pm_sec_params_set(&sec_param);
if (err) {
LOG_ERR("pm_sec_params_set() failed, err: 0x%x", err);
return -EFAULT;
nrf_err = pm_sec_params_set(&sec_param);
if (nrf_err) {
LOG_ERR("pm_sec_params_set() failed, nrf_error 0x%x", nrf_err);
return nrf_err;
}

err = pm_register(pm_evt_handler);
if (err) {
LOG_ERR("pm_register() failed, err: 0x%x", err);
return -EFAULT;
nrf_err = pm_register(pm_evt_handler);
if (nrf_err) {
LOG_ERR("pm_register() failed, nrf_error 0x%x", nrf_err);
return nrf_err;
}

return NRF_SUCCESS;
}

Usage
Expand Down Expand Up @@ -348,25 +350,25 @@ The store operation is finished when either the :c:enum:`PM_EVT_PEER_DATA_UPDATE

.. code-block:: c

uint32_t err;
uint32_t nrf_err;
uint32_t store_token;

err = pm_peer_data_remote_db_store(peer_id, array_of_services, number_of_services, &store_token);
if (err != NRF_ERROR_BUSY) {
return err;
nrf_err = pm_peer_data_remote_db_store(peer_id, array_of_services, number_of_services, &store_token);
if (nrf_err != NRF_SUCCESS && nrf_err != NRF_ERROR_BUSY) {
return nrf_err;
}

The :c:func:`pm_peer_data_remote_db_store`, :c:func:`pm_peer_data_bonding_store`, and :c:func:`pm_peer_data_app_data_store` functions call the :c:func:`pm_peer_data_store` function.
The :c:func:`pm_peer_data_store` function can also be used directly, as in the following example:

.. code-block:: c

uint32_t err;
uint32_t nrf_err;
uint32_t store_token;

err = pm_peer_data_store(peer_id, PM_PEER_DATA_ID_GATT_REMOTE, array_of_services, number_of_services, &store_token);
if (err != NRF_ERROR_BUSY) {
return err;
nrf_err = pm_peer_data_store(peer_id, PM_PEER_DATA_ID_GATT_REMOTE, array_of_services, number_of_services, &store_token);
if (nrf_err != NRF_SUCCESS && nrf_err != NRF_ERROR_BUSY) {
return nrf_err;
}

Using a whitelist
Expand All @@ -392,9 +394,9 @@ The following example shows how to use the :c:func:`pm_whitelist_set` function t
}

/* Whitelist peers. */
err = pm_whitelist_set(peer_ids, n_peer_ids);
if (err != NRF_SUCCESS) {
return err;
nrf_err = pm_whitelist_set(peer_ids, n_peer_ids);
if (nrf_err) {
return nrf_err;
}
}

Expand All @@ -409,7 +411,7 @@ The following example shows how to use the :c:func:`pm_whitelist_set` function t
* previously whitelisted using pm_whitelist_set().
*/

uint32_t err;
uint32_t nrf_err;

/* Storage for the whitelist. */
ble_gap_irk_t irks[8] = {0};
Expand All @@ -418,15 +420,15 @@ The following example shows how to use the :c:func:`pm_whitelist_set` function t
uint32_t irk_cnt = 8;
uint32_t addr_cnt = 8;

err = pm_whitelist_get(addrs, &addr_cnt, irks, &irk_cnt);
if (err != NRF_SUCCESS) {
return err;
nrf_err = pm_whitelist_get(addrs, &addr_cnt, irks, &irk_cnt);
if (nrf_err) {
return;
}

/* Apply the whitelist. */
err = ble_advertising_whitelist_reply(addrs, addr_cnt, irks, irk_cnt);
if (err != NRF_SUCCESS) {
return err;
nrf_err = ble_advertising_whitelist_reply(addrs, addr_cnt, irks, irk_cnt);
if (nrf_err) {
return;
}

break;
Expand Down
24 changes: 17 additions & 7 deletions doc/nrf-bm/release_notes/release_notes_changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ Boards

* MCUboot partition size has been reduced from 36 KiB to 31 KiB for the following board targets:

* `bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice/mcuboot`
* `bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice/mcuboot`
* `bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice/mcuboot`
* ``bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice/mcuboot``
* ``bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice/mcuboot``
* ``bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice/mcuboot``

* Removed unused peripheral nodes from Devicetree.

Expand All @@ -56,7 +56,7 @@ Build system
DFU
===

* Support for KMU usage for MCUboot keys has been added, along with west auto-provisioning support (`west flash --erase` or `west flash --recover` must be used during first programming of a board to program the KMU with the keys).
* Support for KMU usage for MCUboot keys has been added, along with west auto-provisioning support (``west flash --erase`` or ``west flash --recover`` must be used during first programming of a board to program the KMU with the keys).
This feature can be controlled with sysbuild Kconfig options :kconfig:option:`SB_CONFIG_BM_BOOTLOADER_MCUBOOT_SIGNATURE_USING_KMU` to use KMU for key storage and :kconfig:option:`SB_CONFIG_BM_BOOTLOADER_MCUBOOT_GENERATE_DEFAULT_KMU_KEYFILE` to auto-provision the KMU when using the above west flash commands.
* The code for the UART MCUmgr application has now been refactored into a separate library to facilitate reuse in other applications.

Expand All @@ -76,9 +76,19 @@ Libraries

* Added the :ref:`lib_ble_radio_notification` library.

* Updated the following libraries to return ``nrf_errors`` instead of ``errnos``:

* :ref:`lib_ble_adv`.
* Updated the following libraries and BLE services to return ``nrf_errors`` instead of ``errnos``:

* :ref:`lib_ble_adv` library.
* :ref:`lib_ble_conn_params` library.
* :ref:`lib_ble_gatt_queue` library.
* :ref:`lib_ble_queued_writes` library.
* :ref:`lib_ble_service_bas` service.
* :ref:`lib_ble_service_dis` service.
* :ref:`lib_ble_service_hrs` service.
* :ref:`lib_ble_service_lbs` service.
* :ref:`lib_ble_service_mcumgr` service.
* :ref:`lib_ble_service_nus` service.
* BLE Record Access Control Point library.

* :ref:`lib_ble_conn_params` library:

Expand Down
Loading