@@ -126,7 +126,7 @@ static uint32_t mcumgr_characteristic_add(struct ble_mcumgr *service)
126126 */
127127static 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! */
291292static 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
375375NRF_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