44 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
55 */
66
7+ #include <nrf_error.h>
78#include <zephyr/sys/__assert.h>
89#include <zephyr/logging/log.h>
910#include <bm/bluetooth/services/ble_lbs.h>
@@ -52,23 +53,23 @@ void ble_lbs_on_ble_evt(const ble_evt_t *ble_evt, void *lbs_instance)
5253
5354int ble_lbs_init (struct ble_lbs * lbs , const struct ble_lbs_config * cfg )
5455{
55- int err ;
56+ uint32_t nrf_err ;
5657 ble_uuid_t ble_uuid ;
5758 uint8_t initial_value = 0 ;
5859
5960 if (!lbs || !cfg ) {
60- return - EFAULT ;
61+ return NRF_ERROR_NULL ;
6162 }
6263
6364 /* Initialize service structure. */
6465 lbs -> evt_handler = cfg -> evt_handler ;
6566
6667 ble_uuid128_t base_uuid = { .uuid128 = BLE_UUID_LBS_BASE };
6768
68- err = sd_ble_uuid_vs_add (& base_uuid , & lbs -> uuid_type );
69- if (err != NRF_SUCCESS ) {
70- LOG_ERR ("Failed to add vendor UUID, nrf_error %#x" , err );
71- return - EINVAL ;
69+ nrf_err = sd_ble_uuid_vs_add (& base_uuid , & lbs -> uuid_type );
70+ if (nrf_err ) {
71+ LOG_ERR ("Failed to add vendor UUID, nrf_error %#x" , nrf_err );
72+ return NRF_ERROR_INVALID_PARAM ;
7273 }
7374
7475 ble_uuid = (ble_uuid_t ) {
@@ -77,11 +78,11 @@ int ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg)
7778 };
7879
7980 /* Add service. */
80- err = sd_ble_gatts_service_add (BLE_GATTS_SRVC_TYPE_PRIMARY , & ble_uuid ,
81+ nrf_err = sd_ble_gatts_service_add (BLE_GATTS_SRVC_TYPE_PRIMARY , & ble_uuid ,
8182 & lbs -> service_handle );
82- if (err != NRF_SUCCESS ) {
83- LOG_ERR ("Failed to add GATT service, nrf_error %#x" , err );
84- return - EINVAL ;
83+ if (nrf_err != NRF_SUCCESS ) {
84+ LOG_ERR ("Failed to add GATT service, nrf_error %#x" , nrf_err );
85+ return NRF_ERROR_INVALID_PARAM ;
8586 }
8687
8788 /* Add Button characteristic. */
@@ -113,11 +114,11 @@ int ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg)
113114 BLE_GAP_CONN_SEC_MODE_SET_OPEN (& cccd_md .read_perm );
114115 BLE_GAP_CONN_SEC_MODE_SET_OPEN (& cccd_md .write_perm );
115116
116- err = sd_ble_gatts_characteristic_add (lbs -> service_handle , & char_md , & attr_char_value ,
117+ nrf_err = sd_ble_gatts_characteristic_add (lbs -> service_handle , & char_md , & attr_char_value ,
117118 & lbs -> button_char_handles );
118- if (err ) {
119- LOG_ERR ("Failed to add button GATT characteristic, nrf_error %#x" , err );
120- return - EINVAL ;
119+ if (nrf_err ) {
120+ LOG_ERR ("Failed to add button GATT characteristic, nrf_error %#x" , nrf_err );
121+ return NRF_ERROR_INVALID_PARAM ;
121122 }
122123
123124 /* Add LED characteristic. */
@@ -145,24 +146,24 @@ int ble_lbs_init(struct ble_lbs *lbs, const struct ble_lbs_config *cfg)
145146 BLE_GAP_CONN_SEC_MODE_SET_OPEN (& attr_md .read_perm );
146147 BLE_GAP_CONN_SEC_MODE_SET_OPEN (& attr_md .write_perm );
147148
148- err = sd_ble_gatts_characteristic_add (lbs -> service_handle , & char_md , & attr_char_value ,
149+ nrf_err = sd_ble_gatts_characteristic_add (lbs -> service_handle , & char_md , & attr_char_value ,
149150 & lbs -> led_char_handles );
150- if (err ) {
151- LOG_ERR ("Failed to add LED GATT characteristic, nrf_error %#x" , err );
152- return - EINVAL ;
151+ if (nrf_err ) {
152+ LOG_ERR ("Failed to add LED GATT characteristic, nrf_error %#x" , nrf_err );
153+ return NRF_ERROR_INVALID_PARAM ;
153154 }
154155
155- return 0 ;
156+ return NRF_SUCCESS ;
156157}
157158
158159int ble_lbs_on_button_change (struct ble_lbs * lbs , uint16_t conn_handle , uint8_t button_state )
159160{
160- int err ;
161+ uint32_t nrf_err ;
161162
162163 uint16_t len = sizeof (button_state );
163164
164165 if (!lbs ) {
165- return - EFAULT ;
166+ return NRF_ERROR_NULL ;
166167 }
167168
168169 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
172173 .p_len = & len ,
173174 };
174175
175- err = sd_ble_gatts_hvx (conn_handle , & hvx );
176- if (err ) {
177- LOG_ERR ("Failed to notify button change, nrf_error %#x" , err );
178- return - EINVAL ;
176+ nrf_err = sd_ble_gatts_hvx (conn_handle , & hvx );
177+ if (nrf_err ) {
178+ LOG_ERR ("Failed to notify button change, nrf_error %#x" , nrf_err );
179+ return NRF_ERROR_INVALID_PARAM ;
179180 }
180181
181- return 0 ;
182+ return NRF_SUCCESS ;
182183}
0 commit comments