初始版本

This commit is contained in:
xiaozhengsheng
2025-08-19 09:49:41 +08:00
parent 10f1ddf1c1
commit 6df0f7d96e
2974 changed files with 1712873 additions and 54 deletions

View File

@@ -0,0 +1,558 @@
/**
* Copyright (c) 2014 - 2020, 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 <string.h>
#include "ble_conn.h"
#include "ble_serialization.h"
#include "cond_field_serialization.h"
#include "ble_struct_serialization.h"
#include "ble_gap_struct_serialization.h"
#include "ble_gatt_struct_serialization.h"
#include "ble_gattc_struct_serialization.h"
#include "ble_gatts_struct_serialization.h"
#include "ble_l2cap_struct_serialization.h"
#include "app_util.h"
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
uint32_t ble_enable_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_enable_params_t * * const pp_ble_enable_params)
{
SER_REQ_DEC_BEGIN(SD_BLE_ENABLE);
SER_PULL_COND(pp_ble_enable_params, ble_enable_params_t_dec);
SER_REQ_DEC_END;
}
#else
uint32_t ble_enable_req_dec(uint8_t const * const p_buf,
uint32_t packet_len)
{
SER_REQ_DEC_BEGIN(SD_BLE_ENABLE);
SER_REQ_DEC_END;
}
#endif
uint32_t ble_enable_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_ENABLE);
}
uint32_t ble_opt_get_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint32_t * const p_opt_id,
ble_opt_t **const pp_opt )
{
SER_REQ_DEC_BEGIN(SD_BLE_OPT_GET);
SER_ASSERT_NOT_NULL(p_opt_id);
SER_ASSERT_NOT_NULL(pp_opt);
SER_ASSERT_NOT_NULL(*pp_opt);
SER_PULL_uint32(p_opt_id);
SER_PULL_COND(pp_opt, NULL);
SER_REQ_DEC_END;
}
uint32_t ble_opt_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint32_t opt_id,
ble_opt_t const * const p_opt)
{
SER_RSP_ENC_BEGIN(SD_BLE_OPT_GET);
SER_ASSERT_NOT_NULL(p_opt);
SER_PUSH_uint32(&opt_id);
field_encoder_handler_t fp_encoder = NULL;
void const * p_struct = NULL;
switch (opt_id)
{
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
case BLE_COMMON_OPT_CONN_BW:
fp_encoder = ble_common_opt_conn_bw_t_enc;
p_struct = &p_opt->common_opt.conn_bw;
break;
#endif
case BLE_COMMON_OPT_PA_LNA:
fp_encoder = ble_common_opt_pa_lna_t_enc;
p_struct = &p_opt->common_opt.pa_lna;
break;
case BLE_COMMON_OPT_CONN_EVT_EXT:
fp_encoder = ble_common_opt_conn_evt_ext_t_enc;
p_struct = &p_opt->common_opt.conn_evt_ext;
break;
case BLE_GAP_OPT_CH_MAP:
fp_encoder = ble_gap_opt_ch_map_t_enc;
p_struct = &p_opt->gap_opt.ch_map;
break;
case BLE_GAP_OPT_LOCAL_CONN_LATENCY:
fp_encoder = ble_gap_opt_local_conn_latency_t_enc;
p_struct = &p_opt->gap_opt.local_conn_latency;
break;
case BLE_GAP_OPT_PASSKEY:
fp_encoder = ble_gap_opt_passkey_t_enc;
p_struct = &p_opt->gap_opt.passkey;
break;
case BLE_GAP_OPT_AUTH_PAYLOAD_TIMEOUT:
fp_encoder = ble_gap_opt_auth_payload_timeout_t_enc;
p_struct = &p_opt->gap_opt.auth_payload_timeout;
break;
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
case BLE_GAP_OPT_EXT_LEN:
fp_encoder = ble_gap_opt_ext_len_t_enc;
p_struct = &p_opt->gap_opt.ext_len;
break;
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 6
case BLE_GAP_OPT_SCAN_REQ_REPORT:
fp_encoder = ble_gap_opt_scan_req_report_t_enc;
p_struct = &p_opt->gap_opt.scan_req_report;
break;
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
case BLE_GAP_OPT_COMPAT_MODE:
fp_encoder = ble_gap_opt_compat_mode_t_enc;
p_struct = &p_opt->gap_opt.compat_mode;
break;
#else
#ifndef S112
case BLE_GAP_OPT_COMPAT_MODE_1:
fp_encoder = ble_gap_opt_compat_mode_1_t_enc;
p_struct = &p_opt->gap_opt.compat_mode_1;
break;
#endif
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION == 4
case BLE_GAP_OPT_COMPAT_MODE_2:
fp_encoder = ble_gap_opt_compat_mode_2_t_enc;
p_struct = &p_opt->gap_opt.compat_mode_2;
break;
#endif
default:
SER_ASSERT(NRF_ERROR_INVALID_PARAM, NRF_ERROR_INVALID_PARAM);
break;
}
SER_PUSH_FIELD(p_struct, fp_encoder);
SER_RSP_ENC_END;
}
uint32_t ble_opt_set_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint32_t * const p_opt_id,
ble_opt_t **const pp_opt )
{
SER_REQ_DEC_BEGIN(SD_BLE_OPT_SET);
SER_ASSERT_NOT_NULL(p_opt_id);
SER_ASSERT_NOT_NULL(pp_opt);
SER_ASSERT_NOT_NULL(*pp_opt);
SER_PULL_uint32(p_opt_id);
SER_PULL_COND(pp_opt, NULL);
if (*pp_opt)
{
field_decoder_handler_t fp_decoder = NULL;
void * p_struct = NULL;
switch (*p_opt_id)
{
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
case BLE_COMMON_OPT_CONN_BW:
fp_decoder = ble_common_opt_conn_bw_t_dec;
p_struct = &((*pp_opt)->common_opt.conn_bw);
break;
#endif
case BLE_COMMON_OPT_PA_LNA:
fp_decoder = ble_common_opt_pa_lna_t_dec;
p_struct = &((*pp_opt)->common_opt.pa_lna);
break;
case BLE_COMMON_OPT_CONN_EVT_EXT:
fp_decoder = ble_common_opt_conn_evt_ext_t_dec;
p_struct = &((*pp_opt)->common_opt.conn_evt_ext);
break;
case BLE_GAP_OPT_CH_MAP:
fp_decoder = ble_gap_opt_ch_map_t_dec;
p_struct = &((*pp_opt)->gap_opt.ch_map);
break;
case BLE_GAP_OPT_LOCAL_CONN_LATENCY:
fp_decoder = ble_gap_opt_local_conn_latency_t_dec;
p_struct = &((*pp_opt)->gap_opt.local_conn_latency);
break;
case BLE_GAP_OPT_PASSKEY:
fp_decoder = ble_gap_opt_passkey_t_dec;
p_struct = &((*pp_opt)->gap_opt.passkey);
break;
case BLE_GAP_OPT_AUTH_PAYLOAD_TIMEOUT:
fp_decoder = ble_gap_opt_auth_payload_timeout_t_dec;
p_struct = &((*pp_opt)->gap_opt.auth_payload_timeout);
break;
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
case BLE_GAP_OPT_EXT_LEN:
fp_decoder = ble_gap_opt_ext_len_t_dec;
p_struct = &((*pp_opt)->gap_opt.ext_len);
break;
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 6
case BLE_GAP_OPT_SCAN_REQ_REPORT:
fp_decoder = ble_gap_opt_scan_req_report_t_dec;
p_struct = &((*pp_opt)->gap_opt.scan_req_report);
break;
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
case BLE_GAP_OPT_COMPAT_MODE:
fp_decoder = ble_gap_opt_compat_mode_t_dec;
p_struct = &((*pp_opt)->gap_opt.compat_mode);
break;
#else
#ifndef S112
case BLE_GAP_OPT_COMPAT_MODE_1:
fp_decoder = ble_gap_opt_compat_mode_1_t_dec;
p_struct = &((*pp_opt)->gap_opt.compat_mode_1);
break;
#endif
case BLE_GAP_OPT_SLAVE_LATENCY_DISABLE:
fp_decoder = ble_gap_opt_slave_latency_disable_t_dec;
p_struct = &((*pp_opt)->gap_opt.slave_latency_disable);
break;
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION == 4
case BLE_GAP_OPT_COMPAT_MODE_2:
fp_decoder = ble_gap_opt_compat_mode_2_t_dec;
p_struct = &((*pp_opt)->gap_opt.compat_mode_2);
break;
#endif
default:
SER_ASSERT(NRF_ERROR_INVALID_PARAM,NRF_ERROR_INVALID_PARAM);
break;
}
SER_PULL_FIELD(p_struct, fp_decoder);
}
SER_REQ_DEC_END;
}
uint32_t ble_opt_set_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_OPT_SET);
}
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
uint32_t ble_tx_packet_count_get_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
uint8_t * * const pp_count)
{
SER_REQ_DEC_BEGIN(SD_BLE_TX_PACKET_COUNT_GET);
SER_PULL_uint16(p_conn_handle);
SER_PULL_COND(pp_count, NULL);
SER_REQ_DEC_END;
}
uint32_t ble_tx_packet_count_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint8_t const * const p_count)
{
SER_RSP_ENC_BEGIN(SD_BLE_TX_PACKET_COUNT_GET);
SER_PUSH_COND(p_count, uint8_t_enc);
SER_RSP_ENC_END;
}
#endif
uint32_t ble_user_mem_reply_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_conn_handle,
ble_user_mem_block_t * * const pp_mem_block)
{
SER_REQ_DEC_BEGIN(SD_BLE_USER_MEM_REPLY);
SER_ASSERT_NOT_NULL(p_conn_handle);
SER_ASSERT_NOT_NULL(pp_mem_block);
SER_ASSERT_NOT_NULL(*pp_mem_block);
SER_PULL_uint16(p_conn_handle);
SER_PULL_COND(pp_mem_block, ble_user_mem_block_t_dec);
SER_REQ_DEC_END;
}
uint32_t ble_user_mem_reply_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_USER_MEM_REPLY);
}
uint32_t ble_uuid_decode_req_dec(uint8_t const * const p_buf,
uint32_t const packet_len,
uint8_t * p_uuid_le_len,
uint8_t * * const pp_uuid_le,
ble_uuid_t * * const pp_uuid)
{
SER_REQ_DEC_BEGIN(SD_BLE_UUID_DECODE);
SER_PULL_len8data(pp_uuid_le, p_uuid_le_len);
SER_PULL_COND(pp_uuid, NULL);
SER_REQ_DEC_END;
}
uint32_t ble_uuid_decode_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
ble_uuid_t const * const p_uuid)
{
SER_RSP_ENC_BEGIN(SD_BLE_UUID_DECODE);
SER_PUSH_COND(p_uuid, ble_uuid_t_enc);
SER_RSP_ENC_END;
}
uint32_t ble_uuid_encode_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
ble_uuid_t * * const pp_uuid,
uint8_t * * const pp_uuid_le_len,
uint8_t * * const pp_uuid_le)
{
SER_REQ_DEC_BEGIN(SD_BLE_UUID_ENCODE);
SER_ASSERT_NOT_NULL(pp_uuid);
SER_ASSERT_NOT_NULL(pp_uuid_le_len);
SER_ASSERT_NOT_NULL(pp_uuid_le);
SER_ASSERT_NOT_NULL(*pp_uuid);
SER_ASSERT_NOT_NULL(*pp_uuid_le_len);
SER_ASSERT_NOT_NULL(*pp_uuid_le);
SER_PULL_COND(pp_uuid, ble_uuid_t_dec);
SER_PULL_COND(pp_uuid_le_len, NULL);
SER_PULL_COND(pp_uuid_le, NULL);
SER_REQ_DEC_END;
}
uint32_t ble_uuid_encode_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint8_t uuid_le_len,
uint8_t const * const p_uuid_le)
{
SER_RSP_ENC_BEGIN(SD_BLE_UUID_ENCODE);
SER_PUSH_uint8(&uuid_le_len);
if (p_uuid_le != NULL)
{
SER_PUSH_uint8array(p_uuid_le, uuid_le_len);
}
SER_RSP_ENC_END;
}
uint32_t ble_uuid_vs_add_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
ble_uuid128_t * * const pp_uuid,
uint8_t * * const pp_uuid_type)
{
SER_REQ_DEC_BEGIN(SD_BLE_UUID_VS_ADD);
SER_ASSERT_NOT_NULL(pp_uuid);
SER_ASSERT_NOT_NULL(pp_uuid_type);
SER_ASSERT_NOT_NULL(*pp_uuid);
SER_ASSERT_NOT_NULL(*pp_uuid_type);
SER_PULL_COND(pp_uuid, ble_uuid128_t_dec);
SER_PULL_COND(pp_uuid_type, NULL);
SER_REQ_DEC_END;
}
uint32_t ble_uuid_vs_add_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint8_t const * const p_uuid_type)
{
SER_RSP_ENC_BEGIN(SD_BLE_UUID_VS_ADD);
SER_PUSH_COND(p_uuid_type, uint8_t_enc);
SER_RSP_ENC_END;
}
uint32_t ble_version_get_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
ble_version_t * * const pp_version)
{
SER_REQ_DEC_BEGIN(SD_BLE_VERSION_GET);
SER_ASSERT_NOT_NULL(pp_version);
SER_ASSERT_NOT_NULL(*pp_version);
SER_PULL_COND(pp_version, NULL);
SER_REQ_DEC_END;
}
uint32_t ble_version_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
ble_version_t const * const p_version)
{
SER_RSP_ENC_BEGIN(SD_BLE_VERSION_GET);
SER_PUSH_FIELD(p_version, ble_version_t_enc);
SER_RSP_ENC_END;
}
uint32_t ble_opt_id_pre_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint32_t * const p_opt_id)
{
SER_REQ_DEC_BEGIN(SD_BLE_OPT_SET);
SER_ASSERT_NOT_NULL(p_opt_id);
SER_PULL_uint32(p_opt_id);
// Pre-decoding; do not check if the whole packet was processed.
return NRF_SUCCESS;
}
#if NRF_SD_BLE_API_VERSION >= 4
uint32_t ble_cfg_set_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * p_cfg_id,
ble_cfg_t * * const pp_cfg)
{
SER_REQ_DEC_BEGIN(SD_BLE_CFG_SET);
SER_PULL_uint32(p_cfg_id);
SER_PULL_COND(pp_cfg, NULL);
if (*pp_cfg)
{
field_decoder_handler_t fp_decoder = NULL;
void * p_struct = NULL;
switch (*p_cfg_id)
{
case BLE_CONN_CFG_GAP:
fp_decoder = ble_gap_conn_cfg_t_dec;
p_struct = &((*pp_cfg)->conn_cfg.params.gap_conn_cfg);
break;
case BLE_CONN_CFG_GATTC:
fp_decoder = ble_gattc_conn_cfg_t_dec;
p_struct = &((*pp_cfg)->conn_cfg.params.gattc_conn_cfg);
break;
case BLE_CONN_CFG_GATTS:
fp_decoder = ble_gatts_conn_cfg_t_dec;
p_struct = &((*pp_cfg)->conn_cfg.params.gatts_conn_cfg);
break;
case BLE_CONN_CFG_GATT:
fp_decoder = ble_gatt_conn_cfg_t_dec;
p_struct = &((*pp_cfg)->conn_cfg.params.gatt_conn_cfg);
break;
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION >= 5 && !defined(S112)
case BLE_CONN_CFG_L2CAP:
fp_decoder = ble_l2cap_conn_cfg_t_dec;
p_struct = &((*pp_cfg)->conn_cfg.params.l2cap_conn_cfg);
break;
#endif
case BLE_COMMON_CFG_VS_UUID:
fp_decoder = ble_common_cfg_vs_uuid_t_dec;
p_struct = &((*pp_cfg)->common_cfg.vs_uuid_cfg);
break;
case BLE_GAP_CFG_ROLE_COUNT:
fp_decoder = ble_gap_cfg_role_count_t_dec;
p_struct = &((*pp_cfg)->gap_cfg.role_count_cfg);
break;
case BLE_GAP_CFG_DEVICE_NAME:
fp_decoder = ble_gap_cfg_device_name_t_dec;
p_struct = &((*pp_cfg)->gap_cfg.device_name_cfg);
break;
case BLE_GATTS_CFG_SERVICE_CHANGED:
fp_decoder = ble_gatts_cfg_service_changed_t_dec;
p_struct = &((*pp_cfg)->gatts_cfg.service_changed);
break;
case BLE_GATTS_CFG_ATTR_TAB_SIZE:
fp_decoder = ble_gatts_cfg_attr_tab_size_t_dec;
p_struct = &((*pp_cfg)->gatts_cfg.attr_tab_size);
break;
default:
SER_ASSERT(NRF_ERROR_INVALID_PARAM,NRF_ERROR_INVALID_PARAM);
break;
}
if (*p_cfg_id >= BLE_CONN_CFG_BASE && *p_cfg_id <= BLE_CONN_CFG_GATT)
{
SER_PULL_uint8(&(*pp_cfg)->conn_cfg.conn_cfg_tag);
}
SER_PULL_FIELD(p_struct, fp_decoder);
}
SER_REQ_DEC_END;
}
uint32_t ble_cfg_set_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_CFG_SET);
}
#endif

View File

@@ -0,0 +1,521 @@
/**
* Copyright (c) 2013 - 2020, 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.
*
*/
#ifndef BLE_CONN_H__
#define BLE_CONN_H__
/**
* @addtogroup ser_conn_s130_codecs Connectivity codecs for S132 and S140
* @ingroup ser_codecs_conn
*/
/**@file
*
* @defgroup ble_conn Connectivity command request decoders and command response encoders
* @{
* @ingroup ser_conn_s130_codecs
*
* @brief Connectivity command request decoders and command response encoders.
*/
#include "ble.h"
#ifdef __cplusplus
extern "C" {
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
/**@brief Decodes @ref sd_ble_tx_packet_count_get command request.
*
* @sa @ref ble_tx_packet_count_get_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_conn_handle Pointer to connection handle.
* @param[out] pp_count Pointer to pointer to location for count.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_tx_packet_count_get_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
uint8_t * * const pp_count);
/**@brief Encodes @ref sd_ble_tx_packet_count_get command response.
*
* @sa @ref ble_tx_packet_count_get_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_count Pointer to count value.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_tx_packet_count_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint8_t const * const p_count);
#endif
/**@brief Event encoding dispatcher.
*
* The event encoding dispatcher will route the event packet to the correct encoder which in turn
* encodes the contents of the event and updates the \p p_buf buffer.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
* @retval NRF_ERROR_NOT_SUPPORTED Event encoder is not implemented.
*/
uint32_t ble_event_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_version_get command request.
*
* @sa @ref ble_version_get_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] pp_version Pointer to pointer to @ref ble_version_t address.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_version_get_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
ble_version_t * * const pp_version);
/**@brief Encodes @ref sd_ble_version_get command response.
*
* @sa @ref ble_version_get_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_version Pointer to @ref ble_version_t address.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_version_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
ble_version_t const * const p_version);
/**@brief Decodes @ref sd_ble_opt_get command request.
*
* @sa @ref ble_opt_get_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_opt_id Pointer to pointer to @ref ble_version_t address.
* @param[out] pp_opt Pointer to pointer to @ref ble_opt_t address.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_opt_get_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint32_t * const p_opt_id,
ble_opt_t **const pp_opt );
/**@brief Encodes @ref sd_ble_opt_get command response.
*
* @sa @ref ble_opt_get_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] opt_id identifies type of ble_opt_t union
* @param[in] p_opt Pointer to @ref ble_opt_t union.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_opt_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint32_t opt_id,
ble_opt_t const * const p_opt);
/**@brief Decodes @ref sd_ble_opt_set command request.
*
* @sa @ref ble_opt_set_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_opt_id Pointer to @ref ble_opt_t union type identifier.
* @param[out] pp_opt Pointer to pointer to @ref ble_opt_t union.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_opt_set_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint32_t * const p_opt_id,
ble_opt_t **const pp_opt );
/**@brief Encodes @ref sd_ble_opt_set command response.
*
* @sa @ref ble_opt_set_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_opt_set_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_uuid_encode command request.
*
* @sa @ref ble_uuid_encode_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] pp_uuid Pointer to pointer to @ref ble_uuid_t structure.
* @param[out] pp_uuid_le_len Pointer to pointer to the length of encoded UUID.
* @param[out] pp_uuid_le Pointer to pointer to buffer where encoded UUID will be stored.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_uuid_encode_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
ble_uuid_t * * const pp_uuid,
uint8_t * * const pp_uuid_le_len,
uint8_t * * const pp_uuid_le);
/**@brief Encodes @ref sd_ble_uuid_encode command response.
*
* @sa @ref ble_uuid_encode_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] uuid_le_len Length of the encoded UUID.
* @param[in] p_uuid_le Pointer to the buffer with encoded UUID.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_uuid_encode_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint8_t uuid_le_len,
uint8_t const * const p_uuid_le);
/**@brief Decodes @ref sd_ble_uuid_decode command request.
*
* @sa @ref ble_uuid_decode_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_uuid_le_len Pointer to the length of encoded UUID.
* @param[out] pp_uuid_le Pointer to pointer to buffer where encoded UUID will be stored.
* @param[out] pp_uuid Pointer to pointer to @ref ble_uuid_t structure.
* \c It will be set to NULL if p_uuid is not present in the packet.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_uuid_decode_req_dec(uint8_t const * const p_buf,
uint32_t const packet_len,
uint8_t * p_uuid_le_len,
uint8_t * * const pp_uuid_le,
ble_uuid_t * * const pp_uuid);
/**@brief Encodes @ref sd_ble_uuid_decode command response.
*
* @sa @ref ble_uuid_decode_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_uuid Pointer to the buffer with encoded UUID.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_uuid_decode_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
ble_uuid_t const * const p_uuid);
/**@brief Decodes @ref sd_ble_uuid_vs_add command request.
*
* @sa @ref ble_uuid_vs_add_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] pp_uuid Pointer to pointer to UUID.
* \c It will be set to NULL if p_uuid is not present in the packet.
* @param[out] pp_uuid_type Pointer to pointer to UUID type.
* \c It will be set to NULL if p_uuid_type is not present in the packet.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_uuid_vs_add_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
ble_uuid128_t * * const pp_uuid,
uint8_t * * const pp_uuid_type);
/**@brief Encodes @ref sd_ble_uuid_vs_add command response.
*
* @sa @ref ble_uuid_vs_add_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_uuid_type Pointer to the UUID type.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_uuid_vs_add_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint8_t const * const p_uuid_type);
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
/**@brief Decodes @ref sd_ble_enable command request.
*
* @sa @ref ble_enable_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] pp_ble_enable_params Pointer to pointer to ble_enable_params_t.
* \c It will be set to NULL if p_ble_enable_params is not present in the packet.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_enable_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_enable_params_t * * const pp_ble_enable_params);
#else
/**@brief Decodes @ref sd_ble_enable command request.
*
* @sa @ref ble_enable_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_enable_req_dec(uint8_t const * const p_buf,
uint32_t packet_len);
#endif
/**@brief Encodes @ref sd_ble_enable command response.
*
* @sa @ref ble_enable_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_enable_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Pre-decodes opt_id of @ref ble_opt_t for middleware.
*
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] packet_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in,out] p_opt_id Pointer to opt_id which identifies type of @ref ble_opt_t union.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_opt_id_pre_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint32_t * const p_opt_id);
/**@brief Decodes @ref sd_ble_user_mem_reply command request.
*
* @sa @ref ble_user_mem_reply_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[in] p_conn_handle Pointer to Connection Handle.
* @param[in,out] pp_block Pointer to pointer to ble_user_mem_block_t.
* \c It will be set to NULL if p_block is not present in the packet.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_user_mem_reply_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_conn_handle,
ble_user_mem_block_t * * const pp_block);
/**@brief Encodes @ref sd_ble_user_mem_reply command response.
*
* @sa @ref ble_user_mem_reply_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_user_mem_reply_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#if NRF_SD_BLE_API_VERSION >= 4
/**@brief Decodes @ref sd_ble_cfg_set command request.
*
* @sa @ref ble_cfg_set_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[in] p_cfg_id Pointer to ConfigurationId.
* @param[in,out] pp_cfg Pointer to pointer to configuration struct.
* \c It will be set to NULL if p_block is not present in the packet.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_cfg_set_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * p_cfg_id,
ble_cfg_t * * const pp_cfg);
/**@brief Encodes @ref sd_ble_cfg_set command response.
*
* @sa @ref ble_cfg_set_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_cfg_set_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#endif
/** @} */
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,308 @@
/**
* Copyright (c) 2013 - 2020, 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 "ble_conn.h"
#include "ble_evt_conn.h"
#include "ble_gap_evt_conn.h"
#include "ble_gattc_evt_conn.h"
#include "ble_gatts_evt_conn.h"
#include "ble_l2cap_evt_conn.h"
#include "ble_serialization.h"
#include "app_util.h"
#include "nrf_log.h"
#include "ser_dbg_sd_str.h"
uint32_t ble_event_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
uint32_t ret_val = NRF_SUCCESS;
SER_ASSERT_NOT_NULL(p_buf);
SER_ASSERT_NOT_NULL(p_buf_len);
SER_ASSERT_NOT_NULL(p_event);
NRF_LOG_DEBUG("event:%s", ser_dbg_sd_evt_str_get(p_event->header.evt_id));
switch (p_event->header.evt_id)
{
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
case BLE_EVT_TX_COMPLETE:
ret_val = ble_evt_tx_complete_enc(p_event, event_len, p_buf, p_buf_len);
break;
#endif
case BLE_EVT_USER_MEM_RELEASE:
ret_val = ble_evt_user_mem_release_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_EVT_USER_MEM_REQUEST:
ret_val = ble_evt_user_mem_request_enc(p_event, event_len, p_buf, p_buf_len);
break;
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
case BLE_EVT_DATA_LENGTH_CHANGED:
ret_val = ble_evt_data_length_changed_enc(p_event, event_len, p_buf, p_buf_len);
break;
#endif
case BLE_GAP_EVT_CONN_PARAM_UPDATE:
ret_val = ble_gap_evt_conn_param_update_enc(p_event, event_len, p_buf, p_buf_len);
break;
#ifndef S112
case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST:
ret_val = ble_gap_evt_conn_param_update_request_enc(p_event, event_len, p_buf, p_buf_len);
break;
#endif //!S112
case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
ret_val = ble_gap_evt_sec_params_request_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GAP_EVT_SEC_INFO_REQUEST:
ret_val = ble_gap_evt_sec_info_request_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GAP_EVT_AUTH_STATUS:
ret_val = ble_gap_evt_auth_status_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GAP_EVT_PASSKEY_DISPLAY:
ret_val = ble_gap_evt_passkey_display_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GAP_EVT_AUTH_KEY_REQUEST:
ret_val = ble_gap_evt_auth_key_request_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GAP_EVT_CONN_SEC_UPDATE:
ret_val = ble_gap_evt_conn_sec_update_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GAP_EVT_RSSI_CHANGED:
ret_val = ble_gap_evt_rssi_changed_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GAP_EVT_TIMEOUT:
ret_val = ble_gap_evt_timeout_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GAP_EVT_DISCONNECTED:
ret_val = ble_gap_evt_disconnected_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GAP_EVT_CONNECTED:
ret_val = ble_gap_evt_connected_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GAP_EVT_SEC_REQUEST:
ret_val = ble_gap_evt_sec_request_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GAP_EVT_KEY_PRESSED:
ret_val = ble_gap_evt_key_pressed_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GAP_EVT_LESC_DHKEY_REQUEST:
ret_val = ble_gap_evt_lesc_dhkey_request_enc(p_event, event_len, p_buf, p_buf_len);
break;
#if NRF_SD_BLE_API_VERSION >= 5
case BLE_GAP_EVT_PHY_UPDATE:
ret_val = ble_gap_evt_phy_update_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
ret_val = ble_gap_evt_phy_update_request_enc(p_event, event_len, p_buf, p_buf_len);
break;
#endif
#if NRF_SD_BLE_API_VERSION >= 6
#ifndef S112
case BLE_GAP_EVT_QOS_CHANNEL_SURVEY_REPORT:
ret_val = ble_gap_evt_qos_channel_survey_report_enc(p_event, event_len, p_buf, p_buf_len);
break;
#endif
case BLE_GAP_EVT_ADV_SET_TERMINATED:
ret_val = ble_gap_evt_adv_set_terminated_enc(p_event, event_len, p_buf, p_buf_len);
break;
#endif
#if NRF_SD_BLE_API_VERSION >= 4 && !defined(S112)
case BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST:
ret_val = ble_gap_evt_data_length_update_request_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GAP_EVT_DATA_LENGTH_UPDATE:
ret_val = ble_gap_evt_data_length_update_enc(p_event, event_len, p_buf, p_buf_len);
break;
#endif //NRF_SD_BLE_API_VERSION >= 4 && !defined(S112)
case BLE_GATTC_EVT_CHAR_DISC_RSP:
ret_val = ble_gattc_evt_char_disc_rsp_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTC_EVT_DESC_DISC_RSP:
ret_val = ble_gattc_evt_desc_disc_rsp_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP:
ret_val = ble_gattc_evt_char_val_by_uuid_read_rsp_enc(p_event,
event_len,
p_buf,
p_buf_len);
break;
case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP:
ret_val = ble_gattc_evt_prim_srvc_disc_rsp_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTC_EVT_HVX:
ret_val = ble_gattc_evt_hvx_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTC_EVT_READ_RSP:
ret_val = ble_gattc_evt_read_rsp_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTC_EVT_TIMEOUT:
ret_val = ble_gattc_evt_timeout_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTC_EVT_WRITE_RSP:
ret_val = ble_gattc_evt_write_rsp_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTC_EVT_REL_DISC_RSP:
ret_val = ble_gattc_evt_rel_disc_rsp_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTC_EVT_CHAR_VALS_READ_RSP:
ret_val = ble_gattc_evt_char_vals_read_rsp_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTC_EVT_ATTR_INFO_DISC_RSP:
ret_val = ble_gattc_evt_attr_info_disc_rsp_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTC_EVT_EXCHANGE_MTU_RSP:
ret_val = ble_gattc_evt_exchange_mtu_rsp_enc(p_event, event_len, p_buf, p_buf_len);
break;
#if NRF_SD_BLE_API_VERSION >= 4
case BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE:
ret_val = ble_gattc_evt_write_cmd_tx_complete_enc(p_event, event_len, p_buf, p_buf_len);
break;
#endif
case BLE_GATTS_EVT_HVC:
ret_val = ble_gatts_evt_hvc_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTS_EVT_TIMEOUT:
ret_val = ble_gatts_evt_timeout_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTS_EVT_SC_CONFIRM:
ret_val = ble_gatts_evt_sc_confirm_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTS_EVT_WRITE:
ret_val = ble_gatts_evt_write_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
ret_val = ble_gatts_evt_rw_authorize_request_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTS_EVT_SYS_ATTR_MISSING:
ret_val = ble_gatts_evt_sys_attr_missing_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST:
ret_val = ble_gatts_evt_exchange_mtu_request_enc(p_event, event_len, p_buf, p_buf_len);
break;
#if NRF_SD_BLE_API_VERSION >= 4
case BLE_GATTS_EVT_HVN_TX_COMPLETE:
ret_val = ble_gatts_evt_hvn_tx_complete_enc(p_event, event_len, p_buf, p_buf_len);
break;
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
case BLE_L2CAP_EVT_RX:
ret_val = ble_l2cap_evt_rx_enc(p_event, event_len, p_buf, p_buf_len);
break;
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION >= 5 && !defined(S112)
case BLE_L2CAP_EVT_CH_SETUP_REQUEST:
ret_val = ble_l2cap_evt_ch_setup_request_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_L2CAP_EVT_CH_SETUP_REFUSED:
ret_val = ble_l2cap_evt_ch_setup_refused_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_L2CAP_EVT_CH_SETUP:
ret_val = ble_l2cap_evt_ch_setup_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_L2CAP_EVT_CH_RELEASED:
ret_val = ble_l2cap_evt_ch_released_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_L2CAP_EVT_CH_SDU_BUF_RELEASED:
ret_val = ble_l2cap_evt_ch_sdu_buf_released_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_L2CAP_EVT_CH_CREDIT:
ret_val = ble_l2cap_evt_ch_credit_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_L2CAP_EVT_CH_RX:
ret_val = ble_l2cap_evt_ch_rx_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_L2CAP_EVT_CH_TX:
ret_val = ble_l2cap_evt_ch_tx_enc(p_event, event_len, p_buf, p_buf_len);
break;
#endif //defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION >= 5 && !defined(S112)
#ifndef S112
case BLE_GAP_EVT_ADV_REPORT:
ret_val = ble_gap_evt_adv_report_enc(p_event, event_len, p_buf, p_buf_len);
break;
#endif //!S112
case BLE_GAP_EVT_SCAN_REQ_REPORT:
ret_val = ble_gap_evt_scan_req_report_enc(p_event, event_len, p_buf, p_buf_len);
break;
default:
ret_val = NRF_ERROR_NOT_SUPPORTED;
*p_buf_len = 0;
break;
}
return ret_val;
}

View File

@@ -0,0 +1,108 @@
/**
* Copyright (c) 2013 - 2020, 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 "ble_evt_conn.h"
#include <string.h>
#include "ble_serialization.h"
#include "ble_struct_serialization.h"
#include "app_util.h"
#include "conn_ble_user_mem.h"
uint32_t ble_evt_user_mem_release_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_EVT_USER_MEM_RELEASE);
SER_PUSH_uint16(&p_event->evt.common_evt.conn_handle);
SER_PUSH_uint8(&p_event->evt.common_evt.params.user_mem_release.type);
SER_PUSH_uint16(&p_event->evt.common_evt.params.user_mem_release.mem_block.len);
SER_PUSH_COND(p_event->evt.common_evt.params.user_mem_release.mem_block.p_mem, NULL);
// Now user memory context can be released
err_code = conn_ble_user_mem_context_destroy(p_event->evt.common_evt.conn_handle);
SER_ASSERT(err_code == NRF_SUCCESS, err_code);
SER_EVT_ENC_END;
}
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
uint32_t ble_evt_tx_complete_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_EVT_TX_COMPLETE);
SER_PUSH_uint16(&p_event->evt.common_evt.conn_handle);
SER_PUSH_uint8(&p_event->evt.common_evt.params.tx_complete.count);
SER_EVT_ENC_END;
}
#endif
uint32_t ble_evt_user_mem_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_EVT_USER_MEM_REQUEST);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_uint8(&p_event->evt.common_evt.params.user_mem_request.type);
SER_EVT_ENC_END;
}
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
uint32_t ble_evt_data_length_changed_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_EVT_DATA_LENGTH_CHANGED);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.common_evt.params.data_length_changed, ble_evt_data_length_changed_t_enc);
SER_EVT_ENC_END;
}
#endif

View File

@@ -0,0 +1,138 @@
/**
* Copyright (c) 2014 - 2020, 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.
*
*/
#ifndef BLE_EVT_CONN_H__
#define BLE_EVT_CONN_H__
/**@file
*
* @defgroup ble_evt_conn Connectivity event encoders
* @{
* @ingroup ser_conn_s130_codecs
*
* @brief Connectivity event encoders.
*/
#include "ble.h"
#ifdef __cplusplus
extern "C" {
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
/**
* @brief Encodes ble_evt_tx_complete event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that will be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_evt_tx_complete_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#endif
/**
* @brief Encodes ble_evt_user_mem_release event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_evt_user_mem_release_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_evt_user_mem_request event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that will be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_evt_user_mem_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
/**
* @brief Encodes ble_evt_data_length_changed event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that will be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_evt_data_length_changed_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#endif
/** @} */
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,412 @@
/**
* Copyright (c) 2014 - 2020, 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 "ble.h"
#include "ble_gap_evt_conn.h"
#include <string.h>
#include "ble_serialization.h"
#include "cond_field_serialization.h"
#include "ble_gap_struct_serialization.h"
#include "ble_struct_serialization.h"
#include "conn_ble_gap_sec_keys.h"
#include "app_util.h"
extern ser_ble_gap_conn_keyset_t m_conn_keys_table[];
#ifndef S112
uint32_t ble_gap_evt_adv_report_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_ADV_REPORT);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.adv_report, ble_gap_evt_adv_report_t_enc);
#if NRF_SD_BLE_API_VERSION > 5
conn_ble_gap_scan_data_unset(false);
#endif
SER_EVT_ENC_END;
}
#endif //!S112
uint32_t ble_gap_evt_auth_key_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_AUTH_KEY_REQUEST);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_uint8(&p_event->evt.gap_evt.params.auth_key_request.key_type);
SER_EVT_ENC_END;
}
uint32_t ble_gap_evt_auth_status_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_AUTH_STATUS);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.auth_status, ble_gap_evt_auth_status_t_enc);
// keyset is an extension of standard event data - used to synchronize keys at application
uint32_t conn_index;
err_code = conn_ble_gap_sec_context_find(p_event->evt.gap_evt.conn_handle, &conn_index);
if (err_code == NRF_SUCCESS)
{
SER_PUSH_FIELD(&(m_conn_keys_table[conn_index].keyset), ble_gap_sec_keyset_t_enc);
err_code = conn_ble_gap_sec_context_destroy(p_event->evt.gap_evt.conn_handle);
SER_ASSERT(err_code == NRF_SUCCESS, err_code);
}
else
{
err_code = NRF_SUCCESS;
}
SER_EVT_ENC_END;
}
uint32_t ble_gap_evt_conn_param_update_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_CONN_PARAM_UPDATE);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.conn_param_update, ble_gap_evt_conn_param_update_t_enc);
SER_EVT_ENC_END;
}
#ifndef S112
uint32_t ble_gap_evt_conn_param_update_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.conn_param_update_request,
ble_gap_evt_conn_param_update_request_t_enc);
SER_EVT_ENC_END;
}
#endif //!S112
uint32_t ble_gap_evt_conn_sec_update_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_CONN_SEC_UPDATE);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.conn_sec_update, ble_gap_evt_conn_sec_update_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gap_evt_connected_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_CONNECTED);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.connected, ble_gap_evt_connected_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gap_evt_disconnected_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_DISCONNECTED);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.disconnected, ble_gap_evt_disconnected_t_enc);
// If disconnected and context is not yet destroyed, destroy it now
uint32_t conn_index;
err_code = conn_ble_gap_sec_context_find(p_event->evt.gap_evt.conn_handle, &conn_index);
if (err_code == NRF_SUCCESS)
{
err_code = conn_ble_gap_sec_context_destroy(p_event->evt.gap_evt.conn_handle);
SER_ASSERT(err_code == NRF_SUCCESS, err_code);
}
err_code = NRF_SUCCESS;
SER_EVT_ENC_END;
}
uint32_t ble_gap_evt_key_pressed_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_KEY_PRESSED);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_uint8(&p_event->evt.gap_evt.params.key_pressed.kp_not);
SER_EVT_ENC_END;
}
uint32_t ble_gap_evt_lesc_dhkey_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_LESC_DHKEY_REQUEST);
uint8_t ser_data = p_event->evt.gap_evt.params.lesc_dhkey_request.oobd_req & 0x01;
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_COND(p_event->evt.gap_evt.params.lesc_dhkey_request.p_pk_peer, ble_gap_lesc_p256_pk_t_enc);
SER_PUSH_uint8(&ser_data);
SER_EVT_ENC_END;
}
#define PASSKEY_LEN sizeof (p_event->evt.gap_evt.params.passkey_display.passkey)
uint32_t ble_gap_evt_passkey_display_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_PASSKEY_DISPLAY);
uint8_t ser_data = p_event->evt.gap_evt.params.passkey_display.match_request & 0x01;
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_uint8array(p_event->evt.gap_evt.params.passkey_display.passkey, BLE_GAP_PASSKEY_LEN);
SER_PUSH_uint8(&ser_data);
SER_EVT_ENC_END;
}
uint32_t ble_gap_evt_rssi_changed_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_RSSI_CHANGED);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_int8(&p_event->evt.gap_evt.params.rssi_changed.rssi);
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5
SER_PUSH_uint8(&p_event->evt.gap_evt.params.rssi_changed.ch_index);
#endif
SER_EVT_ENC_END;
}
uint32_t ble_gap_evt_scan_req_report_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_SCAN_REQ_REPORT);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5
SER_PUSH_uint8(&p_event->evt.gap_evt.params.scan_req_report.adv_handle);
#endif
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.scan_req_report.peer_addr, ble_gap_addr_t_enc);
SER_PUSH_int8(&p_event->evt.gap_evt.params.scan_req_report.rssi);
SER_EVT_ENC_END;
}
uint32_t ble_gap_evt_sec_info_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_SEC_INFO_REQUEST);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.sec_info_request, ble_gap_evt_sec_info_request_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gap_evt_sec_params_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_SEC_PARAMS_REQUEST);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.sec_params_request, ble_gap_evt_sec_params_request_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gap_evt_sec_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_SEC_REQUEST);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.sec_request, ble_gap_evt_sec_request_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gap_evt_timeout_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_TIMEOUT);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_uint8(&p_event->evt.gap_evt.params.timeout.src);
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 && !defined(S112)
if (p_event->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_SCAN)
{
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.timeout.params.adv_report_buffer, ble_data_t_enc);
}
#endif
SER_EVT_ENC_END;
}
#if NRF_SD_BLE_API_VERSION >= 5
uint32_t ble_gap_evt_phy_update_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_PHY_UPDATE);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_uint8(&p_event->evt.gap_evt.params.phy_update.status);
SER_PUSH_uint8(&p_event->evt.gap_evt.params.phy_update.tx_phy);
SER_PUSH_uint8(&p_event->evt.gap_evt.params.phy_update.rx_phy);
SER_EVT_ENC_END;
}
uint32_t ble_gap_evt_phy_update_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_PHY_UPDATE_REQUEST);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.phy_update_request, ble_gap_phys_t_enc);
SER_EVT_ENC_END;
}
#endif
#if NRF_SD_BLE_API_VERSION >= 4 && !defined(S112)
uint32_t ble_gap_evt_data_length_update_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.data_length_update_request.peer_params, ble_gap_data_length_params_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gap_evt_data_length_update_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_DATA_LENGTH_UPDATE);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.data_length_update.effective_params, ble_gap_data_length_params_t_enc);
SER_EVT_ENC_END;
}
#endif // NRF_SD_BLE_API_VERSION >= 4 && !defined(S112)
#if NRF_SD_BLE_API_VERSION > 5
uint32_t ble_gap_evt_adv_set_terminated_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_ADV_SET_TERMINATED);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.adv_set_terminated, ble_gap_evt_adv_set_terminated_t_enc);
SER_EVT_ENC_END;
}
#ifndef S112
uint32_t ble_gap_evt_qos_channel_survey_report_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_QOS_CHANNEL_SURVEY_REPORT);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_uint8array((uint8_t *)p_event->evt.gap_evt.params.qos_channel_survey_report.channel_energy,
BLE_GAP_CHANNEL_COUNT);
SER_EVT_ENC_END;
}
#endif //!S112
#endif//NRF_SD_BLE_API_VERSION > 5

View File

@@ -0,0 +1,483 @@
/**
* Copyright (c) 2014 - 2020, 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.
*
*/
#ifndef BLE_GAP_EVT_CONN_H__
#define BLE_GAP_EVT_CONN_H__
/**@file
*
* @defgroup ble_gap_evt_conn GAP Connectivity event encoders
* @{
* @ingroup ser_conn_s130_codecs
*
* @brief GAP Connectivity event encoders.
*/
#include "ble.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Encodes ble_gap_evt_auth_key_request event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_auth_key_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_auth_status event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_auth_status_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_conn_param_update event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_conn_param_update_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_conn_sec_update event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_conn_sec_update_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_connected event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_connected_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_disconnected event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_disconnected_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_passkey_display event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_passkey_display_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_rssi_changed event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_rssi_changed_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_sec_info_request event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_sec_info_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_sec_params_request event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_sec_params_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_timeout event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_timeout_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_sec_request event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_sec_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_conn_param_update_request event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_conn_param_update_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_adv_report event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_adv_report_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_scan_req_report event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_scan_req_report_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_key_pressed event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_key_pressed_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_lesc_dhkey_request event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_lesc_dhkey_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#if NRF_SD_BLE_API_VERSION >= 5
/**
* @brief Encodes ble_gap_evt_phy_update event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_phy_update_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_phy_update_request event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_phy_update_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#endif
#if NRF_SD_BLE_API_VERSION >= 4
/**
* @brief Encodes ble_gap_evt_data_length_update_request event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_data_length_update_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_data_length_update event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_data_length_update_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#endif
#if NRF_SD_BLE_API_VERSION >= 6
/**
* @brief Encodes ble_gap_evt_adv_set_terminated event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_adv_set_terminated_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#ifndef S112
/**
* @brief Encodes ble_gap_evt_qos_channel_survey_report event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_qos_channel_survey_report_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#endif //!S112
#endif //NRF_SD_BLE_API_VERSION >= 6
/** @} */
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,299 @@
/**
* Copyright (c) 2014 - 2020, 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 "ble_gattc_conn.h"
#include "ble_serialization.h"
#include "ble_struct_serialization.h"
#include "ble_gattc_struct_serialization.h"
#include "cond_field_serialization.h"
#include "app_util.h"
#include <string.h>
uint32_t ble_gattc_attr_info_discover_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
ble_gattc_handle_range_t * * const pp_handle_range)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTC_ATTR_INFO_DISCOVER);
SER_ASSERT_NOT_NULL(p_conn_handle);
SER_ASSERT_NOT_NULL(pp_handle_range);
SER_ASSERT_NOT_NULL(*pp_handle_range);
SER_PULL_uint16(p_conn_handle);
SER_PULL_COND(pp_handle_range, ble_gattc_handle_range_t_dec);
SER_REQ_DEC_END;
}
uint32_t ble_gattc_attr_info_discover_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_ATTR_INFO_DISCOVER);
}
uint32_t ble_gattc_char_value_by_uuid_read_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
ble_uuid_t * * const pp_uuid,
ble_gattc_handle_range_t * * const
pp_handle_range)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ);
SER_ASSERT_NOT_NULL(p_conn_handle);
SER_ASSERT_NOT_NULL(pp_uuid);
SER_ASSERT_NOT_NULL(*pp_uuid);
SER_ASSERT_NOT_NULL(pp_handle_range);
SER_ASSERT_NOT_NULL(*pp_handle_range);
SER_PULL_uint16(p_conn_handle);
SER_PULL_COND(pp_uuid, ble_uuid_t_dec);
SER_PULL_COND(pp_handle_range, ble_gattc_handle_range_t_dec);
SER_REQ_DEC_END;
}
uint32_t ble_gattc_char_value_by_uuid_read_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ);
}
uint32_t ble_gattc_char_values_read_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
uint16_t * * const pp_handles,
uint16_t * const p_handle_count)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTC_CHAR_VALUES_READ);
SER_ASSERT_NOT_NULL(p_conn_handle);
SER_ASSERT_NOT_NULL(pp_handles);
SER_ASSERT_NOT_NULL(*pp_handles);
SER_ASSERT_NOT_NULL(p_handle_count);
SER_PULL_uint16(p_conn_handle);
SER_PULL_len16data16(pp_handles, p_handle_count);
SER_REQ_DEC_END;
}
uint32_t ble_gattc_char_values_read_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_CHAR_VALUES_READ);
}
uint32_t ble_gattc_characteristics_discover_req_dec(
uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
ble_gattc_handle_range_t * * const pp_handle_range)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTC_CHARACTERISTICS_DISCOVER);
SER_PULL_uint16(p_conn_handle);
SER_PULL_COND(pp_handle_range, ble_gattc_handle_range_t_dec);
SER_REQ_DEC_END;
}
uint32_t ble_gattc_characteristics_discover_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_CHARACTERISTICS_DISCOVER);
}
uint32_t ble_gattc_descriptors_discover_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
ble_gattc_handle_range_t * * const pp_handle_range)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTC_DESCRIPTORS_DISCOVER);
SER_PULL_uint16(p_conn_handle);
SER_PULL_COND(pp_handle_range, ble_gattc_handle_range_t_dec);
SER_REQ_DEC_END;
}
uint32_t ble_gattc_descriptors_discover_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_DESCRIPTORS_DISCOVER);
}
uint32_t ble_gattc_hv_confirm_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_conn_handle,
uint16_t * const p_handle)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTC_HV_CONFIRM);
SER_PULL_uint16(p_conn_handle);
SER_PULL_uint16(p_handle);
SER_REQ_DEC_END;
}
uint32_t ble_gattc_hv_confirm_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_HV_CONFIRM);
}
uint32_t ble_gattc_primary_services_discover_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
uint16_t * const p_start_handle,
ble_uuid_t * * const pp_srvc_uuid)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER);
SER_PULL_uint16(p_conn_handle);
SER_PULL_uint16(p_start_handle);
SER_PULL_COND(pp_srvc_uuid, ble_uuid_t_dec);
SER_REQ_DEC_END;
}
uint32_t ble_gattc_primary_services_discover_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER);
}
uint32_t ble_gattc_read_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
uint16_t * const p_handle,
uint16_t * const p_offset)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTC_READ);
SER_PULL_uint16(p_conn_handle);
SER_PULL_uint16(p_handle);
SER_PULL_uint16(p_offset);
SER_REQ_DEC_END;
}
uint32_t ble_gattc_read_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_READ);
}
uint32_t ble_gattc_relationships_discover_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
ble_gattc_handle_range_t * * const pp_handle_range)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTC_RELATIONSHIPS_DISCOVER);
SER_PULL_uint16(p_conn_handle);
SER_PULL_COND(pp_handle_range, ble_gattc_handle_range_t_dec);
SER_REQ_DEC_END;
}
uint32_t ble_gattc_relationships_discover_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_RELATIONSHIPS_DISCOVER);
}
uint32_t ble_gattc_write_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
ble_gattc_write_params_t * * const pp_write_params)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTC_WRITE);
SER_PULL_uint16(p_conn_handle);
SER_PULL_COND(pp_write_params, ble_gattc_write_params_t_dec);
SER_REQ_DEC_END;
}
uint32_t ble_gattc_write_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_WRITE);
}
uint32_t ble_gattc_exchange_mtu_request_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
uint16_t * const p_client_rx_mtu)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTC_EXCHANGE_MTU_REQUEST);
SER_PULL_uint16(p_conn_handle);
SER_PULL_uint16(p_client_rx_mtu);
SER_REQ_DEC_END;
}
uint32_t ble_gattc_exchange_mtu_request_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_EXCHANGE_MTU_REQUEST);
}

View File

@@ -0,0 +1,481 @@
/**
* Copyright (c) 2013 - 2020, 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.
*
*/
#ifndef BLE_GATTC_CONN_H__
#define BLE_GATTC_CONN_H__
/**@file
*
* @defgroup ble_gatc_conn GATTC connectivity command request decoders and command response encoders
* @{
* @ingroup ser_conn_s130_codecs
*
* @brief GATTC Connectivity command request decoders and command response encoders
*/
#include "ble_gattc.h"
#include "ble.h"
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Decodes @ref sd_ble_gattc_characteristics_discover command request.
*
* @sa @ref ble_gattc_characteristics_discover_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_conn_handle Pointer to connection handle.
* @param[out] pp_handle_range Pointer to pointer to handle range.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_DATA Decoding failure. Invalid value for handle range field present.
*/
uint32_t ble_gattc_characteristics_discover_req_dec
(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
ble_gattc_handle_range_t * * const pp_handle_range);
/**@brief Encodes @ref sd_ble_gattc_characteristics_discover command response.
*
* @sa @ref ble_gattc_characteristics_discover_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[in] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_characteristics_discover_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_gattc_descriptors_discover command request.
*
* @sa @ref ble_gattc_descriptors_discover_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_conn_handle Pointer to connection handle.
* @param[out] pp_handle_range Pointer to pointer to handle range.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_DATA Decoding failure. Invalid value for handle range field present.
*/
uint32_t ble_gattc_descriptors_discover_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
ble_gattc_handle_range_t * * const pp_handle_range);
/**@brief Encodes @ref sd_ble_gattc_descriptors_discover command response.
*
* @sa @ref ble_gattc_descriptors_discover_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[in] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_descriptors_discover_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_gattc_relationships_discover command request.
*
* @sa @ref ble_gattc_relationships_discover_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_conn_handle Pointer to connection handle.
* @param[out] pp_handle_range Pointer to pointer to handle range.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_DATA Decoding failure. Invalid value for handle range field present.
*/
uint32_t ble_gattc_relationships_discover_req_dec
(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
ble_gattc_handle_range_t * * const pp_handle_range);
/**@brief Encodes @ref sd_ble_gattc_relationships_discover command response.
*
* @sa @ref ble_gattc_relationships_discover_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[in] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_relationships_discover_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_gattc_primary_services_discover command request.
*
* @sa @ref ble_gattc_primary_services_discover_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_conn_handle Pointer to connection handle.
* @param[out] p_start_handle Pointer to start handle.
* @param[out] pp_srvc_uuid Pointer to pointer to service uuid.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_DATA Decoding failure. Invalid value for uuid field present.
*/
uint32_t ble_gattc_primary_services_discover_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
uint16_t * const p_start_handle,
ble_uuid_t * * const pp_srvc_uuid);
/**@brief Encodes @ref sd_ble_gattc_primary_services_discover command response.
*
* @sa @ref ble_gattc_primary_services_discover_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[in] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_primary_services_discover_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_gattc_read command request.
*
* @sa @ref ble_gattc_read_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_conn_handle Pointer to connection handle.
* @param[out] p_handle Pointer to handle.
* @param[out] p_offset Pointer to offset.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_read_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
uint16_t * const p_handle,
uint16_t * const p_offset);
/**@brief Encodes @ref sd_ble_gattc_read command response.
*
* @sa @ref ble_gattc_read_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[in] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_read_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_gattc_char_values_read command request.
*
* @sa @ref ble_gattc_char_values_read_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_conn_handle Pointer to connection handle.
* @param[out] pp_handles Pointer to pointer to handle table.
* @param[out] p_handle_count Pointer to handle handle table count.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_char_values_read_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
uint16_t * * const pp_handles,
uint16_t * const p_handle_count);
/**@brief Encodes @ref sd_ble_gattc_char_values_read command response.
*
* @sa @ref ble_gattc_char_values_read_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[in] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_char_values_read_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_gattc_write command request.
*
* @sa @ref ble_gattc_write_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_conn_handle Pointer to connection handle.
* @param[out] pp_write_params Pointer to pointer to write parameters.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_write_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
ble_gattc_write_params_t * * const pp_write_params);
/**@brief Encodes @ref sd_ble_gattc_write command response.
*
* @sa @ref ble_gattc_write_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[in] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_write_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_gattc_hv_confirm command request.
*
* @sa @ref ble_gattc_hv_confirm_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_conn_handle Pointer to connection handle.
* @param[out] p_handle Pointer to handle of the attribute in the indication.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_hv_confirm_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_conn_handle,
uint16_t * const p_handle);
/**@brief Encodes @ref sd_ble_gattc_hv_confirm command response.
*
* @sa @ref ble_gattc_hv_confirm_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[in] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_hv_confirm_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_gattc_char_value_by_uuid_read command request.
*
* @sa @ref ble_gattc_char_value_by_uuid_read_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of request packet.
* @param[out] p_conn_handle Pointer to connection handle of the connection.
* @param[out] pp_uuid Pointer to pointer to a characteristic value UUID to read.
* @param[out] pp_handle_range Pointer to pointer to the range of handles to perform this
* procedure on.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_DATA Decoding failure. Invalid operation type.
*/
uint32_t ble_gattc_char_value_by_uuid_read_req_dec
(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
ble_uuid_t * * const pp_uuid,
ble_gattc_handle_range_t * * const pp_handle_range);
/**@brief Encodes @ref sd_ble_gattc_char_value_by_uuid_read command response.
*
* @sa @ref ble_gattc_char_value_by_uuid_read_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[in] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_char_value_by_uuid_read_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_gattc_attr_info_discover command request.
*
* @sa @ref ble_gattc_attr_info_discover_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] buf_len Length (in bytes) of request packet.
* @param[out] p_conn_handle Pointer to connection handle of the connection.
* @param[out] pp_handle_range Pointer to pointer to the range of handles.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_DATA Decoding failure. Invalid operation type.
*/
uint32_t ble_gattc_attr_info_discover_req_dec(uint8_t const * const p_buf,
uint16_t buf_len,
uint16_t * const p_conn_handle,
ble_gattc_handle_range_t * * const pp_handle_range);
/**@brief Encodes @ref sd_ble_gattc_attr_info_discover command response.
*
* @sa @ref ble_gattc_attr_info_discover_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[in] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_attr_info_discover_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_gattc_exchange_mtu_request command request.
*
* @sa @ref ble_gattc_exchange_mtu_request_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of request packet.
* @param[out] p_conn_handle Pointer to connection handle of the connection.
* @param[out] p_client_rx_mtu Pointer to Client RX MTU size.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_DATA Decoding failure. Invalid operation type.
*/
uint32_t ble_gattc_exchange_mtu_request_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
uint16_t * const p_client_rx_mtu);
/**@brief Encodes @ref sd_ble_gattc_exchange_mtu_request command response.
*
* @sa @ref ble_gattc_exchange_mtu_request_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[in] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_exchange_mtu_request_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/** @} */
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,253 @@
/**
* Copyright (c) 2016 - 2020, 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 "ble_gattc_evt_conn.h"
#include "ble_serialization.h"
#include "ble_gattc_struct_serialization.h"
#include "app_util.h"
#include <string.h>
uint32_t ble_gattc_evt_attr_info_disc_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_ATTR_INFO_DISC_RSP);
SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.attr_info_disc_rsp,
ble_gattc_evt_attr_info_disc_rsp_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gattc_evt_char_disc_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_CHAR_DISC_RSP);
SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.char_disc_rsp,
ble_gattc_evt_char_disc_rsp_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gattc_evt_char_val_by_uuid_read_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP);
SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.char_val_by_uuid_read_rsp,
ble_gattc_evt_char_val_by_uuid_read_rsp_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gattc_evt_char_vals_read_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_CHAR_VALS_READ_RSP);
SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.char_vals_read_rsp,
ble_gattc_evt_char_vals_read_rsp_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gattc_evt_desc_disc_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_DESC_DISC_RSP);
SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.desc_disc_rsp,
ble_gattc_evt_desc_disc_rsp_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gattc_evt_hvx_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_HVX);
SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.hvx, ble_gattc_evt_hvx_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gattc_evt_prim_srvc_disc_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP);
SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.prim_srvc_disc_rsp,
ble_gattc_evt_prim_srvc_disc_rsp_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gattc_evt_read_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_READ_RSP);
SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.read_rsp,
ble_gattc_evt_read_rsp_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gattc_evt_rel_disc_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_REL_DISC_RSP);
SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.rel_disc_rsp,
ble_gattc_evt_rel_disc_rsp_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gattc_evt_timeout_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_TIMEOUT);
SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.timeout,
ble_gattc_evt_timeout_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gattc_evt_write_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_WRITE_RSP);
SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.write_rsp,
ble_gattc_evt_write_rsp_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gattc_evt_exchange_mtu_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_EXCHANGE_MTU_RSP);
SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.exchange_mtu_rsp,
ble_gattc_evt_exchange_mtu_rsp_t_enc);
SER_EVT_ENC_END;
}
#if NRF_SD_BLE_API_VERSION >= 4
uint32_t ble_gattc_evt_write_cmd_tx_complete_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE);
SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PUSH_uint8(&p_event->evt.gattc_evt.params.write_cmd_tx_complete.count);
SER_EVT_ENC_END;
}
#endif

View File

@@ -0,0 +1,300 @@
/**
* Copyright (c) 2014 - 2020, 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.
*
*/
#ifndef BLE_GATTC_EVT_CONN_H__
#define BLE_GATTC_EVT_CONN_H__
/**@file
*
* @defgroup ble_gattc_evt_conn GATTC Connectivity event encoders
* @{
* @ingroup ser_conn_s130_codecs
*
* @brief GATTC Connectivity event encoders.
*/
#include "ble.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Encodes ble_gattc_evt_char_disc_rsp event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_evt_char_disc_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gattc_evt_char_val_by_uuid_read_rsp event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_evt_char_val_by_uuid_read_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gattc_evt_char_vals_read_rsp event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_evt_char_vals_read_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gattc_evt_desc_disc_rsp event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_evt_desc_disc_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gattc_evt_hvx event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_evt_hvx_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gattc_evt_prim_srvc_disc_rsp event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_evt_prim_srvc_disc_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gattc_evt_read_rsp event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_evt_read_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gattc_evt_rel_disc_rsp event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_evt_rel_disc_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gattc_evt_timeout event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_evt_timeout_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gattc_evt_write_rsp event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_evt_write_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gattc_evt_attr_info_disc_rsp event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_evt_attr_info_disc_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gattc_evt_exchange_mtu_rsp event.
*
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_evt_exchange_mtu_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#if NRF_SD_BLE_API_VERSION >= 4
/**
* @brief Encodes @ref BLE_gattc_EVT_WRITE_CMD_TX_COMPLETE event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_evt_write_cmd_tx_complete_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#endif
/** @} */
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,421 @@
/**
* Copyright (c) 2014 - 2020, 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 "ble_gatts_conn.h"
#include <string.h>
#include "ble_serialization.h"
#include "ble_struct_serialization.h"
#include "ble_gatts_struct_serialization.h"
#include "app_util.h"
#include "cond_field_serialization.h"
uint32_t ble_gatts_attr_get_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * p_handle,
ble_uuid_t * * pp_uuid,
ble_gatts_attr_md_t * * pp_md)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTS_ATTR_GET);
SER_PULL_uint16(p_handle);
SER_PULL_COND(pp_uuid, NULL);
SER_PULL_COND(pp_md, NULL);
SER_REQ_DEC_END;
}
uint32_t ble_gatts_attr_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
ble_uuid_t * p_uuid,
ble_gatts_attr_md_t * p_md)
{
SER_RSP_ENC_BEGIN(SD_BLE_GATTS_ATTR_GET);
SER_PUSH_COND(p_uuid, ble_uuid_t_enc);
SER_PUSH_COND(p_md, ble_gatts_attr_md_t_enc);
SER_RSP_ENC_END;
}
uint32_t ble_gatts_characteristic_add_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * p_service_handle,
ble_gatts_char_md_t * * const pp_char_md,
ble_gatts_attr_t * * const pp_attr_char_value,
ble_gatts_char_handles_t * * const pp_handles)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTS_CHARACTERISTIC_ADD);
SER_PULL_uint16(p_service_handle);
SER_PULL_COND(pp_char_md, ble_gatts_char_md_t_dec);
SER_PULL_COND(pp_attr_char_value, ble_gatts_attr_t_dec);
SER_PULL_COND(pp_handles, NULL);
SER_REQ_DEC_END;
}
uint32_t ble_gatts_characteristic_add_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
ble_gatts_char_handles_t const * const p_handles)
{
SER_RSP_ENC_BEGIN(SD_BLE_GATTS_CHARACTERISTIC_ADD);
SER_PUSH_COND(p_handles, ble_gatts_char_handles_t_enc);
SER_RSP_ENC_END;
}
uint32_t ble_gatts_descriptor_add_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_char_handle,
ble_gatts_attr_t * * const pp_attr,
uint16_t * * const pp_handle)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTS_DESCRIPTOR_ADD);
SER_PULL_uint16(p_char_handle);
SER_PULL_COND(pp_attr, ble_gatts_attr_t_dec);
SER_PULL_COND(pp_handle, NULL);
SER_REQ_DEC_END;
}
uint32_t ble_gatts_descriptor_add_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint16_t * p_handle)
{
SER_RSP_ENC_BEGIN(SD_BLE_GATTS_DESCRIPTOR_ADD);
SER_PUSH_COND(p_handle,uint16_t_enc);
SER_RSP_ENC_END;
}
uint32_t ble_gatts_hvx_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_conn_handle,
ble_gatts_hvx_params_t * * const pp_hvx_params)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTS_HVX);
SER_PULL_uint16(p_conn_handle);
SER_PULL_COND(pp_hvx_params, ble_gatts_hvx_params_t_dec);
SER_REQ_DEC_END;
}
uint32_t ble_gatts_hvx_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint16_t const * const p_bytes_written)
{
SER_RSP_ENC_BEGIN(SD_BLE_GATTS_HVX);
SER_PUSH_COND(p_bytes_written, uint16_t_enc);
SER_RSP_ENC_END;
}
uint32_t ble_gatts_include_add_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_service_handle,
uint16_t * const p_inc_srvc_handle,
uint16_t * * const pp_include_handle)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTS_INCLUDE_ADD);
SER_PULL_uint16(p_service_handle);
SER_PULL_uint16(p_inc_srvc_handle);
SER_PULL_COND(pp_include_handle, NULL);
SER_REQ_DEC_END;
}
uint32_t ble_gatts_include_add_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint16_t const * const p_include_handle)
{
SER_RSP_ENC_BEGIN(SD_BLE_GATTS_INCLUDE_ADD);
SER_PUSH_COND(p_include_handle, uint16_t_enc);
SER_RSP_ENC_END;
}
uint32_t ble_gatts_initial_user_handle_get_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * * pp_handle)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTS_INITIAL_USER_HANDLE_GET);
SER_PULL_COND(pp_handle, NULL);
SER_REQ_DEC_END;
}
uint32_t ble_gatts_initial_user_handle_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint16_t * p_handle)
{
SER_RSP_ENC_BEGIN(SD_BLE_GATTS_INITIAL_USER_HANDLE_GET);
SER_PUSH_COND(p_handle, uint16_t_enc);
SER_RSP_ENC_END;
}
uint32_t ble_gatts_rw_authorize_reply_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * p_conn_handle,
ble_gatts_rw_authorize_reply_params_t * * const pp_reply_params)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTS_RW_AUTHORIZE_REPLY);
SER_PULL_uint16(p_conn_handle);
SER_PULL_COND(pp_reply_params, ble_gatts_rw_authorize_reply_params_t_dec);
SER_REQ_DEC_END;
}
uint32_t ble_gatts_rw_authorize_reply_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTS_RW_AUTHORIZE_REPLY);
}
uint32_t ble_gatts_service_add_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint8_t * const p_type,
ble_uuid_t * * const pp_uuid,
uint16_t * * const pp_handle)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTS_SERVICE_ADD);
SER_PULL_uint8(p_type);
SER_PULL_COND(pp_uuid, ble_uuid_t_dec);
SER_PULL_COND(pp_handle, NULL);
SER_REQ_DEC_END;
}
uint32_t ble_gatts_service_add_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint16_t const * const p_handle)
{
SER_RSP_ENC_BEGIN(SD_BLE_GATTS_SERVICE_ADD);
SER_PUSH_COND(p_handle, uint16_t_enc);
//SER_PUSH_uint16(p_handle);
SER_RSP_ENC_END;
}
uint32_t ble_gatts_service_changed_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * p_conn_handle,
uint16_t * p_start_handle,
uint16_t * p_end_handle)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTS_SERVICE_CHANGED);
SER_PULL_uint16(p_conn_handle);
SER_PULL_uint16(p_start_handle);
SER_PULL_uint16(p_end_handle);
SER_REQ_DEC_END;
}
uint32_t ble_gatts_service_changed_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTS_SERVICE_CHANGED);
}
uint32_t ble_gatts_sys_attr_get_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_conn_handle,
uint8_t * * const pp_sys_attr_data,
uint16_t * * const pp_sys_attr_data_len,
uint32_t * const p_flags)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTS_SYS_ATTR_GET);
SER_PULL_uint16(p_conn_handle);
SER_PULL_COND(pp_sys_attr_data_len, uint16_t_dec);
SER_PULL_COND(pp_sys_attr_data, NULL);
SER_PULL_uint32(p_flags);
SER_REQ_DEC_END;
}
uint32_t ble_gatts_sys_attr_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint8_t const * const p_sys_attr_data,
uint16_t const * const p_sys_attr_data_len)
{
SER_RSP_ENC_BEGIN(SD_BLE_GATTS_SYS_ATTR_GET);
SER_PUSH_COND(p_sys_attr_data_len, uint16_t_enc);
if (p_sys_attr_data_len)
{
SER_PUSH_buf(p_sys_attr_data, *p_sys_attr_data_len);
}
SER_RSP_ENC_END;
}
uint32_t ble_gatts_sys_attr_set_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_conn_handle,
uint8_t * * const pp_sys_attr_data,
uint16_t * const p_sys_attr_data_len,
uint32_t * const p_flags)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTS_SYS_ATTR_SET);
SER_PULL_uint16(p_conn_handle);
SER_PULL_len16data(pp_sys_attr_data, p_sys_attr_data_len);
SER_PULL_uint32(p_flags);
SER_REQ_DEC_END;
}
uint32_t ble_gatts_sys_attr_set_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTS_SYS_ATTR_SET);
}
uint32_t ble_gatts_value_get_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
uint16_t * const p_handle,
ble_gatts_value_t * * const pp_value)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTS_VALUE_GET);
SER_PULL_uint16(p_conn_handle);
SER_PULL_uint16(p_handle);
//Special case: skip the data.
SER_PULL_COND(pp_value, NULL);
if (*pp_value)
{
SER_PULL_uint16(&(*pp_value)->offset);
SER_PULL_uint16(&(*pp_value)->len);
SER_PULL_COND(&(*pp_value)->p_value, NULL);
}
SER_REQ_DEC_END;
}
uint32_t ble_gatts_value_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
ble_gatts_value_t * const p_value)
{
SER_RSP_ENC_BEGIN(SD_BLE_GATTS_VALUE_GET);
SER_PUSH_COND(p_value, ble_gatts_value_t_enc);
SER_RSP_ENC_END;
}
uint32_t ble_gatts_value_set_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * p_conn_handle,
uint16_t * p_handle,
ble_gatts_value_t * * const pp_value)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTS_VALUE_SET);
SER_PULL_uint16(p_conn_handle);
SER_PULL_uint16(p_handle);
SER_PULL_COND(pp_value, ble_gatts_value_t_dec);
SER_REQ_DEC_END;
}
uint32_t ble_gatts_value_set_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
ble_gatts_value_t * p_value)
{
SER_RSP_ENC_BEGIN(SD_BLE_GATTS_VALUE_SET);
SER_PUSH_COND(p_value, ble_gatts_value_t_enc);
SER_RSP_ENC_END;
}
uint32_t ble_gatts_exchange_mtu_reply_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
uint16_t * const p_server_rx_mtu)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTS_EXCHANGE_MTU_REPLY);
SER_PULL_uint16(p_conn_handle);
SER_PULL_uint16(p_server_rx_mtu);
SER_REQ_DEC_END;
}
uint32_t ble_gatts_exchange_mtu_reply_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTS_EXCHANGE_MTU_REPLY);
}

View File

@@ -0,0 +1,634 @@
/**
* Copyright (c) 2013 - 2020, 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.
*
*/
#ifndef BLE_GATTS_CONN_H__
#define BLE_GATTS_CONN_H__
/**@file
*
* @defgroup ble_gatts_conn GATTS Connectivity command request decoders and command response encoders
* @{
* @ingroup ser_conn_s130_codecs
*
* @brief GATTS Connectivity command request decoders and command response encoders.
*/
#include "ble_gatts.h"
#include "ble.h"
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Decodes @ref sd_ble_gatts_value_get command request.
*
* @sa @ref ble_gatts_value_get_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of request packet.
* @param[out] p_conn_handle Pointer to the connection_handle.
* @param[out] p_handle Pointer to the attribute_handle.
* @param[out] pp_value Pointer to pointer to the Attribute Value structure.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_value_get_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
uint16_t * const p_handle,
ble_gatts_value_t * * const pp_value);
/**@brief Encodes @ref sd_ble_gatts_value_get command response.
*
* @sa @ref ble_gatts_value_get_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_value Pointer to Attribute Value structure.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_value_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
ble_gatts_value_t * const p_value);
/**@brief Decodes @ref sd_ble_gatts_characteristic_add command request.
*
* @sa @ref ble_gatts_characteristic_add_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of request packet.
* @param[out] p_service_handle Pointer to the service_handle.
* @param[out] constpp_char_md Pointer to pointer to the location where Characteristic metadata
* will be decoded.
* @param[out] pp_attr_char_value Pointer to pointer to the location where GATT Attribute will be
* decoded.
* @param[out] pp_handles Pointer to pointer to the location where Characteristic definition
* handles will be decoded.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_characteristic_add_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * p_service_handle,
ble_gatts_char_md_t * * constpp_char_md,
ble_gatts_attr_t * * const pp_attr_char_value,
ble_gatts_char_handles_t * * const pp_handles);
/**@brief Encodes @ref ble_gatts_sys_attr_get_rsp_enc command response.
*
* @sa @ref ble_gatts_sys_attr_get_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_handles Pointer to handle struct to be encoded.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_characteristic_add_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
ble_gatts_char_handles_t const * const p_handles);
/**@brief Decodes @ref sd_ble_gatts_include_add command request.
*
* @sa @ref ble_gatts_include_add_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of request packet.
* @param[out] p_service_handle Pointer to the service_handle.
* @param[out] p_inc_srvc_handle Pointer to the handle of the included service.
* @param[out] pp_include_handle Pointer to Pointer to 16-bit word where the assigned handle will be stored.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_include_add_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_service_handle,
uint16_t * const p_inc_srvc_handle,
uint16_t * * const pp_include_handle);
/**@brief Encodes @ref ble_gatts_include_add_rsp_enc command response.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_include_handle Pointer to a 16-bit word where the assigned handle was stored.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_include_add_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint16_t const * const p_include_handle);
/**@brief Decodes @ref sd_ble_gatts_service_add command request.
*
* @sa @ref ble_gatts_service_add_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of request packet.
* @param[out] p_type Pointer to the service type.
* @param[out] pp_uuid Pointer to pointer to service UUID.
* @param[out] pp_handle Pointer to pointer to a 16-bit word where the assigned handle will be stored.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_service_add_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint8_t * const p_type,
ble_uuid_t * * const pp_uuid,
uint16_t * * const pp_handle);
/**@brief Encodes @ref ble_gatts_service_add_rsp_enc command response.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_handle Pointer to a 16-bit word where the assigned handle was stored.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_service_add_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint16_t const * const p_handle);
/**@brief Decodes @ref ble_gatts_sys_attr_get_req_dec command request.
*
* @sa @ref ble_gatts_sys_attr_get_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_conn_handle Pointer to connectiton handle.
* @param[out] pp_sys_attr_data Pointer to pointer to buffer where system attributes data will be filled in.
* @param[out] pp_sys_attr_data_len Pointer to pointer to variable which contains size of buffer for system attributes.
* @param[out] p_flags Pointer to additional optional flags.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_gatts_sys_attr_get_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_conn_handle,
uint8_t * * const pp_sys_attr_data,
uint16_t * * const pp_sys_attr_data_len,
uint32_t * const p_flags);
/**@brief Encodes @ref ble_gatts_sys_attr_get_rsp_enc command response.
*
* @sa @ref ble_gatts_sys_attr_get_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_sys_attr_data Pointer to buffer where system attributes data are stored.
* @param[in] p_sys_attr_data_len Pointer to variable which contains size of buffer for system attributes.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_sys_attr_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint8_t const * const p_sys_attr_data,
uint16_t const * const p_sys_attr_data_len);
/**@brief Decodes @ref sd_ble_gatts_value_set command request.
*
* @sa @ref ble_gatts_value_set_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_conn_handle Pointer to connection handle.
* @param[out] p_handle Pointer to attribute handle.
* @param[out] pp_value Pointer to pointer to attribute value structure.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_gatts_value_set_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * p_conn_handle,
uint16_t * p_handle,
ble_gatts_value_t * * const pp_value);
/**@brief Encodes @ref sd_ble_gatts_value_set command response.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[in] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_value \c in: size of value returned when value was written with success
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_value_set_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
ble_gatts_value_t * p_value);
/**@brief Decodes @ref sd_ble_gatts_sys_attr_set command request.
*
* @sa @ref ble_gatts_sys_attr_set_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of request packet.
* @param[out] p_conn_handle Pointer to the buffer raw data to be placed in advertisement packet.
* @param[out] pp_sys_attr_data Pointer to pointer to system attribute data.
* @param[out] p_sys_attr_data_len Pointer to data length for system attribute data.
* @param[out] p_flags Pointer to additional optional flags.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_sys_attr_set_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_conn_handle,
uint8_t * * const pp_sys_attr_data,
uint16_t * const p_sys_attr_data_len,
uint32_t * const p_flags);
/**@brief Encodes @ref sd_ble_gatts_sys_attr_set command response.
*
* @sa @ref ble_gatts_sys_attr_set_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_sys_attr_set_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref ble_gatts_hvx_req_dec command request.
*
* @sa @ref ble_gatts_hvx_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of request packet.
* @param[out] p_conn_handle Pointer to the buffer raw data to be placed in advertisement packet.
* @param[out] pp_hvx_params Pointer to an HVx parameters structure.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_hvx_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_conn_handle,
ble_gatts_hvx_params_t * * const pp_hvx_params);
/**@brief Encodes @ref ble_gatts_hvx_rsp_enc command response.
*
* @sa @ref ble_gatts_hvx_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_bytes_written Pointer to number of bytes written.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_hvx_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint16_t const * const p_bytes_written);
/**@brief Decodes @ref sd_ble_gatts_descriptor_add command request.
*
* @sa @ref ble_gatts_descriptor_add_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of request packet.
* @param[out] p_char_handle Pointer to buffer where characteristic handle will be.
returned.
* @param[out] pp_attr Pointer to pointer to an attribute structure.
* @param[out] pp_handle Pointer to pointer to descriptor handle.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_descriptor_add_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_char_handle,
ble_gatts_attr_t * * const pp_attr,
uint16_t * * const pp_handle);
/**@brief Encodes @ref sd_ble_gatts_descriptor_add command response.
*
* @sa @ref ble_gatts_descriptor_add_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_handle Pointer to descriptor handle value.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_descriptor_add_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint16_t * p_handle);
/**@brief Decodes @ref sd_ble_gatts_rw_authorize_reply command request.
*
* @sa @ref ble_gatts_rw_authorize_reply_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_conn_handle Pointer to connection handle.
* @param[out] pp_reply_params Pointer to pointer to \ref ble_gatts_rw_authorize_reply_params_t .
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_gatts_rw_authorize_reply_req_dec(
uint8_t const * const p_buf,
uint32_t
packet_len,
uint16_t *
p_conn_handle,
ble_gatts_rw_authorize_reply_params_t * * const
pp_reply_params);
/**@brief Encodes @ref sd_ble_gatts_rw_authorize_reply command response.
*
* @sa @ref ble_gatts_rw_authorize_reply_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_rw_authorize_reply_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_gatts_service_changed command request.
*
* @sa @ref ble_gatts_service_changed_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_conn_handle Pointer to connection handle.
* @param[out] p_start_handle Pointer to start handle.
* @param[out] p_end_handle Pointer to end handle.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_gatts_service_changed_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * p_conn_handle,
uint16_t * p_start_handle,
uint16_t * p_end_handle);
/**@brief Encodes @ref sd_ble_gatts_service_changed command response.
*
* @sa @ref ble_gatts_service_changed_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_service_changed_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref ble_gatts_attr_get_req_dec command request.
*
* @sa @ref ble_gatts_attr_get_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_handle Pointer to handle.
* @param[out] pp_uuid Pointer to pointer to location for decoded uuid structure.
* @param[out] pp_md Pointer to pointer to location for md structure.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_gatts_attr_get_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * p_handle,
ble_uuid_t * * pp_uuid,
ble_gatts_attr_md_t * * pp_md);
/**@brief Encodes @ref ble_gatts_attr_get_rsp_enc command response.
*
* @sa @ref ble_gatts_attr_get_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_uuid Pointer to structure to be encoded.
* @param[in] p_md Pointer to structure to be encoded.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_attr_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
ble_uuid_t * p_uuid,
ble_gatts_attr_md_t * p_md);
/**@brief Decodes @ref ble_gatts_initial_user_handle_get_req_dec command request.
*
* @sa @ref ble_gatts_initial_user_handle_get_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] pp_handle Pointer to pointer to handle.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_gatts_initial_user_handle_get_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * * pp_handle);
/**@brief Encodes @ref ble_gatts_initial_user_handle_get_rsp_enc command response.
*
* @sa @ref ble_gatts_initial_user_handle_get_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_handle Pointer to handle to be encoded.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_initial_user_handle_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint16_t * p_handle);
/**@brief Decodes @ref sd_ble_gatts_rw_authorize_reply command request.
*
* @ref ble_gatts_exchange_mtu_reply_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_conn_handle Pointer to connection handle.
* @param[out] p_server_rx_mtu Pointer to Server RX MTU size.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_gatts_exchange_mtu_reply_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
uint16_t * const p_server_rx_mtu);
/**@brief Encodes @ref sd_ble_gatts_rw_authorize_reply command response.
*
* @ref ble_gatts_exchange_mtu_reply_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_exchange_mtu_reply_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/** @} */
#ifdef __cplusplus
}
#endif
#endif //BLE_GATTS_CONN_H__

View File

@@ -0,0 +1,178 @@
/**
* Copyright (c) 2014 - 2020, 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 "ble_gatts_evt_conn.h"
#include "ble_serialization.h"
#include "ble_gatts_struct_serialization.h"
#include "conn_ble_user_mem.h"
#include "app_util.h"
extern sercon_ble_user_mem_t m_conn_user_mem_table[];
uint32_t ble_gatts_evt_rw_authorize_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST);
SER_PUSH_uint16(&p_event->evt.gatts_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gatts_evt.params.authorize_request, ble_gatts_evt_rw_authorize_request_t_enc);
if ((p_event->evt.gatts_evt.params.authorize_request.type == BLE_GATTS_AUTHORIZE_TYPE_WRITE) &&
((p_event->evt.gatts_evt.params.authorize_request.request.write.op == BLE_GATTS_OP_EXEC_WRITE_REQ_NOW) ||
(p_event->evt.gatts_evt.params.authorize_request.request.write.op == BLE_GATTS_OP_PREP_WRITE_REQ)))
{
uint32_t conn_index;
if (conn_ble_user_mem_context_find(p_event->evt.gatts_evt.conn_handle, &conn_index) != NRF_ERROR_NOT_FOUND)
{
err_code = len16data_enc(m_conn_user_mem_table[conn_index].mem_block.p_mem, m_conn_user_mem_table[conn_index].mem_block.len, p_buf, *p_buf_len, &index);
SER_ASSERT(err_code == NRF_SUCCESS, err_code);
}
}
SER_EVT_ENC_END;
}
uint32_t ble_gatts_evt_hvc_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTS_EVT_HVC);
SER_PUSH_uint16(&p_event->evt.gatts_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gatts_evt.params.hvc, ble_gatts_evt_hvc_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gatts_evt_sc_confirm_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTS_EVT_SC_CONFIRM);
SER_PUSH_uint16(&p_event->evt.gatts_evt.conn_handle);
SER_EVT_ENC_END;
}
uint32_t ble_gatts_evt_sys_attr_missing_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTS_EVT_SYS_ATTR_MISSING);
SER_PUSH_uint16(&p_event->evt.gatts_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gatts_evt.params.sys_attr_missing, ble_gatts_evt_sys_attr_missing_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gatts_evt_timeout_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTS_EVT_TIMEOUT);
SER_PUSH_uint16(&p_event->evt.gatts_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gatts_evt.params.timeout, ble_gatts_evt_timeout_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gatts_evt_write_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTS_EVT_WRITE);
SER_PUSH_uint16(&p_event->evt.gatts_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gatts_evt.params.write, ble_gatts_evt_write_t_enc);
if ((p_event->evt.gatts_evt.params.write.op == BLE_GATTS_OP_WRITE_REQ) || (p_event->evt.gatts_evt.params.write.op == BLE_GATTS_OP_EXEC_WRITE_REQ_NOW))
{
uint32_t conn_index;
if (conn_ble_user_mem_context_find(p_event->evt.gatts_evt.conn_handle, &conn_index) != NRF_ERROR_NOT_FOUND)
{
SER_PUSH_len16data(m_conn_user_mem_table[conn_index].mem_block.p_mem, m_conn_user_mem_table[conn_index].mem_block.len);
}
}
SER_EVT_ENC_END;
}
uint32_t ble_gatts_evt_exchange_mtu_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST);
SER_PUSH_uint16(&p_event->evt.gatts_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gatts_evt.params.exchange_mtu_request, ble_gatts_evt_exchange_mtu_request_t_enc);
SER_EVT_ENC_END;
}
#if NRF_SD_BLE_API_VERSION >= 4
uint32_t ble_gatts_evt_hvn_tx_complete_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTS_EVT_HVN_TX_COMPLETE);
SER_PUSH_uint16(&p_event->evt.gatts_evt.conn_handle);
SER_PUSH_uint8(&p_event->evt.gatts_evt.params.hvn_tx_complete.count);
SER_EVT_ENC_END;
}
#endif

View File

@@ -0,0 +1,208 @@
/**
* Copyright (c) 2014 - 2020, 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.
*
*/
#ifndef BLE_GATTS_EVT_CONN_H__
#define BLE_GATTS_EVT_CONN_H__
/**@file
*
* @defgroup ble_gatts_evt_conn GATTS Connectivity event encoders
* @{
* @ingroup ser_conn_s130_codecs
*
* @brief GATTS Connectivity event encoders.
*/
#include "ble.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Encodes @ref BLE_GATTS_EVT_HVC event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_evt_hvc_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes @ref BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_evt_rw_authorize_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes @ref BLE_GATTS_EVT_SC_CONFIRM event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_evt_sc_confirm_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes @ref BLE_GATTS_EVT_SYS_ATTR_MISSING event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_evt_sys_attr_missing_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes @ref BLE_GATTS_EVT_TIMEOUT event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_evt_timeout_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes @ref BLE_GATTS_EVT_WRITE event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_evt_write_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes @ref BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_evt_exchange_mtu_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#if NRF_SD_BLE_API_VERSION >= 4
/**
* @brief Encodes @ref BLE_GATTS_EVT_HVN_TX_COMPLETE event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_evt_hvn_tx_complete_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#endif
/** @} */
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,323 @@
/**
* Copyright (c) 2014 - 2020, 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 <stdlib.h>
#include <string.h>
#include "ble_l2cap_conn.h"
#include "ble_serialization.h"
#include "ble_struct_serialization.h"
#include "ble_l2cap_struct_serialization.h"
#include "cond_field_serialization.h"
#include "conn_ble_l2cap_sdu_pool.h"
#include "app_util.h"
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
uint32_t ble_l2cap_cid_register_req_dec(uint8_t const * const p_buf,
uint32_t buf_len,
uint16_t * p_cid)
{
uint32_t index = 0;
uint32_t err_code = NRF_SUCCESS;
SER_ASSERT_NOT_NULL(p_cid);
SER_ASSERT_NOT_NULL(p_buf);
SER_ASSERT_LENGTH_EQ(3, buf_len);
SER_ASSERT(p_buf[index] == SD_BLE_L2CAP_CID_REGISTER, NRF_ERROR_INVALID_PARAM);
index++;
err_code = uint16_t_dec(p_buf, buf_len, &index, p_cid);
SER_ASSERT(err_code == NRF_SUCCESS, err_code);
SER_ASSERT_LENGTH_EQ(index, buf_len);
return err_code;
}
uint32_t ble_l2cap_cid_register_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
return ser_ble_cmd_rsp_status_code_enc(SD_BLE_L2CAP_CID_REGISTER, return_code,
p_buf, p_buf_len);
}
uint32_t ble_l2cap_cid_unregister_req_dec(uint8_t const * const p_buf,
uint32_t buf_len,
uint16_t * p_cid)
{
uint32_t index = 0;
uint32_t err_code = NRF_SUCCESS;
SER_ASSERT_NOT_NULL(p_cid);
SER_ASSERT_NOT_NULL(p_buf);
SER_ASSERT_LENGTH_EQ(3, buf_len);
SER_ASSERT(p_buf[index] == SD_BLE_L2CAP_CID_UNREGISTER, NRF_ERROR_INVALID_PARAM);
index++;
err_code = uint16_t_dec(p_buf, buf_len, &index, p_cid);
SER_ASSERT(err_code == NRF_SUCCESS, err_code);
SER_ASSERT_LENGTH_EQ(index, buf_len);
return err_code;
}
uint32_t ble_l2cap_cid_unregister_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
return ser_ble_cmd_rsp_status_code_enc(SD_BLE_L2CAP_CID_UNREGISTER, return_code,
p_buf, p_buf_len);
}
uint32_t ble_l2cap_tx_req_dec(uint8_t const * const p_buf,
uint32_t const buf_len,
uint16_t * p_conn_handle,
ble_l2cap_header_t * * const pp_l2cap_header,
uint8_t const * * pp_data)
{
SER_ASSERT_NOT_NULL(p_buf);
SER_ASSERT_NOT_NULL(p_conn_handle);
SER_ASSERT_NOT_NULL(pp_l2cap_header);
SER_ASSERT_NOT_NULL(*pp_l2cap_header);
SER_ASSERT_NOT_NULL(pp_data);
//SER_ASSERT_NOT_NULL(*pp_data);
uint32_t err_code = NRF_SUCCESS;
uint32_t index = SER_CMD_DATA_POS;
err_code = uint16_t_dec(p_buf, buf_len, &index, p_conn_handle);
SER_ASSERT(err_code == NRF_SUCCESS, err_code);
err_code = cond_field_dec(p_buf, buf_len, &index, (void * *)pp_l2cap_header,
ble_l2cap_header_t_dec);
SER_ASSERT(err_code == NRF_SUCCESS, err_code);
if (*pp_l2cap_header != NULL)
{
*pp_data = p_buf + index + 1;
index += 1 + (*pp_l2cap_header)->len;
}
else
{
*pp_data = NULL;
index++;
}
SER_ASSERT_LENGTH_EQ(index, buf_len);
return err_code;
}
uint32_t ble_l2cap_tx_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
return ser_ble_cmd_rsp_status_code_enc(SD_BLE_L2CAP_TX, return_code,
p_buf, p_buf_len);
}
#endif
#if NRF_SD_BLE_API_VERSION >= 5
uint32_t ble_l2cap_ch_setup_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * p_conn_handle,
uint16_t * * pp_local_cid,
ble_l2cap_ch_setup_params_t * * const pp_params)
{
SER_REQ_DEC_BEGIN(SD_BLE_L2CAP_CH_SETUP);
SER_PULL_uint16(p_conn_handle);
SER_PULL_COND(pp_local_cid, uint16_t_dec);
SER_PULL_COND(pp_params, ble_l2cap_ch_setup_params_t_dec);
if (*pp_params && (*pp_params)->rx_params.sdu_buf.p_data)
{
SER_ASSERT_LENGTH_LEQ((*pp_params)->rx_params.sdu_buf.len, CONN_BLE_L2CAP_SDU_MAX_BUFFER_SIZE);
uint8_t * p_data = conn_ble_l2cap_sdu_pool_alloc((*pp_params)->rx_params.sdu_buf.len,
(uint32_t)((*pp_params)->rx_params.sdu_buf.p_data));
(*pp_params)->rx_params.sdu_buf.p_data = p_data;
}
SER_REQ_DEC_END;
}
uint32_t ble_l2cap_ch_setup_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint16_t * p_local_cid)
{
SER_RSP_ENC_BEGIN(SD_BLE_L2CAP_CH_SETUP);
SER_PUSH_COND(p_local_cid, uint16_t_enc);
SER_RSP_ENC_END;
}
uint32_t ble_l2cap_ch_release_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * p_conn_handle,
uint16_t * p_local_cid)
{
SER_REQ_DEC_BEGIN(SD_BLE_L2CAP_CH_RELEASE);
SER_PULL_uint16(p_conn_handle);
SER_PULL_uint16(p_local_cid);
SER_REQ_DEC_END;
}
uint32_t ble_l2cap_ch_release_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_L2CAP_CH_RELEASE);
}
uint32_t ble_l2cap_ch_rx_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * p_conn_handle,
uint16_t * p_local_cid,
ble_data_t * * pp_sdu_buf)
{
SER_REQ_DEC_BEGIN(SD_BLE_L2CAP_CH_RX);
SER_PULL_uint16(p_conn_handle);
SER_PULL_uint16(p_local_cid);
uint8_t * p_tmp = (uint8_t *)1;
SER_PULL_COND(&p_tmp, NULL);
if (p_tmp)
{
SER_PULL_uint16((uint16_t*)&(*pp_sdu_buf)->len);
uint32_t addr;
SER_PULL_uint32(&addr);
SER_ASSERT_LENGTH_LEQ((*pp_sdu_buf)->len, CONN_BLE_L2CAP_SDU_MAX_BUFFER_SIZE);
uint8_t * p_data = conn_ble_l2cap_sdu_pool_alloc((*pp_sdu_buf)->len, addr);
(*pp_sdu_buf)->p_data = p_data;
}
else
{
*pp_sdu_buf = NULL;
}
SER_REQ_DEC_END;
}
uint32_t ble_l2cap_ch_rx_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_L2CAP_CH_RX);
}
uint32_t ble_l2cap_ch_tx_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * p_conn_handle,
uint16_t * p_local_cid,
ble_data_t * * const pp_sdu_buf)
{
SER_REQ_DEC_BEGIN(SD_BLE_L2CAP_CH_TX);
SER_PULL_uint16(p_conn_handle);
SER_PULL_uint16(p_local_cid);
uint8_t * p_tmp = (uint8_t *)1;
SER_PULL_COND(&p_tmp, NULL);
if (p_tmp)
{
uint32_t id;
uint16_t len;
SER_PULL_uint32(&id);
SER_PULL_uint16(&len);
SER_ASSERT_LENGTH_LEQ(len, CONN_BLE_L2CAP_SDU_MAX_BUFFER_SIZE);
uint8_t * p_data = conn_ble_l2cap_sdu_pool_alloc(len, id);
if (p_data)
{
SER_PULL_buf(&p_data, len, len);
}
(*pp_sdu_buf)->p_data = p_data;
(*pp_sdu_buf)->len = len;
}
else
{
*pp_sdu_buf = NULL;
}
SER_REQ_DEC_END;
}
uint32_t ble_l2cap_ch_tx_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_L2CAP_CH_TX);
}
uint32_t ble_l2cap_ch_flow_control_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * p_conn_handle,
uint16_t * p_local_cid,
uint16_t * p_credits,
uint16_t * * pp_credits)
{
SER_REQ_DEC_BEGIN(SD_BLE_L2CAP_CH_FLOW_CONTROL);
SER_PULL_uint16(p_conn_handle);
SER_PULL_uint16(p_local_cid);
SER_PULL_uint16(p_credits);
SER_PULL_COND(pp_credits, NULL);
SER_REQ_DEC_END;
}
uint32_t ble_l2cap_ch_flow_control_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint16_t const * const p_credits)
{
SER_RSP_ENC_BEGIN(SD_BLE_L2CAP_CH_FLOW_CONTROL);
SER_PUSH_COND(p_credits, uint16_t_enc);
SER_RSP_ENC_END;
}
#endif //NRF_SD_BLE_API_VERSION >= 5

View File

@@ -0,0 +1,384 @@
/**
* Copyright (c) 2011 - 2020, 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.
*
*/
/**@file
*
* @defgroup ble_l2cap_conn L2CAP Connectivity command request decoders and command response encoders
* @{
* @ingroup ser_conn_s130_codecs
*
* @brief L2CAP Connectivity command request decoders and command response encoders.
*/
#ifndef BLE_L2CAP_CONN_H__
#define BLE_L2CAP_CONN_H__
#include "ble.h"
#include "ble_types.h"
#include "ble_ranges.h"
#include "ble_err.h"
#include "ble_l2cap.h"
#ifdef __cplusplus
extern "C" {
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
/**@brief Decodes @ref sd_ble_l2cap_cid_register command request.
*
* @sa @ref ble_l2cap_cid_register_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] buf_len Length (in bytes) of response packet.
* @param[in] p_cid Pointer to L2CAP CID.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_l2cap_cid_register_req_dec(uint8_t const * const p_buf,
uint32_t buf_len,
uint16_t * p_cid);
/**@brief Encodes @ref sd_ble_l2cap_cid_register command response.
*
* @sa @ref ble_l2cap_cid_register_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_l2cap_cid_register_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_l2cap_cid_unregister command request.
*
* @sa @ref ble_l2cap_cid_unregister_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] buf_len Length (in bytes) of response packet.
* @param[in] p_cid Pointer to L2CAP CID.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_l2cap_cid_unregister_req_dec(uint8_t const * const p_buf,
uint32_t buf_len,
uint16_t * p_cid);
/**@brief Encodes @ref sd_ble_l2cap_cid_unregister command response.
*
* @sa @ref ble_l2cap_cid_unregister_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_l2cap_cid_unregister_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_l2cap_tx command request.
*
* @sa @ref ble_l2cap_tx_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] buf_len Length (in bytes) of response packet.
* @param[in] p_conn_handle Pointer to connection handle.
* @param[in] pp_l2cap_header Pointer to pointer to L2CAP header.
* @param[in] pp_data Pointer to pointer L2CAP data.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_l2cap_tx_req_dec(uint8_t const * const p_buf,
uint32_t const buf_len,
uint16_t * p_conn_handle,
ble_l2cap_header_t * * const pp_l2cap_header,
uint8_t const * * pp_data);
/**@brief Encodes @ref sd_ble_l2cap_tx command response.
*
* @sa @ref ble_l2cap_tx_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_l2cap_tx_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION >= 5
/**@brief Decodes @ref sd_ble_l2cap_ch_setup command request.
*
* @sa @ref ble_l2cap_ch_setup_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] buf_len Length (in bytes) of response packet.
* @param[in] p_conn_handle Pointer to connection handle.
* @param[in, out] pp_local_cid Pointer to pointer to local cid.
* @param[in, out] pp_params Pointer to pointer to params.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_l2cap_ch_setup_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * p_conn_handle,
uint16_t * * pp_local_cid,
ble_l2cap_ch_setup_params_t * * const pp_params);
/**@brief Encodes @ref sd_ble_l2cap_ch_setup command response.
*
* @sa @ref ble_l2cap_ch_setup_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[p_local_cid Pointer to local cid.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_l2cap_ch_setup_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint16_t * p_local_cid);
/**@brief Decodes @ref sd_ble_l2cap_ch_release command request.
*
* @sa @ref ble_l2cap_ch_release_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] buf_len Length (in bytes) of response packet.
* @param[in] p_conn_handle Pointer to connection handle.
* @param[in] p_local_cid Pointer to local cid.
* @param[in] pp_data Pointer to pointer L2CAP data.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_l2cap_ch_release_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * p_conn_handle,
uint16_t * p_local_cid);
/**@brief Encodes @ref sd_ble_l2cap_ch_releasecommand response.
*
* @sa @ref ble_l2cap_ch_release_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_l2cap_ch_release_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_l2cap_ch_rx command request.
*
* @sa @ref ble_l2cap_ch_rx_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] buf_len Length (in bytes) of response packet.
* @param[in] p_conn_handle Pointer to connection handle.
* @param[in] p_local_cid Pointer to local cid.
* @param[in] pp_sdu_buf Pointer to pointer to SDU buf.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_l2cap_ch_rx_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * p_conn_handle,
uint16_t * p_local_cid,
ble_data_t * * pp_sdu_buf);
/**@brief Encodes @ref sd_ble_l2cap_ch_rx command response.
*
* @sa @ref ble_l2cap_ch_rx_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_l2cap_ch_rx_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_l2cap_ch_tx command request.
*
* @sa @ref ble_l2cap_ch_tx_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] buf_len Length (in bytes) of response packet.
* @param[in] p_conn_handle Pointer to connection handle.
* @param[in] p_local_cid Pointer to local cid.
* @param[in] pp_sdu_buf Pointer to pointer to SDU buf.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_l2cap_ch_tx_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * p_conn_handle,
uint16_t * p_local_cid,
ble_data_t * * const pp_sdu_buf);
/**@brief Encodes @ref sd_ble_l2cap_ch_tx command response.
*
* @sa @ref ble_l2cap_ch_tx_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_l2cap_ch_tx_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_l2cap_ch_flow_control command request.
*
* @sa @ref ble_l2cap_ch_flow_control_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] buf_len Length (in bytes) of response packet.
* @param[in] p_conn_handle Pointer to connection handle.
* @param[in] p_local_cid Pointer to local cid.
* @param[in] p_credits Pointer to credits.
* @param[in,out] pp_credits Pointer to pointer to credits.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_l2cap_ch_flow_control_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * p_conn_handle,
uint16_t * p_local_cid,
uint16_t * p_credits,
uint16_t * * pp_credits);
/**@brief Encodes @ref sd_ble_l2cap_ch_flow_control command response.
*
* @sa @ref ble_l2cap_ch_flow_control_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_credits Pointer to credits.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_l2cap_ch_flow_control_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint16_t const * const p_credits);
#endif
#ifdef __cplusplus
}
#endif
#endif //BLE_L2CAP_CONN_H__
/**
@}
*/

View File

@@ -0,0 +1,199 @@
/**
* Copyright (c) 2014 - 2020, 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 "ble_l2cap_evt_conn.h"
#include <string.h>
#include "ble_serialization.h"
#include "ble_struct_serialization.h"
#include "ble_l2cap_struct_serialization.h"
#include "app_util.h"
#include "conn_ble_l2cap_sdu_pool.h"
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
uint32_t ble_l2cap_evt_rx_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_L2CAP_EVT_RX);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.l2cap_evt.params.rx, ble_l2cap_evt_rx_t_enc);
SER_EVT_ENC_END;
}
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION >= 5
uint32_t ble_l2cap_evt_ch_setup_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_L2CAP_EVT_CH_SETUP_REQUEST);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.local_cid);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.params.ch_setup_request.le_psm);
SER_PUSH_FIELD(&p_event->evt.l2cap_evt.params.ch_setup_request.tx_params, ble_l2cap_ch_tx_params_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_l2cap_evt_ch_setup_refused_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_L2CAP_EVT_CH_SETUP_REFUSED);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.local_cid);
SER_PUSH_uint8(&p_event->evt.l2cap_evt.params.ch_setup_refused.source);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.params.ch_setup_refused.status);
SER_EVT_ENC_END;
}
uint32_t ble_l2cap_evt_ch_setup_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_L2CAP_EVT_CH_SETUP);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.local_cid);
SER_PUSH_FIELD(&p_event->evt.l2cap_evt.params.ch_setup.tx_params, ble_l2cap_ch_tx_params_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_l2cap_evt_ch_released_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_L2CAP_EVT_CH_RELEASED);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.local_cid);
SER_EVT_ENC_END;
}
uint32_t ble_l2cap_evt_ch_sdu_buf_released_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_L2CAP_EVT_CH_SDU_BUF_RELEASED);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.local_cid);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.params.ch_sdu_buf_released.sdu_buf.len);
uint32_t * p_data = (uint32_t *)p_event->evt.l2cap_evt.params.ch_sdu_buf_released.sdu_buf.p_data;
if (p_data)
{
uint32_t id = *(p_data - 1);
conn_ble_l2cap_sdu_pool_free(p_data);
SER_PUSH_uint32(&id);
}
SER_EVT_ENC_END;
}
uint32_t ble_l2cap_evt_ch_credit_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_L2CAP_EVT_CH_CREDIT);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.local_cid);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.params.credit.credits);
SER_EVT_ENC_END;
}
uint32_t ble_l2cap_evt_ch_rx_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_L2CAP_EVT_CH_RX);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.local_cid);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.params.rx.sdu_len);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.params.rx.sdu_buf.len);
uint32_t * p_data = (uint32_t *)p_event->evt.l2cap_evt.params.rx.sdu_buf.p_data;
uint32_t id = *(p_data - 1);
SER_PUSH_uint32(&id);
SER_PUSH_buf(p_event->evt.l2cap_evt.params.rx.sdu_buf.p_data, p_event->evt.l2cap_evt.params.rx.sdu_buf.len);
conn_ble_l2cap_sdu_pool_free(p_data);
SER_EVT_ENC_END;
}
uint32_t ble_l2cap_evt_ch_tx_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_L2CAP_EVT_CH_TX);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.local_cid);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.params.tx.sdu_buf.len);
uint32_t * p_data = (uint32_t *)p_event->evt.l2cap_evt.params.tx.sdu_buf.p_data;
if (p_data)
{
uint32_t id = *(p_data - 1);
conn_ble_l2cap_sdu_pool_free(p_data);
SER_PUSH_uint32(&id);
}
SER_EVT_ENC_END;
}
#endif

View File

@@ -0,0 +1,121 @@
/**
* Copyright (c) 2014 - 2020, 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.
*
*/
#ifndef BLE_L2CAP_EVT_CONN_H__
#define BLE_L2CAP_EVT_CONN_H__
/**@file
*
* @defgroup ble_l2cap_evt_conn L2CAP Connectivity event encoders
* @{
* @ingroup ser_conn_s130_codecs
*
* @brief L2CAP Connectivity event encoders.
*/
#include "ble.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Encodes ble_l2cap_evt_rx event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_l2cap_evt_rx_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
uint32_t ble_l2cap_evt_ch_setup_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
uint32_t ble_l2cap_evt_ch_setup_refused_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
uint32_t ble_l2cap_evt_ch_setup_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
uint32_t ble_l2cap_evt_ch_released_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
uint32_t ble_l2cap_evt_ch_sdu_buf_released_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
uint32_t ble_l2cap_evt_ch_credit_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
uint32_t ble_l2cap_evt_ch_rx_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
uint32_t ble_l2cap_evt_ch_tx_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/** @} */
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,202 @@
/**
* Copyright (c) 2014 - 2020, 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 "conn_ble_gap_sec_keys.h"
#include "ser_config.h"
#include "nrf_error.h"
#include "nordic_common.h"
#include <stddef.h>
ser_ble_gap_conn_keyset_t m_conn_keys_table[SER_MAX_CONNECTIONS];
#if NRF_SD_BLE_API_VERSION >= 6
typedef struct
{
uint32_t id;
uint8_t ble_data[SER_MAX_ADV_DATA];
} ble_data_item_t;
ble_data_item_t m_ble_data_pool[8];
static uint8_t * mp_scan_data;
#endif
void conn_ble_gap_sec_keys_init(void)
{
uint32_t i;
for (i = 0; i < SER_MAX_CONNECTIONS; i++)
{
m_conn_keys_table[i].conn_active = 0;
}
#if NRF_SD_BLE_API_VERSION >= 6
for (i = 0; i < 8; i++)
{
m_ble_data_pool[i].id = 0;
}
#endif
}
uint32_t conn_ble_gap_sec_context_create(uint32_t *p_index)
{
uint32_t err_code = NRF_ERROR_NO_MEM;
uint32_t i;
for (i=0; i<SER_MAX_CONNECTIONS; i++ )
{
if ( ! m_conn_keys_table[i].conn_active )
{
m_conn_keys_table[i].conn_active = 1;
*p_index = i;
err_code = NRF_SUCCESS;
break;
}
}
return err_code;
}
uint32_t conn_ble_gap_sec_context_destroy(uint16_t conn_handle)
{
uint32_t err_code = NRF_ERROR_NOT_FOUND;
uint32_t i;
for (i=0; i<SER_MAX_CONNECTIONS; i++ )
{
if ( m_conn_keys_table[i].conn_handle == conn_handle )
{
m_conn_keys_table[i].conn_active = 0;
err_code = NRF_SUCCESS;
break;
}
}
return err_code;
}
uint32_t conn_ble_gap_sec_context_find(uint16_t conn_handle, uint32_t *p_index)
{
uint32_t err_code = NRF_ERROR_NOT_FOUND;
uint32_t i;
for (i=0; i<SER_MAX_CONNECTIONS; i++ )
{
if ( (m_conn_keys_table[i].conn_handle == conn_handle) && (m_conn_keys_table[i].conn_active == 1) )
{
*p_index = i;
err_code = NRF_SUCCESS;
break;
}
}
return err_code;
}
#if NRF_SD_BLE_API_VERSION >= 6
uint8_t * conn_ble_gap_ble_data_buf_alloc(uint32_t id)
{
uint32_t i;
if (id == 0)
{
return NULL;
}
/* First find if given id already allocated the buffer. */
for (i = 0; i < ARRAY_SIZE(m_ble_data_pool); i++)
{
if (m_ble_data_pool[i].id == id)
{
return m_ble_data_pool[i].ble_data;
}
}
for (i = 0; i < ARRAY_SIZE(m_ble_data_pool); i++)
{
if (m_ble_data_pool[i].id == 0)
{
m_ble_data_pool[i].id = id;
return m_ble_data_pool[i].ble_data;
}
}
return NULL;
}
uint32_t conn_ble_gap_ble_data_buf_free(uint8_t * p_data)
{
uint32_t i;
if (p_data == NULL)
{
return 0;
}
/* First find if given id already allocated the buffer. */
for (i = 0; i < ARRAY_SIZE(m_ble_data_pool); i++)
{
if (m_ble_data_pool[i].ble_data == p_data)
{
uint32_t id = m_ble_data_pool[i].id;
m_ble_data_pool[i].id = 0;
return id;
}
}
return 0;
}
void conn_ble_gap_scan_data_set(uint8_t * p_scan_data)
{
mp_scan_data = p_scan_data;
}
void conn_ble_gap_scan_data_unset(bool free)
{
if (mp_scan_data)
{
if (free)
{
(void)conn_ble_gap_ble_data_buf_free(mp_scan_data);
}
mp_scan_data = NULL;
}
}
#endif

View File

@@ -0,0 +1,131 @@
/**
* Copyright (c) 2014 - 2020, 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.
*
*/
#ifndef _CONN_BLE_GAP_SEC_KEYS_H
#define _CONN_BLE_GAP_SEC_KEYS_H
/**@file
*
* @defgroup conn_ble_gap_sec_keys GAP Functions for managing memory for security keys on connectivity device
* @{
* @ingroup ser_conn_s130_codecs
*
* @brief GAP Connectivity auxiliary functions for providing static memory required by the SoftDevice. This memory is used to store GAP security keys.
*/
#include "ble_gap.h"
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/**@brief GAP connection - keyset mapping structure.
*
* @note This structure is used to map keysets to connection instances, and will be stored in a static table.
*/
typedef struct
{
uint16_t conn_handle; /**< Connection handle. */
uint8_t conn_active; /**< Indication that keys for this connection are used by the SoftDevice. 0: keys used; 1: keys not used. */
ble_gap_sec_keyset_t keyset; /**< Keyset structure, see @ref ble_gap_sec_keyset_t. */
ble_gap_enc_key_t enc_key_own; /**< Own Encryption Key, see @ref ble_gap_enc_key_t. */
ble_gap_id_key_t id_key_own; /**< Own Identity Key, see @ref ble_gap_id_key_t. */
ble_gap_sign_info_t sign_key_own; /**< Own Signing Information, see @ref ble_gap_sign_info_t. */
ble_gap_lesc_p256_pk_t pk_own; /**< Own Public key, see @ref ble_gap_lesc_p256_pk_t. */
ble_gap_enc_key_t enc_key_peer; /**< Peer Encryption Key, see @ref ble_gap_enc_key_t. */
ble_gap_id_key_t id_key_peer; /**< Peer Identity Key, see @ref ble_gap_id_key_t. */
ble_gap_sign_info_t sign_key_peer; /**< Peer Signing Information, see @ref ble_gap_sign_info_t. */
ble_gap_lesc_p256_pk_t pk_peer; /**< Peer Public key, see @ref ble_gap_lesc_p256_pk_t. */
} ser_ble_gap_conn_keyset_t;
/**@brief Initializes buffer pool. */
void conn_ble_gap_sec_keys_init(void);
/**@brief Allocates instance in m_conn_keys_table[] for storage of encryption keys.
*
* @param[out] p_index Pointer to the index of allocated instance.
*
* @retval NRF_SUCCESS Success.
* @retval NRF_ERROR_NO_MEM No free instance available.
*/
uint32_t conn_ble_gap_sec_context_create(uint32_t *p_index);
/**@brief Releases the instance identified by a connection handle.
*
* @param[in] conn_handle conn_handle
*
* @retval NRF_SUCCESS Context released.
* @retval NRF_ERROR_NOT_FOUND Instance with conn_handle not found.
*/
uint32_t conn_ble_gap_sec_context_destroy(uint16_t conn_handle);
/**@brief Finds index of the instance identified by a connection handle in m_conn_keys_table[].
*
* @param[in] conn_handle conn_handle
*
* @param[out] p_index Pointer to the index of entry in the context table corresponding to the given conn_handle.
*
* @retval NRF_SUCCESS Context table entry found.
* @retval NRF_ERROR_NOT_FOUND Instance with the conn_handle not found.
*/
uint32_t conn_ble_gap_sec_context_find(uint16_t conn_handle, uint32_t *p_index);
/** @} */
/** @brief Function allocates data from the pool.
*
* @param id ID used for buffer identification. If buffer with given ID is already allocated the pointer to that buffer is returned.
* @return Allocated buffer of NULL.
*/
uint8_t * conn_ble_gap_ble_data_buf_alloc(uint32_t id);
/** @brief Function for freeing the buffer.
* @param p_data Buffer to be freed.
*/
uint32_t conn_ble_gap_ble_data_buf_free(uint8_t * p_data);
void conn_ble_gap_scan_data_set(uint8_t * p_scan_data);
void conn_ble_gap_scan_data_unset(bool free);
#ifdef __cplusplus
}
#endif
#endif //_CONN_BLE_GAP_SEC_KEYS_H

View File

@@ -0,0 +1,84 @@
/**
* Copyright (c) 2014 - 2020, 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 "conn_ble_l2cap_sdu_pool.h"
#include "app_util.h"
#include "nrf_balloc.h"
#define MAX_NUM_OF_BUFFERS 8
#define ID_SIZE 4
#define TOTAL_BUF_SIZE (CONN_BLE_L2CAP_SDU_MAX_BUFFER_SIZE+ID_SIZE)
NRF_BALLOC_DEF(m_pool, TOTAL_BUF_SIZE, MAX_NUM_OF_BUFFERS);
void conn_ble_l2cap_sdu_pool_init(void)
{
(void)nrf_balloc_init(&m_pool);
}
uint8_t * conn_ble_l2cap_sdu_pool_alloc(uint16_t length, uint32_t id)
{
if (length > CONN_BLE_L2CAP_SDU_MAX_BUFFER_SIZE)
{
return NULL;
}
uint32_t * p_buf = nrf_balloc_alloc(&m_pool);
*p_buf = id;
p_buf++;
return (uint8_t *)p_buf;
}
uint32_t conn_ble_l2cap_sdu_pool_id_get(void * p_data)
{
uint32_t * p_buf = (uint32_t *)p_data;
p_buf--;
return *p_buf;
}
void conn_ble_l2cap_sdu_pool_free(void * p_data)
{
uint32_t * p_buf = (uint32_t *)p_data;
p_buf--;
nrf_balloc_free(&m_pool, p_buf);
}

View File

@@ -0,0 +1,53 @@
/**
* Copyright (c) 2014 - 2020, 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.
*
*/
#ifndef CONN_BLE_L2CAP_SDU_POOL_H
#define CONN_BLE_L2CAP_SDU_POOL_H
#include <stdint.h>
#define CONN_BLE_L2CAP_SDU_MAX_BUFFER_SIZE 124
void conn_ble_l2cap_sdu_pool_init(void);
uint8_t * conn_ble_l2cap_sdu_pool_alloc(uint16_t length, uint32_t id);
uint32_t conn_ble_l2cap_sdu_pool_id_get(void * p_data);
void conn_ble_l2cap_sdu_pool_free(void * p_data);
#endif //CONN_BLE_L2CAP_SDU_POOL_H

View File

@@ -0,0 +1,115 @@
/**
* Copyright (c) 2014 - 2020, 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 "conn_ble_user_mem.h"
#include "ser_config.h"
#include "nrf_error.h"
#include <stddef.h>
sercon_ble_user_mem_t m_conn_user_mem_table[SER_MAX_CONNECTIONS];
void conn_ble_user_mem_init(void)
{
uint32_t i;
for (i=0; i<SER_MAX_CONNECTIONS; i++ )
{
m_conn_user_mem_table[i].conn_active = 0;
}
}
uint32_t conn_ble_user_mem_context_create(uint32_t *p_index)
{
uint32_t err_code = NRF_ERROR_NO_MEM;
uint32_t i;
for (i=0; i<SER_MAX_CONNECTIONS; i++ )
{
if ( ! m_conn_user_mem_table[i].conn_active )
{
m_conn_user_mem_table[i].conn_active = 1;
m_conn_user_mem_table[i].mem_block.p_mem = m_conn_user_mem_table[i].mem_table;
*p_index = i;
err_code = NRF_SUCCESS;
break;
}
}
return err_code;
}
uint32_t conn_ble_user_mem_context_destroy(uint16_t conn_handle)
{
uint32_t err_code = NRF_ERROR_NOT_FOUND;
uint32_t i;
for (i=0; i<SER_MAX_CONNECTIONS; i++ )
{
if ( m_conn_user_mem_table[i].conn_handle == conn_handle )
{
m_conn_user_mem_table[i].conn_active = 0;
m_conn_user_mem_table[i].mem_block.p_mem = NULL;
err_code = NRF_SUCCESS;
break;
}
}
return err_code;
}
uint32_t conn_ble_user_mem_context_find(uint16_t conn_handle, uint32_t *p_index)
{
uint32_t err_code = NRF_ERROR_NOT_FOUND;
uint32_t i;
for (i=0; i<SER_MAX_CONNECTIONS; i++ )
{
if ( (m_conn_user_mem_table[i].conn_handle == conn_handle) && (m_conn_user_mem_table[i].conn_active == 1) )
{
*p_index = i;
err_code = NRF_SUCCESS;
break;
}
}
return err_code;
}

View File

@@ -0,0 +1,111 @@
/**
* Copyright (c) 2014 - 2020, 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.
*
*/
#ifndef _CONN_BLE_USER_MEM_H
#define _CONN_BLE_USER_MEM_H
/**@file
*
* @defgroup conn_ble_user_mem Functions for managing memory for user memory request on connectivity device.
* @{
* @ingroup ser_conn_s130_codecs
*
* @brief Connectivity auxiliary functions for providing static memory required by the SoftDevice.
*/
#include "ble.h"
#include "ser_config.h"
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Connection - user memory mapping structure.
*
* @note This structure is used to map keysets to connection instances, and will be stored in a static table.
*/
//lint -esym(452,ser_ble_user_mem_t)
typedef struct
{
uint16_t conn_handle; /**< Connection handle.*/
uint8_t conn_active; /**< Indication that user memory for this connection is used by the SoftDevice. 0: memory used; 1: memory not used. */
ble_user_mem_block_t mem_block; /**< User memory block structure, see @ref ble_user_mem_block_t. */
uint8_t mem_table[64]; /**< Memory table. */
} sercon_ble_user_mem_t;
/**@brief Initializes buffer pool. */
void conn_ble_user_mem_init(void);
/**@brief Allocates instance in m_user_mem_table[] for storage.
*
* @param[out] p_index Pointer to the index of allocated instance.
*
* @retval NRF_SUCCESS Success.
* @retval NRF_ERROR_NO_MEM No free instance available.
*/
uint32_t conn_ble_user_mem_context_create(uint32_t *p_index);
/**@brief Releases the instance identified by a connection handle.
*
* @param[in] conn_handle conn_handle
*
* @retval NRF_SUCCESS Context released.
* @retval NRF_ERROR_NOT_FOUND Instance with the conn_handle not found.
*/
uint32_t conn_ble_user_mem_context_destroy(uint16_t conn_handle);
/**@brief Finds index of the instance identified by a connection handle in m_user_mem_table[].
*
* @param[in] conn_handle conn_handle
*
* @param[out] p_index Pointer to the index of entry in the context table corresponding to the given conn_handle.
*
* @retval NRF_SUCCESS Context table entry found.
* @retval NRF_ERROR_NOT_FOUND Instance with the conn_handle not found.
*/
uint32_t conn_ble_user_mem_context_find(uint16_t conn_handle, uint32_t *p_index);
/** @} */
#ifdef __cplusplus
}
#endif
#endif //_CONN_BLE_USER_MEM_H

View File

@@ -0,0 +1,89 @@
/**
* Copyright (c) 2014 - 2020, 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 "nrf_soc.h"
#include "nrf_soc_conn.h"
#include "nrf_error.h"
#include "ble_serialization.h"
#include "cond_field_serialization.h"
#include "nrf_soc_struct_serialization.h"
uint32_t ecb_block_encrypt_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
nrf_ecb_hal_data_t * * const pp_ecb_data)
{
SER_REQ_DEC_BEGIN(SD_ECB_BLOCK_ENCRYPT);
SER_PULL_COND(pp_ecb_data, nrf_ecb_hal_data_t_in_dec);
SER_REQ_DEC_END;
}
uint32_t ecb_block_encrypt_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
nrf_ecb_hal_data_t * const p_ecb_data)
{
SER_RSP_ENC_BEGIN(SD_ECB_BLOCK_ENCRYPT);
SER_PUSH_COND(p_ecb_data, nrf_ecb_hal_data_t_out_enc);
SER_RSP_ENC_END;
}
uint32_t power_system_off_req_dec(uint8_t const * const p_buf,
uint16_t packet_len)
{
SER_REQ_DEC_BEGIN(SD_POWER_SYSTEM_OFF);
SER_REQ_DEC_END;
}
uint32_t temp_get_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
int32_t * * const pp_temp)
{
SER_REQ_DEC_BEGIN(SD_TEMP_GET);
SER_PULL_COND(pp_temp, NULL);
SER_REQ_DEC_END;
}
uint32_t temp_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
int32_t * const p_temp)
{
SER_RSP_ENC_BEGIN(SD_TEMP_GET);
SER_PUSH_COND(p_temp, uint32_t_enc);
SER_RSP_ENC_END;
}

View File

@@ -0,0 +1,148 @@
/**
* Copyright (c) 2014 - 2020, 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.
*
*/
#ifndef NRF_SOC_CONN_H__
#define NRF_SOC_CONN_H__
/**@file
*
* @defgroup soc_conn SOC Connectivity command request decoders and command response encoders
* @{
* @ingroup ser_conn_s130_codecs
*
* @brief SOC Connectivity command request decoders and command response encoders.
*/
#include "nrf_soc.h"
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Decodes @ref sd_power_system_off command request.
*
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in] packet_len Length (in bytes) of request packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_PARAM Encoding failure. Incorrect parameter.
*/
uint32_t power_system_off_req_dec(uint8_t const * const p_buf, uint16_t packet_len);
/**@brief Decodes @ref sd_temp_get command request.
*
* @sa @ref temp_get_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in] packet_len Length (in bytes) of request packet.
* @param[out] pp_temp Pointer to pointer to result of temperature measurement.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_PARAM Encoding failure. Incorrect parameter.
*/
uint32_t temp_get_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
int32_t * * const pp_temp);
/**@brief Encodes @ref sd_temp_get command response.
*
* @sa @ref temp_get_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_temp Pointer to result of temperature measurement.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t temp_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
int32_t * const p_temp);
/**@brief Decodes @ref sd_ecb_block_encrypt command request.
*
* @sa @ref ecb_block_encrypt_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in] packet_len Length (in bytes) of request packet.
* @param[out] pp_ecb_data Pointer to pointer to ECB data.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied
* @retval NRF_ERROR_INVALID_PARAM Encoding failure. Incorrect parameter.
*/
uint32_t ecb_block_encrypt_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
nrf_ecb_hal_data_t * * const pp_ecb_data);
/**@brief Encodes @ref sd_ecb_block_encrypt command response.
*
* @sa @ref ecb_block_encrypt_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_ecb_data Pointer to ECB data.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ecb_block_encrypt_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
nrf_ecb_hal_data_t * const p_ecb_data);
/** @} */
#ifdef __cplusplus
}
#endif
#endif