diff options
Diffstat (limited to 'thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble')
33 files changed, 14467 insertions, 0 deletions
diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble.c new file mode 100644 index 0000000..5aa5571 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble.c @@ -0,0 +1,621 @@ +/** + * Copyright (c) 2014 - 2018, 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" + +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; + + 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; + + 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 diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble_gap.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble_gap.c new file mode 100644 index 0000000..55cc2fa --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble_gap.c @@ -0,0 +1,2025 @@ +/** + * Copyright (c) 2014 - 2018, 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 <string.h> +#include "ble_serialization.h" +#include "ser_sd_transport.h" +#include "ble_gap_app.h" +#include "app_error.h" +#include "app_ble_gap_sec_keys.h" +#include "ser_config.h" + +extern ser_ble_gap_app_keyset_t m_app_keys_table[SER_MAX_CONNECTIONS]; + +/**@brief Structure containing @ref sd_ble_gap_device_name_get output parameters. */ +typedef struct +{ + uint8_t * p_dev_name; /**< @ref sd_ble_gap_device_name_get p_dev_name output parameter. */ + uint16_t * p_len; /**< @ref sd_ble_gap_device_name_get p_len output parameter. */ +} gap_device_name_get_output_params_t; + +/**@brief Structure containing @ref sd_ble_gap_appearance_get output parameters. */ +typedef struct +{ + uint16_t * p_appearance; /**< @ref sd_ble_gap_appearance_get p_appearance output parameter. */ +} gap_appearance_get_output_params_t; + +/**@brief Structure containing @ref sd_ble_gap_ppcp_get output parameters. */ +typedef struct +{ + ble_gap_conn_params_t * p_conn_params; /**< @ref sd_ble_gap_ppcp_get p_conn_params output parameter. */ +} gap_ppcp_get_out_params_t; + +/**@brief Structure containing @ref sd_ble_gap_sec_params_reply output parameters. */ +typedef struct +{ + ble_gap_sec_keyset_t const * p_sec_keyset; /**< @ref sd_ble_gap_sec_params_reply p_sec_keyset output parameter. */ + uint16_t conn_handle; /**< @ref sd_ble_gap_sec_params_reply p_conn_handle output parameter. */ +} gap_sec_params_reply_out_params_t; + +/**@brief Union containing BLE command output parameters. */ +typedef union +{ + gap_device_name_get_output_params_t gap_device_name_get_out_params; /**< @ref sd_ble_gap_device_name_get output parameters. */ + gap_appearance_get_output_params_t gap_appearance_get_out_params; /**< @ref sd_ble_gap_appearance_get output parameters. */ + gap_ppcp_get_out_params_t gap_ppcp_get_out_params; /**< @ref sd_ble_gap_ppcp_get output parameters. */ + gap_sec_params_reply_out_params_t gap_sec_params_reply_out_params;/**< @ref sd_ble_sec_params_reply output parameters. */ +} gap_command_output_params_t; + +static gap_command_output_params_t m_output_params; /**< BLE command output parameters. */ + +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_gap_adv_start 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 gap_adv_start_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gap_adv_start_rsp_dec(p_buffer, length, &result_code); + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_adv_start +#define _sd_ble_gap_adv_start sd_ble_gap_adv_start +#endif +uint32_t _sd_ble_gap_adv_start( +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t adv_handle +#else + ble_gap_adv_params_t const * const p_adv_params +#endif +#if NRF_SD_BLE_API_VERSION >= 4 + ,uint8_t conn_cfg_tag +#endif +) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + + const uint32_t err_code = ble_gap_adv_start_req_enc( +#if NRF_SD_BLE_API_VERSION > 5 + adv_handle, +#else + p_adv_params, +#endif +#if NRF_SD_BLE_API_VERSION >= 4 + conn_cfg_tag, +#endif + &(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), + gap_adv_start_rsp_dec); +} + +/**@brief Command response callback function for @ref ble_gap_device_name_get_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 gap_device_name_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = + ble_gap_device_name_get_rsp_dec(p_buffer, + length, + m_output_params.gap_device_name_get_out_params.p_dev_name, + m_output_params.gap_device_name_get_out_params.p_len, + &result_code); + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_device_name_get +#define _sd_ble_gap_device_name_get sd_ble_gap_device_name_get +#endif +uint32_t _sd_ble_gap_device_name_get(uint8_t * const p_dev_name, uint16_t * const p_len) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + m_output_params.gap_device_name_get_out_params.p_dev_name = p_dev_name; + m_output_params.gap_device_name_get_out_params.p_len = p_len; + + const uint32_t err_code = ble_gap_device_name_get_req_enc(p_dev_name, + p_len, + &(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), + gap_device_name_get_rsp_dec); +} + + +/**@brief Command response callback function for @ref sd_ble_gap_appearance_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 gap_appearance_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = + ble_gap_appearance_get_rsp_dec(p_buffer, + length, + m_output_params.gap_appearance_get_out_params.p_appearance, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_appearance_get +#define _sd_ble_gap_appearance_get sd_ble_gap_appearance_get +#endif +uint32_t _sd_ble_gap_appearance_get(uint16_t * const p_appearance) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + m_output_params.gap_appearance_get_out_params.p_appearance = p_appearance; + + const uint32_t err_code = ble_gap_appearance_get_req_enc(p_appearance, + &(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), + gap_appearance_get_rsp_dec); +} + + +/**@brief Command response callback function for @ref sd_ble_gap_device_name_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 gap_device_name_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gap_device_name_set_rsp_dec(p_buffer, length, &result_code); + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_device_name_set +#define _sd_ble_gap_device_name_set sd_ble_gap_device_name_set +#endif +uint32_t _sd_ble_gap_device_name_set(ble_gap_conn_sec_mode_t const * const p_write_perm, + uint8_t const * const p_dev_name, + uint16_t len) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_device_name_set_req_enc(p_write_perm, + p_dev_name, + len, + &(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), + gap_device_name_set_rsp_dec); +} + + +/**@brief Command response callback function for @ref sd_ble_gap_appearance_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 gap_appearance_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gap_appearance_set_rsp_dec(p_buffer, length, &result_code); + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_appearance_set +#define _sd_ble_gap_appearance_set sd_ble_gap_appearance_set +#endif +uint32_t _sd_ble_gap_appearance_set(uint16_t appearance) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_appearance_set_req_enc(appearance, + &(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), + gap_appearance_set_rsp_dec); +} + + +/**@brief Command response callback function for @ref sd_ble_gap_ppcp_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 gap_ppcp_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gap_ppcp_set_rsp_dec(p_buffer, length, &result_code); + + APP_ERROR_CHECK(err_code); + + + return result_code; +} + +#ifndef _sd_ble_gap_ppcp_set +#define _sd_ble_gap_ppcp_set sd_ble_gap_ppcp_set +#endif +uint32_t _sd_ble_gap_ppcp_set(ble_gap_conn_params_t const * const p_conn_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_gap_ppcp_set_req_enc(p_conn_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), + gap_ppcp_set_rsp_dec); +} + + +/**@brief Command response callback function for @ref sd_ble_gap_adv_data_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. + */ +#if NRF_SD_BLE_API_VERSION <= 5 +static uint32_t gap_adv_data_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gap_adv_data_set_rsp_dec(p_buffer, length, &result_code); + + APP_ERROR_CHECK(err_code); + + return result_code; +} +#ifndef _sd_ble_gap_adv_data_set +#define _sd_ble_gap_adv_data_set sd_ble_gap_adv_data_set +#endif +uint32_t _sd_ble_gap_adv_data_set(uint8_t const * const p_data, + uint8_t dlen, + uint8_t const * const p_sr_data, + uint8_t srdlen) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_adv_data_set_req_enc(p_data, + dlen, + p_sr_data, + srdlen, + &(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), + gap_adv_data_set_rsp_dec); +} +#endif + +/**@brief Command response callback function for @ref sd_ble_gap_conn_param_update 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 gap_conn_param_update_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gap_conn_param_update_rsp_dec(p_buffer, length, &result_code); + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_conn_param_update +#define _sd_ble_gap_conn_param_update sd_ble_gap_conn_param_update +#endif +uint32_t _sd_ble_gap_conn_param_update(uint16_t conn_handle, + ble_gap_conn_params_t const * const p_conn_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_gap_conn_param_update_req_enc(conn_handle, + p_conn_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), + gap_conn_param_update_rsp_dec); +} + + +/**@brief Command response callback function for @ref sd_ble_gap_disconnect 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 gap_disconnect_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gap_disconnect_rsp_dec(p_buffer, length, &result_code); + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_disconnect +#define _sd_ble_gap_disconnect sd_ble_gap_disconnect +#endif +uint32_t _sd_ble_gap_disconnect(uint16_t conn_handle, uint8_t hci_status_code) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_disconnect_req_enc(conn_handle, + hci_status_code, + &(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), + gap_disconnect_rsp_dec); +} + + +/**@brief Command response callback function for @ref sd_ble_gap_sec_info_reply 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 gap_sec_info_reply_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gap_sec_info_reply_rsp_dec(p_buffer, length, &result_code); + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_sec_info_reply +#define _sd_ble_gap_sec_info_reply sd_ble_gap_sec_info_reply +#endif +uint32_t _sd_ble_gap_sec_info_reply(uint16_t conn_handle, + ble_gap_enc_info_t const * p_enc_info, + ble_gap_irk_t const * p_id_info, + ble_gap_sign_info_t const * p_sign_info) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_sec_info_reply_req_enc(conn_handle, + p_enc_info, + p_id_info, + p_sign_info, + &(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), + gap_sec_info_reply_rsp_dec); +} + + +/**@brief Command response callback function for @ref sd_ble_gap_sec_params_reply 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 gap_sec_params_reply_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + uint32_t err_code = ble_gap_sec_params_reply_rsp_dec(p_buffer, length, + m_output_params.gap_sec_params_reply_out_params.p_sec_keyset, &result_code); + APP_ERROR_CHECK(err_code); + + // If soft device returned error free security context + if (result_code) + { + err_code = app_ble_gap_sec_context_destroy(m_output_params.gap_sec_params_reply_out_params.conn_handle); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + } + + return result_code; +} + +#ifndef _sd_ble_gap_sec_params_reply +#define _sd_ble_gap_sec_params_reply sd_ble_gap_sec_params_reply +#endif +uint32_t _sd_ble_gap_sec_params_reply(uint16_t conn_handle, + uint8_t sec_status, + ble_gap_sec_params_t const * p_sec_params, + ble_gap_sec_keyset_t const * p_sec_keyset) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + uint32_t sec_tab_index = 0; + uint32_t err_code = NRF_SUCCESS; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + m_output_params.gap_sec_params_reply_out_params.p_sec_keyset = p_sec_keyset; + m_output_params.gap_sec_params_reply_out_params.conn_handle = conn_handle; + + // First allocate security context for serialization + if (p_sec_keyset) + { + err_code = app_ble_gap_sec_context_create(conn_handle, &sec_tab_index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + memcpy(&(m_app_keys_table[sec_tab_index].keyset), p_sec_keyset, sizeof(ble_gap_sec_keyset_t)); + } + + err_code = ble_gap_sec_params_reply_req_enc(conn_handle, + sec_status, + p_sec_params, + p_sec_keyset, + &(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), + gap_sec_params_reply_rsp_dec); +} + + +/**@brief Command response callback function for @ref sd_ble_gap_ppcp_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 gap_ppcp_get_reply_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_ppcp_get_rsp_dec( + p_buffer, + length, + m_output_params.gap_ppcp_get_out_params. + p_conn_params, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_ppcp_get +#define _sd_ble_gap_ppcp_get sd_ble_gap_ppcp_get +#endif +uint32_t _sd_ble_gap_ppcp_get(ble_gap_conn_params_t * const p_conn_params) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + m_output_params.gap_ppcp_get_out_params.p_conn_params = p_conn_params; + + const uint32_t err_code = ble_gap_ppcp_get_req_enc(p_conn_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), + gap_ppcp_get_reply_rsp_dec); +} + + +/**@brief Command response callback function for @ref sd_ble_gap_adv_stop 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 gap_adv_stop_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_adv_stop_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_adv_stop +#define _sd_ble_gap_adv_stop sd_ble_gap_adv_stop +#endif +uint32_t _sd_ble_gap_adv_stop( +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t adv_handle +#else + void +#endif + ) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_adv_stop_req_enc( +#if NRF_SD_BLE_API_VERSION > 5 + adv_handle, +#endif + &(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), + gap_adv_stop_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_auth_key_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 gap_auth_key_reply_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_auth_key_reply_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + + +#ifndef _sd_ble_gap_auth_key_reply +#define _sd_ble_gap_auth_key_reply sd_ble_gap_auth_key_reply +#endif +uint32_t _sd_ble_gap_auth_key_reply(uint16_t conn_handle, + uint8_t key_type, + uint8_t const * const key) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_auth_key_reply_req_enc(conn_handle, key_type, key, + &(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), + gap_auth_key_reply_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_authenticate 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 gap_authenticate_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_authenticate_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gap_authenticate +#define _sd_ble_gap_authenticate sd_ble_gap_authenticate +#endif +uint32_t _sd_ble_gap_authenticate(uint16_t conn_handle, + ble_gap_sec_params_t const * const p_sec_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_gap_authenticate_req_enc(conn_handle, p_sec_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), + gap_authenticate_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_conn_sec_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 gap_conn_sec_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_conn_sec_get_rsp_dec( + p_buffer, + length, + (ble_gap_conn_sec_t * *)&mp_out_params[0 + ], + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gap_conn_sec_get +#define _sd_ble_gap_conn_sec_get sd_ble_gap_conn_sec_get +#endif +uint32_t _sd_ble_gap_conn_sec_get(uint16_t conn_handle, ble_gap_conn_sec_t * const p_conn_sec) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + mp_out_params[0] = p_conn_sec; + + const uint32_t err_code = ble_gap_conn_sec_get_req_enc(conn_handle, p_conn_sec, + &(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), + gap_conn_sec_get_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_rssi_start 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 gap_rssi_start_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_rssi_start_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gap_rssi_start +#define _sd_ble_gap_rssi_start sd_ble_gap_rssi_start +#endif +uint32_t _sd_ble_gap_rssi_start(uint16_t conn_handle, uint8_t threshold_dbm, uint8_t skip_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_gap_rssi_start_req_enc(conn_handle, + threshold_dbm, + skip_count, + &(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), + gap_rssi_start_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_rssi_stop 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 gap_rssi_stop_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_rssi_stop_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gap_rssi_stop +#define _sd_ble_gap_rssi_stop sd_ble_gap_rssi_stop +#endif +uint32_t _sd_ble_gap_rssi_stop(uint16_t conn_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_gap_rssi_stop_req_enc(conn_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), + gap_rssi_stop_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_tx_power_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 gap_tx_power_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_tx_power_set_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gap_tx_power_set +#define _sd_ble_gap_tx_power_set sd_ble_gap_tx_power_set +#endif +uint32_t _sd_ble_gap_tx_power_set( +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t role, uint16_t handle, +#endif + int8_t tx_power) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); +#if NRF_SD_BLE_API_VERSION > 5 + const uint32_t err_code = ble_gap_tx_power_set_req_enc(role, handle, tx_power, + &(p_buffer[1]), &buffer_length); +#else + const uint32_t err_code = ble_gap_tx_power_set_req_enc(tx_power, + &(p_buffer[1]), &buffer_length); +#endif + //@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), + gap_tx_power_set_rsp_dec); +} + +#ifndef S112 +/**@brief Command response callback function for @ref sd_ble_gap_scan_stop 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 gap_scan_stop_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_scan_stop_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gap_scan_stop +#define _sd_ble_gap_scan_stop sd_ble_gap_scan_stop +#endif +uint32_t _sd_ble_gap_scan_stop(void) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_scan_stop_req_enc(&(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), + gap_scan_stop_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_connect 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 gap_connect_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_connect_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gap_connect +#define _sd_ble_gap_connect sd_ble_gap_connect +#endif +uint32_t _sd_ble_gap_connect(ble_gap_addr_t const * const p_addr, + ble_gap_scan_params_t const * const p_scan_params, + ble_gap_conn_params_t const * const p_conn_params +#if NRF_SD_BLE_API_VERSION >= 4 + ,uint8_t conn_cfg_tag +#endif + ) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_connect_req_enc(p_addr, + p_scan_params, + p_conn_params, +#if NRF_SD_BLE_API_VERSION >= 4 + conn_cfg_tag, +#endif + &(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), + gap_connect_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_connect_cancel 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 gap_connect_cancel_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_connect_cancel_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gap_connect_cancel +#define _sd_ble_gap_connect_cancel sd_ble_gap_connect_cancel +#endif +uint32_t _sd_ble_gap_connect_cancel(void) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_connect_cancel_req_enc(&(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), + gap_connect_cancel_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_scan_start 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 gap_scan_start_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_scan_start_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_scan_start +#define _sd_ble_gap_scan_start sd_ble_gap_scan_start +#endif +uint32_t _sd_ble_gap_scan_start(ble_gap_scan_params_t const * const p_scan_params +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 + ,ble_data_t const * p_adv_report_buffer +#endif + ) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + uint32_t err_code; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 + if (p_adv_report_buffer) + { + err_code = app_ble_gap_scan_data_set(p_adv_report_buffer); + APP_ERROR_CHECK(err_code); + } +#endif + err_code = ble_gap_scan_start_req_enc(p_scan_params, +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 + p_adv_report_buffer, +#endif + &(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), + gap_scan_start_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_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 gap_encrypt_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_encrypt_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_encrypt +#define _sd_ble_gap_encrypt sd_ble_gap_encrypt +#endif +uint32_t _sd_ble_gap_encrypt( uint16_t conn_handle, + ble_gap_master_id_t const * p_master_id, + ble_gap_enc_info_t const * p_enc_info) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_encrypt_req_enc( conn_handle, p_master_id, p_enc_info, &(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), + gap_encrypt_rsp_dec); +} +#endif //!S112 + +/**@brief Command response callback function for @ref sd_ble_gap_rssi_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 gap_rssi_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_rssi_get_rsp_dec(p_buffer, + length, + (int8_t *) mp_out_params[0], +#if NRF_SD_BLE_API_VERSION > 5 + (uint8_t *) mp_out_params[1], +#endif + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_rssi_get +#define _sd_ble_gap_rssi_get sd_ble_gap_rssi_get +#endif +uint32_t _sd_ble_gap_rssi_get(uint16_t conn_handle, + int8_t * p_rssi +#if NRF_SD_BLE_API_VERSION > 5 + ,uint8_t * p_ch_index +#endif +) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + mp_out_params[0] = p_rssi; + +#if NRF_SD_BLE_API_VERSION > 5 + mp_out_params[1] = p_ch_index; + const uint32_t err_code = ble_gap_rssi_get_req_enc(conn_handle, p_rssi, p_ch_index, &(p_buffer[1]), &buffer_length); +#else + const uint32_t err_code = ble_gap_rssi_get_req_enc(conn_handle, p_rssi, &(p_buffer[1]), &buffer_length); +#endif + //@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), + gap_rssi_get_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_keypress_notify 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 gap_keypress_notify_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_keypress_notify_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_keypress_notify +#define _sd_ble_gap_keypress_notify sd_ble_gap_keypress_notify +#endif +uint32_t _sd_ble_gap_keypress_notify( uint16_t conn_handle, uint8_t kp_not) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_keypress_notify_req_enc( conn_handle, kp_not, &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), + gap_keypress_notify_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_lesc_dhkey_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 gap_lesc_dhkey_reply_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_lesc_dhkey_reply_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_lesc_dhkey_reply +#define _sd_ble_gap_lesc_dhkey_reply sd_ble_gap_lesc_dhkey_reply +#endif +uint32_t _sd_ble_gap_lesc_dhkey_reply( uint16_t conn_handle, ble_gap_lesc_dhkey_t const *p_dhkey) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_lesc_dhkey_reply_req_enc( conn_handle, p_dhkey, &(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), + gap_lesc_dhkey_reply_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_lesc_oob_data_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 gap_lesc_oob_data_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_lesc_oob_data_set_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_lesc_oob_data_set +#define _sd_ble_gap_lesc_oob_data_set sd_ble_gap_lesc_oob_data_set +#endif +uint32_t _sd_ble_gap_lesc_oob_data_set(uint16_t conn_handle, + ble_gap_lesc_oob_data_t const *p_oobd_own, + ble_gap_lesc_oob_data_t const *p_oobd_peer) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_lesc_oob_data_set_req_enc(conn_handle, p_oobd_own, p_oobd_peer, + &(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), + gap_lesc_oob_data_set_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_lesc_oob_data_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 gap_lesc_oob_data_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_lesc_oob_data_get_rsp_dec(p_buffer, + length, + (ble_gap_lesc_oob_data_t **) &mp_out_params[0], + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_lesc_oob_data_get +#define _sd_ble_gap_lesc_oob_data_get sd_ble_gap_lesc_oob_data_get +#endif +uint32_t _sd_ble_gap_lesc_oob_data_get(uint16_t conn_handle, + ble_gap_lesc_p256_pk_t const *p_pk_own, + ble_gap_lesc_oob_data_t *p_oobd_own) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + mp_out_params[0] = p_oobd_own; + const uint32_t err_code = ble_gap_lesc_oob_data_get_req_enc(conn_handle, p_pk_own, p_oobd_own, + &(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), + gap_lesc_oob_data_get_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_addr_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 gap_addr_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_addr_get_rsp_dec(p_buffer, + length, + (ble_gap_addr_t *)mp_out_params[0], + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + return result_code; +} + +#ifndef _sd_ble_gap_addr_get +#define _sd_ble_gap_addr_get sd_ble_gap_addr_get +#endif +uint32_t _sd_ble_gap_addr_get(ble_gap_addr_t * const p_addr) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + mp_out_params[0] = p_addr; + + const uint32_t err_code = ble_gap_addr_get_req_enc(p_addr, + &(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), + gap_addr_get_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_addr_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 gap_addr_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_addr_set_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + return result_code; +} + +#ifndef _sd_ble_gap_addr_set +#define _sd_ble_gap_addr_set sd_ble_gap_addr_set +#endif +uint32_t _sd_ble_gap_addr_set(ble_gap_addr_t const * const p_addr) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_addr_set_req_enc(p_addr, + &(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), + gap_addr_set_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_privacy_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 gap_privacy_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_privacy_set_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + return result_code; +} + +#ifndef _sd_ble_gap_privacy_set +#define _sd_ble_gap_privacy_set sd_ble_gap_privacy_set +#endif +uint32_t _sd_ble_gap_privacy_set(ble_gap_privacy_params_t const *p_privacy_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_gap_privacy_set_req_enc(p_privacy_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), + gap_privacy_set_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_privacy_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 gap_privacy_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_privacy_get_rsp_dec(p_buffer, + length, + (ble_gap_privacy_params_t *)mp_out_params[0], + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + return result_code; +} + +#ifndef _sd_ble_gap_privacy_get +#define _sd_ble_gap_privacy_get sd_ble_gap_privacy_get +#endif +uint32_t _sd_ble_gap_privacy_get(ble_gap_privacy_params_t *p_privacy_params) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + mp_out_params[0] = p_privacy_params; + + const uint32_t err_code = ble_gap_privacy_get_req_enc(p_privacy_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), + gap_privacy_get_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_whitelist_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 gap_whitelist_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_whitelist_set_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + return result_code; +} + +#ifndef _sd_ble_gap_whitelist_set +#define _sd_ble_gap_whitelist_set sd_ble_gap_whitelist_set +#endif +uint32_t _sd_ble_gap_whitelist_set(ble_gap_addr_t const * const * pp_wl_addrs, uint8_t len) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + + const uint32_t err_code = ble_gap_whitelist_set_req_enc(pp_wl_addrs, len, + &(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), + gap_whitelist_set_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_device_identities_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 gap_device_identities_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_device_identities_set_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + return result_code; +} + +#ifndef _sd_ble_gap_device_identities_set +#define _sd_ble_gap_device_identities_set sd_ble_gap_device_identities_set +#endif +uint32_t _sd_ble_gap_device_identities_set(ble_gap_id_key_t const * const * pp_id_keys, ble_gap_irk_t const * const * pp_local_irks, uint8_t len) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + + const uint32_t err_code = ble_gap_device_identities_set_req_enc(pp_id_keys, + pp_local_irks, + len, + &(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), + gap_device_identities_set_rsp_dec); +} + +#if NRF_SD_BLE_API_VERSION >= 4 && !defined(S112) +/**@brief Command response callback function for @ref sd_ble_gap_data_length_update 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 gap_data_length_update_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_data_length_update_rsp_dec(p_buffer, + length, + (ble_gap_data_length_limitation_t *)mp_out_params[0], + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + return result_code; +} + +#ifndef _sd_ble_gap_data_length_update +#define _sd_ble_gap_data_length_update sd_ble_gap_data_length_update +#endif +uint32_t _sd_ble_gap_data_length_update(uint16_t conn_handle, + ble_gap_data_length_params_t const *p_dl_params, + ble_gap_data_length_limitation_t *p_dl_limitation) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + mp_out_params[0] = p_dl_limitation; + + const uint32_t err_code = ble_gap_data_length_update_req_enc(conn_handle, p_dl_params,p_dl_limitation, + &(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), + gap_data_length_update_rsp_dec); +} + +#endif // NRF_SD_BLE_API_VERSION >= 4 && !defined(S112) + +#if NRF_SD_BLE_API_VERSION >= 5 +/**@brief Command response callback function for @ref sd_ble_gap_phy_update 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 gap_phy_update_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_phy_update_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gap_phy_update +#define _sd_ble_gap_phy_update sd_ble_gap_phy_update +#endif +uint32_t _sd_ble_gap_phy_update(uint16_t conn_handle, + ble_gap_phys_t const * const p_gap_phys) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_phy_update_req_enc(conn_handle, p_gap_phys, + &(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), + gap_phy_update_rsp_dec); +} +#endif + +#if NRF_SD_BLE_API_VERSION >= 6 +/**@brief Command response callback function for @ref sd_ble_gap_adv_set_configure 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 gap_adv_set_configure_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + uint32_t err_code = ble_gap_adv_set_configure_rsp_dec(p_buffer, + length, + (uint8_t *)mp_out_params[0], + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + err_code = app_ble_gap_adv_set_register(*(uint8_t *)mp_out_params[0], + (uint8_t *)mp_out_params[1], + (uint8_t *)mp_out_params[2]); + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_adv_set_configure +#define _sd_ble_gap_adv_set_configure sd_ble_gap_adv_set_configure +#endif +uint32_t _sd_ble_gap_adv_set_configure(uint8_t *p_adv_handle, + ble_gap_adv_data_t const *p_adv_data, + ble_gap_adv_params_t const *p_adv_params) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + + mp_out_params[0] = p_adv_handle; + mp_out_params[1] = p_adv_data ? p_adv_data->adv_data.p_data : NULL; + mp_out_params[2] = p_adv_data ? p_adv_data->scan_rsp_data.p_data : NULL; + const uint32_t err_code = ble_gap_adv_set_configure_req_enc(p_adv_handle, p_adv_data, p_adv_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), + gap_adv_set_configure_rsp_dec); +} + +#ifndef S112 +/**@brief Command response callback function for @ref sd_ble_gap_qos_channel_survey_start 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 gap_qos_channel_survey_start_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + uint32_t err_code = ble_gap_qos_channel_survey_start_rsp_dec(p_buffer, + length, + &result_code); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_qos_channel_survey_start +#define _sd_ble_gap_qos_channel_survey_start sd_ble_gap_qos_channel_survey_start +#endif +uint32_t _sd_ble_gap_qos_channel_survey_start(uint32_t interval_us) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + + const uint32_t err_code = ble_gap_qos_channel_survey_start_req_enc(interval_us, + &(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), + gap_qos_channel_survey_start_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_qos_channel_survey_stop 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 gap_qos_channel_survey_stop_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + uint32_t err_code = ble_gap_qos_channel_survey_stop_rsp_dec(p_buffer, + length, + &result_code); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_qos_channel_survey_stop +#define _sd_ble_gap_qos_channel_survey_stop sd_ble_gap_qos_channel_survey_stop +#endif +uint32_t _sd_ble_gap_qos_channel_survey_stop(void) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + + const uint32_t err_code = ble_gap_qos_channel_survey_stop_req_enc(&(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), + gap_qos_channel_survey_stop_rsp_dec); +} +#endif //!S112 +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble_gattc.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble_gattc.c new file mode 100644 index 0000000..7edf6ee --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble_gattc.c @@ -0,0 +1,566 @@ +/** + * Copyright (c) 2014 - 2018, 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); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble_gatts.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble_gatts.c new file mode 100644 index 0000000..e4b3002 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble_gatts.c @@ -0,0 +1,773 @@ +/** + * Copyright (c) 2013 - 2018, 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); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble_l2cap.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble_l2cap.c new file mode 100644 index 0000000..41aa555 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble_l2cap.c @@ -0,0 +1,453 @@ +/** + * Copyright (c) 2014 - 2018, 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 diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_nrf_soc.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_nrf_soc.c new file mode 100644 index 0000000..0b0158e --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_nrf_soc.c @@ -0,0 +1,171 @@ +/** + * Copyright (c) 2014 - 2018, 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); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/app_ble_gap_sec_keys.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/app_ble_gap_sec_keys.c new file mode 100644 index 0000000..108231d --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/app_ble_gap_sec_keys.c @@ -0,0 +1,182 @@ +/** + * Copyright (c) 2014 - 2018, 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}; +#endif +ser_ble_gap_app_keyset_t m_app_keys_table[SER_MAX_CONNECTIONS]; + +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 +uint32_t app_ble_gap_scan_data_set(ble_data_t const * p_data) +{ + if (m_scan_data.p_data) + { + return NRF_ERROR_BUSY; + } + else + { + memcpy(&m_scan_data, p_data, sizeof(ble_data_t)); + return NRF_SUCCESS; + } +} + + +uint32_t app_ble_gap_scan_data_fetch_clear(ble_data_t * p_data) +{ + memcpy(p_data, &m_scan_data, sizeof(ble_data_t)); + if (m_scan_data.p_data) + { + m_scan_data.p_data = NULL; + return NRF_SUCCESS; + } + else + { + return NRF_ERROR_NOT_FOUND; + } +} + +uint32_t app_ble_gap_adv_set_register(uint8_t adv_handle, uint8_t * p_adv_data, uint8_t * p_scan_rsp_data) +{ + uint32_t err_code = NRF_ERROR_NO_MEM; + uint32_t i; + for (i = 0; i < ARRAY_SIZE(m_adv_sets); i++) + { + if (m_adv_sets[i].active == false) + { + m_adv_sets[i].active = true; + m_adv_sets[i].adv_handle = adv_handle; + m_adv_sets[i].p_adv_data = p_adv_data; + m_adv_sets[i].p_scan_rsp_data = p_scan_rsp_data; + err_code = NRF_SUCCESS; + break; + } + } + return err_code; +} + +uint32_t app_ble_gap_adv_set_unregister(uint8_t adv_handle, uint8_t * * pp_adv_data, uint8_t **pp_scan_rsp_data) +{ + uint32_t err_code = NRF_ERROR_NOT_FOUND; + uint32_t i; + for (i = 0; i < ARRAY_SIZE(m_adv_sets); i++) + { + if ((m_adv_sets[i].active == true) && (m_adv_sets[i].adv_handle == adv_handle)) + { + m_adv_sets[i].active = false; + *pp_adv_data = m_adv_sets[i].p_adv_data; + *pp_scan_rsp_data = m_adv_sets[i].p_scan_rsp_data; + err_code = NRF_SUCCESS; + break; + } + } + return err_code; +} +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/app_ble_gap_sec_keys.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/app_ble_gap_sec_keys.h new file mode 100644 index 0000000..314a5f5 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/app_ble_gap_sec_keys.h @@ -0,0 +1,151 @@ +/** + * Copyright (c) 2014 - 2018, 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> + +#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; + +/**@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 +/** + * @brief Stores buffer for adv report data. + * + * @param p_data Pointer to the buffer. + * + * @return NRF_SUCCESS or error in case pointer is already set. + */ +uint32_t app_ble_gap_scan_data_set(ble_data_t const * p_data); + +/** + * @brief Returns pointer to the buffer for storing report data. Returns error if not paired with + * @ref app_ble_gap_scan_data_set call. + * + * @param[out] p_data Stored data. + * @return NRF_SUCCESS or error in case pointer is already cleared. + */ +uint32_t app_ble_gap_scan_data_fetch_clear(ble_data_t * p_data); + +/** + * @brief Function for registering data pointers related with given adv_handle. + * + * @param adv_handle Handle. + * @param p_adv_data Adv_data buffer. + * @param p_scan_rsp_data Scan_rsp_data buffer. + * + * @return NRF_SUCCESS or error. + * + */ +uint32_t app_ble_gap_adv_set_register(uint8_t adv_handle, uint8_t * p_adv_data, uint8_t * p_scan_rsp_data); + + +/** + * @brief Function for unregistering given . + * + * @param[in] adv_handle Handle. + * @param[out] pp_adv_data Pointer to adv_data buffer associated with given adv_handle. + * @param[out] pp_scan_rsp_data Pointer to adv_data buffer associated with given adv_handle. + * + * @return NRF_SUCCESS or error. + * + */ +uint32_t app_ble_gap_adv_set_unregister(uint8_t adv_handle, uint8_t * * pp_adv_data, uint8_t **pp_scan_rsp_data); +#endif +#ifdef __cplusplus +} +#endif + +#endif //_APP_BLE_GAP_SEC_KEYS_H diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/app_ble_user_mem.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/app_ble_user_mem.c new file mode 100644 index 0000000..dcb1371 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/app_ble_user_mem.c @@ -0,0 +1,101 @@ +/** + * Copyright (c) 2014 - 2018, 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; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/app_ble_user_mem.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/app_ble_user_mem.h new file mode 100644 index 0000000..ac95b01 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/app_ble_user_mem.h @@ -0,0 +1,109 @@ +/** + * Copyright (c) 2014 - 2018, 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 diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_app.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_app.c new file mode 100644 index 0000000..fcc71ab --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_app.c @@ -0,0 +1,513 @@ +/** + * Copyright (c) 2014 - 2018, 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 diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_app.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_app.h new file mode 100644 index 0000000..a68cf0d --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_app.h @@ -0,0 +1,523 @@ +/** + * Copyright (c) 2013 - 2018, 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 diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_event.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_event.c new file mode 100644 index 0000000..e32a905 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_event.c @@ -0,0 +1,316 @@ +/** + * Copyright (c) 2014 - 2018, 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 >= 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; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_evt_app.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_evt_app.c new file mode 100644 index 0000000..a5964c6 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_evt_app.c @@ -0,0 +1,129 @@ +/** + * Copyright (c) 2015 - 2018, 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 diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_evt_app.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_evt_app.h new file mode 100644 index 0000000..67b6135 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_evt_app.h @@ -0,0 +1,157 @@ +/** + * Copyright (c) 2014 - 2018, 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 diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gap_app.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gap_app.c new file mode 100644 index 0000000..ca227e0 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gap_app.c @@ -0,0 +1,1019 @@ +/** + * Copyright (c) 2013 - 2018, 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_app.h" +#include <stdlib.h> +#include <string.h> +#include "ble_serialization.h" +#include "ble_gap_struct_serialization.h" +#include "ble_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 6 +uint32_t ble_gap_adv_data_set_req_enc(uint8_t const * const p_data, + uint8_t dlen, + uint8_t const * const p_sr_data, + uint8_t srdlen, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_ADV_DATA_SET); + + SER_PUSH_len8data(p_data, dlen); + SER_PUSH_len8data(p_sr_data, srdlen); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_adv_data_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_GAP_ADV_DATA_SET); +} +#endif + +uint32_t ble_gap_adv_start_req_enc( +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t adv_handle, +#else + ble_gap_adv_params_t const * const p_adv_params, +#endif +#if NRF_SD_BLE_API_VERSION >= 4 + uint8_t conn_cfg_tag, +#endif + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_ADV_START); + +#if NRF_SD_BLE_API_VERSION > 5 + SER_PUSH_uint8(&adv_handle); +#else + SER_PUSH_COND(p_adv_params, ble_gap_adv_params_t_enc); +#endif + +#if NRF_SD_BLE_API_VERSION >= 4 + SER_PUSH_uint8(&conn_cfg_tag); +#endif + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_adv_start_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_GAP_ADV_START); +} + + +uint32_t ble_gap_adv_stop_req_enc( +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t adv_handle, +#endif + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_ADV_STOP); +#if NRF_SD_BLE_API_VERSION > 5 + SER_PUSH_uint8(&adv_handle); +#endif + SER_REQ_ENC_END; +} + +uint32_t ble_gap_adv_stop_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_GAP_ADV_STOP); +} + + + +uint32_t ble_gap_appearance_get_req_enc(uint16_t const * const p_appearance, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_APPEARANCE_GET); + SER_PUSH_COND(p_appearance, NULL); + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_appearance_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_appearance, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GAP_APPEARANCE_GET); + SER_PULL_COND(&p_appearance, uint16_t_dec); + SER_RSP_DEC_END; +} + + +uint32_t ble_gap_appearance_set_req_enc(uint16_t appearance, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_APPEARANCE_SET); + SER_PUSH_uint16(&appearance); + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_appearance_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_GAP_APPEARANCE_SET); +} + + +uint32_t ble_gap_auth_key_reply_req_enc(uint16_t conn_handle, + uint8_t key_type, + uint8_t const * const p_key, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_AUTH_KEY_REPLY); + + uint8_t key_len; + switch (key_type) + { + case BLE_GAP_AUTH_KEY_TYPE_NONE: + key_len = 0; + break; + + case BLE_GAP_AUTH_KEY_TYPE_PASSKEY: + key_len = 6; + break; + + case BLE_GAP_AUTH_KEY_TYPE_OOB: + key_len = 16; + break; + + default: + return NRF_ERROR_INVALID_PARAM; + } + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_uint8(&key_type); + SER_PUSH_buf(p_key, key_len); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_auth_key_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_GAP_AUTH_KEY_REPLY); +} + + + +uint32_t ble_gap_authenticate_req_enc(uint16_t conn_handle, + ble_gap_sec_params_t const * const p_sec_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_AUTHENTICATE); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_sec_params, ble_gap_sec_params_t_enc); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_authenticate_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_GAP_AUTHENTICATE); +} + + +uint32_t ble_gap_conn_param_update_req_enc(uint16_t conn_handle, + ble_gap_conn_params_t const * const p_conn_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_CONN_PARAM_UPDATE); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_conn_params, ble_gap_conn_params_t_enc); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_conn_param_update_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_GAP_CONN_PARAM_UPDATE); +} + + +uint32_t ble_gap_conn_sec_get_req_enc(uint16_t conn_handle, + ble_gap_conn_sec_t const * const p_conn_sec, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_CONN_SEC_GET); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_conn_sec, NULL); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_conn_sec_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_conn_sec_t * * const pp_conn_sec, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GAP_CONN_SEC_GET); + SER_PULL_COND(pp_conn_sec, ble_gap_conn_sec_t_dec); + SER_RSP_DEC_END; +} + +#ifndef S112 +uint32_t ble_gap_connect_req_enc(ble_gap_addr_t const * const p_peer_addr, + ble_gap_scan_params_t const * const p_scan_params, + ble_gap_conn_params_t const * const p_conn_params, +#if NRF_SD_BLE_API_VERSION >= 4 + uint8_t conn_cfg_tag, +#endif + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_CONNECT); + + SER_PUSH_COND(p_peer_addr, ble_gap_addr_t_enc); + SER_PUSH_COND(p_scan_params, ble_gap_scan_params_t_enc); + SER_PUSH_COND(p_conn_params, ble_gap_conn_params_t_enc); +#if NRF_SD_BLE_API_VERSION >= 4 + SER_PUSH_uint8(&conn_cfg_tag); +#endif + + SER_REQ_ENC_END; +} + +uint32_t ble_gap_connect_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_GAP_CONNECT); +} + + +uint32_t ble_gap_connect_cancel_req_enc(uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_CONNECT_CANCEL); + SER_REQ_ENC_END; +} + +uint32_t ble_gap_connect_cancel_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_GAP_CONNECT_CANCEL); +} +#endif + +uint32_t ble_gap_device_name_get_req_enc(uint8_t const * const p_dev_name, + uint16_t const * const p_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_DEVICE_NAME_GET); + + SER_PUSH_COND(p_len, uint16_t_enc); + SER_PUSH_COND(p_dev_name, NULL); + + SER_REQ_ENC_END; +} + +uint32_t ble_gap_device_name_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_dev_name, + uint16_t * const p_dev_name_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GAP_DEVICE_NAME_GET); + + SER_PULL_COND(&p_dev_name_len, uint16_t_dec); + if (p_dev_name_len) + { + SER_PULL_uint8array(p_dev_name, *p_dev_name_len); + } + + SER_RSP_DEC_END; +} + + +uint32_t ble_gap_device_name_set_req_enc(ble_gap_conn_sec_mode_t const * const p_write_perm, + uint8_t const * const p_dev_name, + uint16_t len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_DEVICE_NAME_SET); + + SER_ERROR_CHECK(len <= BLE_GAP_DEVNAME_MAX_LEN, NRF_ERROR_INVALID_PARAM); + + SER_PUSH_COND(p_write_perm, ble_gap_conn_sec_mode_t_enc); + SER_PUSH_len16data(p_dev_name, len); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_device_name_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_GAP_DEVICE_NAME_SET); +} + + +uint32_t ble_gap_disconnect_req_enc(uint16_t conn_handle, + uint8_t hci_status_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_DISCONNECT); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_uint8(&hci_status_code); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_disconnect_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_GAP_DISCONNECT); +} + +#ifndef S112 +uint32_t ble_gap_encrypt_req_enc(uint16_t conn_handle, + ble_gap_master_id_t const * const p_master_id, + ble_gap_enc_info_t const * const p_enc_info, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_ENCRYPT); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_master_id, ble_gap_master_id_t_enc); + SER_PUSH_COND(p_enc_info, ble_gap_enc_info_t_enc); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_encrypt_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_GAP_ENCRYPT); +} +#endif + +uint32_t ble_gap_keypress_notify_req_enc(uint16_t conn_handle, + uint8_t kp_not, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_KEYPRESS_NOTIFY); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_uint8(&kp_not); + + SER_REQ_ENC_END; +} + +uint32_t ble_gap_keypress_notify_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_GAP_KEYPRESS_NOTIFY); +} + + +uint32_t ble_gap_lesc_dhkey_reply_req_enc(uint16_t conn_handle, + ble_gap_lesc_dhkey_t const *p_dhkey, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_LESC_DHKEY_REPLY); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_dhkey, ble_gap_lesc_dhkey_t_enc); + + SER_REQ_ENC_END; +} + +uint32_t ble_gap_lesc_dhkey_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_GAP_LESC_DHKEY_REPLY); +} + + +uint32_t ble_gap_lesc_oob_data_get_req_enc(uint16_t conn_handle, + ble_gap_lesc_p256_pk_t const *p_pk_own, + ble_gap_lesc_oob_data_t *p_oobd_own, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_LESC_OOB_DATA_GET); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_pk_own, ble_gap_lesc_p256_pk_t_enc); + SER_PUSH_COND(p_oobd_own, NULL); + + SER_REQ_ENC_END; +} + +uint32_t ble_gap_lesc_oob_data_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_lesc_oob_data_t * *pp_oobd_own, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GAP_LESC_OOB_DATA_GET); + SER_PULL_COND(pp_oobd_own, ble_gap_lesc_oob_data_t_dec); + SER_RSP_DEC_END; +} + + +uint32_t ble_gap_lesc_oob_data_set_req_enc(uint16_t conn_handle, + ble_gap_lesc_oob_data_t const *p_oobd_own, + ble_gap_lesc_oob_data_t const *p_oobd_peer, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_LESC_OOB_DATA_SET); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_oobd_own, ble_gap_lesc_oob_data_t_enc); + SER_PUSH_COND(p_oobd_peer, ble_gap_lesc_oob_data_t_enc); + + SER_REQ_ENC_END; +} + +uint32_t ble_gap_lesc_oob_data_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_GAP_LESC_OOB_DATA_SET); +} + + +uint32_t ble_gap_ppcp_get_req_enc(ble_gap_conn_params_t const * const p_conn_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_PPCP_GET); + SER_PUSH_COND(p_conn_params, NULL); + SER_REQ_ENC_END; +} + +uint32_t ble_gap_ppcp_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_conn_params_t * const p_conn_params, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GAP_PPCP_GET); + SER_PULL_COND(&p_conn_params, ble_gap_conn_params_t_dec); + SER_RSP_DEC_END; +} + + +uint32_t ble_gap_ppcp_set_req_enc(ble_gap_conn_params_t const * const p_conn_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_PPCP_SET); + SER_PUSH_COND(p_conn_params, ble_gap_conn_params_t_enc); + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_ppcp_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_GAP_PPCP_SET); +} + +uint32_t ble_gap_rssi_get_req_enc(uint16_t conn_handle, + int8_t const * const p_rssi, +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t const * const p_ch_index, +#endif + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_RSSI_GET); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_rssi, NULL); +#if NRF_SD_BLE_API_VERSION > 5 + SER_PUSH_COND(p_ch_index, NULL); +#endif + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_rssi_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + int8_t * const p_rssi, +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t * const p_ch_index, +#endif + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GAP_RSSI_GET); + SER_PULL_COND(&p_rssi, uint8_t_dec); +#if NRF_SD_BLE_API_VERSION > 5 + SER_PULL_COND(&p_ch_index, uint8_t_dec); +#endif + SER_RSP_DEC_END; +} + + +uint32_t ble_gap_rssi_start_req_enc(uint16_t conn_handle, + uint8_t threshold_dbm, + uint8_t skip_count, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_RSSI_START); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_uint8(&threshold_dbm); + SER_PUSH_uint8(&skip_count); + + SER_REQ_ENC_END; +} + +uint32_t ble_gap_rssi_start_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_GAP_RSSI_START); +} + + +uint32_t ble_gap_rssi_stop_req_enc(uint16_t conn_handle, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_RSSI_STOP); + SER_PUSH_uint16(&conn_handle); + SER_REQ_ENC_END; +} + +uint32_t ble_gap_rssi_stop_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_GAP_RSSI_STOP); +} + +#ifndef S112 +uint32_t ble_gap_scan_start_req_enc(ble_gap_scan_params_t const * p_scan_params, +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 + ble_data_t const * p_adv_report_buffer, +#endif + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_SCAN_START); + SER_PUSH_COND(p_scan_params, ble_gap_scan_params_t_enc); +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 + SER_PUSH_COND(p_adv_report_buffer, ble_data_t_enc); +#endif + SER_REQ_ENC_END; +} +uint32_t ble_gap_scan_start_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_GAP_SCAN_START); +} + + +uint32_t ble_gap_scan_stop_req_enc(uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_SCAN_STOP); + SER_REQ_ENC_END; +} + +uint32_t ble_gap_scan_stop_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_GAP_SCAN_STOP); +} +#endif + +uint32_t ble_gap_sec_info_reply_req_enc(uint16_t conn_handle, + ble_gap_enc_info_t const * p_enc_info, + ble_gap_irk_t const * p_id_info, + ble_gap_sign_info_t const * p_sign_info, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_SEC_INFO_REPLY); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_enc_info, ble_gap_enc_info_t_enc); + SER_PUSH_COND(p_id_info, ble_gap_irk_t_enc); + SER_PUSH_COND(p_sign_info, ble_gap_sign_info_t_enc); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_sec_info_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_GAP_SEC_INFO_REPLY); +} + + +uint32_t ble_gap_sec_params_reply_req_enc(uint16_t conn_handle, + uint8_t sec_status, + ble_gap_sec_params_t const * const p_sec_params, + ble_gap_sec_keyset_t const * const p_sec_keyset, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_SEC_PARAMS_REPLY); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_uint8(&sec_status); + SER_PUSH_COND(p_sec_params, ble_gap_sec_params_t_enc); + SER_PUSH_COND(p_sec_keyset, ble_gap_sec_keyset_t_enc); + + SER_REQ_ENC_END; +} + +uint32_t ble_gap_sec_params_reply_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_sec_keyset_t const * const p_sec_keyset, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GAP_SEC_PARAMS_REPLY); + SER_PULL_COND(&p_sec_keyset, ble_gap_sec_keyset_t_dec); + SER_RSP_DEC_END; +} + + +uint32_t ble_gap_tx_power_set_req_enc( +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t role, uint16_t handle, +#endif + int8_t tx_power, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_TX_POWER_SET); +#if NRF_SD_BLE_API_VERSION > 5 + SER_PUSH_uint8(&role); + SER_PUSH_uint16(&handle); +#endif + SER_PUSH_int8(&tx_power); + SER_REQ_ENC_END; +} + +uint32_t ble_gap_tx_power_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_GAP_TX_POWER_SET); +} + +uint32_t ble_gap_addr_get_req_enc(ble_gap_addr_t const * const p_address, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_ADDR_GET); + SER_PUSH_COND(p_address, NULL); + SER_REQ_ENC_END; +} + +uint32_t ble_gap_addr_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_addr_t * const p_address, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GAP_ADDR_GET); + SER_PULL_FIELD(p_address, ble_gap_addr_t_dec); + SER_RSP_DEC_END; +} + +uint32_t ble_gap_addr_set_req_enc(ble_gap_addr_t const * const p_addr, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_ADDR_SET); + SER_PUSH_COND(p_addr, ble_gap_addr_t_enc); + SER_REQ_ENC_END; +} + +uint32_t ble_gap_addr_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_GAP_ADDR_SET); +} + +uint32_t ble_gap_privacy_set_req_enc(ble_gap_privacy_params_t const * p_privacy_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_PRIVACY_SET); + SER_PUSH_COND(p_privacy_params, ble_gap_privacy_params_t_enc); + SER_REQ_ENC_END; +} + +uint32_t ble_gap_privacy_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_GAP_PRIVACY_SET); +} + + +uint32_t ble_gap_privacy_get_req_enc(ble_gap_privacy_params_t const * const p_privacy_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_PRIVACY_GET); + SER_PUSH_COND(p_privacy_params, ble_gap_privacy_params_t_enc); + SER_REQ_ENC_END; +} + +uint32_t ble_gap_privacy_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_privacy_params_t const * const p_privacy_params, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GAP_PRIVACY_GET); + SER_PULL_COND((void **)&p_privacy_params, ble_gap_privacy_params_t_dec); + SER_RSP_DEC_END; +} + +uint32_t ble_gap_whitelist_set_req_enc(ble_gap_addr_t const * const * const pp_wl_addrs, + uint8_t const len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_WHITELIST_SET); + + uint8_t presence; + SER_PUSH_uint8(&len); + + if (pp_wl_addrs) + { + presence = SER_FIELD_PRESENT; + SER_PUSH_uint8(&presence); + + for (uint32_t i = 0; i < len; ++i) + { + SER_PUSH_COND(pp_wl_addrs[i], ble_gap_addr_t_enc); + } + } + else + { + presence = SER_FIELD_NOT_PRESENT; + SER_PUSH_uint8(&presence); + } + + SER_REQ_ENC_END; +} + +uint32_t ble_gap_whitelist_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_GAP_WHITELIST_SET); +} + +uint32_t ble_gap_device_identities_set_req_enc(ble_gap_id_key_t const * const * const pp_id_keys, + ble_gap_irk_t const * const * const pp_local_irks, + uint8_t const len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_DEVICE_IDENTITIES_SET); + uint8_t presence; + SER_PUSH_uint8(&len); + + if (pp_id_keys) + { + presence = SER_FIELD_PRESENT; + SER_PUSH_uint8(&presence); + + for (uint32_t i = 0; i < len; ++i) + { + SER_PUSH_COND(pp_id_keys[i], ble_gap_id_key_t_enc); + } + } + else + { + presence = SER_FIELD_NOT_PRESENT; + SER_PUSH_uint8(&presence); + } + + if (pp_local_irks) + { + presence = SER_FIELD_PRESENT; + SER_PUSH_uint8(&presence); + + for (uint32_t i = 0; i < len; ++i) + { + SER_PUSH_COND(pp_local_irks[i], ble_gap_irk_t_enc); + } + } + else + { + presence = SER_FIELD_NOT_PRESENT; + SER_PUSH_uint8(&presence); + } + + SER_REQ_ENC_END; +} + +uint32_t ble_gap_device_identities_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_GAP_DEVICE_IDENTITIES_SET); +} +#if NRF_SD_BLE_API_VERSION >= 4 && !defined(S112) +uint32_t ble_gap_data_length_update_req_enc(uint16_t conn_handle, + ble_gap_data_length_params_t const * p_dl_params, + ble_gap_data_length_limitation_t * p_dl_limitation, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_DATA_LENGTH_UPDATE); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_dl_params, ble_gap_data_length_params_t_enc); + SER_PUSH_COND(p_dl_limitation, NULL); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_data_length_update_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_data_length_limitation_t * p_dl_limitation, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GAP_DATA_LENGTH_UPDATE); + SER_PULL_COND((void **)&p_dl_limitation, ble_gap_data_length_limitation_t_dec); + SER_RSP_DEC_END; +} +#endif +#if NRF_SD_BLE_API_VERSION >= 5 +uint32_t ble_gap_phy_update_req_enc(uint16_t conn_handle, + ble_gap_phys_t const * p_gap_phys, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_PHY_UPDATE); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_gap_phys, ble_gap_phys_t_enc); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_phy_update_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_GAP_PHY_UPDATE); +} +#endif + +#if NRF_SD_BLE_API_VERSION > 5 +uint32_t ble_gap_adv_set_configure_req_enc(uint8_t * p_adv_handle, + ble_gap_adv_data_t const * p_adv_data, + ble_gap_adv_params_t const *p_adv_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_ADV_SET_CONFIGURE); + + SER_PUSH_COND(p_adv_handle, uint8_t_enc); + SER_PUSH_COND(p_adv_data, ble_gap_adv_data_t_enc); + SER_PUSH_COND(p_adv_params, ble_gap_adv_params_t_enc); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_adv_set_configure_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * p_adv_handle, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GAP_ADV_SET_CONFIGURE); + SER_PULL_COND((void **)&p_adv_handle, uint8_t_dec); + SER_RSP_DEC_END; +} + +#ifndef S112 +uint32_t ble_gap_qos_channel_survey_start_req_enc(uint32_t interval_us, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_QOS_CHANNEL_SURVEY_START); + + SER_PUSH_uint32(&interval_us); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_qos_channel_survey_start_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_GAP_QOS_CHANNEL_SURVEY_START); +} + +uint32_t ble_gap_qos_channel_survey_stop_req_enc(uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_QOS_CHANNEL_SURVEY_STOP); + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_qos_channel_survey_stop_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_GAP_QOS_CHANNEL_SURVEY_STOP); +} +#endif //!S112 +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gap_app.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gap_app.h new file mode 100644 index 0000000..715a8df --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gap_app.h @@ -0,0 +1,1667 @@ +/** + * Copyright (c) 2013 - 2018, 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_APP_H__ +#define BLE_GAP_APP_H__ + +/**@file + * + * @defgroup ble_gap_app GAP Application command request encoders and command response decoders + * @{ + * @ingroup ser_app_s130_codecs + * + * @brief GAP Application command request encoders and command response decoders. + */ +#include "ble.h" +#include "ble_gap.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(NRF_SD_BLE_API_VERSION) && (NRF_SD_BLE_API_VERSION <= 5) +/** + * @brief Encodes @ref sd_ble_gap_adv_data_set command request. + * + * @sa @ref ble_gap_adv_data_set_rsp_dec for command response decoder. + * + * @param[in] p_data Raw data to be placed in advertisement packet. If NULL, no changes + * are made to the current advertisement packet data. + * @param[in] dlen Data length for p_data. Max size: @ref BLE_GAP_ADV_SR_MAX_LEN_DEFAULT octets. + * Should be 0 if p_data is NULL, can be 0 if p_data is not NULL. + * @param[in] p_sr_data Raw data to be placed in scan response packet. If NULL, + * no changes are made to the current scan response packet data. + * @param[in] srdlen Data length for p_sr_data. Max size: @ref BLE_GAP_ADV_SR_MAX_LEN_DEFAULT octets. + * Should be 0 if p_sr_data is NULL, can be 0 if p_data is not NULL. + * @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_gap_adv_data_set_req_enc(uint8_t const * const p_data, + uint8_t dlen, + uint8_t const * const p_sr_data, + uint8_t srdlen, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_gap_adv_data_set command. + * + * @sa @ref ble_gap_adv_data_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_gap_adv_data_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); +#endif + +/** + * @brief Encodes @ref sd_ble_gap_adv_start command request. + * + * @sa @ref ble_gap_adv_start_rsp_dec for command response decoder. + * + * @param[in] p_adv_params Pointer to advertising parameters structure. + * @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_gap_adv_start_req_enc( +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t adv_handle, +#else + ble_gap_adv_params_t const * const p_adv_params, +#endif +#if NRF_SD_BLE_API_VERSION >= 4 + uint8_t conn_cfg_tag, +#endif + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_gap_adv_start command. + * + * @sa @ref ble_gap_adv_start_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_gap_adv_start_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/** + * @brief Encodes @ref sd_ble_gap_tx_power_set command request. + * + * @sa @ref ble_gap_tx_power_set_rsp_dec for command response decoder. + * + * @param[in] tx_power Radio transmit power in dBm (accepted values are -40, -30, -20, -16, -12, -8, -4, 0, and 4 dBm). + * @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_gap_tx_power_set_req_enc( +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t role, uint16_t handle, +#endif + int8_t tx_power, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_gap_tx_power_set command. + * + * @sa @ref ble_gap_tx_power_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_gap_tx_power_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/** + * @brief Encodes @ref sd_ble_gap_appearance_get command request. + * + * @sa @ref ble_gap_appearance_get_rsp_dec for command response decoder. + * + * @param[in] p_appearance Appearance (16 bit), see @ref BLE_APPEARANCES. + * @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_appearance will not be updated by the command + * request encoder. Updated values are set by @ref ble_gap_appearance_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_gap_appearance_get_req_enc(uint16_t const * const p_appearance, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_gap_appearance_get command. + * + * @sa @ref ble_gap_appearance_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_appearance Appearance (16 bit), see @ref BLE_APPEARANCES. + * @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_gap_appearance_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_appearance, + uint32_t * const p_result_code); + +/** + * @brief Encodes @ref sd_ble_gap_appearance_set command request. + * + * @sa @ref ble_gap_appearance_set_rsp_dec for command response decoder. + * + * @param[in] appearance Appearance (16 bit), see @ref BLE_APPEARANCES. + * @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_gap_appearance_set_req_enc(uint16_t appearance, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_gap_appearance_set command. + * + * @sa @ref ble_gap_appearance_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_gap_appearance_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/** + * @brief Encodes @ref sd_ble_gap_device_name_get command request. + * + * @sa @ref ble_gap_device_name_get_rsp_dec for command response decoder. + * + * @param[in] p_dev_name Pointer to an empty buffer where the UTF-8 <b>non NULL-terminated</b> + * string will be placed. Set to NULL to obtain the complete device + * name length. + * @param[in] p_dev_name_len Length of the buffer pointed by p_dev_name. + * @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_dev_name and \p p_len will not be updated by the command + * request encoder. Updated values are set by @ref ble_gap_device_name_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_gap_device_name_get_req_enc(uint8_t const * const p_dev_name, + uint16_t const * const p_dev_name_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_gap_device_name_get command. + * + * @sa @ref ble_gap_device_name_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_dev_name Pointer to an empty buffer where the UTF-8 + * <b>non NULL-terminated</b> string will be placed. + * @param[in,out] p_dev_name_len Length of the buffer pointed by p_dev_name, complete device name + * length on output. + * @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_gap_device_name_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_dev_name, + uint16_t * const p_dev_name_len, + uint32_t * const p_result_code); + +/** + * @brief Encodes @ref sd_ble_gap_device_name_set command request. + * + * @sa @ref ble_gap_device_name_set_rsp_dec for command response decoder. + * + * @param[in] p_write_perm Write permissions for the Device Name characteristic, see + * @ref ble_gap_conn_sec_mode_t. + * @param[in] p_dev_name Pointer to a UTF-8 encoded, <b>non NULL-terminated</b> string. + * @param[in] len Length of the UTF-8, <b>non NULL-terminated</b> string pointed + * to by p_dev_name in octets (must be smaller or equal + * than @ref BLE_GAP_DEVNAME_MAX_LEN). + * @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_gap_device_name_set_req_enc(ble_gap_conn_sec_mode_t const * const p_write_perm, + uint8_t const * const p_dev_name, + uint16_t len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_gap_device_name_set command. + * + * @sa @ref ble_gap_device_name_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_gap_device_name_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/** + * @brief Encodes @ref sd_ble_gap_ppcp_set command request. + * + * @sa @ref ble_gap_ppcp_set_rsp_dec for command response decoder. + * + * @param[in] p_conn_params Pointer to a @ref ble_gap_conn_params_t structure with the + * desired parameters. + * @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_gap_ppcp_set_req_enc(ble_gap_conn_params_t const * const p_conn_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_gap_ppcp_set command. + * + * @sa @ref ble_gap_ppcp_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_gap_ppcp_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_conn_param_update command request. + * + * @sa @ref ble_gap_conn_param_update_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] p_conn_params Pointer to desired connection parameters. + * @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_gap_conn_param_update_req_enc(uint16_t conn_handle, + ble_gap_conn_params_t const * const p_conn_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_conn_param_update command. + * + * @sa @ref ble_gap_conn_param_update_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_gap_conn_param_update_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_disconnect command request. + * + * @sa @ref ble_gap_disconnect_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] hci_status_code HCI status code, see @ref BLE_HCI_STATUS_CODES. + * @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_gap_disconnect_req_enc(uint16_t conn_handle, + uint8_t hci_status_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_disconnect command. + * + * @sa @ref ble_gap_disconnect_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_gap_disconnect_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + + +/**@brief Encodes @ref sd_ble_gap_rssi_stop command request. + * + * @sa @ref ble_gap_rssi_stop_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @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_gap_rssi_stop_req_enc(uint16_t conn_handle, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_rssi_stop command. + * + * @sa @ref ble_gap_rssi_stop_rsp_dec for command response decoder. + * + * @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_gap_rssi_stop_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + + + + +/**@brief Encodes @ref sd_ble_gap_ppcp_get command request. + * + * @sa @ref ble_gap_ppcp_get_rsp_dec for command response decoder. + * + * @param[in] p_conn_params Pointer to a @ref ble_gap_conn_params_t structure where the + * parameters 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_params will not be updated by the command request encoder. Updated values are + * set by @ref ble_gap_ppcp_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_gap_ppcp_get_req_enc(ble_gap_conn_params_t const * const p_conn_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_ppcp_get command. + * + * @sa @ref ble_gap_ppcp_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_conn_params Pointer to a @ref ble_gap_conn_params_t structure where the parameters + * will be stored. + * @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_gap_ppcp_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_conn_params_t * const p_conn_params, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_auth_key_reply command request. + * + * @sa @ref ble_gap_auth_key_reply_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] key_type Key type which defines length of key data as defined for + * @ref sd_ble_gap_auth_key_reply . + * @param[in] p_key Pointer to a buffer which contains key + * @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. Incorrect param provided (key_type). + */ +uint32_t ble_gap_auth_key_reply_req_enc(uint16_t conn_handle, + uint8_t key_type, + uint8_t const * const p_key, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_auth_key_reply command. + * + * @sa @ref ble_gap_auth_key_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 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_gap_auth_key_reply_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_sec_info_reply command request. + * + * @sa @ref ble_gap_sec_info_reply_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] p_enc_info Pointer to a @ref ble_gap_enc_info_t encryption information + * structure. + * @param[in] p_id_info Pointer to a @ref ble_gap_irk_t id information + * structure. + * @param[in] p_sign_info Pointer to a @ref ble_gap_sign_info_t signing information + * structure. + * @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_gap_sec_info_reply_req_enc(uint16_t conn_handle, + ble_gap_enc_info_t const * p_enc_info, + ble_gap_irk_t const * p_id_info, + ble_gap_sign_info_t const * p_sign_info, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_sec_info_reply command. + * + * @sa @ref ble_gap_sec_info_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 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_gap_sec_info_reply_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_sec_params_reply command request. + * + * @sa @ref ble_gap_sec_params_reply_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] sec_status Security status, see @ref BLE_GAP_SEC_STATUS. + * @param[in] p_sec_params Pointer to @ref ble_gap_sec_params_t security parameters + * structure. + * @param[in] p_sec_keyset Pointer to @ref ble_gap_sec_keyset_t security keys + * structure. + * @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_gap_sec_params_reply_req_enc(uint16_t conn_handle, + uint8_t sec_status, + ble_gap_sec_params_t const * const p_sec_params, + ble_gap_sec_keyset_t const * const p_sec_keyset, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_sec_params_reply command. + * + * @sa @ref ble_gap_sec_params_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[in] p_sec_keyset Pointer to @ref ble_gap_sec_keyset_t security keys + * @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_gap_sec_params_reply_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_sec_keyset_t const * const p_sec_keyset, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_authenticate command request. + * + * @sa @ref ble_gap_authenticate_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] p_sec_params Pointer to a @ref ble_gap_sec_params_t security parameters + * structure. + * @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_gap_authenticate_req_enc(uint16_t conn_handle, + ble_gap_sec_params_t const * const p_sec_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_authenticate command. + * + * @sa @ref ble_gap_authenticate_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_gap_authenticate_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_adv_stop command request. + * + * @sa @ref ble_gap_adv_stop_rsp_dec for command response decoder. + * + * @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_gap_adv_stop_req_enc( +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t adv_handle, +#endif + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_adv_stop command. + * + * @sa @ref ble_gap_adv_stop_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_gap_adv_stop_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_conn_sec_get command request. + * + * @sa @ref ble_gap_conn_sec_get_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] p_conn_sec Pointer to \ref ble_gap_conn_sec_t which will be filled in + * response. + * @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_gap_conn_sec_get_req_enc(uint16_t conn_handle, + ble_gap_conn_sec_t const * const p_conn_sec, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_conn_sec_get command. + * + * @sa @ref ble_gap_conn_sec_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_conn_sec Pointer to pointer to \ref ble_gap_conn_sec_t which will be filled by + * the decoded data (if present). + * @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_gap_conn_sec_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_conn_sec_t * * const pp_conn_sec, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_rssi_start command request. + * + * @sa @ref ble_gap_rssi_start_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] threshold_dbm Threshold in dBm. + * @param[in] skip_count Sample skip count. + * @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_gap_rssi_start_req_enc(uint16_t conn_handle, + uint8_t threshold_dbm, + uint8_t skip_count, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_rssi_start command. + * + * @sa @ref ble_gap_rssi_start_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_gap_rssi_start_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); +#ifndef S112 +/**@brief Encodes @ref sd_ble_gap_scan_stop command request. + * + * @sa @ref ble_gap_scan_stop_rsp_dec for command response decoder. + * + * @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_gap_scan_stop_req_enc(uint8_t * const p_buf, uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_scan_stop command. + * + * @sa @ref ble_gap_scan_stop_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_gap_scan_stop_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_scan_start command request. + * + * @sa @ref ble_gap_scan_start_rsp_dec for command response decoder. + * + * @param[in] p_scan_params Pointer to scan params structure. + * @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_gap_scan_start_req_enc(ble_gap_scan_params_t const * p_scan_params, +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 + ble_data_t const * p_adv_report_buffer, +#endif + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_scan_start command. + * + * @sa @ref ble_gap_scan_start_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_gap_scan_start_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_connect command request. + * + * @sa @ref ble_gap_connect_rsp_dec for command response decoder. + * + * @param[in] p_peer_addr Pointer to peer address. + * @param[in] p_scan_params Pointer to scan params structure. + * @param[in] p_conn_params Pointer to desired connection parameters. + * @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_gap_connect_req_enc(ble_gap_addr_t const * const p_peer_addr, + ble_gap_scan_params_t const * const p_scan_params, + ble_gap_conn_params_t const * const p_conn_params, +#if NRF_SD_BLE_API_VERSION >= 4 + uint8_t conn_cfg_tag, +#endif + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_connect command. + * + * @sa @ref ble_gap_connect_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_gap_connect_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_connect_cancel command request. + * + * @sa @ref ble_gap_connect_cancel_rsp_dec for command response decoder. + * + * @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_gap_connect_cancel_req_enc(uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_connect_cancel command. + * + * @sa @ref ble_gap_connect_cancel_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_gap_connect_cancel_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + + +/**@brief Encodes @ref sd_ble_gap_encrypt command request. + * + * @sa @ref ble_gap_encrypt_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle. + * @param[in] p_master_id Pointer to a master identification structure. + * @param[in] p_enc_info Pointer to desired connection parameters. + * @param[in] p_buf Pointer to a ble_gap_enc_info_t encryption information structure. + * @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_gap_encrypt_req_enc(uint16_t conn_handle, + ble_gap_master_id_t const * const p_master_id, + ble_gap_enc_info_t const * const p_enc_info, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + + +/**@brief Decodes response to @ref sd_ble_gap_encrypt command. + * + * @sa @ref ble_gap_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_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_gap_encrypt_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); +#endif //!S112 + +/**@brief Encodes @ref sd_ble_gap_rssi_get command request. + * + * @sa @ref ble_gap_rssi_get_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle. + * @param[in] p_rssi Pointer to the RSSI value. + * @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_gap_rssi_get_req_enc(uint16_t conn_handle, + int8_t const * const p_rssi, +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t const * const p_ch_index, +#endif + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_rssi_get command. + * + * @sa @ref ble_gap_rssi_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_rssi Pointer to RSSI value. + * @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_gap_rssi_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + int8_t * const p_rssi, +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t * const p_ch_index, +#endif + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_keypress_notify command request. + * + * @sa @ref ble_gap_keypress_notify_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle. + * @param[in] kp_not See @ref sd_ble_gap_keypress_notify. + * @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_gap_keypress_notify_req_enc(uint16_t conn_handle, + uint8_t kp_not, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_keypress_notify command. + * + * @sa @ref ble_gap_keypress_notify_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_gap_keypress_notify_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_lesc_dhkey_reply command request. + * + * @sa @ref ble_gap_lesc_dhkey_reply_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle. + * @param[in] p_dhkey See @ref sd_ble_gap_lesc_dhkey_reply. + * @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_gap_lesc_dhkey_reply_req_enc(uint16_t conn_handle, + ble_gap_lesc_dhkey_t const *p_dhkey, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_lesc_dhkey_reply command. + * + * @sa @ref ble_gap_lesc_dhkey_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 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_gap_lesc_dhkey_reply_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_lesc_oob_data_set command request. + * + * @sa @ref ble_gap_lesc_oob_data_set_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle. + * @param[in] p_oobd_own See @ref sd_ble_gap_lesc_oob_data_set. + * @param[in] p_oobd_peer See @ref sd_ble_gap_lesc_oob_data_set. + * @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_gap_lesc_oob_data_set_req_enc(uint16_t conn_handle, + ble_gap_lesc_oob_data_t const *p_oobd_own, + ble_gap_lesc_oob_data_t const *p_oobd_peer, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_lesc_oob_data_set command. + * + * @sa @ref ble_gap_lesc_oob_data_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 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_gap_lesc_oob_data_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_lesc_oob_data_get command request. + * + * @sa @ref ble_gap_lesc_oob_data_get_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle. + * @param[in] p_pk_own See @ref sd_ble_gap_lesc_oob_data_get. + * @param[in] p_oobd_own See @ref sd_ble_gap_lesc_oob_data_get. + * @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_gap_lesc_oob_data_get_req_enc(uint16_t conn_handle, + ble_gap_lesc_p256_pk_t const *p_pk_own, + ble_gap_lesc_oob_data_t *p_oobd_own, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_lesc_oob_data_get command. + * + * @sa @ref ble_gap_lesc_oob_data_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_oobd_own Pointer to pointer to location where OOB data is decoded. + * @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_gap_lesc_oob_data_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_lesc_oob_data_t * *pp_oobd_own, + uint32_t * const p_result_code); + +/** + * @brief Encodes @ref sd_ble_gap_addr_get command request. + * + * @sa @ref ble_gap_addr_get_rsp_dec for command response decoder. + * + * @param[in] p_address Pointer to address. + * @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_address will not be updated by the command + * request encoder. Updated values are set by @ref ble_gap_addr_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_gap_addr_get_req_enc(ble_gap_addr_t const * const p_address, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_gap_addr_get command. + * + * @sa @ref ble_gap_addr_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_address Pointer to address. + * @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_gap_addr_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_addr_t * const p_address, + uint32_t * const p_result_code); + +/** + * @brief Encodes @ref sd_ble_gap_addr_set command request. + * + * @sa @ref ble_gap_addr_set_rsp_dec for command response decoder. + * + * @param[in] p_addr Pointer to address structure. + * @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_gap_addr_set_req_enc(ble_gap_addr_t const * const p_addr, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_gap_addr_set command. + * + * @sa @ref ble_gap_addr_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_gap_addr_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/** + * @brief Encodes @ref sd_ble_gap_privacy_set command request. + * + * @sa @ref ble_gap_privacy_set_rsp_dec for command response decoder. + * + * @param[in] p_privacy_params Pointer to privacy settings structure. + * @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_gap_privacy_set_req_enc(ble_gap_privacy_params_t const * p_privacy_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_gap_privacy_set command. + * + * @sa @ref ble_gap_privacy_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_gap_privacy_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/** + * @brief Encodes @ref sd_ble_gap_privacy_get command request. + * + * @sa @ref ble_gap_privacy_get_rsp_dec for command response decoder. + * + * @param[in] p_privacy_params Pointer to privacy settings structure. + * @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_gap_privacy_get_req_enc(ble_gap_privacy_params_t const * const p_privacy_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_gap_privacy_get command. + * + * @sa @ref ble_gap_privacy_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_privacy_params Pointer to privacy settings structure. + * @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_gap_privacy_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_privacy_params_t const * const p_privacy_params, + uint32_t * const p_result_code); + +/** + * @brief Encodes @ref sd_ble_gap_whitelist_set command request. + * + * @sa @ref ble_gap_whitelist_set_rsp_dec for command response decoder. + * + * @param[in] pp_wl_addrs Pointer to a whitelist of peer addresses. + * @param[out] len Pointer to a length of the whitelist. + * @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_gap_whitelist_set_req_enc(ble_gap_addr_t const * const * const pp_wl_addrs, + uint8_t const len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_gap_whitelist_set command. + * + * @sa @ref ble_gap_whitelist_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_gap_whitelist_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/** + * @brief Encodes @ref sd_ble_gap_device_identities_set command request. + * + * @sa @ref ble_gap_device_identities_set_rsp_dec for command response decoder. + * + * @param[in] pp_id_keys Pointer to an array of peer identity addresses and peer IRKs. + * @param[in] pp_local_irks Pointer to an array of local IRKs. + * @param[out] len Pointer to a length of the device identity list. + * @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_gap_device_identities_set_req_enc(ble_gap_id_key_t const * const * const pp_id_keys, + ble_gap_irk_t const * const * const pp_local_irks, + uint8_t const len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); +/** + * @brief Decodes response to @ref sd_ble_gap_device_identities_set command. + * + * @sa @ref ble_gap_device_identities_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_gap_device_identities_set_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 && !defined(S112) +/** + * @brief Encodes @ref sd_ble_gap_data_length_update command request. + * + * @sa @ref ble_gap_data_length_update_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle. + * @param[in] p_dl_params Pointer to a data length params structure. + * @param[out] p_dl_limitation Pointer to a data length limitation structure. + * @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_gap_data_length_update_req_enc(uint16_t conn_handle, + ble_gap_data_length_params_t const * p_dl_params, + ble_gap_data_length_limitation_t * p_dl_limitation, + uint8_t * const p_buf, + uint32_t * const p_buf_len); +/** + * @brief Decodes response to @ref sd_ble_gap_data_length_update command. + * + * @sa @ref ble_gap_data_length_update_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_dl_limitation Pointer to a data length limitation structure. + * @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_gap_data_length_update_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_data_length_limitation_t * p_dl_limitation, + uint32_t * const p_result_code); +#endif + +#if NRF_SD_BLE_API_VERSION >= 5 +/**@brief Encodes @ref sd_ble_gap_phy_update command request. + * + * @sa @ref ble_gap_phy_update_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] p_gap_phys Pointer to a @ref ble_gap_phys_t + * structure. + * @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_gap_phy_update_req_enc(uint16_t conn_handle, + ble_gap_phys_t const * p_gap_phys, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_phy_update command. + * + * @sa @ref ble_gap_phy_update_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_gap_phy_update_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 >= 6 +/**@brief Encodes @ref sd_ble_gap_adv_set_configure command request. + * + * @sa @ref ble_gap_adv_set_configure_rsp_dec for command response decoder. + * + * @param[in] p_adv_handle Advertising handle. + * @param[in] p_adv_data Pointer to a @ref ble_gap_adv_data_t structure. + * @param[in] p_adv_params Pointer to a @ref ble_gap_adv_params_t structure. + * @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_gap_adv_set_configure_req_enc(uint8_t * p_adv_handle, + ble_gap_adv_data_t const * p_adv_data, + ble_gap_adv_params_t const *p_adv_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + + +/**@brief Decodes response to @ref sd_ble_gap_adv_set_configure command. + * + * @sa @ref ble_gap_adv_set_configure_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_adv_handle Advertising handle. + * @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_gap_adv_set_configure_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * p_adv_handle, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_qos_channel_survey_start command request. + * + * @sa @ref ble_gap_qos_channel_survey_start_rsp_dec for command response decoder. + * + * @param[in] interval_us Interval. + * @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_gap_qos_channel_survey_start_req_enc(uint32_t interval_us, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + + +/**@brief Decodes response to @ref sd_ble_gap_qos_channel_survey_start command. + * + * @sa @ref ble_gap_qos_channel_survey_start_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_gap_qos_channel_survey_start_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_qos_channel_survey_stop command request. + * + * @sa @ref ble_gap_qos_channel_survey_stop_rsp_dec for command response decoder. + * + * @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_gap_qos_channel_survey_stop_req_enc(uint8_t * const p_buf, + uint32_t * const p_buf_len); + + +/**@brief Decodes response to @ref sd_ble_gap_qos_channel_survey_stop command. + * + * @sa @ref ble_gap_qos_channel_survey_stop_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_gap_qos_channel_survey_stop_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); +#endif +/** @} */ +#ifdef __cplusplus +} +#endif + +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gap_evt_app.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gap_evt_app.c new file mode 100644 index 0000000..150a891 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gap_evt_app.c @@ -0,0 +1,415 @@ +/** + * Copyright (c) 2014 - 2018, 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 "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. + err_code = app_ble_gap_scan_data_fetch_clear(&p_event->evt.gap_evt.params.adv_report.data); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); +#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); +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 + if (BLE_GAP_ROLE_PERIPH == p_event->evt.gap_evt.params.connected.role) + { + err_code = app_ble_gap_adv_set_unregister(p_event->evt.gap_evt.params.connected.adv_handle, + &p_event->evt.gap_evt.params.connected.adv_data.adv_data.p_data, + &p_event->evt.gap_evt.params.connected.adv_data.scan_rsp_data.p_data); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + } +#endif + 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_uint16(&p_event->evt.gap_evt.params.timeout.params.adv_report_buffer.len); + err_code = app_ble_gap_scan_data_fetch_clear(&p_event->evt.gap_evt.params.timeout.params.adv_report_buffer); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + } +#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 +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); + + err_code = app_ble_gap_adv_set_unregister( + p_event->evt.gap_evt.params.adv_set_terminated.adv_handle, + &p_event->evt.gap_evt.params.adv_set_terminated.adv_data.adv_data.p_data, + &p_event->evt.gap_evt.params.adv_set_terminated.adv_data.scan_rsp_data.p_data); + SER_ERROR_CHECK(err_code == NRF_SUCCESS, err_code); + + SER_EVT_DEC_END; +} +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gap_evt_app.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gap_evt_app.h new file mode 100644 index 0000000..b36e70b --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gap_evt_app.h @@ -0,0 +1,546 @@ +/** + * Copyright (c) 2014 - 2018, 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 +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gattc_app.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gattc_app.c new file mode 100644 index 0000000..dc0057c --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gattc_app.c @@ -0,0 +1,286 @@ +/** + * Copyright (c) 2013 - 2018, 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); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gattc_app.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gattc_app.h new file mode 100644 index 0000000..ddb237e --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gattc_app.h @@ -0,0 +1,491 @@ +/** + * Copyright (c) 2013 - 2018, 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 + + diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gattc_evt_app.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gattc_evt_app.c new file mode 100644 index 0000000..c049ed4 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gattc_evt_app.c @@ -0,0 +1,262 @@ +/** + * Copyright (c) 2013 - 2018, 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 diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gattc_evt_app.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gattc_evt_app.h new file mode 100644 index 0000000..73a0c78 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gattc_evt_app.h @@ -0,0 +1,364 @@ +/** + * Copyright (c) 2014 - 2018, 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 diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gatts_app.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gatts_app.c new file mode 100644 index 0000000..eb7c76c --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gatts_app.c @@ -0,0 +1,439 @@ +/** + * Copyright (c) 2013 - 2018, 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); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gatts_app.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gatts_app.h new file mode 100644 index 0000000..3dcf5d5 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gatts_app.h @@ -0,0 +1,677 @@ +/** + * Copyright (c) 2013 - 2018, 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__ + + diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gatts_evt_app.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gatts_evt_app.c new file mode 100644 index 0000000..bbe71e8 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gatts_evt_app.c @@ -0,0 +1,190 @@ +/** + * Copyright (c) 2013 - 2018, 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 diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gatts_evt_app.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gatts_evt_app.h new file mode 100644 index 0000000..d294b81 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gatts_evt_app.h @@ -0,0 +1,249 @@ +/** + * Copyright (c) 2014 - 2018, 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 diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_l2cap_app.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_l2cap_app.c new file mode 100644 index 0000000..8378c80 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_l2cap_app.c @@ -0,0 +1,279 @@ +/** + * Copyright (c) 2014 - 2018, 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 diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_l2cap_app.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_l2cap_app.h new file mode 100644 index 0000000..68d8f68 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_l2cap_app.h @@ -0,0 +1,242 @@ +/** + * Copyright (c) 2014 - 2018, 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__ + +/** + @} + */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_l2cap_evt_app.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_l2cap_evt_app.c new file mode 100644 index 0000000..392d860 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_l2cap_evt_app.c @@ -0,0 +1,183 @@ +/** + * Copyright (c) 2014 - 2018, 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 diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_l2cap_evt_app.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_l2cap_evt_app.h new file mode 100644 index 0000000..e2d7958 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_l2cap_evt_app.h @@ -0,0 +1,126 @@ +/** + * Copyright (c) 2014 - 2018, 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 diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/nrf_soc_app.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/nrf_soc_app.c new file mode 100644 index 0000000..dab842b --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/nrf_soc_app.c @@ -0,0 +1,95 @@ +/** + * Copyright (c) 2013 - 2018, 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; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/nrf_soc_app.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/nrf_soc_app.h new file mode 100644 index 0000000..ed1cb84 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/nrf_soc_app.h @@ -0,0 +1,147 @@ +/** + * Copyright (c) 2013 - 2018, 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__ |