Skip to content

Commit 7f6e4b3

Browse files
bluetooth: services: ble_mcumgr: change error codes to nrf_error
Change error codes to nrf_errors. Signed-off-by: Eivind Jølsgard <[email protected]>
1 parent 1f04562 commit 7f6e4b3

File tree

5 files changed

+53
-51
lines changed

5 files changed

+53
-51
lines changed

applications/firmware_loader/ble_mcumgr/src/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,10 @@ int main(void)
211211

212212
LOG_INF("Bluetooth enabled");
213213

214-
err = ble_mcumgr_init();
214+
nrf_err = ble_mcumgr_init();
215215

216-
if (err) {
217-
LOG_ERR("Failed to initialize MCUmgr service, err %d", err);
216+
if (nrf_err) {
217+
LOG_ERR("Failed to initialize MCUmgr service, nrf_error %#x", nrf_err);
218218
return 0;
219219
}
220220

doc/nrf-bm/release_notes/release_notes_changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ Libraries
8686
* :ref:`lib_ble_service_dis` service.
8787
* :ref:`lib_ble_service_hrs` service.
8888
* :ref:`lib_ble_service_lbs` service.
89+
* :ref:`lib_ble_service_mcumgr` service.
8990
* BLE Record Access Control Point library.
9091

9192
* :ref:`lib_ble_conn_params` library:

include/bm/bluetooth/services/ble_mcumgr.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ extern "C" {
3737
/**
3838
* @brief Function for initializing the MCUmgr Bluetooth service.
3939
*
40-
* @retval 0 On success.
41-
* @retval -EINVAL Invalid parameters.
40+
* @retval NRF_SUCCESS On success.
41+
* @retval NRF_ERROR_INVALID_PARAM Invalid parameters.
4242
*/
43-
int ble_mcumgr_init(void);
43+
uint32_t ble_mcumgr_init(void);
4444

4545
/**
4646
* @brief Function for getting the MCUmgr Bluetooth service UUID type.

samples/boot/mcuboot_recovery_entry/src/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ int main(void)
186186

187187
LOG_INF("Bluetooth enabled");
188188

189-
err = ble_mcumgr_init();
189+
nrf_err = ble_mcumgr_init();
190190

191-
if (err) {
192-
LOG_ERR("Failed to initialize MCUmgr: %d", err);
191+
if (nrf_err) {
192+
LOG_ERR("Failed to initialize MCUmgr, nrf_error %#x", nrf_err);
193193
return 0;
194194
}
195195

subsys/bluetooth/services/ble_mcumgr/mcumgr.c

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static uint32_t mcumgr_characteristic_add(struct ble_mcumgr *service)
126126
*/
127127
static void on_connect(struct ble_mcumgr *service, ble_evt_t const *ble_evt)
128128
{
129-
int err;
129+
uint32_t nrf_err;
130130
uint8_t cccd_value[2];
131131
ble_gatts_value_t gatts_val = {
132132
.p_value = cccd_value,
@@ -145,10 +145,10 @@ static void on_connect(struct ble_mcumgr *service, ble_evt_t const *ble_evt)
145145
/* Check the hosts CCCD value to inform of readiness to send data using the
146146
* RX characteristic
147147
*/
148-
err = sd_ble_gatts_value_get(conn_handle, service->characteristic_handle.cccd_handle,
149-
&gatts_val);
148+
nrf_err = sd_ble_gatts_value_get(conn_handle, service->characteristic_handle.cccd_handle,
149+
&gatts_val);
150150

151-
if (err == 0 && is_notification_enabled(gatts_val.p_value)) {
151+
if (nrf_err == NRF_SUCCESS && is_notification_enabled(gatts_val.p_value)) {
152152
ctx->is_notification_enabled = true;
153153
}
154154
}
@@ -198,7 +198,7 @@ static void on_write(struct ble_mcumgr *service, ble_evt_t const *ble_evt)
198198
* Collection can fail only due to failing to allocate memory or by receiving
199199
* more data than expected.
200200
*/
201-
if (ret == -ENOMEM) {
201+
if (ret == NRF_ERROR_NO_MEM) {
202202
/* Failed to collect the buffer */
203203
LOG_ERR("Failed to collect buffer");
204204
return;
@@ -239,9 +239,9 @@ static void on_write(struct ble_mcumgr *service, ble_evt_t const *ble_evt)
239239
}
240240
}
241241

242-
int ble_mcumgr_data_send(uint8_t *data, uint16_t *len, struct ble_mcumgr_client_context *ctx)
242+
uint32_t ble_mcumgr_data_send(uint8_t *data, uint16_t *len, struct ble_mcumgr_client_context *ctx)
243243
{
244-
int err;
244+
uint32_t nrf_err;
245245
ble_gatts_hvx_params_t hvx_params = {
246246
.handle = ble_mcumgr.characteristic_handle.value_handle,
247247
.p_data = data,
@@ -250,47 +250,47 @@ int ble_mcumgr_data_send(uint8_t *data, uint16_t *len, struct ble_mcumgr_client_
250250
};
251251

252252
if (!data || !len) {
253-
return -EFAULT;
253+
return NRF_ERROR_NULL;
254254
} else if (*len > BLE_GATT_MAX_DATA_LEN) {
255-
return -EINVAL;
255+
return NRF_ERROR_INVALID_PARAM;
256256
} else if (!ctx->is_notification_enabled) {
257-
return -EINVAL;
257+
return NRF_ERROR_INVALID_PARAM;
258258
}
259259

260-
err = sd_ble_gatts_hvx(conn_handle, &hvx_params);
260+
nrf_err = sd_ble_gatts_hvx(conn_handle, &hvx_params);
261261

262-
switch (err) {
262+
switch (nrf_err) {
263263
case NRF_SUCCESS:
264264
{
265-
return 0;
265+
return NRF_SUCCESS;
266266
}
267267
case BLE_ERROR_INVALID_CONN_HANDLE:
268268
{
269-
return -ENOTCONN;
269+
return NRF_ERROR_NOT_FOUND;
270270
}
271271
case NRF_ERROR_INVALID_STATE:
272272
{
273-
return -EPIPE;
273+
return NRF_ERROR_INVALID_STATE;
274274
}
275275
case NRF_ERROR_RESOURCES:
276276
{
277-
return -EAGAIN;
277+
return NRF_ERROR_RESOURCES;
278278
}
279279
case NRF_ERROR_NOT_FOUND:
280280
{
281-
return -EBADF;
281+
return NRF_ERROR_NOT_FOUND;
282282
}
283283
default:
284284
{
285-
LOG_ERR("Failed to send MCUmgr data, nrf_error %#x", err);
286-
return -EIO;
285+
LOG_ERR("Failed to send MCUmgr data, nrf_error %#x", nrf_err);
286+
return NRF_ERROR_INTERNAL;
287287
}
288288
};
289289
}
290290

291+
/* Return errno! */
291292
static int smp_ncs_bm_bt_tx_pkt(struct net_buf *nb)
292293
{
293-
int rc;
294294
uint32_t nrf_err;
295295
struct ble_mcumgr_client_context *ctx;
296296
uint16_t notification_size;
@@ -316,9 +316,9 @@ static int smp_ncs_bm_bt_tx_pkt(struct net_buf *nb)
316316
send_size = notification_size;
317317
}
318318

319-
rc = ble_mcumgr_data_send(send_pos, &send_size, ctx);
319+
nrf_err = ble_mcumgr_data_send(send_pos, &send_size, ctx);
320320

321-
if (rc) {
321+
if (nrf_err) {
322322
break;
323323
}
324324

@@ -374,9 +374,9 @@ static void on_ble_evt(const ble_evt_t *evt, void *ctx)
374374

375375
NRF_SDH_BLE_OBSERVER(sdh_ble, on_ble_evt, &ble_mcumgr, 0);
376376

377-
int ble_mcumgr_init(void)
377+
uint32_t ble_mcumgr_init(void)
378378
{
379-
int err;
379+
uint32_t nrf_err;
380380
ble_uuid_t ble_uuid;
381381
ble_uuid128_t uuid_base_service = {
382382
.uuid128 = BLE_MCUMGR_SERVICE_UUID
@@ -389,39 +389,40 @@ int ble_mcumgr_init(void)
389389
ble_mcumgr.service_handle = BLE_CONN_HANDLE_INVALID;
390390

391391
/* Add MCUmgr service/characteristic UUIDs */
392-
err = sd_ble_uuid_vs_add(&uuid_base_service, &ble_mcumgr.uuid_type_service);
392+
nrf_err = sd_ble_uuid_vs_add(&uuid_base_service, &ble_mcumgr.uuid_type_service);
393393

394-
if (err) {
395-
LOG_ERR("sd_ble_uuid_vs_add failed, nrf_error %#x", err);
396-
return -EINVAL;
394+
if (nrf_err) {
395+
LOG_ERR("sd_ble_uuid_vs_add failed, nrf_error %#x", nrf_err);
396+
return NRF_ERROR_INVALID_PARAM;
397397
}
398398

399-
err = sd_ble_uuid_vs_add(&uuid_base_characteristic, &ble_mcumgr.uuid_type_characteristic);
399+
nrf_err = sd_ble_uuid_vs_add(&uuid_base_characteristic,
400+
&ble_mcumgr.uuid_type_characteristic);
400401

401-
if (err) {
402-
LOG_ERR("sd_ble_uuid_vs_add failed, nrf_error %#x", err);
403-
return -EINVAL;
402+
if (nrf_err) {
403+
LOG_ERR("sd_ble_uuid_vs_add failed, nrf_error %#x", nrf_err);
404+
return NRF_ERROR_INVALID_PARAM;
404405
}
405406

406407
ble_uuid.type = ble_mcumgr.uuid_type_service;
407408
ble_uuid.uuid = BLE_MCUMGR_SERVICE_UUID_SUB;
408409

409410
/* Add the service */
410-
err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
411-
&ble_uuid,
412-
&ble_mcumgr.service_handle);
411+
nrf_err = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
412+
&ble_uuid,
413+
&ble_mcumgr.service_handle);
413414

414-
if (err) {
415-
LOG_ERR("Failed to add MCUmgr service, nrf_error %#x", err);
416-
return -EINVAL;
415+
if (nrf_err) {
416+
LOG_ERR("Failed to add MCUmgr service, nrf_error %#x", nrf_err);
417+
return NRF_ERROR_INVALID_PARAM;
417418
}
418419

419420
/* Add MCUmgr characteristic */
420-
err = mcumgr_characteristic_add(&ble_mcumgr);
421+
nrf_err = mcumgr_characteristic_add(&ble_mcumgr);
421422

422-
if (err) {
423-
LOG_ERR("mcumgr_characteristic_add failed, nrf_error %#x", err);
424-
return -EINVAL;
423+
if (nrf_err) {
424+
LOG_ERR("mcumgr_characteristic_add failed, nrf_error %#x", nrf_err);
425+
return NRF_ERROR_INVALID_PARAM;
425426
}
426427

427428
return 0;

0 commit comments

Comments
 (0)