From 0f76967854e7e80552d598510162982eddc08a4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20J=C3=B8lsgard?= Date: Wed, 22 Oct 2025 13:26:47 +0200 Subject: [PATCH 01/12] doc: nrf-bm: changelog: correct backtics for compliance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed a compliance warning. Signed-off-by: Eivind Jølsgard --- doc/nrf-bm/release_notes/release_notes_changelog.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/nrf-bm/release_notes/release_notes_changelog.rst b/doc/nrf-bm/release_notes/release_notes_changelog.rst index 0a36c1bc16..b7e3620bbe 100644 --- a/doc/nrf-bm/release_notes/release_notes_changelog.rst +++ b/doc/nrf-bm/release_notes/release_notes_changelog.rst @@ -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. @@ -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. From 70ee96796e193fc6da7a94951c26498396ca4ce3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20J=C3=B8lsgard?= Date: Wed, 22 Oct 2025 10:55:34 +0200 Subject: [PATCH 02/12] treewide: rename nrf_err and nrfx_err and align success checks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rename nrf error variables from err to nrf_err. Rename nrfx error variables to nrfx_err and use nrfx_err_t type. Align success checks for nrf_errors. Replace (nrf_err != NRF_SUCCESS) with (nrf_err). Signed-off-by: Eivind Jølsgard --- .../firmware_loader/ble_mcumgr/src/main.c | 51 ++- .../libraries/bluetooth/ble_peer_manager.rst | 64 ++-- drivers/bm_lpuarte/lpuarte.c | 132 ++++---- drivers/console/console_bm_uarte.c | 12 +- lib/bluetooth/ble_adv/ble_adv.c | 4 +- lib/bluetooth/ble_gq/gatt_queue.c | 43 +-- lib/bluetooth/ble_qwr/ble_qwr.c | 52 +-- .../peer_manager/include/modules/pm_buffer.h | 8 +- .../modules/auth_status_tracker.c | 22 +- .../peer_manager/modules/gatt_cache_manager.c | 74 ++-- .../modules/gatts_cache_manager.c | 135 ++++---- .../peer_manager/modules/id_manager.c | 30 +- .../peer_manager/modules/nrf_ble_lesc.c | 57 ++-- .../peer_manager/modules/peer_data_storage.c | 16 +- .../peer_manager/modules/peer_database.c | 58 ++-- .../modules/peer_manager_handler.c | 64 ++-- .../modules/security_dispatcher.c | 153 ++++----- .../peer_manager/modules/security_manager.c | 92 +++-- lib/bluetooth/peer_manager/peer_manager.c | 155 ++++----- lib/bm_buttons/bm_buttons.c | 22 +- samples/bluetooth/ble_cgms/src/main.c | 54 +-- .../bluetooth/ble_hids_keyboard/src/main.c | 115 ++++--- samples/bluetooth/ble_hids_mouse/src/main.c | 92 ++--- samples/bluetooth/ble_hrs/src/main.c | 53 +-- samples/bluetooth/ble_lbs/src/main.c | 25 +- samples/bluetooth/ble_nus/src/main.c | 92 ++--- .../bluetooth/ble_pwr_profiling/src/main.c | 139 ++++---- .../boot/mcuboot_recovery_entry/src/main.c | 29 +- samples/peripherals/lpuarte/src/main.c | 41 +-- samples/peripherals/pwm/src/main.c | 8 +- samples/peripherals/uarte/src/main.c | 42 +-- subsys/bluetooth/services/ble_cgms/cgms.c | 84 ++--- .../bluetooth/services/ble_cgms/cgms_meas.c | 18 +- .../bluetooth/services/ble_cgms/cgms_racp.c | 135 ++++---- .../bluetooth/services/ble_cgms/cgms_socp.c | 34 +- subsys/bluetooth/services/ble_cgms/cgms_sst.c | 20 +- subsys/bluetooth/services/ble_hids/hids.c | 318 +++++++++--------- subsys/bluetooth/services/ble_lbs/lbs.c | 26 +- .../logging/backends/log_backend_bm_uarte.c | 8 +- .../mcumgr/transport/src/bm_uart_mcumgr.c | 18 +- subsys/softdevice_handler/nrf_sdh_soc.c | 18 +- tests/lib/bluetooth/ble_adv/src/unity_test.c | 105 +++--- 42 files changed, 1365 insertions(+), 1353 deletions(-) diff --git a/applications/firmware_loader/ble_mcumgr/src/main.c b/applications/firmware_loader/ble_mcumgr/src/main.c index b6f7b9df8f..6dca3dc071 100644 --- a/applications/firmware_loader/ble_mcumgr/src/main.c +++ b/applications/firmware_loader/ble_mcumgr/src/main.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ -#include +#include #include #include #include @@ -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; @@ -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; } @@ -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; @@ -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; @@ -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; @@ -221,10 +220,10 @@ int main(void) 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 */ @@ -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; } diff --git a/doc/nrf-bm/libraries/bluetooth/ble_peer_manager.rst b/doc/nrf-bm/libraries/bluetooth/ble_peer_manager.rst index c5f41cf37d..f6d05f843f 100644 --- a/doc/nrf-bm/libraries/bluetooth/ble_peer_manager.rst +++ b/doc/nrf-bm/libraries/bluetooth/ble_peer_manager.rst @@ -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) { @@ -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 @@ -348,12 +350,12 @@ 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. @@ -361,12 +363,12 @@ The :c:func:`pm_peer_data_store` function can also be used directly, as in the f .. 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 @@ -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; } } @@ -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}; @@ -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; diff --git a/drivers/bm_lpuarte/lpuarte.c b/drivers/bm_lpuarte/lpuarte.c index 6c87860f59..9dfa7eacba 100644 --- a/drivers/bm_lpuarte/lpuarte.c +++ b/drivers/bm_lpuarte/lpuarte.c @@ -79,7 +79,7 @@ static void req_pin_arm(struct bm_lpuarte *lpu) static nrfx_err_t req_pin_init(struct bm_lpuarte *lpu, nrfx_gpiote_pin_t pin) { uint8_t ch; - nrfx_err_t err; + nrfx_err_t nrfx_err; nrf_gpio_pin_pull_t pull_config = NRF_GPIO_PIN_PULLDOWN; nrfx_gpiote_trigger_config_t trigger_config = { .trigger = NRFX_GPIOTE_TRIGGER_HITOLO, @@ -95,14 +95,14 @@ static nrfx_err_t req_pin_init(struct bm_lpuarte *lpu, nrfx_gpiote_pin_t pin) .p_handler_config = &handler_config }; - err = nrfx_gpiote_channel_alloc(gpiote_get(pin), &ch); - if (err != NRFX_SUCCESS) { - return err; + nrfx_err = nrfx_gpiote_channel_alloc(gpiote_get(pin), &ch); + if (nrfx_err != NRFX_SUCCESS) { + return nrfx_err; } - err = nrfx_gpiote_input_configure(gpiote_get(pin), pin, &input_config); - if (err != NRFX_SUCCESS) { - return err; + nrfx_err = nrfx_gpiote_input_configure(gpiote_get(pin), pin, &input_config); + if (nrfx_err != NRFX_SUCCESS) { + return nrfx_err; } lpu->req_pin = pin; @@ -127,7 +127,7 @@ static void rdy_pin_suspend(struct bm_lpuarte *lpu) static nrfx_err_t rdy_pin_init(struct bm_lpuarte *lpu, nrfx_gpiote_pin_t pin) { - nrfx_err_t err; + nrfx_err_t nrfx_err; nrf_gpio_pin_pull_t pull_config = NRF_GPIO_PIN_NOPULL; nrfx_gpiote_handler_config_t handler_config = { .handler = rdy_pin_handler, @@ -139,14 +139,14 @@ static nrfx_err_t rdy_pin_init(struct bm_lpuarte *lpu, nrfx_gpiote_pin_t pin) .p_handler_config = &handler_config }; - err = nrfx_gpiote_channel_alloc(gpiote_get(pin), &lpu->rdy_ch); - if (err != NRFX_SUCCESS) { - return err; + nrfx_err = nrfx_gpiote_channel_alloc(gpiote_get(pin), &lpu->rdy_ch); + if (nrfx_err != NRFX_SUCCESS) { + return nrfx_err; } - err = nrfx_gpiote_input_configure(gpiote_get(pin), pin, &input_config); - if (err != NRFX_SUCCESS) { - return err; + nrfx_err = nrfx_gpiote_input_configure(gpiote_get(pin), pin, &input_config); + if (nrfx_err != NRFX_SUCCESS) { + return nrfx_err; } lpu->rdy_pin = pin; @@ -163,7 +163,7 @@ static void rdy_pin_uninit(struct bm_lpuarte *lpu, nrfx_gpiote_pin_t pin) /* Pin activated to detect high state (using SENSE). */ static void rdy_pin_idle(struct bm_lpuarte *lpu) { - nrfx_err_t err; + nrfx_err_t nrfx_err; nrfx_gpiote_trigger_config_t trigger_config = { .trigger = NRFX_GPIOTE_TRIGGER_HIGH }; @@ -174,8 +174,8 @@ static void rdy_pin_idle(struct bm_lpuarte *lpu) }; const nrfx_gpiote_t *gpiote = gpiote_get(lpu->rdy_pin); - err = nrfx_gpiote_input_configure(gpiote, lpu->rdy_pin, &input_config); - __ASSERT(err == NRFX_SUCCESS, "Unexpected nrfx_err %#x", err); + nrfx_err = nrfx_gpiote_input_configure(gpiote, lpu->rdy_pin, &input_config); + __ASSERT(nrfx_err == NRFX_SUCCESS, "Unexpected nrfx_err %#x", nrfx_err); nrfx_gpiote_trigger_enable(gpiote, lpu->rdy_pin, true); } @@ -189,7 +189,7 @@ static void rdy_pin_idle(struct bm_lpuarte *lpu) */ static bool rdy_pin_blink(struct bm_lpuarte *lpu) { - nrfx_err_t err; + nrfx_err_t nrfx_err; nrfx_gpiote_trigger_config_t trigger_config = { .trigger = NRFX_GPIOTE_TRIGGER_HITOLO, .p_in_channel = &lpu->rdy_ch @@ -207,8 +207,8 @@ static bool rdy_pin_blink(struct bm_lpuarte *lpu) /* Drive low for a moment */ nrf_gpio_reconfigure(lpu->rdy_pin, &dir_out, NULL, NULL, NULL, NULL); - err = nrfx_gpiote_input_configure(gpiote, lpu->rdy_pin, &input_config); - __ASSERT(err == NRFX_SUCCESS, "Unexpected nrfx_err %#x", err); + nrfx_err = nrfx_gpiote_input_configure(gpiote, lpu->rdy_pin, &input_config); + __ASSERT(nrfx_err == NRFX_SUCCESS, "Unexpected nrfx_err %#x", nrfx_err); nrfx_gpiote_trigger_enable(gpiote, lpu->rdy_pin, true); @@ -241,14 +241,14 @@ static bool rdy_pin_blink(struct bm_lpuarte *lpu) /* Set response pin to idle and disable RX. */ static void deactivate_rx(struct bm_lpuarte *lpu) { - nrfx_err_t err; + nrfx_err_t nrfx_err; /* abort rx */ LOG_DBG("RX: Deactivate"); lpu->rx_state = RX_TO_IDLE; - err = nrfx_uarte_rx_abort(&lpu->uarte_inst, true, false); - if (err != NRFX_SUCCESS) { - LOG_ERR("RX: Failed to disable, nrfx_err %#x", err); + nrfx_err = nrfx_uarte_rx_abort(&lpu->uarte_inst, true, false); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("RX: Failed to disable, nrfx_err %#x", nrfx_err); } rdy_pin_idle(lpu); @@ -260,14 +260,14 @@ static void deactivate_rx(struct bm_lpuarte *lpu) */ static void activate_rx(struct bm_lpuarte *lpu) { - nrfx_err_t err; + nrfx_err_t nrfx_err; LOG_DBG("Activating uarte RX"); - err = nrfx_uarte_rx_enable(&lpu->uarte_inst, + nrfx_err = nrfx_uarte_rx_enable(&lpu->uarte_inst, NRFX_UARTE_RX_ENABLE_CONT | NRFX_UARTE_RX_ENABLE_STOP_ON_END); - if (err != NRFX_SUCCESS) { - LOG_ERR("lpuarte rx enable failed, nrfx_err %#x", err); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("lpuarte rx enable failed, nrfx_err %#x", nrfx_err); } lpu->rx_state = RX_ACTIVE; @@ -312,7 +312,7 @@ static void req_pin_handler(nrfx_gpiote_pin_t pin, nrfx_gpiote_trigger_t trigger ARG_UNUSED(pin); const uint8_t *buf; size_t len; - nrfx_err_t err; + nrfx_err_t nrfx_err; struct bm_lpuarte *lpu = context; LOG_DBG("req_pin_evt"); @@ -334,9 +334,9 @@ static void req_pin_handler(nrfx_gpiote_pin_t pin, nrfx_gpiote_trigger_t trigger buf = lpu->tx_buf; len = lpu->tx_len; NRFX_CRITICAL_SECTION_EXIT(); - err = nrfx_uarte_tx(&lpu->uarte_inst, buf, len, 0); - if (err != NRFX_SUCCESS) { - LOG_ERR("TX: Not started, nrfx_err %#x", err); + nrfx_err = nrfx_uarte_tx(&lpu->uarte_inst, buf, len, 0); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("TX: Not started, nrfx_err %#x", nrfx_err); tx_complete(lpu); const nrfx_uarte_event_t tx_done_aborted_evt = { @@ -384,17 +384,17 @@ static void rdy_pin_handler(nrfx_gpiote_pin_t pin, nrfx_gpiote_trigger_t trigger static void tx_timeout(void *context) { - nrfx_err_t err; + nrfx_err_t nrfx_err; struct bm_lpuarte *lpu = context; const uint8_t *buf = lpu->tx_buf; LOG_WRN("TX abort timeout"); if (lpu->tx_active) { - err = nrfx_uarte_tx_abort(&lpu->uarte_inst, true); - if (err == NRFX_ERROR_INVALID_STATE) { + nrfx_err = nrfx_uarte_tx_abort(&lpu->uarte_inst, true); + if (nrfx_err == NRFX_ERROR_INVALID_STATE) { LOG_DBG("No active transfer. Already finished?"); - } else if (err != NRFX_SUCCESS) { - __ASSERT(0, "Unexpected tx_abort, nrfx_err %#x", err); + } else if (nrfx_err != NRFX_SUCCESS) { + __ASSERT(0, "Unexpected tx_abort, nrfx_err %#x", nrfx_err); } return; } @@ -448,7 +448,7 @@ nrfx_err_t bm_lpuarte_init(struct bm_lpuarte *lpu, struct bm_lpuarte_config *lpu_cfg, nrfx_uarte_event_handler_t event_handler) { - nrfx_err_t err; + nrfx_err_t nrfx_err; /* We use the uarte context for storing the pointer to the lpu instance */ lpu_cfg->uarte_cfg.p_context = lpu; @@ -461,42 +461,42 @@ nrfx_err_t bm_lpuarte_init(struct bm_lpuarte *lpu, lpu->callback = event_handler; if (!nrfx_gpiote_init_check(&gpiote20_instance)) { - err = nrfx_gpiote_init(&gpiote20_instance, 0); - if (err != NRFX_SUCCESS) { - LOG_ERR("Failed to initialize gpiote20, nrfx_err: %#x", err); + nrfx_err = nrfx_gpiote_init(&gpiote20_instance, 0); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("Failed to initialize gpiote20, nrfx_err: %#x", nrfx_err); return NRFX_ERROR_INVALID_STATE; } } if (!nrfx_gpiote_init_check(&gpiote30_instance)) { - err = nrfx_gpiote_init(&gpiote30_instance, 0); - if (err != NRFX_SUCCESS) { - LOG_ERR("Failed to initialize gpiote30, nrfx_err: %#x", err); + nrfx_err = nrfx_gpiote_init(&gpiote30_instance, 0); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("Failed to initialize gpiote30, nrfx_err: %#x", nrfx_err); return NRFX_ERROR_INVALID_STATE; } } - err = req_pin_init(lpu, lpu_cfg->req_pin); - if (err < 0) { - LOG_ERR("req pin init failed, nrfx_err %#x", err); - return err; + nrfx_err = req_pin_init(lpu, lpu_cfg->req_pin); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("req pin init failed, nrfx_err %#x", nrfx_err); + return nrfx_err; } - err = rdy_pin_init(lpu, lpu_cfg->rdy_pin); - if (err < 0) { - LOG_ERR("rdy pin init failed, nrfx_err %#x", err); - return err; + nrfx_err = rdy_pin_init(lpu, lpu_cfg->rdy_pin); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("rdy pin init failed, nrfx_err %#x", nrfx_err); + return nrfx_err; } bm_timer_init(&lpu->tx_timer, BM_TIMER_MODE_SINGLE_SHOT, tx_timeout); - err = nrfx_uarte_init(&lpu->uarte_inst, &lpu_cfg->uarte_cfg, nrfx_uarte_evt_handler); - if (err != NRFX_SUCCESS) { - LOG_ERR("Failed to initialize UARTE, nrfx_err %#x", err); - return err; + nrfx_err = nrfx_uarte_init(&lpu->uarte_inst, &lpu_cfg->uarte_cfg, nrfx_uarte_evt_handler); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("Failed to initialize UARTE, nrfx_err %#x", nrfx_err); + return nrfx_err; } - return err; + return nrfx_err; } void bm_lpuarte_uninit(struct bm_lpuarte *lpu) @@ -544,7 +544,7 @@ bool bm_lpuarte_tx_in_progress(struct bm_lpuarte *lpu) nrfx_err_t bm_lpuarte_tx_abort(struct bm_lpuarte *lpu, bool sync) { - nrfx_err_t err; + nrfx_err_t nrfx_err; const uint8_t *buf = lpu->tx_buf; if (!lpu) { @@ -559,10 +559,10 @@ nrfx_err_t bm_lpuarte_tx_abort(struct bm_lpuarte *lpu, bool sync) tx_complete(lpu); NRFX_CRITICAL_SECTION_EXIT(); - err = nrfx_uarte_tx_abort(&lpu->uarte_inst, sync); - if (err == NRFX_ERROR_INVALID_STATE && !sync) { + nrfx_err = nrfx_uarte_tx_abort(&lpu->uarte_inst, sync); + if (nrfx_err == NRFX_ERROR_INVALID_STATE && !sync) { /* If abort is before TX is started we report ABORT from here. */ - err = NRFX_SUCCESS; + nrfx_err = NRFX_SUCCESS; const nrfx_uarte_event_t tx_done_aborted_evt = { .type = NRFX_UARTE_EVT_TX_DONE, @@ -576,7 +576,7 @@ nrfx_err_t bm_lpuarte_tx_abort(struct bm_lpuarte *lpu, bool sync) lpu->callback(&tx_done_aborted_evt, lpu); } - return err; + return nrfx_err; } nrfx_err_t bm_lpuarte_rx_enable(struct bm_lpuarte *lpu) @@ -599,15 +599,15 @@ nrfx_err_t bm_lpuarte_rx_buffer_set(struct bm_lpuarte *lpu, nrfx_err_t bm_lpuarte_rx_abort(struct bm_lpuarte *lpu, bool sync) { - nrfx_err_t err; + nrfx_err_t nrfx_err; if (lpu->rx_state == RX_OFF) { return NRFX_ERROR_INVALID_STATE; } lpu->rx_state = RX_TO_OFF; - err = nrfx_uarte_rx_abort(&lpu->uarte_inst, true, sync); - if (err == NRFX_ERROR_INVALID_STATE || sync) { + nrfx_err = nrfx_uarte_rx_abort(&lpu->uarte_inst, true, sync); + if (nrfx_err == NRFX_ERROR_INVALID_STATE || sync) { lpu->rx_state = RX_OFF; rdy_pin_idle(lpu); @@ -627,5 +627,5 @@ nrfx_err_t bm_lpuarte_rx_abort(struct bm_lpuarte *lpu, bool sync) } } - return err; + return nrfx_err; } diff --git a/drivers/console/console_bm_uarte.c b/drivers/console/console_bm_uarte.c index 57c3600723..59204405d2 100644 --- a/drivers/console/console_bm_uarte.c +++ b/drivers/console/console_bm_uarte.c @@ -19,9 +19,9 @@ ISR_DIRECT_DECLARE(console_bm_uarte_direct_isr) return 0; } -static int uarte_init(void) +static nrfx_err_t uarte_init(void) { - int err; + nrfx_err_t nrfx_err; nrfx_uarte_config_t uarte_config = NRFX_UARTE_DEFAULT_CONFIG( BOARD_CONSOLE_UARTE_PIN_TX, NRF_UARTE_PSEL_DISCONNECTED); @@ -45,12 +45,12 @@ static int uarte_init(void) irq_enable(NRFX_IRQ_NUMBER_GET(NRF_UARTE_INST_GET(BOARD_CONSOLE_UARTE_INST))); - err = nrfx_uarte_init(&uarte_inst, &uarte_config, NULL); - if (err != NRFX_SUCCESS) { - return err; + nrfx_err = nrfx_uarte_init(&uarte_inst, &uarte_config, NULL); + if (nrfx_err != NRFX_SUCCESS) { + return nrfx_err; } - return 0; + return NRFX_SUCCESS; } static int console_out(int c) diff --git a/lib/bluetooth/ble_adv/ble_adv.c b/lib/bluetooth/ble_adv/ble_adv.c index f9a668a16c..8c12154fb7 100644 --- a/lib/bluetooth/ble_adv/ble_adv.c +++ b/lib/bluetooth/ble_adv/ble_adv.c @@ -391,7 +391,7 @@ uint32_t ble_adv_start(struct ble_adv *ble_adv, enum ble_adv_mode mode) adv_evt.evt_type = BLE_ADV_EVT_FAST; nrf_err = set_adv_mode_fast(ble_adv, &ble_adv->adv_params); if (nrf_err) { - LOG_ERR("Failed to set fast advertising params, error: %d", + LOG_ERR("Failed to set fast advertising params, nrf_error %#x", nrf_err); return NRF_ERROR_INVALID_PARAM; } @@ -405,7 +405,7 @@ uint32_t ble_adv_start(struct ble_adv *ble_adv, enum ble_adv_mode mode) adv_evt.evt_type = BLE_ADV_EVT_SLOW; nrf_err = set_adv_mode_slow(ble_adv, &ble_adv->adv_params); if (nrf_err) { - LOG_ERR("Failed to set slow advertising params, error: %d", + LOG_ERR("Failed to set slow advertising params, nrf_error %#x", nrf_err); return NRF_ERROR_INVALID_PARAM; } diff --git a/lib/bluetooth/ble_gq/gatt_queue.c b/lib/bluetooth/ble_gq/gatt_queue.c index 1c655c0276..95d0e62b3c 100644 --- a/lib/bluetooth/ble_gq/gatt_queue.c +++ b/lib/bluetooth/ble_gq/gatt_queue.c @@ -103,16 +103,17 @@ static const req_data_store_t req_data_store[BLE_GQ_REQ_NUM] = { [BLE_GQ_REQ_GATTS_HVX] = gatts_hvx_store, }; -static void request_error_handle(const struct ble_gq_req *req, uint16_t conn_handle, uint32_t err) +static void request_error_handle(const struct ble_gq_req *req, uint16_t conn_handle, + uint32_t nrf_err) { - if (err == NRF_SUCCESS) { + if (nrf_err == NRF_SUCCESS) { LOG_DBG("SD GATT procedure (%d) succeeded on connection handle: %d.", req->type, conn_handle); } else { LOG_DBG("SD GATT procedure (%d) failed on connection handle %d with nrf_error %#x", - req->type, conn_handle, err); + req->type, conn_handle, nrf_err); if (req->error_handler.cb != NULL) { - req->error_handler.cb(conn_handle, err, req->error_handler.ctx); + req->error_handler.cb(conn_handle, nrf_err, req->error_handler.ctx); } } } @@ -120,61 +121,61 @@ static void request_error_handle(const struct ble_gq_req *req, uint16_t conn_han /* Process a single GATT request. */ static bool request_process(const struct ble_gq_req *req, uint16_t conn_handle) { - uint32_t err_code; + uint32_t nrf_err; uint16_t len; switch (req->type) { case BLE_GQ_REQ_GATTC_READ: LOG_DBG("GATTC read request"); - err_code = sd_ble_gattc_read(conn_handle, req->gattc_read.handle, - req->gattc_read.offset); + nrf_err = sd_ble_gattc_read(conn_handle, req->gattc_read.handle, + req->gattc_read.offset); break; case BLE_GQ_REQ_GATTC_WRITE: LOG_DBG("GATTC write request"); - err_code = sd_ble_gattc_write(conn_handle, &req->gattc_write); + nrf_err = sd_ble_gattc_write(conn_handle, &req->gattc_write); break; case BLE_GQ_REQ_SRV_DISCOVERY: LOG_DBG("GATTC primary services discovery request"); - err_code = sd_ble_gattc_primary_services_discover(conn_handle, - req->gattc_srv_disc.start_handle, - &req->gattc_srv_disc.srvc_uuid); + nrf_err = sd_ble_gattc_primary_services_discover(conn_handle, + req->gattc_srv_disc.start_handle, + &req->gattc_srv_disc.srvc_uuid); break; case BLE_GQ_REQ_CHAR_DISCOVERY: LOG_DBG("GATTC characteristics discovery request"); - err_code = sd_ble_gattc_characteristics_discover(conn_handle, - &req->gattc_char_disc); + nrf_err = sd_ble_gattc_characteristics_discover(conn_handle, + &req->gattc_char_disc); break; case BLE_GQ_REQ_DESC_DISCOVERY: LOG_DBG("GATTC characteristic descriptors discovery request"); - err_code = sd_ble_gattc_descriptors_discover(conn_handle, &req->gattc_desc_disc); + nrf_err = sd_ble_gattc_descriptors_discover(conn_handle, &req->gattc_desc_disc); break; case BLE_GQ_REQ_GATTS_HVX: LOG_DBG("GATTS notification or indication"); if (!req->gatts_hvx.p_len) { LOG_DBG("GATTS HVX request p_len is NULL"); - err_code = NRF_ERROR_INVALID_PARAM; + nrf_err = NRF_ERROR_INVALID_PARAM; break; } len = *(req->gatts_hvx.p_len); - err_code = sd_ble_gatts_hvx(conn_handle, &req->gatts_hvx); - if (err_code == NRF_SUCCESS && len != *(req->gatts_hvx.p_len)) { - err_code = NRF_ERROR_DATA_SIZE; + nrf_err = sd_ble_gatts_hvx(conn_handle, &req->gatts_hvx); + if (nrf_err == NRF_SUCCESS && len != *(req->gatts_hvx.p_len)) { + nrf_err = NRF_ERROR_DATA_SIZE; } break; default: - err_code = NRF_ERROR_NOT_SUPPORTED; + nrf_err = NRF_ERROR_NOT_SUPPORTED; LOG_WRN("Unimplemented GATT request with type: %d", req->type); break; } - if (err_code == NRF_ERROR_BUSY) { + if (nrf_err == NRF_ERROR_BUSY) { LOG_DBG("SD is currently busy. The GATT procedure will be attempted again later."); /* SoftDevice was busy. */ return false; } - request_error_handle(req, conn_handle, err_code); + request_error_handle(req, conn_handle, nrf_err); /* Request was accepted by SoftDevice. */ return true; diff --git a/lib/bluetooth/ble_qwr/ble_qwr.c b/lib/bluetooth/ble_qwr/ble_qwr.c index 32ed745917..9a188107ff 100644 --- a/lib/bluetooth/ble_qwr/ble_qwr.c +++ b/lib/bluetooth/ble_qwr/ble_qwr.c @@ -145,23 +145,23 @@ int ble_qwr_conn_handle_assign(struct ble_qwr *qwr, uint16_t conn_handle) */ static void user_mem_reply(struct ble_qwr *qwr) { - int err; + uint32_t nrf_err; struct ble_qwr_evt evt; if (qwr->is_user_mem_reply_pending) { #if (CONFIG_BLE_QWR_MAX_ATTR == 0) - err = sd_ble_user_mem_reply(qwr->conn_handle, NULL); + nrf_err = sd_ble_user_mem_reply(qwr->conn_handle, NULL); #else - err = sd_ble_user_mem_reply(qwr->conn_handle, - (ble_user_mem_block_t const *)&qwr->mem_buffer); + nrf_err = sd_ble_user_mem_reply( + qwr->conn_handle, (ble_user_mem_block_t const *)&qwr->mem_buffer); #endif - if (err == NRF_SUCCESS) { + if (nrf_err == NRF_SUCCESS) { qwr->is_user_mem_reply_pending = false; - } else if (err == NRF_ERROR_BUSY) { + } else if (nrf_err == NRF_ERROR_BUSY) { qwr->is_user_mem_reply_pending = true; } else { evt.evt_type = BLE_QWR_EVT_ERROR; - evt.error.reason = err; + evt.error.reason = nrf_err; /* Report error to application. */ (void)qwr->evt_handler(qwr, &evt); } @@ -209,7 +209,7 @@ static void on_user_mem_release(struct ble_qwr *qwr, ble_common_evt_t const *evt */ static void on_prepare_write(struct ble_qwr *qwr, ble_gatts_evt_write_t const *write_evt) { - int err; + uint32_t nrf_err; ble_gatts_rw_authorize_reply_params_t auth_reply = {0}; struct ble_qwr_evt evt = {0}; @@ -236,13 +236,13 @@ static void on_prepare_write(struct ble_qwr *qwr, ble_gatts_evt_write_t const *w } } - err = sd_ble_gatts_rw_authorize_reply(qwr->conn_handle, &auth_reply); - if (err != NRF_SUCCESS) { + nrf_err = sd_ble_gatts_rw_authorize_reply(qwr->conn_handle, &auth_reply); + if (nrf_err) { /* Cancel the current operation. */ qwr->nb_written_handles = 0; evt.evt_type = BLE_QWR_EVT_ERROR; - evt.error.reason = err; + evt.error.reason = nrf_err; /* Report error to application. */ (void)qwr->evt_handler(qwr, &evt); } @@ -256,7 +256,7 @@ static void on_prepare_write(struct ble_qwr *qwr, ble_gatts_evt_write_t const *w */ static void on_execute_write(struct ble_qwr *qwr, ble_gatts_evt_write_t const *write_evt) { - uint32_t err; + uint32_t nrf_err; uint16_t ret_val; ble_gatts_rw_authorize_reply_params_t auth_reply = {0}; struct ble_qwr_evt evt; @@ -266,10 +266,10 @@ static void on_execute_write(struct ble_qwr *qwr, ble_gatts_evt_write_t const *w if (qwr->nb_written_handles == 0) { auth_reply.params.write.gatt_status = BLE_QWR_REJ_REQUEST_ERR_CODE; - err = sd_ble_gatts_rw_authorize_reply(qwr->conn_handle, &auth_reply); - if (err != NRF_SUCCESS) { + nrf_err = sd_ble_gatts_rw_authorize_reply(qwr->conn_handle, &auth_reply); + if (nrf_err) { evt.evt_type = BLE_QWR_EVT_ERROR; - evt.error.reason = err; + evt.error.reason = nrf_err; /* Report error to application. */ (void)qwr->evt_handler(qwr, &evt); } @@ -286,10 +286,10 @@ static void on_execute_write(struct ble_qwr *qwr, ble_gatts_evt_write_t const *w } } - err = sd_ble_gatts_rw_authorize_reply(qwr->conn_handle, &auth_reply); - if (err != NRF_SUCCESS) { + nrf_err = sd_ble_gatts_rw_authorize_reply(qwr->conn_handle, &auth_reply); + if (nrf_err) { evt.evt_type = BLE_QWR_EVT_ERROR; - evt.error.reason = err; + evt.error.reason = nrf_err; /* Report error to application. */ (void)qwr->evt_handler(qwr, &evt); } @@ -318,17 +318,17 @@ static void on_execute_write(struct ble_qwr *qwr, ble_gatts_evt_write_t const *w */ static void on_cancel_write(struct ble_qwr *qwr, ble_gatts_evt_write_t const *write_evt) { - uint32_t err; + uint32_t nrf_err; ble_gatts_rw_authorize_reply_params_t auth_reply = {0}; struct ble_qwr_evt evt; auth_reply.type = BLE_GATTS_AUTHORIZE_TYPE_WRITE; auth_reply.params.write.gatt_status = BLE_GATT_STATUS_SUCCESS; - err = sd_ble_gatts_rw_authorize_reply(qwr->conn_handle, &auth_reply); - if (err != NRF_SUCCESS) { + nrf_err = sd_ble_gatts_rw_authorize_reply(qwr->conn_handle, &auth_reply); + if (nrf_err) { evt.evt_type = BLE_QWR_EVT_ERROR; - evt.error.reason = err; + evt.error.reason = nrf_err; /* Report error to application. */ (void)qwr->evt_handler(qwr, &evt); } @@ -345,7 +345,7 @@ static void on_cancel_write(struct ble_qwr *qwr, ble_gatts_evt_write_t const *wr static void on_rw_authorize_request(struct ble_qwr *qwr, ble_gatts_evt_t const *evt) { #if (CONFIG_BLE_QWR_MAX_ATTR == 0) - uint32_t err; + uint32_t nrf_err; ble_gatts_rw_authorize_reply_params_t auth_reply = {0}; struct ble_qwr_evt qwr_evt = {0}; #endif @@ -376,10 +376,10 @@ static void on_rw_authorize_request(struct ble_qwr *qwr, ble_gatts_evt_t const * auth_reply.params.write.gatt_status = BLE_GATT_STATUS_SUCCESS; } - err = sd_ble_gatts_rw_authorize_reply(evt->conn_handle, &auth_reply); - if (err != NRF_SUCCESS) { + nrf_err = sd_ble_gatts_rw_authorize_reply(evt->conn_handle, &auth_reply); + if (nrf_err) { qwr_evt.evt_type = BLE_QWR_EVT_ERROR; - qwr_evt.error.reason = err; + qwr_evt.error.reason = nrf_err; /* Report error to application. */ (void)qwr->evt_handler(qwr, &qwr_evt); } diff --git a/lib/bluetooth/peer_manager/include/modules/pm_buffer.h b/lib/bluetooth/peer_manager/include/modules/pm_buffer.h index 6571646c4a..78142db821 100644 --- a/lib/bluetooth/peer_manager/include/modules/pm_buffer.h +++ b/lib/bluetooth/peer_manager/include/modules/pm_buffer.h @@ -29,14 +29,14 @@ extern "C" { * @param[out] buffer The buffer instance to initialize. * @param[in] n_blocks The desired number of blocks in the buffer. * @param[in] block_size The desired block size of the buffer. - * @param[out] err_code The return code from @ref pm_buffer_init. + * @param[out] nrf_err The return code from @ref pm_buffer_init. */ -#define PM_BUFFER_INIT(buffer, n_blocks, block_size, err_code) \ +#define PM_BUFFER_INIT(buffer, n_blocks, block_size, nrf_err) \ do { \ __ALIGN(4) static uint8_t buffer_memory[(n_blocks) * (block_size)]; \ static atomic_t mutex_memory[(n_blocks - 1) / (sizeof(atomic_t) * 8) + 1]; \ - err_code = pm_buffer_init((buffer), buffer_memory, (n_blocks) * (block_size), \ - mutex_memory, (n_blocks), (block_size)); \ + nrf_err = pm_buffer_init((buffer), buffer_memory, (n_blocks) * (block_size), \ + mutex_memory, (n_blocks), (block_size)); \ } while (0) struct pm_buffer { diff --git a/lib/bluetooth/peer_manager/modules/auth_status_tracker.c b/lib/bluetooth/peer_manager/modules/auth_status_tracker.c index f1fd1a0f70..5230e40d11 100644 --- a/lib/bluetooth/peer_manager/modules/auth_status_tracker.c +++ b/lib/bluetooth/peer_manager/modules/auth_status_tracker.c @@ -149,9 +149,9 @@ static void blacklisted_peers_state_transition_handle(void *context) uint32_t ast_init(void) { - int err_code = bm_timer_init(&pairing_attempt_timer, BM_TIMER_MODE_SINGLE_SHOT, - blacklisted_peers_state_transition_handle); - if (err_code) { + int err = bm_timer_init(&pairing_attempt_timer, BM_TIMER_MODE_SINGLE_SHOT, + blacklisted_peers_state_transition_handle); + if (err) { return NRF_ERROR_INTERNAL; } @@ -161,18 +161,18 @@ uint32_t ast_init(void) void ast_auth_error_notify(uint16_t conn_handle) { int err; - uint32_t err_code; + uint32_t nrf_err; ble_gap_addr_t peer_addr; uint32_t new_timeout; uint32_t free_id = ARRAY_SIZE(blacklisted_peers); bool new_bl_entry = true; /* Get the peer address associated with connection handle. */ - err_code = im_ble_addr_get(conn_handle, &peer_addr); - if (err_code != NRF_SUCCESS) { + nrf_err = im_ble_addr_get(conn_handle, &peer_addr); + if (nrf_err) { LOG_WRN("im_ble_addr_get() returned %s. conn_handle: %d. " "Link was likely disconnected.", - nrf_strerror_get(err_code), conn_handle); + nrf_strerror_get(nrf_err), conn_handle); return; } @@ -251,14 +251,14 @@ void ast_auth_error_notify(uint16_t conn_handle) bool ast_peer_blacklisted(uint16_t conn_handle) { - uint32_t err_code; + uint32_t nrf_err; ble_gap_addr_t peer_addr; - err_code = im_ble_addr_get(conn_handle, &peer_addr); - if (err_code != NRF_SUCCESS) { + nrf_err = im_ble_addr_get(conn_handle, &peer_addr); + if (nrf_err) { LOG_WRN("im_ble_addr_get() returned %s. conn_handle: %d. " "Link was likely disconnected.", - nrf_strerror_get(err_code), conn_handle); + nrf_strerror_get(nrf_err), conn_handle); return true; } diff --git a/lib/bluetooth/peer_manager/modules/gatt_cache_manager.c b/lib/bluetooth/peer_manager/modules/gatt_cache_manager.c index fef8ef1f03..a920c7d261 100644 --- a/lib/bluetooth/peer_manager/modules/gatt_cache_manager.c +++ b/lib/bluetooth/peer_manager/modules/gatt_cache_manager.c @@ -118,15 +118,15 @@ static bool cccd_written(const ble_gatts_evt_write_t *write_evt) * @brief Function for sending an PM_EVT_ERROR_UNEXPECTED event. * * @param[in] conn_handle The connection handle the event pertains to. - * @param[in] err_code The unexpected error that occurred. + * @param[in] nrf_err The unexpected error that occurred. */ -static void send_unexpected_error(uint16_t conn_handle, uint32_t err_code) +static void send_unexpected_error(uint16_t conn_handle, uint32_t nrf_err) { struct pm_evt error_evt = { .evt_id = PM_EVT_ERROR_UNEXPECTED, .conn_handle = conn_handle, .params.error_unexpected = { - .error = err_code, + .error = nrf_err, }, }; @@ -145,7 +145,7 @@ static void send_unexpected_error(uint16_t conn_handle, uint32_t err_code) static void local_db_apply_in_evt(uint16_t conn_handle) { bool set_procedure_as_pending = false; - uint32_t err_code; + uint32_t nrf_err; struct pm_evt event = { .conn_handle = conn_handle, }; @@ -154,9 +154,9 @@ static void local_db_apply_in_evt(uint16_t conn_handle) return; } - err_code = gscm_local_db_cache_apply(conn_handle); + nrf_err = gscm_local_db_cache_apply(conn_handle); - switch (err_code) { + switch (nrf_err) { case NRF_SUCCESS: event.evt_id = PM_EVT_LOCAL_DB_CACHE_APPLIED; @@ -183,8 +183,8 @@ static void local_db_apply_in_evt(uint16_t conn_handle) default: LOG_ERR("gscm_local_db_cache_apply() returned %s which should not happen. " "conn_handle: %d", - nrf_strerror_get(err_code), conn_handle); - send_unexpected_error(conn_handle, err_code); + nrf_strerror_get(nrf_err), conn_handle); + send_unexpected_error(conn_handle, nrf_err); break; } @@ -218,9 +218,9 @@ static bool local_db_update_in_evt(uint16_t conn_handle) { bool set_procedure_as_pending = false; bool success = false; - uint32_t err_code = gscm_local_db_cache_update(conn_handle); + uint32_t nrf_err = gscm_local_db_cache_update(conn_handle); - switch (err_code) { + switch (nrf_err) { case NRF_SUCCESS: success = true; break; @@ -248,8 +248,8 @@ static bool local_db_update_in_evt(uint16_t conn_handle) default: LOG_ERR("gscm_local_db_cache_update() returned %s for conn_handle: %d", - nrf_strerror_get(err_code), conn_handle); - send_unexpected_error(conn_handle, err_code); + nrf_strerror_get(nrf_err), conn_handle); + send_unexpected_error(conn_handle, nrf_err); break; } @@ -275,17 +275,17 @@ static uint32_t service_changed_cccd(uint16_t conn_handle, uint16_t *cccd) bool sc_found = false; uint16_t end_handle; - uint32_t err_code = sd_ble_gatts_initial_user_handle_get(&end_handle); + uint32_t nrf_err = sd_ble_gatts_initial_user_handle_get(&end_handle); - __ASSERT_NO_MSG(err_code == NRF_SUCCESS); + __ASSERT_NO_MSG(nrf_err == NRF_SUCCESS); for (uint16_t handle = 1; handle < end_handle; handle++) { ble_uuid_t uuid; ble_gatts_value_t value = {.p_value = (uint8_t *)&uuid.uuid, .len = 2, .offset = 0}; - err_code = sd_ble_gatts_attr_get(handle, &uuid, NULL); - if (err_code != NRF_SUCCESS) { - return err_code; + nrf_err = sd_ble_gatts_attr_get(handle, &uuid, NULL); + if (nrf_err) { + return nrf_err; } else if (!sc_found && (uuid.uuid == BLE_UUID_GATT_CHARACTERISTIC_SERVICE_CHANGED)) { sc_found = true; @@ -310,9 +310,9 @@ static void service_changed_send_in_evt(uint16_t conn_handle) { bool sc_pending_state = true; bool sc_sent_state = false; - uint32_t err_code = gscm_service_changed_ind_send(conn_handle); + uint32_t nrf_err = gscm_service_changed_ind_send(conn_handle); - switch (err_code) { + switch (nrf_err) { case NRF_SUCCESS: { struct pm_evt event = { .evt_id = PM_EVT_SERVICE_CHANGED_IND_SENT, @@ -332,16 +332,16 @@ static void service_changed_send_in_evt(uint16_t conn_handle) case NRF_ERROR_INVALID_STATE: { uint16_t cccd; - err_code = service_changed_cccd(conn_handle, &cccd); - if ((err_code == NRF_SUCCESS) && cccd) { + nrf_err = service_changed_cccd(conn_handle, &cccd); + if ((nrf_err == NRF_SUCCESS) && cccd) { /* Possible ATT_MTU exchange ongoing. */ /* Do nothing, treat as busy. */ break; } - if (err_code != NRF_SUCCESS) { + if (nrf_err) { LOG_DBG("Unexpected error when looking for service changed " "CCCD: %s", - nrf_strerror_get(err_code)); + nrf_strerror_get(nrf_err)); } /* CCCDs not enabled or an error happened. Drop indication. */ /* Fallthrough. */ @@ -363,8 +363,8 @@ static void service_changed_send_in_evt(uint16_t conn_handle) default: LOG_ERR("gscm_service_changed_ind_send() returned %s for conn_handle: %d", - nrf_strerror_get(err_code), conn_handle); - send_unexpected_error(conn_handle, err_code); + nrf_strerror_get(nrf_err), conn_handle); + send_unexpected_error(conn_handle, nrf_err); break; } @@ -436,10 +436,10 @@ static void car_update_pending_handle(uint16_t conn_handle, void *context) const ble_gattc_handle_range_t car_handle_range = {1, 0xFFFF}; - uint32_t err_code = + uint32_t nrf_err = sd_ble_gattc_char_value_by_uuid_read(conn_handle, &car_uuid, &car_handle_range); - if (err_code == NRF_SUCCESS) { + if (nrf_err == NRF_SUCCESS) { ble_conn_state_user_flag_set(conn_handle, flag_car_handle_queried, true); } } @@ -514,18 +514,18 @@ void gcm_pdb_evt_handler(struct pm_evt *event) #if defined(CONFIG_PM_SERVICE_CHANGED) case PM_PEER_DATA_ID_SERVICE_CHANGED_PENDING: { - uint32_t err_code; + uint32_t nrf_err; bool service_changed_pending = false; uint32_t service_changed_pending_size = sizeof(bool); struct pm_peer_data peer_data; peer_data.all_data = &service_changed_pending; - err_code = pds_peer_data_read(event->peer_id, - PM_PEER_DATA_ID_SERVICE_CHANGED_PENDING, - &peer_data, &service_changed_pending_size); + nrf_err = pds_peer_data_read(event->peer_id, + PM_PEER_DATA_ID_SERVICE_CHANGED_PENDING, + &peer_data, &service_changed_pending_size); - if (err_code == NRF_SUCCESS) { + if (nrf_err == NRF_SUCCESS) { if (service_changed_pending) { uint16_t conn_handle = im_conn_handle_get(event->peer_id); @@ -602,12 +602,12 @@ void store_car_value(uint16_t conn_handle, bool car_value) ble_conn_state_user_flag_set(conn_handle, flag_car_update_pending, false); peer_data.central_addr_res = car_value ? &car_value_true : &car_value_false; - uint32_t err_code = + uint32_t nrf_err = pds_peer_data_store(im_peer_id_get_by_conn_handle(conn_handle), &peer_data, NULL); - if (err_code != NRF_SUCCESS) { + if (nrf_err) { LOG_WRN("CAR char value couldn't be stored (error: %s). Reattempt will " "happen on the next connection.", - nrf_strerror_get(err_code)); + nrf_strerror_get(nrf_err)); } } @@ -680,10 +680,10 @@ void gcm_ble_evt_handler(const ble_evt_t *ble_evt) val->value_len); /* Store 0. */ } else { - uint32_t err_code = sd_ble_gattc_read( + uint32_t nrf_err = sd_ble_gattc_read( conn_handle, *(uint16_t *)val->handle_value, 0); - if (err_code == NRF_SUCCESS) { + if (nrf_err == NRF_SUCCESS) { handle_found = true; ble_conn_state_user_flag_set( conn_handle, flag_car_value_queried, true); diff --git a/lib/bluetooth/peer_manager/modules/gatts_cache_manager.c b/lib/bluetooth/peer_manager/modules/gatts_cache_manager.c index 1abd16a5e1..e9115d8be5 100644 --- a/lib/bluetooth/peer_manager/modules/gatts_cache_manager.c +++ b/lib/bluetooth/peer_manager/modules/gatts_cache_manager.c @@ -74,7 +74,7 @@ static void service_changed_pending_set(void) { __ASSERT_NO_MSG(module_initialized); - uint32_t err_code; + uint32_t nrf_err; /* Use a uint32_t to enforce 4-byte alignment. */ static const uint32_t service_changed_pending = true; @@ -85,23 +85,23 @@ static void service_changed_pending_set(void) }; while (current_sc_store_peer_id != PM_PEER_ID_INVALID) { - err_code = pds_peer_data_store(current_sc_store_peer_id, &peer_data, NULL); - if (err_code != NRF_SUCCESS) { + nrf_err = pds_peer_data_store(current_sc_store_peer_id, &peer_data, NULL); + if (nrf_err) { struct pm_evt evt = {.peer_id = current_sc_store_peer_id}; - if (err_code == NRF_ERROR_BUSY) { + if (nrf_err == NRF_ERROR_BUSY) { /* Do nothing. */ - } else if (err_code == NRF_ERROR_RESOURCES) { + } else if (nrf_err == NRF_ERROR_RESOURCES) { evt.evt_id = PM_EVT_STORAGE_FULL; evt_send(&evt); } else { LOG_ERR("pds_peer_data_store() returned %s while storing " "service changed " "state for peer id %d.", - nrf_strerror_get(err_code), + nrf_strerror_get(nrf_err), current_sc_store_peer_id); evt.evt_id = PM_EVT_ERROR_UNEXPECTED; - evt.params.error_unexpected.error = err_code; + evt.params.error_unexpected.error = nrf_err; evt_send(&evt); } break; @@ -140,7 +140,7 @@ uint32_t gscm_local_db_cache_update(uint16_t conn_handle) __ASSERT_NO_MSG(module_initialized); uint16_t peer_id = im_peer_id_get_by_conn_handle(conn_handle); - uint32_t err_code; + uint32_t nrf_err; if (peer_id == PM_PEER_ID_INVALID) { return BLE_ERROR_INVALID_CONN_HANDLE; @@ -153,19 +153,19 @@ uint32_t gscm_local_db_cache_update(uint16_t conn_handle) do { retry_with_bigger_buffer = false; - err_code = pdb_write_buf_get(peer_id, PM_PEER_DATA_ID_GATT_LOCAL, n_bufs++, - &peer_data); - if (err_code == NRF_SUCCESS) { + nrf_err = pdb_write_buf_get(peer_id, PM_PEER_DATA_ID_GATT_LOCAL, n_bufs++, + &peer_data); + if (nrf_err == NRF_SUCCESS) { struct pm_peer_data_local_gatt_db *local_gatt_db = peer_data.local_gatt_db; local_gatt_db->flags = SYS_ATTR_BOTH; - err_code = sd_ble_gatts_sys_attr_get( + nrf_err = sd_ble_gatts_sys_attr_get( conn_handle, &local_gatt_db->data[0], &local_gatt_db->len, local_gatt_db->flags); - if (err_code == NRF_SUCCESS) { + if (nrf_err == NRF_SUCCESS) { uint8_t local_gatt_db_buf[PM_PEER_DATA_LOCAL_GATT_DB_MAX_SIZE] = { 0 }; @@ -176,35 +176,35 @@ uint32_t gscm_local_db_cache_update(uint16_t conn_handle) curr_peer_data.all_data = local_gatt_db_buf; - err_code = pds_peer_data_read(peer_id, - PM_PEER_DATA_ID_GATT_LOCAL, - &curr_peer_data, - &local_gatt_db_size); + nrf_err = pds_peer_data_read(peer_id, + PM_PEER_DATA_ID_GATT_LOCAL, + &curr_peer_data, + &local_gatt_db_size); - if ((err_code != NRF_SUCCESS) && - (err_code != NRF_ERROR_NOT_FOUND)) { + if ((nrf_err != NRF_SUCCESS) && + (nrf_err != NRF_ERROR_NOT_FOUND)) { LOG_ERR("pds_peer_data_read() returned %s " "for conn_handle: %d", - nrf_strerror_get(err_code), + nrf_strerror_get(nrf_err), conn_handle); return NRF_ERROR_INTERNAL; } - if ((err_code == NRF_ERROR_NOT_FOUND) || + if ((nrf_err == NRF_ERROR_NOT_FOUND) || (local_gatt_db->len != curr_local_gatt_db->len) || (memcmp(local_gatt_db->data, curr_local_gatt_db->data, local_gatt_db->len) != 0)) { - err_code = pdb_write_buf_store( - peer_id, PM_PEER_DATA_ID_GATT_LOCAL, - peer_id); + nrf_err = pdb_write_buf_store(peer_id, + PM_PEER_DATA_ID_GATT_LOCAL, + peer_id); } else { LOG_DBG("Local db is already up to date, " "skipping write."); - uint32_t err_code_release = pdb_write_buf_release( + uint32_t nrf_err_release = pdb_write_buf_release( peer_id, PM_PEER_DATA_ID_GATT_LOCAL); - if (err_code_release == NRF_SUCCESS) { - err_code = NRF_ERROR_INVALID_DATA; + if (nrf_err_release == NRF_SUCCESS) { + nrf_err = NRF_ERROR_INVALID_DATA; } else { LOG_ERR("Did another thread manipulate " "PM_PEER_DATA_ID_GATT_LOCAL for " @@ -212,43 +212,43 @@ uint32_t gscm_local_db_cache_update(uint16_t conn_handle) "pdb_write_buf_release() returned " "%s.", peer_id, - nrf_strerror_get(err_code_release)); - err_code = NRF_ERROR_INTERNAL; + nrf_strerror_get(nrf_err_release)); + nrf_err = NRF_ERROR_INTERNAL; } } } else { - if (err_code == NRF_ERROR_DATA_SIZE) { + if (nrf_err == NRF_ERROR_DATA_SIZE) { /* The sys attributes are bigger than the requested * write buffer. */ retry_with_bigger_buffer = true; - } else if (err_code == NRF_ERROR_NOT_FOUND) { + } else if (nrf_err == NRF_ERROR_NOT_FOUND) { /* There are no sys attributes in the GATT db, so * nothing needs to be stored. */ - err_code = NRF_SUCCESS; + nrf_err = NRF_SUCCESS; } - uint32_t err_code_release = pdb_write_buf_release( + uint32_t nrf_err_release = pdb_write_buf_release( peer_id, PM_PEER_DATA_ID_GATT_LOCAL); - if (err_code_release != NRF_SUCCESS) { + if (nrf_err_release) { LOG_ERR("Did another thread manipulate " "PM_PEER_DATA_ID_GATT_LOCAL for " "peer_id %d at the same time? " "pdb_write_buf_release() returned %s.", peer_id, - nrf_strerror_get(err_code_release)); - err_code = NRF_ERROR_INTERNAL; + nrf_strerror_get(nrf_err_release)); + nrf_err = NRF_ERROR_INTERNAL; } } - } else if (err_code == NRF_ERROR_INVALID_PARAM) { + } else if (nrf_err == NRF_ERROR_INVALID_PARAM) { /* The sys attributes are bigger than the entire write buffer. */ - err_code = NRF_ERROR_DATA_SIZE; + nrf_err = NRF_ERROR_DATA_SIZE; } } while (retry_with_bigger_buffer); - return err_code; + return nrf_err; } uint32_t gscm_local_db_cache_apply(uint16_t conn_handle) @@ -256,7 +256,7 @@ 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 err_code; + uint32_t nrf_err; struct pm_peer_data peer_data; const uint8_t *sys_attr_data = NULL; uint16_t sys_attr_len = 0; @@ -269,9 +269,9 @@ uint32_t gscm_local_db_cache_apply(uint16_t conn_handle) 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; - err_code = pds_peer_data_read(peer_id, PM_PEER_DATA_ID_GATT_LOCAL, &peer_data, - &local_gatt_db_size); - if (err_code == NRF_SUCCESS) { + 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; @@ -282,14 +282,14 @@ uint32_t gscm_local_db_cache_apply(uint16_t conn_handle) } do { - err_code = sd_ble_gatts_sys_attr_set(conn_handle, sys_attr_data, sys_attr_len, - sys_attr_flags); - - if (err_code == NRF_ERROR_NO_MEM) { - err_code = NRF_ERROR_BUSY; - } else if (err_code == NRF_ERROR_INVALID_STATE) { - err_code = NRF_SUCCESS; - } else if (err_code == NRF_ERROR_INVALID_DATA) { + nrf_err = sd_ble_gatts_sys_attr_set(conn_handle, sys_attr_data, sys_attr_len, + sys_attr_flags); + + if (nrf_err == NRF_ERROR_NO_MEM) { + nrf_err = NRF_ERROR_BUSY; + } else if (nrf_err == NRF_ERROR_INVALID_STATE) { + nrf_err = NRF_SUCCESS; + } else if (nrf_err == NRF_ERROR_INVALID_DATA) { all_attributes_applied = false; if (sys_attr_flags & SYS_ATTR_USR) { @@ -305,16 +305,16 @@ uint32_t gscm_local_db_cache_apply(uint16_t conn_handle) "NRF_ERROR_INVALID_DATA for NULL " "pointer which should never happen. conn_handle: %d", conn_handle); - err_code = NRF_ERROR_INTERNAL; + nrf_err = NRF_ERROR_INTERNAL; } } - } while (err_code == NRF_ERROR_INVALID_DATA); + } while (nrf_err == NRF_ERROR_INVALID_DATA); if (!all_attributes_applied) { - err_code = NRF_ERROR_INVALID_DATA; + nrf_err = NRF_ERROR_INVALID_DATA; } - return err_code; + return nrf_err; } #if defined(CONFIG_PM_SERVICE_CHANGED) @@ -327,7 +327,7 @@ void gscm_local_database_has_changed(void) bool gscm_service_changed_ind_needed(uint16_t conn_handle) { - uint32_t err_code; + uint32_t nrf_err; bool service_changed_state; uint32_t service_changed_state_size = sizeof(bool); struct pm_peer_data peer_data; @@ -335,11 +335,10 @@ bool gscm_service_changed_ind_needed(uint16_t conn_handle) peer_data.all_data = &service_changed_state; uint16_t peer_id = im_peer_id_get_by_conn_handle(conn_handle); - err_code = - pds_peer_data_read(peer_id, PM_PEER_DATA_ID_SERVICE_CHANGED_PENDING, &peer_data, - &service_changed_state_size); + nrf_err = pds_peer_data_read(peer_id, PM_PEER_DATA_ID_SERVICE_CHANGED_PENDING, &peer_data, + &service_changed_state_size); - if (err_code != NRF_SUCCESS) { + if (nrf_err) { return false; } @@ -350,25 +349,25 @@ uint32_t gscm_service_changed_ind_send(uint16_t conn_handle) { static uint16_t start_handle; const uint16_t end_handle = 0xFFFF; - uint32_t err_code; + uint32_t nrf_err; - err_code = sd_ble_gatts_initial_user_handle_get(&start_handle); + nrf_err = sd_ble_gatts_initial_user_handle_get(&start_handle); - if (err_code != NRF_SUCCESS) { + if (nrf_err) { LOG_ERR("sd_ble_gatts_initial_user_handle_get() returned %s which should not " "happen.", - nrf_strerror_get(err_code)); + nrf_strerror_get(nrf_err)); return NRF_ERROR_INTERNAL; } do { - err_code = sd_ble_gatts_service_changed(conn_handle, start_handle, end_handle); - if (err_code == BLE_ERROR_INVALID_ATTR_HANDLE) { + nrf_err = sd_ble_gatts_service_changed(conn_handle, start_handle, end_handle); + if (nrf_err == BLE_ERROR_INVALID_ATTR_HANDLE) { start_handle += 1; } - } while (err_code == BLE_ERROR_INVALID_ATTR_HANDLE); + } while (nrf_err == BLE_ERROR_INVALID_ATTR_HANDLE); - return err_code; + return nrf_err; } void gscm_db_change_notification_done(uint16_t peer_id) diff --git a/lib/bluetooth/peer_manager/modules/id_manager.c b/lib/bluetooth/peer_manager/modules/id_manager.c index 9cb18e062e..b98f6c6dcb 100644 --- a/lib/bluetooth/peer_manager/modules/id_manager.c +++ b/lib/bluetooth/peer_manager/modules/id_manager.c @@ -368,13 +368,13 @@ uint32_t im_peer_free(uint16_t peer_id) { const uint16_t conn_handle = im_conn_handle_get(peer_id); const int idx = nrf_sdh_ble_idx_get(conn_handle); - const uint32_t ret = pdb_peer_free(peer_id); + const uint32_t nrf_err = pdb_peer_free(peer_id); - if ((ret == NRF_SUCCESS) && (conn_handle != BLE_CONN_HANDLE_INVALID) && (idx >= 0) && + if ((nrf_err == NRF_SUCCESS) && (conn_handle != BLE_CONN_HANDLE_INVALID) && (idx >= 0) && (idx < IM_MAX_CONN_HANDLES)) { connections[idx].peer_id = PM_PEER_ID_INVALID; } - return ret; + return nrf_err; } /** @brief Given a list of peers, loads their GAP address and IRK into the provided buffers. */ @@ -382,7 +382,7 @@ static uint32_t peers_id_keys_get(const uint16_t *peers, uint32_t peer_cnt, ble_gap_addr_t *gap_addrs, uint32_t *addr_cnt, ble_gap_irk_t *gap_irks, uint32_t *irk_cnt) { - uint32_t ret; + uint32_t nrf_err; struct pm_peer_data_bonding bond_data; struct pm_peer_data peer_data; @@ -420,10 +420,10 @@ static uint32_t peers_id_keys_get(const uint16_t *peers, uint32_t peer_cnt, memset(&bond_data, 0x00, sizeof(bond_data)); /* Read peer data from flash. */ - ret = pds_peer_data_read(peers[i], PM_PEER_DATA_ID_BONDING, &peer_data, - &buf_size); + nrf_err = pds_peer_data_read(peers[i], PM_PEER_DATA_ID_BONDING, &peer_data, + &buf_size); - if ((ret == NRF_ERROR_NOT_FOUND) || (ret == NRF_ERROR_INVALID_PARAM)) { + if ((nrf_err == NRF_ERROR_NOT_FOUND) || (nrf_err == NRF_ERROR_INVALID_PARAM)) { /* Peer data coulnd't be found in flash or peer ID is not valid. */ return NRF_ERROR_NOT_FOUND; } @@ -458,7 +458,7 @@ static uint32_t peers_id_keys_get(const uint16_t *peers, uint32_t peer_cnt, uint32_t im_device_identities_list_set(const uint16_t *peers, uint32_t peer_cnt) { - uint32_t ret; + uint32_t nrf_err; struct pm_peer_data peer_data; struct pm_peer_data_bonding bond_data; @@ -486,10 +486,10 @@ uint32_t im_device_identities_list_set(const uint16_t *peers, uint32_t peer_cnt) memset(&bond_data, 0x00, sizeof(bond_data)); /* Read peer data from flash. */ - ret = pds_peer_data_read(peers[i], PM_PEER_DATA_ID_BONDING, &peer_data, - &buf_size); + nrf_err = pds_peer_data_read(peers[i], PM_PEER_DATA_ID_BONDING, &peer_data, + &buf_size); - if ((ret == NRF_ERROR_NOT_FOUND) || (ret == NRF_ERROR_INVALID_PARAM)) { + if ((nrf_err == NRF_ERROR_NOT_FOUND) || (nrf_err == NRF_ERROR_INVALID_PARAM)) { LOG_WRN("peer id %d: Peer data could not be found in flash. Remove " "the peer ID " "from the peer list and try again.", @@ -585,7 +585,7 @@ uint32_t im_whitelist_set(const uint16_t *peers, uint32_t peer_cnt) wlisted_peer_cnt = peer_cnt; memcpy(wlisted_peers, peers, sizeof(*peers) * peer_cnt); - uint32_t ret; + uint32_t nrf_err; uint32_t wlist_addr_cnt = BLE_GAP_WHITELIST_ADDR_MAX_COUNT; const ble_gap_addr_t *addr_ptrs[BLE_GAP_WHITELIST_ADDR_MAX_COUNT]; @@ -594,14 +594,14 @@ uint32_t im_whitelist_set(const uint16_t *peers, uint32_t peer_cnt) memset(addrs, 0x00, sizeof(addrs)); /* Fetch GAP addresses for these peers, but don't fetch IRKs. */ - ret = peers_id_keys_get(peers, peer_cnt, addrs, &wlist_addr_cnt, NULL, NULL); + nrf_err = peers_id_keys_get(peers, peer_cnt, addrs, &wlist_addr_cnt, NULL, NULL); - if (ret != NRF_SUCCESS) { + if (nrf_err) { /* NRF_ERROR_NOT_FOUND, if a peer or its data were not found. * BLE_ERROR_GAP_INVALID_BLE_ADDR, if a peer address can not be used for * whitelisting. */ - return ret; + return nrf_err; } for (uint32_t i = 0; i < BLE_GAP_WHITELIST_ADDR_MAX_COUNT; i++) { diff --git a/lib/bluetooth/peer_manager/modules/nrf_ble_lesc.c b/lib/bluetooth/peer_manager/modules/nrf_ble_lesc.c index a2fbef19f2..536e1ea756 100644 --- a/lib/bluetooth/peer_manager/modules/nrf_ble_lesc.c +++ b/lib/bluetooth/peer_manager/modules/nrf_ble_lesc.c @@ -184,19 +184,19 @@ uint32_t nrf_ble_lesc_keypair_generate(void) uint32_t nrf_ble_lesc_own_oob_data_generate(void) { - uint32_t err_code = NRF_ERROR_INVALID_STATE; + uint32_t nrf_err = NRF_ERROR_INVALID_STATE; lesc_oobd_own_generated = false; if (keypair_generated) { - err_code = sd_ble_gap_lesc_oob_data_get(BLE_CONN_HANDLE_INVALID, &lesc_public_key, - &ble_lesc_oobd_own); - if (err_code == NRF_SUCCESS) { + nrf_err = sd_ble_gap_lesc_oob_data_get(BLE_CONN_HANDLE_INVALID, &lesc_public_key, + &ble_lesc_oobd_own); + if (nrf_err == NRF_SUCCESS) { lesc_oobd_own_generated = true; } } - return err_code; + return nrf_err; } ble_gap_lesc_p256_pk_t *nrf_ble_lesc_public_key_get(void) @@ -287,7 +287,7 @@ static uint32_t compute_and_give_dhkey(struct lesc_peer_pub_key *peer_public_key uint32_t nrf_ble_lesc_request_handler(void) { - uint32_t err_code; + uint32_t nrf_err; /* If the LESC module is in an invalid state, a restart is required. */ if (ble_lesc_internal_error) { @@ -296,14 +296,14 @@ uint32_t nrf_ble_lesc_request_handler(void) for (uint16_t i = 0; i < NRF_BLE_LESC_LINK_COUNT; i++) { if (peer_keys[i].is_requested) { - err_code = compute_and_give_dhkey(&peer_keys[i]); + nrf_err = compute_and_give_dhkey(&peer_keys[i]); peer_keys[i].is_requested = false; peer_keys[i].is_valid = false; peer_keys[i].passkey_requested = false; peer_keys[i].passkey_displayed = false; - if (err_code != NRF_SUCCESS) { - return err_code; + if (nrf_err) { + return nrf_err; } } } @@ -325,7 +325,7 @@ uint32_t nrf_ble_lesc_request_handler(void) static uint32_t on_dhkey_request(uint16_t conn_handle, int idx, const ble_gap_evt_lesc_dhkey_request_t *dhkey_request) { - uint32_t err_code = NRF_SUCCESS; + uint32_t nrf_err = NRF_SUCCESS; const uint8_t *const public_raw = dhkey_request->p_pk_peer->pk; /* Don't allow to pair with remote peer which uses the same public key. @@ -341,10 +341,10 @@ static uint32_t on_dhkey_request(uint16_t conn_handle, int idx, if (peer_keys[idx].passkey_requested) { peer_keys[idx].passkey_requested = false; - err_code = sd_ble_gap_auth_key_reply(conn_handle, - BLE_GAP_AUTH_KEY_TYPE_NONE, NULL); + nrf_err = sd_ble_gap_auth_key_reply(conn_handle, + BLE_GAP_AUTH_KEY_TYPE_NONE, NULL); - return err_code; + return nrf_err; } /* In case we have gotten passkey display event then we need to disconnect a link @@ -353,10 +353,11 @@ static uint32_t on_dhkey_request(uint16_t conn_handle, int idx, else if (peer_keys[idx].passkey_displayed) { peer_keys[idx].passkey_displayed = false; - err_code = sd_ble_gap_disconnect(conn_handle, - BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); - if (err_code != NRF_SUCCESS && err_code != NRF_ERROR_INVALID_STATE) { - return err_code; + nrf_err = sd_ble_gap_disconnect(conn_handle, + BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); + if ((nrf_err != NRF_SUCCESS) && + (nrf_err != NRF_ERROR_INVALID_STATE)) { + return nrf_err; } return NRF_SUCCESS; @@ -382,7 +383,6 @@ static uint32_t on_dhkey_request(uint16_t conn_handle, int idx, */ static uint32_t lesc_oob_data_set(uint16_t conn_handle) { - uint32_t err_code; ble_gap_lesc_oob_data_t *lesc_oobd_own; ble_gap_lesc_oob_data_t *lesc_oobd_peer; @@ -390,13 +390,12 @@ static uint32_t lesc_oob_data_set(uint16_t conn_handle) lesc_oobd_peer = (lesc_oobd_peer_handler != NULL) ? lesc_oobd_peer_handler(conn_handle) : NULL; - err_code = sd_ble_gap_lesc_oob_data_set(conn_handle, lesc_oobd_own, lesc_oobd_peer); - return err_code; + return sd_ble_gap_lesc_oob_data_set(conn_handle, lesc_oobd_own, lesc_oobd_peer); } void nrf_ble_lesc_on_ble_evt(const ble_evt_t *ble_evt) { - uint32_t err_code = NRF_SUCCESS; + uint32_t nrf_err = NRF_SUCCESS; const uint16_t conn_handle = ble_evt->evt.gap_evt.conn_handle; const int idx = nrf_sdh_ble_idx_get(conn_handle); @@ -429,17 +428,17 @@ void nrf_ble_lesc_on_ble_evt(const ble_evt_t *ble_evt) LOG_DBG("BLE_GAP_EVT_LESC_DHKEY_REQUEST"); if (ble_evt->evt.gap_evt.params.lesc_dhkey_request.oobd_req) { - err_code = lesc_oob_data_set(conn_handle); - if (err_code != NRF_SUCCESS) { + nrf_err = lesc_oob_data_set(conn_handle); + if (nrf_err) { LOG_ERR("sd_ble_gap_lesc_oob_data_set() returned error 0x%x.", - err_code); + nrf_err); ble_lesc_internal_error = true; } } - err_code = on_dhkey_request(conn_handle, idx, - &ble_evt->evt.gap_evt.params.lesc_dhkey_request); - if (err_code != NRF_SUCCESS) { + nrf_err = on_dhkey_request(conn_handle, idx, + &ble_evt->evt.gap_evt.params.lesc_dhkey_request); + if (nrf_err) { ble_lesc_internal_error = true; } break; @@ -447,8 +446,8 @@ void nrf_ble_lesc_on_ble_evt(const ble_evt_t *ble_evt) #if defined(CONFIG_PM_LESC_GENERATE_NEW_KEYS) case BLE_GAP_EVT_AUTH_STATUS: /* Generate new pairing keys. */ - err_code = nrf_ble_lesc_keypair_generate(); - if (err_code != NRF_SUCCESS) { + nrf_err = nrf_ble_lesc_keypair_generate(); + if (nrf_err) { ble_lesc_internal_error = true; } diff --git a/lib/bluetooth/peer_manager/modules/peer_data_storage.c b/lib/bluetooth/peer_manager/modules/peer_data_storage.c index 98c3e1407d..0f757bbd5b 100644 --- a/lib/bluetooth/peer_manager/modules/peer_data_storage.c +++ b/lib/bluetooth/peer_manager/modules/peer_data_storage.c @@ -92,16 +92,16 @@ static bool peer_data_id_is_valid(enum pm_peer_data_id data_id) /** * @brief Function for sending a PM_EVT_ERROR_UNEXPECTED event. * - * @param[in] peer_id The peer the event pertains to. - * @param[in] err_code The unexpected error that occurred. + * @param[in] peer_id The peer the event pertains to. + * @param[in] nrf_err The unexpected error that occurred. */ -static void send_unexpected_error(uint16_t peer_id, uint32_t err_code) +static void send_unexpected_error(uint16_t peer_id, uint32_t nrf_err) { struct pm_evt error_evt = { .evt_id = PM_EVT_ERROR_UNEXPECTED, .peer_id = peer_id, .params.error_unexpected = { - .error = err_code, + .error = nrf_err, }, }; pds_evt_send(&error_evt); @@ -247,13 +247,13 @@ static void bm_zms_evt_handler(const bm_zms_evt_t *evt) pds_evt_send(&pds_evt); } else { uint32_t next_entry_id; - uint32_t ret; + uint32_t nrf_err; - ret = find_next_data_entry_in_peer(peer_id, &next_entry_id); - if (ret == NRF_SUCCESS) { + nrf_err = find_next_data_entry_in_peer(peer_id, &next_entry_id); + if (nrf_err == NRF_SUCCESS) { /* Process the next entry for the peer. */ peer_delete_deferred = true; - } else if (ret == NRF_ERROR_NOT_FOUND) { + } else if (nrf_err == NRF_ERROR_NOT_FOUND) { atomic_dec(&delete_counter); /* Process the next deleted peers, if any are present. */ diff --git a/lib/bluetooth/peer_manager/modules/peer_database.c b/lib/bluetooth/peer_manager/modules/peer_database.c index 64ebb5e80a..c935113412 100644 --- a/lib/bluetooth/peer_manager/modules/peer_database.c +++ b/lib/bluetooth/peer_manager/modules/peer_database.c @@ -309,7 +309,7 @@ static void write_buf_length_words_set(struct pm_peer_data_const *peer_data) */ uint32_t write_buf_store(struct pdb_buffer_record *write_buffer_record) { - uint32_t err_code = NRF_SUCCESS; + uint32_t nrf_err = NRF_SUCCESS; struct pm_peer_data_const peer_data = {.data_id = write_buffer_record->data_id}; uint8_t *buffer_memory; @@ -325,10 +325,10 @@ uint32_t write_buf_store(struct pdb_buffer_record *write_buffer_record) write_buffer_record->n_bufs); write_buf_length_words_set(&peer_data); - err_code = pds_peer_data_store(write_buffer_record->peer_id, &peer_data, - &write_buffer_record->store_token); + nrf_err = pds_peer_data_store(write_buffer_record->peer_id, &peer_data, + &write_buffer_record->store_token); - switch (err_code) { + switch (nrf_err) { case NRF_SUCCESS: write_buffer_record->store_busy = false; write_buffer_record->store_flash_full = false; @@ -339,7 +339,7 @@ uint32_t write_buf_store(struct pdb_buffer_record *write_buffer_record) write_buffer_record->store_flash_full = false; pending_store = true; - err_code = NRF_SUCCESS; + nrf_err = NRF_SUCCESS; break; case NRF_ERROR_RESOURCES: @@ -354,12 +354,12 @@ uint32_t write_buf_store(struct pdb_buffer_record *write_buffer_record) default: LOG_ERR("pds_peer_data_store() returned %s. peer_id: %d", - nrf_strerror_get(err_code), write_buffer_record->peer_id); - err_code = NRF_ERROR_INTERNAL; + nrf_strerror_get(nrf_err), write_buffer_record->peer_id); + nrf_err = NRF_ERROR_INTERNAL; break; } - return err_code; + return nrf_err; } /** @@ -371,24 +371,23 @@ uint32_t write_buf_store(struct pdb_buffer_record *write_buffer_record) */ static bool write_buf_store_in_event(struct pdb_buffer_record *write_buffer_record) { - uint32_t err_code; + uint32_t nrf_err; struct pm_evt event; - err_code = write_buf_store(write_buffer_record); - if (err_code != NRF_SUCCESS) { + nrf_err = write_buf_store(write_buffer_record); + if (nrf_err) { event.conn_handle = BLE_CONN_HANDLE_INVALID; event.peer_id = write_buffer_record->peer_id; - if (err_code == NRF_ERROR_RESOURCES) { + if (nrf_err == NRF_ERROR_RESOURCES) { event.evt_id = PM_EVT_STORAGE_FULL; } else { event.evt_id = PM_EVT_ERROR_UNEXPECTED; - event.params.error_unexpected.error = err_code; + event.params.error_unexpected.error = nrf_err; LOG_ERR("Some peer data was not properly written to flash. " - "write_buf_store() " - "returned %s for peer_id: %d", - nrf_strerror_get(err_code), write_buffer_record->peer_id); + "write_buf_store() returned %s for peer_id: %d", + nrf_strerror_get(nrf_err), write_buffer_record->peer_id); } pdb_evt_send(&event); @@ -481,16 +480,16 @@ void pdb_pds_evt_handler(struct pm_evt *event) uint32_t pdb_init(void) { - uint32_t err_code; + uint32_t nrf_err; __ASSERT_NO_MSG(!module_initialized); internal_state_reset(); - PM_BUFFER_INIT(&write_buffer, CONFIG_PM_FLASH_BUFFERS, PDB_WRITE_BUF_SIZE, err_code); + PM_BUFFER_INIT(&write_buffer, CONFIG_PM_FLASH_BUFFERS, PDB_WRITE_BUF_SIZE, nrf_err); - if (err_code != NRF_SUCCESS) { - LOG_ERR("PM_BUFFER_INIT() returned %s.", nrf_strerror_get(err_code)); + if (nrf_err) { + LOG_ERR("PM_BUFFER_INIT() returned %s.", nrf_strerror_get(nrf_err)); return NRF_ERROR_INTERNAL; } @@ -501,7 +500,7 @@ uint32_t pdb_init(void) uint32_t pdb_peer_free(uint16_t peer_id) { - uint32_t err_code; + uint32_t nrf_err; __ASSERT_NO_MSG(module_initialized); @@ -509,15 +508,16 @@ uint32_t pdb_peer_free(uint16_t peer_id) struct pdb_buffer_record *record = write_buffer_record_find_next(peer_id, &index); while (record != NULL) { - err_code = pdb_write_buf_release(peer_id, record->data_id); + nrf_err = pdb_write_buf_release(peer_id, record->data_id); /* All return values are acceptable. */ - UNUSED_VARIABLE(err_code); + UNUSED_VARIABLE(nrf_err); - if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_NOT_FOUND)) { + if ((nrf_err != NRF_SUCCESS) && + (nrf_err != NRF_ERROR_NOT_FOUND)) { LOG_ERR("pdb_write_buf_release() returned %s which should not " "happen. peer_id: %d, " "data_id: %d", - nrf_strerror_get(err_code), peer_id, record->data_id); + nrf_strerror_get(nrf_err), peer_id, record->data_id); return NRF_ERROR_INTERNAL; } @@ -525,14 +525,14 @@ uint32_t pdb_peer_free(uint16_t peer_id) record = write_buffer_record_find_next(peer_id, &index); } - err_code = pds_peer_id_free(peer_id); + nrf_err = pds_peer_id_free(peer_id); - if ((err_code == NRF_SUCCESS) || (err_code == NRF_ERROR_INVALID_PARAM)) { - return err_code; + if ((nrf_err == NRF_SUCCESS) || (nrf_err == NRF_ERROR_INVALID_PARAM)) { + return nrf_err; } LOG_ERR("Peer ID %d was not properly released. pds_peer_id_free() returned %s", - peer_id, nrf_strerror_get(err_code)); + peer_id, nrf_strerror_get(nrf_err)); return NRF_ERROR_INTERNAL; } diff --git a/lib/bluetooth/peer_manager/modules/peer_manager_handler.c b/lib/bluetooth/peer_manager/modules/peer_manager_handler.c index 751301745e..0cc5822c11 100644 --- a/lib/bluetooth/peer_manager/modules/peer_manager_handler.c +++ b/lib/bluetooth/peer_manager/modules/peer_manager_handler.c @@ -109,14 +109,14 @@ static const char *sec_err_string_get(uint16_t error) static void conn_secure_impl(uint16_t conn_handle, bool force) { - uint32_t err_code; + uint32_t nrf_err; if (!force) { struct pm_conn_sec_status status; - err_code = pm_conn_sec_status_get(conn_handle, &status); - if (err_code != BLE_ERROR_INVALID_CONN_HANDLE) { - APP_ERROR_CHECK(err_code); + nrf_err = pm_conn_sec_status_get(conn_handle, &status); + if (nrf_err != BLE_ERROR_INVALID_CONN_HANDLE) { + APP_ERROR_CHECK(nrf_err); } /* If the link is already secured, don't initiate security procedure. */ @@ -126,32 +126,32 @@ static void conn_secure_impl(uint16_t conn_handle, bool force) } } - err_code = pm_conn_secure(conn_handle, false); + nrf_err = pm_conn_secure(conn_handle, false); - if ((err_code == NRF_SUCCESS) || (err_code == NRF_ERROR_BUSY)) { + if ((nrf_err == NRF_SUCCESS) || (nrf_err == NRF_ERROR_BUSY)) { /* Success. */ - } else if (err_code == NRF_ERROR_TIMEOUT) { + } else if (nrf_err == NRF_ERROR_TIMEOUT) { LOG_WRN("pm_conn_secure() failed because an SMP timeout is preventing security on " "the link. Disconnecting conn_handle %d.", conn_handle); - err_code = sd_ble_gap_disconnect(conn_handle, - BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); - if (err_code != NRF_SUCCESS) { + nrf_err = sd_ble_gap_disconnect(conn_handle, + BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); + if (nrf_err) { LOG_WRN("sd_ble_gap_disconnect() returned %s on conn_handle %d.", - nrf_strerror_get(err_code), conn_handle); + nrf_strerror_get(nrf_err), conn_handle); } - } else if (err_code == NRF_ERROR_INVALID_DATA) { + } else if (nrf_err == NRF_ERROR_INVALID_DATA) { LOG_WRN("pm_conn_secure() failed because the stored data for conn_handle %d does " "not have a valid key.", conn_handle); - } else if (err_code == BLE_ERROR_INVALID_CONN_HANDLE) { + } else if (nrf_err == BLE_ERROR_INVALID_CONN_HANDLE) { LOG_WRN("pm_conn_secure() failed because conn_handle %d is not a valid connection.", conn_handle); } else { LOG_ERR("Asserting. pm_conn_secure() returned %s on conn_handle %d.", - nrf_strerror_get(err_code), conn_handle); - APP_ERROR_CHECK(err_code); + nrf_strerror_get(nrf_err), conn_handle); + APP_ERROR_CHECK(nrf_err); } } @@ -240,7 +240,7 @@ static void rank_highest(uint16_t peer_id) void pm_handler_flash_clean(const struct pm_evt *pm_evt) { - uint32_t err_code; + uint32_t nrf_err; /* Indicates whether a successful write happened after the last garbage * collection. If this is false when flash is full, it means just a * garbage collection won't work, so some data should be deleted. @@ -259,19 +259,19 @@ void pm_handler_flash_clean(const struct pm_evt *pm_evt) switch (pm_evt->evt_id) { case PM_EVT_BONDED_PEER_CONNECTED: - err_code = pm_peer_rank_highest(pm_evt->peer_id); - if ((err_code == NRF_ERROR_RESOURCES) || (err_code == NRF_ERROR_BUSY)) { + nrf_err = pm_peer_rank_highest(pm_evt->peer_id); + if ((nrf_err == NRF_ERROR_RESOURCES) || (nrf_err == NRF_ERROR_BUSY)) { /* Queue pm_peer_rank_highest() call and attempt to clean flash. */ rank_queue[rank_queue_wr] = pm_evt->peer_id; rank_queue_wr = (rank_queue_wr + 1) % RANK_QUEUE_SIZE; pm_handler_flash_clean_on_return(); - } else if ((err_code != NRF_ERROR_NOT_SUPPORTED) && - (err_code != NRF_ERROR_INVALID_PARAM) && - (err_code != NRF_ERROR_DATA_SIZE)) { - APP_ERROR_CHECK(err_code); + } else if ((nrf_err != NRF_ERROR_NOT_SUPPORTED) && + (nrf_err != NRF_ERROR_INVALID_PARAM) && + (nrf_err != NRF_ERROR_DATA_SIZE)) { + APP_ERROR_CHECK(nrf_err); } else { LOG_DBG("pm_peer_rank_highest() returned %s for peer id %d", - nrf_strerror_get(err_code), pm_evt->peer_id); + nrf_strerror_get(nrf_err), pm_evt->peer_id); } break; @@ -461,15 +461,15 @@ void pm_handler_pm_evt_log(const struct pm_evt *pm_evt) void pm_handler_disconnect_on_sec_failure(const struct pm_evt *pm_evt) { - uint32_t err_code; + uint32_t nrf_err; if (pm_evt->evt_id == PM_EVT_CONN_SEC_FAILED) { LOG_WRN("Disconnecting conn_handle %d.", pm_evt->conn_handle); - err_code = sd_ble_gap_disconnect(pm_evt->conn_handle, - BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); - if ((err_code != NRF_ERROR_INVALID_STATE) && - (err_code != BLE_ERROR_INVALID_CONN_HANDLE)) { - APP_ERROR_CHECK(err_code); + nrf_err = sd_ble_gap_disconnect(pm_evt->conn_handle, + BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); + if ((nrf_err != NRF_ERROR_INVALID_STATE) && + (nrf_err != BLE_ERROR_INVALID_CONN_HANDLE)) { + APP_ERROR_CHECK(nrf_err); } } } @@ -480,10 +480,10 @@ void pm_handler_disconnect_on_insufficient_sec(const struct pm_evt *pm_evt, if (pm_evt->evt_id == PM_EVT_CONN_SEC_SUCCEEDED) { if (!pm_sec_is_sufficient(pm_evt->conn_handle, min_conn_sec)) { LOG_WRN("Connection security is insufficient, disconnecting."); - uint32_t err_code = sd_ble_gap_disconnect( + uint32_t nrf_err = sd_ble_gap_disconnect( pm_evt->conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); - APP_ERROR_CHECK(err_code); - LOG_ERR("sd_ble_gap_disconnect() error 0x%x", err_code); + APP_ERROR_CHECK(nrf_err); + LOG_ERR("sd_ble_gap_disconnect() error 0x%x", nrf_err); } } } diff --git a/lib/bluetooth/peer_manager/modules/security_dispatcher.c b/lib/bluetooth/peer_manager/modules/security_dispatcher.c index 8788e2e602..af84b9f8af 100644 --- a/lib/bluetooth/peer_manager/modules/security_dispatcher.c +++ b/lib/bluetooth/peer_manager/modules/security_dispatcher.c @@ -85,8 +85,8 @@ static void evt_send(struct pm_evt *event) /** * @brief Function for sending a PM_EVT_CONN_SEC_START event. * - * @param[in] conn_handle The connection handle the event pertains to. - * @param[in] procedure The procedure that has started on the connection. + * @param[in] conn_handle The connection handle the event pertains to. + * @param[in] procedure The procedure that has started on the connection. */ static void sec_start_send(uint16_t conn_handle, enum pm_conn_sec_procedure procedure) { @@ -104,16 +104,16 @@ static void sec_start_send(uint16_t conn_handle, enum pm_conn_sec_procedure proc /** * @brief Function for sending a PM_EVT_ERROR_UNEXPECTED event. * - * @param[in] conn_handle The connection handle the event pertains to. - * @param[in] err_code The unexpected error that occurred. + * @param[in] conn_handle The connection handle the event pertains to. + * @param[in] nrf_err The unexpected error that occurred. */ -static void send_unexpected_error(uint16_t conn_handle, uint32_t err_code) +static void send_unexpected_error(uint16_t conn_handle, uint32_t nrf_err) { struct pm_evt error_evt = { .evt_id = PM_EVT_ERROR_UNEXPECTED, .conn_handle = conn_handle, .params.error_unexpected = { - .error = err_code, + .error = nrf_err, }, }; @@ -168,22 +168,22 @@ static void conn_sec_failure(uint16_t conn_handle, enum pm_conn_sec_procedure pr */ static void pairing_failure(uint16_t conn_handle, uint16_t error, uint8_t error_src) { - uint32_t err_code = NRF_SUCCESS; + uint32_t nrf_err = NRF_SUCCESS; enum pm_conn_sec_procedure procedure = bonding(conn_handle) ? PM_CONN_SEC_PROCEDURE_BONDING : PM_CONN_SEC_PROCEDURE_PAIRING; uint16_t temp_peer_id; - err_code = pdb_temp_peer_id_get(conn_handle, &temp_peer_id); - if (err_code == NRF_SUCCESS) { - err_code = pdb_write_buf_release(temp_peer_id, PM_PEER_DATA_ID_BONDING); + nrf_err = pdb_temp_peer_id_get(conn_handle, &temp_peer_id); + if (nrf_err == NRF_SUCCESS) { + nrf_err = pdb_write_buf_release(temp_peer_id, PM_PEER_DATA_ID_BONDING); } - if ((err_code != NRF_SUCCESS) && - (err_code != NRF_ERROR_NOT_FOUND /* No buffer was allocated */)) { + if ((nrf_err != NRF_SUCCESS) && + (nrf_err != NRF_ERROR_NOT_FOUND /* No buffer was allocated */)) { LOG_ERR("Could not clean up after failed bonding procedure. " "pdb_write_buf_release() returned %s. conn_handle: %d.", - nrf_strerror_get(err_code), conn_handle); - send_unexpected_error(conn_handle, err_code); + nrf_strerror_get(nrf_err), conn_handle); + send_unexpected_error(conn_handle, nrf_err); } conn_sec_failure(conn_handle, procedure, error, error_src); @@ -265,7 +265,7 @@ static uint32_t link_secure_authenticate(uint16_t conn_handle, ble_gap_sec_param static uint32_t link_secure_central_encryption(uint16_t conn_handle, uint16_t peer_id) { struct pm_peer_data peer_data; - uint32_t err_code; + uint32_t nrf_err; const ble_gap_enc_key_t *existing_key = NULL; bool lesc = false; struct pm_peer_data_bonding bonding_data = { 0 }; @@ -273,9 +273,9 @@ static uint32_t link_secure_central_encryption(uint16_t conn_handle, uint16_t pe peer_data.bonding_data = &bonding_data; - err_code = pds_peer_data_read(peer_id, PM_PEER_DATA_ID_BONDING, &peer_data, &buf_size); + nrf_err = pds_peer_data_read(peer_id, PM_PEER_DATA_ID_BONDING, &peer_data, &buf_size); - if (err_code == NRF_SUCCESS) { + if (nrf_err == NRF_SUCCESS) { /* Use peer's key since they are peripheral. */ existing_key = &(bonding_data.peer_ltk); @@ -287,37 +287,38 @@ static uint32_t link_secure_central_encryption(uint16_t conn_handle, uint16_t pe } } - if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_NOT_FOUND)) { - if (err_code != NRF_ERROR_BUSY) { + if ((nrf_err != NRF_SUCCESS) && + (nrf_err != NRF_ERROR_NOT_FOUND)) { + if (nrf_err != NRF_ERROR_BUSY) { LOG_ERR("Could not retrieve stored bond. pds_peer_data_read() " - "returned %s. peer_id: %d", nrf_strerror_get(err_code), peer_id); - err_code = NRF_ERROR_INTERNAL; + "returned %s. peer_id: %d", nrf_strerror_get(nrf_err), peer_id); + nrf_err = NRF_ERROR_INTERNAL; } /* There is no bonding data stored. This means that a * bonding procedure is in ongoing, or that the records * in flash are in a bad state. */ } else if (existing_key == NULL) { - err_code = NRF_ERROR_BUSY; + nrf_err = NRF_ERROR_BUSY; } else if (!lesc && !im_master_id_is_valid(&(existing_key->master_id))) { /* No LTK to encrypt with. */ - err_code = NRF_ERROR_INVALID_DATA; + nrf_err = NRF_ERROR_INVALID_DATA; } else { /* Encrypt with existing LTK. */ - err_code = sd_ble_gap_encrypt(conn_handle, &(existing_key->master_id), - &(existing_key->enc_info)); + nrf_err = sd_ble_gap_encrypt(conn_handle, &(existing_key->master_id), + &(existing_key->enc_info)); } - sec_proc_start(conn_handle, err_code == NRF_SUCCESS, PM_CONN_SEC_PROCEDURE_ENCRYPTION); + sec_proc_start(conn_handle, nrf_err == NRF_SUCCESS, PM_CONN_SEC_PROCEDURE_ENCRYPTION); - return err_code; + return nrf_err; } /** @brief Function for intiating security as a central. See @ref smd_link_secure for more info. */ static uint32_t link_secure_central(uint16_t conn_handle, ble_gap_sec_params_t *sec_params, bool force_repairing) { - uint32_t err_code; + uint32_t nrf_err; uint16_t peer_id; if (sec_params == NULL) { @@ -335,19 +336,19 @@ static uint32_t link_secure_central(uint16_t conn_handle, ble_gap_sec_params_t * /* There is already data in flash for this peer, and repairing has not been * requested, so the link will be encrypted with the existing keys. */ - err_code = link_secure_central_encryption(conn_handle, peer_id); + nrf_err = link_secure_central_encryption(conn_handle, peer_id); } else { /* There are no existing keys, or repairing has been explicitly requested, so * pairing (possibly including bonding) will be performed to encrypt the link. */ - err_code = link_secure_authenticate(conn_handle, sec_params); + nrf_err = link_secure_authenticate(conn_handle, sec_params); enum pm_conn_sec_procedure procedure = (sec_params && sec_params->bond) ? PM_CONN_SEC_PROCEDURE_BONDING : PM_CONN_SEC_PROCEDURE_PAIRING; - sec_proc_start(conn_handle, err_code == NRF_SUCCESS, procedure); + sec_proc_start(conn_handle, nrf_err == NRF_SUCCESS, procedure); } - return err_code; + return nrf_err; } /** @@ -395,7 +396,7 @@ static uint32_t link_secure_peripheral(uint16_t conn_handle, ble_gap_sec_params_ */ static void sec_info_request_process(const ble_gap_evt_t *gap_evt) { - uint32_t err_code; + uint32_t nrf_err; const ble_gap_enc_info_t *enc_info = NULL; struct pm_peer_data peer_data; uint16_t peer_id = @@ -419,10 +420,10 @@ static void sec_info_request_process(const ble_gap_evt_t *gap_evt) if (peer_id != PM_PEER_ID_INVALID) { peer_data.all_data = &bonding_data; - err_code = pds_peer_data_read(peer_id, PM_PEER_DATA_ID_BONDING, &peer_data, - &bonding_data_size); + nrf_err = pds_peer_data_read(peer_id, PM_PEER_DATA_ID_BONDING, &peer_data, + &bonding_data_size); - if (err_code == NRF_SUCCESS) { + if (nrf_err == NRF_SUCCESS) { /* There is stored bonding data for this peer. */ const ble_gap_enc_key_t *existing_key = &bonding_data.own_ltk; @@ -437,9 +438,9 @@ static void sec_info_request_process(const ble_gap_evt_t *gap_evt) } } - err_code = sd_ble_gap_sec_info_reply(gap_evt->conn_handle, enc_info, NULL, NULL); + nrf_err = sd_ble_gap_sec_info_reply(gap_evt->conn_handle, enc_info, NULL, NULL); - if (err_code == NRF_ERROR_INVALID_STATE) { + if (nrf_err == NRF_ERROR_INVALID_STATE) { /* Do nothing. If disconnecting, it will be caught later by the handling of the * DISCONNECTED event. If there is no SEC_INFO_REQ pending, there is either a logic * error, or the user is also calling sd_ble_gap_sec_info_reply(), but there is no @@ -447,11 +448,11 @@ static void sec_info_request_process(const ble_gap_evt_t *gap_evt) */ LOG_WRN("sd_ble_gap_sec_info_reply() returned NRF_ERROR_INVALID_STATE, which is an " "error unless the link is disconnecting."); - } else if (err_code != NRF_SUCCESS) { + } else if (nrf_err) { LOG_ERR("Could not complete encryption procedure. sd_ble_gap_sec_info_reply() " "returned %s. conn_handle: %d, peer_id: %d.", - nrf_strerror_get(err_code), gap_evt->conn_handle, peer_id); - send_unexpected_error(gap_evt->conn_handle, err_code); + nrf_strerror_get(nrf_err), gap_evt->conn_handle, peer_id); + send_unexpected_error(gap_evt->conn_handle, nrf_err); } else if (gap_evt->params.sec_info_request.enc_info && (enc_info == NULL)) { encryption_failure(gap_evt->conn_handle, PM_CONN_SEC_ERROR_PIN_OR_KEY_MISSING, BLE_GAP_SEC_STATUS_SOURCE_LOCAL); @@ -567,7 +568,7 @@ static void pairing_success_evt_send(const ble_gap_evt_t *gap_evt, bool data_sto */ static void auth_status_success_process(const ble_gap_evt_t *gap_evt) { - uint32_t err_code; + uint32_t nrf_err; uint16_t conn_handle = gap_evt->conn_handle; uint16_t peer_id; uint16_t temp_peer_id; @@ -581,16 +582,16 @@ static void auth_status_success_process(const ble_gap_evt_t *gap_evt) return; } - err_code = pdb_temp_peer_id_get(conn_handle, &temp_peer_id); - if (err_code == NRF_SUCCESS) { - err_code = pdb_write_buf_get(temp_peer_id, PM_PEER_DATA_ID_BONDING, 1, &peer_data); + nrf_err = pdb_temp_peer_id_get(conn_handle, &temp_peer_id); + if (nrf_err == NRF_SUCCESS) { + nrf_err = pdb_write_buf_get(temp_peer_id, PM_PEER_DATA_ID_BONDING, 1, &peer_data); } - if (err_code != NRF_SUCCESS) { + if (nrf_err) { LOG_ERR("RAM buffer for new bond was unavailable. pdb_write_buf_get() " "returned %s. conn_handle: %d.", - nrf_strerror_get(err_code), conn_handle); - send_unexpected_error(conn_handle, err_code); + nrf_strerror_get(nrf_err), conn_handle); + send_unexpected_error(conn_handle, nrf_err); pairing_success_evt_send(gap_evt, false); return; } @@ -628,19 +629,19 @@ static void auth_status_success_process(const ble_gap_evt_t *gap_evt) new_peer_id = true; } - err_code = pdb_write_buf_store(temp_peer_id, PM_PEER_DATA_ID_BONDING, peer_id); + nrf_err = pdb_write_buf_store(temp_peer_id, PM_PEER_DATA_ID_BONDING, peer_id); - if (err_code == NRF_SUCCESS) { + if (nrf_err == NRF_SUCCESS) { pairing_success_evt_send(gap_evt, true); - } else if (err_code == NRF_ERROR_RESOURCES) { + } else if (nrf_err == NRF_ERROR_RESOURCES) { send_storage_full_evt(conn_handle); pairing_success_evt_send(gap_evt, true); } else { /* Unexpected error */ LOG_ERR("Could not store bond. pdb_write_buf_store() returned %s. " "conn_handle: %d, peer_id: %d", - nrf_strerror_get(err_code), conn_handle, peer_id); - send_unexpected_error(conn_handle, err_code); + nrf_strerror_get(nrf_err), conn_handle, peer_id); + send_unexpected_error(conn_handle, nrf_err); pairing_success_evt_send(gap_evt, false); if (new_peer_id) { /* Unused return value. We are already in a bad state. */ @@ -746,10 +747,10 @@ uint32_t smd_init(void) } #if defined(CONFIG_PM_RA_PROTECTION) - uint32_t err_code = ast_init(); + uint32_t nrf_err = ast_init(); - if (err_code != NRF_SUCCESS) { - return err_code; + if (nrf_err) { + return nrf_err; } #endif /* CONFIG_PM_RA_PROTECTION */ @@ -777,7 +778,7 @@ static uint32_t sec_keyset_fill(uint16_t conn_handle, uint8_t role, ble_gap_lesc_p256_pk_t *public_key, ble_gap_sec_keyset_t *sec_keyset) { - uint32_t err_code; + uint32_t nrf_err; uint16_t temp_peer_id; struct pm_peer_data peer_data; @@ -786,19 +787,19 @@ static uint32_t sec_keyset_fill(uint16_t conn_handle, uint8_t role, return NRF_ERROR_INTERNAL; } - err_code = pdb_temp_peer_id_get(conn_handle, &temp_peer_id); - if (err_code == NRF_SUCCESS) { + nrf_err = pdb_temp_peer_id_get(conn_handle, &temp_peer_id); + if (nrf_err == NRF_SUCCESS) { /* Acquire a memory buffer to receive bonding data into. */ - err_code = pdb_write_buf_get(temp_peer_id, PM_PEER_DATA_ID_BONDING, 1, &peer_data); + nrf_err = pdb_write_buf_get(temp_peer_id, PM_PEER_DATA_ID_BONDING, 1, &peer_data); } - if (err_code == NRF_ERROR_BUSY) { + if (nrf_err == NRF_ERROR_BUSY) { /* No action. */ - } else if (err_code != NRF_SUCCESS) { + } else if (nrf_err) { LOG_ERR("Could not retrieve RAM buffer for incoming bond. pdb_write_buf_get() " "returned %s. conn_handle: %d", - nrf_strerror_get(err_code), conn_handle); - err_code = NRF_ERROR_INTERNAL; + nrf_strerror_get(nrf_err), conn_handle); + nrf_err = NRF_ERROR_INTERNAL; } else { memset(peer_data.bonding_data, 0, sizeof(struct pm_peer_data_bonding)); @@ -813,17 +814,17 @@ static uint32_t sec_keyset_fill(uint16_t conn_handle, uint8_t role, /* Retrieve the address the peer used during connection establishment. * This address will be overwritten if ID is shared. Should not fail. */ - err_code = im_ble_addr_get(conn_handle, - &peer_data.bonding_data->peer_ble_id.id_addr_info); - if (err_code != NRF_SUCCESS) { + nrf_err = im_ble_addr_get(conn_handle, + &peer_data.bonding_data->peer_ble_id.id_addr_info); + if (nrf_err) { LOG_WRN("im_ble_addr_get() returned %s. conn_handle: %d. Link was " "likely disconnected.", - nrf_strerror_get(err_code), conn_handle); + nrf_strerror_get(nrf_err), conn_handle); return NRF_ERROR_INVALID_STATE; } } - return err_code; + return nrf_err; } uint32_t smd_params_reply(uint16_t conn_handle, ble_gap_sec_params_t *sec_params, @@ -832,7 +833,7 @@ uint32_t smd_params_reply(uint16_t conn_handle, ble_gap_sec_params_t *sec_params __ASSERT_NO_MSG(module_initialized); uint8_t role = ble_conn_state_role(conn_handle); - uint32_t err_code = NRF_SUCCESS; + uint32_t nrf_err = NRF_SUCCESS; uint8_t sec_status = BLE_GAP_SEC_STATUS_SUCCESS; ble_gap_sec_keyset_t sec_keyset; @@ -880,12 +881,12 @@ uint32_t smd_params_reply(uint16_t conn_handle, ble_gap_sec_params_t *sec_params sec_keyset.keys_peer.p_pk = &peer_pk; } else if (sec_status != BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP) { /* Bonding is to be performed, prepare to receive bonding data. */ - err_code = sec_keyset_fill(conn_handle, role, public_key, - &sec_keyset); + nrf_err = sec_keyset_fill(conn_handle, role, public_key, + &sec_keyset); } } - if (err_code == NRF_SUCCESS) { + if (nrf_err == NRF_SUCCESS) { /* Everything OK, reply to SoftDevice. If an error happened, the user is given an * opportunity to change the parameters and retry the call. */ @@ -894,11 +895,11 @@ uint32_t smd_params_reply(uint16_t conn_handle, ble_gap_sec_params_t *sec_params aux_sec_params = (role == BLE_GAP_ROLE_PERIPH) ? sec_params : NULL; #endif /* CONFIG_SOFTDEVICE_PERIPHERAL */ - err_code = sd_ble_gap_sec_params_reply(conn_handle, sec_status, aux_sec_params, - &sec_keyset); + nrf_err = sd_ble_gap_sec_params_reply(conn_handle, sec_status, aux_sec_params, + &sec_keyset); } - return err_code; + return nrf_err; } uint32_t smd_link_secure(uint16_t conn_handle, ble_gap_sec_params_t *sec_params, diff --git a/lib/bluetooth/peer_manager/modules/security_manager.c b/lib/bluetooth/peer_manager/modules/security_manager.c index b6b112442f..33f73fe5f5 100644 --- a/lib/bluetooth/peer_manager/modules/security_manager.c +++ b/lib/bluetooth/peer_manager/modules/security_manager.c @@ -95,16 +95,16 @@ static void evt_send(struct pm_evt *event) * @brief Function for setting or clearing user flags based on error codes returned from @ref * smd_link_secure or @ref smd_params_reply. * - * @param[in] conn_handle The connection the call pertained to. - * @param[in] err_code The error code returned from @ref smd_link_secure or - * @ref smd_params_reply. - * @param[in] params_reply Whether the call was to @ref smd_params_reply. + * @param[in] conn_handle The connection the call pertained to. + * @param[in] nrf_err The error code returned from @ref smd_link_secure or + * @ref smd_params_reply. + * @param[in] params_reply Whether the call was to @ref smd_params_reply. */ -static void flags_set_from_err_code(uint16_t conn_handle, uint32_t err_code, bool params_reply) +static void flags_set_from_err_code(uint16_t conn_handle, uint32_t nrf_err, bool params_reply) { bool flag_value_busy = false; - if (err_code == NRF_ERROR_BUSY) { + if (nrf_err == NRF_ERROR_BUSY) { flag_value_busy = true; } else { flag_value_busy = false; @@ -134,21 +134,21 @@ static inline struct pm_evt new_evt(enum pm_evt_id evt_id, uint16_t conn_handle) /** * @brief Function for sending a PM_EVT_ERROR_UNEXPECTED event. * - * @param[in] conn_handle The connection handle the event pertains to. - * @param[in] err_code The unexpected error that occurred. + * @param[in] conn_handle The connection handle the event pertains to. + * @param[in] nrf_err The unexpected error that occurred. */ -static void send_unexpected_error(uint16_t conn_handle, uint32_t err_code) +static void send_unexpected_error(uint16_t conn_handle, uint32_t nrf_err) { struct pm_evt error_evt = new_evt(PM_EVT_ERROR_UNEXPECTED, conn_handle); - error_evt.params.error_unexpected.error = err_code; + error_evt.params.error_unexpected.error = nrf_err; evt_send(&error_evt); } /** * @brief Returns whether the LTK came from LESC bonding. * - * @param[in] peer_id The peer to check. + * @param[in] peer_id The peer to check. * * @return Whether the key is LESC or not. */ @@ -157,14 +157,14 @@ static bool key_is_lesc(uint16_t peer_id) struct pm_peer_data_bonding bonding_data = { 0 }; uint32_t bonding_data_size = sizeof(struct pm_peer_data_bonding); struct pm_peer_data peer_data; - uint32_t err_code; + uint32_t nrf_err; peer_data.all_data = &bonding_data; - err_code = pds_peer_data_read(peer_id, PM_PEER_DATA_ID_BONDING, &peer_data, - &bonding_data_size); + nrf_err = pds_peer_data_read(peer_id, PM_PEER_DATA_ID_BONDING, &peer_data, + &bonding_data_size); - return (err_code == NRF_SUCCESS) && (bonding_data.own_ltk.enc_info.lesc); + return (nrf_err == NRF_SUCCESS) && (bonding_data.own_ltk.enc_info.lesc); } /** @@ -172,17 +172,18 @@ static bool key_is_lesc(uint16_t peer_id) * @ref smd_params_reply. * * @param[in] conn_handle The connection the event pertains to. - * @param[in] err_code The error code returned from @ref smd_link_secure or + * @param[in] nrf_err The error code returned from @ref smd_link_secure or * @ref smd_params_reply. * @param[in] sec_params The security parameters attempted to pass in the call to * @ref smd_link_secure or @ref smd_params_reply. */ -static void events_send_from_err_code(uint16_t conn_handle, uint32_t err_code, +static void events_send_from_err_code(uint16_t conn_handle, uint32_t nrf_err, ble_gap_sec_params_t *sec_params) { - if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY) && - (err_code != NRF_ERROR_INVALID_STATE)) { - if (err_code == NRF_ERROR_TIMEOUT) { + if ((nrf_err != NRF_SUCCESS) && + (nrf_err != NRF_ERROR_BUSY) && + (nrf_err != NRF_ERROR_INVALID_STATE)) { + if (nrf_err == NRF_ERROR_TIMEOUT) { LOG_WRN("Cannot secure link because a previous security procedure " "ended in timeout. " "Disconnect and retry. smd_params_reply() or " @@ -202,8 +203,8 @@ static void events_send_from_err_code(uint16_t conn_handle, uint32_t err_code, } else { LOG_ERR("Could not perform security procedure. smd_params_reply() or " "smd_link_secure() returned %s. conn_handle: %d", - nrf_strerror_get(err_code), conn_handle); - send_unexpected_error(conn_handle, err_code); + nrf_strerror_get(nrf_err), conn_handle); + send_unexpected_error(conn_handle, nrf_err); } } } @@ -251,10 +252,10 @@ static struct sec_params_reply_context new_context_get(void) * @return Same return codes as @ref sm_link_secure. */ static uint32_t link_secure(uint16_t conn_handle, bool null_params, bool force_repairing, - bool send_events) + bool send_events) { - uint32_t err_code; - uint32_t return_err_code; + uint32_t nrf_err; + uint32_t return_nrf_err; ble_gap_sec_params_t *sec_params; if (null_params) { @@ -271,38 +272,38 @@ static uint32_t link_secure(uint16_t conn_handle, bool null_params, bool force_r } } - err_code = smd_link_secure(conn_handle, sec_params, force_repairing); + nrf_err = smd_link_secure(conn_handle, sec_params, force_repairing); - flags_set_from_err_code(conn_handle, err_code, false); + flags_set_from_err_code(conn_handle, nrf_err, false); - switch (err_code) { + switch (nrf_err) { case NRF_ERROR_BUSY: ble_conn_state_user_flag_set(conn_handle, flag_link_secure_null_params, null_params); ble_conn_state_user_flag_set(conn_handle, flag_link_secure_force_repairing, force_repairing); - return_err_code = NRF_SUCCESS; + return_nrf_err = NRF_SUCCESS; break; case NRF_SUCCESS: case NRF_ERROR_TIMEOUT: case BLE_ERROR_INVALID_CONN_HANDLE: case NRF_ERROR_INVALID_STATE: case NRF_ERROR_INVALID_DATA: - return_err_code = err_code; + return_nrf_err = nrf_err; break; default: LOG_ERR("Could not perform security procedure. smd_link_secure() returned %s. " "conn_handle: %d", - nrf_strerror_get(err_code), conn_handle); - return_err_code = NRF_ERROR_INTERNAL; + nrf_strerror_get(nrf_err), conn_handle); + return_nrf_err = NRF_ERROR_INTERNAL; break; } if (send_events) { - events_send_from_err_code(conn_handle, err_code, sec_params); + events_send_from_err_code(conn_handle, nrf_err, sec_params); } - return return_err_code; + return return_nrf_err; } /** @@ -315,7 +316,7 @@ static uint32_t link_secure(uint16_t conn_handle, bool null_params, bool force_r static void smd_params_reply_perform(uint16_t conn_handle, const ble_gap_sec_params_t *peer_params) { - uint32_t err_code; + uint32_t nrf_err; ble_gap_lesc_p256_pk_t *public_key; struct sec_params_reply_context context = new_context_get(); @@ -326,10 +327,10 @@ static void smd_params_reply_perform(uint16_t conn_handle, #else public_key = lesc_public_key; #endif /* CONFIG_PM_LESC */ - err_code = smd_params_reply(conn_handle, context.sec_params, public_key); + nrf_err = smd_params_reply(conn_handle, context.sec_params, public_key); - flags_set_from_err_code(conn_handle, err_code, true); - events_send_from_err_code(conn_handle, err_code, context.sec_params); + flags_set_from_err_code(conn_handle, nrf_err, true); + events_send_from_err_code(conn_handle, nrf_err, context.sec_params); } /** @@ -370,13 +371,13 @@ bool sm_sec_is_sufficient(uint16_t conn_handle, struct pm_conn_sec_status *sec_s { /* Set all bits in reserved to 1 so they are ignored in subsequent logic. */ struct pm_conn_sec_status sec_status = {.reserved = ~0}; - uint32_t err_code = sm_conn_sec_status_get(conn_handle, &sec_status); + uint32_t nrf_err = sm_conn_sec_status_get(conn_handle, &sec_status); __ASSERT_NO_MSG(sizeof(struct pm_conn_sec_status) == sizeof(uint8_t)); uint8_t unmet_reqs = (~(*((uint8_t *)&sec_status)) & *((uint8_t *)sec_status_req)); - return (err_code == NRF_SUCCESS) && !unmet_reqs; + return (nrf_err == NRF_SUCCESS) && !unmet_reqs; } #if defined(CONFIG_SOFTDEVICE_CENTRAL) @@ -505,10 +506,10 @@ uint32_t sm_init(void) __ASSERT_NO_MSG(!module_initialized); #if defined(CONFIG_PM_LESC) - uint32_t err_code = nrf_ble_lesc_init(); + uint32_t nrf_err = nrf_ble_lesc_init(); - if (err_code != NRF_SUCCESS) { - return err_code; + if (nrf_err) { + return nrf_err; } #endif @@ -680,10 +681,7 @@ uint32_t sm_lesc_public_key_set(ble_gap_lesc_p256_pk_t *public_key) uint32_t sm_link_secure(uint16_t conn_handle, bool force_repairing) { - uint32_t ret; - __ASSERT_NO_MSG(module_initialized); - ret = link_secure(conn_handle, false, force_repairing, false); - return ret; + return link_secure(conn_handle, false, force_repairing, false); } diff --git a/lib/bluetooth/peer_manager/peer_manager.c b/lib/bluetooth/peer_manager/peer_manager.c index e734b3ca4e..66ff4af500 100644 --- a/lib/bluetooth/peer_manager/peer_manager.c +++ b/lib/bluetooth/peer_manager/peer_manager.c @@ -65,15 +65,15 @@ static void evt_send(const struct pm_evt *pm_evt) /** @brief Function for initializing peer rank static variables. */ static void rank_vars_update(void) { - uint32_t err_code = + uint32_t nrf_err = pm_peer_ranks_get(&highest_ranked_peer, ¤t_highest_peer_rank, NULL, NULL); - if (err_code == NRF_ERROR_NOT_FOUND) { + if (nrf_err == NRF_ERROR_NOT_FOUND) { highest_ranked_peer = PM_PEER_ID_INVALID; current_highest_peer_rank = 0; } - peer_rank_initialized = ((err_code == NRF_SUCCESS) || (err_code == NRF_ERROR_NOT_FOUND)); + peer_rank_initialized = ((nrf_err == NRF_SUCCESS) || (nrf_err == NRF_ERROR_NOT_FOUND)); } #endif @@ -321,47 +321,47 @@ static void internal_state_reset(void) uint32_t pm_init(void) { - uint32_t err_code; + uint32_t nrf_err; - err_code = pds_init(); - if (err_code != NRF_SUCCESS) { + nrf_err = pds_init(); + if (nrf_err) { LOG_ERR("%s failed because pds_init() returned %s.", __func__, - nrf_strerror_get(err_code)); + nrf_strerror_get(nrf_err)); return NRF_ERROR_INTERNAL; } - err_code = pdb_init(); - if (err_code != NRF_SUCCESS) { + nrf_err = pdb_init(); + if (nrf_err) { LOG_ERR("%s failed because pdb_init() returned %s.", __func__, - nrf_strerror_get(err_code)); + nrf_strerror_get(nrf_err)); return NRF_ERROR_INTERNAL; } - err_code = sm_init(); - if (err_code != NRF_SUCCESS) { + nrf_err = sm_init(); + if (nrf_err) { LOG_ERR("%s failed because sm_init() returned %s.", __func__, - nrf_strerror_get(err_code)); + nrf_strerror_get(nrf_err)); return NRF_ERROR_INTERNAL; } - err_code = smd_init(); - if (err_code != NRF_SUCCESS) { + nrf_err = smd_init(); + if (nrf_err) { LOG_ERR("%s failed because smd_init() returned %s.", __func__, - nrf_strerror_get(err_code)); + nrf_strerror_get(nrf_err)); return NRF_ERROR_INTERNAL; } - err_code = gcm_init(); - if (err_code != NRF_SUCCESS) { + nrf_err = gcm_init(); + if (nrf_err) { LOG_ERR("%s failed because gcm_init() returned %s.", __func__, - nrf_strerror_get(err_code)); + nrf_strerror_get(nrf_err)); return NRF_ERROR_INTERNAL; } - err_code = gscm_init(); - if (err_code != NRF_SUCCESS) { + nrf_err = gscm_init(); + if (nrf_err) { LOG_ERR("%s failed because gscm_init() returned %s.", __func__, - nrf_strerror_get(err_code)); + nrf_strerror_get(nrf_err)); return NRF_ERROR_INTERNAL; } @@ -403,31 +403,24 @@ uint32_t pm_sec_params_set(ble_gap_sec_params_t *sec_params) return NRF_ERROR_INVALID_STATE; } - uint32_t err_code; - - err_code = sm_sec_params_set(sec_params); - - /* NRF_ERROR_INVALID_PARAM if parameters are invalid, - * NRF_SUCCESS otherwise. - */ - return err_code; + return sm_sec_params_set(sec_params); } uint32_t pm_conn_secure(uint16_t conn_handle, bool force_repairing) { + uint32_t nrf_err; + if (!module_initialized) { return NRF_ERROR_INVALID_STATE; } - uint32_t err_code; - - err_code = sm_link_secure(conn_handle, force_repairing); + nrf_err = sm_link_secure(conn_handle, force_repairing); - if (err_code == NRF_ERROR_INVALID_STATE) { - err_code = NRF_ERROR_BUSY; + if (nrf_err == NRF_ERROR_INVALID_STATE) { + nrf_err = NRF_ERROR_BUSY; } - return err_code; + return nrf_err; } uint32_t pm_conn_exclude(uint16_t conn_handle, const void *context) @@ -666,7 +659,7 @@ static bool peer_is_irk(const ble_gap_irk_t *const irk) uint32_t pm_peer_id_list(uint16_t *peer_list, uint32_t *const list_size, uint16_t first_peer_id, enum pm_peer_id_list_skip skip_id) { - uint32_t err_code; + uint32_t nrf_err; uint32_t size; uint32_t current_size = 0; struct pm_peer_data pm_car_data; @@ -715,13 +708,13 @@ uint32_t pm_peer_id_list(uint16_t *peer_list, uint32_t *const list_size, pm_bond_data.all_data = &bonding_data; - err_code = pds_peer_data_read(current_peer_id, PM_PEER_DATA_ID_BONDING, - &pm_bond_data, &bonding_data_size); + nrf_err = pds_peer_data_read(current_peer_id, PM_PEER_DATA_ID_BONDING, + &pm_bond_data, &bonding_data_size); - if (err_code == NRF_ERROR_NOT_FOUND) { + if (nrf_err == NRF_ERROR_NOT_FOUND) { skip = true; - } else if (err_code != NRF_SUCCESS) { - return err_code; + } else if (nrf_err) { + return nrf_err; } /* Check data */ @@ -748,14 +741,14 @@ uint32_t pm_peer_id_list(uint16_t *peer_list, uint32_t *const list_size, pm_car_data.all_data = ¢ral_addr_res; - err_code = pds_peer_data_read(current_peer_id, - PM_PEER_DATA_ID_CENTRAL_ADDR_RES, - &pm_car_data, ¢ral_addr_res_size); + nrf_err = pds_peer_data_read(current_peer_id, + PM_PEER_DATA_ID_CENTRAL_ADDR_RES, + &pm_car_data, ¢ral_addr_res_size); - if (err_code == NRF_ERROR_NOT_FOUND) { + if (nrf_err == NRF_ERROR_NOT_FOUND) { skip = true; - } else if (err_code != NRF_SUCCESS) { - return err_code; + } else if (nrf_err) { + return nrf_err; } /* Check data */ @@ -889,7 +882,7 @@ uint32_t pm_peer_data_delete(uint16_t peer_id, enum pm_peer_data_id data_id) uint32_t pm_peer_new(uint16_t *new_peer_id, struct pm_peer_data_bonding *bonding_data, uint32_t *token) { - uint32_t err_code; + uint32_t nrf_err; uint16_t peer_id; uint16_t peer_id_iter; struct pm_peer_data_const peer_data; @@ -932,15 +925,15 @@ uint32_t pm_peer_new(uint16_t *new_peer_id, struct pm_peer_data_bonding *bonding peer_data.bonding_data = bonding_data; peer_data.length_words = BYTES_TO_WORDS(sizeof(struct pm_peer_data_bonding)); - err_code = pds_peer_data_store(*new_peer_id, &peer_data, token); + nrf_err = pds_peer_data_store(*new_peer_id, &peer_data, token); - if (err_code != NRF_SUCCESS) { - uint32_t err_code_free = im_peer_free(*new_peer_id); + if (nrf_err) { + uint32_t nrf_err_free = im_peer_free(*new_peer_id); - if (err_code_free != NRF_SUCCESS) { + if (nrf_err_free) { LOG_ERR("Fatal error during cleanup of a failed call to %s. im_peer_free() " "returned %s. peer_id: %d", - __func__, nrf_strerror_get(err_code_free), *new_peer_id); + __func__, nrf_strerror_get(nrf_err_free), *new_peer_id); return NRF_ERROR_INTERNAL; } @@ -949,7 +942,7 @@ uint32_t pm_peer_new(uint16_t *new_peer_id, struct pm_peer_data_bonding *bonding * NRF_ERROR_INVALID_ADDR, if bonding data is unaligned. * NRF_ERROR_INTENRAL, on internal error. */ - return err_code; + return nrf_err; } return NRF_SUCCESS; @@ -989,12 +982,12 @@ uint32_t pm_peers_delete(void) } while (current_peer_id != PM_PEER_ID_INVALID) { - uint32_t err_code = pm_peer_delete(current_peer_id); + uint32_t nrf_err = pm_peer_delete(current_peer_id); - if (err_code != NRF_SUCCESS) { + if (nrf_err) { LOG_ERR("%s() failed because a call to pm_peer_delete() returned %s. " "peer_id: %d", - __func__, nrf_strerror_get(err_code), current_peer_id); + __func__, nrf_strerror_get(nrf_err), current_peer_id); return NRF_ERROR_INTERNAL; } @@ -1018,7 +1011,7 @@ uint32_t pm_peer_ranks_get(uint16_t *highest_ranked_peer, uint32_t *highest_rank uint32_t peer_rank = 0; uint32_t length = sizeof(peer_rank); struct pm_peer_data peer_data = {.peer_rank = &peer_rank}; - uint32_t err_code = + uint32_t nrf_err = pds_peer_data_read(peer_id, PM_PEER_DATA_ID_PEER_RANK, &peer_data, &length); struct { uint32_t highest; @@ -1032,13 +1025,13 @@ uint32_t pm_peer_ranks_get(uint16_t *highest_ranked_peer, uint32_t *highest_rank .lowest_peer = PM_PEER_ID_INVALID, }; - if (err_code == NRF_ERROR_INVALID_PARAM) { + if (nrf_err == NRF_ERROR_INVALID_PARAM) { /* No peer IDs exist. */ return NRF_ERROR_NOT_FOUND; } - while ((err_code == NRF_SUCCESS) || (err_code == NRF_ERROR_NOT_FOUND)) { - if (err_code == NRF_SUCCESS) { + while ((nrf_err == NRF_SUCCESS) || (nrf_err == NRF_ERROR_NOT_FOUND)) { + if (nrf_err == NRF_SUCCESS) { if (peer_rank >= rank.highest) { rank.highest = peer_rank; rank.highest_peer = peer_id; @@ -1049,15 +1042,15 @@ uint32_t pm_peer_ranks_get(uint16_t *highest_ranked_peer, uint32_t *highest_rank } } peer_id = pds_next_peer_id_get(peer_id); - err_code = + nrf_err = pds_peer_data_read(peer_id, PM_PEER_DATA_ID_PEER_RANK, &peer_data, &length); } if (peer_id == PM_PEER_ID_INVALID) { if ((rank.highest_peer == PM_PEER_ID_INVALID) || (rank.lowest_peer == PM_PEER_ID_INVALID)) { - err_code = NRF_ERROR_NOT_FOUND; + nrf_err = NRF_ERROR_NOT_FOUND; } else { - err_code = NRF_SUCCESS; + nrf_err = NRF_SUCCESS; } if (highest_ranked_peer != NULL) { @@ -1074,10 +1067,10 @@ uint32_t pm_peer_ranks_get(uint16_t *highest_ranked_peer, uint32_t *highest_rank } } else { LOG_ERR("Could not retrieve ranks. pdb_peer_data_load() returned %s. peer_id: %d", - nrf_strerror_get(err_code), peer_id); - err_code = NRF_ERROR_INTERNAL; + nrf_strerror_get(nrf_err), peer_id); + nrf_err = NRF_ERROR_INTERNAL; } - return err_code; + return nrf_err; #endif } @@ -1098,7 +1091,7 @@ uint32_t pm_peer_rank_highest(uint16_t peer_id) return NRF_ERROR_INVALID_STATE; } - uint32_t err_code; + uint32_t nrf_err; struct pm_peer_data_const peer_data = { .length_words = BYTES_TO_WORDS(sizeof(current_highest_peer_rank)), .data_id = PM_PEER_DATA_ID_PEER_RANK, @@ -1109,7 +1102,7 @@ uint32_t pm_peer_rank_highest(uint16_t peer_id) } if (!peer_rank_initialized || (peer_rank_token != PM_STORE_TOKEN_INVALID)) { - err_code = NRF_ERROR_BUSY; + nrf_err = NRF_ERROR_BUSY; } else { if ((peer_id == highest_ranked_peer) && (current_highest_peer_rank > 0)) { struct pm_evt pm_evt; @@ -1117,7 +1110,7 @@ uint32_t pm_peer_rank_highest(uint16_t peer_id) /* The reported peer is already regarded as highest (provided it has an * index at all) */ - err_code = NRF_SUCCESS; + nrf_err = NRF_SUCCESS; memset(&pm_evt, 0, sizeof(struct pm_evt)); pm_evt.evt_id = PM_EVT_PEER_DATA_UPDATE_SUCCEEDED; @@ -1132,31 +1125,31 @@ uint32_t pm_peer_rank_highest(uint16_t peer_id) evt_send(&pm_evt); } else { if (current_highest_peer_rank == UINT32_MAX) { - err_code = NRF_ERROR_DATA_SIZE; + nrf_err = NRF_ERROR_DATA_SIZE; } else { current_highest_peer_rank += 1; - err_code = pds_peer_data_store(peer_id, &peer_data, - &peer_rank_token); - if (err_code != NRF_SUCCESS) { + nrf_err = pds_peer_data_store(peer_id, &peer_data, + &peer_rank_token); + if (nrf_err) { peer_rank_token = PM_STORE_TOKEN_INVALID; current_highest_peer_rank -= 1; /* Assume INVALID_PARAM * refers to peer_id, not * data_id. */ - if ((err_code != NRF_ERROR_BUSY) && - (err_code != NRF_ERROR_RESOURCES) && - (err_code != NRF_ERROR_INVALID_PARAM)) { + if ((nrf_err != NRF_ERROR_BUSY) && + (nrf_err != NRF_ERROR_RESOURCES) && + (nrf_err != NRF_ERROR_INVALID_PARAM)) { LOG_ERR("Could not update rank. " "pdb_raw_store() returned %s. " "peer_id: %d", - nrf_strerror_get(err_code), peer_id); - err_code = NRF_ERROR_INTERNAL; + nrf_strerror_get(nrf_err), peer_id); + nrf_err = NRF_ERROR_INTERNAL; } } } } } - return err_code; + return nrf_err; #endif } diff --git a/lib/bm_buttons/bm_buttons.c b/lib/bm_buttons/bm_buttons.c index 3355b98c30..fc48945ab4 100644 --- a/lib/bm_buttons/bm_buttons.c +++ b/lib/bm_buttons/bm_buttons.c @@ -91,12 +91,12 @@ ISR_DIRECT_DECLARE(gpiote_30_direct_isr) static int gpiote_init(void) { - int err; + nrfx_err_t nrfx_err; if (!nrfx_gpiote_init_check(&gpiote20_instance)) { - err = nrfx_gpiote_init(&gpiote20_instance, 0); - if (err != NRFX_SUCCESS) { - LOG_ERR("Failed to initialize gpiote20, err: 0x%08X", err); + nrfx_err = nrfx_gpiote_init(&gpiote20_instance, 0); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("Failed to initialize gpiote20, nrfx_err: 0x%08X", nrfx_err); return -EIO; } @@ -106,9 +106,9 @@ static int gpiote_init(void) } if (!nrfx_gpiote_init_check(&gpiote30_instance)) { - err = nrfx_gpiote_init(&gpiote30_instance, 0); - if (err != NRFX_SUCCESS) { - LOG_ERR("Failed to initialize gpiote30, err: 0x%08X", err); + nrfx_err = nrfx_gpiote_init(&gpiote30_instance, 0); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("Failed to initialize gpiote30, nrfx_err: 0x%08X", nrfx_err); return -EIO; } @@ -123,13 +123,13 @@ static int gpiote_init(void) static int gpiote_input_configure(nrfx_gpiote_pin_t pin, const nrfx_gpiote_input_pin_config_t *input_config) { - int err; + nrfx_err_t nrfx_err; const nrfx_gpiote_t *gpiote_inst = gpiote_get(NRF_PIN_NUMBER_TO_PORT(pin)); - err = nrfx_gpiote_input_configure(gpiote_inst, pin, input_config); - if (err != NRFX_SUCCESS) { - LOG_ERR("nrfx_gpiote_input_configure, err: 0x%08X", err); + nrfx_err = nrfx_gpiote_input_configure(gpiote_inst, pin, input_config); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("nrfx_gpiote_input_configure, nrfx_err: 0x%08X", nrfx_err); return -EIO; } diff --git a/samples/bluetooth/ble_cgms/src/main.c b/samples/bluetooth/ble_cgms/src/main.c index 68e08a1829..66f0824431 100644 --- a/samples/bluetooth/ble_cgms/src/main.c +++ b/samples/bluetooth/ble_cgms/src/main.c @@ -165,8 +165,8 @@ static void glucose_meas_timeout_handler(void *context) ble_cgms.sensor_status.time_offset = current_time_offset; nrf_err = ble_cgms_update_status(&ble_cgms, &ble_cgms.sensor_status); - if (nrf_err != NRF_SUCCESS) { - LOG_ERR("Failed to update BLE CGMS status, nrf_error %d", nrf_err); + if (nrf_err) { + LOG_ERR("Failed to update BLE CGMS status, nrf_error %#x", nrf_err); } } @@ -202,17 +202,17 @@ static int timers_init(void) * @details This function sets up all the necessary GAP (Generic Access Profile) parameters of the * device including the device name, appearance, and the preferred connection parameters. */ -static int gap_params_init(void) +static uint32_t gap_params_init(void) { uint32_t nrf_err; nrf_err = sd_ble_gap_appearance_set(BLE_APPEARANCE_GENERIC_GLUCOSE_METER); - if (nrf_err != NRF_SUCCESS) { - LOG_ERR("Failed to set GAP appearance, nrf_error %d", nrf_err); - return -1; + if (nrf_err) { + LOG_ERR("Failed to set GAP appearance, nrf_error %#x", nrf_err); + return nrf_err; } - return 0; + return NRF_SUCCESS; } static void cgms_evt_handler(struct ble_cgms *cgms, const struct ble_cgms_evt *evt) @@ -295,7 +295,7 @@ uint16_t qwr_evt_handler(struct ble_qwr *qwr, const struct ble_qwr_evt *evt) * * @details Initialize the Glucose, Battery, and Device Information services. */ -static int services_init(void) +static uint32_t services_init(void) { int err; uint32_t nrf_err; @@ -340,9 +340,9 @@ static int services_init(void) ble_cgms.comm_interval = CONFIG_GLUCOSE_MEAS_INTERVAL; nrf_err = ble_cgms_init(&ble_cgms, &cgms_config); - if (nrf_err != NRF_SUCCESS) { - LOG_ERR("Failed to initialize CGMS service, nrf_error %d", nrf_err); - return -EIO; + if (nrf_err) { + LOG_ERR("Failed to initialize CGMS service, nrf_error %#x", nrf_err); + return nrf_err; } ble_cgms.comm_interval = CONFIG_GLUCOSE_MEAS_INTERVAL; @@ -359,10 +359,10 @@ static int services_init(void) err = ble_dis_init(); if (err) { LOG_ERR("Failed to initialize DIS service, err %d", err); - return -1; + return err; } - return 0; + return NRF_SUCCESS; } /** @brief Function for initializing the sensor simulators. */ @@ -421,8 +421,8 @@ void on_conn_params_evt(const struct ble_conn_params_evt *evt) switch (evt->id) { case BLE_CONN_PARAMS_EVT_REJECTED: nrf_err = sd_ble_gap_disconnect(conn_handle, BLE_HCI_CONN_INTERVAL_UNACCEPTABLE); - if (nrf_err != NRF_SUCCESS) { - LOG_ERR("Failed to disconnect BLE GAP, nrf_error %d", nrf_err); + if (nrf_err) { + LOG_ERR("Failed to disconnect BLE GAP, nrf_error %#x", nrf_err); } LOG_ERR("Disconnected from peer, unacceptable conn params"); break; @@ -456,13 +456,13 @@ static void on_ble_evt(const ble_evt_t *evt, void *ctx) } nrf_err = ble_cgms_conn_handle_assign(&ble_cgms, conn_handle); - if (nrf_err != NRF_SUCCESS) { - LOG_ERR("Failed to assign BLE CGMS conn handle, nrf_error %d", nrf_err); + if (nrf_err) { + LOG_ERR("Failed to assign BLE CGMS conn handle, nrf_error %#x", nrf_err); } nrf_err = sd_ble_gatts_sys_attr_set(conn_handle, NULL, 0, 0); - if (nrf_err != NRF_SUCCESS) { - LOG_ERR("Failed to set system attributes, nrf_error %d", nrf_err); + if (nrf_err) { + LOG_ERR("Failed to set system attributes, nrf_error %#x", nrf_err); } break; @@ -478,8 +478,8 @@ static void on_ble_evt(const ble_evt_t *evt, void *ctx) LOG_DBG("GATT Client Timeout."); nrf_err = sd_ble_gap_disconnect(evt->evt.gattc_evt.conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); - if (nrf_err != NRF_SUCCESS) { - LOG_ERR("Failed to disconnect GAP, nrf_error %d", nrf_err); + if (nrf_err) { + LOG_ERR("Failed to disconnect GAP, nrf_error %#x", nrf_err); } break; case BLE_GAP_EVT_AUTH_STATUS: @@ -492,8 +492,8 @@ 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 */ nrf_err = sd_ble_gatts_sys_attr_set(conn_handle, NULL, 0, 0); - if (nrf_err != NRF_SUCCESS) { - LOG_ERR("Failed to set system attributes, nrf_error %d", nrf_err); + if (nrf_err) { + LOG_ERR("Failed to set system attributes, nrf_error %#x", nrf_err); } break; case BLE_GATTS_EVT_TIMEOUT: @@ -501,8 +501,8 @@ static void on_ble_evt(const ble_evt_t *evt, void *ctx) LOG_DBG("GATT Server Timeout."); nrf_err = sd_ble_gap_disconnect(evt->evt.gatts_evt.conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); - if (nrf_err != NRF_SUCCESS) { - LOG_ERR("Failed to disconnect GAP, nrf_error %d", nrf_err); + if (nrf_err) { + LOG_ERR("Failed to disconnect GAP, nrf_error %#x", nrf_err); } break; } @@ -728,8 +728,8 @@ int main(void) if (err) { goto idle; } - err = gap_params_init(); - if (err) { + nrf_err = gap_params_init(); + if (nrf_err) { goto idle; } nrf_err = advertising_init(); diff --git a/samples/bluetooth/ble_hids_keyboard/src/main.c b/samples/bluetooth/ble_hids_keyboard/src/main.c index c1bc881125..c16e3019ac 100644 --- a/samples/bluetooth/ble_hids_keyboard/src/main.c +++ b/samples/bluetooth/ble_hids_keyboard/src/main.c @@ -155,7 +155,7 @@ void report_fifo_process(void) report.data = keys; nrf_err = ble_hids_inp_rep_send(&ble_hids, conn_handle, &report); - if (nrf_err != NRF_SUCCESS && nrf_err != BLE_ERROR_GATTS_SYS_ATTR_MISSING) { + if (nrf_err && nrf_err != BLE_ERROR_GATTS_SYS_ATTR_MISSING) { LOG_ERR("Failed to send queued input report, nrf_error %#x", nrf_err); } } @@ -269,8 +269,7 @@ static void ble_adv_evt_handler(struct ble_adv *ble_adv, const struct ble_adv_ev nrf_gpio_pin_write(BOARD_PIN_LED_0, !BOARD_LED_ACTIVE_STATE); break; case BLE_ADV_EVT_WHITELIST_REQUEST: - nrf_err = pm_whitelist_get(whitelist_addrs, &addr_cnt, - whitelist_irks, &irk_cnt); + nrf_err = pm_whitelist_get(whitelist_addrs, &addr_cnt, whitelist_irks, &irk_cnt); if (nrf_err) { LOG_ERR("Failed to get whitelist, nrf_error %#x", nrf_err); } @@ -322,7 +321,7 @@ static void ble_adv_evt_handler(struct ble_adv *ble_adv, const struct ble_adv_ev static void on_hid_rep_char_write(const struct ble_hids_evt *evt) { - uint32_t err; + uint32_t nrf_err; uint8_t report_val; uint8_t report_index; @@ -335,11 +334,11 @@ static void on_hid_rep_char_write(const struct ble_hids_evt *evt) */ __ASSERT_NO_MSG(CONFIG_BLE_HIDS_OUTPUT_REPORT_MAX_LEN == 1); - err = ble_hids_outp_rep_get(&ble_hids, report_index, - CONFIG_BLE_HIDS_OUTPUT_REPORT_MAX_LEN, 0, - conn_handle, &report_val); - if (err != NRF_SUCCESS) { - LOG_ERR("ble_hids_outp_rep_get failed, nrf_error %#x", err); + nrf_err = ble_hids_outp_rep_get(&ble_hids, report_index, + CONFIG_BLE_HIDS_OUTPUT_REPORT_MAX_LEN, 0, + conn_handle, &report_val); + if (nrf_err) { + LOG_ERR("ble_hids_outp_rep_get failed, nrf_error %#x", nrf_err); return; } @@ -582,7 +581,7 @@ static int on_key_press(struct ble_hids *hids, const char key, bool pressed) } nrf_err = ble_hids_inp_rep_send(hids, conn_handle, &inp_rep); - if (nrf_err != NRF_SUCCESS && nrf_err != BLE_ERROR_GATTS_SYS_ATTR_MISSING) { + if (nrf_err && nrf_err != BLE_ERROR_GATTS_SYS_ATTR_MISSING) { if (nrf_err == NRF_ERROR_RESOURCES) { return report_fifo_put(&inp_rep); } @@ -595,7 +594,7 @@ static int on_key_press(struct ble_hids *hids, const char key, bool pressed) static void num_comp_reply(uint16_t conn_handle, bool accept) { uint8_t key_type; - uint32_t err; + uint32_t nrf_err; if (accept) { LOG_INF("Numeric Match. Conn handle: %d", conn_handle); @@ -605,9 +604,9 @@ static void num_comp_reply(uint16_t conn_handle, bool accept) key_type = BLE_GAP_AUTH_KEY_TYPE_NONE; } - err = sd_ble_gap_auth_key_reply(conn_handle, key_type, NULL); - if (err != NRF_SUCCESS) { - LOG_ERR("Failed to reply auth request, err %d", err); + nrf_err = sd_ble_gap_auth_key_reply(conn_handle, key_type, NULL); + if (nrf_err) { + LOG_ERR("Failed to reply auth request, nrf_error %#x", nrf_err); } } @@ -667,54 +666,54 @@ static void button_handler(uint8_t pin, uint8_t action) static void whitelist_set(enum pm_peer_id_list_skip skip) { - uint32_t err; + uint32_t nrf_err; uint16_t peer_ids[BLE_GAP_WHITELIST_ADDR_MAX_COUNT]; uint32_t peer_id_count = BLE_GAP_WHITELIST_ADDR_MAX_COUNT; - err = pm_peer_id_list(peer_ids, &peer_id_count, PM_PEER_ID_INVALID, skip); - if (err) { - LOG_ERR("Failed to get peer id list, err %d", err); + nrf_err = pm_peer_id_list(peer_ids, &peer_id_count, PM_PEER_ID_INVALID, skip); + if (nrf_err) { + LOG_ERR("Failed to get peer id list, nrf_error %#x", nrf_err); } LOG_INF("Whitelisted peers: %d, max %d", peer_id_count, BLE_GAP_WHITELIST_ADDR_MAX_COUNT); - err = pm_whitelist_set(peer_ids, peer_id_count); - if (err) { - LOG_ERR("Failed to set whitelist, err %d", err); + nrf_err = pm_whitelist_set(peer_ids, peer_id_count); + if (nrf_err) { + LOG_ERR("Failed to set whitelist, nrf_error %#x", nrf_err); } } static void identities_set(enum pm_peer_id_list_skip skip) { - uint32_t err; + uint32_t nrf_err; uint16_t peer_ids[BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT]; uint32_t peer_id_count = BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT; - err = pm_peer_id_list(peer_ids, &peer_id_count, PM_PEER_ID_INVALID, skip); - if (err) { - LOG_ERR("Failed to get peer id list, err %d", err); + nrf_err = pm_peer_id_list(peer_ids, &peer_id_count, PM_PEER_ID_INVALID, skip); + if (nrf_err) { + LOG_ERR("Failed to get peer id list, nrf_error %#x", nrf_err); } - err = pm_device_identities_list_set(peer_ids, peer_id_count); - if (err) { - LOG_ERR("Failed to set peer manager identity list, err %d", err); + nrf_err = pm_device_identities_list_set(peer_ids, peer_id_count); + if (nrf_err) { + LOG_ERR("Failed to set peer manager identity list, nrf_error %#x", nrf_err); } } static void delete_bonds(void) { - uint32_t err; + uint32_t nrf_err; LOG_INF("Erasing bonds"); - err = pm_peers_delete(); - if (err) { - LOG_ERR("Failed to delete peers, err %d", err); + nrf_err = pm_peers_delete(); + if (nrf_err) { + LOG_ERR("Failed to delete peers, nrf_error %#x", nrf_err); } } -static int advertising_start(bool erase_bonds) +static uint32_t advertising_start(bool erase_bonds) { uint32_t nrf_err = NRF_SUCCESS; @@ -764,14 +763,14 @@ static void pm_evt_handler(struct pm_evt const *evt) } } -static int peer_manager_init(void) +static uint32_t peer_manager_init(void) { ble_gap_sec_params_t sec_param; - int err; + uint32_t nrf_err; - err = pm_init(); - if (err) { - return -EFAULT; + nrf_err = pm_init(); + if (nrf_err) { + return nrf_err; } memset(&sec_param, 0, sizeof(ble_gap_sec_params_t)); @@ -792,19 +791,19 @@ static int peer_manager_init(void) .kdist_peer.id = 1, }; - err = pm_sec_params_set(&sec_param); - if (err) { - LOG_ERR("pm_sec_params_set() failed, err: %d", err); - return -EFAULT; + nrf_err = pm_sec_params_set(&sec_param); + if (nrf_err) { + LOG_ERR("pm_sec_params_set() failed, nrf_error %#x", nrf_err); + return nrf_err; } - err = pm_register(pm_evt_handler); - if (err) { - LOG_ERR("pm_register() failed, err: %d", err); - return -EFAULT; + nrf_err = pm_register(pm_evt_handler); + if (nrf_err) { + LOG_ERR("pm_register() failed, nrf_error %#x", nrf_err); + return nrf_err; } - return 0; + return NRF_SUCCESS; } uint16_t ble_qwr_evt_handler(struct ble_qwr *qwr, const struct ble_qwr_evt *qwr_evt) @@ -944,9 +943,9 @@ int main(void) LOG_INF("Bluetooth is enabled!"); - err = peer_manager_init(); - if (err) { - LOG_ERR("Failed to initialize Peer Manager, err %d", err); + nrf_err = peer_manager_init(); + if (nrf_err) { + LOG_ERR("Failed to initialize Peer Manager, nrf_error %#x", nrf_err); goto idle; } @@ -969,16 +968,16 @@ int main(void) } nrf_err = hids_init(); - if (nrf_err != NRF_SUCCESS) { - LOG_ERR("Failed to initialize HIDS, nrf_error %#x", err); + if (nrf_err) { + LOG_ERR("Failed to initialize HIDS, nrf_error %#x", nrf_err); goto idle; } LOG_INF("HIDS initialized"); - err = sd_ble_gap_appearance_set(BLE_APPEARANCE_HID_KEYBOARD); - if (err) { - LOG_ERR("Failed to sd_ble_gap_appearance_set, err %d", err); + nrf_err = sd_ble_gap_appearance_set(BLE_APPEARANCE_HID_KEYBOARD); + if (nrf_err) { + LOG_ERR("Failed to sd_ble_gap_appearance_set, nrf_error %#x", nrf_err); goto idle; } @@ -995,9 +994,9 @@ int main(void) goto idle; } - err = advertising_start(erase_bonds); - if (err) { - LOG_ERR("Failed to start advertising, err %d", err); + nrf_err = advertising_start(erase_bonds); + if (nrf_err) { + LOG_ERR("Failed to start advertising, nrf_error %#x", nrf_err); goto idle; } diff --git a/samples/bluetooth/ble_hids_mouse/src/main.c b/samples/bluetooth/ble_hids_mouse/src/main.c index 9fe623c0c6..3847e00d04 100644 --- a/samples/bluetooth/ble_hids_mouse/src/main.c +++ b/samples/bluetooth/ble_hids_mouse/src/main.c @@ -123,7 +123,7 @@ static void battery_level_meas_timeout_handler(void *context) static void on_ble_evt(const ble_evt_t *evt, void *ctx) { - uint32_t err; + int err; switch (evt->header.evt_id) { case BLE_GAP_EVT_CONNECTED: @@ -456,7 +456,7 @@ static void mouse_movement_send(struct ble_hids *hids, int16_t delta_x, int16_t nrf_err = ble_hids_inp_rep_send(hids, conn_handle, &inp_rep); } - if (nrf_err != NRF_SUCCESS && nrf_err != BLE_ERROR_GATTS_SYS_ATTR_MISSING) { + if (nrf_err && nrf_err != BLE_ERROR_GATTS_SYS_ATTR_MISSING) { LOG_ERR("Failed to send input report, nrf_error %#x", nrf_err); } } @@ -464,7 +464,7 @@ static void mouse_movement_send(struct ble_hids *hids, int16_t delta_x, int16_t static void num_comp_reply(uint16_t conn_handle, bool accept) { uint8_t key_type; - uint32_t err; + uint32_t nrf_err; if (accept) { LOG_INF("Numeric Match. Conn handle: %d", conn_handle); @@ -474,9 +474,9 @@ static void num_comp_reply(uint16_t conn_handle, bool accept) key_type = BLE_GAP_AUTH_KEY_TYPE_NONE; } - err = sd_ble_gap_auth_key_reply(conn_handle, key_type, NULL); - if (err != NRF_SUCCESS) { - LOG_ERR("Failed to reply auth request, err %d", err); + nrf_err = sd_ble_gap_auth_key_reply(conn_handle, key_type, NULL); + if (nrf_err) { + LOG_ERR("Failed to reply auth request, nrf_error %#x", nrf_err); } auth_key_request = false; @@ -518,56 +518,56 @@ static void button_handler(uint8_t pin, uint8_t action) static void whitelist_set(enum pm_peer_id_list_skip skip) { - uint32_t err; + uint32_t nrf_err; uint16_t peer_ids[BLE_GAP_WHITELIST_ADDR_MAX_COUNT]; uint32_t peer_id_count = BLE_GAP_WHITELIST_ADDR_MAX_COUNT; - err = pm_peer_id_list(peer_ids, &peer_id_count, PM_PEER_ID_INVALID, skip); - if (err) { - LOG_ERR("Failed to get peer id list, err %d", err); + nrf_err = pm_peer_id_list(peer_ids, &peer_id_count, PM_PEER_ID_INVALID, skip); + if (nrf_err) { + LOG_ERR("Failed to get peer id list, nrf_error %#x", nrf_err); } LOG_INF("whitelist_peer_cnt %d, MAX_PEERS_WLIST %d", peer_id_count, BLE_GAP_WHITELIST_ADDR_MAX_COUNT); - err = pm_whitelist_set(peer_ids, peer_id_count); - if (err) { - LOG_ERR("Failed to set whitelist, err %d", err); + nrf_err = pm_whitelist_set(peer_ids, peer_id_count); + if (nrf_err) { + LOG_ERR("Failed to set whitelist, nrf_error %#x", nrf_err); } } static void identities_set(enum pm_peer_id_list_skip skip) { - uint32_t err; + uint32_t nrf_err; uint16_t peer_ids[BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT]; uint32_t peer_id_count = BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT; - err = pm_peer_id_list(peer_ids, &peer_id_count, PM_PEER_ID_INVALID, skip); - if (err) { - LOG_ERR("Failed to get peer id list, err %d", err); + nrf_err = pm_peer_id_list(peer_ids, &peer_id_count, PM_PEER_ID_INVALID, skip); + if (nrf_err) { + LOG_ERR("Failed to get peer id list, nrf_error %#x", nrf_err); } - err = pm_device_identities_list_set(peer_ids, peer_id_count); - if (err) { - LOG_ERR("Failed to set identities list, err %d", err); + nrf_err = pm_device_identities_list_set(peer_ids, peer_id_count); + if (nrf_err) { + LOG_ERR("Failed to set identities list, nrf_error %#x", nrf_err); } } static void delete_bonds(void) { - uint32_t err; + uint32_t nrf_err; LOG_INF("Erase bonds!"); - err = pm_peers_delete(); - if (err) { - LOG_ERR("Failed to delete peers, err %d", err); + nrf_err = pm_peers_delete(); + if (nrf_err) { + LOG_ERR("Failed to delete peers, nrf_error %#x", nrf_err); } } static uint32_t advertising_start(bool erase_bonds) { - int nrf_err = NRF_SUCCESS; + uint32_t nrf_err = NRF_SUCCESS; if (erase_bonds) { delete_bonds(); @@ -614,14 +614,14 @@ static void pm_evt_handler(struct pm_evt const *evt) } } -static int peer_manager_init(void) +static uint32_t peer_manager_init(void) { ble_gap_sec_params_t sec_param; - int err; + uint32_t nrf_err; - err = pm_init(); - if (err) { - return -EFAULT; + nrf_err = pm_init(); + if (nrf_err) { + return nrf_err; } memset(&sec_param, 0, sizeof(ble_gap_sec_params_t)); @@ -642,19 +642,19 @@ static int peer_manager_init(void) .kdist_peer.id = 1, }; - err = pm_sec_params_set(&sec_param); - if (err) { - LOG_ERR("pm_sec_params_set() failed, err: %d", err); - return -EFAULT; + nrf_err = pm_sec_params_set(&sec_param); + if (nrf_err) { + LOG_ERR("pm_sec_params_set() failed, nrf_error %#x", nrf_err); + return nrf_err; } - err = pm_register(pm_evt_handler); - if (err) { - LOG_ERR("pm_register() failed, err: %d", err); - return -EFAULT; + nrf_err = pm_register(pm_evt_handler); + if (nrf_err) { + LOG_ERR("pm_register() failed, nrf_error %#x", nrf_err); + return nrf_err; } - return 0; + return NRF_SUCCESS; } uint16_t ble_qwr_evt_handler(struct ble_qwr *qwr, const struct ble_qwr_evt *qwr_evt) @@ -792,9 +792,9 @@ int main(void) LOG_INF("Bluetooth enabled!"); - err = peer_manager_init(); - if (err) { - LOG_ERR("Failed to initialize Peer Manager, err %d", err); + nrf_err = peer_manager_init(); + if (nrf_err) { + LOG_ERR("Failed to initialize Peer Manager, nrf_error %#x", nrf_err); goto idle; } @@ -817,7 +817,7 @@ int main(void) } nrf_err = hids_init(); - if (nrf_err != NRF_SUCCESS) { + if (nrf_err) { LOG_ERR("Failed to initialize HIDS, nrf_error %#x", nrf_err); goto idle; } @@ -837,9 +837,9 @@ int main(void) goto idle; } - err = advertising_start(erase_bonds); - if (err) { - LOG_ERR("Failed to start advertising, err %d", err); + nrf_err = advertising_start(erase_bonds); + if (nrf_err) { + LOG_ERR("Failed to start advertising, nrf_error %#x", nrf_err); goto idle; } diff --git a/samples/bluetooth/ble_hrs/src/main.c b/samples/bluetooth/ble_hrs/src/main.c index 7b31f2320d..1898bb1c56 100644 --- a/samples/bluetooth/ble_hrs/src/main.c +++ b/samples/bluetooth/ble_hrs/src/main.c @@ -256,14 +256,15 @@ NRF_SDH_BLE_OBSERVER(sdh_ble, on_ble_evt, NULL, 0); void on_conn_params_evt(const struct ble_conn_params_evt *evt) { - int err; + uint32_t nrf_err; switch (evt->id) { case BLE_CONN_PARAMS_EVT_REJECTED: - err = sd_ble_gap_disconnect(evt->conn_handle, BLE_HCI_CONN_INTERVAL_UNACCEPTABLE); - if (err) { + nrf_err = sd_ble_gap_disconnect(evt->conn_handle, + BLE_HCI_CONN_INTERVAL_UNACCEPTABLE); + if (nrf_err) { LOG_ERR("Disconnect failed on conn params update rejection, nrf_error %#x", - err); + nrf_err); } else { LOG_ERR("Disconnected from peer, unacceptable conn params"); } @@ -352,19 +353,19 @@ static int buttons_init(bool *erase_bonds) static void delete_bonds(void) { - uint32_t err; + uint32_t nrf_err; LOG_INF("Erase bonds!"); - err = pm_peers_delete(); - if (err) { - LOG_ERR("Failed to delete peers, err %d", err); + nrf_err = pm_peers_delete(); + if (nrf_err) { + LOG_ERR("Failed to delete peers, nrf_error %#x", nrf_err); } } static void advertising_start(bool erase_bonds) { - int nrf_err; + uint32_t nrf_err; if (erase_bonds) { delete_bonds(); @@ -393,14 +394,14 @@ static void pm_evt_handler(struct pm_evt const *p_evt) } } -static int peer_manager_init(void) +static uint32_t peer_manager_init(void) { ble_gap_sec_params_t sec_param; - int err; + uint32_t nrf_err; - err = pm_init(); - if (err) { - return -EFAULT; + nrf_err = pm_init(); + if (nrf_err) { + return nrf_err; } memset(&sec_param, 0, sizeof(ble_gap_sec_params_t)); @@ -421,19 +422,19 @@ static int peer_manager_init(void) .kdist_peer.id = 1, }; - err = pm_sec_params_set(&sec_param); - if (err) { - LOG_ERR("pm_sec_params_set() failed, err: %d", err); - return -EFAULT; + nrf_err = pm_sec_params_set(&sec_param); + if (nrf_err) { + LOG_ERR("pm_sec_params_set() failed, nrf_error %#x", nrf_err); + return nrf_err; } - err = pm_register(pm_evt_handler); - if (err) { - LOG_ERR("pm_register() failed, err: %d", err); - return -EFAULT; + nrf_err = pm_register(pm_evt_handler); + if (nrf_err) { + LOG_ERR("pm_register() failed, nrf_error %#x", nrf_err); + return nrf_err; } - return 0; + return NRF_SUCCESS; } int main(void) @@ -494,9 +495,9 @@ int main(void) LOG_INF("Bluetooth enabled"); - err = peer_manager_init(); - if (err) { - LOG_ERR("Failed to initialize Peer Manager, err %d", err); + nrf_err = peer_manager_init(); + if (nrf_err) { + LOG_ERR("Failed to initialize Peer Manager, nrf_error %#x", nrf_err); goto idle; } diff --git a/samples/bluetooth/ble_lbs/src/main.c b/samples/bluetooth/ble_lbs/src/main.c index 9cb19d8c57..d9c0992af5 100644 --- a/samples/bluetooth/ble_lbs/src/main.c +++ b/samples/bluetooth/ble_lbs/src/main.c @@ -29,15 +29,15 @@ static uint16_t conn_handle = BLE_CONN_HANDLE_INVALID; static void on_ble_evt(const ble_evt_t *evt, void *ctx) { - int err; + uint32_t nrf_err; switch (evt->header.evt_id) { case BLE_GAP_EVT_CONNECTED: LOG_INF("Peer connected"); conn_handle = evt->evt.gap_evt.conn_handle; - err = sd_ble_gatts_sys_attr_set(conn_handle, NULL, 0, 0); - if (err) { - LOG_ERR("Failed to set system attributes, nrf_error %#x", err); + nrf_err = sd_ble_gatts_sys_attr_set(conn_handle, NULL, 0, 0); + if (nrf_err) { + LOG_ERR("Failed to set system attributes, nrf_error %#x", nrf_err); } break; @@ -55,19 +55,20 @@ 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); - if (err) { - LOG_ERR("Failed to reply with Security params, nrf_error %#x", err); + nrf_err = sd_ble_gap_sec_params_reply(evt->evt.gap_evt.conn_handle, + BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, + NULL); + if (nrf_err) { + LOG_ERR("Failed to reply with Security params, nrf_error %#x", nrf_err); } break; case BLE_GATTS_EVT_SYS_ATTR_MISSING: LOG_INF("BLE_GATTS_EVT_SYS_ATTR_MISSING"); /* No system attributes have been stored */ - err = sd_ble_gatts_sys_attr_set(conn_handle, NULL, 0, 0); - if (err) { - LOG_ERR("Failed to set system attributes, nrf_error %#x", err); + nrf_err = sd_ble_gatts_sys_attr_set(conn_handle, NULL, 0, 0); + if (nrf_err) { + LOG_ERR("Failed to set system attributes, nrf_error %#x", nrf_err); } break; } @@ -203,7 +204,7 @@ int main(void) nrf_err = ble_adv_init(&ble_adv, &ble_adv_config); if (nrf_err) { - LOG_ERR("Failed to initialize BLE advertising, nrf_err %#x", nrf_err); + LOG_ERR("Failed to initialize BLE advertising, nrf_error %#x", nrf_err); goto idle; } diff --git a/samples/bluetooth/ble_nus/src/main.c b/samples/bluetooth/ble_nus/src/main.c index b4109e67d5..c0cfaca7f5 100644 --- a/samples/bluetooth/ble_nus/src/main.c +++ b/samples/bluetooth/ble_nus/src/main.c @@ -189,15 +189,16 @@ static void uarte_evt_handler(nrfx_uarte_event_t const *event, void *ctx) static void on_ble_evt(const ble_evt_t *evt, void *ctx) { int err; + uint32_t nrf_err; switch (evt->header.evt_id) { case BLE_GAP_EVT_CONNECTED: LOG_INF("Peer connected"); ble_nus_max_data_len = BLE_NUS_MAX_DATA_LEN_CALC(BLE_GATT_ATT_MTU_DEFAULT); conn_handle = evt->evt.gap_evt.conn_handle; - err = sd_ble_gatts_sys_attr_set(conn_handle, NULL, 0, 0); - if (err) { - LOG_ERR("Failed to set system attributes, nrf_error %#x", err); + nrf_err = sd_ble_gatts_sys_attr_set(conn_handle, NULL, 0, 0); + if (nrf_err) { + LOG_ERR("Failed to set system attributes, nrf_error %#x", nrf_err); } err = ble_qwr_conn_handle_assign(&ble_qwr, conn_handle); @@ -221,19 +222,20 @@ 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); - if (err) { - LOG_ERR("Failed to reply with Security params, nrf_error %#x", err); + nrf_err = sd_ble_gap_sec_params_reply(evt->evt.gap_evt.conn_handle, + BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, + NULL); + if (nrf_err) { + LOG_ERR("Failed to reply with Security params, nrf_error %#x", nrf_err); } break; case BLE_GATTS_EVT_SYS_ATTR_MISSING: LOG_INF("BLE_GATTS_EVT_SYS_ATTR_MISSING"); /* No system attributes have been stored */ - err = sd_ble_gatts_sys_attr_set(conn_handle, NULL, 0, 0); - if (err) { - LOG_ERR("Failed to set system attributes, nrf_error %#x", err); + nrf_err = sd_ble_gatts_sys_attr_set(conn_handle, NULL, 0, 0); + if (nrf_err) { + LOG_ERR("Failed to set system attributes, nrf_error %#x", nrf_err); } break; } @@ -247,14 +249,15 @@ NRF_SDH_BLE_OBSERVER(sdh_ble, on_ble_evt, NULL, 0); */ void on_conn_params_evt(const struct ble_conn_params_evt *evt) { - int err; + uint32_t nrf_err; switch (evt->id) { case BLE_CONN_PARAMS_EVT_REJECTED: - err = sd_ble_gap_disconnect(evt->conn_handle, BLE_HCI_CONN_INTERVAL_UNACCEPTABLE); - if (err) { + nrf_err = sd_ble_gap_disconnect(evt->conn_handle, + BLE_HCI_CONN_INTERVAL_UNACCEPTABLE); + if (nrf_err) { LOG_ERR("Disconnect failed on conn params update rejection, nrf_error %#x", - err); + nrf_err); } else { LOG_INF("Disconnected from peer, unacceptable conn params"); } @@ -316,7 +319,7 @@ uint16_t ble_qwr_evt_handler(struct ble_qwr *qwr, const struct ble_qwr_evt *qwr_ static void ble_nus_evt_handler(const struct ble_nus_evt *evt) { const char newline = '\n'; - uint32_t err; + nrfx_err_t nrfx_err; if (evt->type != BLE_NUS_EVT_RX_DATA) { return; @@ -327,15 +330,15 @@ static void ble_nus_evt_handler(const struct ble_nus_evt *evt) evt->params.rx_data.length, evt->params.rx_data.data, evt->params.rx_data.length); #if defined(CONFIG_NUS_LPUARTE) - err = bm_lpuarte_tx(&lpu, evt->params.rx_data.data, evt->params.rx_data.length, 3000); - if (err != NRFX_SUCCESS) { - LOG_ERR("bm_lpuarte_tx failed, nrfx_err %#x", err); + nrfx_err = bm_lpuarte_tx(&lpu, evt->params.rx_data.data, evt->params.rx_data.length, 3000); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("bm_lpuarte_tx failed, nrfx_err %#x", nrfx_err); } #else - err = nrfx_uarte_tx(&nus_uarte_inst, evt->params.rx_data.data, + nrfx_err = nrfx_uarte_tx(&nus_uarte_inst, evt->params.rx_data.data, evt->params.rx_data.length, NRFX_UARTE_TX_BLOCKING); - if (err != NRFX_SUCCESS) { - LOG_ERR("nrfx_uarte_tx failed, nrfx_err %#x", err); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("nrfx_uarte_tx failed, nrfx_err %#x", nrfx_err); } #endif @@ -372,9 +375,9 @@ ISR_DIRECT_DECLARE(gpiote_30_direct_isr) /** * @brief Initalize UARTE driver. */ -static int uarte_init(void) +static nrfx_err_t uarte_init(void) { - int err; + nrfx_err_t nrfx_err; nrfx_uarte_config_t *uarte_cfg; #if defined(CONFIG_NUS_LPUARTE) struct bm_lpuarte_config lpu_cfg = { @@ -419,25 +422,26 @@ static int uarte_init(void) IRQ_DIRECT_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_GPIOTE_INST_GET(30)) + NRF_GPIOTE_IRQ_GROUP, CONFIG_GPIOTE_IRQ_PRIO, gpiote_30_direct_isr, 0); - err = bm_lpuarte_init(&lpu, &lpu_cfg, uarte_evt_handler); - if (err != NRFX_SUCCESS) { - LOG_ERR("Failed to initialize UART, nrfx err %d", err); - return err; + nrfx_err = bm_lpuarte_init(&lpu, &lpu_cfg, uarte_evt_handler); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("Failed to initialize UART, nrfx_err %#x", nrfx_err); + return nrfx_err; } #else - err = nrfx_uarte_init(&nus_uarte_inst, &uarte_config, uarte_evt_handler); - if (err != NRFX_SUCCESS) { - LOG_ERR("Failed to initialize UART, nrfx err %d", err); - return err; + nrfx_err = nrfx_uarte_init(&nus_uarte_inst, &uarte_config, uarte_evt_handler); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("Failed to initialize UART, nrfx_err %#x", nrfx_err); + return nrfx_err; } #endif /* CONFIG_NUS_LPUARTE */ - return 0; + return NRFX_SUCCESS; } int main(void) { int err; + nrfx_err_t nrfx_err; uint32_t nrf_err; struct ble_adv_config ble_adv_cfg = { .conn_cfg_tag = CONFIG_NRF_SDH_BLE_CONN_TAG, @@ -457,9 +461,9 @@ int main(void) LOG_INF("BLE NUS sample started"); - err = uarte_init(); - if (err) { - LOG_ERR("Failed to enable UARTE, err %d", err); + nrfx_err = uarte_init(); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("Failed to enable UARTE, nrfx_err %#x", nrfx_err); goto idle; } @@ -514,22 +518,22 @@ int main(void) } #if defined(CONFIG_NUS_LPUARTE) - err = bm_lpuarte_rx_enable(&lpu); - if (err != NRFX_SUCCESS) { - LOG_ERR("UART RX failed, nrfx err %d", err); + nrfx_err = bm_lpuarte_rx_enable(&lpu); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("UART RX failed, nrfx_err %#x", nrfx_err); } #else const uint8_t out[] = "UART started.\r\n"; - err = nrfx_uarte_tx(&nus_uarte_inst, out, sizeof(out), NRFX_UARTE_TX_BLOCKING); - if (err != NRFX_SUCCESS) { - LOG_ERR("UARTE TX failed, nrfx err %d", err); + nrfx_err = nrfx_uarte_tx(&nus_uarte_inst, out, sizeof(out), NRFX_UARTE_TX_BLOCKING); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("UARTE TX failed, nrfx_err %#x", nrfx_err); goto idle; } - err = nrfx_uarte_rx_enable(&nus_uarte_inst, 0); - if (err != NRFX_SUCCESS) { - LOG_ERR("UART RX failed, nrfx err %d", err); + nrfx_err = nrfx_uarte_rx_enable(&nus_uarte_inst, 0); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("UART RX failed, nrfx_err %#x", nrfx_err); } #endif diff --git a/samples/bluetooth/ble_pwr_profiling/src/main.c b/samples/bluetooth/ble_pwr_profiling/src/main.c index 8c608f6fe2..d326fb8d03 100644 --- a/samples/bluetooth/ble_pwr_profiling/src/main.c +++ b/samples/bluetooth/ble_pwr_profiling/src/main.c @@ -181,7 +181,7 @@ static uint32_t ble_pwr_profiling_char_add(const uint8_t uuid_type, uint16_t ser /* Send characteristic notification to peer if in a connected state and notification is enabled. */ static void notification_send(void) { - uint32_t err; + uint32_t nrf_err; uint16_t len = CONFIG_BLE_PWR_PROFILING_CHAR_VALUE_LEN; /* Increase last byte of characteristic value to have different values on each update*/ @@ -197,12 +197,12 @@ static void notification_send(void) .p_data = char_value, }; - err = sd_ble_gatts_hvx(conn_handle, &hvx_params); - if ((err != NRF_SUCCESS) && - (err != NRF_ERROR_INVALID_STATE) && - (err != NRF_ERROR_RESOURCES) && - (err != BLE_ERROR_GATTS_SYS_ATTR_MISSING)) { - LOG_ERR("sd_ble_gatts_hvx failed, nrf_error %#x", err); + nrf_err = sd_ble_gatts_hvx(conn_handle, &hvx_params); + if ((nrf_err != NRF_SUCCESS) && + (nrf_err != NRF_ERROR_INVALID_STATE) && + (nrf_err != NRF_ERROR_RESOURCES) && + (nrf_err != BLE_ERROR_GATTS_SYS_ATTR_MISSING)) { + LOG_ERR("sd_ble_gatts_hvx failed, nrf_error %#x", nrf_err); } } } @@ -227,6 +227,7 @@ static void char_notif_timeout_handler(void *ctx) static void connection_timeout_handler(void *ctx) { int err; + uint32_t nrf_err; ARG_UNUSED(ctx); @@ -238,9 +239,9 @@ static void connection_timeout_handler(void *ctx) LOG_ERR("Failed to stop timer, err %d", err); } - err = sd_ble_gap_disconnect(conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); - if (err != NRF_SUCCESS) { - LOG_ERR("Failed to disconnect, nrf_error %#x", err); + nrf_err = sd_ble_gap_disconnect(conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); + if (nrf_err) { + LOG_ERR("Failed to disconnect, nrf_error %#x", nrf_err); } } @@ -260,7 +261,7 @@ static void poweroff_timeout_handler(void *ctx) */ static void on_write(ble_evt_t const *ble_evt) { - uint32_t err; + int err; bool notif_enabled; ble_gatts_evt_write_t const *evt_write = &ble_evt->evt.gatts_evt.params.write; @@ -299,6 +300,7 @@ static void on_write(ble_evt_t const *ble_evt) static void on_ble_evt(const ble_evt_t *evt, void *ctx) { int err; + uint32_t nrf_err; switch (evt->header.evt_id) { case BLE_GAP_EVT_CONNECTED: @@ -325,18 +327,19 @@ 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); - if (err != NRF_SUCCESS) { - LOG_ERR("Failed to reply with Security params, nrf_error %#x", err); + nrf_err = sd_ble_gap_sec_params_reply(evt->evt.gap_evt.conn_handle, + BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, + NULL, NULL); + if (nrf_err) { + LOG_ERR("Failed to reply with Security params, nrf_error %#x", nrf_err); } break; case BLE_GATTS_EVT_SYS_ATTR_MISSING: /* No system attributes have been stored */ - err = sd_ble_gatts_sys_attr_set(conn_handle, NULL, 0, 0); - if (err != NRF_SUCCESS) { - LOG_ERR("Failed to set system attributes, nrf_error %#x", err); + nrf_err = sd_ble_gatts_sys_attr_set(conn_handle, NULL, 0, 0); + if (nrf_err) { + LOG_ERR("Failed to set system attributes, nrf_error %#x", nrf_err); } break; @@ -360,14 +363,15 @@ NRF_SDH_BLE_OBSERVER(sdh_ble, on_ble_evt, NULL, 0); static void on_conn_params_evt(const struct ble_conn_params_evt *evt) { - int err; + uint32_t nrf_err; switch (evt->id) { case BLE_CONN_PARAMS_EVT_REJECTED: - err = sd_ble_gap_disconnect(evt->conn_handle, BLE_HCI_CONN_INTERVAL_UNACCEPTABLE); - if (err) { + nrf_err = sd_ble_gap_disconnect(evt->conn_handle, + BLE_HCI_CONN_INTERVAL_UNACCEPTABLE); + if (nrf_err) { LOG_ERR("Disconnect failed on conn params update rejection, nrf_error %#x", - err); + nrf_err); } else { LOG_INF("Disconnected from peer, unacceptable conn params"); } @@ -413,7 +417,7 @@ static uint16_t on_ble_qwr_evt(struct ble_qwr *qwr, const struct ble_qwr_evt *qw static uint32_t ble_service_init(uint16_t *service_handle, uint8_t *uuid_type, ble_gatts_char_handles_t *char_handles) { - uint32_t err; + uint32_t nrf_err; ble_uuid_t ble_uuid; ble_uuid128_t uuid_base = { .uuid128 = BLE_UUID_BASE @@ -427,27 +431,27 @@ static uint32_t ble_service_init(uint16_t *service_handle, uint8_t *uuid_type, *service_handle = BLE_CONN_HANDLE_INVALID; /* Add a custom base UUID. */ - err = sd_ble_uuid_vs_add(&uuid_base, uuid_type); - if (err != NRF_SUCCESS) { - LOG_ERR("Failed to add base UUID, nrf_error %#x", err); - return err; + nrf_err = sd_ble_uuid_vs_add(&uuid_base, uuid_type); + if (nrf_err) { + LOG_ERR("Failed to add base UUID, nrf_error %#x", nrf_err); + return nrf_err; } ble_uuid.type = *uuid_type; ble_uuid.uuid = BLE_UUID_PWR_SERVICE; /* Add the service. */ - err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, service_handle); - if (err != NRF_SUCCESS) { - LOG_ERR("Failed to add pwr profiling service, nrf_error %#x", err); - return err; + nrf_err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, service_handle); + if (nrf_err) { + LOG_ERR("Failed to add pwr profiling service, nrf_error %#x", nrf_err); + return nrf_err; } /* Add characteristic. */ - err = ble_pwr_profiling_char_add(*uuid_type, *service_handle, char_handles); - if (err != NRF_SUCCESS) { - LOG_ERR("Failed to add pwr profiling characteristic, nrf_error %#x", err); - return err; + nrf_err = ble_pwr_profiling_char_add(*uuid_type, *service_handle, char_handles); + if (nrf_err) { + LOG_ERR("Failed to add pwr profiling characteristic, nrf_error %#x", nrf_err); + return nrf_err; } return NRF_SUCCESS; @@ -456,7 +460,8 @@ static uint32_t ble_service_init(uint16_t *service_handle, uint8_t *uuid_type, /* Add optional advertising data and start advertising in the given mode */ static void adv_data_update_and_start(enum adv_mode adv_mode) { - uint32_t err; + int err; + uint32_t nrf_err; ble_gap_adv_data_t new_adv_data = {0}; struct ble_adv_data adv_data = { @@ -466,9 +471,9 @@ static void adv_data_update_and_start(enum adv_mode adv_mode) struct ble_adv_data sr_data = {0}; if (adv_mode_current != ADV_MODE_IDLE) { - err = sd_ble_gap_adv_stop(adv_handle); - if (err != NRF_SUCCESS) { - LOG_ERR("Failed to stop advertising, nrf_error %#x", err); + nrf_err = sd_ble_gap_adv_stop(adv_handle); + if (nrf_err) { + LOG_ERR("Failed to stop advertising, nrf_error %#x", nrf_err); return; } @@ -504,9 +509,9 @@ static void adv_data_update_and_start(enum adv_mode adv_mode) new_adv_data.adv_data.len = BLE_GAP_ADV_SET_DATA_SIZE_MAX; - err = ble_adv_data_encode(&adv_data, new_adv_data.adv_data.p_data, - &new_adv_data.adv_data.len); - if (err) { + nrf_err = ble_adv_data_encode(&adv_data, new_adv_data.adv_data.p_data, + &new_adv_data.adv_data.len); + if (nrf_err) { return; } @@ -517,23 +522,23 @@ static void adv_data_update_and_start(enum adv_mode adv_mode) new_adv_data.scan_rsp_data.len = BLE_GAP_ADV_SET_DATA_SIZE_MAX; - err = ble_adv_data_encode(&sr_data, new_adv_data.scan_rsp_data.p_data, - &new_adv_data.scan_rsp_data.len); - if (err) { + nrf_err = ble_adv_data_encode(&sr_data, new_adv_data.scan_rsp_data.p_data, + &new_adv_data.scan_rsp_data.len); + if (nrf_err) { return; } memcpy(&gap_adv_data, &new_adv_data, sizeof(gap_adv_data)); - err = sd_ble_gap_adv_set_configure(&adv_handle, &gap_adv_data, &adv_params); - if (err) { - LOG_ERR("Failed to set advertising data, nrf_error %#x", err); + nrf_err = sd_ble_gap_adv_set_configure(&adv_handle, &gap_adv_data, &adv_params); + if (nrf_err) { + LOG_ERR("Failed to set advertising data, nrf_error %#x", nrf_err); return; } - err = sd_ble_gap_adv_start(adv_handle, CONFIG_NRF_SDH_BLE_CONN_TAG); - if (err) { - LOG_ERR("Failed to start advertising, nrf_error %#x", err); + nrf_err = sd_ble_gap_adv_start(adv_handle, CONFIG_NRF_SDH_BLE_CONN_TAG); + if (nrf_err) { + LOG_ERR("Failed to start advertising, nrf_error %#x", nrf_err); return; } @@ -567,15 +572,15 @@ static void button_handler(uint8_t pin, uint8_t action) static uint32_t adv_init(void) { - uint32_t err; + uint32_t nrf_err; ble_gap_conn_sec_mode_t sec_mode = {0}; BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); - err = sd_ble_gap_device_name_set(&sec_mode, CONFIG_BLE_PWR_PROFILING_ADV_NAME, - strlen(CONFIG_BLE_PWR_PROFILING_ADV_NAME)); - if (err != NRF_SUCCESS) { - LOG_ERR("Failed to set advertising name, nrf_error %#x", err); - return err; + nrf_err = sd_ble_gap_device_name_set(&sec_mode, CONFIG_BLE_PWR_PROFILING_ADV_NAME, + strlen(CONFIG_BLE_PWR_PROFILING_ADV_NAME)); + if (nrf_err) { + LOG_ERR("Failed to set advertising name, nrf_error %#x", nrf_err); + return nrf_err; } gap_adv_data.adv_data.p_data = enc_adv_data[0]; @@ -587,10 +592,10 @@ static uint32_t adv_init(void) adv_params.filter_policy = BLE_GAP_ADV_FP_ANY; adv_params.primary_phy = BLE_GAP_PHY_AUTO; - err = sd_ble_gap_adv_set_configure(&adv_handle, NULL, &adv_params); - if (err != NRF_SUCCESS) { - LOG_ERR("Failed to set GAP advertising parameters, nrf_error %#x", err); - return err; + nrf_err = sd_ble_gap_adv_set_configure(&adv_handle, NULL, &adv_params); + if (nrf_err) { + LOG_ERR("Failed to set GAP advertising parameters, nrf_error %#x", nrf_err); + return nrf_err; } return NRF_SUCCESS; @@ -678,15 +683,15 @@ int main(void) goto idle; } - err = adv_init(); - if (err != NRF_SUCCESS) { - LOG_ERR("Failed to initialize advertising, nrf_error %#x", err); + nrf_err = adv_init(); + if (nrf_err) { + LOG_ERR("Failed to initialize advertising, nrf_error %#x", nrf_err); goto idle; } - err = ble_service_init(&conn_handle, &uuid_type, &char_handles); - if (err != NRF_SUCCESS) { - LOG_ERR("Failed to initialize pwr profiling service, err %#x", err); + nrf_err = ble_service_init(&conn_handle, &uuid_type, &char_handles); + if (nrf_err) { + LOG_ERR("Failed to initialize pwr profiling service, nrf_error %#x", nrf_err); goto idle; } diff --git a/samples/boot/mcuboot_recovery_entry/src/main.c b/samples/boot/mcuboot_recovery_entry/src/main.c index 41beec99ac..28ba3e256a 100644 --- a/samples/boot/mcuboot_recovery_entry/src/main.c +++ b/samples/boot/mcuboot_recovery_entry/src/main.c @@ -43,7 +43,7 @@ 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"); @@ -56,10 +56,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; } @@ -85,11 +85,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; @@ -99,10 +100,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; @@ -226,10 +227,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; } diff --git a/samples/peripherals/lpuarte/src/main.c b/samples/peripherals/lpuarte/src/main.c index 2f6c22dd0c..b56b04e869 100644 --- a/samples/peripherals/lpuarte/src/main.c +++ b/samples/peripherals/lpuarte/src/main.c @@ -31,7 +31,7 @@ static void uarte_rx_handler(char *data, size_t data_len) /* UARTE event handler */ static void lpuarte_event_handler(nrfx_uarte_event_t const *event, void *ctx) { - uint32_t err; + nrfx_err_t nrfx_err; struct bm_lpuarte *lpu = ctx; switch (event->type) { @@ -41,7 +41,7 @@ static void lpuarte_event_handler(nrfx_uarte_event_t const *event, void *ctx) } break; case NRFX_UARTE_EVT_RX_BUF_REQUEST: - err = bm_lpuarte_rx_buffer_set(lpu, &uarte_rx_buf[buf_idx * 128], 128); + nrfx_err = bm_lpuarte_rx_buffer_set(lpu, &uarte_rx_buf[buf_idx * 128], 128); buf_idx++; buf_idx = (buf_idx < 2) ? buf_idx : 0; break; @@ -72,9 +72,9 @@ ISR_DIRECT_DECLARE(lpuarte_direct_isr) } /* Initialize UARTE driver. */ -static uint32_t uarte_init(void) +static nrfx_err_t lpuarte_init(void) { - uint32_t err; + nrfx_err_t nrfx_err; struct bm_lpuarte_config lpu_cfg = { .uarte_inst = NRFX_UARTE_INSTANCE(BOARD_APP_LPUARTE_INST), @@ -101,13 +101,13 @@ static uint32_t uarte_init(void) irq_enable(NRFX_IRQ_NUMBER_GET(NRF_UARTE_INST_GET(BOARD_APP_LPUARTE_INST))); - err = bm_lpuarte_init(&lpu, &lpu_cfg, lpuarte_event_handler); - if (err != NRFX_SUCCESS) { - LOG_ERR("Failed to initialize UARTE, nrfx_err %d", err); - return err; + nrfx_err = bm_lpuarte_init(&lpu, &lpu_cfg, lpuarte_event_handler); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("Failed to initialize UARTE, nrfx_err %#x", nrfx_err); + return nrfx_err; } - return 0; + return NRFX_SUCCESS; } static struct bm_timer tx_timer; @@ -115,32 +115,33 @@ static uint8_t out[] = {1, 2, 3, 4, 5}; static void tx_timeout(void *context) { - uint32_t err; + nrfx_err_t nrfx_err; - err = bm_lpuarte_tx(&lpu, out, sizeof(out), 3000); - if (err != NRFX_SUCCESS) { - LOG_ERR("UARTE TX failed, nrfx err %#x", err); + nrfx_err = bm_lpuarte_tx(&lpu, out, sizeof(out), 3000); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("UARTE TX failed, nrfx err %#x", nrfx_err); return; } } int main(void) { - uint32_t err; + int err; + nrfx_err_t nrfx_err; LOG_INF("LPUARTE sample started"); LOG_INF("Disable console and logging for minimal power consumption"); - err = uarte_init(); - if (err) { - LOG_ERR("Failed to enable UARTE, err %#x", err); + nrfx_err = lpuarte_init(); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("Failed to enable UARTE, nrfx_err %#x", nrfx_err); goto idle; } /* Start reception */ - err = bm_lpuarte_rx_enable(&lpu); - if (err != NRFX_SUCCESS) { - LOG_ERR("UARTE RX failed, nrfx_err %#x", err); + nrfx_err = bm_lpuarte_rx_enable(&lpu); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("UARTE RX failed, nrfx_err %#x", nrfx_err); goto idle; } diff --git a/samples/peripherals/pwm/src/main.c b/samples/peripherals/pwm/src/main.c index 2e4c7609c7..d9c9b60273 100644 --- a/samples/peripherals/pwm/src/main.c +++ b/samples/peripherals/pwm/src/main.c @@ -35,7 +35,7 @@ ISR_DIRECT_DECLARE(pwm_direct_isr) int main(void) { - nrfx_err_t err; + nrfx_err_t nrfx_err; nrfx_pwm_t pwm_instance = NRFX_PWM_INSTANCE(PWM_INST_IDX); /* * PWM signal can be exposed on GPIO pin only within the same domain. @@ -59,9 +59,9 @@ int main(void) CONFIG_PWM_IRQ_PRIO, pwm_direct_isr, 0); - err = nrfx_pwm_init(&pwm_instance, &config, pwm_handler, &pwm_instance); - if (err != NRFX_SUCCESS) { - LOG_ERR("Failed to initialize PWM, nrfx_error %#x", err); + nrfx_err = nrfx_pwm_init(&pwm_instance, &config, pwm_handler, &pwm_instance); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("Failed to initialize PWM, nrfx_err %#x", nrfx_err); goto idle; } diff --git a/samples/peripherals/uarte/src/main.c b/samples/peripherals/uarte/src/main.c index c0a5b8cd78..a57985ad50 100644 --- a/samples/peripherals/uarte/src/main.c +++ b/samples/peripherals/uarte/src/main.c @@ -22,7 +22,7 @@ static int buf_idx; /* Handle data received from UARTE. */ static void uarte_rx_handler(char *data, size_t data_len) { - nrfx_err_t err; + nrfx_err_t nrfx_err; uint8_t c; static char rx_buf[CONFIG_UARTE_DATA_LEN_MAX]; static uint16_t rx_buf_idx; @@ -47,10 +47,10 @@ static void uarte_rx_handler(char *data, size_t data_len) rx_buf[rx_buf_idx++] = '\n'; } - err = nrfx_uarte_tx(&uarte_inst, rx_buf, rx_buf_idx, + nrfx_err = nrfx_uarte_tx(&uarte_inst, rx_buf, rx_buf_idx, NRFX_UARTE_TX_BLOCKING); - if (err != NRFX_SUCCESS) { - LOG_ERR("nrfx_uarte_tx failed, nrfx_err %d", err); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("nrfx_uarte_tx failed, nrfx_err %#x", nrfx_err); } rx_buf_idx = 0; @@ -92,9 +92,9 @@ ISR_DIRECT_DECLARE(uarte_direct_isr) } /* Initialize UARTE driver. */ -static int uarte_init(void) +static nrfx_err_t uarte_init(void) { - int err; + nrfx_err_t nrfx_err; nrfx_uarte_config_t uarte_config = NRFX_UARTE_DEFAULT_CONFIG(BOARD_APP_UARTE_PIN_TX, BOARD_APP_UARTE_PIN_RX); @@ -118,39 +118,39 @@ static int uarte_init(void) irq_enable(NRFX_IRQ_NUMBER_GET(NRF_UARTE_INST_GET(BOARD_APP_UARTE_INST))); - err = nrfx_uarte_init(&uarte_inst, &uarte_config, uarte_event_handler); - if (err != NRFX_SUCCESS) { - LOG_ERR("Failed to initialize UARTE, nrfx err %d", err); - return err; + nrfx_err = nrfx_uarte_init(&uarte_inst, &uarte_config, uarte_event_handler); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("Failed to initialize UARTE, nrfx_err %#x", nrfx_err); + return nrfx_err; } - return 0; + return NRFX_SUCCESS; } int main(void) { - int err; + nrfx_err_t nrfx_err; LOG_INF("UARTE sample started"); - err = uarte_init(); - if (err) { - LOG_ERR("Failed to enable UARTE, err %d", err); + nrfx_err = uarte_init(); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("Failed to enable UARTE, nrfx_err %#x", nrfx_err); goto idle; } const uint8_t out[] = "Hello world! I will echo the lines you enter:\r\n"; - err = nrfx_uarte_tx(&uarte_inst, out, sizeof(out), NRFX_UARTE_TX_BLOCKING); - if (err != NRFX_SUCCESS) { - LOG_ERR("UARTE TX failed, nrfx err %d", err); + nrfx_err = nrfx_uarte_tx(&uarte_inst, out, sizeof(out), NRFX_UARTE_TX_BLOCKING); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("UARTE TX failed, nrfx_err %#x", nrfx_err); goto idle; } /* Start reception */ - err = nrfx_uarte_rx_enable(&uarte_inst, 0); - if (err != NRFX_SUCCESS) { - LOG_ERR("UARTE RX failed, nrfx err %d", err); + nrfx_err = nrfx_uarte_rx_enable(&uarte_inst, 0); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("UARTE RX failed, nrfx_err %#x", nrfx_err); } idle: diff --git a/subsys/bluetooth/services/ble_cgms/cgms.c b/subsys/bluetooth/services/ble_cgms/cgms.c index bf9551938e..1896a88dcc 100644 --- a/subsys/bluetooth/services/ble_cgms/cgms.c +++ b/subsys/bluetooth/services/ble_cgms/cgms.c @@ -179,7 +179,7 @@ uint32_t ble_cgms_init(struct ble_cgms *cgms, const struct ble_cgms_config *cgms return NRF_ERROR_NULL; } - uint32_t err; + uint32_t nrf_err; ble_uuid_t ble_uuid; const uint8_t init_calib_val[] = { 0x3E, 0x00, 0x07, 0x00, @@ -188,9 +188,9 @@ uint32_t ble_cgms_init(struct ble_cgms *cgms, const struct ble_cgms_config *cgms }; /* Initialize data base. */ - err = cgms_db_init(); - if (err != NRF_SUCCESS) { - return err; + nrf_err = cgms_db_init(); + if (nrf_err) { + return nrf_err; } /* Initialize service structure. */ @@ -209,59 +209,59 @@ uint32_t ble_cgms_init(struct ble_cgms *cgms, const struct ble_cgms_config *cgms /* Add service. */ BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_CGM_SERVICE); - err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, - &ble_uuid, &cgms->service_handle); - if (err != NRF_SUCCESS) { - return err; + nrf_err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, + &ble_uuid, &cgms->service_handle); + if (nrf_err) { + return nrf_err; } /* Add CGM Measurement characteristic. */ - err = cgms_meas_char_add(cgms); - if (err != NRF_SUCCESS) { - LOG_ERR("Failed to add CGMS measurement characteristic, nrf_error %#x", err); - return err; + nrf_err = cgms_meas_char_add(cgms); + if (nrf_err) { + LOG_ERR("Failed to add CGMS measurement characteristic, nrf_error %#x", nrf_err); + return nrf_err; } /* Add CGM Feature characteristic. */ - err = feature_char_add(cgms); - if (err != NRF_SUCCESS) { - LOG_ERR("Failed to add CGMS feature characteristic, nrf_error %#x", err); - return err; + nrf_err = feature_char_add(cgms); + if (nrf_err) { + LOG_ERR("Failed to add CGMS feature characteristic, nrf_error %#x", nrf_err); + return nrf_err; } /* Add CGM Status characteristic. */ - err = status_char_add(cgms); - if (err != NRF_SUCCESS) { - LOG_ERR("Failed to add CGMS status characteristic, nrf_error %#x", err); - return err; + nrf_err = status_char_add(cgms); + if (nrf_err) { + LOG_ERR("Failed to add CGMS status characteristic, nrf_error %#x", nrf_err); + return nrf_err; } /* Add CGM Session Start Time characteristic. */ - err = cgms_sst_char_add(cgms); - if (err != NRF_SUCCESS) { - LOG_ERR("Failed to add CGMS SST characteristic, nrf_error %#x", err); - return err; + nrf_err = cgms_sst_char_add(cgms); + if (nrf_err) { + LOG_ERR("Failed to add CGMS SST characteristic, nrf_error %#x", nrf_err); + return nrf_err; } /* Add CGM Session Run Time characteristic. */ - err = srt_char_add(cgms); - if (err != NRF_SUCCESS) { - LOG_ERR("Failed to add CGMS SRT characteristic, nrf_error %#x", err); - return err; + nrf_err = srt_char_add(cgms); + if (nrf_err) { + LOG_ERR("Failed to add CGMS SRT characteristic, nrf_error %#x", nrf_err); + return nrf_err; } /* Add CGM Record Access Control Point characteristic. */ - err = cgms_racp_char_add(cgms); - if (err != NRF_SUCCESS) { - LOG_ERR("Failed to add CGMS RACP characteristic, nrf_error %#x", err); - return err; + nrf_err = cgms_racp_char_add(cgms); + if (nrf_err) { + LOG_ERR("Failed to add CGMS RACP characteristic, nrf_error %#x", nrf_err); + return nrf_err; } /* Add CGM Specific Ops Control Point characteristic. */ - err = cgms_socp_char_add(cgms); - if (err != NRF_SUCCESS) { - LOG_ERR("Failed to add CGMS SOCP characteristic, nrf_error %#x", err); - return err; + nrf_err = cgms_socp_char_add(cgms); + if (nrf_err) { + LOG_ERR("Failed to add CGMS SOCP characteristic, nrf_error %#x", nrf_err); + return nrf_err; } return 0; @@ -330,19 +330,19 @@ void ble_cgms_on_ble_evt(const ble_evt_t *ble_evt, void *context) uint32_t ble_cgms_meas_create(struct ble_cgms *cgms, struct ble_cgms_rec *rec) { - uint32_t err; + uint32_t nrf_err; uint16_t nb_rec_to_send = 1; - err = cgms_db_record_add(rec); - if (err != NRF_SUCCESS) { - return err; + nrf_err = cgms_db_record_add(rec); + if (nrf_err) { + return nrf_err; } if ((cgms->conn_handle != BLE_CONN_HANDLE_INVALID) && (cgms->comm_interval != 0)) { - err = cgms_meas_send(cgms, rec, &nb_rec_to_send); + nrf_err = cgms_meas_send(cgms, rec, &nb_rec_to_send); } - return err; + return nrf_err; } uint32_t ble_cgms_update_status(struct ble_cgms *cgms, struct ble_cgms_status *status) diff --git a/subsys/bluetooth/services/ble_cgms/cgms_meas.c b/subsys/bluetooth/services/ble_cgms/cgms_meas.c index a6327d1781..5daa86a71b 100644 --- a/subsys/bluetooth/services/ble_cgms/cgms_meas.c +++ b/subsys/bluetooth/services/ble_cgms/cgms_meas.c @@ -69,16 +69,16 @@ static uint8_t cgms_meas_encode(struct ble_cgms *cgms, /* Add a characteristic for the Continuous Glucose Meter Measurement. */ uint32_t cgms_meas_char_add(struct ble_cgms *cgms) { - uint32_t err; + uint32_t nrf_err; uint16_t num_recs; uint8_t encoded_cgms_meas[BLE_CGMS_MEAS_LEN_MAX]; struct ble_cgms_rec initial_cgms_rec_value = {0}; num_recs = cgms_db_num_records_get(); if (num_recs > 0) { - err = cgms_db_record_get(&initial_cgms_rec_value, num_recs - 1); - if (err != NRF_SUCCESS) { - return err; + nrf_err = cgms_db_record_get(&initial_cgms_rec_value, num_recs - 1); + if (nrf_err) { + return nrf_err; } } @@ -118,7 +118,7 @@ uint32_t cgms_meas_char_add(struct ble_cgms *cgms) uint32_t cgms_meas_send(struct ble_cgms *cgms, struct ble_cgms_rec *rec, uint16_t *count) { - uint32_t err; + uint32_t nrf_err; uint8_t encoded_meas[BLE_CGMS_MEAS_LEN_MAX + BLE_CGMS_MEAS_REC_LEN_MAX]; uint16_t len = 0; uint16_t hvx_len = BLE_CGMS_MEAS_LEN_MAX; @@ -144,17 +144,17 @@ uint32_t cgms_meas_send(struct ble_cgms *cgms, struct ble_cgms_rec *rec, uint16_ *count = i; hvx_len = len; - err = sd_ble_gatts_hvx(cgms->conn_handle, &hvx_params); - if (err == NRF_SUCCESS) { + nrf_err = sd_ble_gatts_hvx(cgms->conn_handle, &hvx_params); + if (nrf_err == NRF_SUCCESS) { if (hvx_len != len) { - err = NRF_ERROR_DATA_SIZE; + nrf_err = NRF_ERROR_DATA_SIZE; } else { /* Measurement successfully sent */ cgms->racp_data.racp_proc_records_reported += *count; } } - return err; + return nrf_err; } /* Glucose measurement CCCD write event handler */ diff --git a/subsys/bluetooth/services/ble_cgms/cgms_racp.c b/subsys/bluetooth/services/ble_cgms/cgms_racp.c index d25cbf2c7a..29f9235055 100644 --- a/subsys/bluetooth/services/ble_cgms/cgms_racp.c +++ b/subsys/bluetooth/services/ble_cgms/cgms_racp.c @@ -69,7 +69,7 @@ uint32_t cgms_racp_char_add(struct ble_cgms *cgms) static void racp_send(struct ble_cgms *cgms, struct ble_racp_value *racp_val) { - uint32_t err; + uint32_t nrf_err; uint8_t encoded_resp[25]; uint16_t len; @@ -91,13 +91,13 @@ static void racp_send(struct ble_cgms *cgms, struct ble_racp_value *racp_val) .gatts_hvx.p_len = &len, }; - err = ble_gq_item_add(cgms->gatt_queue, &cgms_req, cgms->conn_handle); + nrf_err = ble_gq_item_add(cgms->gatt_queue, &cgms_req, cgms->conn_handle); /* Report error to application */ if ((cgms->evt_handler != NULL) && - (err != NRF_SUCCESS) && - (err != NRF_ERROR_INVALID_STATE)) { - evt.error.reason = err; + (nrf_err) && + (nrf_err != NRF_ERROR_INVALID_STATE)) { + evt.error.reason = nrf_err; cgms->evt_handler(cgms, &evt); } } @@ -127,7 +127,7 @@ static uint32_t racp_report_records_all(struct ble_cgms *cgms) if (cgms->racp_data.racp_proc_record_idx >= total_records) { cgms->racp_data.racp_processing_active = false; } else { - uint32_t err; + uint32_t nrf_err; struct ble_cgms_rec rec[BLE_CGMS_MEAS_REC_PER_NOTIF_MAX]; cur_num_rec = total_records - cgms->racp_data.racp_proc_record_idx; @@ -138,16 +138,16 @@ static uint32_t racp_report_records_all(struct ble_cgms *cgms) recs_to_send = cur_num_rec; for (i = 0; i < cur_num_rec; i++) { - err = cgms_db_record_get(&(rec[i]), - cgms->racp_data.racp_proc_record_idx + i); - if (err != NRF_SUCCESS) { - return err; + nrf_err = cgms_db_record_get(&(rec[i]), + cgms->racp_data.racp_proc_record_idx + i); + if (nrf_err) { + return nrf_err; } } - err = cgms_meas_send(cgms, rec, &recs_to_send); - if (err != NRF_SUCCESS) { - return err; + nrf_err = cgms_meas_send(cgms, rec, &recs_to_send); + if (nrf_err) { + return nrf_err; } cgms->racp_data.racp_proc_record_idx += recs_to_send; @@ -159,7 +159,7 @@ static uint32_t racp_report_records_all(struct ble_cgms *cgms) /* Respond to the FIRST or the LAST operation. */ static uint32_t racp_report_records_first_last(struct ble_cgms *cgms) { - uint32_t err; + uint32_t nrf_err; struct ble_cgms_rec rec; uint16_t total_records; uint16_t recs_to_send = 1; @@ -170,20 +170,20 @@ static uint32_t racp_report_records_first_last(struct ble_cgms *cgms) cgms->racp_data.racp_processing_active = false; } else { if (cgms->racp_data.racp_proc_operator == RACP_OPERATOR_FIRST) { - err = cgms_db_record_get(&rec, 0); - if (err != NRF_SUCCESS) { - return err; + nrf_err = cgms_db_record_get(&rec, 0); + if (nrf_err) { + return nrf_err; } } else if (cgms->racp_data.racp_proc_operator == RACP_OPERATOR_LAST) { - err = cgms_db_record_get(&rec, total_records - 1); - if (err != NRF_SUCCESS) { - return err; + nrf_err = cgms_db_record_get(&rec, total_records - 1); + if (nrf_err) { + return nrf_err; } } - err = cgms_meas_send(cgms, &rec, &recs_to_send); - if (err != NRF_SUCCESS) { - return err; + nrf_err = cgms_meas_send(cgms, &rec, &recs_to_send); + if (nrf_err) { + return nrf_err; } cgms->racp_data.racp_proc_record_idx++; } @@ -204,7 +204,7 @@ static uint32_t racp_report_records_less_equal(struct ble_cgms *cgms) if (cgms->racp_data.racp_proc_record_idx >= recs_to_send_total) { cgms->racp_data.racp_processing_active = false; } else { - uint32_t err; + uint32_t nrf_err; struct ble_cgms_rec rec[BLE_CGMS_MEAS_REC_PER_NOTIF_MAX]; recs_to_send_remaining = (recs_to_send_total - @@ -217,16 +217,16 @@ static uint32_t racp_report_records_less_equal(struct ble_cgms *cgms) } for (i = 0; i < recs_to_send; i++) { - err = cgms_db_record_get(&(rec[i]), - cgms->racp_data.racp_proc_record_idx + i); - if (err != NRF_SUCCESS) { - return err; + nrf_err = cgms_db_record_get(&(rec[i]), + cgms->racp_data.racp_proc_record_idx + i); + if (nrf_err) { + return nrf_err; } } - err = cgms_meas_send(cgms, rec, &recs_to_send); - if (err != NRF_SUCCESS) { - return err; + nrf_err = cgms_meas_send(cgms, rec, &recs_to_send); + if (nrf_err) { + return nrf_err; } cgms->racp_data.racp_proc_record_idx += recs_to_send; @@ -238,7 +238,7 @@ static uint32_t racp_report_records_less_equal(struct ble_cgms *cgms) /* Respond to the GREATER OR EQUAL operation. */ static uint32_t racp_report_records_greater_equal(struct ble_cgms *cgms) { - uint32_t err; + uint32_t nrf_err; uint16_t recs_total = cgms_db_num_records_get(); uint16_t recs_to_send_remaining; uint16_t recs_to_send; @@ -261,14 +261,14 @@ static uint32_t racp_report_records_greater_equal(struct ble_cgms *cgms) } for (i = 0; i < recs_to_send; i++) { - err = cgms_db_record_get(&(rec[i]), cgms->racp_data.racp_proc_record_idx + i); - if (err != NRF_SUCCESS) { - return err; + nrf_err = cgms_db_record_get(&(rec[i]), cgms->racp_data.racp_proc_record_idx + i); + if (nrf_err) { + return nrf_err; } } - err = cgms_meas_send(cgms, rec, &recs_to_send); - if (err != NRF_SUCCESS) { - return err; + nrf_err = cgms_meas_send(cgms, rec, &recs_to_send); + if (nrf_err) { + return nrf_err; } cgms->racp_data.racp_proc_record_idx += recs_to_send; @@ -292,7 +292,7 @@ static void racp_report_records_completed(struct ble_cgms *cgms) /* RACP report records procedure. */ static void racp_report_records_procedure(struct ble_cgms *cgms) { - uint32_t err = NRF_SUCCESS; + uint32_t nrf_err = NRF_SUCCESS; struct ble_cgms_evt evt = { .evt_type = BLE_CGMS_EVT_ERROR, }; @@ -301,19 +301,19 @@ static void racp_report_records_procedure(struct ble_cgms *cgms) /* Execute requested procedure */ switch (cgms->racp_data.racp_proc_operator) { case RACP_OPERATOR_ALL: - err = racp_report_records_all(cgms); + nrf_err = racp_report_records_all(cgms); break; case RACP_OPERATOR_FIRST: /* Fall through. */ case RACP_OPERATOR_LAST: - err = racp_report_records_first_last(cgms); + nrf_err = racp_report_records_first_last(cgms); break; case RACP_OPERATOR_GREATER_OR_EQUAL: - err = racp_report_records_greater_equal(cgms); + nrf_err = racp_report_records_greater_equal(cgms); break; case RACP_OPERATOR_LESS_OR_EQUAL: - err = racp_report_records_less_equal(cgms); + nrf_err = racp_report_records_less_equal(cgms); break; default: /* Report error to application */ @@ -327,7 +327,7 @@ static void racp_report_records_procedure(struct ble_cgms *cgms) } /* Error handling */ - switch (err) { + switch (nrf_err) { case NRF_SUCCESS: if (!cgms->racp_data.racp_processing_active) { racp_report_records_completed(cgms); @@ -436,14 +436,14 @@ static bool is_request_to_be_executed(struct ble_cgms *cgms, /* Get a record with time offset less or equal to the input param. */ static uint32_t record_index_offset_less_or_equal_get(uint16_t offset, uint16_t *record_num) { - uint32_t err; + uint32_t nrf_err; struct ble_cgms_rec rec; uint16_t upper_bound = cgms_db_num_records_get(); for ((*record_num) = upper_bound; ((*record_num)-- > 0);) { - err = cgms_db_record_get(&rec, *record_num); - if (err != NRF_SUCCESS) { - return err; + nrf_err = cgms_db_record_get(&rec, *record_num); + if (nrf_err) { + return nrf_err; } if (rec.meas.time_offset <= offset) { @@ -457,14 +457,14 @@ static uint32_t record_index_offset_less_or_equal_get(uint16_t offset, uint16_t /* Get a record with time offset greater or equal to the input param. */ static uint32_t record_index_offset_greater_or_equal_get(uint16_t offset, uint16_t *record_num) { - uint32_t err; + uint32_t nrf_err; struct ble_cgms_rec rec; uint16_t upper_bound = cgms_db_num_records_get(); for (*record_num = 0; *record_num < upper_bound; (*record_num)++) { - err = cgms_db_record_get(&rec, *record_num); - if (err != NRF_SUCCESS) { - return err; + nrf_err = cgms_db_record_get(&rec, *record_num); + if (nrf_err) { + return nrf_err; } if (rec.meas.time_offset >= offset) { @@ -479,7 +479,7 @@ static uint32_t record_index_offset_greater_or_equal_get(uint16_t offset, uint16 static void report_records_request_execute(struct ble_cgms *cgms, struct ble_racp_value *racp_request) { - uint32_t err; + uint32_t nrf_err; uint16_t offset_requested; uint16_t *record_num; const uint8_t *op; @@ -495,8 +495,8 @@ static void report_records_request_execute(struct ble_cgms *cgms, op = &cgms->racp_data.racp_request.operand[OPERAND_LESS_GREATER_FILTER_TYPE_SIZE]; offset_requested = sys_get_le16(op); record_num = &cgms->racp_data.racp_proc_record_idx; - err = record_index_offset_greater_or_equal_get(offset_requested, record_num); - if (err != NRF_SUCCESS) { + nrf_err = record_index_offset_greater_or_equal_get(offset_requested, record_num); + if (nrf_err) { racp_report_records_completed(cgms); } } @@ -505,8 +505,8 @@ static void report_records_request_execute(struct ble_cgms *cgms, op = &cgms->racp_data.racp_request.operand[OPERAND_LESS_GREATER_FILTER_TYPE_SIZE]; offset_requested = sys_get_le16(op); record_num = &cgms->racp_data.racp_proc_records_idx_last_to_send; - err = record_index_offset_less_or_equal_get(offset_requested, record_num); - if (err != NRF_SUCCESS) { + nrf_err = record_index_offset_less_or_equal_get(offset_requested, record_num); + if (nrf_err) { racp_report_records_completed(cgms); } } @@ -518,7 +518,7 @@ static void report_records_request_execute(struct ble_cgms *cgms, static void report_num_records_request_execute(struct ble_cgms *cgms, struct ble_racp_value *racp_request) { - uint32_t err; + uint32_t nrf_err; uint16_t total_records; uint16_t num_records; @@ -537,9 +537,10 @@ static void report_num_records_request_execute(struct ble_cgms *cgms, uint8_t *operand = cgms->racp_data.racp_request.operand; uint16_t offset_requested = sys_get_le16(&operand[OPERAND_LESS_GREATER_FILTER_TYPE_SIZE]); - err = record_index_offset_greater_or_equal_get(offset_requested, &index_of_offset); + nrf_err = record_index_offset_greater_or_equal_get(offset_requested, + &index_of_offset); - if (err != NRF_SUCCESS) { + if (nrf_err) { num_records = 0; } else { num_records = total_records - index_of_offset; @@ -588,7 +589,7 @@ static void on_racp_value_write(struct ble_cgms *cgms, const ble_gatts_evt_write void cgms_racp_on_rw_auth_req(struct ble_cgms *cgms, const ble_gatts_evt_rw_authorize_request_t *auth_req) { - uint32_t err; + uint32_t nrf_err; struct ble_cgms_evt cgms_evt = { .evt_type = BLE_CGMS_EVT_ERROR, }; @@ -608,16 +609,16 @@ void cgms_racp_on_rw_auth_req(struct ble_cgms *cgms, .offset = 0, }; - err = sd_ble_gatts_value_get(cgms->conn_handle, cgms->char_handles.racp.cccd_handle, - &gatts_val); - if ((err != NRF_SUCCESS) || !is_indication_enabled(gatts_val.p_value)) { + nrf_err = sd_ble_gatts_value_get(cgms->conn_handle, cgms->char_handles.racp.cccd_handle, + &gatts_val); + if (nrf_err || !is_indication_enabled(gatts_val.p_value)) { auth_reply.params.write.gatt_status = BLE_GATT_STATUS_ATTERR_CPS_CCCD_CONFIG_ERROR; } - err = sd_ble_gatts_rw_authorize_reply(cgms->conn_handle, &auth_reply); - if (err != NRF_SUCCESS) { + nrf_err = sd_ble_gatts_rw_authorize_reply(cgms->conn_handle, &auth_reply); + if (nrf_err) { if (cgms->evt_handler != NULL) { - cgms_evt.error.reason = err; + cgms_evt.error.reason = nrf_err; cgms->evt_handler(cgms, &cgms_evt); } return; diff --git a/subsys/bluetooth/services/ble_cgms/cgms_socp.c b/subsys/bluetooth/services/ble_cgms/cgms_socp.c index 9937f903ef..90fe5295f7 100644 --- a/subsys/bluetooth/services/ble_cgms/cgms_socp.c +++ b/subsys/bluetooth/services/ble_cgms/cgms_socp.c @@ -384,7 +384,7 @@ static bool is_feature_present(struct ble_cgms *cgms, uint32_t feature) /* Specific Ops Control Point write event handler. */ static void on_socp_value_write(struct ble_cgms *cgms, const ble_gatts_evt_write_t *evt_write) { - uint32_t err; + uint32_t nrf_err; struct ble_cgms_socp_value socp_request; struct ble_cgms_evt evt; struct ble_cgms_sst sst = {0}; @@ -426,11 +426,11 @@ static void on_socp_value_write(struct ble_cgms *cgms, const ble_gatts_evt_write cgms->evt_handler(cgms, &evt); } - err = cgms_sst_set(cgms, &sst); - if (err != NRF_SUCCESS) { + nrf_err = cgms_sst_set(cgms, &sst); + if (nrf_err) { if (cgms->evt_handler != NULL) { evt.evt_type = BLE_CGMS_EVT_ERROR; - evt.error.reason = err; + evt.error.reason = nrf_err; cgms->evt_handler(cgms, &evt); } } @@ -440,11 +440,11 @@ static void on_socp_value_write(struct ble_cgms *cgms, const ble_gatts_evt_write cgms->sensor_status.time_offset = 0; cgms->sensor_status.status.status &= (~BLE_CGMS_STATUS_SESSION_STOPPED); - err = ble_cgms_update_status(cgms, &cgms->sensor_status); - if (err != NRF_SUCCESS) { + nrf_err = ble_cgms_update_status(cgms, &cgms->sensor_status); + if (nrf_err) { if (cgms->evt_handler != NULL) { evt.evt_type = BLE_CGMS_EVT_ERROR; - evt.error.reason = err; + evt.error.reason = nrf_err; cgms->evt_handler(cgms, &evt); } } @@ -466,11 +466,11 @@ static void on_socp_value_write(struct ble_cgms *cgms, const ble_gatts_evt_write evt.evt_type = BLE_CGMS_EVT_STOP_SESSION; cgms->evt_handler(cgms, &evt); } - err = ble_cgms_update_status(cgms, &status); - if (err != NRF_SUCCESS) { + nrf_err = ble_cgms_update_status(cgms, &status); + if (nrf_err) { if (cgms->evt_handler != NULL) { evt.evt_type = BLE_CGMS_EVT_ERROR; - evt.error.reason = err; + evt.error.reason = nrf_err; cgms->evt_handler(cgms, &evt); } } @@ -487,7 +487,7 @@ static void on_socp_value_write(struct ble_cgms *cgms, const ble_gatts_evt_write void cgms_socp_on_rw_auth_req(struct ble_cgms *cgms, const ble_gatts_evt_rw_authorize_request_t *auth_req) { - uint32_t err; + uint32_t nrf_err; struct ble_cgms_evt cgms_evt = { .evt_type = BLE_CGMS_EVT_ERROR, }; @@ -508,16 +508,16 @@ void cgms_socp_on_rw_auth_req(struct ble_cgms *cgms, .offset = 0, }; - err = sd_ble_gatts_value_get(cgms->conn_handle, cgms->char_handles.socp.cccd_handle, - &gatts_val); - if ((err != NRF_SUCCESS) || !is_indication_enabled(gatts_val.p_value)) { + nrf_err = sd_ble_gatts_value_get(cgms->conn_handle, cgms->char_handles.socp.cccd_handle, + &gatts_val); + if (nrf_err || !is_indication_enabled(gatts_val.p_value)) { auth_reply.params.write.gatt_status = BLE_GATT_STATUS_ATTERR_CPS_CCCD_CONFIG_ERROR; } - err = sd_ble_gatts_rw_authorize_reply(cgms->conn_handle, &auth_reply); - if (err != NRF_SUCCESS) { + nrf_err = sd_ble_gatts_rw_authorize_reply(cgms->conn_handle, &auth_reply); + if (nrf_err) { if (cgms->evt_handler != NULL) { - cgms_evt.error.reason = err; + cgms_evt.error.reason = nrf_err; cgms_evt.evt_type = BLE_CGMS_EVT_ERROR; cgms->evt_handler(cgms, &cgms_evt); } diff --git a/subsys/bluetooth/services/ble_cgms/cgms_sst.c b/subsys/bluetooth/services/ble_cgms/cgms_sst.c index b012cf7d77..6abb97057d 100644 --- a/subsys/bluetooth/services/ble_cgms/cgms_sst.c +++ b/subsys/bluetooth/services/ble_cgms/cgms_sst.c @@ -91,12 +91,12 @@ static uint8_t sst_encode(struct ble_cgms_sst *sst, uint8_t *sst_encoded) static uint32_t cgm_update_sst(struct ble_cgms *cgms, const ble_gatts_evt_write_t *evt_write) { - uint32_t err; + uint32_t nrf_err; struct ble_cgms_sst sst = {0}; struct tm c_time_and_date; - err = sst_decode(&sst, evt_write->data, evt_write->len); - if (err != NRF_SUCCESS) { + nrf_err = sst_decode(&sst, evt_write->data, evt_write->len); + if (nrf_err) { /* Silently drop the update */ return NRF_SUCCESS; } @@ -110,7 +110,7 @@ static uint32_t cgm_update_sst(struct ble_cgms *cgms, const ble_gatts_evt_write_ /* Glucose session start time write event handler. */ static void on_sst_value_write(struct ble_cgms *cgms, const ble_gatts_evt_write_t *evt_write) { - uint32_t err; + uint32_t nrf_err; ble_gatts_rw_authorize_reply_params_t auth_reply = { .type = BLE_GATTS_AUTHORIZE_TYPE_WRITE, .params = { @@ -124,18 +124,18 @@ static void on_sst_value_write(struct ble_cgms *cgms, const ble_gatts_evt_write_ .evt_type = BLE_CGMS_EVT_ERROR, }; - err = sd_ble_gatts_rw_authorize_reply(cgms->conn_handle, &auth_reply); - if (err != NRF_SUCCESS) { + nrf_err = sd_ble_gatts_rw_authorize_reply(cgms->conn_handle, &auth_reply); + if (nrf_err) { if (cgms->evt_handler != NULL) { - cgms_evt.error.reason = err; + cgms_evt.error.reason = nrf_err; cgms->evt_handler(cgms, &cgms_evt); } } - err = cgm_update_sst(cgms, evt_write); - if (err != NRF_SUCCESS) { + nrf_err = cgm_update_sst(cgms, evt_write); + if (nrf_err) { if (cgms->evt_handler != NULL) { - cgms_evt.error.reason = err; + cgms_evt.error.reason = nrf_err; cgms->evt_handler(cgms, &cgms_evt); } } diff --git a/subsys/bluetooth/services/ble_hids/hids.c b/subsys/bluetooth/services/ble_hids/hids.c index ebbbac45ca..4008abe4d4 100644 --- a/subsys/bluetooth/services/ble_hids/hids.c +++ b/subsys/bluetooth/services/ble_hids/hids.c @@ -111,15 +111,15 @@ static struct ble_hids_char_id make_char_id(uint16_t uuid, uint8_t report_type, static void on_connect(struct ble_hids *hids, ble_evt_t const *ble_evt) { - uint32_t err; + uint32_t nrf_err; ble_gatts_value_t gatts_value; struct ble_hids_client_context *client = NULL; - err = link_ctx_get(hids, ble_evt->evt.gap_evt.conn_handle, (void *)&client); - if (err != NRF_SUCCESS) { + nrf_err = link_ctx_get(hids, ble_evt->evt.gap_evt.conn_handle, (void *)&client); + if (nrf_err) { struct ble_hids_evt evt = { .evt_type = BLE_HIDS_EVT_ERROR, - .params.error.reason = err, + .params.error.reason = nrf_err, }; hids->evt_handler(hids, &evt); @@ -142,13 +142,13 @@ static void on_connect(struct ble_hids *hids, ble_evt_t const *ble_evt) gatts_value.offset = 0; gatts_value.p_value = &client->protocol_mode; - err = sd_ble_gatts_value_set(ble_evt->evt.gap_evt.conn_handle, - hids->protocol_mode_handles.value_handle, - &gatts_value); - if (err != NRF_SUCCESS) { + nrf_err = sd_ble_gatts_value_set(ble_evt->evt.gap_evt.conn_handle, + hids->protocol_mode_handles.value_handle, + &gatts_value); + if (nrf_err) { struct ble_hids_evt evt = { .evt_type = BLE_HIDS_EVT_ERROR, - .params.error.reason = err, + .params.error.reason = nrf_err, }; hids->evt_handler(hids, &evt); @@ -158,15 +158,15 @@ static void on_connect(struct ble_hids *hids, ble_evt_t const *ble_evt) static void on_control_point_write(struct ble_hids *hids, ble_evt_t const *ble_evt) { - uint32_t err; + uint32_t nrf_err; struct ble_hids_client_context *host; ble_gatts_evt_write_t const *evt_write = &ble_evt->evt.gatts_evt.params.write; - err = link_ctx_get(hids, ble_evt->evt.gatts_evt.conn_handle, (void *)&host); - if (err != NRF_SUCCESS) { + nrf_err = link_ctx_get(hids, ble_evt->evt.gatts_evt.conn_handle, (void *)&host); + if (nrf_err) { struct ble_hids_evt evt = { .evt_type = BLE_HIDS_EVT_ERROR, - .params.error.reason = err, + .params.error.reason = nrf_err, }; hids->evt_handler(hids, &evt); @@ -206,15 +206,15 @@ static void on_control_point_write(struct ble_hids *hids, ble_evt_t const *ble_e static void on_protocol_mode_write(struct ble_hids *hids, ble_evt_t const *ble_evt) { - uint32_t err; + uint32_t nrf_err; struct ble_hids_client_context *host; ble_gatts_evt_write_t const *evt_write = &ble_evt->evt.gatts_evt.params.write; - err = link_ctx_get(hids, ble_evt->evt.gatts_evt.conn_handle, (void *)&host); - if (err != NRF_SUCCESS) { + nrf_err = link_ctx_get(hids, ble_evt->evt.gatts_evt.conn_handle, (void *)&host); + if (nrf_err) { struct ble_hids_evt evt = { .evt_type = BLE_HIDS_EVT_ERROR, - .params.error.reason = err, + .params.error.reason = nrf_err, }; hids->evt_handler(hids, &evt); @@ -254,17 +254,17 @@ static void on_protocol_mode_write(struct ble_hids *hids, ble_evt_t const *ble_e void on_protocol_mode_read_auth(struct ble_hids *hids, ble_evt_t const *ble_evt) { - uint32_t err; + uint32_t nrf_err; ble_gatts_rw_authorize_reply_params_t auth_read_params; struct ble_hids_client_context *host; ble_gatts_evt_rw_authorize_request_t const *read_auth = &ble_evt->evt.gatts_evt.params.authorize_request; - err = link_ctx_get(hids, ble_evt->evt.gatts_evt.conn_handle, (void *)&host); - if (err != NRF_SUCCESS) { + nrf_err = link_ctx_get(hids, ble_evt->evt.gatts_evt.conn_handle, (void *)&host); + if (nrf_err) { struct ble_hids_evt evt = { .evt_type = BLE_HIDS_EVT_ERROR, - .params.error.reason = err, + .params.error.reason = nrf_err, }; hids->evt_handler(hids, &evt); @@ -281,12 +281,12 @@ void on_protocol_mode_read_auth(struct ble_hids *hids, ble_evt_t const *ble_evt) auth_read_params.params.read.p_data = &host->protocol_mode; auth_read_params.params.read.update = 1; - err = sd_ble_gatts_rw_authorize_reply(ble_evt->evt.gap_evt.conn_handle, - &auth_read_params); - if (err != NRF_SUCCESS) { + nrf_err = sd_ble_gatts_rw_authorize_reply(ble_evt->evt.gap_evt.conn_handle, + &auth_read_params); + if (nrf_err) { struct ble_hids_evt evt = { .evt_type = BLE_HIDS_EVT_ERROR, - .params.error.reason = err, + .params.error.reason = nrf_err, }; hids->evt_handler(hids, &evt); @@ -322,16 +322,16 @@ static void on_report_value_write(struct ble_hids *hids, ble_evt_t const *ble_ev uint16_t rep_max_len) { /* Update host's Output Report data */ - uint32_t err; + uint32_t nrf_err; uint8_t *report; struct ble_hids_client_context *host; ble_gatts_evt_write_t const *write = &ble_evt->evt.gatts_evt.params.write; - err = link_ctx_get(hids, ble_evt->evt.gatts_evt.conn_handle, (void *)&host); - if (err != NRF_SUCCESS) { + nrf_err = link_ctx_get(hids, ble_evt->evt.gatts_evt.conn_handle, (void *)&host); + if (nrf_err) { struct ble_hids_evt evt = { .evt_type = BLE_HIDS_EVT_ERROR, - .params.error.reason = err, + .params.error.reason = nrf_err, }; hids->evt_handler(hids, &evt); @@ -368,13 +368,13 @@ static void on_report_value_read_auth(struct ble_hids *hids, struct ble_hids_cha struct ble_hids_client_context *host; uint8_t *report; uint16_t read_offset; - uint32_t err = NRF_SUCCESS; + uint32_t nrf_err = NRF_SUCCESS; - err = link_ctx_get(hids, ble_evt->evt.gatts_evt.conn_handle, (void *)&host); - if (err != NRF_SUCCESS) { + nrf_err = link_ctx_get(hids, ble_evt->evt.gatts_evt.conn_handle, (void *)&host); + if (nrf_err) { struct ble_hids_evt evt = { .evt_type = BLE_HIDS_EVT_ERROR, - .params.error.reason = err, + .params.error.reason = nrf_err, }; hids->evt_handler(hids, &evt); @@ -393,13 +393,13 @@ static void on_report_value_read_auth(struct ble_hids *hids, struct ble_hids_cha auth_read_params.params.read.p_data = report + read_offset; auth_read_params.params.read.update = 1; - err = sd_ble_gatts_rw_authorize_reply(ble_evt->evt.gap_evt.conn_handle, - &auth_read_params); + nrf_err = sd_ble_gatts_rw_authorize_reply(ble_evt->evt.gap_evt.conn_handle, + &auth_read_params); - if (err != NRF_SUCCESS) { + if (nrf_err) { struct ble_hids_evt evt = { .evt_type = BLE_HIDS_EVT_ERROR, - .params.error.reason = err, + .params.error.reason = nrf_err, }; hids->evt_handler(hids, &evt); @@ -633,7 +633,7 @@ static uint32_t rep_char_add(struct ble_hids *hids, ble_gatt_char_props_t *prope struct ble_hids_char_sec const *const char_sec, struct ble_hids_rep_char *rep_char) { - uint32_t err; + uint32_t nrf_err; uint8_t encoded_rep_ref[BLE_SRV_ENCODED_REPORT_REF_LEN] = { report_id, report_type }; ble_gatts_char_md_t char_md = { @@ -668,10 +668,10 @@ static uint32_t rep_char_add(struct ble_hids *hids, ble_gatt_char_props_t *prope char_md.p_cccd_md = &cccd_md; } - err = sd_ble_gatts_characteristic_add(hids->service_handle, &char_md, &attr_char_value, - &rep_char->char_handles); - if (err != NRF_SUCCESS) { - return err; + nrf_err = sd_ble_gatts_characteristic_add(hids->service_handle, &char_md, &attr_char_value, + &rep_char->char_handles); + if (nrf_err) { + return nrf_err; } ble_uuid_t desc_uuid = { @@ -698,7 +698,7 @@ static uint32_t rep_char_add(struct ble_hids *hids, ble_gatt_char_props_t *prope static uint32_t rep_map_char_add(struct ble_hids *hids, const struct ble_hids_config *hids_cfg) { - uint32_t err; + uint32_t nrf_err; ble_gatts_char_md_t char_md = { .char_props = { .read = 1, @@ -721,10 +721,10 @@ static uint32_t rep_map_char_add(struct ble_hids *hids, const struct ble_hids_co .p_value = hids_cfg->report_map.data, }; - err = sd_ble_gatts_characteristic_add(hids->service_handle, &char_md, &attr_char_value, - &hids->rep_map_handles); - if (err != NRF_SUCCESS) { - return err; + nrf_err = sd_ble_gatts_characteristic_add(hids->service_handle, &char_md, &attr_char_value, + &hids->rep_map_handles); + if (nrf_err) { + return nrf_err; } if (hids_cfg->report_map.ext_rep_ref_num != 0 && hids_cfg->report_map.ext_rep_ref == NULL) { @@ -735,10 +735,10 @@ static uint32_t rep_map_char_add(struct ble_hids *hids, const struct ble_hids_co uint8_t encoded_rep_ref[sizeof(ble_uuid128_t)]; uint8_t encoded_rep_ref_len; - err = sd_ble_uuid_encode(&hids_cfg->report_map.ext_rep_ref[i], &encoded_rep_ref_len, - encoded_rep_ref); - if (err != NRF_SUCCESS) { - return err; + nrf_err = sd_ble_uuid_encode(&hids_cfg->report_map.ext_rep_ref[i], + &encoded_rep_ref_len, encoded_rep_ref); + if (nrf_err) { + return nrf_err; } ble_uuid_t desc_uuid = { @@ -757,10 +757,11 @@ static uint32_t rep_map_char_add(struct ble_hids *hids, const struct ble_hids_co .p_value = encoded_rep_ref, }; - err = sd_ble_gatts_descriptor_add(hids->rep_map_handles.value_handle, &descr_params, - &hids->rep_map_ext_rep_ref_handle); - if (err != NRF_SUCCESS) { - return err; + nrf_err = sd_ble_gatts_descriptor_add(hids->rep_map_handles.value_handle, + &descr_params, + &hids->rep_map_ext_rep_ref_handle); + if (nrf_err) { + return nrf_err; } } @@ -908,7 +909,7 @@ static uint32_t hid_control_point_char_add(struct ble_hids *hids, static uint32_t inp_rep_characteristics_add(struct ble_hids *hids, const struct ble_hids_config *hids_cfg) { - uint32_t err; + uint32_t nrf_err; if ((hids_cfg->input_report_count != 0) && (hids_cfg->input_report != NULL)) { for (uint8_t i = 0; i < hids_cfg->input_report_count; i++) { @@ -919,11 +920,12 @@ static uint32_t inp_rep_characteristics_add(struct ble_hids *hids, .notify = true, }; - err = rep_char_add(hids, &properties, rep_init->len, rep_init->report_id, - rep_init->report_type, &rep_init->sec, - &hids->inp_rep_array[i]); - if (err != NRF_SUCCESS) { - return err; + nrf_err = rep_char_add(hids, &properties, rep_init->len, + rep_init->report_id, + rep_init->report_type, &rep_init->sec, + &hids->inp_rep_array[i]); + if (nrf_err) { + return nrf_err; } } } @@ -934,7 +936,7 @@ static uint32_t inp_rep_characteristics_add(struct ble_hids *hids, static uint32_t outp_rep_characteristics_add(struct ble_hids *hids, const struct ble_hids_config *hids_cfg) { - uint32_t err; + uint32_t nrf_err; if ((hids_cfg->output_report_count != 0) && (hids_cfg->output_report != NULL)) { for (uint8_t i = 0; i < hids_cfg->output_report_count; i++) { @@ -946,11 +948,12 @@ static uint32_t outp_rep_characteristics_add(struct ble_hids *hids, .write_wo_resp = true, }; - err = rep_char_add(hids, &properties, rep_init->len, rep_init->report_id, - rep_init->report_type, &rep_init->sec, - &hids->outp_rep_array[i]); - if (err != NRF_SUCCESS) { - return err; + nrf_err = rep_char_add(hids, &properties, rep_init->len, + rep_init->report_id, + rep_init->report_type, &rep_init->sec, + &hids->outp_rep_array[i]); + if (nrf_err) { + return nrf_err; } } } @@ -961,7 +964,7 @@ static uint32_t outp_rep_characteristics_add(struct ble_hids *hids, static uint32_t feature_rep_characteristics_add(struct ble_hids *hids, const struct ble_hids_config *hids_cfg) { - uint32_t err; + uint32_t nrf_err; if ((hids_cfg->feature_report_count != 0) && (hids_cfg->feature_report != NULL)) { for (uint8_t i = 0; i < hids_cfg->feature_report_count; i++) { @@ -973,11 +976,12 @@ static uint32_t feature_rep_characteristics_add(struct ble_hids *hids, .write = true, }; - err = rep_char_add(hids, &properties, rep_init->len, rep_init->report_id, - rep_init->report_type, &rep_init->sec, - &hids->feature_rep_array[i]); - if (err != NRF_SUCCESS) { - return err; + nrf_err = rep_char_add(hids, &properties, rep_init->len, + rep_init->report_id, + rep_init->report_type, &rep_init->sec, + &hids->feature_rep_array[i]); + if (nrf_err) { + return nrf_err; } } } @@ -987,15 +991,15 @@ static uint32_t feature_rep_characteristics_add(struct ble_hids *hids, static uint32_t includes_add(struct ble_hids *hids, const struct ble_hids_config *hids_cfg) { - uint32_t err; + uint32_t nrf_err; uint16_t unused_include_handle; for (uint8_t i = 0; i < hids_cfg->included_services_count; i++) { - err = sd_ble_gatts_include_add(hids->service_handle, - hids_cfg->included_services_array[i], - &unused_include_handle); - if (err != NRF_SUCCESS) { - return err; + nrf_err = sd_ble_gatts_include_add(hids->service_handle, + hids_cfg->included_services_array[i], + &unused_include_handle); + if (nrf_err) { + return nrf_err; } } @@ -1004,7 +1008,7 @@ static uint32_t includes_add(struct ble_hids *hids, const struct ble_hids_config uint32_t ble_hids_init(struct ble_hids *hids, const struct ble_hids_config *hids_cfg) { - uint32_t err; + uint32_t nrf_err; ble_uuid_t ble_uuid; if (!hids || !hids_cfg) { @@ -1028,97 +1032,97 @@ uint32_t ble_hids_init(struct ble_hids *hids, const struct ble_hids_config *hids BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_HUMAN_INTERFACE_DEVICE_SERVICE); - err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, - &hids->service_handle); - if (err != NRF_SUCCESS) { - return err; + nrf_err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, + &hids->service_handle); + if (nrf_err) { + return nrf_err; } - err = includes_add(hids, hids_cfg); - if (err != NRF_SUCCESS) { - return err; + nrf_err = includes_add(hids, hids_cfg); + if (nrf_err) { + return nrf_err; } #if defined(CONFIG_BLE_HIDS_BOOT_KEYBOARD) || defined(CONFIG_BLE_HIDS_BOOT_MOUSE) /* Add Protocol Mode characteristic. */ - err = protocol_mode_char_add(hids, hids_cfg->protocol_mode_sec.read, - hids_cfg->protocol_mode_sec.write); - if (err != NRF_SUCCESS) { - return err; + nrf_err = protocol_mode_char_add(hids, hids_cfg->protocol_mode_sec.read, + hids_cfg->protocol_mode_sec.write); + if (nrf_err) { + return nrf_err; } #endif /* Add Input Report characteristics (if any). */ - err = inp_rep_characteristics_add(hids, hids_cfg); - if (err != NRF_SUCCESS) { - return err; + nrf_err = inp_rep_characteristics_add(hids, hids_cfg); + if (nrf_err) { + return nrf_err; } /* Add Output Report characteristics (if any). */ - err = outp_rep_characteristics_add(hids, hids_cfg); - if (err != NRF_SUCCESS) { - return err; + nrf_err = outp_rep_characteristics_add(hids, hids_cfg); + if (nrf_err) { + return nrf_err; } /* Add Feature Report characteristic (if any). */ - err = feature_rep_characteristics_add(hids, hids_cfg); - if (err != NRF_SUCCESS) { - return err; + nrf_err = feature_rep_characteristics_add(hids, hids_cfg); + if (nrf_err) { + return nrf_err; } /* Add Report Map characteristic. */ - err = rep_map_char_add(hids, hids_cfg); - if (err != NRF_SUCCESS) { - return err; + nrf_err = rep_map_char_add(hids, hids_cfg); + if (nrf_err) { + return nrf_err; } #if defined(CONFIG_BLE_HIDS_BOOT_KEYBOARD) /* Add Boot Keyboard Input Report characteristic. */ - err = boot_inp_rep_char_add(hids, BLE_UUID_BOOT_KEYBOARD_INPUT_REPORT_CHAR, - BLE_HIDS_BOOT_KB_INPUT_REPORT_MAX_SIZE, - &hids_cfg->boot_kb_inp_rep_sec, - &hids->boot_kb_inp_rep_handles); - if (err != NRF_SUCCESS) { - return err; + nrf_err = boot_inp_rep_char_add(hids, BLE_UUID_BOOT_KEYBOARD_INPUT_REPORT_CHAR, + BLE_HIDS_BOOT_KB_INPUT_REPORT_MAX_SIZE, + &hids_cfg->boot_kb_inp_rep_sec, + &hids->boot_kb_inp_rep_handles); + if (nrf_err) { + return nrf_err; } /* Add Boot Keyboard Output Report characteristic. */ - err = boot_kb_outp_rep_char_add(hids, hids_cfg); - if (err != NRF_SUCCESS) { - return err; + nrf_err = boot_kb_outp_rep_char_add(hids, hids_cfg); + if (nrf_err) { + return nrf_err; } #endif #if defined(CONFIG_BLE_HIDS_BOOT_MOUSE) /* Add Boot Mouse Input Report characteristic. */ - err = boot_inp_rep_char_add( + nrf_err = boot_inp_rep_char_add( hids, BLE_UUID_BOOT_MOUSE_INPUT_REPORT_CHAR, BLE_HIDS_BOOT_MOUSE_INPUT_REPORT_MAX_SIZE, &hids_cfg->boot_mouse_inp_rep_sec, &hids->boot_mouse_inp_rep_handles); - if (err != NRF_SUCCESS) { - return err; + if (nrf_err) { + return nrf_err; } #endif /* Add HID Information characteristic. */ - err = hid_information_char_add(hids, hids_cfg); - if (err != NRF_SUCCESS) { - return err; + nrf_err = hid_information_char_add(hids, hids_cfg); + if (nrf_err) { + return nrf_err; } /* Add HID Control Point characteristic. */ - err = hid_control_point_char_add(hids, hids_cfg->ctrl_point_sec.write); - if (err != NRF_SUCCESS) { - return err; + nrf_err = hid_control_point_char_add(hids, hids_cfg->ctrl_point_sec.write); + if (nrf_err) { + return nrf_err; } - return err; + return nrf_err; } uint32_t ble_hids_inp_rep_send(struct ble_hids *hids, uint16_t conn_handle, struct ble_hids_input_report *report) { - uint32_t err; + uint32_t nrf_err; if (!hids || !report || !report->data) { return NRF_ERROR_NULL; @@ -1133,10 +1137,10 @@ uint32_t ble_hids_inp_rep_send(struct ble_hids *hids, uint16_t conn_handle, uint16_t hvx_len = report->len; uint8_t *host_rep_data; - err = link_ctx_get(hids, conn_handle, (void *)&host_rep_data); - if (err != NRF_SUCCESS) { - LOG_ERR("Failed to get link context, nrf_err %d", err); - return err; + nrf_err = link_ctx_get(hids, conn_handle, (void *)&host_rep_data); + if (nrf_err) { + LOG_ERR("Failed to get link context, nrf_error %#x", nrf_err); + return nrf_err; } host_rep_data += sizeof(struct ble_hids_client_context) + @@ -1165,19 +1169,19 @@ uint32_t ble_hids_inp_rep_send(struct ble_hids *hids, uint16_t conn_handle, hvx_params.p_len = &hvx_len; hvx_params.p_data = report->data; - err = sd_ble_gatts_hvx(conn_handle, &hvx_params); - if ((err == NRF_SUCCESS) && (*hvx_params.p_len != report->len)) { - LOG_ERR("Failed to update attribute value, nrf_err %d", err); - err = NRF_ERROR_DATA_SIZE; + nrf_err = sd_ble_gatts_hvx(conn_handle, &hvx_params); + if ((nrf_err == NRF_SUCCESS) && (*hvx_params.p_len != report->len)) { + LOG_ERR("Failed to update attribute value, nrf_error %#x", nrf_err); + nrf_err = NRF_ERROR_DATA_SIZE; } } else { - err = NRF_ERROR_INVALID_STATE; + nrf_err = NRF_ERROR_INVALID_STATE; } } else { - err = NRF_ERROR_INVALID_PARAM; + nrf_err = NRF_ERROR_INVALID_PARAM; } - return err; + return nrf_err; } uint32_t ble_hids_boot_kb_inp_rep_send(struct ble_hids *hids, uint16_t conn_handle, @@ -1187,16 +1191,16 @@ uint32_t ble_hids_boot_kb_inp_rep_send(struct ble_hids *hids, uint16_t conn_hand return NRF_ERROR_NULL; } - uint32_t err; + uint32_t nrf_err; if (conn_handle != BLE_CONN_HANDLE_INVALID) { ble_gatts_hvx_params_t hvx_params; uint16_t hvx_len = report->len; uint8_t *host_rep_data; - err = link_ctx_get(hids, conn_handle, (void *)&host_rep_data); - if (err != NRF_SUCCESS) { - return err; + nrf_err = link_ctx_get(hids, conn_handle, (void *)&host_rep_data); + if (nrf_err) { + return nrf_err; } host_rep_data += sizeof(struct ble_hids_client_context); @@ -1215,15 +1219,15 @@ uint32_t ble_hids_boot_kb_inp_rep_send(struct ble_hids *hids, uint16_t conn_hand hvx_params.p_len = &hvx_len; hvx_params.p_data = report->data; - err = sd_ble_gatts_hvx(conn_handle, &hvx_params); - if ((err == NRF_SUCCESS) && (*hvx_params.p_len != report->len)) { - err = NRF_ERROR_DATA_SIZE; + nrf_err = sd_ble_gatts_hvx(conn_handle, &hvx_params); + if ((nrf_err == NRF_SUCCESS) && (*hvx_params.p_len != report->len)) { + nrf_err = NRF_ERROR_DATA_SIZE; } } else { - err = NRF_ERROR_INVALID_STATE; + nrf_err = NRF_ERROR_INVALID_STATE; } - return err; + return nrf_err; } uint32_t ble_hids_boot_mouse_inp_rep_send(struct ble_hids *hids, uint16_t conn_handle, @@ -1233,7 +1237,7 @@ uint32_t ble_hids_boot_mouse_inp_rep_send(struct ble_hids *hids, uint16_t conn_h return NRF_ERROR_NULL; } - uint32_t err; + uint32_t nrf_err; if (conn_handle != BLE_CONN_HANDLE_INVALID) { uint16_t hvx_len = BOOT_MOUSE_INPUT_REPORT_MIN_SIZE + report->optional_data_len; @@ -1243,9 +1247,9 @@ uint32_t ble_hids_boot_mouse_inp_rep_send(struct ble_hids *hids, uint16_t conn_h ble_gatts_hvx_params_t hvx_params; uint8_t *host_rep_data; - err = link_ctx_get(hids, conn_handle, (void *)&host_rep_data); - if (err != NRF_SUCCESS) { - return err; + nrf_err = link_ctx_get(hids, conn_handle, (void *)&host_rep_data); + if (nrf_err) { + return nrf_err; } host_rep_data += sizeof(struct ble_hids_client_context) + @@ -1276,20 +1280,20 @@ uint32_t ble_hids_boot_mouse_inp_rep_send(struct ble_hids *hids, uint16_t conn_h hvx_params.p_len = &hvx_len; hvx_params.p_data = buffer; - err = sd_ble_gatts_hvx(conn_handle, &hvx_params); - if ((err == NRF_SUCCESS) && + nrf_err = sd_ble_gatts_hvx(conn_handle, &hvx_params); + if ((nrf_err == NRF_SUCCESS) && (*hvx_params.p_len != (BOOT_MOUSE_INPUT_REPORT_MIN_SIZE + report->optional_data_len))) { - err = NRF_ERROR_DATA_SIZE; + nrf_err = NRF_ERROR_DATA_SIZE; } } else { - err = NRF_ERROR_DATA_SIZE; + nrf_err = NRF_ERROR_DATA_SIZE; } } else { - err = NRF_ERROR_INVALID_STATE; + nrf_err = NRF_ERROR_INVALID_STATE; } - return err; + return nrf_err; } uint32_t ble_hids_outp_rep_get(struct ble_hids *hids, uint8_t report_index, uint16_t len, @@ -1299,7 +1303,7 @@ uint32_t ble_hids_outp_rep_get(struct ble_hids *hids, uint8_t report_index, uint return NRF_ERROR_NULL; } - uint32_t err; + uint32_t nrf_err; uint8_t *rep_data; uint8_t index; @@ -1307,9 +1311,9 @@ uint32_t ble_hids_outp_rep_get(struct ble_hids *hids, uint8_t report_index, uint return NRF_ERROR_INVALID_PARAM; } - err = link_ctx_get(hids, conn_handle, (void *)&rep_data); - if (err != NRF_SUCCESS) { - return err; + nrf_err = link_ctx_get(hids, conn_handle, (void *)&rep_data); + if (nrf_err) { + return nrf_err; } rep_data += sizeof(struct ble_hids_client_context) + diff --git a/subsys/bluetooth/services/ble_lbs/lbs.c b/subsys/bluetooth/services/ble_lbs/lbs.c index 3d699c7890..71ff2dc584 100644 --- a/subsys/bluetooth/services/ble_lbs/lbs.c +++ b/subsys/bluetooth/services/ble_lbs/lbs.c @@ -52,7 +52,7 @@ void ble_lbs_on_ble_evt(const ble_evt_t *ble_evt, void *lbs_instance) int ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg) { - int err; + uint32_t nrf_err; ble_uuid_t ble_uuid; uint8_t initial_value = 0; @@ -65,9 +65,9 @@ int ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg) ble_uuid128_t base_uuid = { .uuid128 = BLE_UUID_LBS_BASE }; - err = sd_ble_uuid_vs_add(&base_uuid, &lbs->uuid_type); - if (err != NRF_SUCCESS) { - LOG_ERR("Failed to add vendor UUID, nrf_error %#x", err); + nrf_err = sd_ble_uuid_vs_add(&base_uuid, &lbs->uuid_type); + if (nrf_err) { + LOG_ERR("Failed to add vendor UUID, nrf_error %#x", nrf_err); return -EINVAL; } @@ -77,10 +77,10 @@ int ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg) }; /* Add service. */ - err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, + nrf_err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &lbs->service_handle); - if (err != NRF_SUCCESS) { - LOG_ERR("Failed to add GATT service, nrf_error %#x", err); + if (nrf_err) { + LOG_ERR("Failed to add GATT service, nrf_error %#x", nrf_err); return -EINVAL; } @@ -113,10 +113,10 @@ int ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg) BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm); BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm); - err = sd_ble_gatts_characteristic_add(lbs->service_handle, &char_md, &attr_char_value, + nrf_err = sd_ble_gatts_characteristic_add(lbs->service_handle, &char_md, &attr_char_value, &lbs->button_char_handles); - if (err) { - LOG_ERR("Failed to add button GATT characteristic, nrf_error %#x", err); + if (nrf_err) { + LOG_ERR("Failed to add button GATT characteristic, nrf_error %#x", nrf_err); return -EINVAL; } @@ -145,10 +145,10 @@ int ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg) BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm); BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm); - err = sd_ble_gatts_characteristic_add(lbs->service_handle, &char_md, &attr_char_value, + nrf_err = sd_ble_gatts_characteristic_add(lbs->service_handle, &char_md, &attr_char_value, &lbs->led_char_handles); - if (err) { - LOG_ERR("Failed to add LED GATT characteristic, nrf_error %#x", err); + if (nrf_err) { + LOG_ERR("Failed to add LED GATT characteristic, nrf_error %#x", nrf_err); return -EINVAL; } diff --git a/subsys/logging/backends/log_backend_bm_uarte.c b/subsys/logging/backends/log_backend_bm_uarte.c index cd76cd2fbb..5a1f68d19c 100644 --- a/subsys/logging/backends/log_backend_bm_uarte.c +++ b/subsys/logging/backends/log_backend_bm_uarte.c @@ -28,7 +28,7 @@ ISR_DIRECT_DECLARE(log_backend_bm_uarte_direct_isr) static int uarte_init(void) { - int err; + nrfx_err_t nrfx_err; nrfx_uarte_config_t uarte_config = NRFX_UARTE_DEFAULT_CONFIG( BOARD_CONSOLE_UARTE_PIN_TX, NRF_UARTE_PSEL_DISCONNECTED); @@ -54,9 +54,9 @@ static int uarte_init(void) irq_enable(NRFX_IRQ_NUMBER_GET(NRF_UARTE_INST_GET(BOARD_CONSOLE_UARTE_INST))); - err = nrfx_uarte_init(&uarte_inst, &uarte_config, NULL); - if (err != NRFX_SUCCESS) { - return err; + nrfx_err = nrfx_uarte_init(&uarte_inst, &uarte_config, NULL); + if (nrfx_err != NRFX_SUCCESS) { + return nrfx_err; } return 0; diff --git a/subsys/mgmt/mcumgr/transport/src/bm_uart_mcumgr.c b/subsys/mgmt/mcumgr/transport/src/bm_uart_mcumgr.c index db2a914280..3d9b7697c6 100644 --- a/subsys/mgmt/mcumgr/transport/src/bm_uart_mcumgr.c +++ b/subsys/mgmt/mcumgr/transport/src/bm_uart_mcumgr.c @@ -207,7 +207,7 @@ ISR_DIRECT_DECLARE(bm_uart_mcumgr_direct_isr) */ static int bm_uarte_init(void) { - int err; + nrfx_err_t nrfx_err; nrfx_uarte_config_t uarte_config = NRFX_UARTE_DEFAULT_CONFIG(BOARD_APP_UARTE_PIN_TX, BOARD_APP_UARTE_PIN_RX); @@ -231,20 +231,20 @@ static int bm_uarte_init(void) irq_enable(NRFX_IRQ_NUMBER_GET(NRF_UARTE_INST_GET(BOARD_APP_UARTE_INST))); - err = nrfx_uarte_init(&uarte_inst, &uarte_config, uarte_event_handler); + nrfx_err = nrfx_uarte_init(&uarte_inst, &uarte_config, uarte_event_handler); - if (err != NRFX_SUCCESS) { - LOG_ERR("Failed to initialize UART, nrfx err %d", err); - return err; + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("Failed to initialize UART, nrfx_err %#x", nrfx_err); + return nrfx_err; } - err = nrfx_uarte_rx(&uarte_inst, uarte_rx_buf, 1); + nrfx_err = nrfx_uarte_rx(&uarte_inst, uarte_rx_buf, 1); - if (err != NRFX_SUCCESS) { - LOG_ERR("UART RX failed, nrfx err %d", err); + if (nrfx_err != NRFX_SUCCESS) { + LOG_ERR("UART RX failed, nrfx_err %#x", nrfx_err); } - return err; + return nrfx_err; } SYS_INIT(bm_uarte_init, APPLICATION, 0); diff --git a/subsys/softdevice_handler/nrf_sdh_soc.c b/subsys/softdevice_handler/nrf_sdh_soc.c index e95ad87db5..093bb8b773 100644 --- a/subsys/softdevice_handler/nrf_sdh_soc.c +++ b/subsys/softdevice_handler/nrf_sdh_soc.c @@ -45,15 +45,15 @@ static const char *tostr(uint32_t evt) static void softdevice_rng_seed(void) { - uint32_t err = NRF_ERROR_INVALID_DATA; + uint32_t nrf_err = NRF_ERROR_INVALID_DATA; psa_status_t status; uint8_t seed[SD_RAND_SEED_SIZE]; status = cracen_get_trng(seed, sizeof(seed)); if (status == PSA_SUCCESS) { - err = sd_rand_seed_set(seed); + nrf_err = sd_rand_seed_set(seed); memset(seed, 0, sizeof(seed)); - if (err == NRF_SUCCESS) { + if (nrf_err == NRF_SUCCESS) { LOG_DBG("SoftDevice RNG seeded"); return; } @@ -61,17 +61,17 @@ static void softdevice_rng_seed(void) LOG_ERR("Generate random failed, psa status %d", status); } - LOG_ERR("Failed to seed SoftDevice RNG, nrf_error %#x", err); + LOG_ERR("Failed to seed SoftDevice RNG, nrf_error %#x", nrf_err); } static void soc_evt_poll(void *context) { - uint32_t err; + uint32_t nrf_err; uint32_t evt_id; while (true) { - err = sd_evt_get(&evt_id); - if (err != NRF_SUCCESS) { + nrf_err = sd_evt_get(&evt_id); + if (nrf_err) { break; } @@ -92,8 +92,8 @@ static void soc_evt_poll(void *context) } } - __ASSERT(err == NRF_ERROR_NOT_FOUND, - "Failed to receive SoftDevice event, nrf_error %#x", err); + __ASSERT(nrf_err == NRF_ERROR_NOT_FOUND, + "Failed to receive SoftDevice event, nrf_error %#x", nrf_err); } /* Listen to SoftDevice events */ diff --git a/tests/lib/bluetooth/ble_adv/src/unity_test.c b/tests/lib/bluetooth/ble_adv/src/unity_test.c index 34cfeb4ac4..b5ddce3510 100644 --- a/tests/lib/bluetooth/ble_adv/src/unity_test.c +++ b/tests/lib/bluetooth/ble_adv/src/unity_test.c @@ -27,13 +27,13 @@ void test_ble_adv_conn_cfg_tag_set(void) { struct ble_adv ble_adv; uint8_t conn_cfg_tag = 1; - int ret; + uint32_t nrf_err; - ret = ble_adv_conn_cfg_tag_set(NULL, conn_cfg_tag); - TEST_ASSERT_EQUAL(NRF_ERROR_NULL, ret); + nrf_err = ble_adv_conn_cfg_tag_set(NULL, conn_cfg_tag); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); - ret = ble_adv_conn_cfg_tag_set(&ble_adv, conn_cfg_tag); - TEST_ASSERT_EQUAL(0, ret); + nrf_err = ble_adv_conn_cfg_tag_set(&ble_adv, conn_cfg_tag); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); TEST_ASSERT_EQUAL(conn_cfg_tag, ble_adv.conn_cfg_tag); } @@ -45,15 +45,15 @@ void test_ble_adv_init_error_null(void) .conn_cfg_tag = 1, .evt_handler = ble_adv_evt_handler, }; - int ret; + uint32_t nrf_err; - ret = ble_adv_init(NULL, &config); - TEST_ASSERT_EQUAL(NRF_ERROR_NULL, ret); - ret = ble_adv_init(&ble_adv, NULL); - TEST_ASSERT_EQUAL(NRF_ERROR_NULL, ret); + nrf_err = ble_adv_init(NULL, &config); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); + nrf_err = ble_adv_init(&ble_adv, NULL); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); config.evt_handler = NULL; - ret = ble_adv_init(&ble_adv, &config); - TEST_ASSERT_EQUAL(NRF_ERROR_NULL, ret); + nrf_err = ble_adv_init(&ble_adv, &config); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); } void test_ble_adv_init_error_invalid_param(void) @@ -66,29 +66,32 @@ void test_ble_adv_init_error_invalid_param(void) .evt_handler = ble_adv_evt_handler, }; ble_gap_conn_sec_mode_t sec_mode = {0}; - int ret; + uint32_t nrf_err; BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); /* Simulate an error in setting the device name */ __cmock_sd_ble_gap_device_name_set_ExpectAndReturn(&sec_mode, CONFIG_BLE_ADV_NAME, - strlen(CONFIG_BLE_ADV_NAME), NRF_ERROR_INVALID_ADDR); - ret = ble_adv_init(&ble_adv, &config); - TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, ret); + strlen(CONFIG_BLE_ADV_NAME), + NRF_ERROR_INVALID_ADDR); + nrf_err = ble_adv_init(&ble_adv, &config); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, nrf_err); /* Simulate an error in setting the adv config */ __cmock_sd_ble_gap_device_name_set_ExpectAndReturn(&sec_mode, CONFIG_BLE_ADV_NAME, - strlen(CONFIG_BLE_ADV_NAME), NRF_SUCCESS); + strlen(CONFIG_BLE_ADV_NAME), + NRF_SUCCESS); __cmock_sd_ble_gap_adv_set_configure_ExpectAndReturn(&ble_adv.adv_handle, - NULL, &ble_adv.adv_params, NRF_ERROR_INVALID_ADDR); - ret = ble_adv_init(&ble_adv, &config); - TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, ret); + NULL, &ble_adv.adv_params, + NRF_ERROR_INVALID_ADDR); + nrf_err = ble_adv_init(&ble_adv, &config); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, nrf_err); } void test_ble_adv_init(void) { uint8_t conn_cfg_tag = 1; - int ret; + uint32_t nrf_err; struct ble_adv ble_adv = { .adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET, }; @@ -101,8 +104,8 @@ void test_ble_adv_init(void) __cmock_sd_ble_gap_device_name_set_IgnoreAndReturn(NRF_SUCCESS); __cmock_sd_ble_gap_adv_set_configure_IgnoreAndReturn(NRF_SUCCESS); - ret = ble_adv_init(&ble_adv, &config); - TEST_ASSERT_EQUAL(0, ret); + nrf_err = ble_adv_init(&ble_adv, &config); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); TEST_ASSERT_TRUE(ble_adv.mode_current == BLE_ADV_MODE_IDLE); TEST_ASSERT_TRUE(ble_adv.conn_cfg_tag == conn_cfg_tag); TEST_ASSERT_TRUE(ble_adv.conn_handle == BLE_CONN_HANDLE_INVALID); @@ -123,16 +126,16 @@ void test_ble_adv_peer_addr_reply(void) .peer_addr_reply_expected = true, }; ble_gap_addr_t peer_addr = {0}; - int ret; + uint32_t nrf_err; - ret = ble_adv_peer_addr_reply(NULL, &peer_addr); - TEST_ASSERT_EQUAL(NRF_ERROR_NULL, ret); + nrf_err = ble_adv_peer_addr_reply(NULL, &peer_addr); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); - ret = ble_adv_peer_addr_reply(&ble_adv, NULL); - TEST_ASSERT_EQUAL(NRF_ERROR_NULL, ret); + nrf_err = ble_adv_peer_addr_reply(&ble_adv, NULL); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); - ret = ble_adv_peer_addr_reply(&ble_adv, &peer_addr); - TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, ret); + nrf_err = ble_adv_peer_addr_reply(&ble_adv, &peer_addr); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, nrf_err); peer_addr = (ble_gap_addr_t){ .addr_id_peer = 0, @@ -140,8 +143,8 @@ void test_ble_adv_peer_addr_reply(void) .addr = {0x01, 0x02, 0x03, 0x00, 0x05, 0x06} }; - ret = ble_adv_peer_addr_reply(&ble_adv, &peer_addr); - TEST_ASSERT_EQUAL(0, ret); + nrf_err = ble_adv_peer_addr_reply(&ble_adv, &peer_addr); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); TEST_ASSERT_TRUE(ble_adv.peer_addr_reply_expected == false); TEST_ASSERT_TRUE(ble_adv.peer_address.addr_type == peer_addr.addr_type); TEST_ASSERT_TRUE( @@ -152,29 +155,29 @@ void test_ble_adv_peer_addr_reply(void) void test_ble_adv_whitelist_reply(void) { struct ble_adv ble_adv_config = {0}; - int ret; + uint32_t nrf_err; const ble_gap_addr_t addrs = {0}; const ble_gap_irk_t irks = {0}; - ret = ble_adv_whitelist_reply(NULL, &addrs, 0, &irks, 0); - TEST_ASSERT_EQUAL(NRF_ERROR_NULL, ret); + nrf_err = ble_adv_whitelist_reply(NULL, &addrs, 0, &irks, 0); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); - ret = ble_adv_whitelist_reply(&ble_adv_config, &addrs, 0, &irks, 0); - TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_STATE, ret); + nrf_err = ble_adv_whitelist_reply(&ble_adv_config, &addrs, 0, &irks, 0); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_STATE, nrf_err); ble_adv_config.whitelist_reply_expected = NULL; - ret = ble_adv_whitelist_reply(&ble_adv_config, NULL, 0, NULL, 0); - TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_STATE, ret); + nrf_err = ble_adv_whitelist_reply(&ble_adv_config, NULL, 0, NULL, 0); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_STATE, nrf_err); ble_adv_config.whitelist_reply_expected = true; - ret = ble_adv_whitelist_reply(&ble_adv_config, &addrs, 0, &irks, 0); - TEST_ASSERT_EQUAL(0, ret); + nrf_err = ble_adv_whitelist_reply(&ble_adv_config, &addrs, 0, &irks, 0); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); TEST_ASSERT_TRUE(ble_adv_config.whitelist_reply_expected == false); TEST_ASSERT_TRUE(ble_adv_config.whitelist_in_use == false); ble_adv_config.whitelist_reply_expected = true; - ret = ble_adv_whitelist_reply(&ble_adv_config, &addrs, 1, &irks, 0); - TEST_ASSERT_EQUAL(0, ret); + nrf_err = ble_adv_whitelist_reply(&ble_adv_config, &addrs, 1, &irks, 0); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); TEST_ASSERT_TRUE(ble_adv_config.whitelist_reply_expected == false); TEST_ASSERT_TRUE(ble_adv_config.whitelist_in_use == true); } @@ -202,7 +205,7 @@ void test_ble_adv_start(void) CONFIG_BLE_ADV_DIRECTED_ADVERTISING_INTERVAL, CONFIG_BLE_ADV_FAST_ADVERTISING_INTERVAL, CONFIG_BLE_ADV_SLOW_ADVERTISING_INTERVAL, 0}; - int ret; + uint32_t nrf_err; /* Verifying the different adv modes in the ble_adv_mode array */ for (int i = 0; i < MAX_ADV_MODES; i++) { @@ -214,8 +217,8 @@ void test_ble_adv_start(void) __cmock_sd_ble_gap_adv_set_configure_IgnoreAndReturn(NRF_SUCCESS); __cmock_sd_ble_gap_adv_start_IgnoreAndReturn(NRF_SUCCESS); - ret = ble_adv_start(&ble_adv, mode[i]); - TEST_ASSERT_EQUAL(0, ret); + nrf_err = ble_adv_start(&ble_adv, mode[i]); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); TEST_ASSERT_TRUE(ble_adv.mode_current == mode[i]); TEST_ASSERT_TRUE(ble_adv.whitelist_in_use == false); TEST_ASSERT_TRUE(ble_adv.adv_params.primary_phy == CONFIG_BLE_ADV_PRIMARY_PHY); @@ -255,16 +258,16 @@ void test_ble_adv_start_error_invalid_param(void) .evt_handler = ble_adv_evt_handler, .whitelist_temporarily_disabled = false, }; - int ret; + uint32_t nrf_err; __cmock_sd_ble_gap_adv_set_configure_IgnoreAndReturn(NRF_ERROR_INVALID_PARAM); - ret = ble_adv_start(&ble_adv, BLE_ADV_MODE_SLOW); - TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, ret); + nrf_err = ble_adv_start(&ble_adv, BLE_ADV_MODE_SLOW); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, nrf_err); __cmock_sd_ble_gap_adv_set_configure_IgnoreAndReturn(NRF_SUCCESS); __cmock_sd_ble_gap_adv_start_IgnoreAndReturn(NRF_ERROR_INVALID_STATE); - ret = ble_adv_start(&ble_adv, BLE_ADV_MODE_SLOW); - TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, ret); + nrf_err = ble_adv_start(&ble_adv, BLE_ADV_MODE_SLOW); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, nrf_err); } void setUp(void) From 3036d8c3b81af30b57a14929b2abf01d2ffb140e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20J=C3=B8lsgard?= Date: Wed, 22 Oct 2025 09:36:49 +0200 Subject: [PATCH 03/12] lib: bluetooth: ble_conn_params: change error codes to nrf_error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change error codes to nrf_errors. Signed-off-by: Eivind Jølsgard --- .../release_notes/release_notes_changelog.rst | 3 +- include/bm/bluetooth/ble_conn_params.h | 58 ++++++++++--------- lib/bluetooth/ble_conn_params/att_mtu.c | 37 ++++++------ lib/bluetooth/ble_conn_params/conn_param.c | 34 ++++++----- lib/bluetooth/ble_conn_params/data_length.c | 31 +++++----- lib/bluetooth/ble_conn_params/event.c | 8 +-- lib/bluetooth/ble_conn_params/phy_mode.c | 26 ++++----- samples/bluetooth/ble_cgms/src/main.c | 6 +- samples/bluetooth/ble_hrs/src/main.c | 6 +- samples/bluetooth/ble_nus/src/main.c | 6 +- .../bluetooth/ble_pwr_profiling/src/main.c | 6 +- subsys/bluetooth/services/ble_mcumgr/mcumgr.c | 6 +- 12 files changed, 118 insertions(+), 109 deletions(-) diff --git a/doc/nrf-bm/release_notes/release_notes_changelog.rst b/doc/nrf-bm/release_notes/release_notes_changelog.rst index b7e3620bbe..6c3e88ce0a 100644 --- a/doc/nrf-bm/release_notes/release_notes_changelog.rst +++ b/doc/nrf-bm/release_notes/release_notes_changelog.rst @@ -78,7 +78,8 @@ Libraries * Updated the following libraries to return ``nrf_errors`` instead of ``errnos``: - * :ref:`lib_ble_adv`. + * :ref:`lib_ble_adv` library. + * :ref:`lib_ble_conn_params` library. * :ref:`lib_ble_conn_params` library: diff --git a/include/bm/bluetooth/ble_conn_params.h b/include/bm/bluetooth/ble_conn_params.h index c91d3f9fc6..bb010a379f 100644 --- a/include/bm/bluetooth/ble_conn_params.h +++ b/include/bm/bluetooth/ble_conn_params.h @@ -114,10 +114,10 @@ typedef void (*ble_conn_params_evt_handler_t)(const struct ble_conn_params_evt * * * @param handler Handler. * - * @retval 0 On success. - * @retval -EFAULT If @p handler is @c NULL. + * @retval NRF_SUCCESS On success. + * @retval NRF_ERROR_NULL If @p handler is @c NULL. */ -int ble_conn_params_evt_handler_set(ble_conn_params_evt_handler_t handler); +uint32_t ble_conn_params_evt_handler_set(ble_conn_params_evt_handler_t handler); /** * @brief Override GAP connection parameters for given peer. @@ -129,11 +129,11 @@ int ble_conn_params_evt_handler_set(ble_conn_params_evt_handler_t handler); * @param conn_handle Connection handle. * @param conn_params Connection parameters. * - * @retval 0 Connection parameter update initiated successfully. - * @retval -EINVAL If @p conn_handle is invalid. - * @retval -EFAULT If @p conn_params is @c NULL. + * @retval NRF_SUCCESS Connection parameter update initiated successfully. + * @retval NRF_ERROR_INVALID_PARAM If @p conn_handle is invalid. + * @retval NRF_ERROR_NULL If @p conn_params is @c NULL. */ -int ble_conn_params_override(uint16_t conn_handle, const ble_gap_conn_params_t *conn_params); +uint32_t ble_conn_params_override(uint16_t conn_handle, const ble_gap_conn_params_t *conn_params); /** * @brief Initiate an ATT MTU exchange procedure for a given connection. @@ -152,10 +152,10 @@ int ble_conn_params_override(uint16_t conn_handle, const ble_gap_conn_params_t * * @param conn_handle Handle to the connection. * @param att_mtu Desired ATT MTU. * - * @retval 0 On success. - * @retval -EINVAL Invalid ATT MTU or connection handle. + * @retval NRF_SUCCESS On success. + * @retval NRF_ERROR_INVALID_PARAM Invalid ATT MTU or connection handle. */ -int ble_conn_params_att_mtu_set(uint16_t conn_handle, uint16_t att_mtu); +uint32_t ble_conn_params_att_mtu_set(uint16_t conn_handle, uint16_t att_mtu); /** * @brief Retrieve the current ATT MTU for a given connection. @@ -163,11 +163,11 @@ int ble_conn_params_att_mtu_set(uint16_t conn_handle, uint16_t att_mtu); * @param conn_handle Handle to the connection. * @param[out] att_mtu The ATT MTU value. * - * @retval 0 On success. - * @retval -EINVAL Invalid connection handle. - * @retval -EFAULT @p att_mtu is @c NULL. + * @retval NRF_SUCCESS On success. + * @retval NRF_ERROR_INVALID_PARAM Invalid connection handle. + * @retval NRF_ERROR_NULL @p att_mtu is @c NULL. */ -int ble_conn_params_att_mtu_get(uint16_t conn_handle, uint16_t *att_mtu); +uint32_t ble_conn_params_att_mtu_get(uint16_t conn_handle, uint16_t *att_mtu); /** * @brief Initiate a GAP data length update procedure for a given connection. @@ -178,10 +178,11 @@ int ble_conn_params_att_mtu_get(uint16_t conn_handle, uint16_t *att_mtu); * @param conn_handle Handle to the connection. * @param data_length Desired GAP data length. * - * @retval 0 On success. - * @retval -EINVAL Invalid data length or connection handle. + * @retval NRF_SUCCESS On success. + * @retval NRF_ERROR_INVALID_PARAM Invalid data length or connection handle. */ -int ble_conn_params_data_length_set(uint16_t conn_handle, struct ble_conn_params_data_length dl); +uint32_t ble_conn_params_data_length_set(uint16_t conn_handle, + struct ble_conn_params_data_length dl); /** * @brief Retrieve the current GAP data length for a given connection. @@ -189,11 +190,12 @@ int ble_conn_params_data_length_set(uint16_t conn_handle, struct ble_conn_params * @param conn_handle Handle to the connection. * @param[out] data_length The data length value. * - * @retval 0 On success. - * @retval -EINVAL Invalid connection handle. - * @retval -EFAULT @p data_length is @c NULL. + * @retval NRF_SUCCESS On success. + * @retval NRF_ERROR_INVALID_PARAM Invalid connection handle. + * @retval NRF_ERROR_NULL @p data_length is @c NULL. */ -int ble_conn_params_data_length_get(uint16_t conn_handle, struct ble_conn_params_data_length *dl); +uint32_t ble_conn_params_data_length_get(uint16_t conn_handle, + struct ble_conn_params_data_length *dl); /** * @brief Initiate a GAP radio PHY mode update procedure for a given connection. @@ -204,10 +206,10 @@ int ble_conn_params_data_length_get(uint16_t conn_handle, struct ble_conn_params * @param conn_handle Handle to the connection. * @param phy_pref Desired GAP radio PHY mode. * - * @retval 0 On success. - * @retval -EINVAL Invalid data length or connection handle. + * @retval NRF_SUCCESS On success. + * @retval NRF_ERROR_INVALID_PARAM Invalid data length or connection handle. */ -int ble_conn_params_phy_radio_mode_set(uint16_t conn_handle, ble_gap_phys_t phy_pref); +uint32_t ble_conn_params_phy_radio_mode_set(uint16_t conn_handle, ble_gap_phys_t phy_pref); /** * @brief Retrieve the current GAP radio PHY mode for a given connection. @@ -215,11 +217,11 @@ int ble_conn_params_phy_radio_mode_set(uint16_t conn_handle, ble_gap_phys_t phy_ * @param conn_handle Handle to the connection. * @param[out] phy_pref The radio PHY mode. * - * @retval 0 On success. - * @retval -EINVAL Invalid connection handle. - * @retval -EFAULT @p phy_pref is @c NULL. + * @retval NRF_SUCCESS On success. + * @retval NRF_ERROR_INVALID_PARAM Invalid connection handle. + * @retval NRF_ERROR_NULL @p phy_pref is @c NULL. */ -int ble_conn_params_phy_radio_mode_get(uint16_t conn_handle, ble_gap_phys_t *phy_pref); +uint32_t ble_conn_params_phy_radio_mode_get(uint16_t conn_handle, ble_gap_phys_t *phy_pref); #ifdef __cplusplus } diff --git a/lib/bluetooth/ble_conn_params/att_mtu.c b/lib/bluetooth/ble_conn_params/att_mtu.c index 6f72c020fa..be20348712 100644 --- a/lib/bluetooth/ble_conn_params/att_mtu.c +++ b/lib/bluetooth/ble_conn_params/att_mtu.c @@ -3,6 +3,7 @@ * * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ +#include #include #include #include @@ -27,26 +28,26 @@ static struct { static void mtu_exchange_request(uint16_t conn_handle, int idx) { - int err; + uint32_t nrf_err; - err = sd_ble_gattc_exchange_mtu_request(conn_handle, links[idx].att_mtu_desired); - if (!err) { + nrf_err = sd_ble_gattc_exchange_mtu_request(conn_handle, links[idx].att_mtu_desired); + if (nrf_err == NRF_SUCCESS) { return; } - if (err == NRF_ERROR_BUSY) { + if (nrf_err == NRF_ERROR_BUSY) { /* Retry */ LOG_DBG("Another procedure is ongoing, will retry"); links[idx].att_mtu_exchange_pending = true; - } else if (err) { - LOG_ERR("Failed to initiate ATT MTU exchange, nrf_error %#x", err); + } else if (nrf_err) { + LOG_ERR("Failed to initiate ATT MTU exchange, nrf_error %#x", nrf_err); } } static void on_exchange_mtu_req_evt(uint16_t conn_handle, int idx, const ble_gatts_evt_exchange_mtu_request_t *evt) { - int err; + uint32_t nrf_err; /* Determine the lowest ATT MTU between our own desired ATT MTU and the peer's, * and at the same time ensure that we don't go lower than the actual MTU size. @@ -57,9 +58,9 @@ static void on_exchange_mtu_req_evt(uint16_t conn_handle, int idx, LOG_INF("Peer %#x requested ATT MTU of %u bytes", conn_handle, evt->client_rx_mtu); - err = sd_ble_gatts_exchange_mtu_reply(conn_handle, links[idx].att_mtu); - if (err) { - LOG_ERR("Failed to reply to MTU exchange request, nrf_error %#x", err); + nrf_err = sd_ble_gatts_exchange_mtu_reply(conn_handle, links[idx].att_mtu); + if (nrf_err) { + LOG_ERR("Failed to reply to MTU exchange request, nrf_error %#x", nrf_err); return; } @@ -161,37 +162,37 @@ static void on_ble_evt(const ble_evt_t *evt, void *ctx) } NRF_SDH_BLE_OBSERVER(ble_observer, on_ble_evt, NULL, 0); -int ble_conn_params_att_mtu_set(uint16_t conn_handle, uint16_t att_mtu) +uint32_t ble_conn_params_att_mtu_set(uint16_t conn_handle, uint16_t att_mtu) { const int idx = nrf_sdh_ble_idx_get(conn_handle); if (idx < 0) { - return -EINVAL; + return NRF_ERROR_INVALID_PARAM; } if (att_mtu < BLE_GATT_ATT_MTU_DEFAULT || CONFIG_BLE_CONN_PARAMS_ATT_MTU < att_mtu) { - return -EINVAL; + return NRF_ERROR_INVALID_PARAM; } links[idx].att_mtu_desired = att_mtu; mtu_exchange_request(conn_handle, idx); - return 0; + return NRF_SUCCESS; } -int ble_conn_params_att_mtu_get(uint16_t conn_handle, uint16_t *att_mtu) +uint32_t ble_conn_params_att_mtu_get(uint16_t conn_handle, uint16_t *att_mtu) { const int idx = nrf_sdh_ble_idx_get(conn_handle); if (idx < 0) { - return -EINVAL; + return NRF_ERROR_INVALID_PARAM; } if (!att_mtu) { - return -EFAULT; + return NRF_ERROR_NULL; } *att_mtu = links[idx].att_mtu; - return 0; + return NRF_SUCCESS; } diff --git a/lib/bluetooth/ble_conn_params/conn_param.c b/lib/bluetooth/ble_conn_params/conn_param.c index 5094e299f0..2e614eefda 100644 --- a/lib/bluetooth/ble_conn_params/conn_param.c +++ b/lib/bluetooth/ble_conn_params/conn_param.c @@ -3,6 +3,7 @@ * * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ +#include #include #include #include @@ -32,13 +33,14 @@ static struct { static void conn_params_negotiate(uint16_t conn_handle, int idx) { - int err; + uint32_t nrf_err; LOG_DBG("Negotiating desired parameters with peer %#x", conn_handle); - err = sd_ble_gap_conn_param_update(conn_handle, &links[idx].ppcp); - if (err) { - LOG_ERR("Failed to request GAP connection parameters update, nrf_error %#x", err); + nrf_err = sd_ble_gap_conn_param_update(conn_handle, &links[idx].ppcp); + if (nrf_err) { + LOG_ERR("Failed to request GAP connection parameters update, nrf_error %#x", + nrf_err); } } @@ -171,15 +173,15 @@ NRF_SDH_BLE_OBSERVER(ble_observer, on_ble_evt, NULL, 0); static void on_state_evt(enum nrf_sdh_state_evt evt, void *ctx) { - int err; + uint32_t nrf_err; if (evt != NRF_SDH_STATE_EVT_BLE_ENABLED) { return; } - err = sd_ble_gap_ppcp_set(&ppcp); - if (err) { - LOG_ERR("Failed to set preferred conn params, nrf_error %#x", err); + nrf_err = sd_ble_gap_ppcp_set(&ppcp); + if (nrf_err) { + LOG_ERR("Failed to set preferred conn params, nrf_error %#x", nrf_err); return; } @@ -190,23 +192,23 @@ static void on_state_evt(enum nrf_sdh_state_evt evt, void *ctx) } NRF_SDH_STATE_EVT_OBSERVER(ble_conn_params_sdh_state_observer, on_state_evt, NULL, 0); -int ble_conn_params_override(uint16_t conn_handle, const ble_gap_conn_params_t *conn_params) +uint32_t ble_conn_params_override(uint16_t conn_handle, const ble_gap_conn_params_t *conn_params) { - int err; + uint32_t nrf_err; const int idx = nrf_sdh_ble_idx_get(conn_handle); if (idx < 0) { - return -EINVAL; + return BLE_ERROR_INVALID_CONN_HANDLE; } if (!conn_params) { - return -EFAULT; + return NRF_ERROR_NULL; } links[idx].ppcp = *conn_params; - err = sd_ble_gap_conn_param_update(conn_handle, conn_params); - if (err) { - return -EINVAL; + nrf_err = sd_ble_gap_conn_param_update(conn_handle, conn_params); + if (nrf_err) { + return nrf_err; } - return 0; + return NRF_SUCCESS; } diff --git a/lib/bluetooth/ble_conn_params/data_length.c b/lib/bluetooth/ble_conn_params/data_length.c index cb28618f81..f91e896176 100644 --- a/lib/bluetooth/ble_conn_params/data_length.c +++ b/lib/bluetooth/ble_conn_params/data_length.c @@ -3,6 +3,7 @@ * * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ +#include #include #include #include @@ -30,7 +31,7 @@ static struct { static void data_length_update(uint16_t conn_handle, int idx) { - int err; + uint32_t nrf_err; bool retry; ble_gap_data_length_params_t dlp = { .max_tx_octets = links[idx].desired.tx, @@ -43,13 +44,13 @@ static void data_length_update(uint16_t conn_handle, int idx) do { retry = false; - err = sd_ble_gap_data_length_update(conn_handle, &dlp, &dll); - if (err == NRF_ERROR_BUSY) { + nrf_err = sd_ble_gap_data_length_update(conn_handle, &dlp, &dll); + if (nrf_err == NRF_ERROR_BUSY) { /* Retry later. */ LOG_DBG("Another procedure is ongoing, will retry"); links[idx].data_length_update_pending = true; return; - } else if (err == NRF_ERROR_RESOURCES) { + } else if (nrf_err == NRF_ERROR_RESOURCES) { if ((dll.tx_payload_limited_octets != 0) || (dll.rx_payload_limited_octets != 0)) { LOG_WRN("The requested TX and RX packet lengths are too long by " @@ -72,9 +73,9 @@ static void data_length_update(uint16_t conn_handle, int idx) "is too long by %u microseconds.", dll.tx_rx_time_limited_us); } - } else if (err) { + } else if (nrf_err) { LOG_ERR("Failed to initiate or respond to Data Length Update procedure, " - "nrf_error %#x", err); + "nrf_error %#x", nrf_err); } } while (retry); } @@ -187,40 +188,42 @@ static void on_ble_evt(const ble_evt_t *evt, void *ctx) } NRF_SDH_BLE_OBSERVER(ble_observer, on_ble_evt, NULL, 0); -int ble_conn_params_data_length_set(uint16_t conn_handle, struct ble_conn_params_data_length dl) +uint32_t ble_conn_params_data_length_set(uint16_t conn_handle, + struct ble_conn_params_data_length dl) { const int idx = nrf_sdh_ble_idx_get(conn_handle); if (idx < 0) { - return -EINVAL; + return NRF_ERROR_INVALID_PARAM; } if (dl.tx < BLE_GAP_DATA_LENGTH_DEFAULT || dl.tx > CONFIG_BLE_CONN_PARAMS_DATA_LENGTH_TX || dl.rx < BLE_GAP_DATA_LENGTH_DEFAULT || dl.rx > CONFIG_BLE_CONN_PARAMS_DATA_LENGTH_RX) { - return -EINVAL; + return NRF_ERROR_INVALID_PARAM; } links[idx].desired.tx = dl.tx; links[idx].desired.rx = dl.rx; data_length_update(conn_handle, idx); - return 0; + return NRF_SUCCESS; } -int ble_conn_params_data_length_get(uint16_t conn_handle, struct ble_conn_params_data_length *dl) +uint32_t ble_conn_params_data_length_get(uint16_t conn_handle, + struct ble_conn_params_data_length *dl) { const int idx = nrf_sdh_ble_idx_get(conn_handle); if (idx < 0) { - return -EINVAL; + return NRF_ERROR_INVALID_PARAM; } if (!dl) { - return -EFAULT; + return NRF_ERROR_NULL; } dl->tx = links[idx].data_length.tx; dl->rx = links[idx].data_length.rx; - return 0; + return NRF_SUCCESS; } diff --git a/lib/bluetooth/ble_conn_params/event.c b/lib/bluetooth/ble_conn_params/event.c index d4e9fc78d8..47d6f61904 100644 --- a/lib/bluetooth/ble_conn_params/event.c +++ b/lib/bluetooth/ble_conn_params/event.c @@ -20,13 +20,13 @@ void ble_conn_params_event_send(const struct ble_conn_params_evt *evt) } } -int ble_conn_params_evt_handler_set(ble_conn_params_evt_handler_t handler) +uint32_t ble_conn_params_evt_handler_set(ble_conn_params_evt_handler_t handler) { - if (handler == NULL) { - return -EFAULT; + if (!handler) { + return NRF_ERROR_NULL; } evt_handler = handler; - return 0; + return NRF_SUCCESS; } diff --git a/lib/bluetooth/ble_conn_params/phy_mode.c b/lib/bluetooth/ble_conn_params/phy_mode.c index 0b305be86e..8a1e6c3b39 100644 --- a/lib/bluetooth/ble_conn_params/phy_mode.c +++ b/lib/bluetooth/ble_conn_params/phy_mode.c @@ -28,7 +28,7 @@ BUILD_ASSERT(CONFIG_BLE_CONN_PARAMS_PHY == BLE_GAP_PHY_AUTO || static void radio_phy_mode_update(uint16_t conn_handle, int idx) { - int err; + uint32_t nrf_err; ble_gap_phys_t phys = links[idx].phy_mode; @@ -40,15 +40,15 @@ static void radio_phy_mode_update(uint16_t conn_handle, int idx) phys.rx_phys &= BLE_GAP_PHYS_SUPPORTED; } - err = sd_ble_gap_phy_update(conn_handle, &phys); - if (!err) { + nrf_err = sd_ble_gap_phy_update(conn_handle, &phys); + if (nrf_err == NRF_SUCCESS) { return; - } else if (err == NRF_ERROR_BUSY) { + } else if (nrf_err == NRF_ERROR_BUSY) { /* Retry */ links[idx].phy_mode_update_pending = true; LOG_DBG("Failed PHY update procedure, another procedure is ongoing, " "Will retry"); - } else if (err == NRF_ERROR_RESOURCES) { + } else if (nrf_err == NRF_ERROR_RESOURCES) { /* PHY update failed. Use current PHY. */ LOG_WRN("Failed PHY update procedure. Continue using current PHY mode"); LOG_DBG("GAP event length (%d) may be too small", @@ -57,7 +57,7 @@ static void radio_phy_mode_update(uint16_t conn_handle, int idx) links[idx].phy_mode.rx_phys = CONFIG_BLE_CONN_PARAMS_PHY; radio_phy_mode_update(conn_handle, idx); } else { - LOG_ERR("Failed PHY update procedure, nrf_error %#x", err); + LOG_ERR("Failed PHY update procedure, nrf_error %#x", nrf_err); } } @@ -158,33 +158,33 @@ static void on_ble_evt(const ble_evt_t *evt, void *ctx) } NRF_SDH_BLE_OBSERVER(ble_observer, on_ble_evt, NULL, 0); -int ble_conn_params_phy_radio_mode_set(uint16_t conn_handle, ble_gap_phys_t phy_pref) +uint32_t ble_conn_params_phy_radio_mode_set(uint16_t conn_handle, ble_gap_phys_t phy_pref) { const int idx = nrf_sdh_ble_idx_get(conn_handle); if (idx < 0) { - return -EINVAL; + return NRF_ERROR_INVALID_PARAM; } links[idx].phy_mode = phy_pref; radio_phy_mode_update(conn_handle, idx); - return 0; + return NRF_SUCCESS; } -int ble_conn_params_phy_radio_mode_get(uint16_t conn_handle, ble_gap_phys_t *phy_pref) +uint32_t ble_conn_params_phy_radio_mode_get(uint16_t conn_handle, ble_gap_phys_t *phy_pref) { const int idx = nrf_sdh_ble_idx_get(conn_handle); if (idx < 0) { - return -EINVAL; + return NRF_ERROR_INVALID_PARAM; } if (!phy_pref) { - return -EFAULT; + return NRF_ERROR_NULL; } *phy_pref = links[idx].phy_mode; - return 0; + return NRF_SUCCESS; } diff --git a/samples/bluetooth/ble_cgms/src/main.c b/samples/bluetooth/ble_cgms/src/main.c index 66f0824431..61cec2f29e 100644 --- a/samples/bluetooth/ble_cgms/src/main.c +++ b/samples/bluetooth/ble_cgms/src/main.c @@ -742,9 +742,9 @@ int main(void) } (void)sensor_simulator_init(); - err = ble_conn_params_evt_handler_set(on_conn_params_evt); - if (err) { - LOG_ERR("Failed to setup conn param event handler, err %d", err); + nrf_err = ble_conn_params_evt_handler_set(on_conn_params_evt); + if (nrf_err) { + LOG_ERR("Failed to setup conn param event handler, nrf_error %#x", nrf_err); goto idle; } diff --git a/samples/bluetooth/ble_hrs/src/main.c b/samples/bluetooth/ble_hrs/src/main.c index 1898bb1c56..44de55b787 100644 --- a/samples/bluetooth/ble_hrs/src/main.c +++ b/samples/bluetooth/ble_hrs/src/main.c @@ -523,9 +523,9 @@ int main(void) LOG_INF("Services initialized"); - err = ble_conn_params_evt_handler_set(on_conn_params_evt); - if (err) { - LOG_ERR("Failed to setup conn param event handler, err %d", err); + nrf_err = ble_conn_params_evt_handler_set(on_conn_params_evt); + if (nrf_err) { + LOG_ERR("Failed to setup conn param event handler, nrf_error %#x", nrf_err); goto idle; } diff --git a/samples/bluetooth/ble_nus/src/main.c b/samples/bluetooth/ble_nus/src/main.c index c0cfaca7f5..64f19afc10 100644 --- a/samples/bluetooth/ble_nus/src/main.c +++ b/samples/bluetooth/ble_nus/src/main.c @@ -505,9 +505,9 @@ int main(void) LOG_INF("Services initialized"); - err = ble_conn_params_evt_handler_set(on_conn_params_evt); - if (err) { - LOG_ERR("Failed to setup conn param event handler, err %d", err); + nrf_err = ble_conn_params_evt_handler_set(on_conn_params_evt); + if (nrf_err) { + LOG_ERR("Failed to setup conn param event handler, nrf_error %#x", nrf_err); goto idle; } diff --git a/samples/bluetooth/ble_pwr_profiling/src/main.c b/samples/bluetooth/ble_pwr_profiling/src/main.c index d326fb8d03..61c29a8958 100644 --- a/samples/bluetooth/ble_pwr_profiling/src/main.c +++ b/samples/bluetooth/ble_pwr_profiling/src/main.c @@ -631,9 +631,9 @@ int main(void) nrf_gpio_pin_write(BOARD_PIN_LED_0, BOARD_LED_ACTIVE_STATE); #endif - err = ble_conn_params_evt_handler_set(on_conn_params_evt); - if (err) { - LOG_ERR("Failed to setup conn param event handler, err %d", err); + nrf_err = ble_conn_params_evt_handler_set(on_conn_params_evt); + if (nrf_err) { + LOG_ERR("Failed to setup conn param event handler, nrf_error %#x", nrf_err); goto idle; } diff --git a/subsys/bluetooth/services/ble_mcumgr/mcumgr.c b/subsys/bluetooth/services/ble_mcumgr/mcumgr.c index 31f313ac86..9e8f926ca4 100644 --- a/subsys/bluetooth/services/ble_mcumgr/mcumgr.c +++ b/subsys/bluetooth/services/ble_mcumgr/mcumgr.c @@ -291,6 +291,7 @@ int ble_mcumgr_data_send(uint8_t *data, uint16_t *len, struct ble_mcumgr_client_ static int smp_ncs_bm_bt_tx_pkt(struct net_buf *nb) { int rc; + uint32_t nrf_err; struct ble_mcumgr_client_context *ctx; uint16_t notification_size; uint8_t *send_pos = nb->data; @@ -301,9 +302,8 @@ static int smp_ncs_bm_bt_tx_pkt(struct net_buf *nb) } ctx = &contexts[0]; - rc = ble_conn_params_att_mtu_get(conn_handle, ¬ification_size); - - if (rc) { + nrf_err = ble_conn_params_att_mtu_get(conn_handle, ¬ification_size); + if (nrf_err) { goto finish; } From 2e741fa92dde83b6d1b775e615526f17e4699f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20J=C3=B8lsgard?= Date: Wed, 22 Oct 2025 09:49:29 +0200 Subject: [PATCH 04/12] lib: bluetooth: ble_gq: change error codes to nrf_error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change error codes to nrf_errors. Signed-off-by: Eivind Jølsgard --- .../release_notes/release_notes_changelog.rst | 1 + include/bm/bluetooth/ble_gq.h | 20 +++--- lib/bluetooth/ble_gq/gatt_queue.c | 71 ++++++++++--------- .../bluetooth/services/ble_cgms/cgms_socp.c | 10 +-- 4 files changed, 53 insertions(+), 49 deletions(-) diff --git a/doc/nrf-bm/release_notes/release_notes_changelog.rst b/doc/nrf-bm/release_notes/release_notes_changelog.rst index 6c3e88ce0a..4e07d856eb 100644 --- a/doc/nrf-bm/release_notes/release_notes_changelog.rst +++ b/doc/nrf-bm/release_notes/release_notes_changelog.rst @@ -80,6 +80,7 @@ Libraries * :ref:`lib_ble_adv` library. * :ref:`lib_ble_conn_params` library. + * :ref:`lib_ble_gatt_queue` library. * :ref:`lib_ble_conn_params` library: diff --git a/include/bm/bluetooth/ble_gq.h b/include/bm/bluetooth/ble_gq.h index cf8b908fea..cb1828c17c 100644 --- a/include/bm/bluetooth/ble_gq.h +++ b/include/bm/bluetooth/ble_gq.h @@ -254,12 +254,14 @@ struct ble_gq { * @param[in] req Pointer to the request. * @param[in] conn_handle Connection handle associated with the request. * - * @retval 0 Request was added successfully. - * @retval -EFAULT Any parameter was NULL. - * @retval -EINVAL If @p conn_handle is not registered or type of request @p req is not valid. - * @retval -ENOMEM There was no room in the queue or in the data pool. + * @retval NRF_SUCCESS Request was added successfully. + * @retval NRF_ERROR_NULL Any parameter was NULL. + * @retval NRF_ERROR_INVALID_PARAM If @p conn_handle is not registered or type of request + * @p req is not valid. + * @retval NRF_ERROR_NO_MEM There was no room in the queue or in the data pool. */ -int ble_gq_item_add(const struct ble_gq *gatt_queue, struct ble_gq_req *req, uint16_t conn_handle); +uint32_t ble_gq_item_add(const struct ble_gq *gatt_queue, struct ble_gq_req *req, + uint16_t conn_handle); /** * @brief Register connection handle in the GATT queue instance. @@ -271,11 +273,11 @@ int ble_gq_item_add(const struct ble_gq *gatt_queue, struct ble_gq_req *req, uin * @param[in] gatt_queue Pointer to the @ref ble_gq instance. * @param[in] conn_handle Connection handle. * - * @retval 0 Connection handle was successful registered. - * @retval -EFAULT If @p gatt_queue was NULL. - * @retval -ENOMEM No space for another connection handle. + * @retval NRF_SUCCESS Connection handle was successful registered. + * @retval NRF_ERROR_NULL If @p gatt_queue was NULL. + * @retval NRF_ERROR_NO_MEM No space for another connection handle. */ -int ble_gq_conn_handle_register(const struct ble_gq *gatt_queue, uint16_t conn_handle); +uint32_t ble_gq_conn_handle_register(const struct ble_gq *gatt_queue, uint16_t conn_handle); /** * @brief Handle BLE events from the SoftDevice. diff --git a/lib/bluetooth/ble_gq/gatt_queue.c b/lib/bluetooth/ble_gq/gatt_queue.c index 95d0e62b3c..f33658b31e 100644 --- a/lib/bluetooth/ble_gq/gatt_queue.c +++ b/lib/bluetooth/ble_gq/gatt_queue.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ -#include +#include #include #include #include @@ -28,15 +28,15 @@ LOG_MODULE_REGISTER(ble_gatt_queue, CONFIG_BLE_GQ_LOG_LEVEL); * req_buf Request storage buffer. * * Should return: - * 0 if successful. - * -ENOMEM if there are no room in the data pool for a new allocation. + * NRF_SUCCESS if successful. + * NRF_ERROR_NO_MEM if there are no room in the data pool for a new allocation. */ -typedef int (*req_data_store_t)(struct k_heap *data_pool, const struct ble_gq_req *req, - struct ble_gq_req *req_buf); +typedef uint32_t (*req_data_store_t)(struct k_heap *data_pool, const struct ble_gq_req *req, + struct ble_gq_req *req_buf); /* Prepare a GATTC write request for storage. */ -static int gattc_write_store(struct k_heap *data_pool, const struct ble_gq_req *req, - struct ble_gq_req *req_buf) +static uint32_t gattc_write_store(struct k_heap *data_pool, const struct ble_gq_req *req, + struct ble_gq_req *req_buf) { const ble_gattc_write_params_t *const gattc_write = &req->gattc_write; uint8_t *data; @@ -44,7 +44,7 @@ static int gattc_write_store(struct k_heap *data_pool, const struct ble_gq_req * /* Allocate additional memory for GATTC write request data. */ data = k_heap_aligned_alloc(data_pool, sizeof(void *), gattc_write->len, K_NO_WAIT); if (data == NULL) { - return -ENOMEM; + return NRF_ERROR_NO_MEM; } LOG_DBG("Allocated heap memory with addr: %#lx", (uintptr_t)data); @@ -59,12 +59,12 @@ static int gattc_write_store(struct k_heap *data_pool, const struct ble_gq_req * req_buf->data = data; req_buf->gattc_write.p_value = data; - return 0; + return NRF_SUCCESS; } /* Prepare a GATTS notification or indication request for storage. */ -static int gatts_hvx_store(struct k_heap *data_pool, const struct ble_gq_req *req, - struct ble_gq_req *req_buf) +static uint32_t gatts_hvx_store(struct k_heap *data_pool, const struct ble_gq_req *req, + struct ble_gq_req *req_buf) { const ble_gatts_hvx_params_t *const gatts_hvx = &req->gatts_hvx; uint8_t *data; @@ -73,7 +73,7 @@ static int gatts_hvx_store(struct k_heap *data_pool, const struct ble_gq_req *re data = k_heap_aligned_alloc(data_pool, sizeof(void *), *gatts_hvx->p_len + sizeof(uint16_t), K_NO_WAIT); if (data == NULL) { - return -ENOMEM; + return NRF_ERROR_NO_MEM; } LOG_DBG("Allocated heap memory with addr: %#lx", (uintptr_t)data); @@ -90,7 +90,7 @@ static int gatts_hvx_store(struct k_heap *data_pool, const struct ble_gq_req *re req_buf->gatts_hvx.p_len = (uint16_t *)&data[0]; req_buf->gatts_hvx.p_data = &data[sizeof(uint16_t)]; - return 0; + return NRF_SUCCESS; } /* Array of memory store functions for different GATT request types. */ @@ -151,9 +151,9 @@ static bool request_process(const struct ble_gq_req *req, uint16_t conn_handle) break; case BLE_GQ_REQ_GATTS_HVX: LOG_DBG("GATTS notification or indication"); - if (!req->gatts_hvx.p_len) { + if (req->gatts_hvx.p_len == NULL) { LOG_DBG("GATTS HVX request p_len is NULL"); - nrf_err = NRF_ERROR_INVALID_PARAM; + nrf_err = NRF_ERROR_INVALID_PARAM; break; } len = *(req->gatts_hvx.p_len); @@ -298,13 +298,13 @@ static uint16_t conn_handle_id_find(const struct ble_gq *gq, uint16_t conn_handl } /* Register the provided connection handle within the GATT queue instance registery. */ -static int conn_handle_register(const struct ble_gq *gq, uint16_t conn_handle) +static uint32_t conn_handle_register(const struct ble_gq *gq, uint16_t conn_handle) { uint16_t unused_id = gq->max_conns; for (uint16_t id = 0; id < gq->max_conns; id++) { if (gq->conn_handles[id] == conn_handle) { - return 0; + return NRF_SUCCESS; } if (gq->conn_handles[id] == BLE_CONN_HANDLE_INVALID && unused_id == gq->max_conns) { unused_id = id; @@ -312,21 +312,22 @@ static int conn_handle_register(const struct ble_gq *gq, uint16_t conn_handle) } if (unused_id == gq->max_conns) { - return -ENOMEM; + return NRF_ERROR_NO_MEM; } gq->conn_handles[unused_id] = conn_handle; - return 0; + return NRF_SUCCESS; } -int ble_gq_item_add(const struct ble_gq *gq, struct ble_gq_req *req, uint16_t conn_handle) +uint32_t ble_gq_item_add(const struct ble_gq *gq, struct ble_gq_req *req, uint16_t conn_handle) { int err; + uint32_t nrf_err; uint16_t conn_id; struct ble_gq_req *buffered_req; if (gq == NULL || req == NULL) { - return -EFAULT; + return NRF_ERROR_NULL; } /* Purge queues that are no longer used by any connection. */ @@ -335,7 +336,7 @@ int ble_gq_item_add(const struct ble_gq *gq, struct ble_gq_req *req, uint16_t co /* Check if connection handle is registered and if GATT request is valid. */ conn_id = conn_handle_id_find(gq, conn_handle); if (req->type >= BLE_GQ_REQ_NUM || conn_id >= gq->max_conns) { - return -EINVAL; + return NRF_ERROR_INVALID_PARAM; } /* Try processing a request without buffering. */ @@ -343,7 +344,7 @@ int ble_gq_item_add(const struct ble_gq *gq, struct ble_gq_req *req, uint16_t co const bool req_processed = request_process(req, conn_handle); if (req_processed) { - return 0; + return NRF_SUCCESS; } } @@ -353,16 +354,16 @@ int ble_gq_item_add(const struct ble_gq *gq, struct ble_gq_req *req, uint16_t co __ASSERT_NO_MSG(gq->req_blocks != NULL); err = k_mem_slab_alloc(gq->req_blocks, (void **)&buffered_req, K_NO_WAIT); if (err) { - return err; + return NRF_ERROR_NO_MEM; } /* Allocate extra memory if required by the request type. */ if (req_data_store[req->type] != NULL) { __ASSERT_NO_MSG(gq->data_pool != NULL); - err = req_data_store[req->type](gq->data_pool, req, buffered_req); - if (err) { + nrf_err = req_data_store[req->type](gq->data_pool, req, buffered_req); + if (nrf_err) { k_mem_slab_free(gq->req_blocks, buffered_req); - return err; + return nrf_err; } } else { /* Copy request. No extra memory needed. */ @@ -374,29 +375,29 @@ int ble_gq_item_add(const struct ble_gq *gq, struct ble_gq_req *req, uint16_t co /* Check if SoftDevice is still busy. */ queue_process(gq, conn_handle, conn_id); - return 0; + return NRF_SUCCESS; } -int ble_gq_conn_handle_register(const struct ble_gq *gq, uint16_t conn_handle) +uint32_t ble_gq_conn_handle_register(const struct ble_gq *gq, uint16_t conn_handle) { - int err; + uint32_t nrf_err; if (gq == NULL) { - return -EFAULT; + return NRF_ERROR_NULL; } /* Purge the queues that are no longer used by any connection. */ req_queues_purge(gq); /* Find a free spot in the connection handle registery and register the connection. */ - err = conn_handle_register(gq, conn_handle); - if (err) { + nrf_err = conn_handle_register(gq, conn_handle); + if (nrf_err) { LOG_DBG("Failed to register connection handle 0x%04x", conn_handle); - return err; + return nrf_err; } LOG_DBG("Registered connection handle 0x%04x", conn_handle); - return 0; + return NRF_SUCCESS; } void ble_gq_on_ble_evt(const ble_evt_t *ble_evt, void *gatt_queue) diff --git a/subsys/bluetooth/services/ble_cgms/cgms_socp.c b/subsys/bluetooth/services/ble_cgms/cgms_socp.c index 90fe5295f7..c6747bd173 100644 --- a/subsys/bluetooth/services/ble_cgms/cgms_socp.c +++ b/subsys/bluetooth/services/ble_cgms/cgms_socp.c @@ -344,7 +344,7 @@ uint32_t cgms_socp_char_add(struct ble_cgms *cgms) /* Send a Specific Ops Control Point response. */ static void socp_send(struct ble_cgms *cgms) { - uint32_t err; + uint32_t nrf_err; uint8_t encoded_resp[BLE_CGMS_SOCP_LEN]; uint16_t len; struct ble_cgms_evt cgms_evt = { @@ -365,13 +365,13 @@ static void socp_send(struct ble_cgms *cgms) .gatts_hvx.p_len = &len, }; - err = ble_gq_item_add(cgms->gatt_queue, &cgms_req, cgms->conn_handle); + nrf_err = ble_gq_item_add(cgms->gatt_queue, &cgms_req, cgms->conn_handle); /* Report error to application. */ if ((cgms->evt_handler != NULL) && - (err != NRF_SUCCESS) && - (err != NRF_ERROR_INVALID_STATE)) { - cgms_evt.error.reason = err; + (nrf_err) && + (nrf_err != NRF_ERROR_INVALID_STATE)) { + cgms_evt.error.reason = nrf_err; cgms->evt_handler(cgms, &cgms_evt); } } From 2b78817f6aed7c682c7d51bc263ecd63c1f4565b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20J=C3=B8lsgard?= Date: Wed, 22 Oct 2025 10:30:41 +0200 Subject: [PATCH 05/12] lib: bluetooth: ble_qwr: change error codes to nrf_error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change error codes to nrf_errors. Signed-off-by: Eivind Jølsgard --- .../release_notes/release_notes_changelog.rst | 1 + include/bm/bluetooth/ble_qwr.h | 38 ++-- lib/bluetooth/ble_qwr/ble_qwr.c | 40 ++-- samples/bluetooth/ble_cgms/src/main.c | 16 +- .../bluetooth/ble_hids_keyboard/src/main.c | 6 +- samples/bluetooth/ble_hids_mouse/src/main.c | 14 +- samples/bluetooth/ble_nus/src/main.c | 13 +- .../bluetooth/ble_pwr_profiling/src/main.c | 7 +- tests/lib/bluetooth/ble_qwr/src/unity_test.c | 198 +++++++++--------- 9 files changed, 167 insertions(+), 166 deletions(-) diff --git a/doc/nrf-bm/release_notes/release_notes_changelog.rst b/doc/nrf-bm/release_notes/release_notes_changelog.rst index 4e07d856eb..a42a5b2342 100644 --- a/doc/nrf-bm/release_notes/release_notes_changelog.rst +++ b/doc/nrf-bm/release_notes/release_notes_changelog.rst @@ -81,6 +81,7 @@ Libraries * :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_conn_params` library: diff --git a/include/bm/bluetooth/ble_qwr.h b/include/bm/bluetooth/ble_qwr.h index 78067d9372..c63bc61f79 100644 --- a/include/bm/bluetooth/ble_qwr.h +++ b/include/bm/bluetooth/ble_qwr.h @@ -67,7 +67,7 @@ struct ble_qwr_evt { union { /** @ref BLE_QWR_EVT_ERROR event data. */ struct { - int reason; + uint32_t reason; } error; /** @ref BLE_QWR_EVT_EXECUTE_WRITE event data. */ struct { @@ -159,11 +159,11 @@ struct ble_qwr_config { * Queued Writes instance. * @param[in] qwr_init Initialization structure. * - * @retval 0 If the Queued Writes module was initialized successfully. - * @retval -EFAULT If @p qwr or @p qwr_init is @c NULL. - * @retval -EPERM If the given @p qwr instance has already been initialized. + * @retval NRF_SUCCESS If the Queued Writes module was initialized successfully. + * @retval NRF_ERROR_NULL If @p qwr or @p qwr_init is @c NULL. + * @retval NRF_ERROR_INVALID_STATE If the given @p qwr instance has already been initialized. */ -int ble_qwr_init(struct ble_qwr *qwr, struct ble_qwr_config const *qwr_config); +uint32_t ble_qwr_init(struct ble_qwr *qwr, struct ble_qwr_config const *qwr_config); /** * @brief Function for assigning a connection handle to an instance of the Queued Writes module. @@ -175,11 +175,11 @@ int ble_qwr_init(struct ble_qwr *qwr, struct ble_qwr_config const *qwr_config); * @param[in] qwr Queued Writes structure. * @param[in] conn_handle Connection handle to be associated with the given Queued Writes instance. * - * @retval 0 If the assignment was successful. - * @retval -EFAULT If @p qwr is @c NULL. - * @retval -EPERM If the given @p qwr instance has not been initialized. + * @retval NRF_SUCCESS If the assignment was successful. + * @retval NRF_ERROR_NULL If @p qwr is @c NULL. + * @retval NRF_ERROR_INVALID_STATE If the given @p qwr instance has not been initialized. */ -int ble_qwr_conn_handle_assign(struct ble_qwr *qwr, uint16_t conn_handle); +uint32_t ble_qwr_conn_handle_assign(struct ble_qwr *qwr, uint16_t conn_handle); /** * @brief Function for handling BLE stack events. @@ -201,12 +201,12 @@ void ble_qwr_on_ble_evt(ble_evt_t const *ble_evt, void *context); * @param[in] qwr Queued Writes structure. * @param[in] attr_handle Handle of the attribute to register. * - * @retval 0 If the registration was successful. - * @retval -ENOMEM If no more memory is available to add this registration. - * @retval -EFAULT If @p qwr is @c NULL. - * @retval -EPERM If the given @p qwr instance has not been initialized. + * @retval NRF_SUCCESS If the registration was successful. + * @retval NRF_ERROR_NO_MEM If no more memory is available to add this registration. + * @retval NRF_ERROR_NULL If @p qwr is @c NULL. + * @retval NRF_ERROR_INVALID_STATE If the given @p qwr instance has not been initialized. */ -int ble_qwr_attr_register(struct ble_qwr *qwr, uint16_t attr_handle); +uint32_t ble_qwr_attr_register(struct ble_qwr *qwr, uint16_t attr_handle); /** * @brief Function for retrieving the received data for a given attribute. @@ -219,12 +219,12 @@ int ble_qwr_attr_register(struct ble_qwr *qwr, uint16_t attr_handle); * @param[out] mem Pointer to the application buffer where the received data will be copied. * @param[in,out] len Input: length of the input buffer. Output: length of the received data. * - * @retval 0 If the data was retrieved and stored successfully. - * @retval -ENOMEM If the provided buffer was smaller than the received data. - * @retval -EFAULT If @p qwr, @p mem or @p len is @c NULL. - * @retval -EPERM If the given @p qwr instance has not been initialized. + * @retval NRF_SUCCESS If the data was retrieved and stored successfully. + * @retval NRF_ERROR_NO_MEM If the provided buffer was smaller than the received data. + * @retval NRF_ERROR_NULL If @p qwr, @p mem or @p len is @c NULL. + * @retval NRF_ERROR_INVALID_STATE If the given @p qwr instance has not been initialized. */ -int ble_qwr_value_get( +uint32_t ble_qwr_value_get( struct ble_qwr *qwr, uint16_t attr_handle, uint8_t *mem, uint16_t *len); #endif /* (CONFIG_BLE_QWR_MAX_ATTR > 0) */ diff --git a/lib/bluetooth/ble_qwr/ble_qwr.c b/lib/bluetooth/ble_qwr/ble_qwr.c index 9a188107ff..e374b05e00 100644 --- a/lib/bluetooth/ble_qwr/ble_qwr.c +++ b/lib/bluetooth/ble_qwr/ble_qwr.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ -#include +#include #include #include #include @@ -27,14 +27,14 @@ static inline uint16_t uint16_decode(const uint8_t *encoded_data) return sys_get_le16(encoded_data); } -int ble_qwr_init(struct ble_qwr *qwr, struct ble_qwr_config const *qwr_config) +uint32_t ble_qwr_init(struct ble_qwr *qwr, struct ble_qwr_config const *qwr_config) { if (!qwr || !qwr_config) { - return -EFAULT; + return NRF_ERROR_NULL; } if (qwr->initialized == BLE_QWR_INITIALIZED) { - return -EPERM; + return NRF_ERROR_INVALID_STATE; } qwr->initialized = BLE_QWR_INITIALIZED; @@ -47,37 +47,37 @@ int ble_qwr_init(struct ble_qwr *qwr, struct ble_qwr_config const *qwr_config) qwr->mem_buffer = qwr_config->mem_buffer; qwr->nb_written_handles = 0; #endif - return 0; + return NRF_SUCCESS; } #if (CONFIG_BLE_QWR_MAX_ATTR > 0) -int ble_qwr_attr_register(struct ble_qwr *qwr, uint16_t attr_handle) +uint32_t ble_qwr_attr_register(struct ble_qwr *qwr, uint16_t attr_handle) { if (!qwr) { - return -EFAULT; + return NRF_ERROR_NULL; } if (qwr->initialized != BLE_QWR_INITIALIZED) { - return -EPERM; + return NRF_ERROR_INVALID_STATE; } if ((qwr->nb_registered_attr == CONFIG_BLE_QWR_MAX_ATTR) || (qwr->mem_buffer.p_mem == NULL) || (qwr->mem_buffer.len == 0)) { - return -ENOMEM; + return NRF_ERROR_NO_MEM; } if (attr_handle == BLE_GATT_HANDLE_INVALID) { - return -EINVAL; + return NRF_ERROR_INVALID_PARAM; } qwr->attr_handles[qwr->nb_registered_attr] = attr_handle; qwr->nb_registered_attr++; - return 0; + return NRF_SUCCESS; } -int ble_qwr_value_get( +uint32_t ble_qwr_value_get( struct ble_qwr *qwr, uint16_t attr_handle, uint8_t *mem, uint16_t *len) { uint16_t i = 0; @@ -87,11 +87,11 @@ int ble_qwr_value_get( uint32_t cur_len = 0; if (!qwr || !mem || !len) { - return -EFAULT; + return NRF_ERROR_NULL; } if (qwr->initialized != BLE_QWR_INITIALIZED) { - return -EPERM; + return NRF_ERROR_INVALID_STATE; } do { @@ -111,7 +111,7 @@ int ble_qwr_value_get( if (cur_len <= *len) { memcpy((mem + val_offset), &(qwr->mem_buffer.p_mem[i]), val_len); } else { - return -ENOMEM; + return NRF_ERROR_NO_MEM; } } @@ -119,23 +119,23 @@ int ble_qwr_value_get( } while (i < qwr->mem_buffer.len); *len = cur_len; - return 0; + return NRF_SUCCESS; } #endif -int ble_qwr_conn_handle_assign(struct ble_qwr *qwr, uint16_t conn_handle) +uint32_t ble_qwr_conn_handle_assign(struct ble_qwr *qwr, uint16_t conn_handle) { if (!qwr) { - return -EFAULT; + return NRF_ERROR_NULL; } if (qwr->initialized != BLE_QWR_INITIALIZED) { - return -EPERM; + return NRF_ERROR_INVALID_STATE; } qwr->conn_handle = conn_handle; - return 0; + return NRF_SUCCESS; } /** diff --git a/samples/bluetooth/ble_cgms/src/main.c b/samples/bluetooth/ble_cgms/src/main.c index 61cec2f29e..bdcbcba4be 100644 --- a/samples/bluetooth/ble_cgms/src/main.c +++ b/samples/bluetooth/ble_cgms/src/main.c @@ -330,10 +330,10 @@ static uint32_t services_init(void) .evt_handler = qwr_evt_handler, }; - err = ble_qwr_init(&ble_qwr, &qwr_config); - if (err) { - LOG_ERR("Failed to initialize QWR service, err %d", err); - return err; + nrf_err = ble_qwr_init(&ble_qwr, &qwr_config); + if (nrf_err) { + LOG_ERR("Failed to initialize QWR service, nrf_error %#x", nrf_err); + return nrf_err; } /* Initialize Glucose Service */ @@ -441,7 +441,7 @@ static void led_indication_set(enum led_indicate led_indicate) static void on_ble_evt(const ble_evt_t *evt, void *ctx) { - int err; + uint32_t nrf_err; switch (evt->header.evt_id) { @@ -450,9 +450,9 @@ static void on_ble_evt(const ble_evt_t *evt, void *ctx) led_indication_set(LED_INDICATE_CONNECTED); conn_handle = evt->evt.gap_evt.conn_handle; - err = ble_qwr_conn_handle_assign(&ble_qwr, conn_handle); - if (err) { - LOG_ERR("Failed to assign BLE QWR conn handle, err %d", err); + nrf_err = ble_qwr_conn_handle_assign(&ble_qwr, conn_handle); + if (nrf_err) { + LOG_ERR("Failed to assign BLE QWR conn handle, nrf_error %#x", nrf_err); } nrf_err = ble_cgms_conn_handle_assign(&ble_cgms, conn_handle); diff --git a/samples/bluetooth/ble_hids_keyboard/src/main.c b/samples/bluetooth/ble_hids_keyboard/src/main.c index c16e3019ac..119f1b6cec 100644 --- a/samples/bluetooth/ble_hids_keyboard/src/main.c +++ b/samples/bluetooth/ble_hids_keyboard/src/main.c @@ -949,9 +949,9 @@ int main(void) goto idle; } - err = ble_qwr_init(&ble_qwr, &qwr_config); - if (err) { - LOG_ERR("ble_qwr_init failed, err %d", err); + nrf_err = ble_qwr_init(&ble_qwr, &qwr_config); + if (nrf_err) { + LOG_ERR("ble_qwr_init failed, nrf_error %#x", nrf_err); goto idle; } diff --git a/samples/bluetooth/ble_hids_mouse/src/main.c b/samples/bluetooth/ble_hids_mouse/src/main.c index 3847e00d04..4a45cb6aee 100644 --- a/samples/bluetooth/ble_hids_mouse/src/main.c +++ b/samples/bluetooth/ble_hids_mouse/src/main.c @@ -123,16 +123,16 @@ static void battery_level_meas_timeout_handler(void *context) static void on_ble_evt(const ble_evt_t *evt, void *ctx) { - int err; + uint32_t nrf_err; switch (evt->header.evt_id) { case BLE_GAP_EVT_CONNECTED: LOG_INF("Peer connected"); conn_handle = evt->evt.gap_evt.conn_handle; - err = ble_qwr_conn_handle_assign(&ble_qwr, conn_handle); - if (err) { - LOG_ERR("Failed to assign qwr handle, nrf_error %#x", err); + nrf_err = ble_qwr_conn_handle_assign(&ble_qwr, conn_handle); + if (nrf_err) { + LOG_ERR("Failed to assign qwr handle, nrf_error %#x", nrf_err); return; } @@ -798,9 +798,9 @@ int main(void) goto idle; } - err = ble_qwr_init(&ble_qwr, &qwr_config); - if (err) { - LOG_ERR("ble_qwr_init failed, err %d", err); + nrf_err = ble_qwr_init(&ble_qwr, &qwr_config); + if (nrf_err) { + LOG_ERR("ble_qwr_init failed, nrf_error %#x", nrf_err); goto idle; } diff --git a/samples/bluetooth/ble_nus/src/main.c b/samples/bluetooth/ble_nus/src/main.c index 64f19afc10..60dcd97d66 100644 --- a/samples/bluetooth/ble_nus/src/main.c +++ b/samples/bluetooth/ble_nus/src/main.c @@ -188,7 +188,6 @@ static void uarte_evt_handler(nrfx_uarte_event_t const *event, void *ctx) */ static void on_ble_evt(const ble_evt_t *evt, void *ctx) { - int err; uint32_t nrf_err; switch (evt->header.evt_id) { @@ -201,9 +200,9 @@ static void on_ble_evt(const ble_evt_t *evt, void *ctx) LOG_ERR("Failed to set system attributes, nrf_error %#x", nrf_err); } - err = ble_qwr_conn_handle_assign(&ble_qwr, conn_handle); - if (err) { - LOG_ERR("Failed to assign qwr handle, err %d", err); + nrf_err = ble_qwr_conn_handle_assign(&ble_qwr, conn_handle); + if (nrf_err) { + LOG_ERR("Failed to assign qwr handle, nrf_error %#x", nrf_err); return; } break; @@ -483,9 +482,9 @@ int main(void) LOG_INF("Bluetooth enabled"); - err = ble_qwr_init(&ble_qwr, &qwr_config); - if (err) { - LOG_ERR("ble_qwr_init failed, err %d", err); + nrf_err = ble_qwr_init(&ble_qwr, &qwr_config); + if (nrf_err) { + LOG_ERR("ble_qwr_init failed, nrf_error %#x", nrf_err); goto idle; } diff --git a/samples/bluetooth/ble_pwr_profiling/src/main.c b/samples/bluetooth/ble_pwr_profiling/src/main.c index 61c29a8958..c76d4d35ea 100644 --- a/samples/bluetooth/ble_pwr_profiling/src/main.c +++ b/samples/bluetooth/ble_pwr_profiling/src/main.c @@ -604,6 +604,7 @@ static uint32_t adv_init(void) int main(void) { int err; + uint32_t nrf_err; uint8_t uuid_type; struct ble_qwr_config qwr_config = { .evt_handler = on_ble_qwr_evt, @@ -677,9 +678,9 @@ int main(void) LOG_INF("Bluetooth enabled"); - err = ble_qwr_init(&ble_qwr, &qwr_config); - if (err) { - LOG_ERR("Failed to initialize QWR, err %d", err); + nrf_err = ble_qwr_init(&ble_qwr, &qwr_config); + if (nrf_err) { + LOG_ERR("Failed to initialize QWR, nrf_error %#x", nrf_err); goto idle; } diff --git a/tests/lib/bluetooth/ble_qwr/src/unity_test.c b/tests/lib/bluetooth/ble_qwr/src/unity_test.c index 412c85ea3e..a7c0115790 100644 --- a/tests/lib/bluetooth/ble_qwr/src/unity_test.c +++ b/tests/lib/bluetooth/ble_qwr/src/unity_test.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ -#include +#include #include #include #include @@ -20,36 +20,36 @@ static uint16_t ble_qwr_evt_handler(struct ble_qwr *qwr, const struct ble_qwr_ev return 0; } -void test_ble_qwr_init_efault(void) +void test_ble_qwr_init_error_null(void) { - int err; + uint32_t nrf_err; struct ble_qwr qwr; struct ble_qwr_config qwr_config = {0}; - err = ble_qwr_init(&qwr, NULL); - TEST_ASSERT_EQUAL(-EFAULT, err); + nrf_err = ble_qwr_init(&qwr, NULL); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); - err = ble_qwr_init(NULL, &qwr_config); - TEST_ASSERT_EQUAL(-EFAULT, err); + nrf_err = ble_qwr_init(NULL, &qwr_config); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); } -void test_ble_qwr_init_eperm(void) +void test_ble_qwr_init_error_invalid_state(void) { - int err; + uint32_t nrf_err; struct ble_qwr qwr; struct ble_qwr_config qwr_config = {0}; - err = ble_qwr_init(&qwr, &qwr_config); - TEST_ASSERT_EQUAL(0, err); + nrf_err = ble_qwr_init(&qwr, &qwr_config); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); /* Second attempt should fail */ - err = ble_qwr_init(&qwr, &qwr_config); - TEST_ASSERT_EQUAL(-EPERM, err); + nrf_err = ble_qwr_init(&qwr, &qwr_config); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_STATE, nrf_err); } void test_ble_qwr_init(void) { - int err; + uint32_t nrf_err; uint8_t mem[10]; struct ble_qwr qwr; struct ble_qwr_config qwr_config = { @@ -60,8 +60,8 @@ void test_ble_qwr_init(void) .evt_handler = ble_qwr_evt_handler, }; - err = ble_qwr_init(&qwr, &qwr_config); - TEST_ASSERT_EQUAL(0, err); + nrf_err = ble_qwr_init(&qwr, &qwr_config); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); TEST_ASSERT_EQUAL(BLE_CONN_HANDLE_INVALID, qwr.conn_handle); TEST_ASSERT_EQUAL(0, qwr.nb_registered_attr); @@ -74,26 +74,26 @@ void test_ble_qwr_init(void) TEST_ASSERT_EQUAL_PTR(ble_qwr_evt_handler, qwr.evt_handler); } -void test_ble_qwr_attr_register_efault(void) +void test_ble_qwr_attr_register_error_null(void) { - int err; + uint32_t nrf_err; - err = ble_qwr_attr_register(NULL, 1); - TEST_ASSERT_EQUAL(-EFAULT, err); + nrf_err = ble_qwr_attr_register(NULL, 1); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); } -void test_ble_qwr_attr_register_eperm(void) +void test_ble_qwr_attr_register_error_invalid_state(void) { - int err; + uint32_t nrf_err; struct ble_qwr qwr = {0}; - err = ble_qwr_attr_register(&qwr, 1); - TEST_ASSERT_EQUAL(-EPERM, err); + nrf_err = ble_qwr_attr_register(&qwr, 1); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_STATE, nrf_err); } -void test_ble_qwr_attr_register_einval(void) +void test_ble_qwr_attr_register_error_invalid_param(void) { - int err; + uint32_t nrf_err; uint8_t mem[10]; struct ble_qwr qwr; struct ble_qwr_config qwr_config = { @@ -104,16 +104,16 @@ void test_ble_qwr_attr_register_einval(void) .evt_handler = ble_qwr_evt_handler, }; - err = ble_qwr_init(&qwr, &qwr_config); - TEST_ASSERT_EQUAL(0, err); + nrf_err = ble_qwr_init(&qwr, &qwr_config); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); - err = ble_qwr_attr_register(&qwr, BLE_GATT_HANDLE_INVALID); - TEST_ASSERT_EQUAL(-EINVAL, err); + nrf_err = ble_qwr_attr_register(&qwr, BLE_GATT_HANDLE_INVALID); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, nrf_err); } -void test_ble_qwr_attr_register_enomem(void) +void test_ble_qwr_attr_register_error_no_mem(void) { - int err; + uint32_t nrf_err; uint8_t mem[10]; struct ble_qwr qwr; struct ble_qwr_config qwr_config = { @@ -127,11 +127,11 @@ void test_ble_qwr_attr_register_enomem(void) qwr_config.mem_buffer.p_mem = NULL; qwr_config.mem_buffer.len = sizeof(mem); - err = ble_qwr_init(&qwr, &qwr_config); - TEST_ASSERT_EQUAL(0, err); + nrf_err = ble_qwr_init(&qwr, &qwr_config); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); - err = ble_qwr_attr_register(&qwr, 1); - TEST_ASSERT_EQUAL(-ENOMEM, err); + nrf_err = ble_qwr_attr_register(&qwr, 1); + TEST_ASSERT_EQUAL(NRF_ERROR_NO_MEM, nrf_err); /* Reset qwr so it can be initialized again */ qwr.initialized = 0; @@ -139,11 +139,11 @@ void test_ble_qwr_attr_register_enomem(void) qwr_config.mem_buffer.p_mem = mem; qwr_config.mem_buffer.len = 0; - err = ble_qwr_init(&qwr, &qwr_config); - TEST_ASSERT_EQUAL(0, err); + nrf_err = ble_qwr_init(&qwr, &qwr_config); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); - err = ble_qwr_attr_register(&qwr, 1); - TEST_ASSERT_EQUAL(-ENOMEM, err); + nrf_err = ble_qwr_attr_register(&qwr, 1); + TEST_ASSERT_EQUAL(NRF_ERROR_NO_MEM, nrf_err); /* Reset qwr so it can be initialized again */ qwr.initialized = 0; @@ -151,22 +151,22 @@ void test_ble_qwr_attr_register_enomem(void) qwr_config.mem_buffer.p_mem = mem; qwr_config.mem_buffer.len = sizeof(mem); - err = ble_qwr_init(&qwr, &qwr_config); - TEST_ASSERT_EQUAL(0, err); + nrf_err = ble_qwr_init(&qwr, &qwr_config); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); - err = ble_qwr_attr_register(&qwr, 1); - TEST_ASSERT_EQUAL(0, err); + nrf_err = ble_qwr_attr_register(&qwr, 1); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); - err = ble_qwr_attr_register(&qwr, 2); - TEST_ASSERT_EQUAL(0, err); + nrf_err = ble_qwr_attr_register(&qwr, 2); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); - err = ble_qwr_attr_register(&qwr, 3); - TEST_ASSERT_EQUAL(-ENOMEM, err); + nrf_err = ble_qwr_attr_register(&qwr, 3); + TEST_ASSERT_EQUAL(NRF_ERROR_NO_MEM, nrf_err); } void test_ble_qwr_attr_register(void) { - int err; + uint32_t nrf_err; uint8_t mem[10]; struct ble_qwr qwr; struct ble_qwr_config qwr_config = { @@ -177,51 +177,51 @@ void test_ble_qwr_attr_register(void) .evt_handler = ble_qwr_evt_handler, }; - err = ble_qwr_init(&qwr, &qwr_config); - TEST_ASSERT_EQUAL(0, err); + nrf_err = ble_qwr_init(&qwr, &qwr_config); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); - err = ble_qwr_attr_register(&qwr, 0xa1); - TEST_ASSERT_EQUAL(0, err); + nrf_err = ble_qwr_attr_register(&qwr, 0xa1); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); TEST_ASSERT_EQUAL(1, qwr.nb_registered_attr); TEST_ASSERT_EQUAL(0xa1, qwr.attr_handles[0]); - err = ble_qwr_attr_register(&qwr, 0xa2); - TEST_ASSERT_EQUAL(0, err); + nrf_err = ble_qwr_attr_register(&qwr, 0xa2); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); TEST_ASSERT_EQUAL(2, qwr.nb_registered_attr); TEST_ASSERT_EQUAL(0xa2, qwr.attr_handles[1]); } -void test_ble_qwr_value_get_efault(void) +void test_ble_qwr_value_get_error_null(void) { - int err; + uint32_t nrf_err; struct ble_qwr qwr; uint8_t mem[1]; uint16_t len = sizeof(mem); - err = ble_qwr_value_get(NULL, 1, mem, &len); - TEST_ASSERT_EQUAL(-EFAULT, err); + nrf_err = ble_qwr_value_get(NULL, 1, mem, &len); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); - err = ble_qwr_value_get(&qwr, 1, NULL, &len); - TEST_ASSERT_EQUAL(-EFAULT, err); + nrf_err = ble_qwr_value_get(&qwr, 1, NULL, &len); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); - err = ble_qwr_value_get(&qwr, 1, mem, NULL); - TEST_ASSERT_EQUAL(-EFAULT, err); + nrf_err = ble_qwr_value_get(&qwr, 1, mem, NULL); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); } -void test_ble_qwr_value_get_eperm(void) +void test_ble_qwr_value_get_error_invalid_state(void) { - int err; + uint32_t nrf_err; struct ble_qwr qwr = {0}; uint8_t mem[1]; uint16_t len = sizeof(mem); - err = ble_qwr_value_get(&qwr, 1, mem, &len); - TEST_ASSERT_EQUAL(-EPERM, err); + nrf_err = ble_qwr_value_get(&qwr, 1, mem, &len); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_STATE, nrf_err); } void test_ble_qwr_value_get(void) { - int err; + uint32_t nrf_err; struct ble_qwr qwr = {0}; /* mem is filled by softdevice, we do it here */ uint8_t mem[] = { @@ -256,44 +256,44 @@ void test_ble_qwr_value_get(void) 0x15, 0x16, }; - err = ble_qwr_init(&qwr, &qwr_config); - TEST_ASSERT_EQUAL(0, err); + nrf_err = ble_qwr_init(&qwr, &qwr_config); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); - err = ble_qwr_value_get(&qwr, 0xa1, buf, &buf_len); - TEST_ASSERT_EQUAL(0, err); + nrf_err = ble_qwr_value_get(&qwr, 0xa1, buf, &buf_len); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); TEST_ASSERT_EQUAL(12, buf_len); TEST_ASSERT_EQUAL_MEMORY(attr1_expected_val, buf, sizeof(attr1_expected_val)); - err = ble_qwr_value_get(&qwr, 0xa2, buf, &buf_len); - TEST_ASSERT_EQUAL(0, err); + nrf_err = ble_qwr_value_get(&qwr, 0xa2, buf, &buf_len); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); TEST_ASSERT_EQUAL(6, buf_len); TEST_ASSERT_EQUAL_MEMORY(attr2_expected_val, buf, sizeof(attr2_expected_val)); - err = ble_qwr_value_get(&qwr, 0xa3, buf, &buf_len); - TEST_ASSERT_EQUAL(0, err); + nrf_err = ble_qwr_value_get(&qwr, 0xa3, buf, &buf_len); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); TEST_ASSERT_EQUAL(0, buf_len); } -void test_ble_qwr_conn_handle_assign_efault(void) +void test_ble_qwr_conn_handle_assign_error_null(void) { - int err; + uint32_t nrf_err; - err = ble_qwr_conn_handle_assign(NULL, 1); - TEST_ASSERT_EQUAL(-EFAULT, err); + nrf_err = ble_qwr_conn_handle_assign(NULL, 1); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); } -void test_ble_qwr_conn_handle_assign_eperm(void) +void test_ble_qwr_conn_handle_assign_error_invalid_state(void) { - int err; + uint32_t nrf_err; struct ble_qwr qwr = {0}; - err = ble_qwr_conn_handle_assign(&qwr, 1); - TEST_ASSERT_EQUAL(-EPERM, err); + nrf_err = ble_qwr_conn_handle_assign(&qwr, 1); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_STATE, nrf_err); } void test_ble_qwr_conn_handle_assign(void) { - int err; + uint32_t nrf_err; struct ble_qwr qwr = {0}; uint8_t mem[1]; struct ble_qwr_config qwr_config = { @@ -304,11 +304,11 @@ void test_ble_qwr_conn_handle_assign(void) .evt_handler = ble_qwr_evt_handler, }; - err = ble_qwr_init(&qwr, &qwr_config); - TEST_ASSERT_EQUAL(0, err); + nrf_err = ble_qwr_init(&qwr, &qwr_config); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); - err = ble_qwr_conn_handle_assign(&qwr, 0xC044); - TEST_ASSERT_EQUAL(0, err); + nrf_err = ble_qwr_conn_handle_assign(&qwr, 0xC044); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); TEST_ASSERT_EQUAL(0xC044, qwr.conn_handle); } @@ -326,7 +326,7 @@ void test_ble_qwr_on_ble_evt_do_nothing(void) void test_ble_qwr_on_ble_evt_mem_req_sd_busy(void) { - int err; + uint32_t nrf_err; struct ble_qwr qwr = {0}; uint8_t mem[16]; struct ble_qwr_config qwr_config = { @@ -362,11 +362,11 @@ void test_ble_qwr_on_ble_evt_mem_req_sd_busy(void) }; /* Initialize qwr */ - err = ble_qwr_init(&qwr, &qwr_config); - TEST_ASSERT_EQUAL(0, err); + nrf_err = ble_qwr_init(&qwr, &qwr_config); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); - err = ble_qwr_conn_handle_assign(&qwr, 0xC044); - TEST_ASSERT_EQUAL(0, err); + nrf_err = ble_qwr_conn_handle_assign(&qwr, 0xC044); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); __cmock_sd_ble_user_mem_reply_ExpectAndReturn(0xC044, &qwr.mem_buffer, NRF_ERROR_BUSY); ble_qwr_on_ble_evt(&ble_evt_mem_req, &qwr); @@ -378,7 +378,7 @@ void test_ble_qwr_on_ble_evt_mem_req_sd_busy(void) void test_ble_qwr_on_ble_evt_mem_req(void) { - int err; + uint32_t nrf_err; struct ble_qwr qwr = {0}; uint8_t mem[16]; struct ble_qwr_config qwr_config = { @@ -414,11 +414,11 @@ void test_ble_qwr_on_ble_evt_mem_req(void) }; /* Initialize qwr */ - err = ble_qwr_init(&qwr, &qwr_config); - TEST_ASSERT_EQUAL(0, err); + nrf_err = ble_qwr_init(&qwr, &qwr_config); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); - err = ble_qwr_conn_handle_assign(&qwr, 0xC044); - TEST_ASSERT_EQUAL(0, err); + nrf_err = ble_qwr_conn_handle_assign(&qwr, 0xC044); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); __cmock_sd_ble_user_mem_reply_ExpectAndReturn(0xC044, &qwr.mem_buffer, NRF_SUCCESS); ble_qwr_on_ble_evt(&ble_evt_mem_req, &qwr); From f9b711d9620b7dc03bdada2a9ff4589777b35cac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20J=C3=B8lsgard?= Date: Wed, 22 Oct 2025 10:38:14 +0200 Subject: [PATCH 06/12] lib: bluetooth: ble_racp: change error codes to nrf_error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change error codes to nrf_errors. Signed-off-by: Eivind Jølsgard --- .../release_notes/release_notes_changelog.rst | 1 + include/bm/bluetooth/ble_racp.h | 9 +-- lib/bluetooth/ble_racp/ble_racp.c | 14 ++--- tests/lib/bluetooth/ble_racp/src/unity_test.c | 58 +++++++++---------- 4 files changed, 39 insertions(+), 43 deletions(-) diff --git a/doc/nrf-bm/release_notes/release_notes_changelog.rst b/doc/nrf-bm/release_notes/release_notes_changelog.rst index a42a5b2342..0f2fef00eb 100644 --- a/doc/nrf-bm/release_notes/release_notes_changelog.rst +++ b/doc/nrf-bm/release_notes/release_notes_changelog.rst @@ -82,6 +82,7 @@ Libraries * :ref:`lib_ble_conn_params` library. * :ref:`lib_ble_gatt_queue` library. * :ref:`lib_ble_queued_writes` library. + * BLE Record Access Control Point library. * :ref:`lib_ble_conn_params` library: diff --git a/include/bm/bluetooth/ble_racp.h b/include/bm/bluetooth/ble_racp.h index ffbf718a3c..d691f4ad43 100644 --- a/include/bm/bluetooth/ble_racp.h +++ b/include/bm/bluetooth/ble_racp.h @@ -114,9 +114,10 @@ struct ble_racp_value { * @param[in] data_len Length of data. * @param[out] racp_val Decoded Record Access Control Point value. * - * @return 0 on success or negative errno on error. + * @retval NRF_SUCCESS on success. + * @retval NRF_ERROR_NULL if @p data or @p racp_val is NULL. */ -int ble_racp_decode(uint8_t const *data, size_t data_len, struct ble_racp_value *racp_val); +uint32_t ble_racp_decode(uint8_t const *data, size_t data_len, struct ble_racp_value *racp_val); /** * @brief Encode a Record Access Control Point response. @@ -127,9 +128,9 @@ int ble_racp_decode(uint8_t const *data, size_t data_len, struct ble_racp_value * @param[out] buf Buffer for encoded data. * @param[out] len Buffer size. * - * @return Length of encoded data or negative errno on error. + * @return Length of encoded data or 0 on error. */ -int ble_racp_encode(const struct ble_racp_value *racp_val, uint8_t *buf, size_t len); +size_t ble_racp_encode(const struct ble_racp_value *racp_val, uint8_t *buf, size_t len); #ifdef __cplusplus } diff --git a/lib/bluetooth/ble_racp/ble_racp.c b/lib/bluetooth/ble_racp/ble_racp.c index db827d9585..d0b78e85f3 100644 --- a/lib/bluetooth/ble_racp/ble_racp.c +++ b/lib/bluetooth/ble_racp/ble_racp.c @@ -4,15 +4,15 @@ * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ -#include +#include #include #include #include -int ble_racp_decode(const uint8_t *data, size_t data_len, struct ble_racp_value *racp_val) +uint32_t ble_racp_decode(const uint8_t *data, size_t data_len, struct ble_racp_value *racp_val) { if (!data || !racp_val) { - return -EFAULT; + return NRF_ERROR_NULL; } racp_val->opcode = (data_len >= 1) ? data[0] : 0xFF; @@ -20,19 +20,19 @@ int ble_racp_decode(const uint8_t *data, size_t data_len, struct ble_racp_value racp_val->operand_len = (data_len >= 3) ? (data_len - 2) : 0; racp_val->operand = (data_len >= 3) ? (uint8_t *)&data[2] : NULL; - return 0; + return NRF_SUCCESS; } -int ble_racp_encode(const struct ble_racp_value *racp_val, uint8_t *buf, size_t buf_len) +size_t ble_racp_encode(const struct ble_racp_value *racp_val, uint8_t *buf, size_t buf_len) { uint8_t len = 0; if (!racp_val || !buf) { - return -EFAULT; + return 0; } if (buf_len < (racp_val->operand_len + 2)) { - return -EINVAL; + return 0; } buf[len++] = racp_val->opcode; diff --git a/tests/lib/bluetooth/ble_racp/src/unity_test.c b/tests/lib/bluetooth/ble_racp/src/unity_test.c index 2777271c29..dab74b40c8 100644 --- a/tests/lib/bluetooth/ble_racp/src/unity_test.c +++ b/tests/lib/bluetooth/ble_racp/src/unity_test.c @@ -4,43 +4,37 @@ * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ -#include +#include #include #include #include #include -void test_ble_racp_encode_efault(void) +void test_ble_racp_encode_error_invalid(void) { int ret; - const struct ble_racp_value racp_val = {0}; + struct ble_racp_value racp_val = {0}; uint8_t data[5]; ret = ble_racp_encode(NULL, data, sizeof(data)); - TEST_ASSERT_EQUAL(-EFAULT, ret); + TEST_ASSERT_EQUAL(0, ret); ret = ble_racp_encode(&racp_val, NULL, 0); - TEST_ASSERT_EQUAL(-EFAULT, ret); -} - -void test_ble_racp_encode_einval(void) -{ - int ret; - struct ble_racp_value racp_val = {0}; - uint8_t data[5]; + TEST_ASSERT_EQUAL(0, ret); ret = ble_racp_encode(&racp_val, data, 0); - TEST_ASSERT_EQUAL(-EINVAL, ret); + TEST_ASSERT_EQUAL(0, ret); ret = ble_racp_encode(&racp_val, data, 1); - TEST_ASSERT_EQUAL(-EINVAL, ret); + TEST_ASSERT_EQUAL(0, ret); racp_val.operand_len = 1; ret = ble_racp_encode(&racp_val, data, 2); - TEST_ASSERT_EQUAL(-EINVAL, ret); + TEST_ASSERT_EQUAL(0, ret); } + void test_ble_racp_encode(void) { int ret; @@ -64,29 +58,29 @@ void test_ble_racp_encode(void) TEST_ASSERT_EQUAL_MEMORY(data_expected, data, sizeof(data)); } -void test_ble_racp_decode_efault(void) +void test_ble_racp_decode_error_null(void) { - int ret; + uint32_t nrf_err; struct ble_racp_value racp_val = {0}; uint8_t data[5]; - ret = ble_racp_decode(NULL, 0, &racp_val); - TEST_ASSERT_EQUAL(-EFAULT, ret); + nrf_err = ble_racp_decode(NULL, 0, &racp_val); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); - ret = ble_racp_decode(data, sizeof(data), NULL); - TEST_ASSERT_EQUAL(-EFAULT, ret); + nrf_err = ble_racp_decode(data, sizeof(data), NULL); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); } void test_ble_racp_decode(void) { - int ret; + uint32_t nrf_err; uint8_t data[] = {RACP_OPCODE_REPORT_RECS, RACP_OPERATOR_LESS_OR_EQUAL, 3, 4, 5}; struct ble_racp_value racp_val; - ret = ble_racp_decode(data, sizeof(data), &racp_val); - TEST_ASSERT_EQUAL(0, ret); + nrf_err = ble_racp_decode(data, sizeof(data), &racp_val); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); TEST_ASSERT_EQUAL(RACP_OPCODE_REPORT_RECS, racp_val.opcode); TEST_ASSERT_EQUAL(RACP_OPERATOR_LESS_OR_EQUAL, racp_val.operator); @@ -95,8 +89,8 @@ void test_ble_racp_decode(void) uint8_t empty[] = {0}; - ret = ble_racp_decode(empty, 0, &racp_val); - TEST_ASSERT_EQUAL(0, ret); + nrf_err = ble_racp_decode(empty, 0, &racp_val); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); TEST_ASSERT_EQUAL(0xFF, racp_val.opcode); TEST_ASSERT_EQUAL(0xFF, racp_val.operator); @@ -105,8 +99,8 @@ void test_ble_racp_decode(void) uint8_t opcode[] = {RACP_OPCODE_DELETE_RECS}; - ret = ble_racp_decode(opcode, sizeof(opcode), &racp_val); - TEST_ASSERT_EQUAL(0, ret); + nrf_err = ble_racp_decode(opcode, sizeof(opcode), &racp_val); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); TEST_ASSERT_EQUAL(RACP_OPCODE_DELETE_RECS, racp_val.opcode); TEST_ASSERT_EQUAL(0xFF, racp_val.operator); @@ -115,8 +109,8 @@ void test_ble_racp_decode(void) uint8_t opcode_operator[] = {RACP_OPCODE_DELETE_RECS, RACP_OPERATOR_RANGE}; - ret = ble_racp_decode(opcode_operator, sizeof(opcode_operator), &racp_val); - TEST_ASSERT_EQUAL(0, ret); + nrf_err = ble_racp_decode(opcode_operator, sizeof(opcode_operator), &racp_val); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); TEST_ASSERT_EQUAL(RACP_OPCODE_DELETE_RECS, racp_val.opcode); TEST_ASSERT_EQUAL(RACP_OPERATOR_RANGE, racp_val.operator); @@ -125,8 +119,8 @@ void test_ble_racp_decode(void) uint8_t opcode_operator_data[] = {RACP_OPCODE_DELETE_RECS, RACP_OPERATOR_RANGE, 0xA}; - ret = ble_racp_decode(opcode_operator_data, sizeof(opcode_operator_data), &racp_val); - TEST_ASSERT_EQUAL(0, ret); + nrf_err = ble_racp_decode(opcode_operator_data, sizeof(opcode_operator_data), &racp_val); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); TEST_ASSERT_EQUAL(RACP_OPCODE_DELETE_RECS, racp_val.opcode); TEST_ASSERT_EQUAL(RACP_OPERATOR_RANGE, racp_val.operator); From 9e8b4bfa55b889e11f5f60895a8488be995d70ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20J=C3=B8lsgard?= Date: Wed, 22 Oct 2025 14:14:11 +0200 Subject: [PATCH 07/12] bluetooth: services: ble_bas: change error codes to nrf_error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change error codes to nrf_errors. Signed-off-by: Eivind Jølsgard --- .../release_notes/release_notes_changelog.rst | 3 +- include/bm/bluetooth/services/ble_bas.h | 33 ++--- samples/bluetooth/ble_cgms/src/main.c | 17 +-- .../bluetooth/ble_hids_keyboard/src/main.c | 15 +- samples/bluetooth/ble_hids_mouse/src/main.c | 15 +- samples/bluetooth/ble_hrs/src/main.c | 15 +- subsys/bluetooth/services/ble_bas/bas.c | 91 ++++++------ .../services/ble_bas/src/unity_test.c | 136 +++++++++--------- 8 files changed, 167 insertions(+), 158 deletions(-) diff --git a/doc/nrf-bm/release_notes/release_notes_changelog.rst b/doc/nrf-bm/release_notes/release_notes_changelog.rst index 0f2fef00eb..23424610df 100644 --- a/doc/nrf-bm/release_notes/release_notes_changelog.rst +++ b/doc/nrf-bm/release_notes/release_notes_changelog.rst @@ -76,12 +76,13 @@ Libraries * Added the :ref:`lib_ble_radio_notification` library. -* Updated the following libraries to return ``nrf_errors`` instead of ``errnos``: +* 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. * BLE Record Access Control Point library. * :ref:`lib_ble_conn_params` library: diff --git a/include/bm/bluetooth/services/ble_bas.h b/include/bm/bluetooth/services/ble_bas.h index 6bc5764c5c..790278f7cb 100644 --- a/include/bm/bluetooth/services/ble_bas.h +++ b/include/bm/bluetooth/services/ble_bas.h @@ -152,11 +152,11 @@ struct ble_bas { * @param bas Battery service. * @param bas_config Battery service configuration. * - * @retval 0 On success. - * @retval -EFAULT If @p bas or @p bas_config are @c NULL. - * @retval -EINVAL Invalid parameters. + * @retval NRF_SUCCESS On success. + * @retval NRF_ERROR_NULL If @p bas or @p bas_config are @c NULL. + * @retval NRF_ERROR_INVALID_PARAM Invalid parameters. */ -int ble_bas_init(struct ble_bas *bas, const struct ble_bas_config *bas_config); +uint32_t ble_bas_init(struct ble_bas *bas, const struct ble_bas_config *bas_config); /** * @brief Update battery level. @@ -168,13 +168,14 @@ int ble_bas_init(struct ble_bas *bas, const struct ble_bas_config *bas_config); * @param conn_handle Connection handle. * @param battery_level Battery level (in percent of full capacity). * - * @retval 0 On success. - * @retval -EFAULT If @p bas is @c NULL. - * @retval -EINVAL Invalid parameters. - * @retval -ENOTCONN Invalid connection handle. - * @retval -EPIPE Notifications not enabled in the CCCD. + * @retval NRF_SUCCESS On success. + * @retval NRF_ERROR_NULL If @p bas is @c NULL. + * @retval NRF_ERROR_INVALID_PARAM Invalid parameters. + * @retval NRF_ERROR_NOT_FOUND Invalid connection handle. + * @retval NRF_ERROR_INVALID_STATE Notifications not enabled in the CCCD. */ -int ble_bas_battery_level_update(struct ble_bas *bas, uint16_t conn_handle, uint8_t battery_level); +uint32_t ble_bas_battery_level_update(struct ble_bas *bas, uint16_t conn_handle, + uint8_t battery_level); /** * @brief Notify battery level. @@ -186,13 +187,13 @@ int ble_bas_battery_level_update(struct ble_bas *bas, uint16_t conn_handle, uint * @param bas Battery service. * @param conn_handle Connection handle. * - * @retval 0 On success. - * @retval -EFAULT If @p bas is @c NULL. - * @retval -EINVAL Invalid parameters. - * @retval -ENOTCONN Invalid connection handle. - * @retval -EPIPE Notifications not enabled in the CCCD. + * @retval NRF_SUCCESS On success. + * @retval NRF_ERROR_NULL If @p bas is @c NULL. + * @retval NRF_ERROR_INVALID_PARAM Invalid parameters. + * @retval NRF_ERROR_NOT_FOUND Invalid connection handle. + * @retval NRF_ERROR_INVALID_STATE Notifications not enabled in the CCCD. */ -int ble_bas_battery_level_notify(struct ble_bas *bas, uint16_t conn_handle); +uint32_t ble_bas_battery_level_notify(struct ble_bas *bas, uint16_t conn_handle); #ifdef __cplusplus } diff --git a/samples/bluetooth/ble_cgms/src/main.c b/samples/bluetooth/ble_cgms/src/main.c index bdcbcba4be..e5a5e07289 100644 --- a/samples/bluetooth/ble_cgms/src/main.c +++ b/samples/bluetooth/ble_cgms/src/main.c @@ -87,6 +87,7 @@ static uint8_t qwr_mem[CONFIG_QWR_MEM_BUFF_SIZE]; static void battery_level_update(void) { int err; + uint32_t nrf_err; uint32_t battery_level; err = (uint8_t)sensorsim_measure(&battery_sim_state, &battery_level); @@ -94,11 +95,11 @@ static void battery_level_update(void) LOG_ERR("Sensorsim measure failed, err %d", err); } - err = ble_bas_battery_level_update(&ble_bas, conn_handle, battery_level); - if (err) { + nrf_err = ble_bas_battery_level_update(&ble_bas, conn_handle, battery_level); + if (nrf_err) { /* Ignore if not in a connection or notifications disabled in CCCD. */ - if (err != -ENOTCONN && err != -EPIPE) { - LOG_ERR("Failed to update battery level, err %d", err); + if (nrf_err != NRF_ERROR_NOT_FOUND && nrf_err != NRF_ERROR_INVALID_STATE) { + LOG_ERR("Failed to update battery level, nrf_error %#x", nrf_err); } } } @@ -349,10 +350,10 @@ static uint32_t services_init(void) /* Add a basic battery measurement with only mandatory fields */ - err = ble_bas_init(&ble_bas, &bas_config); - if (err) { - LOG_ERR("Failed to initialize BAS service, err %d", err); - return err; + nrf_err = ble_bas_init(&ble_bas, &bas_config); + if (nrf_err) { + LOG_ERR("Failed to initialize BAS service, nrf_error %#x", nrf_err); + return nrf_err; } /* Initialize Device Information Service. */ diff --git a/samples/bluetooth/ble_hids_keyboard/src/main.c b/samples/bluetooth/ble_hids_keyboard/src/main.c index 119f1b6cec..d36fbcb185 100644 --- a/samples/bluetooth/ble_hids_keyboard/src/main.c +++ b/samples/bluetooth/ble_hids_keyboard/src/main.c @@ -173,6 +173,7 @@ void report_fifo_clear(void) static void battery_level_meas_timeout_handler(void *context) { int err; + uint32_t nrf_err; uint32_t battery_level; ARG_UNUSED(context); @@ -182,11 +183,11 @@ static void battery_level_meas_timeout_handler(void *context) LOG_ERR("Sensorsim measure failed, err %d", err); } - err = ble_bas_battery_level_update(&ble_bas, conn_handle, battery_level); - if (err) { + nrf_err = ble_bas_battery_level_update(&ble_bas, conn_handle, battery_level); + if (nrf_err) { /* Ignore if not in a connection or notifications disabled in CCCD. */ - if (err != -ENOTCONN && err != -EPIPE) { - LOG_ERR("Failed to update battery level, err %d", err); + if (nrf_err != NRF_ERROR_NOT_FOUND && nrf_err != NRF_ERROR_INVALID_STATE) { + LOG_ERR("Failed to update battery level, nrf_error %#x", nrf_err); } } } @@ -961,9 +962,9 @@ int main(void) goto idle; } - err = ble_bas_init(&ble_bas, &bas_config); - if (err) { - LOG_ERR("Failed to initialize BAS service, err %d", err); + nrf_err = ble_bas_init(&ble_bas, &bas_config); + if (nrf_err) { + LOG_ERR("Failed to initialize BAS service, nrf_error %#x", nrf_err); goto idle; } diff --git a/samples/bluetooth/ble_hids_mouse/src/main.c b/samples/bluetooth/ble_hids_mouse/src/main.c index 4a45cb6aee..384f52a67e 100644 --- a/samples/bluetooth/ble_hids_mouse/src/main.c +++ b/samples/bluetooth/ble_hids_mouse/src/main.c @@ -103,6 +103,7 @@ static bool auth_key_request; static void battery_level_meas_timeout_handler(void *context) { int err; + uint32_t nrf_err; uint32_t battery_level; ARG_UNUSED(context); @@ -112,11 +113,11 @@ static void battery_level_meas_timeout_handler(void *context) LOG_ERR("Sensorsim measure failed, err %d", err); } - err = ble_bas_battery_level_update(&ble_bas, conn_handle, battery_level); - if (err) { + nrf_err = ble_bas_battery_level_update(&ble_bas, conn_handle, battery_level); + if (nrf_err) { /* Ignore if not in a connection or notifications disabled in CCCD. */ - if (err != -ENOTCONN && err != -EPIPE) { - LOG_ERR("Failed to update battery level, err %d", err); + if (nrf_err != NRF_ERROR_NOT_FOUND && nrf_err != NRF_ERROR_INVALID_STATE) { + LOG_ERR("Failed to update battery level, nrf_error %#x", nrf_err); } } } @@ -810,9 +811,9 @@ int main(void) goto idle; } - err = ble_bas_init(&ble_bas, &bas_config); - if (err) { - LOG_ERR("Failed to initialize BAS service, err %d", err); + nrf_err = ble_bas_init(&ble_bas, &bas_config); + if (nrf_err) { + LOG_ERR("Failed to initialize BAS service, nrf_error %#x", nrf_err); goto idle; } diff --git a/samples/bluetooth/ble_hrs/src/main.c b/samples/bluetooth/ble_hrs/src/main.c index 44de55b787..567f4a1bcc 100644 --- a/samples/bluetooth/ble_hrs/src/main.c +++ b/samples/bluetooth/ble_hrs/src/main.c @@ -71,6 +71,7 @@ static struct bm_timer sensor_contact_timer; void battery_level_meas_timeout_handler(void *context) { int err; + uint32_t nrf_err; uint32_t battery_level; ARG_UNUSED(context); @@ -81,11 +82,11 @@ void battery_level_meas_timeout_handler(void *context) return; } - err = ble_bas_battery_level_update(&ble_bas, conn_handle, (uint8_t)battery_level); - if (err) { + nrf_err = ble_bas_battery_level_update(&ble_bas, conn_handle, battery_level); + if (nrf_err) { /* Ignore if not in a connection or notifications disabled in CCCD. */ - if (err != -ENOTCONN && err != -EPIPE) { - LOG_ERR("Failed to update battery level, err %d", err); + if (nrf_err != NRF_ERROR_NOT_FOUND && nrf_err != NRF_ERROR_INVALID_STATE) { + LOG_ERR("Failed to update battery level, nrf_error %#x", nrf_err); } } } @@ -509,9 +510,9 @@ int main(void) goto idle; } - err = ble_bas_init(&ble_bas, &bas_cfg); - if (err) { - LOG_ERR("Failed to initialize battery service, err %d", err); + nrf_err = ble_bas_init(&ble_bas, &bas_cfg); + if (nrf_err) { + LOG_ERR("Failed to initialize battery service, nrf_error %#x", nrf_err); goto idle; } diff --git a/subsys/bluetooth/services/ble_bas/bas.c b/subsys/bluetooth/services/ble_bas/bas.c index cddb36e88a..e29dd6d358 100644 --- a/subsys/bluetooth/services/ble_bas/bas.c +++ b/subsys/bluetooth/services/ble_bas/bas.c @@ -4,6 +4,7 @@ * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ +#include #include #include #include @@ -123,13 +124,13 @@ void ble_bas_on_ble_evt(const ble_evt_t *ble_evt, void *bas_instance) } } -int ble_bas_init(struct ble_bas *bas, const struct ble_bas_config *cfg) +uint32_t ble_bas_init(struct ble_bas *bas, const struct ble_bas_config *cfg) { - int err; + uint32_t nrf_err; ble_uuid_t ble_uuid; if (bas == NULL || cfg == NULL) { - return -EFAULT; + return NRF_ERROR_NULL; } /* Initialize service structure */ @@ -140,42 +141,44 @@ int ble_bas_init(struct ble_bas *bas, const struct ble_bas_config *cfg) BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_BATTERY_SERVICE); /* Add service */ - err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, - &bas->service_handle); - if (err) { - LOG_ERR("Failed to add battery service, nrf_error %#x", err); - return -EINVAL; + nrf_err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, + &bas->service_handle); + if (nrf_err) { + LOG_ERR("Failed to add battery service, nrf_error %#x", nrf_err); + return NRF_ERROR_INVALID_PARAM; } /* Add battery level characteristic */ - err = battery_level_char_add(bas, cfg); - if (err) { - LOG_ERR("Failed to add battery service characteristic, nrf_error %#x", err); - return -EINVAL; + nrf_err = battery_level_char_add(bas, cfg); + if (nrf_err) { + LOG_ERR("Failed to add battery service characteristic, nrf_error %#x", nrf_err); + return NRF_ERROR_INVALID_PARAM; } /* Add reference descriptor if present */ if (cfg->report_ref != NULL) { - err = report_reference_descriptor_add(bas, cfg); - if (err) { - LOG_ERR("Failed to add report reference descriptor, nrf_error %#x", err); - return -EINVAL; + nrf_err = report_reference_descriptor_add(bas, cfg); + if (nrf_err) { + LOG_ERR("Failed to add report reference descriptor, nrf_error %#x", + nrf_err); + return NRF_ERROR_INVALID_PARAM; } } LOG_DBG("Battery service initialized"); - return 0; + return NRF_SUCCESS; } -int ble_bas_battery_level_update(struct ble_bas *bas, uint16_t conn_handle, uint8_t battery_level) +uint32_t ble_bas_battery_level_update( + struct ble_bas *bas, uint16_t conn_handle, uint8_t battery_level) { - int err; + uint32_t nrf_err; ble_gatts_value_t gatts_value = {0}; ble_gatts_hvx_params_t hvx = {0}; if (!bas) { - return -EFAULT; + return NRF_ERROR_NULL; } if (bas->battery_level == battery_level) { @@ -187,11 +190,11 @@ int ble_bas_battery_level_update(struct ble_bas *bas, uint16_t conn_handle, uint gatts_value.len = sizeof(uint8_t); gatts_value.p_value = &battery_level; - err = sd_ble_gatts_value_set(BLE_CONN_HANDLE_INVALID, - bas->battery_level_handles.value_handle, &gatts_value); - if (err) { - LOG_ERR("Failed to update battery level, nrf_error %#x", err); - return -EINVAL; + nrf_err = sd_ble_gatts_value_set(BLE_CONN_HANDLE_INVALID, + bas->battery_level_handles.value_handle, &gatts_value); + if (nrf_err) { + LOG_ERR("Failed to update battery level, nrf_error %#x", nrf_err); + return NRF_ERROR_INVALID_PARAM; } LOG_DBG("Battery level: %d%%", battery_level); @@ -199,7 +202,7 @@ int ble_bas_battery_level_update(struct ble_bas *bas, uint16_t conn_handle, uint if (!bas->can_notify) { /* We are done */ - return 0; + return NRF_SUCCESS; } /* Notify */ @@ -209,32 +212,32 @@ int ble_bas_battery_level_update(struct ble_bas *bas, uint16_t conn_handle, uint hvx.p_len = &gatts_value.len; hvx.p_data = gatts_value.p_value; - err = sd_ble_gatts_hvx(conn_handle, &hvx); - switch (err) { + nrf_err = sd_ble_gatts_hvx(conn_handle, &hvx); + switch (nrf_err) { case NRF_SUCCESS: - return 0; + return NRF_SUCCESS; case BLE_ERROR_INVALID_CONN_HANDLE: - return -ENOTCONN; + return NRF_ERROR_NOT_FOUND; case NRF_ERROR_INVALID_STATE: case BLE_ERROR_GATTS_SYS_ATTR_MISSING: - return -EPIPE; + return NRF_ERROR_INVALID_STATE; default: - LOG_ERR("Failed to notify battery level, nrf_error %#x", err); - return -EINVAL; + LOG_ERR("Failed to notify battery level, nrf_error %#x", nrf_err); + return NRF_ERROR_INVALID_PARAM; } } -int ble_bas_battery_level_notify(struct ble_bas *bas, uint16_t conn_handle) +uint32_t ble_bas_battery_level_notify(struct ble_bas *bas, uint16_t conn_handle) { - int err; + uint32_t nrf_err; ble_gatts_hvx_params_t hvx = {0}; uint16_t len = sizeof(uint8_t); if (!bas) { - return -EFAULT; + return NRF_ERROR_NULL; } if (!bas->can_notify) { - return -EINVAL; + return NRF_ERROR_INVALID_PARAM; } hvx.handle = bas->battery_level_handles.value_handle; @@ -243,16 +246,16 @@ int ble_bas_battery_level_notify(struct ble_bas *bas, uint16_t conn_handle) hvx.p_len = &len; hvx.p_data = &bas->battery_level; - err = sd_ble_gatts_hvx(conn_handle, &hvx); - switch (err) { + nrf_err = sd_ble_gatts_hvx(conn_handle, &hvx); + switch (nrf_err) { case NRF_SUCCESS: - return 0; + return NRF_SUCCESS; case BLE_ERROR_INVALID_CONN_HANDLE: - return -ENOTCONN; + return NRF_ERROR_NOT_FOUND; case NRF_ERROR_INVALID_STATE: - return -EPIPE; + return NRF_ERROR_INVALID_STATE; default: - LOG_ERR("Failed to notify battery level, nrf_error %#x", err); - return -EINVAL; + LOG_ERR("Failed to notify battery level, nrf_error %#x", nrf_err); + return NRF_ERROR_INVALID_PARAM; } } diff --git a/tests/subsys/bluetooth/services/ble_bas/src/unity_test.c b/tests/subsys/bluetooth/services/ble_bas/src/unity_test.c index 27c4ce1ced..d3777f88ea 100644 --- a/tests/subsys/bluetooth/services/ble_bas/src/unity_test.c +++ b/tests/subsys/bluetooth/services/ble_bas/src/unity_test.c @@ -179,14 +179,14 @@ static void ble_bas_evt_handler_notif_disable(struct ble_bas *bas, const struct void bas_init(const struct ble_bas_config *cfg) { - int ret; + uint32_t nrf_err; __cmock_sd_ble_gatts_service_add_Stub(stub_sd_ble_gatts_service_add_success); __cmock_sd_ble_gatts_characteristic_add_Stub(stub_sd_ble_gatts_characteristic_add_success); __cmock_sd_ble_gatts_descriptor_add_Stub(stub_sd_ble_gatts_descriptor_add_success); - ret = ble_bas_init(&ble_bas, cfg); - TEST_ASSERT_EQUAL(0, ret); + nrf_err = ble_bas_init(&ble_bas, cfg); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); } void test_ble_bas_on_ble_evt(void) @@ -231,46 +231,46 @@ void test_ble_bas_on_ble_evt(void) TEST_ASSERT_FALSE(evt_handler_called); } -void test_ble_bas_init_efault(void) +void test_ble_bas_init_error_null(void) { - int ret; + uint32_t nrf_err; struct ble_bas_config bas_config = { .evt_handler = ble_bas_evt_handler }; - ret = ble_bas_init(NULL, &bas_config); - TEST_ASSERT_EQUAL(-EFAULT, ret); + nrf_err = ble_bas_init(NULL, &bas_config); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); TEST_ASSERT_NOT_EQUAL(bas_config.evt_handler, ble_bas.evt_handler); - ret = ble_bas_init(&ble_bas, NULL); - TEST_ASSERT_EQUAL(-EFAULT, ret); + nrf_err = ble_bas_init(&ble_bas, NULL); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); TEST_ASSERT_NOT_EQUAL(bas_config.evt_handler, ble_bas.evt_handler); } -void test_ble_bas_init_einval(void) +void test_ble_bas_init_error_invalid_param(void) { - int ret; + uint32_t nrf_err; struct ble_bas_config bas_config = { .evt_handler = ble_bas_evt_handler }; bas_config.report_ref = (void *)&report_ref; __cmock_sd_ble_gatts_service_add_ExpectAnyArgsAndReturn(NRF_ERROR_INVALID_PARAM); - ret = ble_bas_init(&ble_bas, &bas_config); - TEST_ASSERT_EQUAL(-EINVAL, ret); + nrf_err = ble_bas_init(&ble_bas, &bas_config); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, nrf_err); __cmock_sd_ble_gatts_service_add_ExpectAnyArgsAndReturn(NRF_SUCCESS); __cmock_sd_ble_gatts_characteristic_add_ExpectAnyArgsAndReturn(NRF_ERROR_INVALID_PARAM); - ret = ble_bas_init(&ble_bas, &bas_config); - TEST_ASSERT_EQUAL(-EINVAL, ret); + nrf_err = ble_bas_init(&ble_bas, &bas_config); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, nrf_err); __cmock_sd_ble_gatts_service_add_ExpectAnyArgsAndReturn(NRF_SUCCESS); __cmock_sd_ble_gatts_characteristic_add_ExpectAnyArgsAndReturn(NRF_SUCCESS); __cmock_sd_ble_gatts_descriptor_add_ExpectAnyArgsAndReturn(NRF_ERROR_INVALID_PARAM); - ret = ble_bas_init(&ble_bas, &bas_config); - TEST_ASSERT_EQUAL(-EINVAL, ret); + nrf_err = ble_bas_init(&ble_bas, &bas_config); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, nrf_err); } void test_ble_bas_init_success(void) { - int ret; + uint32_t nrf_err; struct ble_bas_config bas_cfg = bas_cfg_template; bas_cfg.evt_handler = ble_bas_evt_handler; @@ -280,25 +280,25 @@ void test_ble_bas_init_success(void) __cmock_sd_ble_gatts_descriptor_add_Stub(stub_sd_ble_gatts_descriptor_add_success); __cmock_sd_ble_gatts_hvx_Stub(stub_sd_ble_gatts_hvx_param_check); - ret = ble_bas_init(&ble_bas, &bas_cfg); - TEST_ASSERT_EQUAL(0, ret); - ret = ble_bas_battery_level_notify(&ble_bas, SERVICE_HANDLE); - TEST_ASSERT_EQUAL(0, ret); + nrf_err = ble_bas_init(&ble_bas, &bas_cfg); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); + nrf_err = ble_bas_battery_level_notify(&ble_bas, SERVICE_HANDLE); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); TEST_ASSERT_EQUAL(1, hvx_stub_called); } -void test_ble_bas_battery_level_update_efault(void) +void test_ble_bas_battery_level_update_error_null(void) { - int ret; + uint32_t nrf_err; uint16_t conn_handle = BLE_CONN_HANDLE_INVALID; - ret = ble_bas_battery_level_update(NULL, conn_handle, battery_level); - TEST_ASSERT_EQUAL(-EFAULT, ret); + nrf_err = ble_bas_battery_level_update(NULL, conn_handle, battery_level); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); } -void test_ble_bas_battery_level_update_einval(void) +void test_ble_bas_battery_level_update_error_invalid_param(void) { - int ret; + uint32_t nrf_err; uint16_t conn_handle = BLE_CONN_HANDLE_INVALID; struct ble_bas_config bas_cfg = bas_cfg_template; @@ -306,20 +306,20 @@ void test_ble_bas_battery_level_update_einval(void) bas_cfg.can_notify = false; bas_init(&bas_cfg); __cmock_sd_ble_gatts_value_set_ExpectAnyArgsAndReturn(NRF_ERROR_INVALID_PARAM); - ret = ble_bas_battery_level_update(&ble_bas, conn_handle, battery_level); - TEST_ASSERT_EQUAL(-EINVAL, ret); + nrf_err = ble_bas_battery_level_update(&ble_bas, conn_handle, battery_level); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, nrf_err); bas_cfg.can_notify = true; bas_init(&bas_cfg); __cmock_sd_ble_gatts_value_set_ExpectAnyArgsAndReturn(NRF_SUCCESS); __cmock_sd_ble_gatts_hvx_ExpectAnyArgsAndReturn(NRF_ERROR_TIMEOUT); - ret = ble_bas_battery_level_update(&ble_bas, conn_handle, battery_level); - TEST_ASSERT_EQUAL(-EINVAL, ret); + nrf_err = ble_bas_battery_level_update(&ble_bas, conn_handle, battery_level); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, nrf_err); } -void test_ble_bas_battery_level_update_enotconn(void) +void test_ble_bas_battery_level_update_error_not_found(void) { - int ret; + uint32_t nrf_err; uint16_t conn_handle = 0x0001; struct ble_bas_config bas_cfg = bas_cfg_template; @@ -329,13 +329,13 @@ void test_ble_bas_battery_level_update_enotconn(void) __cmock_sd_ble_gatts_value_set_ExpectAnyArgsAndReturn(NRF_SUCCESS); __cmock_sd_ble_gatts_hvx_ExpectAnyArgsAndReturn(BLE_ERROR_INVALID_CONN_HANDLE); - ret = ble_bas_battery_level_update(&ble_bas, conn_handle, battery_level); - TEST_ASSERT_EQUAL(-ENOTCONN, ret); + nrf_err = ble_bas_battery_level_update(&ble_bas, conn_handle, battery_level); + TEST_ASSERT_EQUAL(NRF_ERROR_NOT_FOUND, nrf_err); } -void test_ble_bas_battery_level_update_epipe(void) +void test_ble_bas_battery_level_update_error_invalid_state(void) { - int ret; + uint32_t nrf_err; uint16_t conn_handle = BLE_CONN_HANDLE_INVALID; struct ble_bas_config bas_cfg = bas_cfg_template; @@ -344,13 +344,13 @@ void test_ble_bas_battery_level_update_epipe(void) bas_init(&bas_cfg); __cmock_sd_ble_gatts_value_set_Stub(stub_sd_ble_gatts_value_set_check); __cmock_sd_ble_gatts_hvx_ExpectAnyArgsAndReturn(NRF_ERROR_INVALID_STATE); - ret = ble_bas_battery_level_update(&ble_bas, conn_handle, battery_level); - TEST_ASSERT_EQUAL(-EPIPE, ret); + nrf_err = ble_bas_battery_level_update(&ble_bas, conn_handle, battery_level); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_STATE, nrf_err); } void test_ble_bas_battery_level_update_success(void) { - int ret; + uint32_t nrf_err; uint16_t conn_handle = 0x0001; struct ble_bas_config bas_cfg = bas_cfg_template; @@ -358,82 +358,82 @@ void test_ble_bas_battery_level_update_success(void) bas_init(&bas_cfg); /* Battery level hasn't changed 'Nothing to do' */ - ret = ble_bas_battery_level_update(&ble_bas, conn_handle, battery_level); - TEST_ASSERT_EQUAL(0, ret); + nrf_err = ble_bas_battery_level_update(&ble_bas, conn_handle, battery_level); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); /* Change battery level, and ble_bas should update but not notify */ battery_level = 42; __cmock_sd_ble_gatts_value_set_Stub(stub_sd_ble_gatts_value_set_check); - ret = ble_bas_battery_level_update(&ble_bas, conn_handle, battery_level); - TEST_ASSERT_EQUAL(0, ret); + nrf_err = ble_bas_battery_level_update(&ble_bas, conn_handle, battery_level); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); /* Change battery level, and ble_bas should update and notify */ battery_level = 84; bas_cfg.can_notify = true; bas_init(&bas_cfg); __cmock_sd_ble_gatts_hvx_Stub(stub_sd_ble_gatts_hvx_param_check); - ret = ble_bas_battery_level_update(&ble_bas, conn_handle, battery_level); - TEST_ASSERT_EQUAL(0, ret); + nrf_err = ble_bas_battery_level_update(&ble_bas, conn_handle, battery_level); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); TEST_ASSERT_EQUAL(1, hvx_stub_called); } -void test_ble_bas_battery_level_notify_efault(void) +void test_ble_bas_battery_level_notify_error_null(void) { - int ret; + uint32_t nrf_err; uint16_t conn_handle = 0x0001; - ret = ble_bas_battery_level_notify(NULL, conn_handle); - TEST_ASSERT_EQUAL(-EFAULT, ret); + nrf_err = ble_bas_battery_level_notify(NULL, conn_handle); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); } -void test_ble_bas_battery_level_notify_einval(void) +void test_ble_bas_battery_level_notify_error_invalid_param(void) { - int ret; + uint32_t nrf_err; uint16_t conn_handle = 0x0001; struct ble_bas_config bas_cfg = bas_cfg_template; bas_cfg.can_notify = false; bas_init(&bas_cfg); - ret = ble_bas_battery_level_notify(&ble_bas, conn_handle); - TEST_ASSERT_EQUAL(-EINVAL, ret); + nrf_err = ble_bas_battery_level_notify(&ble_bas, conn_handle); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, nrf_err); bas_cfg.can_notify = true; bas_init(&bas_cfg); __cmock_sd_ble_gatts_hvx_ExpectAnyArgsAndReturn(NRF_ERROR_TIMEOUT); - ret = ble_bas_battery_level_notify(&ble_bas, conn_handle); - TEST_ASSERT_EQUAL(-EINVAL, ret); + nrf_err = ble_bas_battery_level_notify(&ble_bas, conn_handle); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, nrf_err); } -void test_ble_bas_battery_level_notify_enotconn(void) +void test_ble_bas_battery_level_notify_error_not_found(void) { - int ret; + uint32_t nrf_err; uint16_t conn_handle = BLE_CONN_HANDLE_INVALID; struct ble_bas_config bas_cfg = bas_cfg_template; bas_init(&bas_cfg); __cmock_sd_ble_gatts_hvx_ExpectAnyArgsAndReturn(BLE_ERROR_INVALID_CONN_HANDLE); - ret = ble_bas_battery_level_notify(&ble_bas, conn_handle); - TEST_ASSERT_EQUAL(-ENOTCONN, ret); + nrf_err = ble_bas_battery_level_notify(&ble_bas, conn_handle); + TEST_ASSERT_EQUAL(NRF_ERROR_NOT_FOUND, nrf_err); } -void test_ble_bas_battery_level_notify_epipe(void) +void test_ble_bas_battery_level_notify_error_invalid_state(void) { - int ret; + uint32_t nrf_err; uint16_t conn_handle = 0x0001; struct ble_bas_config bas_cfg = bas_cfg_template; bas_init(&bas_cfg); __cmock_sd_ble_gatts_hvx_ExpectAnyArgsAndReturn(NRF_ERROR_INVALID_STATE); - ret = ble_bas_battery_level_notify(&ble_bas, conn_handle); - TEST_ASSERT_EQUAL(-EPIPE, ret); + nrf_err = ble_bas_battery_level_notify(&ble_bas, conn_handle); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_STATE, nrf_err); } void test_ble_bas_battery_level_notify_success(void) { - int ret; + uint32_t nrf_err; uint16_t conn_handle = 0x0001; struct ble_bas_config bas_cfg = bas_cfg_template; @@ -441,8 +441,8 @@ void test_ble_bas_battery_level_notify_success(void) __cmock_sd_ble_gatts_hvx_Stub(stub_sd_ble_gatts_hvx_param_check); - ret = ble_bas_battery_level_notify(&ble_bas, conn_handle); - TEST_ASSERT_EQUAL(0, ret); + nrf_err = ble_bas_battery_level_notify(&ble_bas, conn_handle); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); } void setUp(void) From f73aa13bd90d64c439546afb53a3906e76f49ed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20J=C3=B8lsgard?= Date: Wed, 22 Oct 2025 14:22:28 +0200 Subject: [PATCH 08/12] bluetooth: services: ble_dis: change error codes to nrf_error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change error codes to nrf_errors. Cleanup of ble_dis header. Signed-off-by: Eivind Jølsgard --- .../release_notes/release_notes_changelog.rst | 1 + include/bm/bluetooth/services/ble_dis.h | 181 +++++------------- samples/bluetooth/ble_cgms/src/main.c | 13 +- .../bluetooth/ble_hids_keyboard/src/main.c | 6 +- samples/bluetooth/ble_hids_mouse/src/main.c | 6 +- samples/bluetooth/ble_hrs/src/main.c | 6 +- samples/bluetooth/ble_lbs/src/main.c | 6 +- subsys/bluetooth/services/ble_dis/dis.c | 26 +-- .../services/ble_dis/src/unity_test.c | 18 +- 9 files changed, 90 insertions(+), 173 deletions(-) diff --git a/doc/nrf-bm/release_notes/release_notes_changelog.rst b/doc/nrf-bm/release_notes/release_notes_changelog.rst index 23424610df..e59ba9699e 100644 --- a/doc/nrf-bm/release_notes/release_notes_changelog.rst +++ b/doc/nrf-bm/release_notes/release_notes_changelog.rst @@ -83,6 +83,7 @@ Libraries * :ref:`lib_ble_gatt_queue` library. * :ref:`lib_ble_queued_writes` library. * :ref:`lib_ble_service_bas` service. + * :ref:`lib_ble_service_dis` service. * BLE Record Access Control Point library. * :ref:`lib_ble_conn_params` library: diff --git a/include/bm/bluetooth/services/ble_dis.h b/include/bm/bluetooth/services/ble_dis.h index 69d15328ee..d196f45905 100644 --- a/include/bm/bluetooth/services/ble_dis.h +++ b/include/bm/bluetooth/services/ble_dis.h @@ -1,133 +1,48 @@ -/** - * Copyright (c) 2012 - 2021, Nordic Semiconductor ASA - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form, except as embedded into a Nordic - * Semiconductor ASA integrated circuit in a product or a software update for - * such product, must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * 4. This software, with or without modification, must only be used with a - * Nordic Semiconductor ASA integrated circuit. - * - * 5. Any software provided in binary form under this license must not be reverse - * engineered, decompiled, modified and/or disassembled. - * - * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ -/** @file - * - * @defgroup ble_dis Device Information Service - * @{ - * @ingroup ble_sdk_srv - * @brief Device Information Service module. - * - * @details This module implements the Device Information Service. - * During initialization it adds the Device Information Service to the BLE stack database. - * It then encodes the supplied information, and adds the corresponding characteristics. - * - * @note Attention! - * To maintain compliance with Nordic Semiconductor ASA Bluetooth profile - * qualification listings, this section of source code must not be modified. - */ - -#ifndef BLE_DIS_H__ -#define BLE_DIS_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** @defgroup DIS_VENDOR_ID_SRC_VALUES Vendor ID Source values - * @{ - */ -#define BLE_DIS_VENDOR_ID_SRC_BLUETOOTH_SIG 1 /**< Vendor ID assigned by Bluetooth SIG. */ -#define BLE_DIS_VENDOR_ID_SRC_USB_IMPL_FORUM 2 /**< Vendor ID assigned by USB Implementer's Forum. */ -/** @} */ - -/**@brief System ID parameters */ -typedef struct -{ - uint64_t manufacturer_id; /**< Manufacturer ID. Only 5 LSOs shall be used. */ - uint32_t organizationally_unique_id; /**< Organizationally unique ID. Only 3 LSOs shall be used. */ -} ble_dis_sys_id_t; - -/**@brief IEEE 11073-20601 Regulatory Certification Data List Structure */ -typedef struct -{ - uint8_t * p_list; /**< Pointer the byte array containing the encoded opaque structure based on IEEE 11073-20601 specification. */ - uint8_t list_len; /**< Length of the byte array. */ -} ble_dis_reg_cert_data_list_t; - -/**@brief PnP ID parameters */ -typedef struct -{ - uint8_t vendor_id_source; /**< Vendor ID Source. see @ref DIS_VENDOR_ID_SRC_VALUES. */ - uint16_t vendor_id; /**< Vendor ID. */ - uint16_t product_id; /**< Product ID. */ - uint16_t product_version; /**< Product Version. */ -} ble_dis_pnp_id_t; - -/**@brief Device Information Service init structure. This contains all possible characteristics - * needed for initialization of the service. - */ - #if 0 -typedef struct -{ - ble_srv_utf8_str_t manufact_name_str; /**< Manufacturer Name String. */ - ble_srv_utf8_str_t model_num_str; /**< Model Number String. */ - ble_srv_utf8_str_t serial_num_str; /**< Serial Number String. */ - ble_srv_utf8_str_t hw_rev_str; /**< Hardware Revision String. */ - ble_srv_utf8_str_t fw_rev_str; /**< Firmware Revision String. */ - ble_srv_utf8_str_t sw_rev_str; /**< Software Revision String. */ - ble_dis_sys_id_t * p_sys_id; /**< System ID. */ - ble_dis_reg_cert_data_list_t * p_reg_cert_data_list; /**< IEEE 11073-20601 Regulatory Certification Data List. */ - ble_dis_pnp_id_t * p_pnp_id; /**< PnP ID. */ - security_req_t dis_char_rd_sec; /**< Security requirement for reading any DIS characteristic value. */ -} ble_dis_init_t; -#endif -/**@brief Function for initializing the Device Information Service. - * - * @details This call allows the application to initialize the device information service. - * It adds the DIS service and DIS characteristics to the database, using the initial - * values supplied through the p_dis_init parameter. Characteristics which are not to be - * added, shall be set to NULL in p_dis_init. - * - * @param[in] p_dis_init The structure containing the values of characteristics needed by the - * service. - * - * @return NRF_SUCCESS on successful initialization of service. - */ -int ble_dis_init(void); - -#ifdef __cplusplus -} -#endif - -#endif // BLE_DIS_H__ - -/** @} */ +/* + * Copyright (c) 2012 - 2025 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ +/** @file + * + * @defgroup ble_dis Device Information Service + * + * @brief Device Information Service module. + * + * @details This module implements the Device Information Service. + * During initialization it adds the Device Information Service to the BLE stack database. + * It then encodes the supplied information, and adds the corresponding characteristics. + * + * @note Attention! + * To maintain compliance with Nordic Semiconductor ASA Bluetooth profile + * qualification listings, this section of source code must not be modified. + */ + +#ifndef BLE_DIS_H__ +#define BLE_DIS_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Function for initializing the Device Information Service. + * + * @details This call allows the application to initialize the device information service. + * It adds the DIS service and DIS characteristics to the database, using the initial + * values supplied through the p_dis_init parameter. Characteristics which are not to be + * added, shall be set to NULL in p_dis_init. + * + * @return NRF_SUCCESS on successful initialization of service or nrf_error on failure. + */ +uint32_t ble_dis_init(void); + +#ifdef __cplusplus +} +#endif + +#endif /* BLE_DIS_H__ */ + +/** @} */ diff --git a/samples/bluetooth/ble_cgms/src/main.c b/samples/bluetooth/ble_cgms/src/main.c index e5a5e07289..2e7060856c 100644 --- a/samples/bluetooth/ble_cgms/src/main.c +++ b/samples/bluetooth/ble_cgms/src/main.c @@ -298,7 +298,6 @@ uint16_t qwr_evt_handler(struct ble_qwr *qwr, const struct ble_qwr_evt *evt) */ static uint32_t services_init(void) { - int err; uint32_t nrf_err; struct ble_cgms_config cgms_config = { .evt_handler = cgms_evt_handler, @@ -357,10 +356,10 @@ static uint32_t services_init(void) } /* Initialize Device Information Service. */ - err = ble_dis_init(); - if (err) { - LOG_ERR("Failed to initialize DIS service, err %d", err); - return err; + nrf_err = ble_dis_init(); + if (nrf_err) { + LOG_ERR("Failed to initialize DIS service, nrf_error %#x", nrf_err); + return nrf_err; } return NRF_SUCCESS; @@ -737,8 +736,8 @@ int main(void) if (nrf_err) { goto idle; } - err = services_init(); - if (err) { + nrf_err = services_init(); + if (nrf_err) { goto idle; } (void)sensor_simulator_init(); diff --git a/samples/bluetooth/ble_hids_keyboard/src/main.c b/samples/bluetooth/ble_hids_keyboard/src/main.c index d36fbcb185..61b578d934 100644 --- a/samples/bluetooth/ble_hids_keyboard/src/main.c +++ b/samples/bluetooth/ble_hids_keyboard/src/main.c @@ -956,9 +956,9 @@ int main(void) goto idle; } - err = ble_dis_init(); - if (err) { - LOG_ERR("Failed to initialize device information service, err %d", err); + nrf_err = ble_dis_init(); + if (nrf_err) { + LOG_ERR("Failed to initialize device information service, nrf_error %#x", nrf_err); goto idle; } diff --git a/samples/bluetooth/ble_hids_mouse/src/main.c b/samples/bluetooth/ble_hids_mouse/src/main.c index 384f52a67e..750b75bc54 100644 --- a/samples/bluetooth/ble_hids_mouse/src/main.c +++ b/samples/bluetooth/ble_hids_mouse/src/main.c @@ -805,9 +805,9 @@ int main(void) goto idle; } - err = ble_dis_init(); - if (err) { - LOG_ERR("Failed to initialize device information service, err %d", err); + nrf_err = ble_dis_init(); + if (nrf_err) { + LOG_ERR("Failed to initialize device information service, nrf_error %#x", nrf_err); goto idle; } diff --git a/samples/bluetooth/ble_hrs/src/main.c b/samples/bluetooth/ble_hrs/src/main.c index 567f4a1bcc..b942f84fce 100644 --- a/samples/bluetooth/ble_hrs/src/main.c +++ b/samples/bluetooth/ble_hrs/src/main.c @@ -516,9 +516,9 @@ int main(void) goto idle; } - err = ble_dis_init(); - if (err) { - LOG_ERR("Failed to initialize device information service, err %d", err); + nrf_err = ble_dis_init(); + if (nrf_err) { + LOG_ERR("Failed to initialize device information service, nrf_error %#x", nrf_err); goto idle; } diff --git a/samples/bluetooth/ble_lbs/src/main.c b/samples/bluetooth/ble_lbs/src/main.c index d9c0992af5..8fab62a051 100644 --- a/samples/bluetooth/ble_lbs/src/main.c +++ b/samples/bluetooth/ble_lbs/src/main.c @@ -187,9 +187,9 @@ int main(void) goto idle; } - err = ble_dis_init(); - if (err) { - LOG_ERR("Failed to initialize device information service, err %d", err); + nrf_err = ble_dis_init(); + if (nrf_err) { + LOG_ERR("Failed to initialize device information service, nrf_error %#x", nrf_err); goto idle; } diff --git a/subsys/bluetooth/services/ble_dis/dis.c b/subsys/bluetooth/services/ble_dis/dis.c index 32076dd9ce..1c775f16ba 100644 --- a/subsys/bluetooth/services/ble_dis/dis.c +++ b/subsys/bluetooth/services/ble_dis/dis.c @@ -4,6 +4,8 @@ * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ +#include +#include #include #include #include @@ -56,9 +58,9 @@ static const uint8_t regulatory_certifications[IEEE_CERT_LEN] = LOG_MODULE_REGISTER(ble_dis, CONFIG_BLE_DIS_LOG_LEVEL); -int ble_dis_init(void) +uint32_t ble_dis_init(void) { - int err; + uint32_t nrf_err; uint16_t service_handle; ble_uuid_t ble_uuid; ble_gatts_char_handles_t char_handles = {0}; @@ -102,10 +104,10 @@ int ble_dis_init(void) /* Add service */ BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_DEVICE_INFORMATION_SERVICE); - err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &service_handle); - if (err) { - LOG_ERR("Failed to add device information service, nrf_error %#x", err); - return -EINVAL; + nrf_err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &service_handle); + if (nrf_err) { + LOG_ERR("Failed to add device information service, nrf_error %#x", nrf_err); + return nrf_err; } for (size_t i = 0; i < ARRAY_SIZE(chars); i++) { @@ -121,13 +123,13 @@ int ble_dis_init(void) LOG_DBG("Added char %#x, len %d", chars[i].uuid, chars[i].len); - err = sd_ble_gatts_characteristic_add(service_handle, &char_md, - &attr_char_value, &char_handles); - if (err) { - LOG_ERR("Failed to add characteristic, nrf_error %#x", err); - return -EINVAL; + nrf_err = sd_ble_gatts_characteristic_add(service_handle, &char_md, + &attr_char_value, &char_handles); + if (nrf_err) { + LOG_ERR("Failed to add characteristic, nrf_error %#x", nrf_err); + return nrf_err; } } - return 0; + return NRF_SUCCESS; } diff --git a/tests/subsys/bluetooth/services/ble_dis/src/unity_test.c b/tests/subsys/bluetooth/services/ble_dis/src/unity_test.c index 6d8ca52f19..366ab4f071 100644 --- a/tests/subsys/bluetooth/services/ble_dis/src/unity_test.c +++ b/tests/subsys/bluetooth/services/ble_dis/src/unity_test.c @@ -148,32 +148,32 @@ uint32_t stub_sd_ble_gatts_characteristic_add( return NRF_SUCCESS; } -void test_ble_dis_init_einval(void) +void test_ble_dis_init_error_invalid_param(void) { - int err; + uint32_t nrf_err; __cmock_sd_ble_gatts_service_add_Stub(stub_sd_ble_gatts_service_add_invalid_param); - err = ble_dis_init(); - TEST_ASSERT_EQUAL(-EINVAL, err); + nrf_err = ble_dis_init(); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, nrf_err); __cmock_sd_ble_gatts_service_add_Stub(stub_sd_ble_gatts_service_add); __cmock_sd_ble_gatts_characteristic_add_Stub( stub_sd_ble_gatts_characteristic_add_invalid_param); - err = ble_dis_init(); - TEST_ASSERT_EQUAL(-EINVAL, err); + nrf_err = ble_dis_init(); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, nrf_err); } void test_ble_dis_init(void) { - int err; + uint32_t nrf_err; __cmock_sd_ble_gatts_service_add_Stub(stub_sd_ble_gatts_service_add); __cmock_sd_ble_gatts_characteristic_add_Stub(stub_sd_ble_gatts_characteristic_add); - err = ble_dis_init(); - TEST_ASSERT_EQUAL(NRF_SUCCESS, err); + nrf_err = ble_dis_init(); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); } extern int unity_main(void); From 1a316c2044e46cba860743d106d3a3574ed381d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20J=C3=B8lsgard?= Date: Wed, 22 Oct 2025 14:32:10 +0200 Subject: [PATCH 09/12] bluetooth: services: ble_hrs: change error codes to nrf_error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change error codes to nrf_errors. Signed-off-by: Eivind Jølsgard --- .../release_notes/release_notes_changelog.rst | 1 + include/bm/bluetooth/services/ble_hrs.h | 50 +++++----- samples/bluetooth/ble_hrs/src/main.c | 30 +++--- subsys/bluetooth/services/ble_hrs/hrs.c | 97 ++++++++++--------- 4 files changed, 94 insertions(+), 84 deletions(-) diff --git a/doc/nrf-bm/release_notes/release_notes_changelog.rst b/doc/nrf-bm/release_notes/release_notes_changelog.rst index e59ba9699e..47126a1144 100644 --- a/doc/nrf-bm/release_notes/release_notes_changelog.rst +++ b/doc/nrf-bm/release_notes/release_notes_changelog.rst @@ -84,6 +84,7 @@ Libraries * :ref:`lib_ble_queued_writes` library. * :ref:`lib_ble_service_bas` service. * :ref:`lib_ble_service_dis` service. + * :ref:`lib_ble_service_hrs` service. * BLE Record Access Control Point library. * :ref:`lib_ble_conn_params` library: diff --git a/include/bm/bluetooth/services/ble_hrs.h b/include/bm/bluetooth/services/ble_hrs.h index 99d28e74f9..060bff31d0 100644 --- a/include/bm/bluetooth/services/ble_hrs.h +++ b/include/bm/bluetooth/services/ble_hrs.h @@ -161,11 +161,11 @@ struct ble_hrs { * @param hrs Heart rate service. * @param hrs_config Heart rate service configuration. * - * @retval 0 On success. - * @retval -EFAULT If @p hrs or @p hrs_config are @c NULL. - * @retval -EINVAL Invalid parameters. + * @retval NRF_SUCCESS On success. + * @retval NRF_ERROR_NULL If @p hrs or @p hrs_config are @c NULL. + * @retval NRF_ERROR_INVALID_PARAM Invalid parameters. */ -int ble_hrs_init(struct ble_hrs *hrs, const struct ble_hrs_config *hrs_config); +uint32_t ble_hrs_init(struct ble_hrs *hrs, const struct ble_hrs_config *hrs_config); /** * @brief Connection parameters event handler. @@ -187,13 +187,13 @@ void ble_hrs_conn_params_evt(struct ble_hrs *hrs, const struct ble_conn_params_e * @param hrs Heart rate service. * @param heart_rate heart rate Measurement. * - * @retval 0 On success. - * @retval -EFAULT If @p hrs is @c NULL. - * @retval -EINVAL Failed to send notification. - * @retval -ENOTCONN Invalid connection handle. - * @retval -EPIPE Notifications not enabled in the CCCD. + * @retval NRF_SUCCESS On success. + * @retval NRF_ERROR_NULL If @p hrs is @c NULL. + * @retval NRF_ERROR_INVALID_PARAM Failed to send notification. + * @retval NRF_ERROR_NOT_FOUND Invalid connection handle. + * @retval NRF_ERROR_INVALID_STATE Notifications not enabled in the CCCD. */ -int ble_hrs_heart_rate_measurement_send(struct ble_hrs *hrs, uint16_t heart_rate); +uint32_t ble_hrs_heart_rate_measurement_send(struct ble_hrs *hrs, uint16_t heart_rate); /** * @brief Function for adding a RR Interval measurement to the RR Interval buffer. @@ -205,10 +205,10 @@ int ble_hrs_heart_rate_measurement_send(struct ble_hrs *hrs, uint16_t heart_rate * @param hrs Heart rate service. * @param rr_interval New RR interval measurement. * - * @retval 0 On success. - * @retval -EFAULT If @p hrs is @c NULL. + * @retval NRF_SUCCESS On success. + * @retval NRF_ERROR_NULL If @p hrs is @c NULL. */ -int ble_hrs_rr_interval_add(struct ble_hrs *hrs, uint16_t rr_interval); +uint32_t ble_hrs_rr_interval_add(struct ble_hrs *hrs, uint16_t rr_interval); /** * @brief Function for checking if RR Interval buffer is full. @@ -227,11 +227,12 @@ bool ble_hrs_rr_interval_buffer_is_full(struct ble_hrs *hrs); * @param hrs Heart rate service. * @param is_sensor_contact_supported New state of the sensor contact support bit. * - * @retval 0 On success. - * @retval -EFAULT If @p hrs is @c NULL. - * @retval -EISCONN If in a connection. + * @retval NRF_SUCCESS On success. + * @retval NRF_ERROR_NULL If @p hrs is @c NULL. + * @retval NRF_ERROR_INVALID_STATE If in a connection. */ -int ble_hrs_sensor_contact_supported_set(struct ble_hrs *hrs, bool is_sensor_contact_supported); +uint32_t ble_hrs_sensor_contact_supported_set(struct ble_hrs *hrs, + bool is_sensor_contact_supported); /** * @brief Function for setting the state of the sensor contact detected bit. @@ -239,10 +240,11 @@ int ble_hrs_sensor_contact_supported_set(struct ble_hrs *hrs, bool is_sensor_con * @param hrs Heart rate service. * @param is_sensor_contact_detected New state of the sensor contact detected bit. * - * @retval 0 On success. - * @retval -EFAULT If @p hrs is @c NULL. + * @retval NRF_SUCCESS On success. + * @retval NRF_ERROR_NULL If @p hrs is @c NULL. */ -int ble_hrs_sensor_contact_detected_update(struct ble_hrs *hrs, bool is_sensor_contact_detected); +uint32_t ble_hrs_sensor_contact_detected_update(struct ble_hrs *hrs, + bool is_sensor_contact_detected); /** * @brief Function for setting the Body Sensor Location. @@ -253,11 +255,11 @@ int ble_hrs_sensor_contact_detected_update(struct ble_hrs *hrs, bool is_sensor_c * @param hrs Heart rate service. * @param body_sensor_location New body sensor location. * - * @retval 0 On success. - * @retval -EFAULT If @p hrs is @c NULL. - * @retval -EINVAL Failed to set new value. + * @retval NRF_SUCCESS On success. + * @retval NRF_ERROR_NULL If @p hrs is @c NULL. + * @retval NRF_ERROR_INVALID_PARAM Failed to set new value. */ -int ble_hrs_body_sensor_location_set(struct ble_hrs *hrs, uint8_t body_sensor_location); +uint32_t ble_hrs_body_sensor_location_set(struct ble_hrs *hrs, uint8_t body_sensor_location); #ifdef __cplusplus } diff --git a/samples/bluetooth/ble_hrs/src/main.c b/samples/bluetooth/ble_hrs/src/main.c index b942f84fce..31c705dbaf 100644 --- a/samples/bluetooth/ble_hrs/src/main.c +++ b/samples/bluetooth/ble_hrs/src/main.c @@ -95,6 +95,7 @@ static void heart_rate_meas_timeout_handler(void *context) { static uint32_t cnt; int err; + uint32_t nrf_err; uint32_t heart_rate; ARG_UNUSED(context); @@ -105,11 +106,11 @@ static void heart_rate_meas_timeout_handler(void *context) return; } - err = ble_hrs_heart_rate_measurement_send(&ble_hrs, (uint16_t)heart_rate); - if (err) { + nrf_err = ble_hrs_heart_rate_measurement_send(&ble_hrs, (uint16_t)heart_rate); + if (nrf_err) { /* Ignore if not in a connection or notifications disabled in CCCD. */ - if (err != -ENOTCONN && err != -EPIPE) { - LOG_ERR("Failed to update heart rate measurement, err %d", err); + if (nrf_err != NRF_ERROR_NOT_FOUND && nrf_err != NRF_ERROR_INVALID_STATE) { + LOG_ERR("Failed to update heart rate measurement, nrf_error %#x", nrf_err); } } @@ -123,6 +124,7 @@ static void heart_rate_meas_timeout_handler(void *context) static void rr_interval_timeout_handler(void *context) { int err; + uint32_t nrf_err; uint32_t rr_interval; ARG_UNUSED(context); @@ -138,9 +140,9 @@ static void rr_interval_timeout_handler(void *context) break; } - err = ble_hrs_rr_interval_add(&ble_hrs, (uint16_t)rr_interval); - if (err) { - LOG_ERR("Failed to add RR interval, err %d", err); + nrf_err = ble_hrs_rr_interval_add(&ble_hrs, (uint16_t)rr_interval); + if (nrf_err) { + LOG_ERR("Failed to add RR interval, nrf_error %#x", nrf_err); } } } @@ -148,14 +150,14 @@ static void rr_interval_timeout_handler(void *context) static void sensor_contact_detected_timeout_handler(void *context) { static bool sim_sensor_contact_detected; - int err; + uint32_t nrf_err; ARG_UNUSED(context); sim_sensor_contact_detected = !sim_sensor_contact_detected; - err = ble_hrs_sensor_contact_detected_update(&ble_hrs, sim_sensor_contact_detected); - if (err) { - LOG_ERR("Failed to update sensor contact detected state, err %d", err); + nrf_err = ble_hrs_sensor_contact_detected_update(&ble_hrs, sim_sensor_contact_detected); + if (nrf_err) { + LOG_ERR("Failed to update sensor contact detected state, nrf_error %#x", nrf_err); } } @@ -504,9 +506,9 @@ int main(void) LOG_INF("Peer Manager initialized"); - err = ble_hrs_init(&ble_hrs, &hrs_cfg); - if (err) { - LOG_ERR("Failed to initialize heart rate service, err %d", err); + nrf_err = ble_hrs_init(&ble_hrs, &hrs_cfg); + if (nrf_err) { + LOG_ERR("Failed to initialize heart rate service, nrf_error %#x", nrf_err); goto idle; } diff --git a/subsys/bluetooth/services/ble_hrs/hrs.c b/subsys/bluetooth/services/ble_hrs/hrs.c index 05bb0fac3e..43b74a2733 100644 --- a/subsys/bluetooth/services/ble_hrs/hrs.c +++ b/subsys/bluetooth/services/ble_hrs/hrs.c @@ -4,6 +4,7 @@ * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ +#include #include #include #include @@ -211,13 +212,13 @@ void ble_hrs_on_ble_evt(const ble_evt_t *ble_evt, void *hrs_instance) } } -int ble_hrs_init(struct ble_hrs *hrs, const struct ble_hrs_config *cfg) +uint32_t ble_hrs_init(struct ble_hrs *hrs, const struct ble_hrs_config *cfg) { - int err; + uint32_t nrf_err; ble_uuid_t ble_uuid; if (hrs == NULL || cfg == NULL) { - return -EFAULT; + return NRF_ERROR_NULL; } /* Initialize service structure. */ @@ -231,39 +232,41 @@ int ble_hrs_init(struct ble_hrs *hrs, const struct ble_hrs_config *cfg) BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_HEART_RATE_SERVICE); /* Add Heart rate service declaration. */ - err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, - &hrs->service_handle); - if (err) { - LOG_ERR("Failed to add heart rate service, nrf_error %#x", err); - return -EINVAL; + nrf_err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, + &hrs->service_handle); + if (nrf_err) { + LOG_ERR("Failed to add heart rate service, nrf_error %#x", nrf_err); + return NRF_ERROR_INVALID_PARAM; } /* Add Heart rate measurement characteristic. */ - err = heart_rate_measurement_char_add(hrs, cfg); - if (err) { - LOG_ERR("Failed to add heart rate measurement characteristic, nrf_error %#x", err); - return -EINVAL; + nrf_err = heart_rate_measurement_char_add(hrs, cfg); + if (nrf_err) { + LOG_ERR("Failed to add heart rate measurement characteristic, nrf_error %#x", + nrf_err); + return NRF_ERROR_INVALID_PARAM; } /* Add Body sensor location characteristic. */ - err = body_sensor_location_char_add(hrs, cfg); - if (err) { - LOG_ERR("Failed to add body sensor location characteristic, nrf_error %#x", err); - return -EINVAL; + nrf_err = body_sensor_location_char_add(hrs, cfg); + if (nrf_err) { + LOG_ERR("Failed to add body sensor location characteristic, nrf_error %#x", + nrf_err); + return NRF_ERROR_INVALID_PARAM; } - return 0; + return NRF_SUCCESS; } -int ble_hrs_heart_rate_measurement_send(struct ble_hrs *hrs, uint16_t heart_rate) +uint32_t ble_hrs_heart_rate_measurement_send(struct ble_hrs *hrs, uint16_t heart_rate) { - int err; + uint32_t nrf_err; uint8_t encoded_hrm[MAX_HRM_LEN_CALC(CONFIG_NRF_SDH_BLE_GATT_MAX_MTU_SIZE)]; uint16_t len; uint16_t hvx_len; if (!hrs) { - return -EFAULT; + return NRF_ERROR_NULL; } LOG_INF("Heart rate: %d bpm", heart_rate); @@ -281,29 +284,29 @@ int ble_hrs_heart_rate_measurement_send(struct ble_hrs *hrs, uint16_t heart_rate .p_data = encoded_hrm, }; - err = sd_ble_gatts_hvx(hrs->conn_handle, &hvx); - switch (err) { + nrf_err = sd_ble_gatts_hvx(hrs->conn_handle, &hvx); + switch (nrf_err) { case NRF_SUCCESS: if (hvx_len != len) { LOG_ERR("Notified %d of %d bytes", hvx_len, len); - return -EINVAL; + return NRF_ERROR_INVALID_PARAM; } - return 0; + return NRF_SUCCESS; case BLE_ERROR_INVALID_CONN_HANDLE: - return -ENOTCONN; + return NRF_ERROR_NOT_FOUND; case NRF_ERROR_INVALID_STATE: case BLE_ERROR_GATTS_SYS_ATTR_MISSING: - return -EPIPE; + return NRF_ERROR_INVALID_STATE; default: - LOG_ERR("Failed to notify heart rate measurement, nrf_error %#x", err); - return -EINVAL; + LOG_ERR("Failed to notify heart rate measurement, nrf_error %#x", nrf_err); + return NRF_ERROR_INVALID_PARAM; } } -int ble_hrs_rr_interval_add(struct ble_hrs *hrs, uint16_t rr_interval) +uint32_t ble_hrs_rr_interval_add(struct ble_hrs *hrs, uint16_t rr_interval) { if (!hrs) { - return -EFAULT; + return NRF_ERROR_NULL; } if (hrs->rr_interval_count == CONFIG_BLE_HRS_MAX_BUFFERED_RR_INTERVALS) { @@ -313,7 +316,7 @@ int ble_hrs_rr_interval_add(struct ble_hrs *hrs, uint16_t rr_interval) } hrs->rr_interval[hrs->rr_interval_count++] = rr_interval; - return 0; + return NRF_SUCCESS; } bool ble_hrs_rr_interval_buffer_is_full(struct ble_hrs *hrs) @@ -323,34 +326,35 @@ bool ble_hrs_rr_interval_buffer_is_full(struct ble_hrs *hrs) return (hrs->rr_interval_count == CONFIG_BLE_HRS_MAX_BUFFERED_RR_INTERVALS); } -int ble_hrs_sensor_contact_supported_set(struct ble_hrs *hrs, bool is_sensor_contact_supported) +uint32_t ble_hrs_sensor_contact_supported_set(struct ble_hrs *hrs, bool is_sensor_contact_supported) { if (!hrs) { - return -EFAULT; + return NRF_ERROR_NULL; } /* Check if we are connected to peer. */ if (hrs->conn_handle != BLE_CONN_HANDLE_INVALID) { - return -EISCONN; + return NRF_ERROR_INVALID_STATE; } hrs->is_sensor_contact_supported = is_sensor_contact_supported; - return 0; + return NRF_SUCCESS; } -int ble_hrs_sensor_contact_detected_update(struct ble_hrs *hrs, bool is_sensor_contact_detected) +uint32_t ble_hrs_sensor_contact_detected_update(struct ble_hrs *hrs, + bool is_sensor_contact_detected) { if (!hrs) { - return -EFAULT; + return NRF_ERROR_NULL; } hrs->is_sensor_contact_detected = is_sensor_contact_detected; - return 0; + return NRF_SUCCESS; } -int ble_hrs_body_sensor_location_set(struct ble_hrs *hrs, uint8_t body_sensor_location) +uint32_t ble_hrs_body_sensor_location_set(struct ble_hrs *hrs, uint8_t body_sensor_location) { - int err; + uint32_t nrf_err; ble_gatts_value_t gatts_value = { .len = sizeof(uint8_t), .offset = 0, @@ -358,16 +362,17 @@ int ble_hrs_body_sensor_location_set(struct ble_hrs *hrs, uint8_t body_sensor_lo }; if (!hrs) { - return -EFAULT; + return NRF_ERROR_NULL; } - err = sd_ble_gatts_value_set(hrs->conn_handle, hrs->bsl_handles.value_handle, &gatts_value); - if (err) { - LOG_ERR("Failed to update body sensor location, nrf_error %#x", err); - return -EINVAL; + nrf_err = sd_ble_gatts_value_set(hrs->conn_handle, hrs->bsl_handles.value_handle, + &gatts_value); + if (nrf_err) { + LOG_ERR("Failed to update body sensor location, nrf_error %#x", nrf_err); + return NRF_ERROR_INVALID_PARAM; } - return 0; + return NRF_SUCCESS; } void ble_hrs_conn_params_evt(struct ble_hrs *hrs, const struct ble_conn_params_evt *conn_params_evt) From f1014cc7436e35f3441d1aac833d27c4eb8ac693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20J=C3=B8lsgard?= Date: Wed, 22 Oct 2025 15:17:17 +0200 Subject: [PATCH 10/12] bluetooth: services: ble_lbs: change error codes to nrf_error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change error codes to nrf_errors. Signed-off-by: Eivind Jølsgard --- .../release_notes/release_notes_changelog.rst | 1 + include/bm/bluetooth/services/ble_lbs.h | 12 ++++-- samples/bluetooth/ble_lbs/src/main.c | 6 +-- subsys/bluetooth/services/ble_lbs/lbs.c | 37 ++++++++++--------- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/doc/nrf-bm/release_notes/release_notes_changelog.rst b/doc/nrf-bm/release_notes/release_notes_changelog.rst index 47126a1144..0a66e65a48 100644 --- a/doc/nrf-bm/release_notes/release_notes_changelog.rst +++ b/doc/nrf-bm/release_notes/release_notes_changelog.rst @@ -85,6 +85,7 @@ Libraries * :ref:`lib_ble_service_bas` service. * :ref:`lib_ble_service_dis` service. * :ref:`lib_ble_service_hrs` service. + * :ref:`lib_ble_service_lbs` service. * BLE Record Access Control Point library. * :ref:`lib_ble_conn_params` library: diff --git a/include/bm/bluetooth/services/ble_lbs.h b/include/bm/bluetooth/services/ble_lbs.h index 6b2ce77db7..2318477151 100644 --- a/include/bm/bluetooth/services/ble_lbs.h +++ b/include/bm/bluetooth/services/ble_lbs.h @@ -94,9 +94,11 @@ struct ble_lbs { * be used to identify this particular service instance. * @param[in] cfg Information needed to initialize the service. * - * @retval 0 If the service was initialized successfully. Otherwise, an error code is returned. + * @retval NRF_SUCCESS If the service was initialized successfully. + * @retval NRF_ERROR_NULL If @p lbs or @p cfg is NULL. + * @retval NRF_ERROR_INVALID_PARAM If the supplied configuration is invalid. */ -int ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg); +uint32_t ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg); /** * @brief Function for handling the application's BLE stack events. @@ -117,9 +119,11 @@ void ble_lbs_on_ble_evt(const ble_evt_t *ble_evt, void *lbs_instance); * @param[in] lbs LED Button Service structure. * @param[in] button_state New button state. * - * @retval 0 If the notification was sent successfully. Otherwise, an error code is returned. + * @retval NRF_SUCCESS If the notification was sent successfully. + * @retval NRF_ERROR_NULL If @p lbs is NULL. + * @retval NRF_ERROR_INVALID_PARAM If the parameters are invalid. */ -int ble_lbs_on_button_change(struct ble_lbs *lbs, uint16_t conn_handle, uint8_t button_state); +uint32_t ble_lbs_on_button_change(struct ble_lbs *lbs, uint16_t conn_handle, uint8_t button_state); #ifdef __cplusplus } diff --git a/samples/bluetooth/ble_lbs/src/main.c b/samples/bluetooth/ble_lbs/src/main.c index 8fab62a051..b37bf79701 100644 --- a/samples/bluetooth/ble_lbs/src/main.c +++ b/samples/bluetooth/ble_lbs/src/main.c @@ -181,9 +181,9 @@ int main(void) goto idle; } - err = ble_lbs_init(&ble_lbs, &lbs_cfg); - if (err) { - LOG_ERR("Failed to setup LED Button Service, err %d", err); + nrf_err = ble_lbs_init(&ble_lbs, &lbs_cfg); + if (nrf_err) { + LOG_ERR("Failed to setup LED Button Service, nrf_error %#x", nrf_err); goto idle; } diff --git a/subsys/bluetooth/services/ble_lbs/lbs.c b/subsys/bluetooth/services/ble_lbs/lbs.c index 71ff2dc584..6f7f14a177 100644 --- a/subsys/bluetooth/services/ble_lbs/lbs.c +++ b/subsys/bluetooth/services/ble_lbs/lbs.c @@ -4,6 +4,7 @@ * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ +#include #include #include #include @@ -50,14 +51,14 @@ void ble_lbs_on_ble_evt(const ble_evt_t *ble_evt, void *lbs_instance) } } -int ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg) +uint32_t ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg) { uint32_t nrf_err; ble_uuid_t ble_uuid; uint8_t initial_value = 0; if (!lbs || !cfg) { - return -EFAULT; + return NRF_ERROR_NULL; } /* Initialize service structure. */ @@ -68,7 +69,7 @@ int ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg) nrf_err = sd_ble_uuid_vs_add(&base_uuid, &lbs->uuid_type); if (nrf_err) { LOG_ERR("Failed to add vendor UUID, nrf_error %#x", nrf_err); - return -EINVAL; + return NRF_ERROR_INVALID_PARAM; } ble_uuid = (ble_uuid_t) { @@ -78,10 +79,10 @@ int ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg) /* Add service. */ nrf_err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, - &lbs->service_handle); + &lbs->service_handle); if (nrf_err) { LOG_ERR("Failed to add GATT service, nrf_error %#x", nrf_err); - return -EINVAL; + return NRF_ERROR_INVALID_PARAM; } /* Add Button characteristic. */ @@ -114,10 +115,10 @@ int ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg) BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm); nrf_err = sd_ble_gatts_characteristic_add(lbs->service_handle, &char_md, &attr_char_value, - &lbs->button_char_handles); + &lbs->button_char_handles); if (nrf_err) { LOG_ERR("Failed to add button GATT characteristic, nrf_error %#x", nrf_err); - return -EINVAL; + return NRF_ERROR_INVALID_PARAM; } /* Add LED characteristic. */ @@ -146,23 +147,23 @@ int ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg) BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm); nrf_err = sd_ble_gatts_characteristic_add(lbs->service_handle, &char_md, &attr_char_value, - &lbs->led_char_handles); + &lbs->led_char_handles); if (nrf_err) { LOG_ERR("Failed to add LED GATT characteristic, nrf_error %#x", nrf_err); - return -EINVAL; + return NRF_ERROR_INVALID_PARAM; } - return 0; + return NRF_SUCCESS; } -int ble_lbs_on_button_change(struct ble_lbs *lbs, uint16_t conn_handle, uint8_t button_state) +uint32_t ble_lbs_on_button_change(struct ble_lbs *lbs, uint16_t conn_handle, uint8_t button_state) { - int err; + uint32_t nrf_err; uint16_t len = sizeof(button_state); if (!lbs) { - return -EFAULT; + return NRF_ERROR_NULL; } ble_gatts_hvx_params_t hvx = { @@ -172,11 +173,11 @@ int ble_lbs_on_button_change(struct ble_lbs *lbs, uint16_t conn_handle, uint8_t .p_len = &len, }; - err = sd_ble_gatts_hvx(conn_handle, &hvx); - if (err) { - LOG_ERR("Failed to notify button change, nrf_error %#x", err); - return -EINVAL; + nrf_err = sd_ble_gatts_hvx(conn_handle, &hvx); + if (nrf_err) { + LOG_ERR("Failed to notify button change, nrf_error %#x", nrf_err); + return NRF_ERROR_INVALID_PARAM; } - return 0; + return NRF_SUCCESS; } From ae26e01db3d10fd14addb789723841ec1540e316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20J=C3=B8lsgard?= Date: Wed, 22 Oct 2025 15:56:07 +0200 Subject: [PATCH 11/12] bluetooth: services: ble_mcumgr: change error codes to nrf_error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change error codes to nrf_errors. Signed-off-by: Eivind Jølsgard --- .../firmware_loader/ble_mcumgr/src/main.c | 6 +- .../release_notes/release_notes_changelog.rst | 1 + include/bm/bluetooth/services/ble_mcumgr.h | 6 +- .../boot/mcuboot_recovery_entry/src/main.c | 6 +- subsys/bluetooth/services/ble_mcumgr/mcumgr.c | 85 ++++++++++--------- 5 files changed, 53 insertions(+), 51 deletions(-) diff --git a/applications/firmware_loader/ble_mcumgr/src/main.c b/applications/firmware_loader/ble_mcumgr/src/main.c index 6dca3dc071..234ed3b7ff 100644 --- a/applications/firmware_loader/ble_mcumgr/src/main.c +++ b/applications/firmware_loader/ble_mcumgr/src/main.c @@ -211,10 +211,10 @@ 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; } diff --git a/doc/nrf-bm/release_notes/release_notes_changelog.rst b/doc/nrf-bm/release_notes/release_notes_changelog.rst index 0a66e65a48..a624ee450a 100644 --- a/doc/nrf-bm/release_notes/release_notes_changelog.rst +++ b/doc/nrf-bm/release_notes/release_notes_changelog.rst @@ -86,6 +86,7 @@ Libraries * :ref:`lib_ble_service_dis` service. * :ref:`lib_ble_service_hrs` service. * :ref:`lib_ble_service_lbs` service. + * :ref:`lib_ble_service_mcumgr` service. * BLE Record Access Control Point library. * :ref:`lib_ble_conn_params` library: diff --git a/include/bm/bluetooth/services/ble_mcumgr.h b/include/bm/bluetooth/services/ble_mcumgr.h index dcbc7c817e..56f0698cb4 100644 --- a/include/bm/bluetooth/services/ble_mcumgr.h +++ b/include/bm/bluetooth/services/ble_mcumgr.h @@ -37,10 +37,10 @@ extern "C" { /** * @brief Function for initializing the MCUmgr Bluetooth service. * - * @retval 0 On success. - * @retval -EINVAL Invalid parameters. + * @retval NRF_SUCCESS On success. + * @retval NRF_ERROR_INVALID_PARAM Invalid parameters. */ -int ble_mcumgr_init(void); +uint32_t ble_mcumgr_init(void); /** * @brief Function for getting the MCUmgr Bluetooth service UUID type. diff --git a/samples/boot/mcuboot_recovery_entry/src/main.c b/samples/boot/mcuboot_recovery_entry/src/main.c index 28ba3e256a..b3a6e9abea 100644 --- a/samples/boot/mcuboot_recovery_entry/src/main.c +++ b/samples/boot/mcuboot_recovery_entry/src/main.c @@ -186,10 +186,10 @@ int main(void) LOG_INF("Bluetooth enabled"); - err = ble_mcumgr_init(); + nrf_err = ble_mcumgr_init(); - if (err) { - LOG_ERR("Failed to initialize MCUmgr: %d", err); + if (nrf_err) { + LOG_ERR("Failed to initialize MCUmgr, nrf_error %#x", nrf_err); return 0; } diff --git a/subsys/bluetooth/services/ble_mcumgr/mcumgr.c b/subsys/bluetooth/services/ble_mcumgr/mcumgr.c index 9e8f926ca4..b0ba281422 100644 --- a/subsys/bluetooth/services/ble_mcumgr/mcumgr.c +++ b/subsys/bluetooth/services/ble_mcumgr/mcumgr.c @@ -126,7 +126,7 @@ static uint32_t mcumgr_characteristic_add(struct ble_mcumgr *service) */ static void on_connect(struct ble_mcumgr *service, ble_evt_t const *ble_evt) { - int err; + uint32_t nrf_err; uint8_t cccd_value[2]; ble_gatts_value_t gatts_val = { .p_value = cccd_value, @@ -145,10 +145,10 @@ static void on_connect(struct ble_mcumgr *service, ble_evt_t const *ble_evt) /* Check the hosts CCCD value to inform of readiness to send data using the * RX characteristic */ - err = sd_ble_gatts_value_get(conn_handle, service->characteristic_handle.cccd_handle, - &gatts_val); + nrf_err = sd_ble_gatts_value_get(conn_handle, service->characteristic_handle.cccd_handle, + &gatts_val); - if (err == 0 && is_notification_enabled(gatts_val.p_value)) { + if (nrf_err == NRF_SUCCESS && is_notification_enabled(gatts_val.p_value)) { ctx->is_notification_enabled = true; } } @@ -198,7 +198,7 @@ static void on_write(struct ble_mcumgr *service, ble_evt_t const *ble_evt) * Collection can fail only due to failing to allocate memory or by receiving * more data than expected. */ - if (ret == -ENOMEM) { + if (ret == NRF_ERROR_NO_MEM) { /* Failed to collect the buffer */ LOG_ERR("Failed to collect buffer"); return; @@ -239,9 +239,9 @@ static void on_write(struct ble_mcumgr *service, ble_evt_t const *ble_evt) } } -int ble_mcumgr_data_send(uint8_t *data, uint16_t *len, struct ble_mcumgr_client_context *ctx) +uint32_t ble_mcumgr_data_send(uint8_t *data, uint16_t *len, struct ble_mcumgr_client_context *ctx) { - int err; + uint32_t nrf_err; ble_gatts_hvx_params_t hvx_params = { .handle = ble_mcumgr.characteristic_handle.value_handle, .p_data = data, @@ -250,47 +250,47 @@ int ble_mcumgr_data_send(uint8_t *data, uint16_t *len, struct ble_mcumgr_client_ }; if (!data || !len) { - return -EFAULT; + return NRF_ERROR_NULL; } else if (*len > BLE_GATT_MAX_DATA_LEN) { - return -EINVAL; + return NRF_ERROR_INVALID_PARAM; } else if (!ctx->is_notification_enabled) { - return -EINVAL; + return NRF_ERROR_INVALID_PARAM; } - err = sd_ble_gatts_hvx(conn_handle, &hvx_params); + nrf_err = sd_ble_gatts_hvx(conn_handle, &hvx_params); - switch (err) { + switch (nrf_err) { case NRF_SUCCESS: { - return 0; + return NRF_SUCCESS; } case BLE_ERROR_INVALID_CONN_HANDLE: { - return -ENOTCONN; + return NRF_ERROR_NOT_FOUND; } case NRF_ERROR_INVALID_STATE: { - return -EPIPE; + return NRF_ERROR_INVALID_STATE; } case NRF_ERROR_RESOURCES: { - return -EAGAIN; + return NRF_ERROR_RESOURCES; } case NRF_ERROR_NOT_FOUND: { - return -EBADF; + return NRF_ERROR_NOT_FOUND; } default: { - LOG_ERR("Failed to send MCUmgr data, nrf_error %#x", err); - return -EIO; + LOG_ERR("Failed to send MCUmgr data, nrf_error %#x", nrf_err); + return NRF_ERROR_INTERNAL; } }; } +/* Return errno! */ static int smp_ncs_bm_bt_tx_pkt(struct net_buf *nb) { - int rc; uint32_t nrf_err; struct ble_mcumgr_client_context *ctx; uint16_t notification_size; @@ -316,9 +316,9 @@ static int smp_ncs_bm_bt_tx_pkt(struct net_buf *nb) send_size = notification_size; } - rc = ble_mcumgr_data_send(send_pos, &send_size, ctx); + nrf_err = ble_mcumgr_data_send(send_pos, &send_size, ctx); - if (rc) { + if (nrf_err) { break; } @@ -374,9 +374,9 @@ static void on_ble_evt(const ble_evt_t *evt, void *ctx) NRF_SDH_BLE_OBSERVER(sdh_ble, on_ble_evt, &ble_mcumgr, 0); -int ble_mcumgr_init(void) +uint32_t ble_mcumgr_init(void) { - int err; + uint32_t nrf_err; ble_uuid_t ble_uuid; ble_uuid128_t uuid_base_service = { .uuid128 = BLE_MCUMGR_SERVICE_UUID @@ -389,39 +389,40 @@ int ble_mcumgr_init(void) ble_mcumgr.service_handle = BLE_CONN_HANDLE_INVALID; /* Add MCUmgr service/characteristic UUIDs */ - err = sd_ble_uuid_vs_add(&uuid_base_service, &ble_mcumgr.uuid_type_service); + nrf_err = sd_ble_uuid_vs_add(&uuid_base_service, &ble_mcumgr.uuid_type_service); - if (err) { - LOG_ERR("sd_ble_uuid_vs_add failed, nrf_error %#x", err); - return -EINVAL; + if (nrf_err) { + LOG_ERR("sd_ble_uuid_vs_add failed, nrf_error %#x", nrf_err); + return NRF_ERROR_INVALID_PARAM; } - err = sd_ble_uuid_vs_add(&uuid_base_characteristic, &ble_mcumgr.uuid_type_characteristic); + nrf_err = sd_ble_uuid_vs_add(&uuid_base_characteristic, + &ble_mcumgr.uuid_type_characteristic); - if (err) { - LOG_ERR("sd_ble_uuid_vs_add failed, nrf_error %#x", err); - return -EINVAL; + if (nrf_err) { + LOG_ERR("sd_ble_uuid_vs_add failed, nrf_error %#x", nrf_err); + return NRF_ERROR_INVALID_PARAM; } ble_uuid.type = ble_mcumgr.uuid_type_service; ble_uuid.uuid = BLE_MCUMGR_SERVICE_UUID_SUB; /* Add the service */ - err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, - &ble_uuid, - &ble_mcumgr.service_handle); + nrf_err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, + &ble_uuid, + &ble_mcumgr.service_handle); - if (err) { - LOG_ERR("Failed to add MCUmgr service, nrf_error %#x", err); - return -EINVAL; + if (nrf_err) { + LOG_ERR("Failed to add MCUmgr service, nrf_error %#x", nrf_err); + return NRF_ERROR_INVALID_PARAM; } /* Add MCUmgr characteristic */ - err = mcumgr_characteristic_add(&ble_mcumgr); + nrf_err = mcumgr_characteristic_add(&ble_mcumgr); - if (err) { - LOG_ERR("mcumgr_characteristic_add failed, nrf_error %#x", err); - return -EINVAL; + if (nrf_err) { + LOG_ERR("mcumgr_characteristic_add failed, nrf_error %#x", nrf_err); + return NRF_ERROR_INVALID_PARAM; } return 0; From c31ca295dcb12c684c7a2b1767ecb6fc91c11eb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20J=C3=B8lsgard?= Date: Tue, 28 Oct 2025 14:50:59 +0100 Subject: [PATCH 12/12] bluetooth: services: ble_nus: change error codes to nrf_error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change error codes to nrf_errors. Signed-off-by: Eivind Jølsgard --- .../release_notes/release_notes_changelog.rst | 1 + include/bm/bluetooth/services/ble_nus.h | 22 +-- samples/bluetooth/ble_nus/src/main.c | 38 ++--- subsys/bluetooth/services/ble_nus/nus.c | 82 ++++----- .../services/ble_nus/src/unity_test.c | 161 +++++++----------- 5 files changed, 126 insertions(+), 178 deletions(-) diff --git a/doc/nrf-bm/release_notes/release_notes_changelog.rst b/doc/nrf-bm/release_notes/release_notes_changelog.rst index a624ee450a..334128a151 100644 --- a/doc/nrf-bm/release_notes/release_notes_changelog.rst +++ b/doc/nrf-bm/release_notes/release_notes_changelog.rst @@ -87,6 +87,7 @@ Libraries * :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: diff --git a/include/bm/bluetooth/services/ble_nus.h b/include/bm/bluetooth/services/ble_nus.h index 5d58a6bf7e..80e3348151 100644 --- a/include/bm/bluetooth/services/ble_nus.h +++ b/include/bm/bluetooth/services/ble_nus.h @@ -162,11 +162,11 @@ struct ble_nus { * later be used to identify this particular service instance. * @param[in] nus_init Information needed to initialize the service. * - * @retval 0 On success. - * @retval -EFAULT If @p nus or @p nus_config is @c NULL. - * @retval -EINVAL Invalid parameters. + * @retval NRF_SUCCESS On success. + * @retval NRF_ERROR_NULL If @p nus or @p nus_config is @c NULL. + * @retval NRF_ERROR_INVALID_PARAM Invalid parameters. */ -int ble_nus_init(struct ble_nus *nus, struct ble_nus_config const *nus_config); +uint32_t ble_nus_init(struct ble_nus *nus, struct ble_nus_config const *nus_config); /** * @brief Function for handling the Nordic UART Service's BLE events. @@ -192,17 +192,11 @@ void ble_nus_on_ble_evt(ble_evt_t const *ble_evt, void *context); * @param[in,out] length In: Length of the @p data string. Out: Number of bytes sent. * @param[in] conn_handle Connection handle of the destination client. * - * @retval 0 On success. - * @retval -EFAULT If @p nus, @p data or @p length is @c NULL. - * @retval -EINVAL Invalid parameters. - * @retval -ENOENT Invalid @p conn_handle. - * @retval -EIO Failed to send notification. - * @retval -ENOTCONN Connection handle unknown to the softdevice. - * @retval -EPIPE Notifications not enabled in the CCCD. - * @retval -EBADF Not found. - * @retval -EAGAIN Not enough resources for operation. + * @retval NRF_SUCCESS On success. + * @return nrf_error on failure. */ -int ble_nus_data_send(struct ble_nus *nus, uint8_t *data, uint16_t *length, uint16_t conn_handle); +uint32_t ble_nus_data_send(struct ble_nus *nus, uint8_t *data, uint16_t *length, + uint16_t conn_handle); #ifdef __cplusplus } diff --git a/samples/bluetooth/ble_nus/src/main.c b/samples/bluetooth/ble_nus/src/main.c index 60dcd97d66..1c7e36317c 100644 --- a/samples/bluetooth/ble_nus/src/main.c +++ b/samples/bluetooth/ble_nus/src/main.c @@ -71,26 +71,26 @@ static int buf_idx; #if defined(CONFIG_NUS_LPUARTE) static void lpuarte_rx_handler(char *data, size_t data_len) { - int err; + uint32_t nrf_err; uint16_t len = data_len; LOG_INF("Sending data over BLE NUS, len %d", len); do { - err = ble_nus_data_send(&ble_nus, data, &len, conn_handle); - if ((err != 0) && - (err != -EPIPE) && - (err != -EAGAIN) && - (err != -EBADF)) { - LOG_ERR("Failed to send NUS data, err %d", err); + nrf_err = ble_nus_data_send(&ble_nus, data, &len, conn_handle); + if ((nrf_err) && + (nrf_err != NRF_ERROR_INVALID_STATE) && + (nrf_err != NRF_ERROR_RESOURCES) && + (nrf_err != NRF_ERROR_NOT_FOUND)) { + LOG_ERR("Failed to send NUS data, nrf_error %#x", nrf_err); return; } - } while (err == -EAGAIN); + } while (nrf_err == NRF_ERROR_RESOURCES); } #else static void uarte_rx_handler(char *data, size_t data_len) { - int err; + uint32_t nrf_err; uint8_t c; /* receive buffer used in UART ISR callback */ static char rx_buf[BLE_NUS_MAX_DATA_LEN]; @@ -114,15 +114,15 @@ static void uarte_rx_handler(char *data, size_t data_len) LOG_INF("Sending data over BLE NUS, len %d", len); do { - err = ble_nus_data_send(&ble_nus, rx_buf, &len, conn_handle); - if ((err != 0) && - (err != -EPIPE) && - (err != -EAGAIN) && - (err != -EBADF)) { - LOG_ERR("Failed to send NUS data, err %d", err); + nrf_err = ble_nus_data_send(&ble_nus, rx_buf, &len, conn_handle); + if ((nrf_err) && + (nrf_err != NRF_ERROR_INVALID_STATE) && + (nrf_err != NRF_ERROR_RESOURCES) && + (nrf_err != NRF_ERROR_NOT_FOUND)) { + LOG_ERR("Failed to send NUS data, nrf_error %#x", nrf_err); return; } - } while (err == -EAGAIN); + } while (nrf_err == NRF_ERROR_RESOURCES); if (len == rx_buf_idx) { rx_buf_idx = 0; @@ -488,9 +488,9 @@ int main(void) goto idle; } - err = ble_nus_init(&ble_nus, &nus_cfg); - if (err) { - LOG_ERR("Failed to initialize Nordic uart service, err %d", err); + nrf_err = ble_nus_init(&ble_nus, &nus_cfg); + if (nrf_err) { + LOG_ERR("Failed to initialize Nordic uart service, nrf_error %#x", nrf_err); goto idle; } diff --git a/subsys/bluetooth/services/ble_nus/nus.c b/subsys/bluetooth/services/ble_nus/nus.c index 9fd502ca44..7765916a6d 100644 --- a/subsys/bluetooth/services/ble_nus/nus.c +++ b/subsys/bluetooth/services/ble_nus/nus.c @@ -4,6 +4,7 @@ * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ +#include #include #include #include @@ -100,7 +101,7 @@ static uint32_t nus_tx_char_add(struct ble_nus *nus, struct ble_nus_config const */ static void on_connect(struct ble_nus *nus, ble_evt_t const *ble_evt) { - int err; + uint32_t nrf_err; const uint16_t conn_handle = ble_evt->evt.gap_evt.conn_handle; struct ble_nus_evt evt = { .type = BLE_NUS_EVT_COMM_STARTED, @@ -123,8 +124,8 @@ static void on_connect(struct ble_nus *nus, ble_evt_t const *ble_evt) /* Check the hosts CCCD value to inform of readiness to send data using the * RX characteristic */ - err = sd_ble_gatts_value_get(conn_handle, nus->tx_handles.cccd_handle, &gatts_val); - if ((err == 0) && (nus->evt_handler != NULL) && + nrf_err = sd_ble_gatts_value_get(conn_handle, nus->tx_handles.cccd_handle, &gatts_val); + if ((nrf_err == NRF_SUCCESS) && (nus->evt_handler != NULL) && is_notification_enabled(gatts_val.p_value)) { if (ctx != NULL) { ctx->is_notification_enabled = true; @@ -243,14 +244,14 @@ void ble_nus_on_ble_evt(ble_evt_t const *ble_evt, void *ctx) } } -int ble_nus_init(struct ble_nus *nus, struct ble_nus_config const *cfg) +uint32_t ble_nus_init(struct ble_nus *nus, struct ble_nus_config const *cfg) { - int err; + uint32_t nrf_err; ble_uuid_t ble_uuid; ble_uuid128_t uuid_base = { .uuid128 = BLE_NUS_UUID_BASE }; if (!nus || !cfg) { - return -EFAULT; + return NRF_ERROR_NULL; } /* Initialize the service structure. */ @@ -258,45 +259,44 @@ int ble_nus_init(struct ble_nus *nus, struct ble_nus_config const *cfg) nus->service_handle = BLE_CONN_HANDLE_INVALID; /* Add a custom base UUID. */ - err = sd_ble_uuid_vs_add(&uuid_base, &nus->uuid_type); - if (err) { - LOG_ERR("sd_ble_uuid_vs_add failed, nrf_error %#x", err); - return -EINVAL; + nrf_err = sd_ble_uuid_vs_add(&uuid_base, &nus->uuid_type); + if (nrf_err) { + LOG_ERR("sd_ble_uuid_vs_add failed, nrf_error %#x", nrf_err); + return NRF_ERROR_INVALID_PARAM; } ble_uuid.type = nus->uuid_type; ble_uuid.uuid = BLE_UUID_NUS_SERVICE; /* Add the service. */ - err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, - &ble_uuid, - &nus->service_handle); - if (err) { - LOG_ERR("Failed to add NUS service, nrf_error %#x", err); - return -EINVAL; + nrf_err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, + &ble_uuid, + &nus->service_handle); + if (nrf_err) { + LOG_ERR("Failed to add NUS service, nrf_error %#x", nrf_err); + return NRF_ERROR_INVALID_PARAM; } /* Add NUS RX characteristic. */ - err = nus_rx_char_add(nus, cfg); - if (err) { - LOG_ERR("nus_rx_char_add failed, nrf_error %#x", err); - return -EINVAL; + nrf_err = nus_rx_char_add(nus, cfg); + if (nrf_err) { + LOG_ERR("nus_rx_char_add failed, nrf_error %#x", nrf_err); + return NRF_ERROR_INVALID_PARAM; } /* Add NUS TX characteristic. */ - err = nus_tx_char_add(nus, cfg); - if (err) { - LOG_ERR("nus_tx_char_add failed, nrf_error %#x", err); - return -EINVAL; + nrf_err = nus_tx_char_add(nus, cfg); + if (nrf_err) { + LOG_ERR("nus_tx_char_add failed, nrf_error %#x", nrf_err); + return NRF_ERROR_INVALID_PARAM; } return 0; } -int ble_nus_data_send(struct ble_nus *nus, uint8_t *data, +uint32_t ble_nus_data_send(struct ble_nus *nus, uint8_t *data, uint16_t *len, uint16_t conn_handle) { - int err; ble_gatts_hvx_params_t hvx_params = { .p_data = data, .p_len = len, @@ -305,45 +305,27 @@ int ble_nus_data_send(struct ble_nus *nus, uint8_t *data, struct ble_nus_client_context *ctx; if (!nus || !data || !len) { - return -EFAULT; + return NRF_ERROR_NULL; } if (*len > BLE_NUS_MAX_DATA_LEN) { - return -EINVAL; + return NRF_ERROR_INVALID_PARAM; } if (conn_handle == BLE_CONN_HANDLE_INVALID) { - return -ENOENT; + return NRF_ERROR_NOT_FOUND; } ctx = ble_nus_client_context_get(nus, conn_handle); if (ctx == NULL) { - return -ENOENT; + return NRF_ERROR_NOT_FOUND; } if (!ctx->is_notification_enabled) { - return -EINVAL; + return NRF_ERROR_INVALID_PARAM; } hvx_params.handle = nus->tx_handles.value_handle; - err = sd_ble_gatts_hvx(conn_handle, &hvx_params); - switch (err) { - case NRF_SUCCESS: - return 0; - case BLE_ERROR_INVALID_CONN_HANDLE: - return -ENOTCONN; - case NRF_ERROR_INVALID_STATE: - case BLE_ERROR_GATTS_SYS_ATTR_MISSING: - return -EPIPE; - case NRF_ERROR_RESOURCES: - return -EAGAIN; - case NRF_ERROR_NOT_FOUND: - return -EBADF; - default: - LOG_ERR("Failed to send NUS data, nrf_error %#x", err); - return -EIO; - } - - return 0; + return sd_ble_gatts_hvx(conn_handle, &hvx_params); } diff --git a/tests/subsys/bluetooth/services/ble_nus/src/unity_test.c b/tests/subsys/bluetooth/services/ble_nus/src/unity_test.c index 19cfdc04a7..3a702dfc7d 100644 --- a/tests/subsys/bluetooth/services/ble_nus/src/unity_test.c +++ b/tests/subsys/bluetooth/services/ble_nus/src/unity_test.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ -#include +#include #include #include #include @@ -131,7 +131,7 @@ static void ble_nus_evt_handler_on_hvx_tx_complete(const struct ble_nus_evt *evt static void nus_init(struct ble_nus_config *nus_cfg) { - int ret; + uint32_t nrf_err; uint8_t expected_uuid_type = 123; __cmock_sd_ble_uuid_vs_add_ExpectAnyArgsAndReturn(NRF_SUCCESS); @@ -139,8 +139,8 @@ static void nus_init(struct ble_nus_config *nus_cfg) __cmock_sd_ble_gatts_service_add_Stub(stub_sd_ble_gatts_service_add); __cmock_sd_ble_gatts_characteristic_add_Stub(stub_sd_ble_gatts_characteristic_add); - ret = ble_nus_init(&ble_nus, nus_cfg); - TEST_ASSERT_EQUAL(0, ret); + nrf_err = ble_nus_init(&ble_nus, nus_cfg); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); TEST_ASSERT_EQUAL_PTR(nus_cfg->evt_handler, ble_nus.evt_handler); } @@ -159,49 +159,49 @@ static void setup_with_notif_enabled(uint16_t conn_handle) TEST_ASSERT_TRUE(evt_handler_called); } -void test_ble_nus_init_efault(void) +void test_ble_nus_init_error_null(void) { - int ret; + uint32_t nrf_err; struct ble_nus_config nus_cfg = {0}; - ret = ble_nus_init(NULL, &nus_cfg); - TEST_ASSERT_EQUAL(-EFAULT, ret); + nrf_err = ble_nus_init(NULL, &nus_cfg); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); - ret = ble_nus_init(&ble_nus, NULL); - TEST_ASSERT_EQUAL(-EFAULT, ret); + nrf_err = ble_nus_init(&ble_nus, NULL); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); } -void test_ble_nus_init_einval(void) +void test_ble_nus_init_error_invalid_param(void) { - int ret; + uint32_t nrf_err; struct ble_nus_config nus_cfg = {0}; __cmock_sd_ble_uuid_vs_add_ExpectAnyArgsAndReturn(NRF_ERROR_INVALID_PARAM); - ret = ble_nus_init(&ble_nus, &nus_cfg); - TEST_ASSERT_EQUAL(-EINVAL, ret); + nrf_err = ble_nus_init(&ble_nus, &nus_cfg); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, nrf_err); __cmock_sd_ble_uuid_vs_add_ExpectAnyArgsAndReturn(NRF_SUCCESS); __cmock_sd_ble_gatts_service_add_ExpectAnyArgsAndReturn(NRF_ERROR_INVALID_PARAM); - ret = ble_nus_init(&ble_nus, &nus_cfg); - TEST_ASSERT_EQUAL(-EINVAL, ret); + nrf_err = ble_nus_init(&ble_nus, &nus_cfg); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, nrf_err); __cmock_sd_ble_uuid_vs_add_ExpectAnyArgsAndReturn(NRF_SUCCESS); __cmock_sd_ble_gatts_service_add_ExpectAnyArgsAndReturn(NRF_SUCCESS); __cmock_sd_ble_gatts_characteristic_add_ExpectAnyArgsAndReturn(NRF_ERROR_INVALID_PARAM); - ret = ble_nus_init(&ble_nus, &nus_cfg); - TEST_ASSERT_EQUAL(-EINVAL, ret); + nrf_err = ble_nus_init(&ble_nus, &nus_cfg); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, nrf_err); __cmock_sd_ble_uuid_vs_add_ExpectAnyArgsAndReturn(NRF_SUCCESS); __cmock_sd_ble_gatts_service_add_ExpectAnyArgsAndReturn(NRF_SUCCESS); __cmock_sd_ble_gatts_characteristic_add_ExpectAnyArgsAndReturn(NRF_SUCCESS); __cmock_sd_ble_gatts_characteristic_add_ExpectAnyArgsAndReturn(NRF_ERROR_INVALID_PARAM); - ret = ble_nus_init(&ble_nus, &nus_cfg); - TEST_ASSERT_EQUAL(-EINVAL, ret); + nrf_err = ble_nus_init(&ble_nus, &nus_cfg); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, nrf_err); } void test_ble_nus_init_success(void) { - int ret; + uint32_t nrf_err; struct ble_nus_config nus_cfg = {0}; uint8_t expected_uuid_type = 123; @@ -211,7 +211,8 @@ void test_ble_nus_init_success(void) __cmock_sd_ble_gatts_service_add_Stub(stub_sd_ble_gatts_service_add); __cmock_sd_ble_gatts_characteristic_add_Stub(stub_sd_ble_gatts_characteristic_add); - ret = ble_nus_init(&ble_nus, &nus_cfg); + nrf_err = ble_nus_init(&ble_nus, &nus_cfg); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); } void test_ble_nus_on_ble_evt_gap_evt_do_nothing(void) @@ -321,6 +322,7 @@ void test_ble_nus_on_ble_evt_gap_evt_on_write(void) TEST_ASSERT_TRUE(evt_handler_called); evt_handler_called = false; + ble_nus.evt_handler = ble_nus_evt_handler_on_write_indica; __cmock_nrf_sdh_ble_idx_get_ExpectAndReturn(test_case_conn_handle, -1); ble_nus_on_ble_evt(&ble_evt, &ble_nus); @@ -371,28 +373,28 @@ void test_ble_nus_on_hvx_tx_complete(void) TEST_ASSERT_TRUE(evt_handler_called); } -void test_ble_nus_data_send_efault(void) +void test_ble_nus_data_send_error_null(void) { - int ret; + uint32_t nrf_err; uint8_t data[2]; uint16_t length = sizeof(data); - ret = ble_nus_data_send(NULL, NULL, NULL, test_case_conn_handle); - TEST_ASSERT_EQUAL(-EFAULT, ret); + nrf_err = ble_nus_data_send(NULL, NULL, NULL, test_case_conn_handle); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); - ret = ble_nus_data_send(&ble_nus, data, NULL, test_case_conn_handle); - TEST_ASSERT_EQUAL(-EFAULT, ret); + nrf_err = ble_nus_data_send(&ble_nus, data, NULL, test_case_conn_handle); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); - ret = ble_nus_data_send(&ble_nus, NULL, &length, test_case_conn_handle); - TEST_ASSERT_EQUAL(-EFAULT, ret); + nrf_err = ble_nus_data_send(&ble_nus, NULL, &length, test_case_conn_handle); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); - ret = ble_nus_data_send(NULL, data, &length, test_case_conn_handle); - TEST_ASSERT_EQUAL(-EFAULT, ret); + nrf_err = ble_nus_data_send(NULL, data, &length, test_case_conn_handle); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); } -void test_ble_nus_data_send_einval(void) +void test_ble_nus_data_send_error_invalid_param(void) { - int ret; + uint32_t nrf_err; uint8_t data[2]; uint16_t length = sizeof(data); ble_evt_t ble_evt = { @@ -419,34 +421,20 @@ void test_ble_nus_data_send_einval(void) ble_nus_on_ble_evt(&ble_evt, &ble_nus); TEST_ASSERT_TRUE(evt_handler_called); - /* Test for -EINVAL */ + /* Test for invalid parameter */ __cmock_nrf_sdh_ble_idx_get_ExpectAndReturn(test_case_conn_handle, 0); - ret = ble_nus_data_send(&ble_nus, data, &length, test_case_conn_handle); - TEST_ASSERT_EQUAL(-EINVAL, ret); + nrf_err = ble_nus_data_send(&ble_nus, data, &length, test_case_conn_handle); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, nrf_err); length = (BLE_NUS_MAX_DATA_LEN + 1); - ret = ble_nus_data_send(&ble_nus, data, &length, test_case_conn_handle); - TEST_ASSERT_EQUAL(-EINVAL, ret); + nrf_err = ble_nus_data_send(&ble_nus, data, &length, test_case_conn_handle); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, nrf_err); } -void test_ble_nus_data_send_enoent(void) -{ - int ret; - uint8_t data[2]; - uint16_t length = sizeof(data); - uint16_t conn_handle_inval = BLE_CONN_HANDLE_INVALID; - - ret = ble_nus_data_send(&ble_nus, data, &length, conn_handle_inval); - TEST_ASSERT_EQUAL(-ENOENT, ret); - - __cmock_nrf_sdh_ble_idx_get_ExpectAndReturn(test_case_conn_handle, -1); - ret = ble_nus_data_send(&ble_nus, data, &length, test_case_conn_handle); - TEST_ASSERT_EQUAL(-ENOENT, ret); -} -void test_ble_nus_data_send_eio(void) +void test_ble_nus_data_send_error_invalid_param_hvx(void) { - int ret; + uint32_t nrf_err; uint8_t data[2]; uint16_t length = sizeof(data); struct ble_nus_config nus_cfg = { .evt_handler = ble_nus_evt_handler_on_connect }; @@ -456,45 +444,28 @@ void test_ble_nus_data_send_eio(void) __cmock_nrf_sdh_ble_idx_get_ExpectAndReturn(test_case_conn_handle, 0); __cmock_sd_ble_gatts_hvx_ExpectAnyArgsAndReturn(NRF_ERROR_INVALID_PARAM); - ret = ble_nus_data_send(&ble_nus, data, &length, test_case_conn_handle); - TEST_ASSERT_EQUAL(-EIO, ret); + nrf_err = ble_nus_data_send(&ble_nus, data, &length, test_case_conn_handle); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, nrf_err); } -void test_ble_nus_data_send_enotconn(void) +void test_ble_nus_data_send_error_not_found(void) { - int ret; + uint32_t nrf_err; uint8_t data[2]; uint16_t length = sizeof(data); - struct ble_nus_config nus_cfg = { .evt_handler = ble_nus_evt_handler_on_connect }; - - nus_init(&nus_cfg); - setup_with_notif_enabled(test_case_conn_handle); - - __cmock_nrf_sdh_ble_idx_get_ExpectAndReturn(test_case_conn_handle, 0); - __cmock_sd_ble_gatts_hvx_ExpectAnyArgsAndReturn(BLE_ERROR_INVALID_CONN_HANDLE); - ret = ble_nus_data_send(&ble_nus, data, &length, test_case_conn_handle); - TEST_ASSERT_EQUAL(-ENOTCONN, ret); -} + uint16_t conn_handle_inval = BLE_CONN_HANDLE_INVALID; -void test_ble_nus_data_send_epipe(void) -{ - int ret; - uint8_t data[2]; - uint16_t length = sizeof(data); - struct ble_nus_config nus_cfg = { .evt_handler = ble_nus_evt_handler_on_connect }; + nrf_err = ble_nus_data_send(&ble_nus, data, &length, conn_handle_inval); + TEST_ASSERT_EQUAL(NRF_ERROR_NOT_FOUND, nrf_err); - nus_init(&nus_cfg); - setup_with_notif_enabled(test_case_conn_handle); - - __cmock_nrf_sdh_ble_idx_get_ExpectAndReturn(test_case_conn_handle, 0); - __cmock_sd_ble_gatts_hvx_ExpectAnyArgsAndReturn(NRF_ERROR_INVALID_STATE); - ret = ble_nus_data_send(&ble_nus, data, &length, test_case_conn_handle); - TEST_ASSERT_EQUAL(-EPIPE, ret); + __cmock_nrf_sdh_ble_idx_get_ExpectAndReturn(test_case_conn_handle, -1); + nrf_err = ble_nus_data_send(&ble_nus, data, &length, test_case_conn_handle); + TEST_ASSERT_EQUAL(NRF_ERROR_NOT_FOUND, nrf_err); } -void test_ble_nus_data_send_ebadf(void) +void test_ble_nus_data_send_error_invalid_conn_handle(void) { - int ret; + uint32_t nrf_err; uint8_t data[2]; uint16_t length = sizeof(data); struct ble_nus_config nus_cfg = { .evt_handler = ble_nus_evt_handler_on_connect }; @@ -503,14 +474,14 @@ void test_ble_nus_data_send_ebadf(void) setup_with_notif_enabled(test_case_conn_handle); __cmock_nrf_sdh_ble_idx_get_ExpectAndReturn(test_case_conn_handle, 0); - __cmock_sd_ble_gatts_hvx_ExpectAnyArgsAndReturn(NRF_ERROR_NOT_FOUND); - ret = ble_nus_data_send(&ble_nus, data, &length, test_case_conn_handle); - TEST_ASSERT_EQUAL(-EBADF, ret); + __cmock_sd_ble_gatts_hvx_ExpectAnyArgsAndReturn(BLE_ERROR_INVALID_CONN_HANDLE); + nrf_err = ble_nus_data_send(&ble_nus, data, &length, test_case_conn_handle); + TEST_ASSERT_EQUAL(BLE_ERROR_INVALID_CONN_HANDLE, nrf_err); } -void test_ble_nus_data_send_eagain(void) +void test_ble_nus_data_send_error_invalid_state(void) { - int ret; + uint32_t nrf_err; uint8_t data[2]; uint16_t length = sizeof(data); struct ble_nus_config nus_cfg = { .evt_handler = ble_nus_evt_handler_on_connect }; @@ -519,14 +490,14 @@ void test_ble_nus_data_send_eagain(void) setup_with_notif_enabled(test_case_conn_handle); __cmock_nrf_sdh_ble_idx_get_ExpectAndReturn(test_case_conn_handle, 0); - __cmock_sd_ble_gatts_hvx_ExpectAnyArgsAndReturn(NRF_ERROR_RESOURCES); - ret = ble_nus_data_send(&ble_nus, data, &length, test_case_conn_handle); - TEST_ASSERT_EQUAL(-EAGAIN, ret); + __cmock_sd_ble_gatts_hvx_ExpectAnyArgsAndReturn(NRF_ERROR_INVALID_STATE); + nrf_err = ble_nus_data_send(&ble_nus, data, &length, test_case_conn_handle); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_STATE, nrf_err); } void test_ble_nus_data_send_success(void) { - int ret; + uint32_t nrf_err; uint8_t data[2] = {0x01, 0x02}; uint16_t length = sizeof(data); ble_gatts_hvx_params_t expected_hvx_params = { @@ -543,8 +514,8 @@ void test_ble_nus_data_send_success(void) __cmock_sd_ble_gatts_hvx_ExpectAndReturn(test_case_conn_handle, &expected_hvx_params, NRF_SUCCESS); - ret = ble_nus_data_send(&ble_nus, data, &length, test_case_conn_handle); - TEST_ASSERT_EQUAL(0, ret); + nrf_err = ble_nus_data_send(&ble_nus, data, &length, test_case_conn_handle); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); } void setUp(void)