nrf_ble_gatt.c 18.5 KB
Newer Older
X
xieyangrun 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
/**
 * Copyright (c) 2016 - 2017, 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.
 * 
 */
#include "sdk_config.h"

#if NRF_BLE_GATT_ENABLED
#include "nrf_ble_gatt.h"
#include "ble_srv_common.h"
#include "sdk_common.h"
#include "app_error.h"
#include "sdk_macros.h"

#define NRF_LOG_MODULE_NAME "nrf_ble_gatt"
#include "nrf_log.h"

#define LL_HEADER_LEN   4   //!< Length of a link layer header, in bytes.


STATIC_ASSERT(NRF_BLE_GATT_MAX_MTU_SIZE <= 251);
STATIC_ASSERT(NRF_BLE_GATT_MAX_MTU_SIZE + LL_HEADER_LEN <= 255);


/**@brief Initialize a link's parameters to defaults. */
static void link_init(nrf_ble_gatt_link_t * p_link)
{
    p_link->att_mtu_desired            = NRF_BLE_GATT_MAX_MTU_SIZE;
    p_link->att_mtu_effective          = BLE_GATT_ATT_MTU_DEFAULT;
    p_link->att_mtu_exchange_pending   = false;
    p_link->att_mtu_exchange_requested = false;
    p_link->data_length_desired        = NRF_BLE_GATT_MAX_MTU_SIZE + LL_HEADER_LEN;
    p_link->data_length_effective      = BLE_GATT_ATT_MTU_DEFAULT + LL_HEADER_LEN;
}

/**@brief   Start a data length update request.
 * @details This function is called to request a data length update upon connection.
 *          When the peer requests a data length update, sd_ble_gap_data_length_update()
 *          is called directly in response to the BLE_GAP_EVT_DATA_LENGTH_UPDATE event in
 *          on_data_length_update_evt().
 */
static void data_length_update(uint16_t conn_handle, nrf_ble_gatt_t const * p_gatt)
{
    NRF_LOG_DEBUG("Requesting to update data length to %u on connection 0x%x.\r\n",
                  p_gatt->links[conn_handle].data_length_desired, conn_handle);

    ble_gap_data_length_params_t const dlp =
    {
        .max_rx_octets  = p_gatt->links[conn_handle].data_length_desired,
        .max_tx_octets  = p_gatt->links[conn_handle].data_length_desired,
        .max_rx_time_us = BLE_GAP_DATA_LENGTH_AUTO,
        .max_tx_time_us = BLE_GAP_DATA_LENGTH_AUTO,
    };

    ret_code_t err_code = sd_ble_gap_data_length_update(conn_handle, &dlp, NULL);
    if (err_code != NRF_SUCCESS)
    {
        NRF_LOG_ERROR("sd_ble_gap_data_length_update() (request)"
                      " on connection 0x%x returned unexpected value 0x%x.\r\n",
                      conn_handle, err_code);
    }
}


/**@brief Handle a connected event.
 *
 * @param[in]   p_gatt      GATT structure.
 * @param[in]   p_ble_evt   Event received from the BLE stack.
 */
static void on_connected_evt(nrf_ble_gatt_t * p_gatt, ble_evt_t const * p_ble_evt)
{
    ret_code_t            err_code;
    uint16_t              conn_handle = p_ble_evt->evt.common_evt.conn_handle;
    nrf_ble_gatt_link_t * p_link      = &p_gatt->links[conn_handle];

    // Update the link desired settings to reflect the current global settings.

    p_link->data_length_desired = p_gatt->data_length;

    switch (p_ble_evt->evt.gap_evt.params.connected.role)
    {
        case BLE_GAP_ROLE_PERIPH:
            p_link->att_mtu_desired = p_gatt->att_mtu_desired_periph;
            break;

        case BLE_GAP_ROLE_CENTRAL:
            p_link->att_mtu_desired = p_gatt->att_mtu_desired_central;
            break;

        default:
            // Ignore.
            break;
    }

    // Begin an ATT MTU exchange if necessary.
    if (p_link->att_mtu_desired > p_link->att_mtu_effective)
    {
        NRF_LOG_DEBUG("Requesting to update ATT MTU to %u bytes on connection 0x%x.\r\n",
                      p_link->att_mtu_desired, conn_handle);

        err_code = sd_ble_gattc_exchange_mtu_request(conn_handle, p_link->att_mtu_desired);

        if (err_code == NRF_SUCCESS)
        {
            p_link->att_mtu_exchange_requested = true;
        }
        else if (err_code == NRF_ERROR_BUSY)
        {
            p_link->att_mtu_exchange_pending = true;
            NRF_LOG_DEBUG("sd_ble_gattc_exchange_mtu_request()"
                          " on connection 0x%x returned busy, will retry.\r\n", conn_handle);
        }
        else
        {
            NRF_LOG_ERROR("sd_ble_gattc_exchange_mtu_request()"
                          " returned unexpected value 0x%x.\r\n",
                          err_code);
        }
    }

    // Send a data length update request if necessary.
    if (p_link->data_length_desired > p_link->data_length_effective)
    {
        data_length_update(conn_handle, p_gatt);
    }
}


static void on_disconnected_evt(nrf_ble_gatt_t * p_gatt, ble_evt_t const * p_ble_evt)
{
    // Reset connection parameters.
    link_init(&p_gatt->links[p_ble_evt->evt.gap_evt.conn_handle]);
}


/**@brief   Handle a BLE_GATTC_EVT_EXCHANGE_MTU_RSP event.
 *
 * @details The effective ATT MTU is set to the lowest between what we requested and the peer's
 *          response. This events concludes the ATT MTU exchange. An event is sent to the user
 *          and a data length update procedure is started if necessary.
 *
 * @param[in]   p_gatt      GATT structure.
 * @param[in]   p_ble_evt   Event received from the BLE stack.
 */
static void on_exchange_mtu_rsp_evt(nrf_ble_gatt_t * p_gatt, ble_evt_t const * p_ble_evt)
{
    uint16_t conn_handle   = p_ble_evt->evt.gattc_evt.conn_handle;
    uint16_t server_rx_mtu = p_ble_evt->evt.gattc_evt.params.exchange_mtu_rsp.server_rx_mtu;

    nrf_ble_gatt_link_t * p_link = &p_gatt->links[conn_handle];

    // Determine the lowest MTU between our own desired MTU and the peer's.
    // The MTU may not be less than BLE_GATT_ATT_MTU_DEFAULT.
    p_link->att_mtu_effective = MIN(server_rx_mtu, p_link->att_mtu_desired);
    p_link->att_mtu_effective = MAX(p_link->att_mtu_effective, BLE_GATT_ATT_MTU_DEFAULT);

    NRF_LOG_DEBUG("ATT MTU updated to %u bytes on connection 0x%x (response).\r\n",
                  p_link->att_mtu_effective, conn_handle);

    // Trigger an event indicating that the ATT MTU size has changed.
    // Send an event to the application only if an ATT MTU exchange was requested.
    if ((p_gatt->evt_handler != NULL) && (p_link->att_mtu_exchange_requested))
    {
        nrf_ble_gatt_evt_t const evt =
        {
            .evt_id                   = NRF_BLE_GATT_EVT_ATT_MTU_UPDATED,
            .conn_handle              = conn_handle,
            .params.att_mtu_effective = p_link->att_mtu_effective,
        };

        p_gatt->evt_handler(p_gatt, &evt);
    }

    p_link->att_mtu_exchange_requested = false;
    p_link->att_mtu_exchange_pending   = false;
}


/**@brief Handle a BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST event.
 *
 * @param[in]   p_gatt      GATT structure.
 * @param[in]   p_ble_evt   Event received from the BLE stack.
 */
static void on_exchange_mtu_request_evt(nrf_ble_gatt_t * p_gatt, ble_evt_t const * p_ble_evt)
{
    ret_code_t err_code;
    uint16_t   conn_handle = p_ble_evt->evt.gatts_evt.conn_handle;
    uint16_t   client_mtu  = p_ble_evt->evt.gatts_evt.params.exchange_mtu_request.client_rx_mtu;

    nrf_ble_gatt_link_t * p_link = &p_gatt->links[conn_handle];

    NRF_LOG_DEBUG("Peer on connection 0x%x requested an ATT MTU of %u bytes.\r\n",
                  conn_handle, client_mtu);

    client_mtu = MAX(client_mtu, BLE_GATT_ATT_MTU_DEFAULT);
    p_link->att_mtu_effective = MIN(client_mtu, p_link->att_mtu_desired);
    p_link->att_mtu_exchange_pending = false;

    NRF_LOG_DEBUG("Updating ATT MTU to %u bytes (desired: %u) on connection 0x%x.\r\n",
                  p_link->att_mtu_effective, p_link->att_mtu_desired, conn_handle);

    err_code = sd_ble_gatts_exchange_mtu_reply(conn_handle, p_link->att_mtu_desired);

    if (err_code != NRF_SUCCESS)
    {
        NRF_LOG_ERROR("sd_ble_gatts_exchange_mtu_reply() returned unexpected value 0x%x.\r\n",
                      err_code);
    }

    // If an ATT_MTU exchange was requested to the peer, defer sending
    // the data length update request and the event to the application until
    // the response for that request is received.
    if (p_link->att_mtu_exchange_requested)
    {
        return;
    }

    // The ATT MTU exchange has finished. Send an event to the application.
    if (p_gatt->evt_handler != NULL)
    {
        nrf_ble_gatt_evt_t const evt =
        {
            .evt_id                   = NRF_BLE_GATT_EVT_ATT_MTU_UPDATED,
            .conn_handle              = conn_handle,
            .params.att_mtu_effective = p_link->att_mtu_effective,
        };

        p_gatt->evt_handler(p_gatt, &evt);
    }
}


/**@brief   Handle a BLE_GAP_EVT_DATA_LENGTH_UPDATE event.
 *
 * @details Update the connection data length and send an event to the user.
 *
 * @param[in]   p_gatt      GATT structure.
 * @param[in]   p_ble_evt   Event received from the BLE stack.
 */
static void on_data_length_update_evt(nrf_ble_gatt_t * p_gatt, ble_evt_t const * p_ble_evt)
{
    ble_gap_evt_t const gap_evt     = p_ble_evt->evt.gap_evt;
    uint16_t      const conn_handle = gap_evt.conn_handle;

    // Update the connection data length.
    p_gatt->links[conn_handle].data_length_effective =
        gap_evt.params.data_length_update.effective_params.max_tx_octets;

    NRF_LOG_DEBUG("Data length updated to %u on connection 0x%0x.\r\n",
                  p_gatt->links[conn_handle].data_length_effective,
                  conn_handle);

    NRF_LOG_DEBUG("max_rx_octets: %u\r\n",
                  gap_evt.params.data_length_update.effective_params.max_rx_octets);
    NRF_LOG_DEBUG("max_tx_octets: %u\r\n",
                  gap_evt.params.data_length_update.effective_params.max_tx_octets);
    NRF_LOG_DEBUG("max_rx_time: %u\r\n",
                  gap_evt.params.data_length_update.effective_params.max_rx_time_us);
    NRF_LOG_DEBUG("max_tx_time: %u\r\n",
                  gap_evt.params.data_length_update.effective_params.max_tx_time_us);

    if (p_gatt->evt_handler != NULL)
    {
        nrf_ble_gatt_evt_t const evt =
        {
            .evt_id             = NRF_BLE_GATT_EVT_DATA_LENGTH_UPDATED,
            .conn_handle        = conn_handle,
            .params.data_length = p_gatt->links[conn_handle].data_length_effective,
        };

        p_gatt->evt_handler(p_gatt, &evt);
    }
}


/**@brief   Handle a BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST event.
 *
 *@details  Reply with a sd_ble_gap_data_length_update() call, using the minimum between the
 *          link's preferred data length, and what requested by the peer.
 *          The link preferred data length is set to the global preferred data length
 *          upon connection and can be overridden by calling nrf_ble_gatt_data_length_set().
 *          The default is NRF_BLE_GATT_MAX_MTU_SIZE + LL_HEADER_LEN.
 *
 *@note     The SoftDevice will not send any BLE_GAP_EVT_DATA_LENGTH_UPDATE events on this side.
 *          Therefore, the connection data length is updated immediately and an event is sent
 *          to the user.
 *
 * @param[in]   p_gatt      GATT structure.
 * @param[in]   p_ble_evt   Event received from the BLE stack.
 */
static void on_data_length_update_request_evt(nrf_ble_gatt_t * p_gatt, ble_evt_t const * p_ble_evt)
{
    ret_code_t err_code;

    ble_gap_evt_t       const * p_gap_evt = &p_ble_evt->evt.gap_evt;
    nrf_ble_gatt_link_t       * p_link    = &p_gatt->links[p_gap_evt->conn_handle];

    uint8_t const data_length_peer =
        p_gap_evt->params.data_length_update_request.peer_params.max_tx_octets;

    NRF_LOG_DEBUG("Peer on connection 0x%x requested a data length of %u bytes.\r\n",
                  p_gap_evt->conn_handle, data_length_peer);

    uint8_t const data_length = MIN(p_link->data_length_desired, data_length_peer);

    ble_gap_data_length_params_t const dlp =
    {
        .max_rx_octets = data_length,
        .max_tx_octets = data_length,
    };

    NRF_LOG_DEBUG("Updating data length to %u bytes on connection 0x%x.\r\n",
                  data_length, p_gap_evt->conn_handle);

    err_code = sd_ble_gap_data_length_update(p_gap_evt->conn_handle, &dlp, NULL);

    if (err_code != NRF_SUCCESS)
    {
        NRF_LOG_ERROR("sd_ble_gap_data_length_update() (reply)"
                      " returned unexpected value 0x%x.\r\n",
                      err_code);
    }
}


ret_code_t nrf_ble_gatt_init(nrf_ble_gatt_t * p_gatt, nrf_ble_gatt_evt_handler_t evt_handler)
{
    VERIFY_PARAM_NOT_NULL(p_gatt);

    p_gatt->evt_handler             = evt_handler;
    p_gatt->att_mtu_desired_periph  = NRF_BLE_GATT_MAX_MTU_SIZE;
    p_gatt->att_mtu_desired_central = NRF_BLE_GATT_MAX_MTU_SIZE;
    p_gatt->data_length             = NRF_BLE_GATT_MAX_MTU_SIZE + LL_HEADER_LEN;

    for (uint32_t i = 0; i < NRF_BLE_GATT_LINK_COUNT; i++)
    {
        link_init(&p_gatt->links[i]);
    }

    return NRF_SUCCESS;
}


ret_code_t nrf_ble_gatt_att_mtu_periph_set(nrf_ble_gatt_t * p_gatt, uint16_t desired_mtu)
{
    VERIFY_PARAM_NOT_NULL(p_gatt);

    if ((desired_mtu < BLE_GATT_ATT_MTU_DEFAULT) || (desired_mtu > NRF_BLE_GATT_MAX_MTU_SIZE))
    {
        return NRF_ERROR_INVALID_PARAM;
    }

    p_gatt->att_mtu_desired_periph = desired_mtu;
    return NRF_SUCCESS;
}


ret_code_t nrf_ble_gatt_att_mtu_central_set(nrf_ble_gatt_t * p_gatt, uint16_t desired_mtu)
{
    VERIFY_PARAM_NOT_NULL(p_gatt);

    if ((desired_mtu < BLE_GATT_ATT_MTU_DEFAULT) || (desired_mtu > NRF_BLE_GATT_MAX_MTU_SIZE))
    {
        return NRF_ERROR_INVALID_PARAM;
    }

    p_gatt->att_mtu_desired_central = desired_mtu;
    return NRF_SUCCESS;
}


uint16_t nrf_ble_gatt_eff_mtu_get(nrf_ble_gatt_t const * p_gatt, uint16_t conn_handle)
{
    if ((p_gatt == NULL) || (conn_handle >= NRF_BLE_GATT_LINK_COUNT))
    {
        return 0;
    }

    return p_gatt->links[conn_handle].att_mtu_effective;
}


ret_code_t nrf_ble_gatt_data_length_set(nrf_ble_gatt_t * p_gatt,
                                        uint16_t         conn_handle,
                                        uint8_t          data_length)
{
    ret_code_t err_code;

    if (p_gatt == NULL)
    {
        return NRF_ERROR_NULL;
    }

    if (conn_handle == BLE_CONN_HANDLE_INVALID)
    {
        p_gatt->data_length = MIN(data_length, NRF_BLE_GATT_MAX_MTU_SIZE + LL_HEADER_LEN);
        return NRF_SUCCESS;
    }

    if (conn_handle >= NRF_BLE_GATT_LINK_COUNT)
    {
        return NRF_ERROR_INVALID_PARAM;
    }

    p_gatt->links[conn_handle].data_length_desired = data_length;

    ble_gap_data_length_params_t const dlp =
    {
        .max_rx_octets = data_length,
        .max_tx_octets = data_length,
    };

    err_code = sd_ble_gap_data_length_update(conn_handle, &dlp, NULL);
    return err_code;
}


ret_code_t nrf_ble_gatt_data_length_get(nrf_ble_gatt_t const * p_gatt,
                                        uint16_t               conn_handle,
                                        uint8_t              * p_data_length)
{
    if ((p_gatt == NULL) || (p_data_length == NULL))
    {
        return NRF_ERROR_NULL;
    }

    if (conn_handle == BLE_CONN_HANDLE_INVALID)
    {
        *p_data_length = p_gatt->data_length;
        return NRF_SUCCESS;
    }

    if (conn_handle >= NRF_BLE_GATT_LINK_COUNT)
    {
        return NRF_ERROR_INVALID_PARAM;
    }

    *p_data_length = p_gatt->links[conn_handle].data_length_effective;
    return NRF_SUCCESS;
}


void nrf_ble_gatt_on_ble_evt(nrf_ble_gatt_t * p_gatt, ble_evt_t const * p_ble_evt)
{
    uint16_t conn_handle = p_ble_evt->evt.common_evt.conn_handle;

    if (conn_handle >= NRF_BLE_GATT_LINK_COUNT)
    {
        return;
    }

    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            on_connected_evt(p_gatt, p_ble_evt);
            break;

        case BLE_GAP_EVT_DISCONNECTED:
            on_disconnected_evt(p_gatt, p_ble_evt);
            break;

        case BLE_GATTC_EVT_EXCHANGE_MTU_RSP:
            on_exchange_mtu_rsp_evt(p_gatt, p_ble_evt);
            break;

        case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST:
            on_exchange_mtu_request_evt(p_gatt, p_ble_evt);
            break;

        case BLE_GAP_EVT_DATA_LENGTH_UPDATE:
            on_data_length_update_evt(p_gatt, p_ble_evt);
            break;

        case BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST:
            on_data_length_update_request_evt(p_gatt, p_ble_evt);
            break;

        default:
            break;
    }

    if (p_gatt->links[conn_handle].att_mtu_exchange_pending)
    {
        ret_code_t err_code;

        err_code = sd_ble_gattc_exchange_mtu_request(conn_handle,
                                                     p_gatt->links[conn_handle].att_mtu_desired);

        if (err_code == NRF_SUCCESS)
        {
            p_gatt->links[conn_handle].att_mtu_exchange_pending   = false;
            p_gatt->links[conn_handle].att_mtu_exchange_requested = true;

            NRF_LOG_DEBUG("Requesting to update ATT MTU to %u bytes on connection 0x%x (retry).\r\n",
                          p_gatt->links[conn_handle].att_mtu_desired, conn_handle);
        }
        else if (err_code != NRF_ERROR_BUSY)
        {
            NRF_LOG_ERROR("sd_ble_gattc_exchange_mtu_request() returned unexpected value 0x%x.\r\n",
                          err_code);
        }
    }
}

#endif //NRF_BLE_GATT_ENABLED