diff --git a/applications/firmware_loader/ble_mcumgr/src/main.c b/applications/firmware_loader/ble_mcumgr/src/main.c index ff0a87b5be..9887f1fd89 100644 --- a/applications/firmware_loader/ble_mcumgr/src/main.c +++ b/applications/firmware_loader/ble_mcumgr/src/main.c @@ -176,6 +176,7 @@ static int ble_change_address(void) int main(void) { int err; + uint32_t nrf_err; struct ble_adv_config ble_adv_cfg = { .conn_cfg_tag = CONFIG_NRF_SDH_BLE_CONN_TAG, .evt_handler = ble_adv_evt_handler, @@ -231,17 +232,15 @@ int main(void) ble_adv_cfg.sr_data.uuid_lists.complete.uuid = &adv_uuid_list[0]; ble_adv_cfg.sr_data.uuid_lists.complete.len = ARRAY_SIZE(adv_uuid_list); - err = ble_adv_init(&ble_adv, &ble_adv_cfg); - - if (err) { - LOG_ERR("Failed to initialize advertising, err %d", err); + nrf_err = ble_adv_init(&ble_adv, &ble_adv_cfg); + if (nrf_err) { + LOG_ERR("Failed to initialize advertising, nrf_error %#x", nrf_err); return 0; } - err = ble_adv_start(&ble_adv, BLE_ADV_MODE_FAST); - - if (err) { - LOG_ERR("Failed to start advertising, err %d", err); + nrf_err = ble_adv_start(&ble_adv, BLE_ADV_MODE_FAST); + if (nrf_err) { + LOG_ERR("Failed to start advertising, nrf_error %#x", err); return 0; } diff --git a/doc/nrf-bm/libraries/bluetooth/ble_peer_manager.rst b/doc/nrf-bm/libraries/bluetooth/ble_peer_manager.rst index 9fb47086f3..b909aa45e8 100644 --- a/doc/nrf-bm/libraries/bluetooth/ble_peer_manager.rst +++ b/doc/nrf-bm/libraries/bluetooth/ble_peer_manager.rst @@ -151,11 +151,11 @@ The following code example shows how the Peer Manager is initialized: static int 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) { + nrf_err = pm_init(); + if (nrf_err) { return -EFAULT; } @@ -179,15 +179,15 @@ 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); + 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 -EFAULT; } - err = pm_register(pm_evt_handler); - if (err) { - LOG_ERR("pm_register() failed, err: 0x%x", err); + nrf_err = pm_register(pm_evt_handler); + if (nrf_err) { + LOG_ERR("pm_register() failed, nrf_error: 0x%x", nrf_err); return -EFAULT; } } @@ -348,12 +348,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; pm_store_token_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_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 +361,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; pm_store_token_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_ERROR_BUSY) { + return nrf_err; } Using a whitelist @@ -392,9 +392,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 != NRF_SUCCESS) { + return nrf_err; } } @@ -409,7 +409,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 +418,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 != NRF_SUCCESS) { + return nrf_err; } /* 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 != NRF_SUCCESS) { + return nrf_err; } break; diff --git a/doc/nrf-bm/release_notes/release_notes_changelog.rst b/doc/nrf-bm/release_notes/release_notes_changelog.rst index e45bfb731e..681fc7b4fe 100644 --- a/doc/nrf-bm/release_notes/release_notes_changelog.rst +++ b/doc/nrf-bm/release_notes/release_notes_changelog.rst @@ -41,16 +41,16 @@ 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. 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. @@ -68,6 +68,18 @@ No changes since the latest nRF Connect SDK Bare Metal release. Libraries ========= +* Updated the following libraries and BLE services to return ``nrf_errors`` instead of ``errnos``: + + * BLE Advertising library. + * :ref:`lib_ble_conn_params` library. + * BLE Gatt Queue library. + * BLE QWR library. + * BLE Record Access Control Point library. + * :ref:`lib_ble_service_bas` service. + * :ref:`lib_ble_service_dis` service. + * :ref:`lib_ble_service_hrs` service. + * :ref:`lib_ble_service_lbs` service. + * :ref:`lib_ble_conn_params` library: * Added missing Kconfig dependencies. diff --git a/include/bm/bluetooth/ble_adv.h b/include/bm/bluetooth/ble_adv.h index 3319d38d77..a32c648388 100644 --- a/include/bm/bluetooth/ble_adv.h +++ b/include/bm/bluetooth/ble_adv.h @@ -136,7 +136,7 @@ struct ble_adv_evt { union { /** @ref BLE_ADV_EVT_ERROR event data. */ struct { - int reason; + uint32_t reason; } error; }; }; @@ -256,11 +256,11 @@ void ble_adv_on_ble_evt(const ble_evt_t *ble_evt, void *ble_adv); * @param[in] ble_adv BLE advertising instance. * @param[in] ble_adv_config Initialization configuration. * - * @retval 0 On success. - * @retval -FAULT If @p ble_adv or @p ble_adv_config are @c NULL. - * @retval -EINVAL If the configuration @p ble_adv_config is invalid. + * @retval NRF_SUCCESS On success. + * @retval NRF_ERROR_NULL If @p ble_adv or @p ble_adv_config are @c NULL. + * @retval NRF_ERROR_INVALID_PARAM If the configuration @p ble_adv_config is invalid. */ -int ble_adv_init(struct ble_adv *ble_adv, struct ble_adv_config *ble_adv_config); +uint32_t ble_adv_init(struct ble_adv *ble_adv, struct ble_adv_config *ble_adv_config); /** * @brief Set the connection configuration tag used for connections. @@ -268,7 +268,7 @@ int ble_adv_init(struct ble_adv *ble_adv, struct ble_adv_config *ble_adv_config) * @param[in] ble_adv BLE advertising instance. * @param[in] ble_cfg_tag Connection configuration tag. */ -int ble_adv_conn_cfg_tag_set(struct ble_adv *ble_adv, uint8_t ble_cfg_tag); +uint32_t ble_adv_conn_cfg_tag_set(struct ble_adv *ble_adv, uint8_t ble_cfg_tag); /** * @brief Start advertising in given mode. @@ -279,12 +279,12 @@ int ble_adv_conn_cfg_tag_set(struct ble_adv *ble_adv, uint8_t ble_cfg_tag); * @param[in] ble_adv BLE advertising instance. * @param[in] mode Desired advertising mode. * - * @retval 0 On success. - * @retval -EPERM Library is not initialized. - * @retval -EFAULT @p ble_adv is @c NULL. - * @retval -EINVAL Invalid parameters. + * @retval NRF_SUCCESS On success. + * @retval NRF_ERROR_INVALID_STATE Library is not initialized. + * @retval NRF_ERROR_NULL @p ble_adv is @c NULL. + * @retval NRF_ERROR_INVALID_PARAM Invalid parameters. */ -int ble_adv_start(struct ble_adv *ble_adv, enum ble_adv_mode mode); +uint32_t ble_adv_start(struct ble_adv *ble_adv, enum ble_adv_mode mode); /** * @brief Set the peer address for directed advertising. @@ -296,12 +296,12 @@ int ble_adv_start(struct ble_adv *ble_adv, enum ble_adv_mode mode); * @param[in] p_advertising Advertising Module instance. * @param[in] p_peer_addr Pointer to a peer address. * - * @retval 0 On success. - * @retval -EPERM Library is not initialized. - * @retval -EFAULT @p ble_adv is @c NULL. - * @retval -EINVAL Invalid parameters. + * @retval NRF_SUCCESS On success. + * @retval NRF_ERROR_INVALID_STATE Library is not initialized. + * @retval NRF_ERROR_NULL @p ble_adv is @c NULL. + * @retval NRF_ERROR_INVALID_PARAM Invalid parameters. */ -int ble_adv_peer_addr_reply(struct ble_adv *ble_adv, const ble_gap_addr_t *peer_addr); +uint32_t ble_adv_peer_addr_reply(struct ble_adv *ble_adv, const ble_gap_addr_t *peer_addr); /** * @brief Set a whitelist for fast and slow advertising. @@ -315,14 +315,14 @@ int ble_adv_peer_addr_reply(struct ble_adv *ble_adv, const ble_gap_addr_t *peer_ * @param[in] gap_irks The list of peer IRK to whitelist. * @param[in] irk_cnt The number of peer IRK to whitelist. * - * @retval 0 On success. - * @retval -EPERM Library is not initialized. - * @retval -EFAULT @p ble_adv is @c NULL. - * @retval -EINVAL Invalid parameters. + * @retval NRF_SUCCESS On success. + * @retval NRF_ERROR_INVALID_STATE Library is not initialized. + * @retval NRF_ERROR_NULL @p ble_adv is @c NULL. + * @retval NRF_ERROR_INVALID_PARAM Invalid parameters. */ -int ble_adv_whitelist_reply(struct ble_adv *ble_adv, - const ble_gap_addr_t *gap_addrs, uint32_t addr_cnt, - const ble_gap_irk_t *gap_irks, uint32_t irk_cnt); +uint32_t ble_adv_whitelist_reply(struct ble_adv *ble_adv, + const ble_gap_addr_t *gap_addrs, uint32_t addr_cnt, + const ble_gap_irk_t *gap_irks, uint32_t irk_cnt); /** * @brief Restart advertising without whitelist. @@ -332,11 +332,12 @@ int ble_adv_whitelist_reply(struct ble_adv *ble_adv, * * @param[in] ble_adv Advertising Module instance. * - * @retval 0 On success. - * @retval -EPERM Library is not initialized. - * @retval -EFAULT @p ble_adv is @c NULL. + * @retval NRF_SUCCESS On success. + * @retval NRF_ERROR_INVALID_STATE Library is not initialized. + * @retval NRF_ERROR_NULL @p ble_adv is @c NULL. + * @retval NRF_ERROR_INVALID_PARAM Invalid advertising parameters. */ -int ble_adv_restart_without_whitelist(struct ble_adv *ble_adv); +uint32_t ble_adv_restart_without_whitelist(struct ble_adv *ble_adv); /**@brief Function for updating advertising data. * @@ -355,9 +356,9 @@ int ble_adv_restart_without_whitelist(struct ble_adv *ble_adv); * @retval @ref NRF_SUCCESS or any error from @ref ble_advdata_encode or * @ref sd_ble_gap_adv_set_configure(). */ -int ble_adv_data_update(struct ble_adv *ble_adv, - const struct ble_adv_data *adv, - const struct ble_adv_data *sr); +uint32_t ble_adv_data_update(struct ble_adv *ble_adv, + const struct ble_adv_data *adv, + const struct ble_adv_data *sr); #ifdef __cplusplus } diff --git a/include/bm/bluetooth/ble_adv_data.h b/include/bm/bluetooth/ble_adv_data.h index db9705ebcb..4841d36889 100644 --- a/include/bm/bluetooth/ble_adv_data.h +++ b/include/bm/bluetooth/ble_adv_data.h @@ -185,9 +185,11 @@ struct ble_adv_data { * @param[out] buf Output buffer. * @param[in,out] len Size of @p buf on input, length of encoded data on output. * - * @retval 0 If the operation was successful. - * @retval -EINVAL Invalid parameter. - * @retval -E2BIG Buffer is too small to encode all data. + * @retval NRF_SUCCESS If the operation was successful. + * @retval NRF_ERROR_INVALID_ADDR Invalid address. + * @retval NRF_ERROR_INVALID_PARAM Invalid parameter provided in the adverising data context. + * @retval NRF_ERROR_NULL @p ble_adv_data, @p buf or @p len is NULL. + * @retval NRF_ERROR_DATA_SIZE Buffer is too small to encode all data. * * @warning This API may override the application's request to use the long name and use a short * name instead. This truncation will occur in case the long name does not fit the provided buffer @@ -199,7 +201,7 @@ struct ble_adv_data { * application can specify, and if the preference is too large to fit in the provided buffer, the * name can be truncated further. */ -int ble_adv_data_encode(const struct ble_adv_data *ble_adv_data, uint8_t *buf, uint16_t *len); +uint32_t ble_adv_data_encode(const struct ble_adv_data *ble_adv_data, uint8_t *buf, uint16_t *len); /** * @brief Search Advertising or Scan Response data for specific data types. 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/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/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/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/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/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/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/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/lib/bluetooth/ble_adv/ble_adv.c b/lib/bluetooth/ble_adv/ble_adv.c index a7bb09dac5..441df0e687 100644 --- a/lib/bluetooth/ble_adv/ble_adv.c +++ b/lib/bluetooth/ble_adv/ble_adv.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ -#include +#include #include "zephyr/toolchain.h" #include #include @@ -72,17 +72,17 @@ static void on_connected(struct ble_adv *ble_adv, ble_evt_t const *ble_evt) static void on_disconnected(struct ble_adv *ble_adv, ble_evt_t const *ble_evt) { - int err; + uint32_t nrf_err; struct ble_adv_evt adv_evt; ble_adv->whitelist_temporarily_disabled = false; if (IS_ENABLED(CONFIG_BLE_ADV_RESTART_ON_DISCONNECT)) { if (ble_evt->evt.gap_evt.conn_handle == ble_adv->conn_handle) { - err = ble_adv_start(ble_adv, BLE_ADV_MODE_DIRECTED_HIGH_DUTY); - if (err) { + nrf_err = ble_adv_start(ble_adv, BLE_ADV_MODE_DIRECTED_HIGH_DUTY); + if (nrf_err != NRF_SUCCESS) { adv_evt.evt_type = BLE_ADV_EVT_ERROR; - adv_evt.error.reason = err; + adv_evt.error.reason = nrf_err; ble_adv->evt_handler(ble_adv, &adv_evt); } } @@ -91,7 +91,7 @@ static void on_disconnected(struct ble_adv *ble_adv, ble_evt_t const *ble_evt) static void on_terminated(struct ble_adv *ble_adv, ble_evt_t const *ble_evt) { - int err; + uint32_t nrf_err; const uint8_t reason = ble_evt->evt.gap_evt.params.adv_set_terminated.reason; struct ble_adv_evt adv_evt; @@ -99,18 +99,18 @@ static void on_terminated(struct ble_adv *ble_adv, ble_evt_t const *ble_evt) if (reason == BLE_GAP_EVT_ADV_SET_TERMINATED_REASON_TIMEOUT || reason == BLE_GAP_EVT_ADV_SET_TERMINATED_REASON_LIMIT_REACHED) { LOG_DBG("Advertising timeout"); - err = ble_adv_start(ble_adv, adv_mode_next(ble_adv->mode_current)); - if (err) { - adv_evt.error.reason = err; + nrf_err = ble_adv_start(ble_adv, adv_mode_next(ble_adv->mode_current)); + if (nrf_err != NRF_SUCCESS) { + adv_evt.error.reason = nrf_err; adv_evt.evt_type = BLE_ADV_EVT_ERROR; ble_adv->evt_handler(ble_adv, &adv_evt); } } } -static int flags_set(struct ble_adv *ble_adv, uint8_t flags) +static uint32_t flags_set(struct ble_adv *ble_adv, uint8_t flags) { - int err; + uint32_t nrf_err; uint8_t *parsed_flags; parsed_flags = ble_adv_data_parse(ble_adv->adv_data.adv_data.p_data, @@ -118,22 +118,22 @@ static int flags_set(struct ble_adv *ble_adv, uint8_t flags) if (!parsed_flags) { LOG_WRN("Unable to find flags in current advertising data"); - return -EINVAL; + return NRF_ERROR_INVALID_PARAM; } *parsed_flags = flags; - err = sd_ble_gap_adv_set_configure(&ble_adv->adv_handle, &ble_adv->adv_data, + nrf_err = sd_ble_gap_adv_set_configure(&ble_adv->adv_handle, &ble_adv->adv_data, &ble_adv->adv_params); - if (err) { - LOG_ERR("Failed to set advertising flags, nrf_error %#x", err); - return -EINVAL; + if (nrf_err != NRF_SUCCESS) { + LOG_ERR("Failed to set advertising flags, nrf_error %#x", nrf_err); + return NRF_ERROR_INVALID_PARAM; } - return 0; + return NRF_SUCCESS; } -static int set_adv_mode_directed_high_duty(struct ble_adv *ble_adv, +static uint32_t set_adv_mode_directed_high_duty(struct ble_adv *ble_adv, ble_gap_adv_params_t *adv_params) { #if CONFIG_BLE_ADV_DIRECTED_ADVERTISING_HIGH_DUTY @@ -143,10 +143,10 @@ static int set_adv_mode_directed_high_duty(struct ble_adv *ble_adv, adv_params->duration = BLE_GAP_ADV_TIMEOUT_HIGH_DUTY_MAX; adv_params->interval = 0; #endif - return 0; + return NRF_SUCCESS; } -static int set_adv_mode_directed(struct ble_adv *ble_adv, ble_gap_adv_params_t *adv_params) +static uint32_t set_adv_mode_directed(struct ble_adv *ble_adv, ble_gap_adv_params_t *adv_params) { #if CONFIG_BLE_ADV_DIRECTED_ADVERTISING #if defined(BLE_GAP_ADV_TYPE_EXTENDED_CONNECTABLE_NONSCANNABLE_DIRECTED) @@ -163,13 +163,13 @@ static int set_adv_mode_directed(struct ble_adv *ble_adv, ble_gap_adv_params_t * adv_params->duration = CONFIG_BLE_ADV_DIRECTED_ADVERTISING_TIMEOUT; adv_params->interval = CONFIG_BLE_ADV_DIRECTED_ADVERTISING_INTERVAL; #endif - return 0; + return NRF_SUCCESS; } -static int set_adv_mode_fast(struct ble_adv *ble_adv, ble_gap_adv_params_t *adv_params) +static uint32_t set_adv_mode_fast(struct ble_adv *ble_adv, ble_gap_adv_params_t *adv_params) { #if CONFIG_BLE_ADV_FAST_ADVERTISING - int err; + uint32_t nrf_err; #if defined(BLE_GAP_ADV_TYPE_EXTENDED_CONNECTABLE_NONSCANNABLE_UNDIRECTED) if (IS_ENABLED(CONFIG_BLE_ADV_EXTENDED_ADVERTISING)) { @@ -188,19 +188,19 @@ static int set_adv_mode_fast(struct ble_adv *ble_adv, ble_gap_adv_params_t *adv_ if (use_whitelist(ble_adv)) { /* Set filter policy and advertising flags */ adv_params->filter_policy = BLE_GAP_ADV_FP_FILTER_CONNREQ; - err = flags_set(ble_adv, BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED); - if (err) { - return err; + nrf_err = flags_set(ble_adv, BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED); + if (nrf_err != NRF_SUCCESS) { + return nrf_err; } } #endif - return 0; + return NRF_SUCCESS; } -static int set_adv_mode_slow(struct ble_adv *ble_adv, ble_gap_adv_params_t *adv_params) +static uint32_t set_adv_mode_slow(struct ble_adv *ble_adv, ble_gap_adv_params_t *adv_params) { #if CONFIG_BLE_ADV_SLOW_ADVERTISING - int err; + uint32_t nrf_err; #if defined(BLE_GAP_ADV_TYPE_EXTENDED_CONNECTABLE_NONSCANNABLE_UNDIRECTED) if (IS_ENABLED(CONFIG_BLE_ADV_EXTENDED_ADVERTISING)) { @@ -220,13 +220,13 @@ static int set_adv_mode_slow(struct ble_adv *ble_adv, ble_gap_adv_params_t *adv_ if (use_whitelist(ble_adv)) { /* Set filter policy and advertising flags */ adv_params->filter_policy = BLE_GAP_ADV_FP_FILTER_CONNREQ; - err = flags_set(ble_adv, BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED); - if (err) { - return err; + nrf_err = flags_set(ble_adv, BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED); + if (nrf_err != NRF_SUCCESS) { + return nrf_err; } } #endif - return 0; + return NRF_SUCCESS; } static uint16_t adv_data_size_max_get(void) @@ -242,27 +242,24 @@ static uint16_t adv_data_size_max_get(void) #endif } -int ble_adv_conn_cfg_tag_set(struct ble_adv *ble_adv, uint8_t ble_cfg_tag) +uint32_t ble_adv_conn_cfg_tag_set(struct ble_adv *ble_adv, uint8_t ble_cfg_tag) { if (!ble_adv) { - return -EFAULT; + return NRF_ERROR_NULL; } ble_adv->conn_cfg_tag = ble_cfg_tag; - return 0; + return NRF_SUCCESS; } -int ble_adv_init(struct ble_adv *ble_adv, struct ble_adv_config *ble_adv_config) +uint32_t ble_adv_init(struct ble_adv *ble_adv, struct ble_adv_config *ble_adv_config) { - int err; + uint32_t nrf_err; ble_gap_conn_sec_mode_t sec_mode = {0}; - if (!ble_adv || !ble_adv_config) { - return -EFAULT; - } - if (!ble_adv_config->evt_handler) { - return -EFAULT; + if (!ble_adv || !ble_adv_config || !ble_adv_config->evt_handler) { + return NRF_ERROR_NULL; } ble_adv->mode_current = BLE_ADV_MODE_IDLE; @@ -274,29 +271,30 @@ int ble_adv_init(struct ble_adv *ble_adv, struct ble_adv_config *ble_adv_config) memset(&ble_adv->peer_address, 0x00, sizeof(ble_adv->peer_address)); BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); - err = sd_ble_gap_device_name_set(&sec_mode, CONFIG_BLE_ADV_NAME, + nrf_err = sd_ble_gap_device_name_set(&sec_mode, CONFIG_BLE_ADV_NAME, strlen(CONFIG_BLE_ADV_NAME)); - if (err) { - LOG_ERR("Failed to set advertising name, nrf_error %#x", err); - return -EINVAL; + if (nrf_err != NRF_SUCCESS) { + LOG_ERR("Failed to set advertising name, nrf_error %#x", nrf_err); + return NRF_ERROR_INVALID_PARAM; } ble_adv->adv_data.adv_data.p_data = ble_adv->enc_adv_data[0]; ble_adv->adv_data.adv_data.len = adv_data_size_max_get(); - err = ble_adv_data_encode(&ble_adv_config->adv_data, ble_adv->enc_adv_data[0], - &ble_adv->adv_data.adv_data.len); - if (err) { - return err; + nrf_err = ble_adv_data_encode(&ble_adv_config->adv_data, ble_adv->enc_adv_data[0], + &ble_adv->adv_data.adv_data.len); + if (nrf_err != NRF_SUCCESS) { + return nrf_err; } ble_adv->adv_data.scan_rsp_data.p_data = ble_adv->enc_scan_rsp_data[0]; ble_adv->adv_data.scan_rsp_data.len = adv_data_size_max_get(); - err = ble_adv_data_encode(&ble_adv_config->sr_data, ble_adv->adv_data.scan_rsp_data.p_data, - &ble_adv->adv_data.scan_rsp_data.len); - if (err) { - return err; + nrf_err = ble_adv_data_encode(&ble_adv_config->sr_data, + ble_adv->adv_data.scan_rsp_data.p_data, + &ble_adv->adv_data.scan_rsp_data.len); + if (nrf_err != NRF_SUCCESS) { + return nrf_err; } /* Configure a initial advertising configuration. The advertising data and parameters @@ -309,26 +307,26 @@ int ble_adv_init(struct ble_adv *ble_adv, struct ble_adv_config *ble_adv_config) ble_adv->adv_params.filter_policy = BLE_GAP_ADV_FP_ANY; ble_adv->adv_params.primary_phy = BLE_GAP_PHY_AUTO; - err = sd_ble_gap_adv_set_configure(&ble_adv->adv_handle, NULL, &ble_adv->adv_params); - if (err) { - LOG_ERR("Failed to set GAP advertising parameters, nrf_error %#x", err); - return -EINVAL; + nrf_err = sd_ble_gap_adv_set_configure(&ble_adv->adv_handle, NULL, &ble_adv->adv_params); + if (nrf_err != NRF_SUCCESS) { + LOG_ERR("Failed to set GAP advertising parameters, nrf_error %#x", nrf_err); + return NRF_ERROR_INVALID_PARAM; } ble_adv->is_initialized = true; - return 0; + return NRF_SUCCESS; } -int ble_adv_start(struct ble_adv *ble_adv, enum ble_adv_mode mode) +uint32_t ble_adv_start(struct ble_adv *ble_adv, enum ble_adv_mode mode) { - int err; + uint32_t nrf_err; struct ble_adv_evt adv_evt; if (!ble_adv) { - return -EFAULT; + return NRF_ERROR_NULL; } if (!ble_adv->is_initialized) { - return -EPERM; + return NRF_ERROR_INVALID_STATE; } ble_adv->whitelist_in_use = false; @@ -373,7 +371,7 @@ int ble_adv_start(struct ble_adv *ble_adv, enum ble_adv_mode mode) LOG_INF("Directed advertising (high duty)"); mode = BLE_ADV_MODE_DIRECTED_HIGH_DUTY; adv_evt.evt_type = BLE_ADV_EVT_DIRECTED_HIGH_DUTY; - err = set_adv_mode_directed_high_duty(ble_adv, &ble_adv->adv_params); + nrf_err = set_adv_mode_directed_high_duty(ble_adv, &ble_adv->adv_params); break; } __fallthrough; @@ -382,7 +380,7 @@ int ble_adv_start(struct ble_adv *ble_adv, enum ble_adv_mode mode) LOG_INF("Directed advertising"); mode = BLE_ADV_MODE_DIRECTED; adv_evt.evt_type = BLE_ADV_EVT_DIRECTED; - err = set_adv_mode_directed(ble_adv, &ble_adv->adv_params); + nrf_err = set_adv_mode_directed(ble_adv, &ble_adv->adv_params); break; } __fallthrough; @@ -391,10 +389,11 @@ int ble_adv_start(struct ble_adv *ble_adv, enum ble_adv_mode mode) LOG_INF("Fast advertising"); mode = BLE_ADV_MODE_FAST; adv_evt.evt_type = BLE_ADV_EVT_FAST; - err = set_adv_mode_fast(ble_adv, &ble_adv->adv_params); - if (err) { - LOG_ERR("Failed to set fast advertising params, error: %d", err); - return -EINVAL; + nrf_err = set_adv_mode_fast(ble_adv, &ble_adv->adv_params); + if (nrf_err != NRF_SUCCESS) { + LOG_ERR("Failed to set fast advertising params, error: %d", + nrf_err); + return NRF_ERROR_INVALID_PARAM; } break; } __fallthrough; @@ -404,10 +403,11 @@ int ble_adv_start(struct ble_adv *ble_adv, enum ble_adv_mode mode) LOG_INF("Slow advertising"); mode = BLE_ADV_MODE_SLOW; adv_evt.evt_type = BLE_ADV_EVT_SLOW; - err = set_adv_mode_slow(ble_adv, &ble_adv->adv_params); - if (err) { - LOG_ERR("Failed to set slow advertising params, error: %d", err); - return -EINVAL; + nrf_err = set_adv_mode_slow(ble_adv, &ble_adv->adv_params); + if (nrf_err != NRF_SUCCESS) { + LOG_ERR("Failed to set slow advertising params, error: %d", + nrf_err); + return NRF_ERROR_INVALID_PARAM; } break; } __fallthrough; @@ -421,23 +421,23 @@ int ble_adv_start(struct ble_adv *ble_adv, enum ble_adv_mode mode) } if (mode != BLE_ADV_MODE_IDLE) { - err = sd_ble_gap_adv_set_configure(&ble_adv->adv_handle, &ble_adv->adv_data, + nrf_err = sd_ble_gap_adv_set_configure(&ble_adv->adv_handle, &ble_adv->adv_data, &ble_adv->adv_params); - if (err) { - LOG_ERR("Failed to set advertising data, nrf_error %#x", err); - return -EINVAL; + if (nrf_err != NRF_SUCCESS) { + LOG_ERR("Failed to set advertising data, nrf_error %#x", nrf_err); + return NRF_ERROR_INVALID_PARAM; } - err = sd_ble_gap_adv_start(ble_adv->adv_handle, ble_adv->conn_cfg_tag); - if (err) { - LOG_ERR("Failed to start advertising, nrf_error %#x", err); - return -EINVAL; + nrf_err = sd_ble_gap_adv_start(ble_adv->adv_handle, ble_adv->conn_cfg_tag); + if (nrf_err != NRF_SUCCESS) { + LOG_ERR("Failed to start advertising, nrf_error %#x", nrf_err); + return NRF_ERROR_INVALID_PARAM; } } ble_adv->mode_current = mode; ble_adv->evt_handler(ble_adv, &adv_evt); - return 0; + return NRF_SUCCESS; } void ble_adv_on_ble_evt(const ble_evt_t *ble_evt, void *instance) @@ -462,44 +462,44 @@ void ble_adv_on_ble_evt(const ble_evt_t *ble_evt, void *instance) } } -int ble_adv_peer_addr_reply(struct ble_adv *ble_adv, const ble_gap_addr_t *peer_addr) +uint32_t ble_adv_peer_addr_reply(struct ble_adv *ble_adv, const ble_gap_addr_t *peer_addr) { if (!ble_adv || !peer_addr) { - return -EFAULT; + return NRF_ERROR_NULL; } if (!ble_adv->peer_addr_reply_expected) { - return -EPERM; + return NRF_ERROR_INVALID_STATE; } if (!peer_addr_is_valid(peer_addr)) { - return -EINVAL; + return NRF_ERROR_INVALID_PARAM; } ble_adv->peer_addr_reply_expected = false; memcpy(&ble_adv->peer_address, peer_addr, sizeof(ble_adv->peer_address)); - return 0; + return NRF_SUCCESS; } -int ble_adv_whitelist_reply(struct ble_adv *ble_adv, - const ble_gap_addr_t *addrs, uint32_t addr_cnt, - const ble_gap_irk_t *irks, uint32_t irk_cnt) +uint32_t ble_adv_whitelist_reply(struct ble_adv *ble_adv, + const ble_gap_addr_t *addrs, uint32_t addr_cnt, + const ble_gap_irk_t *irks, uint32_t irk_cnt) { if (!ble_adv) { - return -EFAULT; + return NRF_ERROR_NULL; } if (!ble_adv->whitelist_reply_expected) { - return -EPERM; + return NRF_ERROR_INVALID_STATE; } ble_adv->whitelist_reply_expected = false; ble_adv->whitelist_in_use = (addr_cnt > 0 || irk_cnt > 0); - return 0; + return NRF_SUCCESS; } -int ble_adv_restart_without_whitelist(struct ble_adv *ble_adv) +uint32_t ble_adv_restart_without_whitelist(struct ble_adv *ble_adv) { - int err; + uint32_t nrf_err; (void)sd_ble_gap_adv_stop(ble_adv->adv_handle); @@ -507,30 +507,30 @@ int ble_adv_restart_without_whitelist(struct ble_adv *ble_adv) ble_adv->adv_params.filter_policy = BLE_GAP_ADV_FP_ANY; /* Set correct flags */ - err = flags_set(ble_adv, BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); - if (err) { - return err; + nrf_err = flags_set(ble_adv, BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); + if (nrf_err != NRF_SUCCESS) { + return nrf_err; } - err = ble_adv_start(ble_adv, ble_adv->mode_current); - if (err) { - return err; + nrf_err = ble_adv_start(ble_adv, ble_adv->mode_current); + if (nrf_err != NRF_SUCCESS) { + return nrf_err; } - return 0; + return NRF_SUCCESS; } -int ble_adv_data_update(struct ble_adv *ble_adv, const struct ble_adv_data *adv_data, +uint32_t ble_adv_data_update(struct ble_adv *ble_adv, const struct ble_adv_data *adv_data, const struct ble_adv_data *sr_data) { - int err; + uint32_t nrf_err; ble_gap_adv_data_t new_adv_data = {0}; if (!ble_adv || (adv_data == NULL && sr_data == NULL)) { - return -EFAULT; + return NRF_ERROR_NULL; } if (!ble_adv->is_initialized) { - return -EPERM; + return NRF_ERROR_INVALID_STATE; } if (adv_data) { @@ -541,10 +541,10 @@ int ble_adv_data_update(struct ble_adv *ble_adv, const struct ble_adv_data *adv_ new_adv_data.adv_data.len = adv_data_size_max_get(); - err = ble_adv_data_encode(adv_data, new_adv_data.adv_data.p_data, + nrf_err = ble_adv_data_encode(adv_data, new_adv_data.adv_data.p_data, &new_adv_data.adv_data.len); - if (err) { - return err; + if (nrf_err != NRF_SUCCESS) { + return nrf_err; } } @@ -556,20 +556,20 @@ int ble_adv_data_update(struct ble_adv *ble_adv, const struct ble_adv_data *adv_ new_adv_data.scan_rsp_data.len = adv_data_size_max_get(); - err = ble_adv_data_encode(sr_data, new_adv_data.scan_rsp_data.p_data, + nrf_err = ble_adv_data_encode(sr_data, new_adv_data.scan_rsp_data.p_data, &new_adv_data.scan_rsp_data.len); - if (err) { - return err; + if (nrf_err != NRF_SUCCESS) { + return nrf_err; } } memcpy(&ble_adv->adv_data, &new_adv_data, sizeof(ble_adv->adv_data)); - err = sd_ble_gap_adv_set_configure(&ble_adv->adv_handle, &ble_adv->adv_data, NULL); - if (err) { - LOG_ERR("Failed to set GAP advertising data, nrf_error %#x", err); - return -EINVAL; + nrf_err = sd_ble_gap_adv_set_configure(&ble_adv->adv_handle, &ble_adv->adv_data, NULL); + if (nrf_err != NRF_SUCCESS) { + LOG_ERR("Failed to set GAP advertising data, nrf_error %#x", nrf_err); + return NRF_ERROR_INVALID_PARAM; } - return 0; + return NRF_SUCCESS; } diff --git a/lib/bluetooth/ble_adv/ble_adv_data.c b/lib/bluetooth/ble_adv/ble_adv_data.c index d1e1a8e15a..3d98f62d4b 100644 --- a/lib/bluetooth/ble_adv/ble_adv_data.c +++ b/lib/bluetooth/ble_adv/ble_adv_data.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ -#include +#include #include #include #include @@ -59,21 +59,21 @@ LOG_MODULE_REGISTER(ble_adv_data); -static int device_addr_encode(uint8_t *buf, uint16_t *offset, uint16_t max_size) +static uint32_t device_addr_encode(uint8_t *buf, uint16_t *offset, uint16_t max_size) { - int err; + uint32_t nrf_err; ble_gap_addr_t device_addr; /* Check for buffer overflow */ if (*offset + AD_TYPE_BLE_DEVICE_ADDR_SIZE > max_size) { - return -E2BIG; + return NRF_ERROR_DATA_SIZE; } /* Get BLE address */ - err = sd_ble_gap_addr_get(&device_addr); - if (err) { - LOG_ERR("Failed to get device GAP address, nrf_error %#x", err); - return -EINVAL; + nrf_err = sd_ble_gap_addr_get(&device_addr); + if (nrf_err) { + LOG_ERR("Failed to get device GAP address, nrf_error %#x", nrf_err); + return NRF_ERROR_INVALID_ADDR; } /* Encode BLE device address */ @@ -96,10 +96,10 @@ static int device_addr_encode(uint8_t *buf, uint16_t *offset, uint16_t max_size) return 0; } -static int device_name_encode(const struct ble_adv_data *ble_adv_data, uint8_t *data, - uint16_t *offset, uint16_t max_size) +static uint32_t device_name_encode(const struct ble_adv_data *ble_adv_data, uint8_t *data, + uint16_t *offset, uint16_t max_size) { - int err; + uint32_t nrf_err; uint16_t rem_adv_data_len; uint16_t actual_length; uint8_t adv_data_format; @@ -107,24 +107,24 @@ static int device_name_encode(const struct ble_adv_data *ble_adv_data, uint8_t * /* Validate parameters */ if ((ble_adv_data->name_type == BLE_ADV_DATA_SHORT_NAME) && (ble_adv_data->short_name_len == 0)) { - return -EINVAL; + return NRF_ERROR_INVALID_PARAM; } /* Check for buffer overflow */ if ((*offset + AD_DATA_OFFSET > max_size) || ((ble_adv_data->name_type == BLE_ADV_DATA_SHORT_NAME) && ((*offset + AD_DATA_OFFSET + ble_adv_data->short_name_len) > max_size))) { - return -E2BIG; + return NRF_ERROR_DATA_SIZE; } rem_adv_data_len = max_size - *offset - AD_DATA_OFFSET; actual_length = rem_adv_data_len; /* Get GAP device name and length */ - err = sd_ble_gap_device_name_get(&data[*offset + AD_DATA_OFFSET], &actual_length); - if (err) { - LOG_ERR("Failed to get device GAP name, nrf_error %#x", err); - return -EINVAL; + nrf_err = sd_ble_gap_device_name_get(&data[*offset + AD_DATA_OFFSET], &actual_length); + if (nrf_err) { + LOG_ERR("Failed to get device GAP name, nrf_error %#x", nrf_err); + return NRF_ERROR_INVALID_PARAM; } /* Check if device intend to use short name and it can fit available data size. @@ -157,7 +157,7 @@ static int device_name_encode(const struct ble_adv_data *ble_adv_data, uint8_t * * (actual_length + AD_TYPE_FIELD_SIZE) */ if (actual_length > (0x00FF - AD_TYPE_FIELD_SIZE)) { - return -E2BIG; + return NRF_ERROR_DATA_SIZE; } /* Complete name field in encoded data. */ @@ -171,21 +171,21 @@ static int device_name_encode(const struct ble_adv_data *ble_adv_data, uint8_t * return 0; } -static int appearance_encode(uint8_t *buf, uint16_t *offset, uint16_t max_size) +static uint32_t appearance_encode(uint8_t *buf, uint16_t *offset, uint16_t max_size) { - int err; + uint32_t nrf_err; uint16_t appearance; /* Check for buffer overflow */ if (*offset + AD_TYPE_APPEARANCE_SIZE > max_size) { - return -E2BIG; + return NRF_ERROR_DATA_SIZE; } /* Get GAP appearance field */ - err = sd_ble_gap_appearance_get(&appearance); - if (err) { - LOG_ERR("Failed to get GAP appearance, nrf_error %#x", err); - return -EINVAL; + nrf_err = sd_ble_gap_appearance_get(&appearance); + if (nrf_err) { + LOG_ERR("Failed to get GAP appearance, nrf_error %#x", nrf_err); + return NRF_ERROR_INVALID_ADDR; } /* Encode Length, AD Type and Appearance */ @@ -201,11 +201,11 @@ static int appearance_encode(uint8_t *buf, uint16_t *offset, uint16_t max_size) return 0; } -static int flags_encode(int8_t flags, uint8_t *buf, uint16_t *offset, uint16_t max_size) +static uint32_t flags_encode(int8_t flags, uint8_t *buf, uint16_t *offset, uint16_t max_size) { /* Check for buffer overflow */ if (*offset + AD_TYPE_FLAGS_SIZE > max_size) { - return -E2BIG; + return NRF_ERROR_DATA_SIZE; } /* Encode flags */ @@ -221,12 +221,12 @@ static int flags_encode(int8_t flags, uint8_t *buf, uint16_t *offset, uint16_t m return 0; } -static int tx_power_level_encode(int8_t tx_power_level, uint8_t *buf, uint16_t *offset, - uint16_t max_size) +static uint32_t tx_power_level_encode(int8_t tx_power_level, uint8_t *buf, uint16_t *offset, + uint16_t max_size) { /* Check for buffer overflow */ if (*offset + AD_TYPE_TX_POWER_LEVEL_SIZE > max_size) { - return -E2BIG; + return NRF_ERROR_DATA_SIZE; } /* Encode TX Power Level */ @@ -242,11 +242,11 @@ static int tx_power_level_encode(int8_t tx_power_level, uint8_t *buf, uint16_t * return 0; } -static int uuid_list_sized_encode(const struct ble_adv_data_uuid_list *list, uint8_t adv_type, - uint8_t uuid_size, uint8_t *buf, uint16_t *offset, - uint16_t max_size) +static uint32_t uuid_list_sized_encode(const struct ble_adv_data_uuid_list *list, uint8_t adv_type, + uint8_t uuid_size, uint8_t *buf, uint16_t *offset, + uint16_t max_size) { - int err; + uint32_t nrf_err; bool is_heading_written = false; uint16_t start_pos = *offset; uint16_t length; @@ -256,10 +256,10 @@ static int uuid_list_sized_encode(const struct ble_adv_data_uuid_list *list, uin ble_uuid_t uuid = list->uuid[i]; /* Find encoded uuid size */ - err = sd_ble_uuid_encode(&uuid, &encoded_size, NULL); - if (err) { - LOG_ERR("Failed to encode UUID, nrf_error %#x", err); - return -EINVAL; + nrf_err = sd_ble_uuid_encode(&uuid, &encoded_size, NULL); + if (nrf_err) { + LOG_ERR("Failed to encode UUID, nrf_error %#x", nrf_err); + return nrf_err; } /* Check size */ @@ -268,7 +268,7 @@ static int uuid_list_sized_encode(const struct ble_adv_data_uuid_list *list, uin /* Check for buffer overflow */ if ((*offset + encoded_size + heading_bytes) > max_size) { - return -E2BIG; + return NRF_ERROR_DATA_SIZE; } if (!is_heading_written) { @@ -280,10 +280,10 @@ static int uuid_list_sized_encode(const struct ble_adv_data_uuid_list *list, uin } /* Write UUID */ - err = sd_ble_uuid_encode(&uuid, &encoded_size, &buf[*offset]); - if (err) { - LOG_ERR("Failed to encode UUID, nrf_error %#x", err); - return -EINVAL; + nrf_err = sd_ble_uuid_encode(&uuid, &encoded_size, &buf[*offset]); + if (nrf_err) { + LOG_ERR("Failed to encode UUID, nrf_error %#x", nrf_err); + return nrf_err; } *offset += encoded_size; @@ -294,7 +294,7 @@ static int uuid_list_sized_encode(const struct ble_adv_data_uuid_list *list, uin /* The length field does not count itself. */ length = *offset - (start_pos + AD_LENGTH_FIELD_SIZE); if (length > 0x00FF) { - return -E2BIG; + return NRF_ERROR_DATA_SIZE; } buf[start_pos] = (uint8_t)length; } @@ -302,56 +302,57 @@ static int uuid_list_sized_encode(const struct ble_adv_data_uuid_list *list, uin return 0; } -static int uuid_list_encode(const struct ble_adv_data_uuid_list *list, uint8_t adv_type_16, - uint8_t adv_type_128, uint8_t *buf, uint16_t *offset, uint16_t max_size) +static uint32_t uuid_list_encode(const struct ble_adv_data_uuid_list *list, uint8_t adv_type_16, + uint8_t adv_type_128, uint8_t *buf, uint16_t *offset, + uint16_t max_size) { - int err; + uint32_t nrf_err; /* Encode 16 bit UUIDs */ - err = uuid_list_sized_encode(list, adv_type_16, UUID16_SIZE, buf, offset, max_size); - if (err) { - return err; + nrf_err = uuid_list_sized_encode(list, adv_type_16, UUID16_SIZE, buf, offset, max_size); + if (nrf_err) { + return nrf_err; } /* Encode 128 bit UUIDs */ - err = uuid_list_sized_encode(list, adv_type_128, UUID128_SIZE, buf, offset, max_size); - if (err) { - return err; + nrf_err = uuid_list_sized_encode(list, adv_type_128, UUID128_SIZE, buf, offset, max_size); + if (nrf_err) { + return nrf_err; } return 0; } -static int conn_int_check(const struct ble_adv_data_conn_int *conn_interval) +static uint32_t conn_int_check(const struct ble_adv_data_conn_int *conn_interval) { /* Check Minimum Connection Interval */ if ((conn_interval->min_conn_interval < 0x0006) || ((conn_interval->min_conn_interval > 0x0c80) && (conn_interval->min_conn_interval != 0xffff))) { - return -EINVAL; + return NRF_ERROR_INVALID_PARAM; } /* Check Maximum Connection Interval */ if ((conn_interval->max_conn_interval < 0x0006) || ((conn_interval->max_conn_interval > 0x0c80) && (conn_interval->max_conn_interval != 0xffff))) { - return -EINVAL; + return NRF_ERROR_INVALID_PARAM; } /* Check Minimum Connection Interval is smaller than Maximum Connection Interval */ if ((conn_interval->min_conn_interval != 0xffff) && (conn_interval->max_conn_interval != 0xffff) && (conn_interval->min_conn_interval > conn_interval->max_conn_interval)) { - return -EINVAL; + return NRF_ERROR_INVALID_PARAM; } return 0; } -static int conn_int_encode(const struct ble_adv_data_conn_int *conn_int, uint8_t *buf, - uint16_t *offset, uint16_t max_size) +static uint32_t conn_int_encode(const struct ble_adv_data_conn_int *conn_int, uint8_t *buf, + uint16_t *offset, uint16_t max_size) { - int err; + uint32_t nrf_err; /* Check for buffer overflow */ if (*offset + AD_TYPE_CONN_INT_SIZE > max_size) { @@ -359,9 +360,9 @@ static int conn_int_encode(const struct ble_adv_data_conn_int *conn_int, uint8_t } /* Check parameter */ - err = conn_int_check(conn_int); - if (err) { - return err; + nrf_err = conn_int_check(conn_int); + if (nrf_err) { + return nrf_err; } /* Encode Length and AD Type */ @@ -380,19 +381,19 @@ static int conn_int_encode(const struct ble_adv_data_conn_int *conn_int, uint8_t return 0; } -static int manuf_specific_data_encode(const struct ble_adv_data_manufacturer *manuf_data, uint8_t *buf, - uint16_t *offset, uint16_t max_size) +static uint32_t manuf_specific_data_encode(const struct ble_adv_data_manufacturer *manuf_data, + uint8_t *buf, uint16_t *offset, uint16_t max_size) { uint32_t data_size = AD_TYPE_MANUF_SPEC_DATA_ID_SIZE + manuf_data->len; /* Check for buffer overflow */ if ((*offset + AD_DATA_OFFSET + data_size) > max_size) { - return -E2BIG; + return NRF_ERROR_DATA_SIZE; } /* There is only 1 byte intended to encode length which is (data_size + AD_TYPE_FIELD_SIZE) */ if (data_size > (0x00FF - AD_TYPE_FIELD_SIZE)) { - return -E2BIG; + return NRF_ERROR_DATA_SIZE; } /* Encode Length and AD Type */ @@ -407,8 +408,8 @@ static int manuf_specific_data_encode(const struct ble_adv_data_manufacturer *ma /* Encode additional manufacturer specific data */ if (manuf_data->len > 0) { - if (manuf_data->data == NULL) { - return -EINVAL; + if (!manuf_data->data) { + return NRF_ERROR_NULL; } memcpy(&buf[*offset], manuf_data->data, manuf_data->len); *offset += manuf_data->len; @@ -418,15 +419,15 @@ static int manuf_specific_data_encode(const struct ble_adv_data_manufacturer *ma } /* Implemented only for 16-bit UUIDs */ -static int service_data_encode(const struct ble_adv_data *ble_adv_data, uint8_t *buf, - uint16_t *offset, uint16_t max_size) +static uint32_t service_data_encode(const struct ble_adv_data *ble_adv_data, uint8_t *buf, + uint16_t *offset, uint16_t max_size) { uint32_t data_size; struct ble_adv_data_service *service_data; /* Check parameter consistency */ - if (ble_adv_data->srv_list.service == NULL) { - return -EFAULT; + if (!ble_adv_data->srv_list.service) { + return NRF_ERROR_NULL; } for (uint8_t i = 0; i < ble_adv_data->srv_list.len; i++) { @@ -454,8 +455,8 @@ static int service_data_encode(const struct ble_adv_data *ble_adv_data, uint8_t /* Encode additional service data */ if (service_data->len > 0) { - if (service_data->data == NULL) { - return -EINVAL; + if (!service_data->data) { + return NRF_ERROR_NULL; } memcpy(&buf[*offset], service_data->data, service_data->len); *offset += service_data->len; @@ -465,103 +466,107 @@ static int service_data_encode(const struct ble_adv_data *ble_adv_data, uint8_t return 0; } -int ble_adv_data_encode(const struct ble_adv_data *ble_adv_data, uint8_t *buf, uint16_t *len) +uint32_t ble_adv_data_encode(const struct ble_adv_data *ble_adv_data, uint8_t *buf, uint16_t *len) { - int err; + uint32_t nrf_err; uint16_t max_size; - err = 0; + nrf_err = NRF_SUCCESS; max_size = *len; *len = 0; + if (!ble_adv_data || !buf || !len) { + return NRF_ERROR_NULL; + } + /* Encode LE Bluetooth Device Address */ if (ble_adv_data->include_ble_device_addr) { - err = device_addr_encode(buf, len, max_size); - if (err) { - return err; + nrf_err = device_addr_encode(buf, len, max_size); + if (nrf_err) { + return nrf_err; } } /* Encode appearance */ if (ble_adv_data->include_appearance) { - err = appearance_encode(buf, len, max_size); - if (err) { - return err; + nrf_err = appearance_encode(buf, len, max_size); + if (nrf_err) { + return nrf_err; } } /* Encode Flag */ if (ble_adv_data->flags != 0) { - err = flags_encode(ble_adv_data->flags, buf, len, max_size); - if (err) { - return err; + nrf_err = flags_encode(ble_adv_data->flags, buf, len, max_size); + if (nrf_err) { + return nrf_err; } } /* Encode TX power level */ if (ble_adv_data->tx_power_level != NULL) { - err = tx_power_level_encode(*ble_adv_data->tx_power_level, buf, len, max_size); - if (err) { - return err; + nrf_err = tx_power_level_encode(*ble_adv_data->tx_power_level, buf, len, max_size); + if (nrf_err) { + return nrf_err; } } /* Encode 'more available' uuid list */ if (ble_adv_data->uuid_lists.more_available.len > 0) { - err = uuid_list_encode(&ble_adv_data->uuid_lists.more_available, + nrf_err = uuid_list_encode(&ble_adv_data->uuid_lists.more_available, BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_MORE_AVAILABLE, BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_MORE_AVAILABLE, buf, len, max_size); - if (err) { - return err; + if (nrf_err) { + return nrf_err; } } /* Encode 'complete' uuid list */ if (ble_adv_data->uuid_lists.complete.len > 0) { - err = uuid_list_encode( + nrf_err = uuid_list_encode( &ble_adv_data->uuid_lists.complete, BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_COMPLETE, BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_COMPLETE, buf, len, max_size); - if (err) { - return err; + if (nrf_err) { + return nrf_err; } } /* Encode 'solicited service' uuid list */ if (ble_adv_data->uuid_lists.solicited.len > 0) { - err = uuid_list_encode(&ble_adv_data->uuid_lists.solicited, + nrf_err = uuid_list_encode(&ble_adv_data->uuid_lists.solicited, BLE_GAP_AD_TYPE_SOLICITED_SERVICE_UUIDS_16BIT, BLE_GAP_AD_TYPE_SOLICITED_SERVICE_UUIDS_128BIT, buf, len, max_size); - if (err) { - return err; + if (nrf_err) { + return nrf_err; } } /* Encode Slave Connection Interval Range */ if (ble_adv_data->slave_conn_int != NULL) { - err = conn_int_encode(ble_adv_data->slave_conn_int, buf, len, max_size); - if (err) { - return err; + nrf_err = conn_int_encode(ble_adv_data->slave_conn_int, buf, len, max_size); + if (nrf_err) { + return nrf_err; } } /* Encode Manufacturer Specific Data */ if (ble_adv_data->manufacturer_data != NULL) { - err = manuf_specific_data_encode(ble_adv_data->manufacturer_data, buf, len, + nrf_err = manuf_specific_data_encode(ble_adv_data->manufacturer_data, buf, len, max_size); - if (err) { - return err; + if (nrf_err) { + return nrf_err; } } /* Encode Service Data */ if (ble_adv_data->srv_list.len > 0) { - err = service_data_encode(ble_adv_data, buf, len, max_size); - if (err) { - return err; + nrf_err = service_data_encode(ble_adv_data, buf, len, max_size); + if (nrf_err) { + return nrf_err; } } /* Encode name. It is encoded last on purpose since too long device name is truncated */ if (ble_adv_data->name_type != BLE_ADV_DATA_NO_NAME) { - err = device_name_encode(ble_adv_data, buf, len, max_size); - if (err) { - return err; + nrf_err = device_name_encode(ble_adv_data, buf, len, max_size); + if (nrf_err) { + return nrf_err; } } - return err; + return nrf_err; } uint16_t ble_adv_data_search(const uint8_t *data, uint16_t data_len, uint16_t *offset, @@ -668,7 +673,7 @@ bool ble_adv_data_short_name_find(const uint8_t *data, uint16_t data_len, const bool ble_adv_data_uuid_find(const uint8_t *data, uint16_t data_len, const ble_uuid_t *uuid) { - int err; + uint32_t nrf_err; uint16_t data_offset; uint8_t raw_uuid_len; uint16_t parsed_uuid_len = data_len; @@ -679,8 +684,8 @@ bool ble_adv_data_uuid_find(const uint8_t *data, uint16_t data_len, const ble_uu return false; } - err = sd_ble_uuid_encode(uuid, &raw_uuid_len, raw_uuid); - if (err) { + nrf_err = sd_ble_uuid_encode(uuid, &raw_uuid_len, raw_uuid); + if (nrf_err != NRF_SUCCESS) { /* Invalid encoded data or target UUID */ return false; } 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..2b5f5fd703 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 NRF_ERROR_INVALID_PARAM; } 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_ERROR_INVALID_PARAM; } - 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/lib/bluetooth/ble_gq/gatt_queue.c b/lib/bluetooth/ble_gq/gatt_queue.c index 1c655c0276..72526b9d73 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 @@ -31,11 +31,11 @@ LOG_MODULE_REGISTER(ble_gatt_queue, CONFIG_BLE_GQ_LOG_LEVEL); * 0 if successful. * -ENOMEM 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, +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, +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; @@ -43,8 +43,8 @@ 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; + if (!data) { + return NRF_ERROR_NO_MEM; } LOG_DBG("Allocated heap memory with addr: %#lx", (uintptr_t)data); @@ -59,11 +59,11 @@ 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, +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; @@ -72,8 +72,8 @@ static int gatts_hvx_store(struct k_heap *data_pool, const struct ble_gq_req *re /* Allocate additional memory for GATTS notification or indication request data. */ data = k_heap_aligned_alloc(data_pool, sizeof(void *), *gatts_hvx->p_len + sizeof(uint16_t), K_NO_WAIT); - if (data == NULL) { - return -ENOMEM; + if (!data) { + 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. */ @@ -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; @@ -297,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; @@ -311,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; + if (!gq || !req) { + return NRF_ERROR_NULL; } /* Purge queues that are no longer used by any connection. */ @@ -334,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. */ @@ -342,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; } } @@ -352,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. */ @@ -373,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; + if (!gq) { + 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/lib/bluetooth/ble_qwr/ble_qwr.c b/lib/bluetooth/ble_qwr/ble_qwr.c index 791a8428d5..6584e5f960 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; } /** @@ -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, + 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 = {}; struct ble_qwr_evt evt = {}; @@ -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 = {}; 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 = {}; 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 = {}; #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/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/samples/bluetooth/ble_cgms/src/main.c b/samples/bluetooth/ble_cgms/src/main.c index e1c2b7d692..a4cfa2eb86 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 != -ENOTCONN && nrf_err != -EPIPE) { + LOG_ERR("Failed to update battery level, nrf_error %#x", nrf_err); } } } @@ -165,7 +166,7 @@ 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) { + if (nrf_err) { LOG_ERR("Failed to update BLE CGMS status, nrf_error %d", nrf_err); } } @@ -207,7 +208,7 @@ static int 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) { + if (nrf_err) { LOG_ERR("Failed to set GAP appearance, nrf_error %d", nrf_err); return -1; } @@ -297,7 +298,6 @@ uint16_t qwr_evt_handler(struct ble_qwr *qwr, const struct ble_qwr_evt *evt) */ static int services_init(void) { - int err; uint32_t nrf_err; struct ble_cgms_config cgms_config = { .evt_handler = cgms_evt_handler, @@ -330,17 +330,17 @@ static int 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 */ ble_cgms.comm_interval = CONFIG_GLUCOSE_MEAS_INTERVAL; nrf_err = ble_cgms_init(&ble_cgms, &cgms_config); - if (nrf_err != NRF_SUCCESS) { + if (nrf_err) { LOG_ERR("Failed to initialize CGMS service, nrf_error %d", nrf_err); return -EIO; } @@ -349,16 +349,16 @@ static int 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. */ - err = ble_dis_init(); - if (err) { - LOG_ERR("Failed to initialize DIS service, err %d", err); + nrf_err = ble_dis_init(); + if (nrf_err) { + LOG_ERR("Failed to initialize DIS service, nrf_error %#x", nrf_err); return -1; } @@ -421,7 +421,7 @@ 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) { + if (nrf_err) { LOG_ERR("Failed to disconnect BLE GAP, nrf_error %d", nrf_err); } LOG_ERR("Disconnected from peer, unacceptable conn params"); @@ -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,18 +450,18 @@ 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); - if (nrf_err != NRF_SUCCESS) { + if (nrf_err) { LOG_ERR("Failed to assign BLE CGMS conn handle, nrf_error %d", nrf_err); } nrf_err = sd_ble_gatts_sys_attr_set(conn_handle, NULL, 0, 0); - if (nrf_err != NRF_SUCCESS) { + if (nrf_err) { LOG_ERR("Failed to set system attributes, nrf_error %d", nrf_err); } @@ -478,7 +478,7 @@ 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) { + if (nrf_err) { LOG_ERR("Failed to disconnect GAP, nrf_error %d", nrf_err); } break; @@ -492,7 +492,7 @@ 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) { + if (nrf_err) { LOG_ERR("Failed to set system attributes, nrf_error %d", nrf_err); } break; @@ -501,7 +501,7 @@ 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) { + if (nrf_err) { LOG_ERR("Failed to disconnect GAP, nrf_error %d", nrf_err); } break; @@ -521,8 +521,8 @@ static void ble_adv_evt_handler(struct ble_adv *adv, const struct ble_adv_evt *a { switch (adv_evt->evt_type) { case BLE_ADV_EVT_ERROR: - LOG_ERR("BLE advertising error, %d", adv_evt->error.reason); - __ASSERT(false, "BLE advertising error %d", adv_evt->error.reason); + LOG_ERR("BLE advertising error, %#x", adv_evt->error.reason); + __ASSERT(false, "BLE advertising error %#x", adv_evt->error.reason); break; case BLE_ADV_EVT_DIRECTED_HIGH_DUTY: led_indication_set(LED_INDICATE_ADVERTISING_DIRECTED); @@ -614,7 +614,7 @@ static void button_handler(uint8_t pin, uint8_t action) } /** @brief Function for initializing the Advertising functionality. */ -static int advertising_init(void) +static uint32_t advertising_init(void) { int err; uint8_t adv_flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; @@ -637,8 +637,8 @@ static int advertising_init(void) }; err = ble_adv_init(&ble_adv, &config); - if (err) { - LOG_ERR("BLE advertising init failed, err %d", err); + if (err != NRF_SUCCESS) { + LOG_ERR("BLE advertising init failed, nrf_error %#x", err); return err; } @@ -713,6 +713,7 @@ static int buttons_leds_init(bool *erase_bonds) int main(void) { int err; + uint32_t nrf_err; bool erase_bonds; err = timers_init(); @@ -731,19 +732,19 @@ int main(void) if (err) { goto idle; } - err = advertising_init(); - if (err) { + nrf_err = advertising_init(); + if (nrf_err) { goto idle; } - err = services_init(); - if (err) { + nrf_err = services_init(); + if (nrf_err) { goto idle; } (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; } @@ -753,9 +754,9 @@ int main(void) goto idle; } - err = ble_adv_start(&ble_adv, BLE_ADV_MODE_FAST); - if (err) { - LOG_ERR("Failed to start advertising, err %d", err); + nrf_err = ble_adv_start(&ble_adv, BLE_ADV_MODE_FAST); + if (nrf_err) { + LOG_ERR("Failed to start advertising, nrf_error %#x", nrf_err); goto idle; } diff --git a/samples/bluetooth/ble_hids_keyboard/src/main.c b/samples/bluetooth/ble_hids_keyboard/src/main.c index d6e34e9e69..e61b43c51c 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); } } @@ -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 != -ENOTCONN && nrf_err != -EPIPE) { + LOG_ERR("Failed to update battery level, nrf_error %#x", nrf_err); } } } @@ -246,7 +247,7 @@ NRF_SDH_BLE_OBSERVER(sdh_ble, on_ble_evt, NULL, 0); static void ble_adv_evt_handler(struct ble_adv *ble_adv, const struct ble_adv_evt *evt) { - uint32_t err; + uint32_t nrf_err; ble_gap_addr_t *peer_addr; ble_gap_addr_t whitelist_addrs[BLE_GAP_WHITELIST_ADDR_MAX_COUNT]; ble_gap_irk_t whitelist_irks[BLE_GAP_WHITELIST_ADDR_MAX_COUNT]; @@ -255,7 +256,7 @@ static void ble_adv_evt_handler(struct ble_adv *ble_adv, const struct ble_adv_ev switch (evt->evt_type) { case BLE_ADV_EVT_ERROR: - LOG_ERR("Advertising error %d", evt->error.reason); + LOG_ERR("Advertising error %#x", evt->error.reason); break; case BLE_ADV_EVT_DIRECTED_HIGH_DUTY: case BLE_ADV_EVT_DIRECTED: @@ -269,10 +270,10 @@ 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: - err = pm_whitelist_get(whitelist_addrs, &addr_cnt, + nrf_err = pm_whitelist_get(whitelist_addrs, &addr_cnt, whitelist_irks, &irk_cnt); - if (err) { - LOG_ERR("Failed to get whitelist, nrf_error %#x", err); + if (nrf_err) { + LOG_ERR("Failed to get whitelist, nrf_error %#x", nrf_err); } LOG_DBG("pm_whitelist_get returns %d addr in whitelist and %d irk whitelist", addr_cnt, irk_cnt); @@ -282,10 +283,10 @@ static void ble_adv_evt_handler(struct ble_adv *ble_adv, const struct ble_adv_ev */ identities_set(PM_PEER_ID_LIST_SKIP_NO_IRK); - err = ble_adv_whitelist_reply(ble_adv, whitelist_addrs, addr_cnt, whitelist_irks, - irk_cnt); - if (err) { - LOG_ERR("Failed to set whitelist, nrf_error %#x", err); + nrf_err = ble_adv_whitelist_reply(ble_adv, whitelist_addrs, addr_cnt, + whitelist_irks, irk_cnt); + if (nrf_err) { + LOG_ERR("Failed to set whitelist, nrf_error %#x", nrf_err); } break; @@ -294,10 +295,11 @@ static void ble_adv_evt_handler(struct ble_adv *ble_adv, const struct ble_adv_ev /* Only Give peer address if we have a handle to the bonded peer. */ if (peer_id != PM_PEER_ID_INVALID) { - err = pm_peer_data_bonding_load(peer_id, &peer_bonding_data); - if (err != NRF_ERROR_NOT_FOUND) { - if (err) { - LOG_ERR("Failed to load bonding data, nrf_error %#x", err); + nrf_err = pm_peer_data_bonding_load(peer_id, &peer_bonding_data); + if (nrf_err != NRF_ERROR_NOT_FOUND) { + if (nrf_err) { + LOG_ERR("Failed to load bonding data, nrf_error %#x", + nrf_err); } /* Manipulate identities to exclude peers with no @@ -306,9 +308,10 @@ static void ble_adv_evt_handler(struct ble_adv *ble_adv, const struct ble_adv_ev identities_set(PM_PEER_ID_LIST_SKIP_ALL); peer_addr = &(peer_bonding_data.peer_ble_id.id_addr_info); - err = ble_adv_peer_addr_reply(ble_adv, peer_addr); - if (err) { - LOG_ERR("Failed to reply peer address, nrf_error %#x", err); + nrf_err = ble_adv_peer_addr_reply(ble_adv, peer_addr); + if (nrf_err) { + LOG_ERR("Failed to reply peer address, nrf_error %#x", + nrf_err); } } } @@ -320,7 +323,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; @@ -333,11 +336,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, + nrf_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); + if (nrf_err) { + LOG_ERR("ble_hids_outp_rep_get failed, nrf_error %#x", nrf_err); return; } @@ -580,7 +583,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); } @@ -593,7 +596,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); @@ -603,9 +606,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); } } @@ -665,69 +668,69 @@ static void button_handler(uint8_t pin, uint8_t action) static void whitelist_set(pm_peer_id_list_skip_t skip) { - uint32_t err; + uint32_t nrf_err; pm_peer_id_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(pm_peer_id_list_skip_t skip) { - uint32_t err; + uint32_t nrf_err; pm_peer_id_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) { - int err = 0; + uint32_t nrf_err = 0; if (erase_bonds) { delete_bonds(); } else { whitelist_set(PM_PEER_ID_LIST_SKIP_NO_ID_ADDR); - err = ble_adv_start(&ble_adv, BLE_ADV_MODE_FAST); - if (err) { - LOG_ERR("Failed to start advertising, err %d", err); + nrf_err = ble_adv_start(&ble_adv, BLE_ADV_MODE_FAST); + if (nrf_err) { + LOG_ERR("Failed to start advertising, nrf_error %#x", nrf_err); } } - return err; + return nrf_err; } static void pm_evt_handler(pm_evt_t const *evt) @@ -765,10 +768,10 @@ static void pm_evt_handler(pm_evt_t const *evt) static int peer_manager_init(void) { ble_gap_sec_params_t sec_param; - int err; + int nrf_err; - err = pm_init(); - if (err) { + nrf_err = pm_init(); + if (nrf_err) { return -EFAULT; } @@ -790,15 +793,15 @@ 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); + nrf_err = pm_sec_params_set(&sec_param); + if (nrf_err) { + LOG_ERR("pm_sec_params_set() failed, nrf_error %#x", nrf_err); return -EFAULT; } - err = pm_register(pm_evt_handler); - if (err) { - LOG_ERR("pm_register() failed, err: %d", err); + nrf_err = pm_register(pm_evt_handler); + if (nrf_err) { + LOG_ERR("pm_register() failed, nrf_error %#x", nrf_err); return -EFAULT; } @@ -948,26 +951,26 @@ 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; } - 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; } - 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; } nrf_err = hids_init(); - if (nrf_err != NRF_SUCCESS) { + if (nrf_err) { LOG_ERR("Failed to initialize HIDS, nrf_error %#x", err); goto idle; } @@ -980,9 +983,9 @@ int main(void) goto idle; } - err = ble_adv_init(&ble_adv, &ble_adv_cfg); - if (err) { - LOG_ERR("Failed to initialize BLE advertising, err %d", err); + nrf_err = ble_adv_init(&ble_adv, &ble_adv_cfg); + if (nrf_err) { + LOG_ERR("Failed to initialize BLE 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 ec0f086d2d..f3249d3938 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,27 +113,27 @@ 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 != -ENOTCONN && nrf_err != -EPIPE) { + LOG_ERR("Failed to update battery level, nrf_error %#x", nrf_err); } } } static void on_ble_evt(const ble_evt_t *evt, void *ctx) { - uint32_t 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; } @@ -171,7 +172,7 @@ NRF_SDH_BLE_OBSERVER(sdh_ble, on_ble_evt, NULL, 0); static void ble_adv_evt_handler(struct ble_adv *ble_adv, const struct ble_adv_evt *evt) { - uint32_t err; + uint32_t nrf_err; ble_gap_addr_t *peer_addr; pm_peer_data_bonding_t peer_bonding_data; ble_gap_addr_t whitelist_addrs[BLE_GAP_WHITELIST_ADDR_MAX_COUNT]; @@ -181,7 +182,7 @@ static void ble_adv_evt_handler(struct ble_adv *ble_adv, const struct ble_adv_ev switch (evt->evt_type) { case BLE_ADV_EVT_ERROR: - LOG_ERR("Advertising error %d", evt->error.reason); + LOG_ERR("Advertising error %#x", evt->error.reason); break; case BLE_ADV_EVT_DIRECTED_HIGH_DUTY: case BLE_ADV_EVT_DIRECTED: @@ -195,9 +196,9 @@ 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: - err = pm_whitelist_get(whitelist_addrs, &addr_cnt, whitelist_irks, &irk_cnt); - if (err) { - LOG_ERR("Failed to get whitelist, nrf_error %#x", err); + 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); } LOG_DBG("pm_whitelist_get returns %d addr in whitelist and %d irk whitelist", addr_cnt, irk_cnt); @@ -207,20 +208,21 @@ static void ble_adv_evt_handler(struct ble_adv *ble_adv, const struct ble_adv_ev */ identities_set(PM_PEER_ID_LIST_SKIP_NO_IRK); - err = ble_adv_whitelist_reply(ble_adv, whitelist_addrs, addr_cnt, whitelist_irks, - irk_cnt); - if (err) { - LOG_ERR("Failed to set whitelist, nrf_error %#x", err); + nrf_err = ble_adv_whitelist_reply(ble_adv, whitelist_addrs, addr_cnt, + whitelist_irks, irk_cnt); + if (nrf_err) { + LOG_ERR("Failed to set whitelist, nrf_error %#x", nrf_err); } break; case BLE_ADV_EVT_PEER_ADDR_REQUEST: /* Only Give peer address if we have a handle to the bonded peer. */ if (peer_id != PM_PEER_ID_INVALID) { - err = pm_peer_data_bonding_load(peer_id, &peer_bonding_data); - if (err != NRF_ERROR_NOT_FOUND) { - if (err) { - LOG_ERR("Failed to load bonding data, nrf_error %#x", err); + nrf_err = pm_peer_data_bonding_load(peer_id, &peer_bonding_data); + if (nrf_err != NRF_ERROR_NOT_FOUND) { + if (nrf_err) { + LOG_ERR("Failed to load bonding data, nrf_error %#x", + nrf_err); } /* Manipulate identities to exclude peers with no @@ -229,9 +231,10 @@ static void ble_adv_evt_handler(struct ble_adv *ble_adv, const struct ble_adv_ev identities_set(PM_PEER_ID_LIST_SKIP_ALL); peer_addr = &(peer_bonding_data.peer_ble_id.id_addr_info); - err = ble_adv_peer_addr_reply(ble_adv, peer_addr); - if (err) { - LOG_ERR("Failed to reply peer address, nrf_error %#x", err); + nrf_err = ble_adv_peer_addr_reply(ble_adv, peer_addr); + if (nrf_err) { + LOG_ERR("Failed to reply peer address, nrf_error %#x", + nrf_err); } } } @@ -454,7 +457,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); } } @@ -462,7 +465,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); @@ -472,9 +475,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; @@ -516,69 +519,69 @@ static void button_handler(uint8_t pin, uint8_t action) static void whitelist_set(pm_peer_id_list_skip_t skip) { - uint32_t err; + uint32_t nrf_err; pm_peer_id_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(pm_peer_id_list_skip_t skip) { - uint32_t err; + uint32_t nrf_err; pm_peer_id_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 err = NRF_SUCCESS; + int nrf_err = NRF_SUCCESS; if (erase_bonds) { delete_bonds(); } else { whitelist_set(PM_PEER_ID_LIST_SKIP_NO_ID_ADDR); - err = ble_adv_start(&ble_adv, BLE_ADV_MODE_FAST); - if (err) { - LOG_ERR("Failed to start advertising, err %d", err); + nrf_err = ble_adv_start(&ble_adv, BLE_ADV_MODE_FAST); + if (nrf_err) { + LOG_ERR("Failed to start advertising, nrf_error %#x", nrf_err); } } - return err; + return nrf_err; } static void pm_evt_handler(pm_evt_t const *evt) @@ -615,10 +618,10 @@ static void pm_evt_handler(pm_evt_t const *evt) static int peer_manager_init(void) { ble_gap_sec_params_t sec_param; - int err; + int nrf_err; - err = pm_init(); - if (err) { + nrf_err = pm_init(); + if (nrf_err) { return -EFAULT; } @@ -640,15 +643,15 @@ 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); + nrf_err = pm_sec_params_set(&sec_param); + if (nrf_err) { + LOG_ERR("pm_sec_params_set() failed, nrf_error %#x", nrf_err); return -EFAULT; } - err = pm_register(pm_evt_handler); - if (err) { - LOG_ERR("pm_register() failed, err: %d", err); + nrf_err = pm_register(pm_evt_handler); + if (nrf_err) { + LOG_ERR("pm_register() failed, nrf_error %#x", nrf_err); return -EFAULT; } @@ -796,35 +799,35 @@ 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_err %#x", nrf_err); 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; } - 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; } 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; } LOG_INF("HIDS initialized"); - err = ble_adv_init(&ble_adv, &ble_adv_cfg); - if (err) { - LOG_ERR("Failed to initialize BLE advertising, err %d", err); + nrf_err = ble_adv_init(&ble_adv, &ble_adv_cfg); + if (nrf_err) { + LOG_ERR("Failed to initialize BLE 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 f73d0293d0..cd3428d22c 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 != -ENOTCONN && nrf_err != -EPIPE) { + LOG_ERR("Failed to update battery level, nrf_error %#x", nrf_err); } } } @@ -94,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); @@ -104,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 != -ENOTCONN && nrf_err != -EPIPE) { + LOG_ERR("Failed to update heart rate measurement, nrf_error %#x", nrf_err); } } @@ -122,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); @@ -137,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); } } } @@ -147,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; + int 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); } } @@ -282,7 +285,7 @@ static void ble_adv_evt_handler(struct ble_adv *adv, const struct ble_adv_evt *a { switch (adv_evt->evt_type) { case BLE_ADV_EVT_ERROR: - LOG_ERR("Advertising error %d", adv_evt->error.reason); + LOG_ERR("Advertising error %#x", adv_evt->error.reason); break; default: break; @@ -352,26 +355,26 @@ 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 err; + int nrf_err; if (erase_bonds) { delete_bonds(); } else { - err = ble_adv_start(&ble_adv, BLE_ADV_MODE_FAST); - if (err) { - LOG_ERR("Failed to start advertising, err %d", err); + nrf_err = ble_adv_start(&ble_adv, BLE_ADV_MODE_FAST); + if (nrf_err) { + LOG_ERR("Failed to start advertising, nrf_error %#x", nrf_err); } else { LOG_INF("Advertising as %s", CONFIG_BLE_ADV_NAME); } @@ -396,10 +399,10 @@ static void pm_evt_handler(pm_evt_t const *p_evt) static int peer_manager_init(void) { ble_gap_sec_params_t sec_param; - int err; + int nrf_err; - err = pm_init(); - if (err) { + nrf_err = pm_init(); + if (nrf_err) { return -EFAULT; } @@ -421,15 +424,15 @@ 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); + nrf_err = pm_sec_params_set(&sec_param); + if (nrf_err) { + LOG_ERR("pm_sec_params_set() failed, nrf_error %#x", nrf_err); return -EFAULT; } - err = pm_register(pm_evt_handler); - if (err) { - LOG_ERR("pm_register() failed, err: %d", err); + nrf_err = pm_register(pm_evt_handler); + if (nrf_err) { + LOG_ERR("pm_register() failed, nrf_error %#x", nrf_err); return -EFAULT; } @@ -439,6 +442,7 @@ static int peer_manager_init(void) int main(void) { int err; + uint32_t nrf_err; bool erase_bonds = false; uint8_t body_sensor_location = BLE_HRS_BODY_SENSOR_LOCATION_FINGER; ble_uuid_t adv_uuid_list[] = { @@ -501,29 +505,29 @@ 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; } - 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; } - 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; } 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; } @@ -533,9 +537,9 @@ int main(void) goto idle; } - err = ble_adv_init(&ble_adv, &ble_adv_cfg); - if (err) { - LOG_ERR("Failed to initialize advertising, err %d", err); + nrf_err = ble_adv_init(&ble_adv, &ble_adv_cfg); + if (nrf_err) { + LOG_ERR("Failed to initialize advertising, 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 6a8a7cfc4b..920562ba92 100644 --- a/samples/bluetooth/ble_lbs/src/main.c +++ b/samples/bluetooth/ble_lbs/src/main.c @@ -78,7 +78,7 @@ static void ble_adv_evt_handler(struct ble_adv *adv, const struct ble_adv_evt *a { switch (adv_evt->evt_type) { case BLE_ADV_EVT_ERROR: - LOG_ERR("Advertising error %d", adv_evt->error.reason); + LOG_ERR("Advertising error %#x", adv_evt->error.reason); break; default: break; @@ -127,6 +127,7 @@ static void lbs_evt_handler(struct ble_lbs *lbs, const struct ble_lbs_evt *lbs_e int main(void) { int err; + uint32_t nrf_err; struct ble_adv_config ble_adv_config = { .conn_cfg_tag = CONFIG_NRF_SDH_BLE_CONN_TAG, .evt_handler = ble_adv_evt_handler, @@ -179,15 +180,15 @@ 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; } - 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; } @@ -200,15 +201,15 @@ int main(void) LOG_INF("Services initialized"); - err = ble_adv_init(&ble_adv, &ble_adv_config); - if (err) { - LOG_ERR("Failed to initialize BLE advertising, err %d", err); + 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); goto idle; } - err = ble_adv_start(&ble_adv, BLE_ADV_MODE_FAST); - if (err) { - LOG_ERR("Failed to start advertising, err %d", err); + nrf_err = ble_adv_start(&ble_adv, BLE_ADV_MODE_FAST); + if (nrf_err) { + LOG_ERR("Failed to start 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 ce2166c2f9..afc460613f 100644 --- a/samples/bluetooth/ble_nus/src/main.c +++ b/samples/bluetooth/ble_nus/src/main.c @@ -188,21 +188,21 @@ 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); - 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; @@ -221,19 +221,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, + 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; 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; } @@ -284,7 +284,7 @@ static void ble_adv_evt_handler(struct ble_adv *adv, const struct ble_adv_evt *a { switch (adv_evt->evt_type) { case BLE_ADV_EVT_ERROR: - LOG_ERR("Advertising error %d", adv_evt->error.reason); + LOG_ERR("Advertising error %#x", adv_evt->error.reason); break; default: break; @@ -316,7 +316,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; + uint32_t nrfx_err; if (evt->type != BLE_NUS_EVT_RX_DATA) { return; @@ -327,15 +327,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 @@ -352,9 +352,9 @@ static void ble_nus_evt_handler(const struct ble_nus_evt *evt) /** * @brief Initalize UARTE driver. */ -static int uarte_init(void) +static uint32_t uarte_init(void) { - int err; + int nrfx_err; nrfx_uarte_config_t *uarte_cfg; #if defined(CONFIG_NUS_LPUARTE) struct bm_lpuarte_config lpu_cfg = { @@ -399,16 +399,16 @@ static int uarte_init(void) IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_GPIOTE_INST_GET(30)) + NRF_GPIOTE_IRQ_GROUP, CONFIG_GPIOTE_IRQ_PRIO, NRFX_GPIOTE_INST_HANDLER_GET(30), 0, 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) { + LOG_ERR("Failed to initialize UART, nrfx_err %d", 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) { + LOG_ERR("Failed to initialize UART, nrfx_err %d", nrfx_err); + return nrfx_err; } #endif /* CONFIG_NUS_LPUARTE */ @@ -418,6 +418,7 @@ static int uarte_init(void) int main(void) { int err; + uint32_t nrf_err; struct ble_adv_config ble_adv_cfg = { .conn_cfg_tag = CONFIG_NRF_SDH_BLE_CONN_TAG, .evt_handler = ble_adv_evt_handler, @@ -436,9 +437,9 @@ int main(void) LOG_INF("BLE NUS sample started"); - err = uarte_init(); - if (err) { - LOG_ERR("Failed to enable UARTE, err %d", err); + nrf_err = uarte_init(); + if (nrf_err) { + LOG_ERR("Failed to enable UARTE, nrfx_err %#x", nrf_err); goto idle; } @@ -458,9 +459,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; } @@ -480,15 +481,15 @@ 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; } - err = ble_adv_init(&ble_adv, &ble_adv_cfg); - if (err) { - LOG_ERR("Failed to initialize advertising, err %d", err); + nrf_err = ble_adv_init(&ble_adv, &ble_adv_cfg); + if (nrf_err) { + LOG_ERR("Failed to initialize advertising, nrf_error %#x", nrf_err); goto idle; } @@ -512,9 +513,9 @@ int main(void) } #endif - err = ble_adv_start(&ble_adv, BLE_ADV_MODE_FAST); - if (err) { - LOG_ERR("Failed to start advertising, err %d", err); + nrf_err = ble_adv_start(&ble_adv, BLE_ADV_MODE_FAST); + if (nrf_err) { + LOG_ERR("Failed to start advertising, 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 fd4525a78b..5e67714133 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_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,18 @@ 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, + 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 != NRF_SUCCESS) { - 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; 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 +362,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; + int 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 +416,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 +430,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 +459,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 +470,9 @@ static void adv_data_update_and_start(enum adv_mode adv_mode) struct ble_adv_data sr_data = {}; 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; } @@ -525,15 +529,15 @@ static void adv_data_update_and_start(enum adv_mode adv_mode) 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 +571,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, + nrf_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; + 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 +591,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; @@ -626,9 +630,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; } @@ -672,9 +676,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/samples/boot/mcuboot_recovery_entry/src/main.c b/samples/boot/mcuboot_recovery_entry/src/main.c index 3aae267f42..41beec99ac 100644 --- a/samples/boot/mcuboot_recovery_entry/src/main.c +++ b/samples/boot/mcuboot_recovery_entry/src/main.c @@ -125,7 +125,7 @@ static void ble_adv_evt_handler(struct ble_adv *adv, const struct ble_adv_evt *a { switch (adv_evt->evt_type) { case BLE_ADV_EVT_ERROR: - LOG_ERR("Advertising error: %d", adv_evt->error.reason); + LOG_ERR("Advertising error: %#x", adv_evt->error.reason); break; default: break; @@ -152,6 +152,7 @@ static enum mgmt_cb_return os_mgmt_reboot_hook(uint32_t event, enum mgmt_cb_retu int main(void) { int err; + uint32_t nrf_err; struct ble_adv_config ble_adv_cfg = { .conn_cfg_tag = CONFIG_NRF_SDH_BLE_CONN_TAG, .evt_handler = ble_adv_evt_handler, @@ -196,17 +197,17 @@ int main(void) ble_adv_cfg.sr_data.uuid_lists.complete.uuid = &adv_uuid_list[0]; ble_adv_cfg.sr_data.uuid_lists.complete.len = ARRAY_SIZE(adv_uuid_list); - err = ble_adv_init(&ble_adv, &ble_adv_cfg); + nrf_err = ble_adv_init(&ble_adv, &ble_adv_cfg); - if (err) { - LOG_ERR("Failed to initialize advertising: %d", err); + if (nrf_err) { + LOG_ERR("Failed to initialize advertising, nrf_error %#x", nrf_err); return 0; } - err = ble_adv_start(&ble_adv, BLE_ADV_MODE_FAST); + nrf_err = ble_adv_start(&ble_adv, BLE_ADV_MODE_FAST); - if (err) { - LOG_ERR("Failed to start advertising: %d", err); + if (nrf_err) { + LOG_ERR("Failed to start advertising, nrf_error %#x", nrf_err); return 0; } diff --git a/samples/peripherals/lpuarte/src/main.c b/samples/peripherals/lpuarte/src/main.c index 250f0b67bb..a789ffe845 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; + uint32_t nrf_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); + nrf_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; @@ -56,7 +56,7 @@ static void lpuarte_event_handler(nrfx_uarte_event_t const *event, void *ctx) /* Initialize UARTE driver. */ static uint32_t uarte_init(void) { - uint32_t err; + uint32_t nrf_err; struct bm_lpuarte_config lpu_cfg = { .uarte_inst = NRFX_UARTE_INSTANCE(BOARD_APP_LPUARTE_INST), @@ -84,10 +84,10 @@ 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; + nrf_err = bm_lpuarte_init(&lpu, &lpu_cfg, lpuarte_event_handler); + if (nrf_err) { + LOG_ERR("Failed to initialize UARTE, nrfx_err %#x", nrf_err); + return nrf_err; } return 0; @@ -98,32 +98,33 @@ static uint8_t out[] = {1, 2, 3, 4, 5}; static void tx_timeout(void *context) { - uint32_t err; + uint32_t nrf_err; - err = bm_lpuarte_tx(&lpu, out, sizeof(out), 3000); - if (err != NRFX_SUCCESS) { - LOG_ERR("UARTE TX failed, nrfx err %#x", err); + nrf_err = bm_lpuarte_tx(&lpu, out, sizeof(out), 3000); + if (nrf_err) { + LOG_ERR("UARTE TX failed, nrfx err %#x", nrf_err); return; } } int main(void) { - uint32_t err; + int err; + uint32_t nrf_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); + nrf_err = uarte_init(); + if (nrf_err) { + LOG_ERR("Failed to enable UARTE, nrf_error %#x", nrf_err); goto idle; } /* Start reception */ - err = bm_lpuarte_rx_enable(&lpu); - if (err != NRFX_SUCCESS) { - LOG_ERR("UARTE RX failed, nrfx_err %#x", err); + nrf_err = bm_lpuarte_rx_enable(&lpu); + if (nrf_err != NRFX_SUCCESS) { + LOG_ERR("UARTE RX failed, nrfx_error %#x", nrf_err); goto idle; } diff --git a/samples/peripherals/storage/src/main.c b/samples/peripherals/storage/src/main.c index a803db0ae2..89aa16c125 100644 --- a/samples/peripherals/storage/src/main.c +++ b/samples/peripherals/storage/src/main.c @@ -101,18 +101,18 @@ static void wait_for_outstanding_writes(void) static uint32_t storage_inits(void) { - uint32_t err; + uint32_t nrf_err; - err = bm_storage_init(&storage_a); - if (err != NRF_SUCCESS) { - LOG_ERR("bm_storage_init() failed, err %#x", err); - return err; + nrf_err = bm_storage_init(&storage_a); + if (nrf_err) { + LOG_ERR("bm_storage_init() failed, nrf_error %#x", nrf_err); + return nrf_err; } - err = bm_storage_init(&storage_b); - if (err != NRF_SUCCESS) { - LOG_ERR("bm_storage_init() failed, err %#x", err); - return err; + nrf_err = bm_storage_init(&storage_b); + if (nrf_err) { + LOG_ERR("bm_storage_init() failed, nrf_error %#x", nrf_err); + return nrf_err; } return NRF_SUCCESS; @@ -120,18 +120,18 @@ static uint32_t storage_inits(void) static uint32_t storage_uninits(void) { - uint32_t err; + uint32_t nrf_err; - err = bm_storage_uninit(&storage_a); - if (err != NRF_SUCCESS && err != NRF_ERROR_NOT_SUPPORTED) { - LOG_ERR("bm_storage_uninit() failed, err %#x", err); - return err; + nrf_err = bm_storage_uninit(&storage_a); + if (nrf_err && nrf_err != NRF_ERROR_NOT_SUPPORTED) { + LOG_ERR("bm_storage_uninit() failed, nrf_error %#x", nrf_err); + return nrf_err; } - err = bm_storage_uninit(&storage_b); - if (err != NRF_SUCCESS && err != NRF_ERROR_NOT_SUPPORTED) { - LOG_ERR("bm_storage_uninit() failed, err %#x", err); - return err; + nrf_err = bm_storage_uninit(&storage_b); + if (nrf_err && nrf_err != NRF_ERROR_NOT_SUPPORTED) { + LOG_ERR("bm_storage_uninit() failed, nrf_error %#x", nrf_err); + return nrf_err; } return NRF_SUCCESS; @@ -139,7 +139,7 @@ static uint32_t storage_uninits(void) static uint32_t storage_writes(void) { - uint32_t err; + uint32_t nrf_err; char input_a[BUFFER_BLOCK_SIZE] = "Hello"; char input_b[BUFFER_BLOCK_SIZE] = "World!"; @@ -149,20 +149,21 @@ static uint32_t storage_writes(void) LOG_INF("Writing in Partition A, addr: 0x%08X, size: %d", storage_a.start_addr, sizeof(input_a)); - err = bm_storage_write(&storage_a, storage_a.start_addr, input_a, sizeof(input_a), NULL); - if (err != NRF_SUCCESS) { - LOG_ERR("bm_storage_write() failed, err %#x", err); - return err; + nrf_err = bm_storage_write(&storage_a, storage_a.start_addr, input_a, sizeof(input_a), + NULL); + if (nrf_err) { + LOG_ERR("bm_storage_write() failed, nrf_error %#x", nrf_err); + return nrf_err; } LOG_INF("Writing in Partition B, addr: 0x%08X, size: %d", storage_b.start_addr, sizeof(input_b)); - err = bm_storage_write(&storage_b, storage_b.start_addr, input_b, sizeof(input_b), + nrf_err = bm_storage_write(&storage_b, storage_b.start_addr, input_b, sizeof(input_b), NULL); - if (err != NRF_SUCCESS) { - LOG_ERR("bm_storage_write() failed, err %#x", err); - return err; + if (nrf_err) { + LOG_ERR("bm_storage_write() failed, nrf_error %#x", nrf_err); + return nrf_err; } return NRF_SUCCESS; @@ -170,7 +171,7 @@ static uint32_t storage_writes(void) static uint32_t storage_erases(void) { - uint32_t err; + uint32_t nrf_err; char erase[BUFFER_BLOCK_SIZE] = { 0 }; /* Prepare writes. */ @@ -179,19 +180,19 @@ static uint32_t storage_erases(void) LOG_INF("Erasing in Partition A, addr: 0x%08X, size: %d", storage_a.start_addr, sizeof(erase)); - err = bm_storage_write(&storage_a, storage_a.start_addr, erase, sizeof(erase), NULL); - if (err != NRF_SUCCESS) { - LOG_ERR("bm_storage_write() failed, err %#x", err); - return err; + nrf_err = bm_storage_write(&storage_a, storage_a.start_addr, erase, sizeof(erase), NULL); + if (nrf_err) { + LOG_ERR("bm_storage_write() failed, nrf_error %#x", nrf_err); + return nrf_err; } LOG_INF("Erasing in Partition B, addr: 0x%08X, size: %d", storage_b.start_addr, sizeof(erase)); - err = bm_storage_write(&storage_b, storage_b.start_addr, erase, sizeof(erase), NULL); - if (err != NRF_SUCCESS) { - LOG_ERR("bm_storage_write() failed, err %#x", err); - return err; + nrf_err = bm_storage_write(&storage_b, storage_b.start_addr, erase, sizeof(erase), NULL); + if (nrf_err) { + LOG_ERR("bm_storage_write() failed, nrf_error %#x", nrf_err); + return nrf_err; } return NRF_SUCCESS; @@ -199,23 +200,23 @@ static uint32_t storage_erases(void) static uint32_t storage_reads(void) { - uint32_t err; + uint32_t nrf_err; char output[BUFFER_BLOCK_SIZE] = { 0 }; - err = bm_storage_read(&storage_a, storage_a.start_addr, output, sizeof(output)); - if (err != NRF_SUCCESS) { - LOG_ERR("bm_storage_read() failed, err %#x", err); - return err; + nrf_err = bm_storage_read(&storage_a, storage_a.start_addr, output, sizeof(output)); + if (nrf_err) { + LOG_ERR("bm_storage_read() failed, nrf_error %#x", nrf_err); + return nrf_err; } LOG_HEXDUMP_INF(output, sizeof(output), "output A:"); memset(output, 0, sizeof(output)); - err = bm_storage_read(&storage_b, storage_b.start_addr, output, sizeof(output)); - if (err != NRF_SUCCESS) { - LOG_ERR("bm_storage_read() failed, err %#x", err); - return err; + nrf_err = bm_storage_read(&storage_b, storage_b.start_addr, output, sizeof(output)); + if (nrf_err) { + LOG_ERR("bm_storage_read() failed, nrf_err %#x", nrf_err); + return nrf_err; } LOG_HEXDUMP_INF(output, sizeof(output), "output B:"); @@ -225,7 +226,10 @@ static uint32_t storage_reads(void) int main(void) { - uint32_t err; +#if defined(CONFIG_SOFTDEVICE) + int err; +#endif + uint32_t nrf_err; LOG_INF("Storage sample started"); @@ -237,27 +241,27 @@ int main(void) } #endif - err = storage_inits(); - if (err) { + nrf_err = storage_inits(); + if (nrf_err) { goto idle; } LOG_INF("Reading persisted data"); - err = storage_reads(); - if (err) { + nrf_err = storage_reads(); + if (nrf_err) { goto idle; } - err = storage_erases(); - if (err) { + nrf_err = storage_erases(); + if (nrf_err) { goto idle; } wait_for_outstanding_writes(); - err = storage_reads(); - if (err) { + nrf_err = storage_reads(); + if (nrf_err) { goto idle; } @@ -268,25 +272,25 @@ int main(void) */ err = nrf_sdh_disable_request(); if (err) { - LOG_ERR("Failed to disable SoftDevice, err %#x", err); + LOG_ERR("Failed to disable SoftDevice, err %d", err); goto idle; } #endif - err = storage_writes(); - if (err) { + nrf_err = storage_writes(); + if (nrf_err) { goto idle; } wait_for_outstanding_writes(); - err = storage_reads(); - if (err) { + nrf_err = storage_reads(); + if (nrf_err) { goto idle; } - err = storage_uninits(); - if (err) { + nrf_err = storage_uninits(); + if (nrf_err) { goto idle; } diff --git a/subsys/bluetooth/services/ble_bas/bas.c b/subsys/bluetooth/services/ble_bas/bas.c index cddb36e88a..d7fea11cf9 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, + nrf_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; + 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/subsys/bluetooth/services/ble_cgms/cgms.c b/subsys/bluetooth/services/ble_cgms/cgms.c index bf9551938e..da63ea9772 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, + nrf_err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &cgms->service_handle); - if (err != NRF_SUCCESS) { - return err; + 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 bdf55efca8..35313ea4b9 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 = {}; 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 != NRF_SUCCESS) { + 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..00951c3385 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; + int err; uint8_t encoded_resp[25]; uint16_t len; @@ -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]), + nrf_err = cgms_db_record_get(&(rec[i]), cgms->racp_data.racp_proc_record_idx + i); - if (err != NRF_SUCCESS) { - return err; + 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]), + nrf_err = cgms_db_record_get(&(rec[i]), cgms->racp_data.racp_proc_record_idx + i); - if (err != NRF_SUCCESS) { - return err; + 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, + nrf_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)) { + 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 e82adb0eb1..60026237a6 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); } } @@ -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 = {}; @@ -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, + nrf_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)) { + 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 62eb5db087..334b9f4971 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 = {}; 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_dis/dis.c b/subsys/bluetooth/services/ble_dis/dis.c index 32076dd9ce..b98af7f133 100644 --- a/subsys/bluetooth/services/ble_dis/dis.c +++ b/subsys/bluetooth/services/ble_dis/dis.c @@ -4,6 +4,7 @@ * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ +#include #include #include #include @@ -56,9 +57,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 +103,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 +122,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/subsys/bluetooth/services/ble_hids/hids.c b/subsys/bluetooth/services/ble_hids/hids.c index 22abd0c5de..668b7ad75f 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, + nrf_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) { + 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, + 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); @@ -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, + 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, + nrf_err = sd_ble_gatts_characteristic_add(hids->service_handle, &char_md, &attr_char_value, &rep_char->char_handles); - if (err != NRF_SUCCESS) { - return err; + 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, + nrf_err = sd_ble_gatts_characteristic_add(hids->service_handle, &char_md, &attr_char_value, &hids->rep_map_handles); - if (err != NRF_SUCCESS) { - return err; + 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, + nrf_err = sd_ble_gatts_include_add(hids->service_handle, hids_cfg->included_services_array[i], &unused_include_handle); - if (err != NRF_SUCCESS) { - return err; + 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, + nrf_err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &hids->service_handle); - if (err != NRF_SUCCESS) { - return err; + 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, + nrf_err = protocol_mode_char_add(hids, hids_cfg->protocol_mode_sec.read, hids_cfg->protocol_mode_sec.write); - if (err != NRF_SUCCESS) { - return err; + 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, + 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 (err != NRF_SUCCESS) { - return err; + 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_err %d", 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_err %#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_hrs/hrs.c b/subsys/bluetooth/services/ble_hrs/hrs.c index 05bb0fac3e..15cab26e5d 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; ble_uuid_t ble_uuid; if (hrs == NULL || cfg == NULL) { - return -EFAULT; + return NRF_ERROR_NULL; } /* Initialize service structure. */ @@ -235,27 +236,27 @@ int ble_hrs_init(struct ble_hrs *hrs, const struct ble_hrs_config *cfg) &hrs->service_handle); if (err) { LOG_ERR("Failed to add heart rate service, nrf_error %#x", err); - return -EINVAL; + 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; + 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; + 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; uint8_t encoded_hrm[MAX_HRM_LEN_CALC(CONFIG_NRF_SDH_BLE_GATT_MAX_MTU_SIZE)]; @@ -263,7 +264,7 @@ int ble_hrs_heart_rate_measurement_send(struct ble_hrs *hrs, uint16_t heart_rate uint16_t hvx_len; if (!hrs) { - return -EFAULT; + return NRF_ERROR_NULL; } LOG_INF("Heart rate: %d bpm", heart_rate); @@ -286,24 +287,24 @@ int ble_hrs_heart_rate_measurement_send(struct ble_hrs *hrs, uint16_t heart_rate 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; + 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 +314,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,32 +324,33 @@ 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; ble_gatts_value_t gatts_value = { @@ -358,16 +360,16 @@ 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; + 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) diff --git a/subsys/bluetooth/services/ble_lbs/lbs.c b/subsys/bluetooth/services/ble_lbs/lbs.c index 3d699c7890..add0e1048f 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 @@ -52,12 +53,12 @@ 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; if (!lbs || !cfg) { - return -EFAULT; + return NRF_ERROR_NULL; } /* Initialize service structure. */ @@ -65,10 +66,10 @@ 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); - return -EINVAL; + 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 NRF_ERROR_INVALID_PARAM; } ble_uuid = (ble_uuid_t) { @@ -77,11 +78,11 @@ 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); - return -EINVAL; + if (nrf_err != NRF_SUCCESS) { + LOG_ERR("Failed to add GATT service, nrf_error %#x", nrf_err); + return NRF_ERROR_INVALID_PARAM; } /* Add Button characteristic. */ @@ -113,11 +114,11 @@ 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); - return -EINVAL; + if (nrf_err) { + LOG_ERR("Failed to add button GATT characteristic, nrf_error %#x", nrf_err); + return NRF_ERROR_INVALID_PARAM; } /* Add LED characteristic. */ @@ -145,24 +146,24 @@ 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); - return -EINVAL; + if (nrf_err) { + LOG_ERR("Failed to add LED GATT characteristic, nrf_error %#x", nrf_err); + 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) { - 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; } 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; } diff --git a/subsys/softdevice_handler/nrf_sdh_soc.c b/subsys/softdevice_handler/nrf_sdh_soc.c index e95ad87db5..5a8398efa3 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 != NRF_SUCCESS) { 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/subsys/storage/bm_storage/bm_storage.c b/subsys/storage/bm_storage/bm_storage.c index e41ef6e9ce..ce4fd89679 100644 --- a/subsys/storage/bm_storage/bm_storage.c +++ b/subsys/storage/bm_storage/bm_storage.c @@ -35,7 +35,7 @@ static inline bool is_within_bounds(off_t addr, size_t len, off_t boundary_start uint32_t bm_storage_init(struct bm_storage *storage) { - uint32_t err; + uint32_t nrf_err; if (!storage) { return NRF_ERROR_NULL; @@ -43,9 +43,9 @@ uint32_t bm_storage_init(struct bm_storage *storage) storage->nvm_info = &bm_storage_info; - err = bm_storage_backend_init(storage); - if (err != NRF_SUCCESS) { - return err; + nrf_err = bm_storage_backend_init(storage); + if (nrf_err != NRF_SUCCESS) { + return nrf_err; } storage->initialized = true; @@ -55,7 +55,7 @@ uint32_t bm_storage_init(struct bm_storage *storage) uint32_t bm_storage_uninit(struct bm_storage *storage) { - uint32_t err; + uint32_t nrf_err; if (!storage) { return NRF_ERROR_NULL; @@ -65,14 +65,14 @@ uint32_t bm_storage_uninit(struct bm_storage *storage) return NRF_ERROR_INVALID_STATE; } - err = bm_storage_backend_uninit(storage); + nrf_err = bm_storage_backend_uninit(storage); - if (err == NRF_SUCCESS) { + if (nrf_err == NRF_SUCCESS) { storage->initialized = false; storage->nvm_info = NULL; } - return err; + return nrf_err; } uint32_t bm_storage_read(const struct bm_storage *storage, uint32_t src, void *dest, uint32_t len) diff --git a/subsys/storage/bm_storage/rram/bm_storage_rram.c b/subsys/storage/bm_storage/rram/bm_storage_rram.c index a3530c5a06..2e8990f1bf 100644 --- a/subsys/storage/bm_storage/rram/bm_storage_rram.c +++ b/subsys/storage/bm_storage/rram/bm_storage_rram.c @@ -37,7 +37,7 @@ static void event_send(const struct bm_storage *storage, struct bm_storage_evt * uint32_t bm_storage_backend_init(struct bm_storage *storage) { - uint32_t err; + uint32_t nrf_err; nrfx_err_t nrfx_err; /* If it's already initialized, return early successfully. @@ -57,15 +57,15 @@ uint32_t bm_storage_backend_init(struct bm_storage *storage) nrfx_err = nrfx_rramc_init(&rramc_config, NULL); if (nrfx_err != NRFX_SUCCESS) { - err = NRF_ERROR_INTERNAL; + nrf_err = NRF_ERROR_INTERNAL; } else { state.is_rramc_init = true; - err = NRF_SUCCESS; + nrf_err = NRF_SUCCESS; } atomic_set(&state.operation_ongoing, 0); - return err; + return nrf_err; } uint32_t bm_storage_backend_read(const struct bm_storage *storage, uint32_t src, void *dest, diff --git a/subsys/storage/bm_storage/sd/bm_storage_sd.c b/subsys/storage/bm_storage/sd/bm_storage_sd.c index b3170708b2..5d10496ff0 100644 --- a/subsys/storage/bm_storage/sd/bm_storage_sd.c +++ b/subsys/storage/bm_storage/sd/bm_storage_sd.c @@ -115,9 +115,9 @@ static uint32_t write_execute(const struct bm_storage_sd_op *op) uint32_t *dest = (uint32_t *)(op->dest + op->offset); const uint32_t *src = (const uint32_t *)((uint32_t)op->src + op->offset); - uint32_t err = sd_flash_write(dest, src, chunk_len_words); + uint32_t nrf_err = sd_flash_write(dest, src, chunk_len_words); - return err; + return nrf_err; } static void queue_process(void) diff --git a/tests/lib/bluetooth/ble_adv/src/unity_test.c b/tests/lib/bluetooth/ble_adv/src/unity_test.c index 39c0748fc5..ca9cd795a9 100644 --- a/tests/lib/bluetooth/ble_adv/src/unity_test.c +++ b/tests/lib/bluetooth/ble_adv/src/unity_test.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ -#include +#include #include #include #include @@ -30,7 +30,7 @@ void test_ble_adv_conn_cfg_tag_set(void) int ret; ret = ble_adv_conn_cfg_tag_set(NULL, conn_cfg_tag); - TEST_ASSERT_EQUAL(-EFAULT, ret); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, ret); ret = ble_adv_conn_cfg_tag_set(&ble_adv, conn_cfg_tag); TEST_ASSERT_EQUAL(0, ret); @@ -38,7 +38,7 @@ void test_ble_adv_conn_cfg_tag_set(void) TEST_ASSERT_EQUAL(conn_cfg_tag, ble_adv.conn_cfg_tag); } -void test_ble_adv_init_efault(void) +void test_ble_adv_init_error_null(void) { struct ble_adv ble_adv; struct ble_adv_config config = { @@ -48,15 +48,15 @@ void test_ble_adv_init_efault(void) int ret; ret = ble_adv_init(NULL, &config); - TEST_ASSERT_EQUAL(-EFAULT, ret); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, ret); ret = ble_adv_init(&ble_adv, NULL); - TEST_ASSERT_EQUAL(-EFAULT, ret); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, ret); config.evt_handler = NULL; ret = ble_adv_init(&ble_adv, &config); - TEST_ASSERT_EQUAL(-EFAULT, ret); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, ret); } -void test_ble_adv_init_einval(void) +void test_ble_adv_init_error_invalid_param(void) { struct ble_adv ble_adv = { .adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET, @@ -74,7 +74,7 @@ void test_ble_adv_init_einval(void) __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(-EINVAL, ret); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, ret); /* Simulate an error in setting the adv config */ __cmock_sd_ble_gap_device_name_set_ExpectAndReturn(&sec_mode, CONFIG_BLE_ADV_NAME, @@ -82,7 +82,7 @@ void test_ble_adv_init_einval(void) __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(-EINVAL, ret); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, ret); } void test_ble_adv_init(void) @@ -126,13 +126,13 @@ void test_ble_adv_peer_addr_reply(void) int ret; ret = ble_adv_peer_addr_reply(NULL, &peer_addr); - TEST_ASSERT_EQUAL(-EFAULT, ret); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, ret); ret = ble_adv_peer_addr_reply(&ble_adv, NULL); - TEST_ASSERT_EQUAL(-EFAULT, ret); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, ret); ret = ble_adv_peer_addr_reply(&ble_adv, &peer_addr); - TEST_ASSERT_EQUAL(-EINVAL, ret); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, ret); peer_addr = (ble_gap_addr_t){ .addr_id_peer = 0, @@ -157,14 +157,14 @@ void test_ble_adv_whitelist_reply(void) const ble_gap_irk_t irks = {0}; ret = ble_adv_whitelist_reply(NULL, &addrs, 0, &irks, 0); - TEST_ASSERT_EQUAL(-EFAULT, ret); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, ret); ret = ble_adv_whitelist_reply(&ble_adv_config, &addrs, 0, &irks, 0); - TEST_ASSERT_EQUAL(-EPERM, ret); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_STATE, ret); ble_adv_config.whitelist_reply_expected = NULL; ret = ble_adv_whitelist_reply(&ble_adv_config, NULL, 0, NULL, 0); - TEST_ASSERT_EQUAL(-EPERM, ret); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_STATE, ret); ble_adv_config.whitelist_reply_expected = true; ret = ble_adv_whitelist_reply(&ble_adv_config, &addrs, 0, &irks, 0); @@ -259,12 +259,12 @@ void test_ble_adv_start_einval(void) __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(-EINVAL, ret); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, ret); __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(-EINVAL, ret); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, ret); } void setUp(void) diff --git a/tests/lib/bluetooth/ble_qwr/src/unity_test.c b/tests/lib/bluetooth/ble_qwr/src/unity_test.c index 0841a333b1..94e5a4524e 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 = {}; - 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 = {}; - err = ble_qwr_init(&qwr, &qwr_config); - TEST_ASSERT_EQUAL(0, err); + nrf_err = ble_qwr_init(&qwr, &qwr_config); + TEST_ASSERT_EQUAL(0, 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 = {}; - 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 = {}; 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 = {}; /* 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 = {}; - 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 = {}; 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 = {}; 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 = {}; 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); diff --git a/tests/lib/bluetooth/ble_racp/src/unity_test.c b/tests/lib/bluetooth/ble_racp/src/unity_test.c index 95a187110b..100e2cd0b5 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(void) { int ret; - const struct ble_racp_value racp_val = {}; + struct ble_racp_value racp_val = {}; 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 = {}; - 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,17 +58,17 @@ 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; struct ble_racp_value racp_val = {}; uint8_t data[5]; ret = ble_racp_decode(NULL, 0, &racp_val); - TEST_ASSERT_EQUAL(-EFAULT, ret); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, ret); ret = ble_racp_decode(data, sizeof(data), NULL); - TEST_ASSERT_EQUAL(-EFAULT, ret); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, ret); } void test_ble_racp_decode(void) 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..8393b7f4fb 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; + int 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; + int 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; + int 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; + int 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(0, nrf_err); + nrf_err = ble_bas_battery_level_notify(&ble_bas, SERVICE_HANDLE); + TEST_ASSERT_EQUAL(0, 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; + int 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; + int 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; + int 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; + int 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; + int 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(0, 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(0, 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(0, 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; + int 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; + int 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; + int 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; + int 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; + int 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(0, nrf_err); } void setUp(void) 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..ce203184a9 100644 --- a/tests/subsys/bluetooth/services/ble_dis/src/unity_test.c +++ b/tests/subsys/bluetooth/services/ble_dis/src/unity_test.c @@ -148,21 +148,21 @@ 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; __cmock_sd_ble_gatts_service_add_Stub(stub_sd_ble_gatts_service_add_invalid_param); err = ble_dis_init(); - TEST_ASSERT_EQUAL(-EINVAL, err); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, 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); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, err); } void test_ble_dis_init(void) diff --git a/tests/subsys/storage/bm_storage/src/unity_test.c b/tests/subsys/storage/bm_storage/src/unity_test.c index 8b43ec5879..da71f70e09 100644 --- a/tests/subsys/storage/bm_storage/src/unity_test.c +++ b/tests/subsys/storage/bm_storage/src/unity_test.c @@ -69,15 +69,15 @@ static void bm_storage_evt_handler(struct bm_storage_evt *evt) void test_bm_storage_init_error_null(void) { - uint32_t err; + uint32_t nrf_err; - err = bm_storage_init(NULL); - TEST_ASSERT_EQUAL(NRF_ERROR_NULL, err); + nrf_err = bm_storage_init(NULL); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); } void test_bm_storage_init(void) { - uint32_t err; + uint32_t nrf_err; struct bm_storage storage = { .evt_handler = bm_storage_evt_handler, @@ -85,13 +85,13 @@ void test_bm_storage_init(void) .end_addr = PARTITION_START + PARTITION_SIZE, }; - err = bm_storage_init(&storage); - TEST_ASSERT_EQUAL(NRF_SUCCESS, err); + nrf_err = bm_storage_init(&storage); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); } void test_bm_storage_uninit_error_null(void) { - uint32_t err; + uint32_t nrf_err; struct bm_storage storage = { .evt_handler = bm_storage_evt_handler, @@ -99,16 +99,16 @@ void test_bm_storage_uninit_error_null(void) .end_addr = PARTITION_START + PARTITION_SIZE, }; - err = bm_storage_init(&storage); - TEST_ASSERT_EQUAL(NRF_SUCCESS, err); + nrf_err = bm_storage_init(&storage); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); - err = bm_storage_uninit(NULL); - TEST_ASSERT_EQUAL(NRF_ERROR_NULL, err); + nrf_err = bm_storage_uninit(NULL); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); } void test_bm_storage_uninit_error_invalid_state(void) { - uint32_t err; + uint32_t nrf_err; struct bm_storage storage = { .evt_handler = bm_storage_evt_handler, @@ -116,13 +116,13 @@ void test_bm_storage_uninit_error_invalid_state(void) .end_addr = PARTITION_START + PARTITION_SIZE, }; - err = bm_storage_uninit(&storage); - TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_STATE, err); + nrf_err = bm_storage_uninit(&storage); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_STATE, nrf_err); } void test_bm_storage_uninit(void) { - uint32_t err; + uint32_t nrf_err; struct bm_storage storage = { .evt_handler = bm_storage_evt_handler, @@ -130,16 +130,16 @@ void test_bm_storage_uninit(void) .end_addr = PARTITION_START + PARTITION_SIZE, }; - err = bm_storage_init(&storage); - TEST_ASSERT_EQUAL(NRF_SUCCESS, err); + nrf_err = bm_storage_init(&storage); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); - err = bm_storage_uninit(&storage); - TEST_ASSERT_EQUAL(NRF_SUCCESS, err); + nrf_err = bm_storage_uninit(&storage); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); } void test_bm_storage_write_error_null(void) { - uint32_t err; + uint32_t nrf_err; char input[BLOCK_SIZE] = "Ciao"; struct bm_storage storage = { @@ -148,16 +148,16 @@ void test_bm_storage_write_error_null(void) .end_addr = PARTITION_START + PARTITION_SIZE, }; - err = bm_storage_write(NULL, PARTITION_START, input, sizeof(input), NULL); - TEST_ASSERT_EQUAL(NRF_ERROR_NULL, err); + nrf_err = bm_storage_write(NULL, PARTITION_START, input, sizeof(input), NULL); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); - err = bm_storage_write(&storage, PARTITION_START, NULL, sizeof(input), NULL); - TEST_ASSERT_EQUAL(NRF_ERROR_NULL, err); + nrf_err = bm_storage_write(&storage, PARTITION_START, NULL, sizeof(input), NULL); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); } void test_bm_storage_write_error_invalid_state(void) { - uint32_t err; + uint32_t nrf_err; char input[BLOCK_SIZE] = "Ciao"; struct bm_storage storage = { @@ -167,13 +167,13 @@ void test_bm_storage_write_error_invalid_state(void) }; /* Storage is uninitialized. */ - err = bm_storage_write(&storage, PARTITION_START, input, sizeof(input), NULL); - TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_STATE, err); + nrf_err = bm_storage_write(&storage, PARTITION_START, input, sizeof(input), NULL); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_STATE, nrf_err); } void test_bm_storage_write_error_invalid_length(void) { - uint32_t err; + uint32_t nrf_err; /* Write buffer size must be a multiple of the program unit. * This will cause an error. */ @@ -185,16 +185,16 @@ void test_bm_storage_write_error_invalid_length(void) .end_addr = PARTITION_START + PARTITION_SIZE, }; - err = bm_storage_init(&storage); - TEST_ASSERT_EQUAL(NRF_SUCCESS, err); + nrf_err = bm_storage_init(&storage); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); - err = bm_storage_write(&storage, PARTITION_START, input, sizeof(input), NULL); - TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_LENGTH, err); + nrf_err = bm_storage_write(&storage, PARTITION_START, input, sizeof(input), NULL); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_LENGTH, nrf_err); } void test_bm_storage_write_error_invalid_addr(void) { - uint32_t err; + uint32_t nrf_err; char input[BLOCK_SIZE] = "Ciao"; char input_large[BLOCK_SIZE * 4] = "Ciao"; @@ -204,21 +204,22 @@ void test_bm_storage_write_error_invalid_addr(void) .end_addr = PARTITION_START + PARTITION_SIZE, }; - err = bm_storage_init(&storage); - TEST_ASSERT_EQUAL(NRF_SUCCESS, err); + nrf_err = bm_storage_init(&storage); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); /* Operation is out of bounds. */ - err = bm_storage_write(&storage, PARTITION_START - 1, input, sizeof(input), NULL); - TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_ADDR, err); + nrf_err = bm_storage_write(&storage, PARTITION_START - 1, input, sizeof(input), NULL); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_ADDR, nrf_err); /* Operation is out of bounds. */ - err = bm_storage_write(&storage, PARTITION_START, input_large, sizeof(input_large), NULL); - TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_ADDR, err); + nrf_err = bm_storage_write( + &storage, PARTITION_START, input_large, sizeof(input_large), NULL); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_ADDR, nrf_err); } void test_bm_storage_write(void) { - uint32_t err; + uint32_t nrf_err; /* Write buffer size must be a multiple of the program unit. */ char input[BLOCK_SIZE] = "Ciao"; @@ -228,16 +229,16 @@ void test_bm_storage_write(void) .end_addr = PARTITION_START + PARTITION_SIZE, }; - err = bm_storage_init(&storage); - TEST_ASSERT_EQUAL(NRF_SUCCESS, err); + nrf_err = bm_storage_init(&storage); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); - err = bm_storage_write(&storage, PARTITION_START, input, sizeof(input), NULL); - TEST_ASSERT_EQUAL(NRF_SUCCESS, err); + nrf_err = bm_storage_write(&storage, PARTITION_START, input, sizeof(input), NULL); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); } void test_bm_storage_read_error_null(void) { - uint32_t err; + uint32_t nrf_err; char output[BLOCK_SIZE] = { 0 }; struct bm_storage storage = { @@ -246,19 +247,19 @@ void test_bm_storage_read_error_null(void) .end_addr = PARTITION_START + PARTITION_SIZE, }; - err = bm_storage_init(&storage); - TEST_ASSERT_EQUAL(NRF_SUCCESS, err); + nrf_err = bm_storage_init(&storage); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); - err = bm_storage_read(NULL, PARTITION_START, output, sizeof(output)); - TEST_ASSERT_EQUAL(NRF_ERROR_NULL, err); + nrf_err = bm_storage_read(NULL, PARTITION_START, output, sizeof(output)); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); - err = bm_storage_read(&storage, PARTITION_START, NULL, sizeof(output)); - TEST_ASSERT_EQUAL(NRF_ERROR_NULL, err); + nrf_err = bm_storage_read(&storage, PARTITION_START, NULL, sizeof(output)); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); } void test_bm_storage_read_error_invalid_state(void) { - uint32_t err; + uint32_t nrf_err; char output[BLOCK_SIZE] = { 0 }; struct bm_storage storage = { @@ -268,13 +269,13 @@ void test_bm_storage_read_error_invalid_state(void) }; /* Storage is uninitialized. */ - err = bm_storage_read(&storage, PARTITION_START, output, sizeof(output)); - TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_STATE, err); + nrf_err = bm_storage_read(&storage, PARTITION_START, output, sizeof(output)); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_STATE, nrf_err); } void test_bm_storage_read_error_invalid_length(void) { - uint32_t err; + uint32_t nrf_err; char output[BLOCK_SIZE] = { 0 }; struct bm_storage storage = { @@ -283,16 +284,16 @@ void test_bm_storage_read_error_invalid_length(void) .end_addr = PARTITION_START + PARTITION_SIZE, }; - err = bm_storage_init(&storage); - TEST_ASSERT_EQUAL(NRF_SUCCESS, err); + nrf_err = bm_storage_init(&storage); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); - err = bm_storage_read(&storage, PARTITION_START, output, 0); - TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_LENGTH, err); + nrf_err = bm_storage_read(&storage, PARTITION_START, output, 0); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_LENGTH, nrf_err); } void test_bm_storage_read_error_invalid_addr(void) { - uint32_t err; + uint32_t nrf_err; char output[BLOCK_SIZE] = { 0 }; char output_large[BLOCK_SIZE * 4] = { 0 }; @@ -302,21 +303,21 @@ void test_bm_storage_read_error_invalid_addr(void) .end_addr = PARTITION_START + PARTITION_SIZE, }; - err = bm_storage_init(&storage); - TEST_ASSERT_EQUAL(NRF_SUCCESS, err); + nrf_err = bm_storage_init(&storage); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); /* Operation is out of bounds. */ - err = bm_storage_read(&storage, PARTITION_START - 1, output, sizeof(output)); - TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_ADDR, err); + nrf_err = bm_storage_read(&storage, PARTITION_START - 1, output, sizeof(output)); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_ADDR, nrf_err); /* Operation is out of bounds. */ - err = bm_storage_read(&storage, PARTITION_START, output_large, sizeof(output_large)); - TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_ADDR, err); + nrf_err = bm_storage_read(&storage, PARTITION_START, output_large, sizeof(output_large)); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_ADDR, nrf_err); } void test_bm_storage_read(void) { - uint32_t err; + uint32_t nrf_err; char output[BLOCK_SIZE] = { 0 }; struct bm_storage storage = { @@ -325,24 +326,24 @@ void test_bm_storage_read(void) .end_addr = PARTITION_START + PARTITION_SIZE, }; - err = bm_storage_init(&storage); - TEST_ASSERT_EQUAL(NRF_SUCCESS, err); + nrf_err = bm_storage_init(&storage); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); - err = bm_storage_read(&storage, PARTITION_START, output, sizeof(output)); - TEST_ASSERT_EQUAL(NRF_SUCCESS, err); + nrf_err = bm_storage_read(&storage, PARTITION_START, output, sizeof(output)); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); } void test_bm_storage_erase_error_null(void) { - uint32_t err; + uint32_t nrf_err; - err = bm_storage_erase(NULL, PARTITION_START, BLOCK_SIZE, NULL); - TEST_ASSERT_EQUAL(NRF_ERROR_NULL, err); + nrf_err = bm_storage_erase(NULL, PARTITION_START, BLOCK_SIZE, NULL); + TEST_ASSERT_EQUAL(NRF_ERROR_NULL, nrf_err); } void test_bm_storage_erase_error_invalid_state(void) { - uint32_t err; + uint32_t nrf_err; struct bm_storage storage = { .evt_handler = bm_storage_evt_handler, @@ -351,13 +352,13 @@ void test_bm_storage_erase_error_invalid_state(void) }; /* Storage is uninitialized. */ - err = bm_storage_erase(&storage, PARTITION_START, BLOCK_SIZE, NULL); - TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_STATE, err); + nrf_err = bm_storage_erase(&storage, PARTITION_START, BLOCK_SIZE, NULL); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_STATE, nrf_err); } void test_bm_storage_erase_error_invalid_length(void) { - uint32_t err; + uint32_t nrf_err; struct bm_storage storage = { .evt_handler = bm_storage_evt_handler, @@ -365,16 +366,16 @@ void test_bm_storage_erase_error_invalid_length(void) .end_addr = PARTITION_START + PARTITION_SIZE, }; - err = bm_storage_init(&storage); - TEST_ASSERT_EQUAL(NRF_SUCCESS, err); + nrf_err = bm_storage_init(&storage); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); - err = bm_storage_erase(&storage, PARTITION_START, BLOCK_SIZE + 1, NULL); - TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_LENGTH, err); + nrf_err = bm_storage_erase(&storage, PARTITION_START, BLOCK_SIZE + 1, NULL); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_LENGTH, nrf_err); } void test_bm_storage_erase_error_invalid_addr(void) { - uint32_t err; + uint32_t nrf_err; struct bm_storage storage = { .evt_handler = bm_storage_evt_handler, @@ -382,21 +383,21 @@ void test_bm_storage_erase_error_invalid_addr(void) .end_addr = PARTITION_START + PARTITION_SIZE, }; - err = bm_storage_init(&storage); - TEST_ASSERT_EQUAL(NRF_SUCCESS, err); + nrf_err = bm_storage_init(&storage); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); /* Operation is out of bounds. */ - err = bm_storage_erase(&storage, PARTITION_START - 1, BLOCK_SIZE, NULL); - TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_ADDR, err); + nrf_err = bm_storage_erase(&storage, PARTITION_START - 1, BLOCK_SIZE, NULL); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_ADDR, nrf_err); /* Operation is out of bounds. */ - err = bm_storage_erase(&storage, PARTITION_START, BLOCK_SIZE * 4, NULL); - TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_ADDR, err); + nrf_err = bm_storage_erase(&storage, PARTITION_START, BLOCK_SIZE * 4, NULL); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_ADDR, nrf_err); } void test_bm_storage_erase(void) { - uint32_t err; + uint32_t nrf_err; struct bm_storage storage = { .evt_handler = bm_storage_evt_handler, @@ -404,16 +405,16 @@ void test_bm_storage_erase(void) .end_addr = PARTITION_START + PARTITION_SIZE, }; - err = bm_storage_init(&storage); - TEST_ASSERT_EQUAL(NRF_SUCCESS, err); + nrf_err = bm_storage_init(&storage); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); - err = bm_storage_erase(&storage, PARTITION_START, BLOCK_SIZE, NULL); - TEST_ASSERT_EQUAL(NRF_SUCCESS, err); + nrf_err = bm_storage_erase(&storage, PARTITION_START, BLOCK_SIZE, NULL); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); } void test_bm_storage_is_busy(void) { - uint32_t err; + uint32_t nrf_err; bool is_busy = false; struct bm_storage storage = { @@ -426,8 +427,8 @@ void test_bm_storage_is_busy(void) is_busy = bm_storage_is_busy(NULL); TEST_ASSERT_EQUAL(true, is_busy); - err = bm_storage_init(&storage); - TEST_ASSERT_EQUAL(NRF_SUCCESS, err); + nrf_err = bm_storage_init(&storage); + TEST_ASSERT_EQUAL(NRF_SUCCESS, nrf_err); is_busy = bm_storage_is_busy(&storage); TEST_ASSERT_EQUAL(false, is_busy);