Skip to content

Commit e2641ff

Browse files
lib: bluetooth: ble_adv: change error codes to nrf_error
Change error codes to nrf_errors. Signed-off-by: Eivind Jølsgard <[email protected]>
1 parent 3d0eee9 commit e2641ff

File tree

14 files changed

+452
-425
lines changed

14 files changed

+452
-425
lines changed

applications/firmware_loader/ble_mcumgr/src/main.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ static int ble_change_address(void)
176176
int main(void)
177177
{
178178
int err;
179+
uint32_t nrf_err;
179180
struct ble_adv_config ble_adv_cfg = {
180181
.conn_cfg_tag = CONFIG_NRF_SDH_BLE_CONN_TAG,
181182
.evt_handler = ble_adv_evt_handler,
@@ -231,17 +232,15 @@ int main(void)
231232
ble_adv_cfg.sr_data.uuid_lists.complete.uuid = &adv_uuid_list[0];
232233
ble_adv_cfg.sr_data.uuid_lists.complete.len = ARRAY_SIZE(adv_uuid_list);
233234

234-
err = ble_adv_init(&ble_adv, &ble_adv_cfg);
235-
236-
if (err) {
237-
LOG_ERR("Failed to initialize advertising, err %d", err);
235+
nrf_err = ble_adv_init(&ble_adv, &ble_adv_cfg);
236+
if (nrf_err) {
237+
LOG_ERR("Failed to initialize advertising, nrf_error %#x", nrf_err);
238238
return 0;
239239
}
240240

241-
err = ble_adv_start(&ble_adv, BLE_ADV_MODE_FAST);
242-
243-
if (err) {
244-
LOG_ERR("Failed to start advertising, err %d", err);
241+
nrf_err = ble_adv_start(&ble_adv, BLE_ADV_MODE_FAST);
242+
if (nrf_err) {
243+
LOG_ERR("Failed to start advertising, nrf_error %#x", nrf_err);
245244
return 0;
246245
}
247246

doc/nrf-bm/release_notes/release_notes_changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ No changes since the latest nRF Connect SDK Bare Metal release.
6868
Libraries
6969
=========
7070

71+
* Updated the following libraries to return ``nrf_errors`` instead of ``errnos``:
72+
73+
* :ref:`lib_ble_adv`.
74+
7175
* :ref:`lib_ble_conn_params` library:
7276

7377
* Added missing Kconfig dependencies.

include/bm/bluetooth/ble_adv.h

Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ enum ble_adv_mode {
4949
*/
5050
BLE_ADV_MODE_IDLE,
5151
/**
52-
* @brief Directed advertising (high duty cycle).
52+
* @brief Directed advertising (high duty cycle).
5353
*
5454
* Attempt to connect to the most recently disconnected peer.
5555
*/
@@ -67,7 +67,7 @@ enum ble_adv_mode {
6767
*/
6868
BLE_ADV_MODE_FAST,
6969
/**
70-
* @brief Slow advertising.
70+
* @brief Slow advertising.
7171
*
7272
* Similar to fast advertising. By default it uses a longer advertising interval and
7373
* time-out than fast advertising. However, these options can be adjusted by the user.
@@ -136,7 +136,7 @@ struct ble_adv_evt {
136136
union {
137137
/** @ref BLE_ADV_EVT_ERROR event data. */
138138
struct {
139-
int reason;
139+
uint32_t reason;
140140
} error;
141141
};
142142
};
@@ -233,7 +233,7 @@ struct ble_adv_config {
233233
*/
234234
struct ble_adv_data sr_data;
235235
/**
236-
* @brief Event handler.
236+
* @brief Event handler.
237237
*/
238238
ble_adv_evt_handler_t evt_handler;
239239
/**
@@ -256,19 +256,22 @@ void ble_adv_on_ble_evt(const ble_evt_t *ble_evt, void *ble_adv);
256256
* @param[in] ble_adv BLE advertising instance.
257257
* @param[in] ble_adv_config Initialization configuration.
258258
*
259-
* @retval 0 On success.
260-
* @retval -FAULT If @p ble_adv or @p ble_adv_config are @c NULL.
261-
* @retval -EINVAL If the configuration @p ble_adv_config is invalid.
259+
* @retval NRF_SUCCESS On success.
260+
* @retval NRF_ERROR_NULL If @p ble_adv or @p ble_adv_config are @c NULL.
261+
* @retval NRF_ERROR_INVALID_PARAM If the configuration @p ble_adv_config is invalid.
262262
*/
263-
int ble_adv_init(struct ble_adv *ble_adv, struct ble_adv_config *ble_adv_config);
263+
uint32_t ble_adv_init(struct ble_adv *ble_adv, struct ble_adv_config *ble_adv_config);
264264

265265
/**
266266
* @brief Set the connection configuration tag used for connections.
267267
*
268268
* @param[in] ble_adv BLE advertising instance.
269269
* @param[in] ble_cfg_tag Connection configuration tag.
270+
*
271+
* @retval NRF_SUCCESS On success.
272+
* @retval NRF_ERROR_NULL If @p ble_adv is @c NULL.
270273
*/
271-
int ble_adv_conn_cfg_tag_set(struct ble_adv *ble_adv, uint8_t ble_cfg_tag);
274+
uint32_t ble_adv_conn_cfg_tag_set(struct ble_adv *ble_adv, uint8_t ble_cfg_tag);
272275

273276
/**
274277
* @brief Start advertising in given mode.
@@ -279,12 +282,12 @@ int ble_adv_conn_cfg_tag_set(struct ble_adv *ble_adv, uint8_t ble_cfg_tag);
279282
* @param[in] ble_adv BLE advertising instance.
280283
* @param[in] mode Desired advertising mode.
281284
*
282-
* @retval 0 On success.
283-
* @retval -EPERM Library is not initialized.
284-
* @retval -EFAULT @p ble_adv is @c NULL.
285-
* @retval -EINVAL Invalid parameters.
285+
* @retval NRF_SUCCESS On success.
286+
* @retval NRF_ERROR_INVALID_STATE Library is not initialized.
287+
* @retval NRF_ERROR_NULL @p ble_adv is @c NULL.
288+
* @retval NRF_ERROR_INVALID_PARAM Invalid parameters.
286289
*/
287-
int ble_adv_start(struct ble_adv *ble_adv, enum ble_adv_mode mode);
290+
uint32_t ble_adv_start(struct ble_adv *ble_adv, enum ble_adv_mode mode);
288291

289292
/**
290293
* @brief Set the peer address for directed advertising.
@@ -293,15 +296,15 @@ int ble_adv_start(struct ble_adv *ble_adv, enum ble_adv_mode mode);
293296
* @ref BLE_ADV_EVT_PEER_ADDR_REQUEST event. If the application does not reply
294297
* with a peer address, the device starts advertising in the next advertising mode.
295298
*
296-
* @param[in] p_advertising Advertising Module instance.
297-
* @param[in] p_peer_addr Pointer to a peer address.
299+
* @param[in] advertising Advertising Module instance.
300+
* @param[in] peer_addr Pointer to a peer address.
298301
*
299-
* @retval 0 On success.
300-
* @retval -EPERM Library is not initialized.
301-
* @retval -EFAULT @p ble_adv is @c NULL.
302-
* @retval -EINVAL Invalid parameters.
302+
* @retval NRF_SUCCESS On success.
303+
* @retval NRF_ERROR_INVALID_STATE Library is not initialized.
304+
* @retval NRF_ERROR_NULL @p ble_adv is @c NULL.
305+
* @retval NRF_ERROR_INVALID_PARAM Invalid parameters.
303306
*/
304-
int ble_adv_peer_addr_reply(struct ble_adv *ble_adv, const ble_gap_addr_t *peer_addr);
307+
uint32_t ble_adv_peer_addr_reply(struct ble_adv *ble_adv, const ble_gap_addr_t *peer_addr);
305308

306309
/**
307310
* @brief Set a whitelist for fast and slow advertising.
@@ -315,14 +318,14 @@ int ble_adv_peer_addr_reply(struct ble_adv *ble_adv, const ble_gap_addr_t *peer_
315318
* @param[in] gap_irks The list of peer IRK to whitelist.
316319
* @param[in] irk_cnt The number of peer IRK to whitelist.
317320
*
318-
* @retval 0 On success.
319-
* @retval -EPERM Library is not initialized.
320-
* @retval -EFAULT @p ble_adv is @c NULL.
321-
* @retval -EINVAL Invalid parameters.
321+
* @retval NRF_SUCCESS On success.
322+
* @retval NRF_ERROR_INVALID_STATE Library is not initialized.
323+
* @retval NRF_ERROR_NULL @p ble_adv is @c NULL.
324+
* @retval NRF_ERROR_INVALID_PARAM Invalid parameters.
322325
*/
323-
int ble_adv_whitelist_reply(struct ble_adv *ble_adv,
324-
const ble_gap_addr_t *gap_addrs, uint32_t addr_cnt,
325-
const ble_gap_irk_t *gap_irks, uint32_t irk_cnt);
326+
uint32_t ble_adv_whitelist_reply(struct ble_adv *ble_adv,
327+
const ble_gap_addr_t *gap_addrs, uint32_t addr_cnt,
328+
const ble_gap_irk_t *gap_irks, uint32_t irk_cnt);
326329

327330
/**
328331
* @brief Restart advertising without whitelist.
@@ -332,32 +335,36 @@ int ble_adv_whitelist_reply(struct ble_adv *ble_adv,
332335
*
333336
* @param[in] ble_adv Advertising Module instance.
334337
*
335-
* @retval 0 On success.
336-
* @retval -EPERM Library is not initialized.
337-
* @retval -EFAULT @p ble_adv is @c NULL.
338+
* @retval NRF_SUCCESS On success.
339+
* @retval NRF_ERROR_INVALID_STATE Library is not initialized.
340+
* @retval NRF_ERROR_NULL @p ble_adv is @c NULL.
341+
* @retval NRF_ERROR_INVALID_PARAM Invalid advertising parameters.
338342
*/
339-
int ble_adv_restart_without_whitelist(struct ble_adv *ble_adv);
343+
uint32_t ble_adv_restart_without_whitelist(struct ble_adv *ble_adv);
340344

341-
/**@brief Function for updating advertising data.
345+
/**
346+
* @brief Function for updating advertising data.
342347
*
343348
* @details This function can be called if you wish to reconfigure the advertising data The update
344349
* will be effective even if advertising has already been started.
345350
*
346-
* @param[in] p_advertising Advertising Module instance.
347-
* @param[in] p_advdata Pointer to the structure for specifying the content of advertising
348-
* data. Or null if there should be no advertising data.
349-
* @param[in] p_srdata Pointer to the structure for specifying the content of scan response
350-
* data. Or null if there should be no advertising data.
351+
* @param[in] ble_adv Advertising Module instance.
352+
* @param[in] adv Pointer to the structure for specifying the content of advertising
353+
* data. Or null if there should be no advertising data.
354+
* @param[in] sr Pointer to the structure for specifying the content of scan response
355+
* data. Or null if there should be no advertising data.
351356
*
352-
* @retval @ref NRF_ERROR_NULL If advertising instance was null.
353-
* If both \p p_advdata and \p p_srdata are null.
354-
* @retval @ref NRF_ERROR_INVALID_STATE If advertising instance was not initialized.
355-
* @retval @ref NRF_SUCCESS or any error from @ref ble_advdata_encode or
356-
* @ref sd_ble_gap_adv_set_configure().
357+
* @retval NRF_SUCCESS If the operation was successful.
358+
* @retval NRF_ERROR_NULL If @p ble_adv is null or if both @p adv and @p sr are @p NULL.
359+
* @retval NRF_ERROR_INVALID_STATE If advertising instance was not initialized.
360+
* @retval NRF_ERROR_INVALID_ADDR Invalid address.
361+
* @retval NRF_ERROR_INVALID_PARAM Invalid parameter provided in the advertising data context.
362+
* @retval NRF_ERROR_DATA_SIZE Buffer is too small to encode all data.
363+
* @returns Any error from @c sd_ble_gap_adv_set_configure on failure.
357364
*/
358-
int ble_adv_data_update(struct ble_adv *ble_adv,
359-
const struct ble_adv_data *adv,
360-
const struct ble_adv_data *sr);
365+
uint32_t ble_adv_data_update(struct ble_adv *ble_adv,
366+
const struct ble_adv_data *adv,
367+
const struct ble_adv_data *sr);
361368

362369
#ifdef __cplusplus
363370
}

include/bm/bluetooth/ble_adv_data.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,11 @@ struct ble_adv_data {
185185
* @param[out] buf Output buffer.
186186
* @param[in,out] len Size of @p buf on input, length of encoded data on output.
187187
*
188-
* @retval 0 If the operation was successful.
189-
* @retval -EINVAL Invalid parameter.
190-
* @retval -E2BIG Buffer is too small to encode all data.
188+
* @retval NRF_SUCCESS If the operation was successful.
189+
* @retval NRF_ERROR_INVALID_ADDR Invalid address.
190+
* @retval NRF_ERROR_INVALID_PARAM Invalid parameter provided in the advertising data context.
191+
* @retval NRF_ERROR_NULL @p ble_adv_data, @p buf or @p len is NULL.
192+
* @retval NRF_ERROR_DATA_SIZE Buffer is too small to encode all data.
191193
*
192194
* @warning This API may override the application's request to use the long name and use a short
193195
* 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 {
199201
* application can specify, and if the preference is too large to fit in the provided buffer, the
200202
* name can be truncated further.
201203
*/
202-
int ble_adv_data_encode(const struct ble_adv_data *ble_adv_data, uint8_t *buf, uint16_t *len);
204+
uint32_t ble_adv_data_encode(const struct ble_adv_data *ble_adv_data, uint8_t *buf, uint16_t *len);
203205

204206
/**
205207
* @brief Search Advertising or Scan Response data for specific data types.

0 commit comments

Comments
 (0)