初始版本

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,626 @@
/**
* 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_serialization.h"
#include <stdint.h>
#include "ble_app.h"
#include "ser_sd_transport.h"
#include "app_error.h"
#include "app_ble_user_mem.h"
#include "app_ble_gap_sec_keys.h"
extern ser_ble_user_mem_t m_app_user_mem_table[];
/**@brief Structure containing @ref sd_ble_uuid_encode output parameters. */
typedef struct
{
uint8_t * p_uuid_le_len; /**< @ref sd_ble_uuid_encode appearance p_uuid_le_len output parameter. */
uint8_t * p_uuid_le; /**< @ref sd_ble_uuid_encode appearance p_uuid_le output parameter. */
} ble_uuid_encode_out_params_t;
/**@brief Structure containing @ref sd_ble_user_mem_reply output parameters. */
typedef struct
{
uint16_t conn_handle; /**< @ref sd_ble_user_mem_reply conn_handle. */
uint8_t context_allocated; /**< @ref sd_ble_user_mem_reply user memory context allocated flag. */
} ble_user_mem_reply_out_params_t;
/**@brief Union containing BLE command output parameters. */
typedef union
{
ble_uuid_encode_out_params_t ble_uuid_encode_out_params; /**< @ref sd_ble_uuid_encode output parameters. */
ble_user_mem_reply_out_params_t ble_user_mem_reply_out_params; /**< @ref sd_ble_user_mem_reply output parameters. */
} ble_command_output_params_t;
static ble_command_output_params_t m_output_params; /**< BLE command output parameters. */
static void * mp_out_params[3];
static uint32_t m_uint32_param;
static void tx_buf_alloc(uint8_t * * p_data, uint32_t * p_len)
{
uint32_t err_code;
uint16_t len16;
do
{
err_code = ser_sd_transport_tx_alloc(p_data, &len16);
}
while (err_code != NRF_SUCCESS);
*p_data[0] = SER_PKT_TYPE_CMD;
*p_len = (uint32_t)len16 - 1;
}
/**@brief Command response callback function for @ref sd_ble_uuid_encode BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t uuid_encode_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code =
ble_uuid_encode_rsp_dec(p_buffer,
length,
m_output_params.ble_uuid_encode_out_params.p_uuid_le_len,
m_output_params.ble_uuid_encode_out_params.p_uuid_le,
&result_code);
//@note: Should never fail.
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_uuid_encode
#define _sd_ble_uuid_encode sd_ble_uuid_encode
#endif
uint32_t _sd_ble_uuid_encode(ble_uuid_t const * const p_uuid,
uint8_t * const p_uuid_le_len,
uint8_t * const p_uuid_le)
{
uint8_t * p_buffer;
uint32_t buffer_length;
tx_buf_alloc(&p_buffer, &buffer_length);
m_output_params.ble_uuid_encode_out_params.p_uuid_le_len = p_uuid_le_len;
m_output_params.ble_uuid_encode_out_params.p_uuid_le = p_uuid_le;
uint32_t err_code = ble_uuid_encode_req_enc(p_uuid,
p_uuid_le_len,
p_uuid_le,
&(p_buffer[1]),
&buffer_length);
//@note: Should never fail.
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
uuid_encode_rsp_dec);
}
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
/**@brief Command response callback function for @ref sd_ble_tx_packet_count_get BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t tx_packet_count_get_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = ble_tx_packet_count_get_rsp_dec(p_buffer,
length,
(uint8_t * *)&mp_out_params[0],
&result_code);
//@note: Should never fail.
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_tx_packet_count_get
#define _sd_ble_tx_packet_count_get sd_ble_tx_packet_count_get
#endif
uint32_t _sd_ble_tx_packet_count_get(uint16_t conn_handle, uint8_t * p_count)
{
uint8_t * p_buffer;
uint32_t buffer_length;
tx_buf_alloc(&p_buffer, &buffer_length);
mp_out_params[0] = p_count;
const uint32_t err_code = ble_tx_packet_count_get_req_enc(conn_handle,
p_count,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
tx_packet_count_get_rsp_dec);
}
#endif
/**@brief Command response callback function for @ref sd_ble_uuid_vs_add BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t uuid_vs_add_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = ble_uuid_vs_add_rsp_dec(p_buffer,
length,
(uint8_t * *)&mp_out_params[0],
&result_code);
//@note: Should never fail.
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_uuid_vs_add
#define _sd_ble_uuid_vs_add sd_ble_uuid_vs_add
#endif
uint32_t _sd_ble_uuid_vs_add(ble_uuid128_t const * const p_vs_uuid, uint8_t * const p_uuid_type)
{
uint8_t * p_buffer;
uint32_t buffer_length;
tx_buf_alloc(&p_buffer, &buffer_length);
mp_out_params[0] = p_uuid_type;
const uint32_t err_code = ble_uuid_vs_add_req_enc(p_vs_uuid, p_uuid_type,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
uuid_vs_add_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ble_uuid_decode BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t uuid_decode_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = ble_uuid_decode_rsp_dec(p_buffer,
length,
(ble_uuid_t * *)&mp_out_params[0],
&result_code);
//@note: Should never fail.
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_uuid_decode
#define _sd_ble_uuid_decode sd_ble_uuid_decode
#endif
uint32_t _sd_ble_uuid_decode(uint8_t uuid_le_len,
uint8_t const * const p_uuid_le,
ble_uuid_t * const p_uuid)
{
uint8_t * p_buffer;
uint32_t buffer_length;
tx_buf_alloc(&p_buffer, &buffer_length);
mp_out_params[0] = p_uuid;
const uint32_t err_code = ble_uuid_decode_req_enc(uuid_le_len, p_uuid_le, p_uuid,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
uuid_decode_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ble_version_get BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t version_get_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = ble_version_get_rsp_dec(p_buffer,
length,
(ble_version_t *)mp_out_params[0],
&result_code);
//@note: Should never fail.
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_version_get
#define _sd_ble_version_get sd_ble_version_get
#endif
uint32_t _sd_ble_version_get(ble_version_t * p_version)
{
uint8_t * p_buffer;
uint32_t buffer_length;
tx_buf_alloc(&p_buffer, &buffer_length);
mp_out_params[0] = p_version;
const uint32_t err_code = ble_version_get_req_enc(p_version,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
version_get_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ble_opt_get BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t opt_get_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
uint32_t uint32_param;
uint32_t err_code = ble_opt_get_rsp_dec(p_buffer,
length,
&uint32_param,
(ble_opt_t *)mp_out_params[0],
&result_code);
APP_ERROR_CHECK(err_code);
if ((result_code == NRF_SUCCESS) && (m_uint32_param != uint32_param)) // decoded id should be the same as encoded one
{
err_code = NRF_ERROR_INVALID_PARAM;
}
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_opt_get
#define _sd_ble_opt_get sd_ble_opt_get
#endif
uint32_t _sd_ble_opt_get(uint32_t opt_id, ble_opt_t *p_opt)
{
uint8_t * p_buffer;
uint32_t buffer_length;
tx_buf_alloc(&p_buffer, &buffer_length);
mp_out_params[0] = p_opt;
m_uint32_param = opt_id;
const uint32_t err_code = ble_opt_get_req_enc(opt_id,
p_opt,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
opt_get_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ble_opt_set BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t opt_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = ble_opt_set_rsp_dec(p_buffer,
length,
&result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_opt_set
#define _sd_ble_opt_set sd_ble_opt_set
#endif
uint32_t _sd_ble_opt_set(uint32_t opt_id, ble_opt_t const *p_opt)
{
uint8_t * p_buffer;
uint32_t buffer_length;
tx_buf_alloc(&p_buffer, &buffer_length);
const uint32_t err_code = ble_opt_set_req_enc(opt_id,
p_opt,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
opt_set_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ble_enable BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t enable_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = ble_enable_rsp_dec(p_buffer,
length,
&result_code);
//@note: Should never fail.
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_enable
#define _sd_ble_enable sd_ble_enable
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
uint32_t _sd_ble_enable(ble_enable_params_t * p_params, uint32_t * p_app_ram_base)
{
uint8_t * p_buffer;
uint32_t buffer_length;
//Ignore ram_base parameter
(void)p_app_ram_base;
app_ble_gap_sec_keys_init();
tx_buf_alloc(&p_buffer, &buffer_length);
mp_out_params[0] = p_params;
const uint32_t err_code = ble_enable_req_enc(p_params,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
enable_rsp_dec);
}
#else
uint32_t _sd_ble_enable(uint32_t * p_app_ram_base)
{
uint8_t * p_buffer;
uint32_t buffer_length;
//Ignore ram_base parameter
(void)p_app_ram_base;
app_ble_gap_sec_keys_init();
tx_buf_alloc(&p_buffer, &buffer_length);
const uint32_t err_code = ble_enable_req_enc(&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
enable_rsp_dec);
}
#endif
/**@brief Command response callback function for @ref sd_ble_user_mem_reply BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t user_mem_reply_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
uint32_t err_code = ble_user_mem_reply_rsp_dec(p_buffer,
length,
&result_code);
APP_ERROR_CHECK(err_code);
if ((result_code != NRF_SUCCESS) &&
(m_output_params.ble_user_mem_reply_out_params.context_allocated))
{
err_code = app_ble_user_mem_context_destroy(
m_output_params.ble_user_mem_reply_out_params.conn_handle);
SER_ASSERT(err_code == NRF_SUCCESS, err_code);
}
return result_code;
}
#ifndef _sd_ble_user_mem_reply
#define _sd_ble_user_mem_reply sd_ble_user_mem_reply
#endif
uint32_t _sd_ble_user_mem_reply(uint16_t conn_handle, ble_user_mem_block_t const *p_block)
{
uint8_t * p_buffer;
uint32_t buffer_length, user_mem_table_index;
uint32_t err_code = NRF_SUCCESS;
tx_buf_alloc(&p_buffer, &buffer_length);
// Prepare User Memory Block context for later synchronization when SoftDevice updates
// the data in the memory block
if (p_block != NULL)
{
err_code = app_ble_user_mem_context_create(conn_handle, &user_mem_table_index);
SER_ASSERT(err_code == NRF_SUCCESS, err_code);
m_app_user_mem_table[user_mem_table_index].mem_block.len = p_block->len;
m_app_user_mem_table[user_mem_table_index].mem_block.p_mem = p_block->p_mem;
// Save connection handle and context allocation flag for case if context destroy was needed
m_output_params.ble_user_mem_reply_out_params.conn_handle = conn_handle;
m_output_params.ble_user_mem_reply_out_params.context_allocated = 1;
}
else
{
m_output_params.ble_user_mem_reply_out_params.context_allocated = 0;
}
err_code = ble_user_mem_reply_req_enc(conn_handle,
p_block,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
user_mem_reply_rsp_dec);
}
#if NRF_SD_BLE_API_VERSION >= 4
/**@brief Command response callback function for @ref sd_ble_cfg_set BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t cfg_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = ble_cfg_set_rsp_dec(p_buffer,
length,
&result_code);
//@note: Should never fail.
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_cfg_set
#define _sd_ble_cfg_set sd_ble_cfg_set
#endif
uint32_t _sd_ble_cfg_set(uint32_t cfg_id, ble_cfg_t const * p_cfg, uint32_t app_ram_base)
{
uint8_t * p_buffer;
uint32_t buffer_length;
//Ignore ram_base parameter
(void)app_ram_base;
tx_buf_alloc(&p_buffer, &buffer_length);
const uint32_t err_code = ble_cfg_set_req_enc(cfg_id, p_cfg,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
cfg_set_rsp_dec);
}
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,566 @@
/**
* 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 <stdint.h>
#include "ble_gattc.h"
#include "ble_gattc_app.h"
#include "ble_serialization.h"
#include "ser_sd_transport.h"
#include "app_error.h"
static void tx_buf_alloc(uint8_t * * p_data, uint16_t * p_len)
{
uint32_t err_code;
do
{
err_code = ser_sd_transport_tx_alloc(p_data, p_len);
}
while (err_code != NRF_SUCCESS);
*p_data[0] = SER_PKT_TYPE_CMD;
*p_len -= 1;
}
/**@brief Command response callback function for @ref sd_ble_gattc_primary_services_discover BLE command.
*
* Callback for decoding the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t gattc_primary_services_discover_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = ble_gattc_primary_services_discover_rsp_dec(p_buffer,
length,
&result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_gattc_primary_services_discover
#define _sd_ble_gattc_primary_services_discover sd_ble_gattc_primary_services_discover
#endif
uint32_t _sd_ble_gattc_primary_services_discover(uint16_t conn_handle,
uint16_t start_handle,
ble_uuid_t const * const p_srvc_uuid)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
const uint32_t err_code = ble_gattc_primary_services_discover_req_enc(conn_handle,
start_handle,
p_srvc_uuid,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
gattc_primary_services_discover_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ble_gattc_relationships_discover BLE command.
*
* Callback for decoding the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t gattc_relationships_discover_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = ble_gattc_relationships_discover_rsp_dec(p_buffer,
length,
&result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_gattc_relationships_discover
#define _sd_ble_gattc_relationships_discover sd_ble_gattc_relationships_discover
#endif
uint32_t _sd_ble_gattc_relationships_discover(uint16_t conn_handle,
ble_gattc_handle_range_t const * const p_handle_range)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
const uint32_t err_code = ble_gattc_relationships_discover_req_enc(conn_handle,
p_handle_range,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
gattc_relationships_discover_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ble_gattc_characteristics_discover BLE command.
*
* Callback for decoding the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t gattc_characteristics_discover_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = ble_gattc_characteristics_discover_rsp_dec(p_buffer,
length,
&result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_gattc_characteristics_discover
#define _sd_ble_gattc_characteristics_discover sd_ble_gattc_characteristics_discover
#endif
uint32_t _sd_ble_gattc_characteristics_discover(
uint16_t conn_handle,
ble_gattc_handle_range_t const * const
p_handle_range)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
const uint32_t err_code = ble_gattc_characteristics_discover_req_enc(conn_handle,
p_handle_range,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
gattc_characteristics_discover_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ble_gattc_descriptors_discover BLE command.
*
* Callback for decoding the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t gattc_descriptors_discover_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = ble_gattc_descriptors_discover_rsp_dec(p_buffer, length, &result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_gattc_descriptors_discover
#define _sd_ble_gattc_descriptors_discover sd_ble_gattc_descriptors_discover
#endif
uint32_t _sd_ble_gattc_descriptors_discover(uint16_t conn_handle,
ble_gattc_handle_range_t const * const p_handle_range)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
const uint32_t err_code = ble_gattc_descriptors_discover_req_enc(conn_handle,
p_handle_range,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
gattc_descriptors_discover_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ble_gattc_char_value_by_uuid_read BLE command.
*
* Callback for decoding the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t gattc_char_value_by_uuid_read_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = ble_gattc_char_value_by_uuid_read_rsp_dec(p_buffer,
length,
&result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_gattc_char_value_by_uuid_read
#define _sd_ble_gattc_char_value_by_uuid_read sd_ble_gattc_char_value_by_uuid_read
#endif
uint32_t _sd_ble_gattc_char_value_by_uuid_read(uint16_t conn_handle,
ble_uuid_t const * const p_uuid,
ble_gattc_handle_range_t const * const p_handle_range)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
const uint32_t err_code = ble_gattc_char_value_by_uuid_read_req_enc(conn_handle,
p_uuid,
p_handle_range,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
gattc_char_value_by_uuid_read_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ble_gattc_read BLE command.
*
* Callback for decoding the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t gattc_read_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = ble_gattc_read_rsp_dec(p_buffer, length, &result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_gattc_read
#define _sd_ble_gattc_read sd_ble_gattc_read
#endif
uint32_t _sd_ble_gattc_read(uint16_t conn_handle,
uint16_t handle,
uint16_t offset)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
const uint32_t err_code = ble_gattc_read_req_enc(conn_handle,
handle,
offset,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
gattc_read_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ble_gattc_char_values_read BLE command.
*
* Callback for decoding the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t gattc_char_values_read_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = ble_gattc_char_values_read_rsp_dec(p_buffer, length, &result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_gattc_char_values_read
#define _sd_ble_gattc_char_values_read sd_ble_gattc_char_values_read
#endif
uint32_t _sd_ble_gattc_char_values_read(uint16_t conn_handle,
uint16_t const * const p_handles,
uint16_t handle_count)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
const uint32_t err_code = ble_gattc_char_values_read_req_enc(conn_handle,
p_handles,
handle_count,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
gattc_char_values_read_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ble_gattc_write BLE command.
*
* Callback for decoding the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t gattc_write_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = ble_gattc_write_rsp_dec(p_buffer, length, &result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_gattc_write
#define _sd_ble_gattc_write sd_ble_gattc_write
#endif
uint32_t _sd_ble_gattc_write(uint16_t conn_handle,
ble_gattc_write_params_t const * const p_write_params)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
const uint32_t err_code = ble_gattc_write_req_enc(conn_handle,
p_write_params,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
gattc_write_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ble_gattc_hv_confirm BLE command.
*
* Callback for decoding the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t gattc_hv_confirm_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = ble_gattc_hv_confirm_rsp_dec(p_buffer, length, &result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_gattc_hv_confirm
#define _sd_ble_gattc_hv_confirm sd_ble_gattc_hv_confirm
#endif
uint32_t _sd_ble_gattc_hv_confirm(uint16_t conn_handle,
uint16_t handle)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
const uint32_t err_code = ble_gattc_hv_confirm_req_enc(conn_handle,
handle,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
gattc_hv_confirm_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ble_gattc_info_discover BLE command.
*
* Callback for decoding the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t gattc_attr_info_discover_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = ble_gattc_attr_info_discover_rsp_dec(p_buffer, length, &result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_gattc_attr_info_discover
#define _sd_ble_gattc_attr_info_discover sd_ble_gattc_attr_info_discover
#endif
uint32_t _sd_ble_gattc_attr_info_discover(uint16_t conn_handle,
ble_gattc_handle_range_t const * const p_handle_range)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
const uint32_t err_code = ble_gattc_attr_info_discover_req_enc(conn_handle,
p_handle_range,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
gattc_attr_info_discover_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ble_gattc_write BLE command.
*
* Callback for decoding the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t gattc_exchange_mtu_request_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = ble_gattc_exchange_mtu_request_rsp_dec(p_buffer, length, &result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_gattc_exchange_mtu_request
#define _sd_ble_gattc_exchange_mtu_request sd_ble_gattc_exchange_mtu_request
#endif
uint32_t _sd_ble_gattc_exchange_mtu_request(uint16_t conn_handle,
uint16_t client_rx_mtu)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
const uint32_t err_code = ble_gattc_exchange_mtu_request_req_enc(conn_handle,
client_rx_mtu,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
gattc_exchange_mtu_request_rsp_dec);
}

View File

@@ -0,0 +1,773 @@
/**
* 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_gatts.h"
#include <stdint.h>
#include "ble_serialization.h"
#include "ser_sd_transport.h"
#include "ble_gatts_app.h"
#include "app_error.h"
//Pointer for sd calls output params
static void * mp_out_params[3];
static void tx_buf_alloc(uint8_t * * p_data, uint16_t * p_len)
{
uint32_t err_code;
do
{
err_code = ser_sd_transport_tx_alloc(p_data, p_len);
}
while (err_code != NRF_SUCCESS);
*p_data[0] = SER_PKT_TYPE_CMD;
*p_len -= 1;
}
/**@brief Command response callback function for @ref sd_ble_gatts_sys_attr_set BLE command.
*
* Callback for decoding the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t gatts_sys_attr_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = ble_gatts_sys_attr_set_rsp_dec(p_buffer, length, &result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_gatts_sys_attr_set
#define _sd_ble_gatts_sys_attr_set sd_ble_gatts_sys_attr_set
#endif
uint32_t _sd_ble_gatts_sys_attr_set(uint16_t conn_handle,
uint8_t const * const p_sys_attr_data,
uint16_t len,
uint32_t flags)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
const uint32_t err_code = ble_gatts_sys_attr_set_req_enc(conn_handle,
p_sys_attr_data,
len,
flags,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
gatts_sys_attr_set_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ble_gatts_hvx BLE command.
*
* Callback for decoding the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t gatts_hvx_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = ble_gatts_hvx_rsp_dec(p_buffer, length, &result_code,
(uint16_t * *)&mp_out_params[0]);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_gatts_hvx
#define _sd_ble_gatts_hvx sd_ble_gatts_hvx
#endif
uint32_t _sd_ble_gatts_hvx(uint16_t conn_handle, ble_gatts_hvx_params_t const * const p_hvx_params)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
mp_out_params[0] = (p_hvx_params) ? p_hvx_params->p_len : NULL;
const uint32_t err_code = ble_gatts_hvx_req_enc(conn_handle,
p_hvx_params,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
gatts_hvx_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ble_gatts_service_add BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t gatts_service_add_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code =
ble_gatts_service_add_rsp_dec(p_buffer,
length,
(uint16_t *)mp_out_params[0],
&result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_gatts_service_add
#define _sd_ble_gatts_service_add sd_ble_gatts_service_add
#endif
uint32_t _sd_ble_gatts_service_add(uint8_t type,
ble_uuid_t const * const p_uuid,
uint16_t * const p_handle)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
mp_out_params[0] = p_handle;
const uint32_t err_code = ble_gatts_service_add_req_enc(type,
p_uuid,
p_handle,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
gatts_service_add_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ble_gatts_service_add BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t gatts_service_changed_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code = NRF_SUCCESS;
const uint32_t err_code = ble_gatts_service_changed_rsp_dec(p_buffer,
length,
&result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_gatts_service_changed
#define _sd_ble_gatts_service_changed sd_ble_gatts_service_changed
#endif
uint32_t _sd_ble_gatts_service_changed(uint16_t conn_handle,
uint16_t start_handle,
uint16_t end_handle)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
const uint32_t err_code = ble_gatts_service_changed_req_enc(conn_handle,
start_handle,
end_handle,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
gatts_service_changed_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ble_gatts_include_add BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t gatts_include_add_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code = NRF_SUCCESS;
const uint32_t err_code =
ble_gatts_include_add_rsp_dec(p_buffer,
length,
(uint16_t *) mp_out_params[0],
&result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_gatts_include_add
#define _sd_ble_gatts_include_add sd_ble_gatts_include_add
#endif
uint32_t _sd_ble_gatts_include_add(uint16_t service_handle,
uint16_t inc_serv_handle,
uint16_t * const p_include_handle)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
mp_out_params[0] = p_include_handle;
const uint32_t err_code = ble_gatts_include_add_req_enc(service_handle,
inc_serv_handle,
p_include_handle,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
gatts_include_add_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ble_gatts_characteristic_add BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t gatts_characteristic_add_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = ble_gatts_characteristic_add_rsp_dec(
p_buffer,
length,
(uint16_t * *)&mp_out_params[0],
&result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_gatts_characteristic_add
#define _sd_ble_gatts_characteristic_add sd_ble_gatts_characteristic_add
#endif
uint32_t _sd_ble_gatts_characteristic_add(uint16_t service_handle,
ble_gatts_char_md_t const * const p_char_md,
ble_gatts_attr_t const * const p_attr_char_value,
ble_gatts_char_handles_t * const p_handles)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
mp_out_params[0] = p_handles;
const uint32_t err_code = ble_gatts_characteristic_add_req_enc(service_handle,
p_char_md,
p_attr_char_value,
p_handles,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
gatts_characteristic_add_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ble_gatts_descriptor_add BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t gatts_descriptor_add_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code = NRF_SUCCESS;
const uint32_t err_code =
ble_gatts_descriptor_add_rsp_dec(p_buffer,
length,
(uint16_t *) mp_out_params[0],
&result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_gatts_descriptor_add
#define _sd_ble_gatts_descriptor_add sd_ble_gatts_descriptor_add
#endif
uint32_t _sd_ble_gatts_descriptor_add(uint16_t char_handle,
ble_gatts_attr_t const * const p_attr,
uint16_t * const p_handle)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
mp_out_params[0] = p_handle;
const uint32_t err_code = ble_gatts_descriptor_add_req_enc(char_handle,
p_attr,
p_handle,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
gatts_descriptor_add_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ble_gatts_rw_authorize_reply BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t gatts_rw_authorize_reply_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code = NRF_SUCCESS;
const uint32_t err_code = ble_gatts_rw_authorize_reply_rsp_dec(p_buffer,
length,
&result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_gatts_rw_authorize_reply
#define _sd_ble_gatts_rw_authorize_reply sd_ble_gatts_rw_authorize_reply
#endif
uint32_t _sd_ble_gatts_rw_authorize_reply(
uint16_t conn_handle,
ble_gatts_rw_authorize_reply_params_t const * const
p_rw_authorize_reply_params)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
const uint32_t err_code = ble_gatts_rw_authorize_reply_req_enc(conn_handle,
p_rw_authorize_reply_params,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
gatts_rw_authorize_reply_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ble_gatts_value_get BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t gatts_value_get_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = ble_gatts_value_get_rsp_dec(p_buffer,
length,
(ble_gatts_value_t *)mp_out_params[0],
&result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_gatts_value_get
#define _sd_ble_gatts_value_get sd_ble_gatts_value_get
#endif
uint32_t _sd_ble_gatts_value_get(uint16_t conn_handle,
uint16_t handle,
ble_gatts_value_t * p_value)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
mp_out_params[0] = p_value;
const uint32_t err_code = ble_gatts_value_get_req_enc(conn_handle,
handle,
p_value,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
gatts_value_get_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ble_gatts_value_set BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t gatts_value_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = ble_gatts_value_set_rsp_dec(
p_buffer,
length,
(ble_gatts_value_t *)mp_out_params[0],
&result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_gatts_value_set
#define _sd_ble_gatts_value_set sd_ble_gatts_value_set
#endif
uint32_t _sd_ble_gatts_value_set(uint16_t conn_handle,
uint16_t handle,
ble_gatts_value_t * p_value)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
mp_out_params[0] = p_value;
const uint32_t err_code = ble_gatts_value_set_req_enc(conn_handle,
handle,
p_value,
&(p_buffer[1]),
&buffer_length);
//@note: Should never fail.
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
gatts_value_set_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ble_gatts_sys_attr_get BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t gatts_sys_attr_get_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = ble_gatts_sys_attr_get_rsp_dec(
p_buffer,
length,
(uint8_t * *) &mp_out_params[0],
(uint16_t * *) &mp_out_params[1],
&result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_gatts_sys_attr_get
#define _sd_ble_gatts_sys_attr_get sd_ble_gatts_sys_attr_get
#endif
uint32_t _sd_ble_gatts_sys_attr_get(uint16_t conn_handle,
uint8_t * const p_sys_attr_data,
uint16_t * const p_len,
uint32_t flags)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
mp_out_params[0] = p_sys_attr_data;
mp_out_params[1] = p_len;
const uint32_t err_code = ble_gatts_sys_attr_get_req_enc(conn_handle,
p_sys_attr_data,
p_len,
flags,
&(p_buffer[1]),
&buffer_length);
//@note: Should never fail.
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
gatts_sys_attr_get_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ble_gatts_attr_get BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t gatts_attr_get_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = ble_gatts_attr_get_rsp_dec(
p_buffer,
length,
(ble_uuid_t **)&mp_out_params[0],
(ble_gatts_attr_md_t **)&mp_out_params[1],
&result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_gatts_attr_get
#define _sd_ble_gatts_attr_get sd_ble_gatts_attr_get
#endif
uint32_t _sd_ble_gatts_attr_get(uint16_t handle,
ble_uuid_t * p_uuid,
ble_gatts_attr_md_t * p_md)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
mp_out_params[0] = p_uuid;
mp_out_params[1] = p_md;
const uint32_t err_code = ble_gatts_attr_get_req_enc(handle,
p_uuid,
p_md,
&(p_buffer[1]),
&buffer_length);
//@note: Should never fail.
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
gatts_attr_get_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ble_gatts_initial_user_handle_get BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t gatts_initial_user_handle_get_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = ble_gatts_initial_user_handle_get_rsp_dec(
p_buffer,
length,
(uint16_t **)&mp_out_params[0],
&result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_gatts_initial_user_handle_get
#define _sd_ble_gatts_initial_user_handle_get sd_ble_gatts_initial_user_handle_get
#endif
uint32_t _sd_ble_gatts_initial_user_handle_get(uint16_t * p_handle)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
mp_out_params[0] = p_handle;
const uint32_t err_code = ble_gatts_initial_user_handle_get_req_enc(p_handle,
&(p_buffer[1]),
&buffer_length);
//@note: Should never fail.
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
gatts_initial_user_handle_get_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ble_gatts_exchange_mtu_reply BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t gatts_exchange_mtu_reply_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = ble_gatts_exchange_mtu_reply_rsp_dec(
p_buffer,
length,
&result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_gatts_exchange_mtu_reply
#define _sd_ble_gatts_exchange_mtu_reply sd_ble_gatts_exchange_mtu_reply
#endif
uint32_t _sd_ble_gatts_exchange_mtu_reply(uint16_t conn_handle, uint16_t server_rx_mtu)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
const uint32_t err_code = ble_gatts_exchange_mtu_reply_req_enc(conn_handle,
server_rx_mtu,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
gatts_exchange_mtu_reply_rsp_dec);
}

View File

@@ -0,0 +1,453 @@
/**
* 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_gap.h"
#include <stdint.h>
#include "ble_serialization.h"
#include "ser_sd_transport.h"
#include "ble_l2cap_app.h"
#include "app_error.h"
#if defined(NRF_SD_BLE_API_VERSION) && ((NRF_SD_BLE_API_VERSION < 4) || (NRF_SD_BLE_API_VERSION >=5))
static void tx_buf_alloc(uint8_t * * p_data, uint16_t * p_len)
{
uint32_t err_code;
do
{
err_code = ser_sd_transport_tx_alloc(p_data, p_len);
}
while (err_code != NRF_SUCCESS);
*p_data[0] = SER_PKT_TYPE_CMD;
*p_len -= 1;
}
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
/**@brief Command response callback function for @ref ble_l2cap_cid_register_req_enc BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t l2cap_cid_register_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code =
ble_l2cap_cid_register_rsp_dec(p_buffer,
length,
&result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_l2cap_cid_register
#define _sd_ble_l2cap_cid_register sd_ble_l2cap_cid_register
#endif
uint32_t _sd_ble_l2cap_cid_register(uint16_t cid)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
const uint32_t err_code = ble_l2cap_cid_register_req_enc(cid,
&(p_buffer[1]),
&buffer_length);
//@note: Should never fail.
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
l2cap_cid_register_rsp_dec);
}
/**@brief Command response callback function for @ref ble_l2cap_cid_unregister_req_enc BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t l2cap_cid_unregister_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code =
ble_l2cap_cid_unregister_rsp_dec(p_buffer,
length,
&result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_l2cap_cid_unregister
#define _sd_ble_l2cap_cid_unregister sd_ble_l2cap_cid_unregister
#endif
uint32_t _sd_ble_l2cap_cid_unregister(uint16_t cid)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
const uint32_t err_code = ble_l2cap_cid_unregister_req_enc(cid,
&(p_buffer[1]),
&buffer_length);
//@note: Should never fail.
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
l2cap_cid_unregister_rsp_dec);
}
/**@brief Command response callback function for @ref ble_l2cap_tx_req_enc BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t l2cap_tx_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code =
ble_l2cap_tx_rsp_dec(p_buffer,
length,
&result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_l2cap_tx
#define _sd_ble_l2cap_tx sd_ble_l2cap_tx
#endif
uint32_t _sd_ble_l2cap_tx(uint16_t conn_handle,
ble_l2cap_header_t const * const p_header,
uint8_t const * const p_data)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
const uint32_t err_code = ble_l2cap_tx_req_enc(conn_handle, p_header, p_data,
&(p_buffer[1]),
&buffer_length);
//@note: Should never fail.
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
l2cap_tx_rsp_dec);
}
#endif
#if NRF_SD_BLE_API_VERSION >= 5
static void * mp_out_params[1];
/**@brief Command response callback function for @ref ble_l2cap_ch_setup_req_enc BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t l2cap_ch_setup_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code =
ble_l2cap_ch_setup_rsp_dec(p_buffer,
length,
(uint16_t *)mp_out_params[0],
&result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_l2cap_ch_setup
#define _sd_ble_l2cap_ch_setup sd_ble_l2cap_ch_setup
#endif
uint32_t _sd_ble_l2cap_ch_setup(uint16_t conn_handle,
uint16_t * p_local_cid,
ble_l2cap_ch_setup_params_t const *p_params)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
mp_out_params[0] = p_local_cid;
const uint32_t err_code = ble_l2cap_ch_setup_req_enc(conn_handle, p_local_cid, p_params,
&(p_buffer[1]),
&buffer_length);
//@note: Should never fail.
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
l2cap_ch_setup_rsp_dec);
}
/**@brief Command response callback function for @ref ble_l2cap_ch_release_req_enc BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t l2cap_ch_release_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code =
ble_l2cap_ch_release_rsp_dec(p_buffer,
length,
&result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_l2cap_ch_release
#define _sd_ble_l2cap_ch_release sd_ble_l2cap_ch_release
#endif
uint32_t _sd_ble_l2cap_ch_release(uint16_t conn_handle,
uint16_t local_cid)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
const uint32_t err_code = ble_l2cap_ch_release_req_enc(conn_handle, local_cid,
&(p_buffer[1]),
&buffer_length);
//@note: Should never fail.
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
l2cap_ch_release_rsp_dec);
}
/**@brief Command response callback function for @ref ble_l2cap_ch_rx_req_enc BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t l2cap_ch_rx_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code =
ble_l2cap_ch_rx_rsp_dec(p_buffer,
length,
&result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_l2cap_ch_rx
#define _sd_ble_l2cap_ch_rx sd_ble_l2cap_ch_rx
#endif
uint32_t _sd_ble_l2cap_ch_rx(uint16_t conn_handle, uint16_t local_cid, ble_data_t const *p_sdu_buf)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
const uint32_t err_code = ble_l2cap_ch_rx_req_enc(conn_handle, local_cid, p_sdu_buf,
&(p_buffer[1]),
&buffer_length);
//@note: Should never fail.
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
l2cap_ch_rx_rsp_dec);
}
/**@brief Command response callback function for @ref ble_l2cap_ch_tx_req_enc BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t l2cap_ch_tx_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code =
ble_l2cap_ch_tx_rsp_dec(p_buffer,
length,
&result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_l2cap_ch_tx
#define _sd_ble_l2cap_ch_tx sd_ble_l2cap_ch_tx
#endif
uint32_t _sd_ble_l2cap_ch_tx(uint16_t conn_handle, uint16_t local_cid, ble_data_t const *p_sdu_buf)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
const uint32_t err_code = ble_l2cap_ch_tx_req_enc(conn_handle, local_cid, p_sdu_buf,
&(p_buffer[1]),
&buffer_length);
//@note: Should never fail.
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
l2cap_ch_tx_rsp_dec);
}
/**@brief Command response callback function for @ref ble_l2cap_ch_flow_control_req_enc BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t l2cap_ch_flow_control_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code =
ble_l2cap_ch_flow_control_rsp_dec(p_buffer,
length,
(uint16_t *)mp_out_params[0],
&result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
#ifndef _sd_ble_l2cap_ch_flow_control
#define _sd_ble_l2cap_ch_flow_control sd_ble_l2cap_ch_flow_control
#endif
uint32_t _sd_ble_l2cap_ch_flow_control(uint16_t conn_handle,
uint16_t local_cid,
uint16_t credits,
uint16_t *p_credits)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
mp_out_params[0] = p_credits;
const uint32_t err_code = ble_l2cap_ch_flow_control_req_enc(conn_handle, local_cid, credits, p_credits,
&(p_buffer[1]),
&buffer_length);
//@note: Should never fail.
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
l2cap_ch_flow_control_rsp_dec);
}
#endif

View File

@@ -0,0 +1,171 @@
/**
* 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 <stdint.h>
#include <string.h>
#include "ser_sd_transport.h"
#include "nrf_soc_app.h"
#include "nrf_error_soc.h"
#include "app_error.h"
#include "ble_serialization.h"
#include "ser_app_power_system_off.h"
static void * mp_out_param;
static void tx_buf_alloc(uint8_t * * p_data, uint16_t * p_len)
{
uint32_t err_code;
do
{
err_code = ser_sd_transport_tx_alloc(p_data, p_len);
}
while (err_code != NRF_SUCCESS);
*p_data[0] = SER_PKT_TYPE_CMD;
*p_len -= 1;
}
uint32_t sd_power_system_off(void)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
const uint32_t err_code = power_system_off_req_enc(&(p_buffer[1]), &buffer_length);
APP_ERROR_CHECK(err_code);
ser_app_power_system_off_set();
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
NULL);
}
/**@brief Command response callback function for @ref sd_temp_get BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t mw_temp_get_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = temp_get_rsp_dec(p_buffer,
length,
&result_code,
(int32_t * *) &mp_out_param);
APP_ERROR_CHECK(err_code);
return result_code;
}
uint32_t sd_temp_get(int32_t * p_temp)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
mp_out_param = p_temp;
const uint32_t err_code = temp_get_req_enc(p_temp,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
mw_temp_get_rsp_dec);
}
/**@brief Command response callback function for @ref sd_ecb_block_encrypt BLE command.
*
* Callback for decoding the output parameters and the command response return code.
*
* @param[in] p_buffer Pointer to begin of command response buffer.
* @param[in] length Length of data in bytes.
*
* @return Decoded command response return code.
*/
static uint32_t mw_ecb_block_encrypt_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
uint32_t result_code;
const uint32_t err_code = ecb_block_encrypt_rsp_dec(p_buffer,
length,
(nrf_ecb_hal_data_t * *)&mp_out_param,
&result_code);
APP_ERROR_CHECK(err_code);
return result_code;
}
uint32_t sd_ecb_block_encrypt(nrf_ecb_hal_data_t * p_ecb_data)
{
uint8_t * p_buffer;
uint32_t buffer_length = 0;
tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length);
mp_out_param = p_ecb_data;
const uint32_t err_code = ecb_block_encrypt_req_enc(p_ecb_data,
&(p_buffer[1]),
&buffer_length);
APP_ERROR_CHECK(err_code);
//@note: Increment buffer length as internally managed packet type field must be included.
return ser_sd_transport_cmd_write(p_buffer,
(++buffer_length),
mw_ecb_block_encrypt_rsp_dec);
}

View File

@@ -0,0 +1,216 @@
/**
* 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 "app_ble_gap_sec_keys.h"
#include "ser_config.h"
#include "nrf_error.h"
#include "nordic_common.h"
#include <stddef.h>
#include <stdbool.h>
#include <string.h>
#if NRF_SD_BLE_API_VERSION >= 6
typedef struct {
bool active;
uint8_t adv_handle;
uint8_t * p_adv_data;
uint8_t * p_scan_rsp_data;
} adv_set_t;
static adv_set_t m_adv_sets[4]; //todo configurable number of adv sets.
static ble_data_t m_scan_data = {0};
static int scan_data_id;
#endif
ser_ble_gap_app_keyset_t m_app_keys_table[SER_MAX_CONNECTIONS];
#if NRF_SD_BLE_API_VERSION >= 6
static void *m_ble_gap_adv_buf_addr_storage[8];
#endif
void app_ble_gap_sec_keys_init(void)
{
#if NRF_SD_BLE_API_VERSION >= 6
memset(m_ble_gap_adv_buf_addr_storage, 0, sizeof(m_ble_gap_adv_buf_addr_storage));
memset(&m_scan_data, 0, sizeof(m_scan_data));
memset(m_adv_sets, 0, sizeof(m_adv_sets));
#endif
memset(m_app_keys_table, 0, sizeof(m_app_keys_table));
}
uint32_t app_ble_gap_sec_context_create(uint16_t conn_handle, 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_app_keys_table[i].conn_active )
{
m_app_keys_table[i].conn_active = 1;
m_app_keys_table[i].conn_handle = conn_handle;
*p_index = i;
err_code = NRF_SUCCESS;
break;
}
}
return err_code;
}
uint32_t app_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_app_keys_table[i].conn_handle == conn_handle )
{
m_app_keys_table[i].conn_active = 0;
err_code = NRF_SUCCESS;
break;
}
}
return err_code;
}
uint32_t app_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_app_keys_table[i].conn_handle == conn_handle) && (m_app_keys_table[i].conn_active == 1) )
{
*p_index = i;
err_code = NRF_SUCCESS;
break;
}
}
return err_code;
}
#if NRF_SD_BLE_API_VERSION >= 6
int app_ble_gap_adv_buf_register(void * p_buf)
{
uint32_t i;
if (p_buf == NULL)
{
return 0;
}
for (i = 0; i < ARRAY_SIZE(m_ble_gap_adv_buf_addr_storage); i++)
{
if ((m_ble_gap_adv_buf_addr_storage[i] == NULL) ||
(m_ble_gap_adv_buf_addr_storage[i] == p_buf))
{
m_ble_gap_adv_buf_addr_storage[i] = p_buf;
return i+1;
}
}
return -1;
}
void *app_ble_gap_adv_buf_unregister(int id, bool event_context)
{
(void)event_context;
if (id == 0)
{
return NULL;
}
void * ret = m_ble_gap_adv_buf_addr_storage[id-1];
m_ble_gap_adv_buf_addr_storage[id-1] = NULL;
return ret;
}
void app_ble_gap_adv_buf_addr_unregister(void * p_buf, bool event_context)
{
(void)event_context;
uint32_t i;
if (p_buf == NULL)
{
return;
}
for (i = 0; i < ARRAY_SIZE(m_ble_gap_adv_buf_addr_storage); i++)
{
if (m_ble_gap_adv_buf_addr_storage[i] == p_buf)
{
m_ble_gap_adv_buf_addr_storage[i] = NULL;
}
}
}
void app_ble_gap_scan_data_set(uint8_t * p_scan_data)
{
uint32_t i;
for (i = 0; i < ARRAY_SIZE(m_ble_gap_adv_buf_addr_storage); i++)
{
if (m_ble_gap_adv_buf_addr_storage[i] == p_scan_data)
{
scan_data_id = i+1;
return;
}
}
scan_data_id = 0;
}
void app_ble_gap_scan_data_unset(bool free)
{
if (scan_data_id)
{
if (free)
{
(void)app_ble_gap_adv_buf_unregister(scan_data_id, false);
}
scan_data_id = 0;
}
}
#endif /* NRF_SD_BLE_API_VERSION >= 6 */

View File

@@ -0,0 +1,120 @@
/**
* 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 _APP_BLE_GAP_SEC_KEYS_H
#define _APP_BLE_GAP_SEC_KEYS_H
/**@file
*
* @defgroup app_ble_gap_sec_keys GAP Functions for managing memory for security keys in the application device.
* @{
* @ingroup ser_app_s130_codecs
*
* @brief GAP Application auxiliary functions for synchronizing the GAP security keys with the ones stored in the connectivity device.
*/
#include "ble_gap.h"
#include "ble_types.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 store them 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.*/
} ser_ble_gap_app_keyset_t;
void app_ble_gap_sec_keys_init(void);
/**@brief Allocates the instance in m_app_keys_table[] for storage of encryption keys.
*
* @param[in] conn_handle conn_handle
* @param[out] p_index Pointer to the index of the allocated instance.
*
* @retval NRF_SUCCESS Context allocated.
* @retval NRF_ERROR_NO_MEM No free instance available.
*/
uint32_t app_ble_gap_sec_context_create(uint16_t conn_handle, uint32_t *p_index);
/**@brief Release 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 app_ble_gap_sec_context_destroy(uint16_t conn_handle);
/**@brief Finds index of instance identified by a connection handle in m_app_keys_table[].
*
* @param[in] conn_handle conn_handle
*
* @param[out] p_index Pointer to the index of the entry in the context table corresponding to the given conn_handle.
*
* @retval NRF_SUCCESS Context found.
* @retval NRF_ERROR_NOT_FOUND Instance with conn_handle not found.
*/
uint32_t app_ble_gap_sec_context_find(uint16_t conn_handle, uint32_t *p_index);
/** @} */
#if NRF_SD_BLE_API_VERSION >= 6
int app_ble_gap_adv_buf_register(void * p_buf);
void *app_ble_gap_adv_buf_unregister(int id, bool event_context);
void app_ble_gap_adv_buf_addr_unregister(void * p_buf, bool event_context);
void app_ble_gap_scan_data_set(uint8_t * p_scan_data);
void app_ble_gap_scan_data_unset(bool free);
#endif
#ifdef __cplusplus
}
#endif
#endif //_APP_BLE_GAP_SEC_KEYS_H

View File

@@ -0,0 +1,101 @@
/**
* 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 "app_ble_user_mem.h"
#include "ser_config.h"
#include "nrf_error.h"
#include <stddef.h>
ser_ble_user_mem_t m_app_user_mem_table[SER_MAX_CONNECTIONS];
uint32_t app_ble_user_mem_context_create(uint16_t conn_handle, 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_app_user_mem_table[i].conn_active )
{
m_app_user_mem_table[i].conn_active = 1;
m_app_user_mem_table[i].conn_handle = conn_handle;
*p_index = i;
err_code = NRF_SUCCESS;
break;
}
}
return err_code;
}
uint32_t app_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_app_user_mem_table[i].conn_handle == conn_handle )
{
m_app_user_mem_table[i].conn_active = 0;
err_code = NRF_SUCCESS;
break;
}
}
return err_code;
}
uint32_t app_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_app_user_mem_table[i].conn_handle == conn_handle) && (m_app_user_mem_table[i].conn_active == 1) )
{
*p_index = i;
err_code = NRF_SUCCESS;
break;
}
}
return err_code;
}

View File

@@ -0,0 +1,109 @@
/**
* 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 _APP_BLE_USER_MEM_H
#define _APP_BLE_USER_MEM_H
/**@file
*
* @defgroup app_ble_user_mem Functions for managing memory for user memory request in the application device.
* @{
* @ingroup ser_app_s130_codecs
*
* @brief Application auxiliary functions for synchronizing user memory with the one stored in the connectivity device.
*/
#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 user memory to connection instances and store it 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. */
} ser_ble_user_mem_t;
/**@brief Allocates instance in m_user_mem_table[] for storage.
*
* @param[in] conn_handle conn_handle
* @param[out] p_index Pointer to the index of the allocated instance.
*
* @retval NRF_SUCCESS Context allocated.
* @retval NRF_ERROR_NO_MEM No free instance available.
*/
uint32_t app_ble_user_mem_context_create(uint16_t conn_handle, uint32_t *p_index);
/**@brief Release 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 app_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 the entry in the context table corresponding to the given conn_handle.
*
* @retval NRF_SUCCESS Context found.
* @retval NRF_ERROR_NOT_FOUND Instance with conn_handle not found.
*/
uint32_t app_ble_user_mem_context_find(uint16_t conn_handle, uint32_t *p_index);
/** @} */
#ifdef __cplusplus
}
#endif
#endif //_APP_BLE_USER_MEM_H

View File

@@ -0,0 +1,513 @@
/**
* 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_app.h"
#include "ble_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 "cond_field_serialization.h"
#include "app_util.h"
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
uint32_t ble_enable_req_enc(ble_enable_params_t * p_ble_enable_params,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_ENABLE);
SER_PUSH_COND(p_ble_enable_params, ble_enable_params_t_enc);
SER_REQ_ENC_END;
}
#else
uint32_t ble_enable_req_enc(uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_ENABLE);
SER_REQ_ENC_END;
}
#endif
uint32_t ble_enable_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code)
{
SER_RSP_DEC_RESULT_ONLY(SD_BLE_ENABLE);
}
uint32_t ble_opt_get_req_enc(uint32_t opt_id,
ble_opt_t const * const p_opt,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_OPT_GET);
SER_PUSH_uint32(&opt_id);
SER_PUSH_COND(p_opt, NULL);
SER_REQ_ENC_END;
}
uint32_t ble_opt_get_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_opt_id,
ble_opt_t * const p_opt,
uint32_t * const p_result_code)
{
SER_RSP_DEC_BEGIN(SD_BLE_OPT_GET);
SER_PULL_uint32(p_opt_id);
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 = &(p_opt->common_opt.conn_bw);
break;
#endif
case BLE_COMMON_OPT_PA_LNA:
fp_decoder = ble_common_opt_pa_lna_t_dec;
p_struct = &(p_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 = &(p_opt->common_opt.conn_evt_ext);
break;
case BLE_GAP_OPT_CH_MAP:
fp_decoder = ble_gap_opt_ch_map_t_dec;
p_struct =&(p_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 = &(p_opt->gap_opt.local_conn_latency);
break;
case BLE_GAP_OPT_PASSKEY:
fp_decoder = ble_gap_opt_passkey_t_dec;
p_struct = &(p_opt->gap_opt.passkey);
break;
case BLE_GAP_OPT_AUTH_PAYLOAD_TIMEOUT:
fp_decoder = ble_gap_opt_auth_payload_timeout_t_dec;
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_decoder = ble_gap_opt_ext_len_t_dec;
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_decoder = ble_gap_opt_scan_req_report_t_dec;
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_decoder = ble_gap_opt_compat_mode_t_dec;
p_struct = &(p_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 = &(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_decoder = ble_gap_opt_compat_mode_2_t_dec;
p_struct = &(p_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_RSP_DEC_END;
}
uint32_t ble_opt_set_req_enc(uint32_t const opt_id,
ble_opt_t const * const p_opt,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_OPT_SET);
SER_PUSH_uint32(&opt_id);
field_encoder_handler_t fp_encoder = NULL;
void const * p_struct = NULL;
SER_PUSH_COND(p_opt, NULL);
if (p_opt)
{
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
case BLE_GAP_OPT_SLAVE_LATENCY_DISABLE:
fp_encoder = ble_gap_opt_slave_latency_disable_t_enc;
p_struct = &(p_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_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_REQ_ENC_END;
}
uint32_t ble_opt_set_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code)
{
SER_RSP_DEC_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_enc(uint16_t conn_handle,
uint8_t const * const p_count,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_TX_PACKET_COUNT_GET);
SER_PUSH_uint16(&conn_handle);
SER_PUSH_COND(p_count, NULL);
SER_REQ_ENC_END;
}
uint32_t ble_tx_packet_count_get_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint8_t * * const pp_count,
uint32_t * const p_result_code)
{
SER_RSP_DEC_BEGIN(SD_BLE_TX_PACKET_COUNT_GET);
SER_PULL_COND(pp_count, uint8_t_dec);
SER_RSP_DEC_END;
}
#endif
uint32_t ble_user_mem_reply_req_enc(uint16_t conn_handle,
ble_user_mem_block_t const * p_block,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_USER_MEM_REPLY);
SER_PUSH_uint16(&conn_handle);
SER_PUSH_COND(p_block, ble_user_mem_block_t_enc);
SER_REQ_ENC_END;
}
uint32_t ble_user_mem_reply_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code)
{
SER_RSP_DEC_RESULT_ONLY(SD_BLE_USER_MEM_REPLY);
}
uint32_t ble_uuid_decode_req_enc(uint8_t uuid_le_len,
uint8_t const * const p_uuid_le,
ble_uuid_t * const p_uuid,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_UUID_DECODE);
SER_PUSH_len8data(p_uuid_le, uuid_le_len);
SER_PUSH_COND(p_uuid, NULL);
SER_REQ_ENC_END;
}
uint32_t ble_uuid_decode_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_uuid_t * * const pp_uuid,
uint32_t * const p_result_code)
{
SER_RSP_DEC_BEGIN(SD_BLE_UUID_DECODE);
SER_PULL_COND(pp_uuid, ble_uuid_t_dec);
SER_RSP_DEC_END;
}
uint32_t ble_uuid_encode_req_enc(ble_uuid_t const * const p_uuid,
uint8_t const * const p_uuid_le_len,
uint8_t const * const p_uuid_le,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_UUID_ENCODE);
SER_PUSH_COND(p_uuid, ble_uuid_t_enc);
SER_PUSH_COND(p_uuid_le_len, NULL);
SER_PUSH_COND(p_uuid_le, NULL);
SER_REQ_ENC_END;
}
uint32_t ble_uuid_encode_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint8_t * const p_uuid_le_len,
uint8_t * const p_uuid_le,
uint32_t * const p_result_code)
{
SER_RSP_DEC_BEGIN(SD_BLE_UUID_ENCODE);
uint8_t uuid_le_len;
SER_PULL_uint8(&uuid_le_len);
if (p_uuid_le_len)
{
*p_uuid_le_len = uuid_le_len;
if (p_uuid_le)
{
SER_PULL_uint8array(p_uuid_le, uuid_le_len);
}
}
SER_RSP_DEC_END;
}
uint32_t ble_uuid_vs_add_req_enc(ble_uuid128_t const * const p_vs_uuid,
uint8_t * const p_uuid_type,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_UUID_VS_ADD);
SER_PUSH_COND(p_vs_uuid, ble_uuid128_t_enc);
SER_PUSH_COND(p_uuid_type, NULL);
SER_REQ_ENC_END;
}
uint32_t ble_uuid_vs_add_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint8_t * * const pp_uuid_type,
uint32_t * const p_result_code)
{
SER_RSP_DEC_BEGIN(SD_BLE_UUID_VS_ADD);
SER_ASSERT_NOT_NULL(pp_uuid_type);
SER_PULL_COND(pp_uuid_type, uint8_t_dec);
SER_RSP_DEC_END;
}
uint32_t ble_version_get_req_enc(ble_version_t const * const p_version,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_VERSION_GET);
SER_PUSH_COND(p_version, NULL);
SER_REQ_ENC_END;
}
uint32_t ble_version_get_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_version_t * p_version,
uint32_t * const p_result_code)
{
SER_RSP_DEC_BEGIN(SD_BLE_VERSION_GET);
SER_PULL_FIELD(p_version, ble_version_t_dec);
SER_RSP_DEC_END;
}
#if NRF_SD_BLE_API_VERSION >= 4
uint32_t ble_cfg_set_req_enc(uint32_t cfg_id,
ble_cfg_t const * p_cfg,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_CFG_SET);
SER_PUSH_uint32(&cfg_id);
field_encoder_handler_t fp_encoder = NULL;
void const * p_struct = NULL;
SER_PUSH_COND(p_cfg, NULL);
if (p_cfg)
{
switch (cfg_id)
{
case BLE_CONN_CFG_GAP:
fp_encoder = ble_gap_conn_cfg_t_enc;
p_struct = &(p_cfg->conn_cfg.params.gap_conn_cfg);
break;
case BLE_CONN_CFG_GATTC:
fp_encoder = ble_gattc_conn_cfg_t_enc;
p_struct = &(p_cfg->conn_cfg.params.gattc_conn_cfg);
break;
case BLE_CONN_CFG_GATTS:
fp_encoder = ble_gatts_conn_cfg_t_enc;
p_struct = &(p_cfg->conn_cfg.params.gatts_conn_cfg);
break;
case BLE_CONN_CFG_GATT:
fp_encoder = ble_gatt_conn_cfg_t_enc;
p_struct = &(p_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_encoder = ble_l2cap_conn_cfg_t_enc;
p_struct = &(p_cfg->conn_cfg.params.l2cap_conn_cfg);
break;
#endif
case BLE_COMMON_CFG_VS_UUID:
fp_encoder = ble_common_cfg_vs_uuid_t_enc;
p_struct = &(p_cfg->common_cfg.vs_uuid_cfg);
break;
case BLE_GAP_CFG_ROLE_COUNT:
fp_encoder = ble_gap_cfg_role_count_t_enc;
p_struct = &(p_cfg->gap_cfg.role_count_cfg);
break;
case BLE_GAP_CFG_DEVICE_NAME:
fp_encoder = ble_gap_cfg_device_name_t_enc;
p_struct = &(p_cfg->gap_cfg.device_name_cfg);
break;
case BLE_GATTS_CFG_SERVICE_CHANGED:
fp_encoder = ble_gatts_cfg_service_changed_t_enc;
p_struct = &(p_cfg->gatts_cfg.service_changed);
break;
case BLE_GATTS_CFG_ATTR_TAB_SIZE:
fp_encoder = ble_gatts_cfg_attr_tab_size_t_enc;
p_struct = &(p_cfg->gatts_cfg.attr_tab_size);
break;
}
if (cfg_id >= BLE_CONN_CFG_BASE && cfg_id <= BLE_CONN_CFG_GATT)
{
SER_PUSH_uint8(&p_cfg->conn_cfg.conn_cfg_tag);
}
SER_PUSH_FIELD(p_struct, fp_encoder);
}
SER_REQ_ENC_END;
}
uint32_t ble_cfg_set_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code)
{
SER_RSP_DEC_RESULT_ONLY(SD_BLE_CFG_SET);
}
#endif //NRF_SD_BLE_API_VERSION >= 4

View File

@@ -0,0 +1,523 @@
/**
* 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_APP_H__
#define BLE_APP_H__
/**
* @addtogroup ser_codecs Serialization codecs
* @ingroup ble_sdk_lib_serialization
*/
/**
* @addtogroup ser_app_s130_codecs Application codecs for S132 and S140
* @ingroup ser_codecs_app
*/
/**@file
*
* @defgroup ble_app Application command request encoders and command response decoders
* @{
* @ingroup ser_app_s130_codecs
*
* @brief Application command request encoders and command response decoders.
*/
#include "ble.h"
#ifdef __cplusplus
extern "C" {
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
/**
* @brief Encodes @ref sd_ble_tx_packet_count_get command request.
*
* @sa @ref ble_tx_packet_count_get_rsp_dec for command response decoder.
*
* @param[in] conn_handle Connection handle.
* @param[in] p_count Pointer to count value to be filled.
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
* \c out: Length of the encoded command packet.
*
* @note \p p_count will not be updated by the command
* request encoder. Updated values are set by @ref ble_tx_packet_count_get_rsp_dec.
*
* @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_req_enc(uint16_t conn_handle,
uint8_t const * const p_count,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Decodes a response to @ref sd_ble_tx_packet_count_get command.
*
* @sa @ref ble_tx_packet_count_get_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to the beginning of a command response packet.
* @param[in] packet_len Length (in bytes) of the response packet.
* @param[out] pp_count Pointer to the pointer to count value.
* @param[out] p_result_code Command result code.
*
* @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. Decoded operation code does not match
* expected operation code.
*/
uint32_t ble_tx_packet_count_get_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint8_t * * const pp_count,
uint32_t * const p_result_code);
#endif
/**@brief Encodes the @ref sd_ble_uuid_encode command request.
*
* @sa @ref ble_uuid_encode_rsp_dec for command response decoder.
*
* @param[in] p_uuid Pointer to a @ref ble_uuid_t structure that will be encoded into bytes.
* @param[in] p_uuid_le_len Size of \p p_uuid_le, if \p p_uuid_le is not NULL
* @param[in] p_uuid_le Pointer to a buffer where the little endian raw UUID bytes(2 or 16)
* will be stored. Can be NULL to calculate the required size.
* @param[in] p_buf Pointer to a buffer where the encoded data command will be returned.
* @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
* \c out: Length of the encoded command packet.
*
* @note \p p_uuid_le_len and \p p_uuid_le will not be updated by the command
* request encoder. Updated values are set by @ref ble_uuid_encode_rsp_dec.
*
* @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_req_enc(ble_uuid_t const * const p_uuid,
uint8_t const * const p_uuid_le_len,
uint8_t const * const p_uuid_le,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes a response to the @ref sd_ble_uuid_encode command.
*
* @sa @ref ble_uuid_encode_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to the beginning of a command response packet.
* @param[in] packet_len Length (in bytes) of a response packet.
* @param[in,out] p_uuid_le_len \c in: Size (in bytes) of \p p_uuid_le buffer.
* \c out: Length of decoded contents of \p p_uuid_le.
* @param[out] p_uuid_le Pointer to a buffer where the encoded UUID will be stored.
* @param[out] p_result_code Command result code.
*
* @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_DATA_SIZE Length of \p p_uuid_le is too small to hold the decoded
* value from response.
* @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match the expected
* operation code.
*/
uint32_t ble_uuid_encode_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint8_t * const p_uuid_le_len,
uint8_t * const p_uuid_le,
uint32_t * const p_result_code);
/**@brief Encodes @ref sd_ble_uuid_decode command request.
*
* @sa @ref ble_uuid_decode_rsp_dec for command response decoder.
*
* @param[in] uuid_le_len Size of \p p_uuid_le if \p p_uuid_le is not NULL.
* @param[in] p_uuid_le Pointer to a buffer where the little endian raw UUID bytes(2 or 16)
* are stored.
* @param[out] p_uuid Pointer to a @ref ble_uuid_t structure were the raw UUID will be decoded.
* @param[in] p_buf Pointer to the buffer where encoded data command will be returned.
* @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
* \c out: Length of the encoded command packet.
*
* @note \p p_uuid will not be updated by the command request encoder.
* Updated values are set by @ref ble_uuid_decode_rsp_dec.
*
* @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_req_enc(uint8_t uuid_le_len,
uint8_t const * const p_uuid_le,
ble_uuid_t * const p_uuid,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes a response to the @ref sd_ble_uuid_decode command.
*
* @sa @ref ble_uuid_decode_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to the beginning of command response packet.
* @param[in] packet_len Length (in bytes) of the response packet.
* @param[out] p_uuid Pointer to a buffer where the decoded UUID will be stored.
* @param[out] p_result_code Command result code.
*
* @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. Decoded operation code does not match the expected
* operation code.
*/
uint32_t ble_uuid_decode_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_uuid_t * * const p_uuid,
uint32_t * const p_result_code);
/**@brief Encodes the @ref sd_ble_uuid_vs_add command request.
*
* @sa @ref ble_uuid_vs_add_rsp_dec for command response decoder.
*
* @param[in] p_vs_uuid Pointer to a @ref ble_uuid128_t structure.
* @param[in] p_uuid_type Pointer to uint8_t where UUID type will be returned.
* @param[in] p_buf Pointer to buffer where the encoded data command will be returned.
* @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
* \c out: Length of encoded command packet.
*
* @note \p p_uuid_type will not be updated by the command request encoder.
* Updated values are set by @ref ble_uuid_vs_add_rsp_dec.
*
* @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_req_enc(ble_uuid128_t const * const p_vs_uuid,
uint8_t * const p_uuid_type,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes response to the @ref sd_ble_uuid_vs_add command.
*
* @sa @ref ble_uuid_vs_add_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to the beginning of command response packet.
* @param[in] packet_len Length (in bytes) of a response packet.
* @param[out] pp_uuid_type Pointer to a pointer to uint8_t where the decoded UUID type will be stored.
* @param[out] p_result_code Command result code.
*
* @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. Decoded operation code does not match expected
* operation code.
*/
uint32_t ble_uuid_vs_add_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint8_t * * const pp_uuid_type,
uint32_t * const p_result_code);
/**@brief Encodes the @ref sd_ble_version_get command request.
*
* @sa @ref ble_version_get_rsp_dec for command response decoder.
*
* @param[in] p_version Pointer to a @ref ble_version_t structure to be filled by the response.
* @param[in] p_buf Pointer to a buffer where the encoded data command will be returned.
* @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
* \c out: Length of encoded command 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_version_get_req_enc(ble_version_t const * const p_version,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes response to the @ref sd_ble_version_get command.
*
* @sa @ref ble_version_get_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to the beginning of a command response packet.
* @param[in] packet_len Length (in bytes) of the response packet.
* @param[out] p_version Pointer to a @ref ble_version_t where the decoded version will be stored.
* @param[out] p_result_code Command result code.
*
* @retval NRF_SUCCESS Version information stored successfully.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold the decoded event.
*/
uint32_t ble_version_get_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_version_t * p_version,
uint32_t * const p_result_code);
/**@brief Encodes the @ref sd_ble_opt_set command request.
*
* @sa @ref ble_opt_set_rsp_dec for command response decoder.
*
* @param[in] opt_id Identifies type of parameter in ble_opt_t union.
* @param[in] p_opt Pointer to the ble_opt_t union.
* @param[in] p_buf Pointer to a buffer where the encoded data command will be returned.
* @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
* \c out: Length of the encoded command 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.
* @retval NRF_ERROR_INVALID_PARAM Invalid opt id.
*/
uint32_t ble_opt_set_req_enc(uint32_t const opt_id,
ble_opt_t const * const p_opt,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes response to the @ref sd_ble_opt_set command.
*
* @sa @ref ble_opt_set_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to the beginning of a command response packet.
* @param[in] packet_len Length (in bytes) of the response packet.
* @param[out] p_result_code Command result code.
*
* @retval NRF_SUCCESS Version information stored successfully.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_opt_set_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code);
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
/**@brief Encodes the @ref sd_ble_enable command request.
*
* @sa @ref ble_enable_rsp_dec for command response decoder.
*
* @param[in] p_ble_enable_params Pointer to the @ref ble_enable_params_t structure.
* @param[in] p_buf Pointer to the buffer where encoded data command will be returned.
* @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
* \c out: Length of the encoded command 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_req_enc(ble_enable_params_t * p_ble_enable_params,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#else
/**@brief Encodes the @ref sd_ble_enable command request.
*
* @sa @ref ble_enable_rsp_dec for command response decoder.
*
* @param[in] p_buf Pointer to the buffer where encoded data command will be returned.
* @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
* \c out: Length of the encoded command 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_req_enc(uint8_t * const p_buf,
uint32_t * const p_buf_len);
#endif
/**@brief Decodes response to the @ref sd_ble_enable command.
*
* @sa @ref ble_enable_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to the beginning of a command response packet.
* @param[in] packet_len Length (in bytes) of the response packet.
* @param[out] p_result_code Command result code.
*
* @retval NRF_SUCCESS Success.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold the decoded event.
*/
uint32_t ble_enable_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code);
/**@brief Encodes the @ref sd_ble_opt_get command request.
*
* @sa @ref ble_opt_get_rsp_dec for command response decoder.
*
* @param[in] opt_id Identifies the type of parameter in the ble_opt_t union.
* @param[in] p_opt Pointer to the @ref ble_opt_t union to be filled by the response.
* @param[in] p_buf Pointer to the buffer where the encoded data command will be returned.
* @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
* \c out: Length of the encoded command 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.
* @retval NRF_ERROR_INVALID_PARAM Invalid opt id.
*/
uint32_t ble_opt_get_req_enc(uint32_t opt_id,
ble_opt_t const * const p_opt,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes response to the @ref sd_ble_opt_get command.
*
* @sa @ref ble_opt_get_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to the beginning of a command response packet.
* @param[in] packet_len Length (in bytes) of the response packet.
* @param[out] p_opt_id Pointer to the decoded opt_id.
* @param[out] p_opt Pointer to the decoded @ref ble_opt_t union.
* @param[out] p_result_code Command result code.
*
* @retval NRF_SUCCESS Opt stored successfully.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold the decoded event.
* @retval NRF_ERROR_INVALID_PARAM Invalid opt id.
*/
uint32_t ble_opt_get_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_opt_id,
ble_opt_t * const p_opt,
uint32_t * const p_result_code);
/**@brief Encodes the @ref sd_ble_user_mem_reply command request.
*
* @sa @ref ble_user_mem_reply_rsp_dec for command response decoder.
*
* @param[in] conn_handle Connection handle.
* @param[in] p_block Pointer to the @ref ble_user_mem_block_t structure.
* @param[in] p_buf Pointer to the buffer where the encoded data command will be returned.
* @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
* \c out: Length of the encoded command 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.
* @retval NRF_ERROR_INVALID_PARAM Invalid opt id.
*/
uint32_t ble_user_mem_reply_req_enc(uint16_t conn_handle,
ble_user_mem_block_t const * p_block,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes response to the @ref sd_ble_user_mem_reply command.
*
* @sa @ref ble_user_mem_reply_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to the beginning of a command response packet.
* @param[in] packet_len Length (in bytes) of the response packet.
* @param[out] p_result_code Command result code.
*
* @retval NRF_SUCCESS Opt stored successfully.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold the decoded event.
* @retval NRF_ERROR_INVALID_PARAM Invalid opt id.
*/
uint32_t ble_user_mem_reply_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code);
#if NRF_SD_BLE_API_VERSION >= 4
/**@brief Encodes the @ref sd_ble_cfg_set command request.
*
* @sa @ref ble_cfg_set_rsp_dec for command response decoder.
*
* @param[in] cfg_id Configuratio id.
* @param[in] p_cfg Pointer to the configuration.
* @param[in] p_buf Pointer to the buffer where the encoded data command will be returned.
* @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
* \c out: Length of the encoded command 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.
* @retval NRF_ERROR_INVALID_PARAM Invalid opt id.
*/
uint32_t ble_cfg_set_req_enc(uint32_t cfg_id,
ble_cfg_t const * p_cfg,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes response to the @ref sd_ble_cfg_set command.
*
* @sa @ref ble_cfg_set_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to the beginning of a command response packet.
* @param[in] packet_len Length (in bytes) of the response packet.
* @param[out] p_result_code Command result code.
*
* @retval NRF_SUCCESS Opt stored successfully.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold the decoded event.
* @retval NRF_ERROR_INVALID_PARAM Invalid opt id.
*/
uint32_t ble_cfg_set_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code);
#endif //NRF_SD_BLE_API_VERSION >= 4
/**@brief Event decoding dispatcher.
*
* The event decoding dispatcher will route the event packet to the correct decoder, which in turn
* decodes the contents of the event and updates the \p p_event struct.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of the event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to the \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, the required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of the decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold the decoded event.
* @retval NRF_ERROR_NOT_FOUND Decoding failure. No event decoder is available.
*/
uint32_t ble_event_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/** @} */
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,326 @@
/**
* 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_serialization.h"
#include "ble_app.h"
#include "ble_evt_app.h"
#include "ble_gap_evt_app.h"
#include "ble_gattc_evt_app.h"
#include "ble_gatts_evt_app.h"
#include "ble_l2cap_evt_app.h"
#include "app_util.h"
uint32_t ble_event_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
uint32_t err_code;
SER_ASSERT_NOT_NULL(p_buf);
SER_ASSERT_NOT_NULL(p_event_len);
SER_ASSERT_LENGTH_LEQ(SER_EVT_HEADER_SIZE, packet_len);
SER_ASSERT_NOT_NULL(p_event);
SER_ASSERT_LENGTH_LEQ(sizeof (ble_evt_hdr_t), *p_event_len);
*p_event_len -= sizeof (ble_evt_hdr_t);
const uint16_t event_id = uint16_decode(&p_buf[SER_EVT_ID_POS]);
const uint8_t * p_sub_buffer = &p_buf[SER_EVT_HEADER_SIZE];
const uint32_t sub_packet_len = packet_len - SER_EVT_HEADER_SIZE;
uint32_t (*fp_event_decoder)(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len) = NULL;
switch (event_id)
{
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
case BLE_EVT_TX_COMPLETE:
fp_event_decoder = ble_evt_tx_complete_dec;
break;
case BLE_EVT_DATA_LENGTH_CHANGED:
fp_event_decoder = ble_evt_data_length_changed_dec;
break;
#endif
case BLE_EVT_USER_MEM_REQUEST:
fp_event_decoder = ble_evt_user_mem_request_dec;
break;
case BLE_EVT_USER_MEM_RELEASE:
fp_event_decoder = ble_evt_user_mem_release_dec;
break;
case BLE_GAP_EVT_PASSKEY_DISPLAY:
fp_event_decoder = ble_gap_evt_passkey_display_dec;
break;
case BLE_GAP_EVT_AUTH_KEY_REQUEST:
fp_event_decoder = ble_gap_evt_auth_key_request_dec;
break;
case BLE_GAP_EVT_CONN_PARAM_UPDATE:
fp_event_decoder = ble_gap_evt_conn_param_update_dec;
break;
#ifndef S112
case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST:
fp_event_decoder = ble_gap_evt_conn_param_update_request_dec;
break;
#endif
case BLE_GAP_EVT_CONN_SEC_UPDATE:
fp_event_decoder = ble_gap_evt_conn_sec_update_dec;
break;
case BLE_GAP_EVT_CONNECTED:
fp_event_decoder = ble_gap_evt_connected_dec;
break;
case BLE_GAP_EVT_DISCONNECTED:
fp_event_decoder = ble_gap_evt_disconnected_dec;
break;
case BLE_GAP_EVT_TIMEOUT:
fp_event_decoder = ble_gap_evt_timeout_dec;
break;
case BLE_GAP_EVT_RSSI_CHANGED:
fp_event_decoder = ble_gap_evt_rssi_changed_dec;
break;
case BLE_GAP_EVT_SEC_INFO_REQUEST:
fp_event_decoder = ble_gap_evt_sec_info_request_dec;
break;
case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
fp_event_decoder = ble_gap_evt_sec_params_request_dec;
break;
case BLE_GAP_EVT_AUTH_STATUS:
fp_event_decoder = ble_gap_evt_auth_status_dec;
break;
case BLE_GAP_EVT_SEC_REQUEST:
fp_event_decoder = ble_gap_evt_sec_request_dec;
break;
case BLE_GAP_EVT_KEY_PRESSED:
fp_event_decoder = ble_gap_evt_key_pressed_dec;
break;
case BLE_GAP_EVT_LESC_DHKEY_REQUEST:
fp_event_decoder = ble_gap_evt_lesc_dhkey_request_dec;
break;
#if NRF_SD_BLE_API_VERSION >= 5
case BLE_GAP_EVT_PHY_UPDATE:
fp_event_decoder = ble_gap_evt_phy_update_dec;
break;
case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
fp_event_decoder = ble_gap_evt_phy_update_request_dec;
break;
#endif
#if NRF_SD_BLE_API_VERSION >= 6
#ifndef S112
case BLE_GAP_EVT_QOS_CHANNEL_SURVEY_REPORT:
fp_event_decoder = ble_gap_evt_qos_channel_survey_report_dec;
break;
#endif
case BLE_GAP_EVT_ADV_SET_TERMINATED:
fp_event_decoder = ble_gap_evt_adv_set_terminated_dec;
break;
#endif
#if NRF_SD_BLE_API_VERSION >= 4 && !defined(S112)
case BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST:
fp_event_decoder = ble_gap_evt_data_length_update_request_dec;
break;
case BLE_GAP_EVT_DATA_LENGTH_UPDATE:
fp_event_decoder = ble_gap_evt_data_length_update_dec;
break;
#endif
case BLE_GATTC_EVT_CHAR_DISC_RSP:
fp_event_decoder = ble_gattc_evt_char_disc_rsp_dec;
break;
case BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP:
fp_event_decoder = ble_gattc_evt_char_val_by_uuid_read_rsp_dec;
break;
case BLE_GATTC_EVT_DESC_DISC_RSP:
fp_event_decoder = ble_gattc_evt_desc_disc_rsp_dec;
break;
case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP:
fp_event_decoder = ble_gattc_evt_prim_srvc_disc_rsp_dec;
break;
case BLE_GATTC_EVT_READ_RSP:
fp_event_decoder = ble_gattc_evt_read_rsp_dec;
break;
case BLE_GATTC_EVT_HVX:
fp_event_decoder = ble_gattc_evt_hvx_dec;
break;
case BLE_GATTC_EVT_TIMEOUT:
fp_event_decoder = ble_gattc_evt_timeout_dec;
break;
case BLE_GATTC_EVT_WRITE_RSP:
fp_event_decoder = ble_gattc_evt_write_rsp_dec;
break;
case BLE_GATTC_EVT_CHAR_VALS_READ_RSP:
fp_event_decoder = ble_gattc_evt_char_vals_read_rsp_dec;
break;
case BLE_GATTC_EVT_REL_DISC_RSP:
fp_event_decoder = ble_gattc_evt_rel_disc_rsp_dec;
break;
case BLE_GATTC_EVT_ATTR_INFO_DISC_RSP:
fp_event_decoder = ble_gattc_evt_attr_info_disc_rsp_dec;
break;
case BLE_GATTC_EVT_EXCHANGE_MTU_RSP:
fp_event_decoder = ble_gattc_evt_exchange_mtu_rsp_dec;
break;
#if NRF_SD_BLE_API_VERSION >= 4
case BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE:
fp_event_decoder = ble_gattc_evt_write_cmd_tx_complete_dec;
break;
#endif
case BLE_GATTS_EVT_WRITE:
fp_event_decoder = ble_gatts_evt_write_dec;
break;
case BLE_GATTS_EVT_TIMEOUT:
fp_event_decoder = ble_gatts_evt_timeout_dec;
break;
case BLE_GATTS_EVT_SC_CONFIRM:
fp_event_decoder = ble_gatts_evt_sc_confirm_dec;
break;
case BLE_GATTS_EVT_HVC:
fp_event_decoder = ble_gatts_evt_hvc_dec;
break;
case BLE_GATTS_EVT_SYS_ATTR_MISSING:
fp_event_decoder = ble_gatts_evt_sys_attr_missing_dec;
break;
case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
fp_event_decoder = ble_gatts_evt_rw_authorize_request_dec;
break;
case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST:
fp_event_decoder = ble_gatts_evt_exchange_mtu_request_dec;
break;
#if NRF_SD_BLE_API_VERSION >= 4
case BLE_GATTS_EVT_HVN_TX_COMPLETE:
fp_event_decoder = ble_gatts_evt_hvn_tx_complete_dec;
break;
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
case BLE_L2CAP_EVT_RX:
fp_event_decoder = ble_l2cap_evt_rx_dec;
break;
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION >= 5 && !defined(S112)
case BLE_L2CAP_EVT_CH_SETUP_REQUEST:
fp_event_decoder = ble_l2cap_evt_ch_setup_request_dec;
break;
case BLE_L2CAP_EVT_CH_SETUP_REFUSED:
fp_event_decoder = ble_l2cap_evt_ch_setup_refused_dec;
break;
case BLE_L2CAP_EVT_CH_SETUP:
fp_event_decoder = ble_l2cap_evt_ch_setup_dec;
break;
case BLE_L2CAP_EVT_CH_RELEASED:
fp_event_decoder = ble_l2cap_evt_ch_released_dec;
break;
case BLE_L2CAP_EVT_CH_SDU_BUF_RELEASED:
fp_event_decoder = ble_l2cap_evt_ch_sdu_buf_released_dec;
break;
case BLE_L2CAP_EVT_CH_CREDIT:
fp_event_decoder = ble_l2cap_evt_ch_credit_dec;
break;
case BLE_L2CAP_EVT_CH_RX:
fp_event_decoder = ble_l2cap_evt_ch_rx_dec;
break;
case BLE_L2CAP_EVT_CH_TX:
fp_event_decoder = ble_l2cap_evt_ch_tx_dec;
break;
#endif
#ifndef S112
case BLE_GAP_EVT_ADV_REPORT:
fp_event_decoder = ble_gap_evt_adv_report_dec;
break;
#endif
case BLE_GAP_EVT_SCAN_REQ_REPORT:
fp_event_decoder = ble_gap_evt_scan_req_report_dec;
break;
default:
break;
}
if (fp_event_decoder)
{
err_code = fp_event_decoder(p_sub_buffer, sub_packet_len, p_event, p_event_len);
}
else
{
err_code = NRF_ERROR_NOT_FOUND;
}
*p_event_len += offsetof(ble_evt_t, evt);
p_event->header.evt_id = (err_code == NRF_SUCCESS) ? event_id : 0;
p_event->header.evt_len = (err_code == NRF_SUCCESS) ? (uint16_t)*p_event_len : 0;
return err_code;
}

View File

@@ -0,0 +1,129 @@
/**
* Copyright (c) 2015 - 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_serialization.h"
#include "ble_struct_serialization.h"
#include "cond_field_serialization.h"
#include "app_util.h"
#include "ble_evt_app.h"
#include "app_ble_user_mem.h"
// Helper definitions for common event type names to be compliant with
// event serialization macros.
#define ble_common_evt_tx_complete_t ble_evt_tx_complete_t
#define ble_common_evt_user_mem_request_t ble_evt_user_mem_request_t
#define ble_common_evt_user_mem_release_t ble_evt_user_mem_release_t
#define ble_common_evt_data_length_changed_t ble_evt_data_length_changed_t
extern ser_ble_user_mem_t m_app_user_mem_table[];
uint32_t ble_evt_user_mem_release_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_EVT_USER_MEM_RELEASE, common, user_mem_release);
SER_PULL_uint16(&p_event->evt.common_evt.conn_handle);
SER_PULL_uint8(&p_event->evt.common_evt.params.user_mem_release.type);
SER_PULL_uint16(&p_event->evt.common_evt.params.user_mem_release.mem_block.len);
//Set the memory pointer to not-null value.
p_event->evt.common_evt.params.user_mem_release.mem_block.p_mem = (uint8_t *)~0;
SER_PULL_COND(&p_event->evt.common_evt.params.user_mem_release.mem_block.p_mem, NULL);
if (p_event->evt.common_evt.params.user_mem_release.mem_block.p_mem)
{
// Using connection handle find which mem block to release in Application Processor
uint32_t user_mem_table_index;
err_code = app_ble_user_mem_context_find(p_event->evt.common_evt.conn_handle, &user_mem_table_index);
SER_ASSERT(err_code == NRF_SUCCESS, err_code);
p_event->evt.common_evt.params.user_mem_release.mem_block.p_mem =
m_app_user_mem_table[user_mem_table_index].mem_block.p_mem;
}
// Now user memory context can be released
err_code = app_ble_user_mem_context_destroy(p_event->evt.common_evt.conn_handle);
SER_ASSERT(err_code == NRF_SUCCESS, err_code);
SER_EVT_DEC_END;
}
uint32_t ble_evt_user_mem_request_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_EVT_USER_MEM_REQUEST, common, user_mem_request);
SER_PULL_uint16(&p_event->evt.common_evt.conn_handle);
SER_PULL_uint8(&p_event->evt.common_evt.params.user_mem_request.type);
SER_EVT_DEC_END;
}
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
uint32_t ble_evt_tx_complete_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_EVT_TX_COMPLETE, common, tx_complete);
SER_PULL_uint16(&p_event->evt.common_evt.conn_handle);
SER_PULL_uint8(&p_event->evt.common_evt.params.tx_complete.count);
SER_EVT_DEC_END;
}
uint32_t ble_evt_data_length_changed_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_EVT_DATA_LENGTH_CHANGED, common, data_length_changed);
SER_PULL_uint16(&p_event->evt.common_evt.conn_handle);
SER_PULL_FIELD(&p_event->evt.common_evt.params.data_length_changed, ble_evt_data_length_changed_t_dec);
SER_EVT_DEC_END;
}
#endif

View File

@@ -0,0 +1,157 @@
/**
* 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_APP_H__
#define BLE_EVT_APP_H__
/**@file
*
* @defgroup ble_evt_app Application event decoders
* @{
* @ingroup ser_app_s130_codecs
*
* @brief Application event decoders.
*/
#include "ble.h"
#ifdef __cplusplus
extern "C" {
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
/**
* @brief Decodes the ble_evt_tx_complete event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of the event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to the \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, the required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of the \p p_event buffer.
* \c out: Length of the decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold the decoded event.
*/
uint32_t ble_evt_tx_complete_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
#endif
/**
* @brief Decodes the ble_evt_user_mem_request event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of the event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to the \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, the required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of the \p p_event buffer.
* \c out: Length of the decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold the decoded event.
*/
uint32_t ble_evt_user_mem_request_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes the ble_evt_user_mem_release event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of the event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to the \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, the required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of the \p p_event buffer.
* \c out: Length of the decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold the decoded event.
*/
uint32_t ble_evt_user_mem_release_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
/**
* @brief Decodes the ble_evt_data_length_changed event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of the event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to the \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, the required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of the \p p_event buffer.
* \c out: Length of the decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold the decoded event.
*/
uint32_t ble_evt_data_length_changed_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_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,415 @@
/**
* 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_gap_evt_app.h"
#include "ble_serialization.h"
#include "app_util.h"
#include "app_ble_gap_sec_keys.h"
#include "ble_gap_struct_serialization.h"
#include "ble_struct_serialization.h"
#include "cond_field_serialization.h"
#include <string.h>
extern ser_ble_gap_app_keyset_t m_app_keys_table[];
#ifndef S112
uint32_t ble_gap_evt_adv_report_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GAP_EVT_ADV_REPORT, gap, adv_report);
SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle);
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION >= 6
//get buffer stored during scan start.
app_ble_gap_scan_data_unset(false);
#endif
SER_PULL_FIELD(&p_event->evt.gap_evt.params.adv_report, ble_gap_evt_adv_report_t_dec);
SER_EVT_DEC_END;
}
#endif //!S112
uint32_t ble_gap_evt_auth_key_request_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GAP_EVT_AUTH_KEY_REQUEST, gap, auth_key_request);
SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PULL_uint8(&p_event->evt.gap_evt.params.auth_key_request.key_type);
SER_EVT_DEC_END;
}
extern ser_ble_gap_app_keyset_t m_app_keys_table[];
uint32_t ble_gap_evt_auth_status_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GAP_EVT_AUTH_STATUS, gap, auth_status);
SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PULL_FIELD(&p_event->evt.gap_evt.params.auth_status, ble_gap_evt_auth_status_t_dec);
// keyset is an extension of standard event data - used to synchronize keys at application
uint32_t conn_index;
err_code = app_ble_gap_sec_context_find(p_event->evt.gap_evt.conn_handle, &conn_index);
if (err_code == NRF_SUCCESS)
{
SER_PULL_FIELD(&(m_app_keys_table[conn_index].keyset), ble_gap_sec_keyset_t_dec);
err_code = app_ble_gap_sec_context_destroy(p_event->evt.gap_evt.conn_handle);
SER_ASSERT(err_code == NRF_SUCCESS, err_code);
}
SER_EVT_DEC_END;
}
uint32_t ble_gap_evt_conn_param_update_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GAP_EVT_CONN_PARAM_UPDATE, gap, conn_param_update);
SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PULL_FIELD(&p_event->evt.gap_evt.params.conn_param_update, ble_gap_evt_conn_param_update_t_dec);
SER_EVT_DEC_END;
}
#ifndef S112
uint32_t ble_gap_evt_conn_param_update_request_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST, gap, conn_param_update_request);
SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PULL_FIELD(&p_event->evt.gap_evt.params.conn_param_update_request,
ble_gap_evt_conn_param_update_request_t_dec);
SER_EVT_DEC_END;
}
#endif
uint32_t ble_gap_evt_conn_sec_update_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GAP_EVT_CONN_SEC_UPDATE, gap, conn_sec_update);
SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PULL_FIELD(&p_event->evt.gap_evt.params.conn_sec_update, ble_gap_evt_conn_sec_update_t_dec);
SER_EVT_DEC_END;
}
uint32_t ble_gap_evt_connected_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GAP_EVT_CONNECTED, gap, connected);
SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PULL_FIELD(&p_event->evt.gap_evt.params.connected, ble_gap_evt_connected_t_dec);
SER_EVT_DEC_END;
}
uint32_t ble_gap_evt_disconnected_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GAP_EVT_DISCONNECTED, gap, disconnected);
SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PULL_FIELD(&p_event->evt.gap_evt.params.disconnected, ble_gap_evt_disconnected_t_dec);
SER_EVT_DEC_END;
}
uint32_t ble_gap_evt_key_pressed_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GAP_EVT_KEY_PRESSED, gap, key_pressed);
SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PULL_uint8(&p_event->evt.gap_evt.params.key_pressed.kp_not);
SER_EVT_DEC_END;
}
uint32_t ble_gap_evt_lesc_dhkey_request_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GAP_EVT_LESC_DHKEY_REQUEST, gap, lesc_dhkey_request);
uint8_t ser_data;
SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle);
// keyset is an extension of standard event data - used to synchronize keys at application
uint32_t conn_index;
err_code = app_ble_gap_sec_context_find(p_event->evt.gap_evt.conn_handle, &conn_index);
SER_ASSERT(err_code == NRF_SUCCESS, err_code);
p_event->evt.gap_evt.params.lesc_dhkey_request.p_pk_peer = m_app_keys_table[conn_index].keyset.keys_peer.p_pk;
SER_PULL_COND(&p_event->evt.gap_evt.params.lesc_dhkey_request.p_pk_peer, ble_gap_lesc_p256_pk_t_dec);
SER_PULL_uint8(&ser_data);
p_event->evt.gap_evt.params.lesc_dhkey_request.oobd_req = ser_data & 0x01;
SER_EVT_DEC_END;
}
#define PASSKEY_LEN sizeof (p_event->evt.gap_evt.params.passkey_display.passkey)
uint32_t ble_gap_evt_passkey_display_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GAP_EVT_PASSKEY_DISPLAY, gap, passkey_display);
uint8_t ser_data;
SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PULL_uint8array(p_event->evt.gap_evt.params.passkey_display.passkey, BLE_GAP_PASSKEY_LEN);
SER_PULL_uint8(&ser_data);
p_event->evt.gap_evt.params.passkey_display.match_request = (ser_data & 0x01);
SER_EVT_DEC_END;
}
uint32_t ble_gap_evt_rssi_changed_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GAP_EVT_RSSI_CHANGED, gap, rssi_changed);
SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PULL_int8(&p_event->evt.gap_evt.params.rssi_changed.rssi);
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5
SER_PULL_uint8(&p_event->evt.gap_evt.params.rssi_changed.ch_index);
#endif
SER_EVT_DEC_END;
}
uint32_t ble_gap_evt_scan_req_report_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GAP_EVT_SCAN_REQ_REPORT, gap, scan_req_report);
SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle);
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5
SER_PULL_uint8(&p_event->evt.gap_evt.params.scan_req_report.adv_handle);
#endif
SER_PULL_FIELD(&p_event->evt.gap_evt.params.scan_req_report.peer_addr, ble_gap_addr_t_dec);
SER_PULL_int8(&p_event->evt.gap_evt.params.scan_req_report.rssi);
SER_EVT_DEC_END;
}
uint32_t ble_gap_evt_sec_info_request_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GAP_EVT_SEC_INFO_REQUEST, gap, sec_info_request);
SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PULL_FIELD(&p_event->evt.gap_evt.params.sec_info_request, ble_gap_evt_sec_info_request_t_dec);
SER_EVT_DEC_END;
}
uint32_t ble_gap_evt_sec_params_request_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GAP_EVT_SEC_PARAMS_REQUEST, gap, sec_params_request);
SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PULL_FIELD(&p_event->evt.gap_evt.params.sec_params_request, ble_gap_evt_sec_params_request_t_dec);
SER_EVT_DEC_END;
}
uint32_t ble_gap_evt_sec_request_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GAP_EVT_SEC_REQUEST, gap, sec_request);
SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PULL_FIELD(&p_event->evt.gap_evt.params.sec_request, ble_gap_evt_sec_request_t_dec);
SER_EVT_DEC_END;
}
uint32_t ble_gap_evt_timeout_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GAP_EVT_TIMEOUT, gap, timeout);
SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PULL_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_PULL_FIELD(&p_event->evt.gap_evt.params.timeout.params.adv_report_buffer, ble_data_t_dec);
}
#endif
SER_EVT_DEC_END;
}
#if NRF_SD_BLE_API_VERSION >= 5
uint32_t ble_gap_evt_phy_update_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GAP_EVT_PHY_UPDATE, gap, phy_update);
SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PULL_uint8(&p_event->evt.gap_evt.params.phy_update.status);
SER_PULL_uint8(&p_event->evt.gap_evt.params.phy_update.tx_phy);
SER_PULL_uint8(&p_event->evt.gap_evt.params.phy_update.rx_phy);
SER_EVT_DEC_END;
}
uint32_t ble_gap_evt_phy_update_request_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GAP_EVT_PHY_UPDATE_REQUEST, gap, phy_update);
SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PULL_FIELD(&p_event->evt.gap_evt.params.phy_update_request, ble_gap_phys_t_dec);
SER_EVT_DEC_END;
}
#endif
#if NRF_SD_BLE_API_VERSION >= 4 && !defined(S112)
uint32_t ble_gap_evt_data_length_update_request_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST, gap, timeout);
SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PULL_FIELD(&p_event->evt.gap_evt.params.data_length_update_request.peer_params, ble_gap_data_length_params_t_dec);
SER_EVT_DEC_END;
}
uint32_t ble_gap_evt_data_length_update_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GAP_EVT_DATA_LENGTH_UPDATE, gap, timeout);
SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PULL_FIELD(&p_event->evt.gap_evt.params.data_length_update.effective_params, ble_gap_data_length_params_t_dec);
SER_EVT_DEC_END;
}
#endif //NRF_SD_BLE_API_VERSION >= 4 @@ !defined(S112)
#if NRF_SD_BLE_API_VERSION > 5
#ifndef S112
uint32_t ble_gap_evt_qos_channel_survey_report_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GAP_EVT_QOS_CHANNEL_SURVEY_REPORT, gap, qos_channel_survey_report);
SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PULL_uint8array((uint8_t *)p_event->evt.gap_evt.params.qos_channel_survey_report.channel_energy, BLE_GAP_CHANNEL_COUNT);
SER_EVT_DEC_END;
}
#endif //S112
uint32_t ble_gap_evt_adv_set_terminated_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GAP_EVT_ADV_SET_TERMINATED, gap, adv_set_terminated);
SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PULL_FIELD(&p_event->evt.gap_evt.params.adv_set_terminated, ble_gap_evt_adv_set_terminated_t_dec);
SER_EVT_DEC_END;
}
#endif

View File

@@ -0,0 +1,597 @@
/**
* 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_APP_H__
#define BLE_GAP_EVT_APP_H__
/**@file
*
* @defgroup ble_gap_evt_app GAP Application event decoders
* @{
* @ingroup ser_app_s130_codecs
*
* @brief GAP Application event decoders.
*/
#include "ble.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Decodes ble_gap_evt_auth_key_request event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gap_evt_auth_key_request_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gap_evt_auth_status event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gap_evt_auth_status_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gap_evt_conn_param_update event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gap_evt_conn_param_update_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gap_evt_conn_sec_update event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gap_evt_conn_sec_update_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gap_evt_connected event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gap_evt_connected_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gap_evt_disconnected event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gap_evt_disconnected_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gap_evt_passkey_display event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gap_evt_passkey_display_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gap_evt_rssi_changed event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gap_evt_rssi_changed_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gap_evt_sec_info_request event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gap_evt_sec_info_request_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gap_evt_sec_params_request event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gap_evt_sec_params_request_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gap_evt_timeout event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gap_evt_timeout_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gap_evt_sec_request event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gap_evt_sec_request_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gap_evt_conn_param_update_request event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gap_evt_conn_param_update_request_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gap_evt_adv_report event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gap_evt_adv_report_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gap_evt_scan_req_report event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gap_evt_scan_req_report_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gap_evt_key_pressed event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gap_evt_key_pressed_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gap_evt_lesc_dhkey_request event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gap_evt_lesc_dhkey_request_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
#if NRF_SD_BLE_API_VERSION >= 5
/**
* @brief Decodes ble_gap_evt_phy_update event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gap_evt_phy_update_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gap_evt_phy_update_request event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gap_evt_phy_update_request_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
#endif
#if NRF_SD_BLE_API_VERSION >= 4
/**
* @brief Decodes ble_gap_evt_data_length_update_request event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gap_evt_data_length_update_request_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gap_evt_data_length_update event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gap_evt_data_length_update_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
#endif //NRF_SD_BLE_API_VERSION >= 4
#if NRF_SD_BLE_API_VERSION >= 6
#ifndef S112
/**
* @brief Decodes ble_gap_evt_qos_channel_survey_report event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gap_evt_qos_channel_survey_report_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
#endif
/**
* @brief Decodes ble_gap_evt_adv_set_terminated event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gap_evt_adv_set_terminated_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
#endif
/** @} */
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,286 @@
/**
* 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_gattc_app.h"
#include <string.h>
#include "ble_serialization.h"
#include "ble_gattc_struct_serialization.h"
#include "cond_field_serialization.h"
#include "app_util.h"
#include "ble_struct_serialization.h"
#include "ble_types.h"
uint32_t ble_gattc_attr_info_discover_req_enc(uint16_t conn_handle,
ble_gattc_handle_range_t const * const p_handle_range,
uint8_t * const p_buf,
uint32_t * p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_GATTC_ATTR_INFO_DISCOVER);
SER_PUSH_uint16(&conn_handle);
SER_PUSH_COND(p_handle_range, ble_gattc_handle_range_t_enc);
SER_REQ_ENC_END;
}
uint32_t ble_gattc_attr_info_discover_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code)
{
SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_ATTR_INFO_DISCOVER);
}
uint32_t ble_gattc_char_value_by_uuid_read_req_enc(uint16_t conn_handle,
ble_uuid_t const * const p_uuid,
ble_gattc_handle_range_t const * const p_handle_range,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ);
SER_PUSH_uint16(&conn_handle);
SER_PUSH_COND(p_uuid, ble_uuid_t_enc);
SER_PUSH_COND(p_handle_range, ble_gattc_handle_range_t_enc);
SER_REQ_ENC_END;
}
uint32_t ble_gattc_char_value_by_uuid_read_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code)
{
SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ);
}
uint32_t ble_gattc_char_values_read_req_enc(uint16_t conn_handle,
uint16_t const * const p_handles,
uint16_t handle_count,
uint8_t * const p_buf,
uint32_t * p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_GATTC_CHAR_VALUES_READ);
SER_PUSH_uint16(&conn_handle);
SER_PUSH_len16data16(p_handles, handle_count);
SER_REQ_ENC_END;
}
uint32_t ble_gattc_char_values_read_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code)
{
SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_CHAR_VALUES_READ);
}
uint32_t ble_gattc_characteristics_discover_req_enc(
uint16_t conn_handle,
ble_gattc_handle_range_t const * const p_handle_range,
uint8_t * const p_buf,
uint32_t * p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_GATTC_CHARACTERISTICS_DISCOVER);
SER_PUSH_uint16(&conn_handle);
SER_PUSH_COND(p_handle_range, ble_gattc_handle_range_t_enc);
SER_REQ_ENC_END;
}
uint32_t ble_gattc_characteristics_discover_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code)
{
SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_CHARACTERISTICS_DISCOVER);
}
uint32_t ble_gattc_descriptors_discover_req_enc(
uint16_t conn_handle,
ble_gattc_handle_range_t const * const p_handle_range,
uint8_t * const p_buf,
uint32_t * p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_GATTC_DESCRIPTORS_DISCOVER);
SER_PUSH_uint16(&conn_handle);
SER_PUSH_COND(p_handle_range, ble_gattc_handle_range_t_enc);
SER_REQ_ENC_END;
}
uint32_t ble_gattc_descriptors_discover_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code)
{
SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_DESCRIPTORS_DISCOVER);
}
uint32_t ble_gattc_hv_confirm_req_enc(uint16_t conn_handle,
uint16_t handle,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_GATTC_HV_CONFIRM);
SER_PUSH_uint16(&conn_handle);
SER_PUSH_uint16(&handle);
SER_REQ_ENC_END;
}
uint32_t ble_gattc_hv_confirm_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code)
{
SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_HV_CONFIRM);
}
uint32_t ble_gattc_primary_services_discover_req_enc(uint16_t conn_handle,
uint16_t start_handle,
ble_uuid_t const * const p_srvc_uuid,
uint8_t * const p_buf,
uint32_t * p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER);
SER_PUSH_uint16(&conn_handle);
SER_PUSH_uint16(&start_handle);
SER_PUSH_COND(p_srvc_uuid, ble_uuid_t_enc);
SER_REQ_ENC_END;
}
uint32_t ble_gattc_primary_services_discover_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code)
{
SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER);
}
uint32_t ble_gattc_read_req_enc(uint16_t conn_handle,
uint16_t handle,
uint16_t offset,
uint8_t * const p_buf,
uint32_t * p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_GATTC_READ);
SER_PUSH_uint16(&conn_handle);
SER_PUSH_uint16(&handle);
SER_PUSH_uint16(&offset);
SER_REQ_ENC_END;
}
uint32_t ble_gattc_read_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code)
{
SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_READ);
}
uint32_t ble_gattc_relationships_discover_req_enc(
uint16_t conn_handle,
ble_gattc_handle_range_t const * const p_handle_range,
uint8_t * const p_buf,
uint32_t * p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_GATTC_RELATIONSHIPS_DISCOVER);
SER_PUSH_uint16(&conn_handle);
SER_PUSH_COND(p_handle_range, ble_gattc_handle_range_t_enc);
SER_REQ_ENC_END;
}
uint32_t ble_gattc_relationships_discover_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code)
{
SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_RELATIONSHIPS_DISCOVER);
}
uint32_t ble_gattc_write_req_enc(uint16_t conn_handle,
ble_gattc_write_params_t const * const p_write_params,
uint8_t * const p_buf,
uint32_t * p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_GATTC_WRITE);
SER_PUSH_uint16(&conn_handle);
SER_PUSH_COND(p_write_params, ble_gattc_write_params_t_enc);
SER_REQ_ENC_END;
}
uint32_t ble_gattc_write_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code)
{
SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_WRITE);
}
uint32_t ble_gattc_exchange_mtu_request_req_enc(uint16_t conn_handle,
uint16_t client_rx_mtu,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_GATTC_EXCHANGE_MTU_REQUEST);
SER_PUSH_uint16(&conn_handle);
SER_PUSH_uint16(&client_rx_mtu);
SER_REQ_ENC_END;
}
uint32_t ble_gattc_exchange_mtu_request_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code)
{
SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_EXCHANGE_MTU_REQUEST);
}

View File

@@ -0,0 +1,491 @@
/**
* 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_APP_H__
#define BLE_GATTC_APP_H__
/**@file
*
* @defgroup ble_gattc_app GATTC Application command request encoders and command response decoders
* @{
* @ingroup ser_app_s130_codecs
*
* @brief GATTC Application command request encoders and command response decoders.
*/
#include "ble_gattc.h"
#include "ble.h"
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Encodes @ref sd_ble_gattc_primary_services_discover command request.
*
* @sa @ref ble_gattc_primary_services_discover_rsp_dec for command response decoder.
*
* @param[in] conn_handle Connection handle of the connection.
* @param[in] start_handle Handle to start searching from.
* @param[in] p_srvc_uuid Pointer to a @ref ble_uuid_t which indicates the service UUID to
* be found. If it is NULL, all primary services will be returned.
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command 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_req_enc(uint16_t conn_handle,
uint16_t start_handle,
ble_uuid_t const * const p_srvc_uuid,
uint8_t * const p_buf,
uint32_t * p_buf_len);
/**@brief Decodes response to @ref sd_ble_gattc_primary_services_discover command.
*
* @sa @ref ble_gattc_primary_services_discover_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_result_code Command response result code.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected
* operation code.
*/
uint32_t ble_gattc_primary_services_discover_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code);
/**@brief Encodes @ref sd_ble_gattc_descriptors_discover command request.
*
* @sa @ref ble_gattc_descriptors_discover_rsp_dec for command response decoder.
*
* @param[in] conn_handle Connection handle of the connection.
* @param[in] p_handle_range A pointer to the range of handles of the Service to perform
* this procedure on.
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command 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_req_enc(
uint16_t conn_handle,
ble_gattc_handle_range_t const * const p_handle_range,
uint8_t * const p_buf,
uint32_t * p_buf_len);
/**@brief Decodes response to @ref sd_ble_gattc_descriptors_discover command.
*
* @sa @ref ble_gattc_primary_services_discover_rsp_dec for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_result_code Command response result code.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected
* operation code.
*/
uint32_t ble_gattc_descriptors_discover_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code);
/**@brief Encodes @ref sd_ble_gattc_relationships_discover command request.
*
* @sa @ref ble_gattc_relationships_discover_rsp_dec for command response decoder.
*
* @param[in] conn_handle Connection handle of the connection.
* @param[in] p_handle_range A pointer to the range of handles of the Service to perform
* this procedure on.
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command 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_req_enc(
uint16_t conn_handle,
ble_gattc_handle_range_t const * const p_handle_range,
uint8_t * const p_buf,
uint32_t * p_buf_len);
/**@brief Decodes response to @ref sd_ble_gattc_relationships_discover command.
*
* @sa @ref ble_gattc_relationships_discover_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_result_code Command response result code.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected
* operation code.
*/
uint32_t ble_gattc_relationships_discover_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code);
/**@brief Encodes @ref sd_ble_gattc_characteristics_discover command request.
*
* @sa @ref ble_gattc_characteristics_discover_rsp_dec for command response decoder.
*
* @param[in] conn_handle Connection handle of the connection.
* @param[in] p_handle_range A pointer to the range of handles of the Service to perform
* this procedure on.
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command 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_req_enc
(uint16_t conn_handle,
ble_gattc_handle_range_t const * const p_handle_range,
uint8_t * const p_buf,
uint32_t * p_buf_len);
/**@brief Decodes response to @ref sd_ble_gattc_characteristics_discover command.
*
* @sa @ref ble_gattc_primary_services_discover_rsp_dec for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_result_code Command response result code.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected
* operation code.
*/
uint32_t ble_gattc_characteristics_discover_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code);
/**@brief Encodes @ref sd_ble_gattc_read command request.
*
* @sa @ref ble_gattc_read_rsp_dec for command response decoder.
*
* @param[in] conn_handle Connection handle of the connection.
* @param[in] handle The handle of the attribute to be read.
* @param[in] offset Offset into the attribute value to be read.
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command 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_req_enc(uint16_t conn_handle,
uint16_t handle,
uint16_t offset,
uint8_t * const p_buf,
uint32_t * p_buf_len);
/**@brief Decodes response to @ref sd_ble_gattc_read command.
*
* @sa @ref ble_gattc_read_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_result_code Command response result code.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected
* operation code.
*/
uint32_t ble_gattc_read_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code);
/**@brief Encodes @ref sd_ble_gattc_char_values_read command request.
*
* @sa @ref ble_gattc_char_values_read_rsp_dec for command response decoder.
*
* @param[in] conn_handle Connection handle of the connection.
* @param[in] p_handles A pointer to the handle(s) of the attribute(s) to be read.
* @param[in] handle_count The number of handles in p_handles.
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command 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_req_enc(uint16_t conn_handle,
uint16_t const * const p_handles,
uint16_t handle_count,
uint8_t * const p_buf,
uint32_t * p_buf_len);
/**@brief Decodes response to @ref sd_ble_gattc_char_values_read command.
*
* @sa @ref ble_gattc_char_values_read_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_result_code Command response result code.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected
* operation code.
*/
uint32_t ble_gattc_char_values_read_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code);
/**@brief Encodes @ref sd_ble_gattc_write command request.
*
* @sa @ref ble_gattc_write_rsp_dec for command response decoder.
*
* @param[in] conn_handle Connection handle of the connection.
* @param[in] p_write_params Pointer to \ref sd_ble_gattc_write params.
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command 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_req_enc(uint16_t conn_handle,
ble_gattc_write_params_t const * const p_write_params,
uint8_t * const p_buf,
uint32_t * p_buf_len);
/**@brief Decodes response to @ref sd_ble_gattc_write command.
*
* @sa @ref ble_gattc_write_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_result_code Command response result code.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected
* operation code.
*/
uint32_t ble_gattc_write_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code);
/**@brief Encodes @ref sd_ble_gattc_hv_confirm command request.
*
* @sa @ref ble_gattc_hv_confirm_rsp_dec for command response decoder.
*
* @param[in] conn_handle Connection handle of the connection.
* @param[in] handle Handle of the attribute in the indication.
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command 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_req_enc(uint16_t conn_handle,
uint16_t handle,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes response to @ref sd_ble_gattc_hv_confirm command.
*
* @sa @ref ble_gattc_hv_confirm_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_result_code Pointer to command response result code.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected
* operation code.
*/
uint32_t ble_gattc_hv_confirm_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code);
/**@brief Encodes @ref sd_ble_gattc_char_value_by_uuid_read command request.
*
* @sa @ref ble_gattc_char_value_by_uuid_read_rsp_dec for command response decoder.
*
* @param[in] conn_handle Connection handle of the connection.
* @param[in] p_uuid Pointer to a characteristic value UUID to read.
* @param[in] p_handle_range Pointer to the range of handles to perform this procedure on.
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command 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_req_enc
(uint16_t conn_handle,
ble_uuid_t const * const p_uuid,
ble_gattc_handle_range_t const * const p_handle_range,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes response to @ref sd_ble_gattc_char_value_by_uuid_read command.
*
* @sa @ref ble_gattc_char_value_by_uuid_read_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_result_code Pointer to command response result code.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected
* operation code.
*/
uint32_t ble_gattc_char_value_by_uuid_read_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code);
/**@brief Encodes @ref sd_ble_gattc_attr_info_discover command request.
*
* @sa @ref ble_gattc_attr_info_discover_rsp_dec for command response decoder.
*
* @param[in] conn_handle Connection handle of the connection.
* @param[in] p_handle_range Pointer to the range of handles
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command 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_req_enc(uint16_t conn_handle,
ble_gattc_handle_range_t const * const p_handle_range,
uint8_t * const p_buf,
uint32_t * p_buf_len);
/**@brief Decodes response to @ref sd_ble_gattc_attr_info_discover command.
*
* @sa @ref ble_gattc_attr_info_discover_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_result_code Pointer to command response result code.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected
* operation code.
*/
uint32_t ble_gattc_attr_info_discover_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code);
/**@brief Encodes @ref sd_ble_gattc_exchange_mtu_request command request.
*
* @sa @ref ble_gattc_exchange_mtu_request_rsp_dec for command response decoder.
*
* @param[in] conn_handle Connection handle of the connection.
* @param[in] client_rx_mtu Client MTU Size.
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command 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_req_enc(uint16_t conn_handle,
uint16_t client_rx_mtu,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes response to @ref sd_ble_gattc_exchange_mtu_request command.
*
* @sa @ref ble_gattc_exchange_mtu_request_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_result_code Pointer to command response result code.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected
* operation code.
*/
uint32_t ble_gattc_exchange_mtu_request_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code);
/** @} */
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,262 @@
/**
* 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_gattc_evt_app.h"
#include <string.h>
#include "ble_serialization.h"
#include "ble_gattc_struct_serialization.h"
#include "app_util.h"
uint32_t ble_gattc_evt_attr_info_disc_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_ATTR_INFO_DISC_RSP, gattc, attr_info_disc_rsp);
SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.attr_info_disc_rsp,
ble_gattc_evt_attr_info_disc_rsp_t_dec);
SER_EVT_DEC_END;
}
uint32_t ble_gattc_evt_char_disc_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_CHAR_DISC_RSP, gattc, char_disc_rsp);
SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.char_disc_rsp,
ble_gattc_evt_char_disc_rsp_t_dec);
SER_EVT_DEC_END;
}
uint32_t ble_gattc_evt_char_val_by_uuid_read_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP, gattc, char_val_by_uuid_read_rsp);
SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.char_val_by_uuid_read_rsp,
ble_gattc_evt_char_val_by_uuid_read_rsp_t_dec);
SER_EVT_DEC_END;
}
uint32_t ble_gattc_evt_char_vals_read_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_CHAR_VALS_READ_RSP, gattc, char_vals_read_rsp);
SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.char_vals_read_rsp,
ble_gattc_evt_char_vals_read_rsp_t_dec);
SER_EVT_DEC_END;
}
uint32_t ble_gattc_evt_desc_disc_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_DESC_DISC_RSP, gattc, desc_disc_rsp);
SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.desc_disc_rsp,
ble_gattc_evt_desc_disc_rsp_t_dec);
SER_EVT_DEC_END;
}
uint32_t ble_gattc_evt_hvx_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_HVX, gattc, hvx);
SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.hvx,
ble_gattc_evt_hvx_t_dec);
SER_EVT_DEC_END;
}
uint32_t ble_gattc_evt_prim_srvc_disc_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP, gattc, prim_srvc_disc_rsp);
SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.prim_srvc_disc_rsp,
ble_gattc_evt_prim_srvc_disc_rsp_t_dec);
SER_EVT_DEC_END;
}
uint32_t ble_gattc_evt_read_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_READ_RSP, gattc, read_rsp);
SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.read_rsp,
ble_gattc_evt_read_rsp_t_dec);
SER_EVT_DEC_END;
}
#define BLE_GATTC_EVT_REL_DISC_RSP_COUNT_POSITION 6
uint32_t ble_gattc_evt_rel_disc_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_READ_RSP, gattc, rel_disc_rsp);
SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.rel_disc_rsp,
ble_gattc_evt_rel_disc_rsp_t_dec);
SER_EVT_DEC_END;
}
uint32_t ble_gattc_evt_timeout_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_TIMEOUT, gattc, timeout);
SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PULL_FIELD(&p_event->evt.gattc_evt.params.timeout,
ble_gattc_evt_timeout_t_dec);
SER_EVT_DEC_END;
}
uint32_t ble_gattc_evt_write_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_WRITE_RSP, gattc, write_rsp);
SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.write_rsp,
ble_gattc_evt_write_rsp_t_dec);
SER_EVT_DEC_END;
}
uint32_t ble_gattc_evt_exchange_mtu_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_EXCHANGE_MTU_RSP, gattc, exchange_mtu_rsp);
SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PULL_FIELD(&p_event->evt.gattc_evt.params.exchange_mtu_rsp,
ble_gattc_evt_exchange_mtu_rsp_t_dec);
SER_EVT_DEC_END;
}
#if NRF_SD_BLE_API_VERSION >= 4
uint32_t ble_gattc_evt_write_cmd_tx_complete_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE, gattc, write_cmd_tx_complete);
SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PULL_uint8(&p_event->evt.gattc_evt.params.write_cmd_tx_complete.count);
SER_EVT_DEC_END;
}
#endif

View File

@@ -0,0 +1,364 @@
/**
* 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_APP_H__
#define BLE_GATTC_EVT_APP_H__
/**@file
*
* @defgroup ble_gattc_evt_app GATTC Application event decoders
* @{
* @ingroup ser_app_s130_codecs
*
* @brief GATTC Application event decoders.
*/
#include "ble.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Decodes ble_gattc_evt_char_disc_rsp event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gattc_evt_char_disc_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gattc_evt_char_val_by_uuid_read_rsp event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gattc_evt_char_val_by_uuid_read_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gattc_evt_char_vals_read_rsp event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gattc_evt_char_vals_read_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gattc_evt_desc_disc_rsp event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gattc_evt_desc_disc_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gattc_evt_hvx event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gattc_evt_hvx_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gattc_evt_prim_srvc_disc_rsp event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gattc_evt_prim_srvc_disc_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gattc_evt_read_rsp event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gattc_evt_read_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gattc_evt_rel_disc_rsp_dec event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gattc_evt_rel_disc_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gattc_evt_timeout event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gattc_evt_timeout_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gattc_evt_write_rsp event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gattc_evt_write_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gattc_evt_attr_info_disc_rsp event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gattc_evt_attr_info_disc_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gattc_evt_exchange_mtu_rsp event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gattc_evt_exchange_mtu_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
#if NRF_SD_BLE_API_VERSION >= 4
/**
* @brief Decodes ble_gattc_evt_write_cmd_tx_complete event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gattc_evt_write_cmd_tx_complete_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
#endif
/** @} */
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,439 @@
/**
* 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_gatts_app.h"
#include <stdlib.h>
#include <string.h>
#include "ble_serialization.h"
#include "ble_gatts_struct_serialization.h"
#include "ble_struct_serialization.h"
#include "cond_field_serialization.h"
#include "app_util.h"
uint32_t ble_gatts_attr_get_req_enc(uint16_t handle,
ble_uuid_t * p_uuid,
ble_gatts_attr_md_t * p_md,
uint8_t * const p_buf,
uint32_t * p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_GATTS_ATTR_GET);
SER_PUSH_uint16(&handle);
SER_PUSH_COND(p_uuid, NULL);
SER_PUSH_COND(p_md, NULL);
SER_REQ_ENC_END;
}
uint32_t ble_gatts_attr_get_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_uuid_t ** pp_uuid,
ble_gatts_attr_md_t ** pp_md,
uint32_t * const p_result_code)
{
SER_RSP_DEC_BEGIN(SD_BLE_GATTS_ATTR_GET);
SER_PULL_COND(pp_uuid, ble_uuid_t_dec);
SER_PULL_COND(pp_md, ble_gatts_attr_md_t_dec);
SER_RSP_DEC_END;
}
uint32_t ble_gatts_characteristic_add_req_enc(
uint16_t service_handle,
ble_gatts_char_md_t const * const p_char_md,
ble_gatts_attr_t const * const p_attr_char_value,
ble_gatts_char_handles_t const * const p_handles,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_GATTS_CHARACTERISTIC_ADD);
SER_PUSH_uint16(&service_handle);
SER_PUSH_COND(p_char_md, ble_gatts_char_md_t_enc);
SER_PUSH_COND(p_attr_char_value, ble_gatts_attr_t_enc);
SER_PUSH_COND(p_handles, NULL);
SER_REQ_ENC_END;
}
uint32_t ble_gatts_characteristic_add_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * * const pp_handles,
uint32_t * const p_result_code)
{
SER_RSP_DEC_BEGIN(SD_BLE_GATTS_CHARACTERISTIC_ADD);
SER_PULL_COND(pp_handles, ble_gatts_char_handles_t_dec);
SER_RSP_DEC_END;
}
uint32_t ble_gatts_descriptor_add_req_enc(uint16_t char_handle,
ble_gatts_attr_t const * const p_attr,
uint16_t * const p_handle,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_GATTS_DESCRIPTOR_ADD);
SER_PUSH_uint16(&char_handle);
SER_PUSH_COND(p_attr, ble_gatts_attr_t_enc);
SER_PUSH_COND(p_handle, NULL);
SER_REQ_ENC_END;
}
uint32_t ble_gatts_descriptor_add_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_handle,
uint32_t * const p_result_code)
{
SER_RSP_DEC_BEGIN(SD_BLE_GATTS_DESCRIPTOR_ADD);
SER_PULL_COND(&p_handle, uint16_t_dec);
SER_RSP_DEC_END;
}
uint32_t ble_gatts_hvx_req_enc(uint16_t conn_handle,
ble_gatts_hvx_params_t const * const p_hvx_params,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_GATTS_HVX);
SER_PUSH_uint16(&conn_handle);
SER_PUSH_COND(p_hvx_params, ble_gatts_hvx_params_t_enc);
SER_REQ_ENC_END;
}
uint32_t ble_gatts_hvx_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code,
uint16_t * * const pp_bytes_written)
{
SER_RSP_DEC_BEGIN(SD_BLE_GATTS_HVX);
SER_PULL_COND(pp_bytes_written, uint16_t_dec);
SER_RSP_DEC_END;
}
uint32_t ble_gatts_include_add_req_enc(uint16_t service_handle,
uint16_t inc_srvc_handle,
uint16_t * const p_include_handle,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_GATTS_INCLUDE_ADD);
SER_PUSH_uint16(&service_handle);
SER_PUSH_uint16(&inc_srvc_handle);
SER_PUSH_COND(p_include_handle, NULL);
SER_REQ_ENC_END;
}
uint32_t ble_gatts_include_add_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_include_handle,
uint32_t * const p_result_code)
{
SER_RSP_DEC_BEGIN(SD_BLE_GATTS_INCLUDE_ADD);
SER_PULL_COND(&p_include_handle, uint16_t_dec);
SER_RSP_DEC_END;
}
uint32_t ble_gatts_initial_user_handle_get_req_enc(uint16_t * p_handle,
uint8_t * const p_buf,
uint32_t * p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_GATTS_INITIAL_USER_HANDLE_GET);
SER_PUSH_COND(p_handle, NULL);
SER_REQ_ENC_END;
}
uint32_t ble_gatts_initial_user_handle_get_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t ** pp_handle,
uint32_t * const p_result_code)
{
SER_RSP_DEC_BEGIN(SD_BLE_GATTS_INITIAL_USER_HANDLE_GET);
SER_PULL_COND(pp_handle, uint16_t_dec);
SER_RSP_DEC_END;
}
uint32_t ble_gatts_rw_authorize_reply_req_enc(uint16_t conn_handle,
ble_gatts_rw_authorize_reply_params_t const * const p_reply_params,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_GATTS_RW_AUTHORIZE_REPLY);
SER_PUSH_uint16(&conn_handle);
SER_PUSH_COND(p_reply_params, ble_gatts_rw_authorize_reply_params_t_enc);
SER_REQ_ENC_END;
}
uint32_t ble_gatts_rw_authorize_reply_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code)
{
SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTS_RW_AUTHORIZE_REPLY);
}
uint32_t ble_gatts_service_add_req_enc(uint8_t type,
ble_uuid_t const * const p_uuid,
uint16_t const * const p_conn_handle,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_GATTS_SERVICE_ADD);
SER_PUSH_uint8(&type);
SER_PUSH_COND(p_uuid, ble_uuid_t_enc);
SER_PUSH_COND(p_conn_handle, NULL);
SER_REQ_ENC_END;
}
uint32_t ble_gatts_service_add_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_conn_handle,
uint32_t * const p_result_code)
{
SER_RSP_DEC_BEGIN(SD_BLE_GATTS_SERVICE_ADD);
SER_PULL_COND(&p_conn_handle, uint16_t_dec);
SER_RSP_DEC_END;
}
uint32_t ble_gatts_service_changed_req_enc(uint16_t conn_handle,
uint16_t start_handle,
uint16_t end_handle,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_GATTS_SERVICE_CHANGED);
SER_PUSH_uint16(&conn_handle);
SER_PUSH_uint16(&start_handle);
SER_PUSH_uint16(&end_handle);
SER_REQ_ENC_END;
}
uint32_t ble_gatts_service_changed_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code)
{
SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTS_SERVICE_CHANGED);
}
uint32_t ble_gatts_sys_attr_get_req_enc(uint16_t conn_handle,
uint8_t const * const p_sys_attr_data,
uint16_t const * const p_sys_attr_data_len,
uint32_t flags,
uint8_t * const p_buf,
uint32_t * p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_GATTS_SYS_ATTR_GET);
SER_PUSH_uint16(&conn_handle);
SER_PUSH_COND(p_sys_attr_data_len, uint16_t_enc);
SER_PUSH_COND(p_sys_attr_data, NULL);
SER_PUSH_uint32(&flags);
SER_REQ_ENC_END;
}
uint32_t ble_gatts_sys_attr_get_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint8_t * * const pp_sys_attr_data,
uint16_t * * const pp_sys_attr_data_len,
uint32_t * const p_result_code)
{
SER_RSP_DEC_BEGIN(SD_BLE_GATTS_SYS_ATTR_GET);
SER_PULL_COND(pp_sys_attr_data_len, uint16_t_dec);
if (*pp_sys_attr_data_len)
{
SER_PULL_buf(pp_sys_attr_data, **pp_sys_attr_data_len, **pp_sys_attr_data_len);
}
SER_RSP_DEC_END;
}
uint32_t ble_gatts_sys_attr_set_req_enc(uint16_t conn_handle,
uint8_t const * const p_sys_attr_data,
uint16_t sys_attr_data_len,
uint32_t flags,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_GATTS_SYS_ATTR_SET);
SER_PUSH_uint16(&conn_handle);
SER_PUSH_len16data(p_sys_attr_data, sys_attr_data_len);
SER_PUSH_uint32(&flags);
SER_REQ_ENC_END;
}
uint32_t ble_gatts_sys_attr_set_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code)
{
return ser_ble_cmd_rsp_dec(p_buf, packet_len, SD_BLE_GATTS_SYS_ATTR_SET, p_result_code);
}
uint32_t ble_gatts_value_get_req_enc(uint16_t conn_handle,
uint16_t handle,
ble_gatts_value_t const * const p_value,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_GATTS_VALUE_GET);
SER_PUSH_uint16(&conn_handle);
SER_PUSH_uint16(&handle);
//Special case: skip the data.
SER_PUSH_COND(p_value, NULL);
if (p_value)
{
SER_PUSH_uint16(&p_value->offset);
SER_PUSH_uint16(&p_value->len);
SER_PUSH_COND(p_value->p_value, NULL);
}
SER_REQ_ENC_END;
}
uint32_t ble_gatts_value_get_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_gatts_value_t * const p_value,
uint32_t * const p_result_code)
{
SER_RSP_DEC_BEGIN(SD_BLE_GATTS_VALUE_GET);
SER_PULL_COND(&p_value, ble_gatts_value_t_dec);
SER_RSP_DEC_END;
}
uint32_t ble_gatts_value_set_req_enc(uint16_t conn_handle,
uint16_t handle,
ble_gatts_value_t * p_value,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_GATTS_VALUE_SET);
SER_PUSH_uint16(&conn_handle);
SER_PUSH_uint16(&handle);
SER_PUSH_COND(p_value, ble_gatts_value_t_enc);
SER_REQ_ENC_END;
}
uint32_t ble_gatts_value_set_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_gatts_value_t * const p_value,
uint32_t * const p_result_code)
{
SER_RSP_DEC_BEGIN(SD_BLE_GATTS_VALUE_SET);
SER_PULL_COND(&p_value, ble_gatts_value_t_dec);
SER_RSP_DEC_END;
}
uint32_t ble_gatts_exchange_mtu_reply_req_enc(uint16_t conn_handle,
uint16_t server_rx_mtu,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_GATTS_EXCHANGE_MTU_REPLY);
SER_PUSH_uint16(&conn_handle);
SER_PUSH_uint16(&server_rx_mtu);
SER_REQ_ENC_END;
}
uint32_t ble_gatts_exchange_mtu_reply_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code)
{
SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTS_EXCHANGE_MTU_REPLY);
}

View File

@@ -0,0 +1,677 @@
/**
* 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_APP_H__
#define BLE_GATTS_APP_H__
/**@file
*
* @defgroup ble_gatts_app GATTS Application command request encoders and command response decoders
* @{
* @ingroup ser_app_s130_codecs
*
* @brief GATTS Application command request encoders and command response decoders.
*/
#include "ble_gatts.h"
#include "ble.h"
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Encodes @ref sd_ble_gatts_value_get command request.
*
* @sa @ref ble_gatts_value_get_rsp_dec for command response decoder.
*
* @param[in] conn_handle Connection handle.
* @param[in] handle Attribute handle.
* @param[in] p_value Pointer to attribute value information.
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
* \c out: Length of encoded command packet.
*
* @note \p p_data_len and \p p_data will not be updated by the command
* request encoder. Updated values are set by @ref ble_gatts_value_get_rsp_dec.
*
* @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_req_enc(uint16_t conn_handle,
uint16_t handle,
ble_gatts_value_t const * const p_value,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes response to @ref sd_ble_gatts_value_get command.
*
* @sa @ref ble_gatts_value_get_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_value Pointer to structure where the attribute value will be stored.
* @param[out] p_result_code Command result code.
*
* @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_DATA_SIZE Length of \p p_value is too small to hold decoded
* value from response.
*/
uint32_t ble_gatts_value_get_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_gatts_value_t * const p_value,
uint32_t * const p_result_code);
/**@brief Encodes @ref sd_ble_gatts_hvx command request.
*
* @sa @ref ble_gatts_hvx_rsp_dec for command response decoder.
*
* @param[in] conn_handle Connection handle.
* @param[in] p_hvx_params Pointer to an HVx parameters structure to be encoded.
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
* \c out: Length of encoded command packet.
*
* @note \p p_hvx_params will not be updated by the command
* request encoder. Updated values are set by @ref ble_gatts_hvx_rsp_dec.
*
* @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_req_enc(uint16_t conn_handle,
ble_gatts_hvx_params_t const * const p_hvx_params,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes response to @ref sd_ble_gatts_hvx command.
*
* @sa @ref ble_gatts_hvx_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_result_code Command result code.
* @param[out] pp_bytes_written Pointer to pointer to location where number of bytes is written.
*
* @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. Decoded operation code does not match
* expected operation code.
*/
uint32_t ble_gatts_hvx_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code,
uint16_t * * const pp_bytes_written);
/**@brief Encodes @ref sd_ble_gatts_characteristic_add command request.
*
* @sa @ref ble_gatts_characteristic_add_rsp_dec for command response decoder.
*
* @param[in] service_handle Handle of the service where the characteristic is to be placed.
* If @ref BLE_GATT_HANDLE_INVALID is used, it will be placed
* sequentially.
* @param[in] p_char_md Pointer to a @ref ble_gatts_char_md_t structure, characteristic
* metadata.
* @param[in] p_attr_char_value Pointer to a @ref ble_gatts_attr_t structure, corresponding to
* the characteristic value.
* @param[in] p_handles Pointer to a @ref ble_gatts_char_handles_t structure, where the
* assigned handles will be stored.
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
* \c out: Length of encoded command packet.
*
* @note \p p_handles will not be updated by the command
* request encoder. Updated values are set by @ref ble_gatts_characteristic_add_rsp_dec.
*
* @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_req_enc
(uint16_t service_handle,
ble_gatts_char_md_t const * const p_char_md,
ble_gatts_attr_t const * const p_attr_char_value,
ble_gatts_char_handles_t const * const p_handles,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes response to @ref sd_ble_gatts_characteristic_add command.
*
* @sa @ref ble_gatts_characteristic_add_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] pp_handles Pointer to pointer to location where handles should be decoded.
* @param[out] p_result_code Pointer to command result code decode location.
*
* @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. Decoded operation code does not match
* expected operation code.
*/
uint32_t ble_gatts_characteristic_add_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * * const pp_handles,
uint32_t * const p_result_code);
/**@brief Encodes @ref sd_ble_gatts_service_add command request.
*
* @sa @ref ble_gatts_service_add_rsp_dec for command response decoder.
*
* @param[in] type Toggles between primary and secondary services,
* see @ref BLE_GATTS_SRVC_TYPES.
* @param[in] p_uuid Pointer to service UUID.
* @param[in] p_conn_handle Pointer to a 16-bit word where the assigned handle will be stored.
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
* \c out: Length of encoded command packet.
*
* @note \p p_conn_handle will not be updated by the command
* request encoder. Updated values are set by @ref ble_gatts_service_add_rsp_dec.
*
* @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_req_enc(uint8_t type,
ble_uuid_t const * const p_uuid,
uint16_t const * const p_conn_handle,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes response to @ref sd_ble_gatts_service_add command.
*
* @sa @ref ble_gatts_service_add_req_enc for command request encoder.
*
* @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 Connection handle.
* @param[out] p_result_code Command result code.
*
* @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. Decoded operation code does not match
* expected operation code.
*/
uint32_t ble_gatts_service_add_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_conn_handle,
uint32_t * const p_result_code);
/**@brief Encodes @ref sd_ble_gatts_sys_attr_set command request.
*
* @sa @ref ble_gatts_sys_attr_set_rsp_dec for command response decoder.
*
* @param[in] conn_handle Connection handle.
* @param[in] p_sys_attr_data Pointer to a buffer (at least \p sys_attr_data_len bytes long)
* containing the attribute value to write.
* @param[in] sys_attr_data_len Length (in bytes) of \p p_sys_attr_data.
* @param[in] flags Optional additional flags.
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
* \c out: Length of encoded command 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_req_enc(uint16_t conn_handle,
uint8_t const * const p_sys_attr_data,
uint16_t sys_attr_data_len,
uint32_t flags,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes response to @ref sd_ble_gatts_sys_attr_set command.
*
* @sa @ref ble_gatts_sys_attr_set_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_result_code Command result code.
*
* @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. Decoded operation code does not match
* expected operation code.
*/
uint32_t ble_gatts_sys_attr_set_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code);
/**@brief Encodes @ref sd_ble_gatts_value_set command request.
*
* @sa @ref ble_gatts_value_set_rsp_dec for command response decoder.
*
* @param[in] conn_handle Connection handle.
* @param[in] handle Attribute handle.
* @param[in] p_value Pointer to attribute value information.
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
* \c out: Length of encoded command 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_value_set_req_enc(uint16_t conn_handle,
uint16_t handle,
ble_gatts_value_t * p_value,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes response to @ref sd_ble_gatts_value_set command.
*
* @sa @ref ble_gatts_value_set_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_value Pointer to attribute value information.
* @param[out] p_result_code Command result code.
*
* @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. Decoded operation code does not match
* expected operation code.
*/
uint32_t ble_gatts_value_set_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_gatts_value_t * const p_value,
uint32_t * const p_result_code);
/**@brief Encodes @ref sd_ble_gatts_sys_attr_get command request.
*
* @sa @ref ble_gatts_sys_attr_get_rsp_dec for command response decoder.
*
* @param[in] conn_handle Connection handle of the connection.
* @param[in] p_sys_attr_data Pointer to buffer where updated information about system
* attributes will be stored. Can be NULL to calculate required
* size.
* @param[in] p_sys_attr_data_len Size of p_sys_attr_data buffer if \p p_sys_attr_data is
* not NULL.
* @param[in] flags Additional optional flags.
* @param[in,out] p_buf Pointer to buffer where encoded data command will
* be returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command packet.
*
* @note \p p_sys_attr_data and \p p_sys_attr_data_len will not be updated by the command
* request encoder. Updated values are set by @ref ble_gatts_sys_attr_get_rsp_dec.
*
* @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_req_enc(uint16_t conn_handle,
uint8_t const * const p_sys_attr_data,
uint16_t const * const p_sys_attr_data_len,
uint32_t flags,
uint8_t * const p_buf,
uint32_t * p_buf_len);
/**@brief Decodes response to @ref sd_ble_gatts_sys_attr_get command.
*
* @sa @ref ble_gatts_sys_attr_get_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] pp_sys_attr_data Pointer to a buffer where updated information about system
* attributes will be stored.
* @param[in,out] pp_sys_attr_data_len \c in: Size (in bytes) of \p p_sys_attr_data buffer.
* \c out: Length of decoded contents of \p p_sys_attr_data.
* @param[out] p_result_code Command result code.
*
* @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_DATA_SIZE Length of \p p_sys_attr_data is too small to hold decoded
* value from response.
* @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match
* expected operation code.
*/
uint32_t ble_gatts_sys_attr_get_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint8_t * * const pp_sys_attr_data,
uint16_t * * const pp_sys_attr_data_len,
uint32_t * const p_result_code);
/**@brief Encodes @ref sd_ble_gatts_descriptor_add command request.
*
* @sa @ref ble_gatts_descriptor_add_rsp_dec for command response decoder.
*
* @param[in] char_handle Handle of the characteristic where the description is to be placed.
* If @ref BLE_GATT_HANDLE_INVALID is used, it will be placed
* sequentially.
* @param[in] p_attr Pointer to a @ref ble_gatts_attr_t structure, characteristic
* metadata.
* @param[in] p_handle Pointer to a @ref ble_gatts_char_handles_t structure, where the
* assigned handles will be stored.
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
* \c out: Length of encoded command 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_descriptor_add_req_enc(uint16_t char_handle,
ble_gatts_attr_t const * const p_attr,
uint16_t * const p_handle,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes response to @ref sd_ble_gatts_descriptor_add command.
*
* @sa @ref ble_gatts_descriptor_add_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_handle Pointer to bufer where descriptor handle will be
returned.
* @param[out] p_result_code Pointer to command result code decode location.
*
* @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. Decoded operation code does not match
* expected operation code.
*/
uint32_t ble_gatts_descriptor_add_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_handle,
uint32_t * const p_result_code);
/**@brief Encodes @ref sd_ble_gatts_include_add command request.
*
* @sa @ref ble_gatts_include_add_rsp_dec for command response decoder.
*
* @param[in] service_handle Handle of the service where the included service is to be placed.
* @param[in] inc_srvc_handle Handle of the included service
* @param[in] p_include_handle Pointer to Pointer to a 16-bit word where the assigned handle will be stored.
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
* \c out: Length of encoded command 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_include_add_req_enc(uint16_t service_handle,
uint16_t inc_srvc_handle,
uint16_t * const p_include_handle,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes response to @ref sd_ble_gatts_include_add command.
*
* @sa @ref ble_gatts_include_add_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_include_handle Pointer to a 16-bit word where the assigned handle will be stored.
* @param[out] p_result_code Pointer to command result code decode location.
*
* @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. Decoded operation code does not match
* expected operation code.
*/
uint32_t ble_gatts_include_add_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_include_handle,
uint32_t * const p_result_code);
/**@brief Encodes @ref sd_ble_gatts_rw_authorize_reply command request.
*
* @sa @ref ble_gatts_rw_authorize_reply_rsp_dec for command response decoder.
*
* @param[in] conn_handle Connection handle.
* @param[in] p_reply_params Pointer to \ref ble_gatts_rw_authorize_reply_params_t
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
* \c out: Length of encoded command 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.
* @retval NRF_ERROR_INVALID_PARAM Encoding failure. Invalid param provided in p_reply_params.
*/
uint32_t ble_gatts_rw_authorize_reply_req_enc(
uint16_t conn_handle,
ble_gatts_rw_authorize_reply_params_t const * const
p_reply_params,
uint8_t * const
p_buf,
uint32_t * const
p_buf_len);
/**@brief Decodes response to @ref sd_ble_gatts_rw_authorize_reply command.
*
* @sa @ref ble_gatts_rw_authorize_reply_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_result_code Command result code.
*
* @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. Decoded operation code does not match
* expected operation code.
*/
uint32_t ble_gatts_rw_authorize_reply_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code);
/**@brief Encodes @ref sd_ble_gatts_service_changed command request.
*
* @sa @ref ble_gatts_service_changed_rsp_dec for command response decoder.
*
* @param[in] conn_handle Connection handle.
* @param[in] start_handle Start of affected attribute handle range.
* @param[in] end_handle End of affected attribute handle range.
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
* \c out: Length of encoded command 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.
* @retval NRF_ERROR_INVALID_PARAM Encoding failure. Invalid param provided in p_reply_params.
*/
uint32_t ble_gatts_service_changed_req_enc(uint16_t conn_handle,
uint16_t start_handle,
uint16_t end_handle,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes response to @ref sd_ble_gatts_service_changed command.
*
* @sa @ref ble_gatts_service_changed_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_result_code Command result code.
*
* @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. Decoded operation code does not match
* expected operation code.
*/
uint32_t ble_gatts_service_changed_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code);
/**@brief Encodes @ref sd_ble_gatts_attr_get command request.
*
* @sa @ref ble_gatts_attr_get_rsp_dec for command response decoder.
*
* @param[in] handle See @ref sd_ble_gatts_attr_get.
* @param[in] p_uuid See @ref sd_ble_gatts_attr_get.
* @param[out] p_md See @ref sd_ble_gatts_attr_get.
* @param[in,out] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command 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_attr_get_req_enc(uint16_t handle,
ble_uuid_t * p_uuid,
ble_gatts_attr_md_t * p_md,
uint8_t * const p_buf,
uint32_t * p_buf_len);
/**@brief Decodes response to @ref sd_ble_gatts_attr_get command.
*
* @sa @ref ble_gatts_attr_get_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] pp_uuid Pointer to address where to put output data.
* @param[out] pp_md Pointer to address where to put output data.
* @param[out] p_result_code Command result code.
*
* @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. Decoded operation code does not match
* expected operation code.
*/
uint32_t ble_gatts_attr_get_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_uuid_t ** pp_uuid,
ble_gatts_attr_md_t ** pp_md,
uint32_t * const p_result_code);
/**@brief Encodes @ref sd_ble_gatts_initial_user_handle_get command request.
*
* @sa @ref ble_gatts_initial_user_handle_get_rsp_dec for command response decoder.
*
* @param[out] p_handle See @ref sd_ble_gatts_initial_user_handle_get.
* @param[in,out] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command 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_initial_user_handle_get_req_enc(uint16_t * p_handle,
uint8_t * const p_buf,
uint32_t * p_buf_len);
/**@brief Decodes response to @ref sd_ble_gatts_initial_user_handle_get command.
*
* @sa @ref ble_gatts_initial_user_handle_get_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] pp_handle Pointer to address where to put output data.
* @param[out] p_result_code Command result code.
*
* @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. Decoded operation code does not match
* expected operation code.
*/
uint32_t ble_gatts_initial_user_handle_get_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t ** pp_handle,
uint32_t * const p_result_code);
/**@brief Encodes @ref sd_ble_gatts_exchange_mtu_reply command request.
*
* @sa @ref ble_gatts_exchange_mtu_reply_rsp_dec for command response decoder.
*
* @param[in] conn_handle Connection handle.
* @param[in] server_rx_mtu Server MTU Size.
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
* \c out: Length of encoded command 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.
* @retval NRF_ERROR_INVALID_PARAM Encoding failure. Invalid param provided in p_reply_params.
*/
uint32_t ble_gatts_exchange_mtu_reply_req_enc(uint16_t conn_handle,
uint16_t server_rx_mtu,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes response to @ref sd_ble_gatts_exchange_mtu_reply command.
*
* @sa @ref ble_gatts_exchange_mtu_reply_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_result_code Command result code.
*
* @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. Decoded operation code does not match
* expected operation code.
*/
uint32_t ble_gatts_exchange_mtu_reply_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code);
/** @} */
#ifdef __cplusplus
}
#endif
#endif //BLE_GATTS_APP_H__

View File

@@ -0,0 +1,190 @@
/**
* 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_gatts_evt_app.h"
#include "ble_serialization.h"
#include "ble_gatts_struct_serialization.h"
#include "app_ble_user_mem.h"
#include "app_util.h"
extern ser_ble_user_mem_t m_app_user_mem_table[];
uint32_t ble_gatts_evt_hvc_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GATTS_EVT_HVC, gatts, hvc);
SER_PULL_uint16(&p_event->evt.gatts_evt.conn_handle);
SER_PULL_FIELD(&p_event->evt.gatts_evt.params.hvc,
ble_gatts_evt_hvc_t_dec);
SER_EVT_DEC_END;
}
uint32_t ble_gatts_evt_rw_authorize_request_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GATTS_EVT_HVC, gatts, rw_authorize_request);
SER_PULL_uint16(&p_event->evt.gatts_evt.conn_handle);
SER_PULL_FIELD_EXTENDED(&p_event->evt.gatts_evt.params.authorize_request, ble_gatts_evt_rw_authorize_request_t_dec);
//Correct event length / memory sync.
if (p_event->evt.gatts_evt.params.authorize_request.type == BLE_GATTS_AUTHORIZE_TYPE_READ)
{
evt_struct_len = offsetof(ble_evt_t, evt.gatts_evt.params.authorize_request.request.read)
- offsetof(ble_evt_t, evt)
+ sizeof(ble_gatts_evt_read_t);
}
else 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 (app_ble_user_mem_context_find(p_event->evt.gatts_evt.conn_handle, &conn_index) != NRF_ERROR_NOT_FOUND)
{
SER_PULL_len16data(&m_app_user_mem_table[conn_index].mem_block.p_mem, &m_app_user_mem_table[conn_index].mem_block.len);
}
}
SER_EVT_DEC_END;
}
uint32_t ble_gatts_evt_sc_confirm_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN_NO_STRUCT(BLE_GATTS_EVT_SC_CONFIRM, gatts);
SER_PULL_uint16(&p_event->evt.gatts_evt.conn_handle);
SER_EVT_DEC_END;
}
uint32_t ble_gatts_evt_sys_attr_missing_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GATTS_EVT_SYS_ATTR_MISSING, gatts, sys_attr_missing);
SER_PULL_uint16(&p_event->evt.gatts_evt.conn_handle);
SER_PULL_FIELD(&p_event->evt.gatts_evt.params.sys_attr_missing,
ble_gatts_evt_sys_attr_missing_t_dec);
SER_EVT_DEC_END;
}
uint32_t ble_gatts_evt_timeout_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GATTS_EVT_TIMEOUT, gatts, timeout);
SER_PULL_uint16(&p_event->evt.gatts_evt.conn_handle);
SER_PULL_FIELD(&p_event->evt.gatts_evt.params.timeout,
ble_gatts_evt_timeout_t_dec);
SER_EVT_DEC_END;
}
uint32_t ble_gatts_evt_write_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GATTS_EVT_WRITE, gatts, write);
SER_PULL_uint16(&p_event->evt.gatts_evt.conn_handle);
SER_PULL_FIELD_EXTENDED(&p_event->evt.gatts_evt.params.write, ble_gatts_evt_write_t_dec);
if (p_event != NULL)
{
if (p_event->evt.gatts_evt.params.write.op == BLE_GATTS_OP_EXEC_WRITE_REQ_NOW)
{
uint32_t conn_index;
if (app_ble_user_mem_context_find(p_event->evt.gatts_evt.conn_handle, &conn_index) != NRF_ERROR_NOT_FOUND)
{
SER_PULL_len16data(&m_app_user_mem_table[conn_index].mem_block.p_mem, &m_app_user_mem_table[conn_index].mem_block.len);
SER_ASSERT(err_code == NRF_SUCCESS, err_code);
}
}
}
SER_EVT_DEC_END;
}
uint32_t ble_gatts_evt_exchange_mtu_request_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST, gatts, exchange_mtu_request);
SER_PULL_uint16(&p_event->evt.gatts_evt.conn_handle);
SER_PULL_FIELD(&p_event->evt.gatts_evt.params.exchange_mtu_request, ble_gatts_evt_exchange_mtu_request_t_dec);
SER_EVT_DEC_END;
}
#if NRF_SD_BLE_API_VERSION >= 4
uint32_t ble_gatts_evt_hvn_tx_complete_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_GATTS_EVT_HVN_TX_COMPLETE, gatts, hvn_tx_complete);
SER_PULL_uint16(&p_event->evt.gatts_evt.conn_handle);
SER_PULL_uint8(&p_event->evt.gatts_evt.params.hvn_tx_complete.count);
SER_EVT_DEC_END;
}
#endif

View File

@@ -0,0 +1,249 @@
/**
* 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_APP_H__
#define BLE_GATTS_EVT_APP_H__
/**@file
*
* @defgroup ble_gatts_evt_app GATTS Application event decoders
* @{
* @ingroup ser_app_s130_codecs
*
* @brief GATTS Application event decoders.
*/
#include "ble.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Decodes ble_gatts_evt_hvc event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gatts_evt_hvc_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gatts_evt_rw_authorize_request event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gatts_evt_rw_authorize_request_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gatts_evt_sc_confirm event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gatts_evt_sc_confirm_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gatts_evt_sys_attr_missing event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gatts_evt_sys_attr_missing_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gatts_evt_timeout event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gatts_evt_timeout_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gatts_evt_write event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gatts_evt_write_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/**
* @brief Decodes ble_gatts_evt_exchange_mtu_request event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gatts_evt_exchange_mtu_request_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
#if NRF_SD_BLE_API_VERSION >= 4
/**
* @brief Decodes ble_gatts_evt_hvn_tx_complete event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_gatts_evt_hvn_tx_complete_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
#endif
/** @} */
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,279 @@
/**
* 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_l2cap_app.h"
#include "ble_serialization.h"
#include "ble_struct_serialization.h"
#include "ble_l2cap_struct_serialization.h"
#include "ble_gap.h"
#include "app_util.h"
#include "cond_field_serialization.h"
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
uint32_t ble_l2cap_cid_register_req_enc(uint16_t cid,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
uint32_t index = 0;
uint32_t err_code = NRF_SUCCESS;
SER_ASSERT_NOT_NULL(p_buf);
SER_ASSERT_NOT_NULL(p_buf_len);
SER_ASSERT_LENGTH_LEQ(index + 3, *p_buf_len);
p_buf[index++] = SD_BLE_L2CAP_CID_REGISTER;
err_code = uint16_t_enc(&cid, p_buf, *p_buf_len, &index);
SER_ASSERT(err_code == NRF_SUCCESS, err_code);
*p_buf_len = index;
return err_code;
}
uint32_t ble_l2cap_cid_register_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code)
{
return ser_ble_cmd_rsp_dec(p_buf, packet_len, SD_BLE_L2CAP_CID_REGISTER, p_result_code);
}
uint32_t ble_l2cap_cid_unregister_req_enc(uint16_t cid,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
uint32_t index = 0;
uint32_t err_code = NRF_SUCCESS;
SER_ASSERT_NOT_NULL(p_buf);
SER_ASSERT_NOT_NULL(p_buf_len);
SER_ASSERT_LENGTH_LEQ(index + 3, *p_buf_len);
p_buf[index++] = SD_BLE_L2CAP_CID_UNREGISTER;
err_code = uint16_t_enc(&cid, p_buf, *p_buf_len, &index);
SER_ASSERT(err_code == NRF_SUCCESS, err_code);
*p_buf_len = index;
return err_code;
}
uint32_t ble_l2cap_cid_unregister_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code)
{
return ser_ble_cmd_rsp_dec(p_buf, packet_len, SD_BLE_L2CAP_CID_UNREGISTER, p_result_code);
}
uint32_t ble_l2cap_tx_req_enc(uint16_t conn_handle,
ble_l2cap_header_t const * const p_l2cap_header,
uint8_t const * const p_data,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
uint32_t index = 0;
uint32_t err_code = NRF_SUCCESS;
SER_ASSERT_NOT_NULL(p_buf);
SER_ASSERT_NOT_NULL(p_buf_len);
SER_ASSERT_LENGTH_LEQ(1, *p_buf_len);
p_buf[index++] = SD_BLE_L2CAP_TX;
err_code = uint16_t_enc(&conn_handle, p_buf, *p_buf_len, &index);
SER_ASSERT(err_code == NRF_SUCCESS, err_code);
err_code = cond_field_enc(p_l2cap_header, p_buf, *p_buf_len, &index, ble_l2cap_header_t_enc);
SER_ASSERT(err_code == NRF_SUCCESS, err_code);
if (p_l2cap_header != NULL)
{
err_code = buf_enc(p_data, p_l2cap_header->len, p_buf, *p_buf_len, &index);
}
else
{
err_code = buf_enc(NULL, 0, p_buf, *p_buf_len, &index);
}
*p_buf_len = index;
return err_code;
}
uint32_t ble_l2cap_tx_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code)
{
return ser_ble_cmd_rsp_dec(p_buf, packet_len, SD_BLE_L2CAP_TX, p_result_code);
}
#endif
#if NRF_SD_BLE_API_VERSION >= 5
uint32_t ble_l2cap_ch_setup_req_enc(uint16_t conn_handle,
uint16_t * p_local_cid,
ble_l2cap_ch_setup_params_t const *p_params,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_L2CAP_CH_SETUP);
SER_PUSH_uint16(&conn_handle);
SER_PUSH_COND(p_local_cid, uint16_t_enc);
SER_PUSH_COND(p_params, ble_l2cap_ch_setup_params_t_enc);
SER_REQ_ENC_END;
}
uint32_t ble_l2cap_ch_setup_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * p_local_cid,
uint32_t * const p_result_code)
{
SER_RSP_DEC_BEGIN(SD_BLE_L2CAP_CH_SETUP);
SER_PULL_COND((void **)&p_local_cid, uint16_t_dec);
SER_RSP_DEC_END;
}
uint32_t ble_l2cap_ch_release_req_enc(uint16_t conn_handle,
uint16_t local_cid,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_L2CAP_CH_RELEASE);
SER_PUSH_uint16(&conn_handle);
SER_PUSH_uint16(&local_cid);
SER_REQ_ENC_END;
}
uint32_t ble_l2cap_ch_release_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code)
{
SER_RSP_DEC_RESULT_ONLY(SD_BLE_L2CAP_CH_RELEASE);
}
uint32_t ble_l2cap_ch_rx_req_enc(uint16_t conn_handle,
uint16_t local_cid,
ble_data_t const *p_sdu_buf,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_L2CAP_CH_RX);
SER_PUSH_uint16(&conn_handle);
SER_PUSH_uint16(&local_cid);
SER_PUSH_COND(p_sdu_buf, NULL);
if (p_sdu_buf)
{
SER_PUSH_uint16(&p_sdu_buf->len);
SER_PUSH_uint32(&p_sdu_buf->p_data);
}
SER_REQ_ENC_END;
}
uint32_t ble_l2cap_ch_rx_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code)
{
SER_RSP_DEC_RESULT_ONLY(SD_BLE_L2CAP_CH_RX);
}
uint32_t ble_l2cap_ch_tx_req_enc(uint16_t conn_handle,
uint16_t local_cid,
ble_data_t const *p_sdu_buf,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_L2CAP_CH_TX);
SER_PUSH_uint16(&conn_handle);
SER_PUSH_uint16(&local_cid);
SER_PUSH_COND(p_sdu_buf, NULL);
if (p_sdu_buf)
{
SER_PUSH_uint32(&p_sdu_buf->p_data);
SER_PUSH_uint16(&p_sdu_buf->len);
SER_PUSH_buf(p_sdu_buf->p_data, p_sdu_buf->len);
}
SER_REQ_ENC_END;
}
uint32_t ble_l2cap_ch_tx_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code)
{
SER_RSP_DEC_RESULT_ONLY(SD_BLE_L2CAP_CH_TX);
}
uint32_t ble_l2cap_ch_flow_control_req_enc(uint16_t conn_handle,
uint16_t local_cid,
uint16_t credits,
uint16_t *p_credits,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_BLE_L2CAP_CH_FLOW_CONTROL);
SER_PUSH_uint16(&conn_handle);
SER_PUSH_uint16(&local_cid);
SER_PUSH_uint16(&credits);
SER_PUSH_COND(p_credits, NULL);
SER_REQ_ENC_END;
}
uint32_t ble_l2cap_ch_flow_control_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * p_credits,
uint32_t * const p_result_code)
{
SER_RSP_DEC_BEGIN(SD_BLE_L2CAP_CH_FLOW_CONTROL);
SER_PULL_COND((void **)&p_credits, uint16_t_dec);
SER_RSP_DEC_END;
}
#endif //NRF_SD_BLE_API_VERSION >= 5

View File

@@ -0,0 +1,242 @@
/**
* 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.
*
*/
/**@file
*
* @defgroup ble_l2cap_app L2CAP Application command request encoders and command response decoders
* @{
* @ingroup ser_app_s130_codecs
*
* @brief L2CAP Application command request encoders and command response decoders.
*/
#ifndef BLE_L2CAP_APP_H__
#define BLE_L2CAP_APP_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 Register a CID with L2CAP.
*
* @details This registers a higher protocol layer with the L2CAP multiplexer, and is required prior to all operations on the CID.
*
* @param[in] cid L2CAP CID.
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
* \c out: Length of encoded command 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_req_enc(uint16_t cid,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Decodes response to @ref sd_ble_l2cap_cid_register command.
*
* @sa @ref ble_l2cap_cid_register_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_result_code Command result code.
*
* @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. Decoded operation code does not match
* expected operation code.
*/
uint32_t ble_l2cap_cid_register_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code);
/**@brief Unregister a CID with L2CAP.
*
* @details This unregisters a previously registered higher protocol layer with the L2CAP multiplexer.
*
* @param[in] cid L2CAP CID.
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in,out] p_buf_len \c in: Size of \p p_buf buffer.
* \c out: Length of encoded command 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_req_enc(uint16_t cid,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Decodes response to @ref sd_ble_l2cap_cid_unregister command.
*
* @sa @ref ble_l2cap_cid_unregister_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_result_code Command result code.
*
* @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. Decoded operation code does not match
* expected operation code.
*/
uint32_t ble_l2cap_cid_unregister_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code);
/**@brief Transmit an L2CAP packet.
*
* @note It is important to note that a call to this function will <b>consume an application buffer</b>, and will therefore
* generate a @ref BLE_EVT_TX_COMPLETE event when the packet has been transmitted.
* See the documentation of @ref sd_ble_tx_packet_count_get for more details.
*
* @param[in] conn_handle Connection handle.
* @param[in] p_l2cap_header Pointer to a packet header containing length and CID.
* @param[in] p_data Pointer to the data to be transmitted.
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in,out] p_buf_len\ c in: Size of \p p_buf buffer.
* \c out: Length of encoded command packet.
*
* @retval NRF_SUCCESS Successfully queued an L2CAP packet for transmission.
* @retval NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @retval NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, CIDs must be registered beforehand with @ref sd_ble_l2cap_cid_register.
* @retval NRF_ERROR_NOT_FOUND CID not found.
* @retval NRF_ERROR_NO_MEM Not enough memory to complete operation.
* @retval NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, see @ref BLE_L2CAP_MTU_DEF.
*/
uint32_t ble_l2cap_tx_req_enc(uint16_t conn_handle,
ble_l2cap_header_t const * const p_l2cap_header,
uint8_t const * const p_data,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Decodes response to @ref sd_ble_l2cap_tx command.
*
* @sa @ref ble_l2cap_tx_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_result_code Command result code.
*
* @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. Decoded operation code does not match
* expected operation code.
*/
uint32_t ble_l2cap_tx_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code);
#endif
#if NRF_SD_BLE_API_VERSION >= 5
uint32_t ble_l2cap_ch_setup_req_enc(uint16_t conn_handle,
uint16_t * p_local_cid,
ble_l2cap_ch_setup_params_t const *p_params,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
uint32_t ble_l2cap_ch_setup_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * p_local_cid,
uint32_t * const p_result_code);
uint32_t ble_l2cap_ch_release_req_enc(uint16_t conn_handle,
uint16_t local_cid,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
uint32_t ble_l2cap_ch_release_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code);
uint32_t ble_l2cap_ch_rx_req_enc(uint16_t conn_handle,
uint16_t local_cid,
ble_data_t const *p_sdu_buf,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
uint32_t ble_l2cap_ch_rx_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code);
uint32_t ble_l2cap_ch_tx_req_enc(uint16_t conn_handle,
uint16_t local_cid,
ble_data_t const *p_sdu_buf,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
uint32_t ble_l2cap_ch_tx_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code);
uint32_t ble_l2cap_ch_flow_control_req_enc(uint16_t conn_handle,
uint16_t local_cid,
uint16_t credits,
uint16_t *p_credits,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
uint32_t ble_l2cap_ch_flow_control_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * p_credits,
uint32_t * const p_result_code);
#endif //NRF_SD_BLE_API_VERSION >= 5
#ifdef __cplusplus
}
#endif
#endif //BLE_L2CAP_APP_H__
/**
@}
*/

View File

@@ -0,0 +1,183 @@
/**
* 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_serialization.h"
#include "ble_struct_serialization.h"
#include "ble_l2cap_struct_serialization.h"
#include "app_util.h"
#include "ble_l2cap_evt_app.h"
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
uint32_t ble_l2cap_evt_rx_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_L2CAP_EVT_RX, l2cap, rx);
SER_PULL_uint16(&p_event->evt.l2cap_evt.conn_handle);
SER_PULL_FIELD_EXTENDED(&p_event->evt.l2cap_evt.params.rx, ble_l2cap_evt_rx_t_dec);
SER_EVT_DEC_END;
}
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION >= 5
uint32_t ble_l2cap_evt_ch_setup_request_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_L2CAP_EVT_CH_SETUP_REQUEST, l2cap, ch_setup_request);
SER_PULL_uint16(&p_event->evt.l2cap_evt.conn_handle);
SER_PULL_uint16(&p_event->evt.l2cap_evt.local_cid);
SER_PULL_uint16(&p_event->evt.l2cap_evt.params.ch_setup_request.le_psm);
SER_PULL_FIELD(&p_event->evt.l2cap_evt.params.ch_setup_request.tx_params, ble_l2cap_ch_tx_params_t_dec);
SER_EVT_DEC_END;
}
uint32_t ble_l2cap_evt_ch_setup_refused_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_L2CAP_EVT_CH_SETUP_REFUSED, l2cap, ch_setup_refused);
SER_PULL_uint16(&p_event->evt.l2cap_evt.conn_handle);
SER_PULL_uint16(&p_event->evt.l2cap_evt.local_cid);
SER_PULL_uint8(&p_event->evt.l2cap_evt.params.ch_setup_refused.source);
SER_PULL_uint16(&p_event->evt.l2cap_evt.params.ch_setup_refused.status);
SER_EVT_DEC_END;
}
uint32_t ble_l2cap_evt_ch_setup_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_L2CAP_EVT_CH_SETUP, l2cap, ch_setup);
SER_PULL_uint16(&p_event->evt.l2cap_evt.conn_handle);
SER_PULL_uint16(&p_event->evt.l2cap_evt.local_cid);
SER_PULL_FIELD(&p_event->evt.l2cap_evt.params.ch_setup.tx_params, ble_l2cap_ch_tx_params_t_dec);
SER_EVT_DEC_END;
}
uint32_t ble_l2cap_evt_ch_released_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN_NO_STRUCT(BLE_L2CAP_EVT_CH_RELEASED, l2cap);
SER_PULL_uint16(&p_event->evt.l2cap_evt.conn_handle);
SER_PULL_uint16(&p_event->evt.l2cap_evt.local_cid);
SER_EVT_DEC_END;
}
uint32_t ble_l2cap_evt_ch_sdu_buf_released_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_L2CAP_EVT_CH_SDU_BUF_RELEASED, l2cap, ch_sdu_buf_released);
SER_PULL_uint16(&p_event->evt.l2cap_evt.conn_handle);
SER_PULL_uint16(&p_event->evt.l2cap_evt.local_cid);
SER_PULL_uint16(&p_event->evt.l2cap_evt.params.ch_sdu_buf_released.sdu_buf.len);
SER_PULL_uint32(&p_event->evt.l2cap_evt.params.ch_sdu_buf_released.sdu_buf.p_data);
SER_EVT_DEC_END;
}
uint32_t ble_l2cap_evt_ch_credit_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_L2CAP_EVT_CH_CREDIT, l2cap, ch_credit);
SER_PULL_uint16(&p_event->evt.l2cap_evt.conn_handle);
SER_PULL_uint16(&p_event->evt.l2cap_evt.local_cid);
SER_PULL_uint16(&p_event->evt.l2cap_evt.params.credit.credits);
SER_EVT_DEC_END;
}
uint32_t ble_l2cap_evt_ch_rx_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_L2CAP_EVT_CH_RX, l2cap, ch_rx);
SER_PULL_uint16(&p_event->evt.l2cap_evt.conn_handle);
SER_PULL_uint16(&p_event->evt.l2cap_evt.local_cid);
SER_PULL_uint16(&p_event->evt.l2cap_evt.params.rx.sdu_len);
SER_PULL_uint16(&p_event->evt.l2cap_evt.params.rx.sdu_buf.len);
SER_PULL_uint32(&p_event->evt.l2cap_evt.params.rx.sdu_buf.p_data);
SER_PULL_buf(&p_event->evt.l2cap_evt.params.rx.sdu_buf.p_data, p_event->evt.l2cap_evt.params.rx.sdu_buf.len, p_event->evt.l2cap_evt.params.rx.sdu_buf.len);
SER_EVT_DEC_END;
}
uint32_t ble_l2cap_evt_ch_tx_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len)
{
SER_EVT_DEC_BEGIN(BLE_L2CAP_EVT_CH_TX, l2cap, ch_tx);
SER_PULL_uint16(&p_event->evt.l2cap_evt.conn_handle);
SER_PULL_uint16(&p_event->evt.l2cap_evt.local_cid);
SER_PULL_uint16(&p_event->evt.l2cap_evt.params.tx.sdu_buf.len);
SER_PULL_uint32(&p_event->evt.l2cap_evt.params.tx.sdu_buf.p_data);
SER_EVT_DEC_END;
}
#endif

View File

@@ -0,0 +1,126 @@
/**
* 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_APP_H__
#define BLE_L2CAP_EVT_APP_H__
/**@file
*
* @defgroup ble_l2cap_evt_app L2CAP Application event decoders
* @{
* @ingroup ser_app_s130_codecs
*
* @brief L2CAP Application event decoders.
*/
#include "ble.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Decodes ble_l2cap_evt_rx event.
*
* If \p p_event is null, the required length of \p p_event is returned in \p p_event_len.
*
* @param[in] p_buf Pointer to the beginning of an event packet.
* @param[in] packet_len Length (in bytes) of the event packet.
* @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be
* stored. If NULL, required length will be returned in \p p_event_len.
* @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer.
* \c out: Length of decoded contents of \p p_event.
*
* @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_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ble_l2cap_evt_rx_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
uint32_t ble_l2cap_evt_ch_setup_request_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
uint32_t ble_l2cap_evt_ch_setup_refused_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
uint32_t ble_l2cap_evt_ch_setup_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
uint32_t ble_l2cap_evt_ch_released_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
uint32_t ble_l2cap_evt_ch_sdu_buf_released_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
uint32_t ble_l2cap_evt_ch_credit_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
uint32_t ble_l2cap_evt_ch_rx_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
uint32_t ble_l2cap_evt_ch_tx_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_evt_t * const p_event,
uint32_t * const p_event_len);
/** @} */
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,95 @@
/**
* 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 "nrf_soc_app.h"
#include "nrf_soc.h"
#include <stdlib.h>
#include <string.h>
#include "ble_serialization.h"
#include "cond_field_serialization.h"
#include "nrf_soc_struct_serialization.h"
#include "app_util.h"
uint32_t ecb_block_encrypt_req_enc(nrf_ecb_hal_data_t * p_ecb_data,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_ECB_BLOCK_ENCRYPT);
SER_PUSH_COND(p_ecb_data, nrf_ecb_hal_data_t_in_enc);
SER_REQ_ENC_END;
}
uint32_t ecb_block_encrypt_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
nrf_ecb_hal_data_t * * const pp_ecb_data,
uint32_t * const p_result_code)
{
SER_RSP_DEC_BEGIN(SD_ECB_BLOCK_ENCRYPT);
SER_PULL_COND(pp_ecb_data, nrf_ecb_hal_data_t_out_dec);
SER_RSP_DEC_END;
}
uint32_t power_system_off_req_enc(uint8_t * const p_buf, uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_POWER_SYSTEM_OFF);
SER_REQ_ENC_END;
}
uint32_t temp_get_req_enc(int32_t const * const p_temp,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_REQ_ENC_BEGIN(SD_TEMP_GET);
SER_PUSH_COND(p_temp, NULL);
SER_REQ_ENC_END;
}
uint32_t temp_get_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code,
int32_t * * const pp_temp)
{
SER_RSP_DEC_BEGIN(SD_TEMP_GET);
SER_PULL_COND(pp_temp, uint32_t_dec);
SER_RSP_DEC_END;
}

View File

@@ -0,0 +1,147 @@
/**
* 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.
*
*/
/**@file
*
* @defgroup soc_app SOC Application command request encoders and command response decoders
* @{
* @ingroup ser_app_s130_codecs
*
* @brief SOC Application command request encoders and command response decoders.
*/
#ifndef NRF_SOC_APP_H__
#define NRF_SOC_APP_H__
#include <stdint.h>
#include "nrf_soc.h"
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Encodes @ref sd_power_system_off command request.
*
*
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in,out] p_buf_len \c in: size of p_buf buffer. \c out: Length of encoded command 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 power_system_off_req_enc(uint8_t * const p_buf, uint32_t * const p_buf_len);
/**@brief Encodes @ref sd_temp_get command request.
*
* @sa @ref temp_get_rsp_dec for command response decoder.
*
* @param[in] p_temp Pointer to result of temperature measurement.
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in,out] p_buf_len \c in: size of p_buf buffer. \c out: Length of encoded command 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 temp_get_req_enc(int32_t const * const p_temp,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes response to @ref sd_temp_get command.
*
* @sa @ref temp_get_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_result_code Command result code.
* @param[out] pp_temp Pointer to result of temperature measurement.
*
* @retval NRF_SUCCESS Version information stored successfully.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t temp_get_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * const p_result_code,
int32_t * * const pp_temp);
/**@brief Encodes @ref sd_ecb_block_encrypt command request.
*
* @sa @ref ecb_block_encrypt_rsp_dec for command response decoder.
*
* @param[in] p_ecb_data Pointer to ECB data.
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in,out] p_buf_len \c in: size of p_buf buffer. \c out: Length of encoded command 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 ecb_block_encrypt_req_enc(nrf_ecb_hal_data_t * p_ecb_data,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes response to @ref sd_ecb_block_encrypt command.
*
* @sa @ref ecb_block_encrypt_req_enc for command request encoder.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_ecb_data Pointer to ECB data.
* @param[out] p_result_code Command result code.
*
* @retval NRF_SUCCESS Version information stored successfully.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to
* hold decoded event.
*/
uint32_t ecb_block_encrypt_rsp_dec(uint8_t const * const p_buf,
uint32_t packet_len,
nrf_ecb_hal_data_t * * const p_ecb_data,
uint32_t * const p_result_code);
/** @} */
#ifdef __cplusplus
}
#endif
#endif // NRF_SOC_APP_H__