diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2018-08-23 17:08:59 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2018-08-23 17:12:21 +0200 |
commit | 3061ecca3d0fdfb87dabbf5f63c9e06c2a30f53a (patch) | |
tree | ab49cc16ed0b853452c5c2ed2d3042416d628986 /thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity | |
download | iot-sensors-master.tar.gz iot-sensors-master.tar.bz2 iot-sensors-master.tar.xz iot-sensors-master.zip |
Diffstat (limited to 'thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity')
111 files changed, 24644 insertions, 0 deletions
diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/middleware/conn_mw_ant.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/middleware/conn_mw_ant.c new file mode 100644 index 0000000..95b9b24 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/middleware/conn_mw_ant.c @@ -0,0 +1,1196 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "conn_mw_ant.h" +#include "ble_serialization.h" +#include "nrf_log_ctrl.h" +#include "sdk_config.h" + +#define ANT_BUFFER_SIZE_FOR_SD ANT_ENABLE_GET_REQUIRED_SPACE(ANT_SER_CONFIG_TOTAL_CHANNELS_ALLOCATED, \ + ANT_SER_CONFIG_ENCRYPTED_CHANNELS, \ + ANT_SER_CONFIG_BURST_QUEUE_SIZE, \ + ANT_SER_CONFIG_EVENT_QUEUE_SIZE) +#define ANT_ADV_BURST_CFG_SIZE_MAX (11u) +#define ANT_CRYPTO_INFO_SIZE (((MESG_CONFIG_ENCRYPT_REQ_CONFIG_USER_DATA_SIZE) - \ + (MESG_CHANNEL_NUM_SIZE)) + \ + ((MESG_CONFIG_ENCRYPT_REQ_CONFIG_ID_SIZE) - \ + (MESG_CHANNEL_NUM_SIZE))) +#define ANT_CRYPTO_INFO_MAX_SIZE (MESG_CONFIG_ENCRYPT_REQ_CONFIG_USER_DATA_SIZE - \ + MESG_CHANNEL_NUM_SIZE) + +#ifdef ANT_STACK_SUPPORT_REQD +static union +{ + uint8_t u8[ANT_BUFFER_SIZE_FOR_SD]; + uint32_t u32[1]; // force allign to uint32_t +}ant_stack_buffer; /*!< Memory buffer provided in order to support channel configuration */ +#endif + +uint32_t conn_mw_ant_enable(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + + ANT_ENABLE params; + ANT_ENABLE * p_params = ¶ms; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_enable_req_dec(p_rx_buf, rx_buf_len, &p_params); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT(p_params -> ucTotalNumberOfChannels == ANT_SER_CONFIG_TOTAL_CHANNELS_ALLOCATED, err_code); + SER_ASSERT(p_params -> ucNumberOfEncryptedChannels == ANT_SER_CONFIG_ENCRYPTED_CHANNELS, err_code); + SER_ASSERT(p_params -> usNumberOfEvents == ANT_SER_CONFIG_EVENT_QUEUE_SIZE, err_code); + SER_ASSERT(p_params -> usMemoryBlockByteSize == ANT_BUFFER_SIZE_FOR_SD, err_code); + + ANT_ENABLE m_ant_enable_cfg = + { + .ucTotalNumberOfChannels = p_params -> ucTotalNumberOfChannels, + .ucNumberOfEncryptedChannels = p_params -> ucNumberOfEncryptedChannels, + .usNumberOfEvents = p_params -> usNumberOfEvents, + .pucMemoryBlockStartLocation = ant_stack_buffer.u8, + .usMemoryBlockByteSize = p_params -> usMemoryBlockByteSize + }; + + sd_err_code = sd_ant_enable(&m_ant_enable_cfg); + + err_code = ant_enable_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_channel_assign(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t channel; + uint8_t type; + uint8_t network; + uint8_t ext_assign; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code =ant_channel_assign_req_dec(p_rx_buf, rx_buf_len, &channel, &type, &network, &ext_assign); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + //disabled till codec is adopted. + sd_err_code = sd_ant_channel_assign(channel, type, network, ext_assign); + + + err_code = ant_channel_assign_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; + +} + +uint32_t conn_ant_channel_open_with_offset(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t channel; + uint16_t usOffset; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_channel_open_with_offset_req_dec(p_rx_buf, rx_buf_len, &channel, &usOffset); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_channel_open_with_offset(channel, usOffset); + + err_code = ant_channel_open_with_offset_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + + +uint32_t conn_ant_channel_id_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t channel; + uint16_t device_number; + uint8_t device_type; + uint8_t transmission_type; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code =ant_channel_id_set_req_dec(p_rx_buf, rx_buf_len, &channel, &device_number, &device_type, &transmission_type); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + //disabled till codec is adopted. + sd_err_code = sd_ant_channel_id_set(channel, device_number, device_type, transmission_type); + + err_code = ant_channel_id_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_channel_period_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t channel; + uint16_t period; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_channel_period_set_req_dec(p_rx_buf, rx_buf_len, &channel, &period); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_channel_period_set(channel, period); + + err_code = ant_channel_period_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_channel_radio_freq_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t channel; + uint8_t freq; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_channel_radio_freq_set_req_dec(p_rx_buf, rx_buf_len, &channel, &freq); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_channel_radio_freq_set(channel, freq); + + err_code = ant_channel_radio_freq_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_broadcast_message_tx(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t channel; + uint8_t size; + uint8_t mesg[ANT_STANDARD_DATA_PAYLOAD_SIZE]; + uint8_t * p_mesg = mesg; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_broadcast_message_tx_req_dec(p_rx_buf, rx_buf_len, &channel, &size, &p_mesg); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_broadcast_message_tx(channel, size, p_mesg); + + err_code = ant_broadcast_message_tx_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_acknowledge_message_tx(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t channel; + uint8_t size; + uint8_t mesg[ANT_STANDARD_DATA_PAYLOAD_SIZE]; + uint8_t * p_mesg = mesg; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_acknowledge_message_tx_req_dec(p_rx_buf, rx_buf_len, &channel, &size, &p_mesg); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_acknowledge_message_tx(channel, size, p_mesg); + + err_code = ant_acknowledge_message_tx_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_channel_unassign(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t channel; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_channel_unassign_req_dec(p_rx_buf, rx_buf_len, &channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_channel_unassign(channel); + + err_code = ant_channel_unassign_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_channel_close(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t channel; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_channel_close_req_dec(p_rx_buf, rx_buf_len, &channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_channel_close(channel); + + err_code = ant_channel_close_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_network_address_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t network; + uint8_t network_address[MESG_NETWORK_KEY_SIZE - MESG_CHANNEL_NUM_SIZE]; + uint8_t * p_network_address = network_address; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_network_address_set_req_dec(p_rx_buf, rx_buf_len, &network, &p_network_address); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_network_address_set(network, p_network_address); + + err_code = ant_network_address_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_channel_radio_tx_power_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t channel; + uint8_t tx_power; + uint8_t custom_tx_power; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_channel_radio_tx_power_set_req_dec(p_rx_buf, rx_buf_len, &channel, &tx_power, &custom_tx_power); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_channel_radio_tx_power_set(channel, tx_power, custom_tx_power); + + err_code = ant_channel_radio_tx_power_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_channel_rx_search_timeout_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t channel; + uint8_t timeout; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_channel_rx_search_timeout_set_req_dec(p_rx_buf, rx_buf_len, &channel, &timeout); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_channel_rx_search_timeout_set(channel, timeout); + + err_code = ant_channel_rx_search_timeout_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_channel_low_priority_rx_search_timeout_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t channel; + uint8_t timeout; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_channel_low_priority_rx_search_timeout_set_req_dec(p_rx_buf, rx_buf_len, &channel, &timeout); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_channel_low_priority_rx_search_timeout_set(channel, timeout); + + err_code = ant_channel_low_priority_rx_search_timeout_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_prox_search_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t channel; + uint8_t prox_threshold; + uint8_t custom_prox_threshold; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_prox_search_set_req_dec(p_rx_buf, rx_buf_len, &channel, &prox_threshold, &custom_prox_threshold); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_prox_search_set(channel, prox_threshold, custom_prox_threshold); + + err_code = ant_prox_search_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_search_waveform_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t channel; + uint16_t waveform; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_search_waveform_set_req_dec(p_rx_buf, rx_buf_len, &channel, &waveform); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_search_waveform_set(channel, waveform); + + err_code = ant_search_waveform_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_channel_id_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t device_number; + uint8_t device_type; + uint8_t transmit_type; + uint8_t channel; + uint16_t * p_device_number = &device_number; + uint8_t * p_device_type = &device_type; + uint8_t * p_transmit_type = &transmit_type; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_channel_id_get_req_dec(p_rx_buf, rx_buf_len, &channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_channel_id_get(channel, p_device_number, p_device_type, p_transmit_type); + + err_code = ant_channel_id_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_device_number, p_device_type, p_transmit_type); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_channel_radio_freq_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t r_freq; + uint8_t channel; + uint8_t * p_r_freq = &r_freq; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_channel_radio_freq_get_req_dec(p_rx_buf, rx_buf_len, &channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_channel_radio_freq_get(channel, p_r_freq); + + err_code = ant_channel_radio_freq_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_r_freq); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_channel_period_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t period; + uint8_t channel; + uint16_t * p_period = . + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_channel_period_get_req_dec(p_rx_buf, rx_buf_len, &channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_channel_period_get(channel, p_period); + + err_code = ant_channel_period_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_period); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_search_channel_priority_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t channel; + uint8_t search_priority; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_search_channel_priority_set_req_dec(p_rx_buf, rx_buf_len, &channel, &search_priority); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_search_channel_priority_set(channel, search_priority); + + err_code = ant_search_channel_priority_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_active_search_sharing_cycles_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t channel; + uint8_t cycles; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_active_search_sharing_cycles_set_req_dec(p_rx_buf, rx_buf_len, &channel, &cycles); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_active_search_sharing_cycles_set(channel, cycles); + + err_code = ant_active_search_sharing_cycles_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_lib_config_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t ant_lib_config; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_lib_config_set_req_dec(p_rx_buf, rx_buf_len, &ant_lib_config); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_lib_config_set(ant_lib_config); + + err_code = ant_lib_config_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_active_search_sharing_cycles_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t cycles; + uint8_t channel; + uint8_t * p_cycles = &cycles; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_active_search_sharing_cycles_get_req_dec(p_rx_buf, rx_buf_len, &channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_active_search_sharing_cycles_get(channel, p_cycles); + + err_code = ant_active_search_sharing_cycles_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_cycles); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_lib_config_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t ant_lib_config; + uint8_t * p_ant_lib_config = &ant_lib_config; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + sd_err_code = sd_ant_lib_config_get(p_ant_lib_config); + + err_code = ant_lib_config_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_ant_lib_config); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_lib_config_clear(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t ant_lib_config; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_lib_config_clear_req_dec(p_rx_buf, rx_buf_len, &ant_lib_config); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_lib_config_clear(ant_lib_config); + + err_code = ant_lib_config_clear_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_stack_reset(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + sd_err_code = sd_ant_stack_reset(); + + err_code = ant_stack_reset_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_rx_scan_mode_start(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t sync_channel_packets_only; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_rx_scan_mode_start_req_dec(p_rx_buf, rx_buf_len, &sync_channel_packets_only); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_rx_scan_mode_start(sync_channel_packets_only); + + err_code = ant_rx_scan_mode_start_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_id_list_add(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t channel; + uint8_t dev_id[ANT_ID_SIZE]; + uint8_t * p_dev_id = dev_id; + uint8_t list_index; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_id_list_add_req_dec(p_rx_buf, rx_buf_len, &channel, &p_dev_id, &list_index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_id_list_add(channel, p_dev_id, list_index); + + err_code = ant_id_list_add_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_id_list_config(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t channel; + uint8_t id_list_size; + uint8_t inc_exc_flag; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_id_list_config_req_dec(p_rx_buf, rx_buf_len, &channel, &id_list_size, &inc_exc_flag); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_id_list_config(channel, id_list_size, inc_exc_flag); + + err_code = ant_id_list_config_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_channel_status_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t status; + uint8_t channel; + uint8_t * p_status = &status; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_channel_status_get_req_dec(p_rx_buf, rx_buf_len, &channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_channel_status_get(channel, p_status); + + err_code = ant_channel_status_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_status); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_cw_test_mode_init(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + sd_err_code = sd_ant_cw_test_mode_init(); + + err_code = ant_cw_test_mode_init_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_cw_test_mode(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t radio_freq; + uint8_t tx_power; + uint8_t custom_tx_power; + uint8_t mode; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_cw_test_mode_req_dec(p_rx_buf, rx_buf_len, &radio_freq, &tx_power, &custom_tx_power, &mode); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_cw_test_mode(radio_freq, tx_power, custom_tx_power, mode); + + err_code = ant_cw_test_mode_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_version_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t version[MESG_BUFFER_SIZE]; + memset(version, 0, sizeof(version)); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + sd_err_code = sd_ant_version_get(version); + + err_code = ant_version_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, version); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_capabilities_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t capabilities[MESG_CAPABILITIES_SIZE]; + memset(capabilities, 0, sizeof(capabilities)); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + sd_err_code = sd_ant_capabilities_get(capabilities); + + err_code = ant_capabilities_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, capabilities); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_crypto_channel_enable(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t channel; + uint8_t enable; + uint8_t key_num; + uint8_t decimation_rate; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_crypto_channel_enable_req_dec(p_rx_buf, rx_buf_len, &channel, &enable, &key_num, &decimation_rate); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_crypto_channel_enable(channel, enable, key_num, decimation_rate); + + err_code = ant_crypto_channel_enable_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_adv_burst_config_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t size; + uint8_t config[ANT_ADV_BURST_CFG_SIZE_MAX]; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_adv_burst_config_set_req_dec(p_rx_buf, rx_buf_len, config, &size); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_adv_burst_config_set(config, size); + + err_code = ant_adv_burst_config_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_crypto_key_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t key_num; + uint8_t key[SIZE_OF_ENCRYPTED_KEY]; + uint8_t * p_key = key; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_crypto_key_set_req_dec(p_rx_buf, rx_buf_len, &key_num, &p_key); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_crypto_key_set(key_num, p_key); + + err_code = ant_crypto_key_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_crypto_info_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t type; + uint8_t info[ANT_CRYPTO_INFO_SIZE]; + uint8_t * p_info = info; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_crypto_info_set_req_dec(p_rx_buf, rx_buf_len, &type, &p_info); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_crypto_info_set(type, p_info); + + err_code = ant_crypto_info_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_crypto_info_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t type; + uint8_t info[ANT_CRYPTO_INFO_MAX_SIZE]; + memset(info, 0, sizeof(info)); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_crypto_info_get_req_dec(p_rx_buf, rx_buf_len, &type); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_crypto_info_get(type, info); + + err_code = ant_crypto_info_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, type, info); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_coex_config_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t channel; + uint8_t coex_config_buffer[(MESG_BUFFER_SIZE / 2) - 1]; + uint8_t adv_coex_config_buffer[(MESG_BUFFER_SIZE / 2) - 1]; + + ANT_BUFFER_PTR coex_config = + { + .ucBufferSize = 0, + .pucBuffer = coex_config_buffer + }; + + ANT_BUFFER_PTR adv_coex_config = + { + .ucBufferSize = 0, + .pucBuffer = adv_coex_config_buffer + }; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_coex_config_set_req_dec(p_rx_buf, rx_buf_len, &channel, &coex_config, &adv_coex_config); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + if (coex_config.ucBufferSize == 0 && adv_coex_config.ucBufferSize == 0) + { + sd_err_code = sd_ant_coex_config_set(channel, NULL, NULL); + } + else if (coex_config.ucBufferSize == 0) + { + sd_err_code = sd_ant_coex_config_set(channel, NULL, &adv_coex_config); + } + else if (adv_coex_config.ucBufferSize == 0) + { + sd_err_code = sd_ant_coex_config_set(channel, &coex_config, NULL); + } + else + { + sd_err_code = sd_ant_coex_config_set(channel, &coex_config, &adv_coex_config); + } + + err_code = ant_coex_config_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_ant_coex_config_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t channel; + uint8_t coex_config_buffer[(MESG_BUFFER_SIZE / 2) - 1]; + uint8_t adv_coex_config_buffer[(MESG_BUFFER_SIZE / 2) - 1]; + + ANT_BUFFER_PTR coex_config = + { + .ucBufferSize = sizeof(coex_config_buffer), + .pucBuffer = coex_config_buffer + }; + + ANT_BUFFER_PTR adv_coex_config = + { + .ucBufferSize = sizeof(adv_coex_config_buffer), + .pucBuffer = adv_coex_config_buffer + }; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code = 0; + + err_code = ant_coex_config_get_req_dec(p_rx_buf, rx_buf_len, &channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ant_coex_config_get(channel, &coex_config, &adv_coex_config); + + err_code = ant_coex_config_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, &coex_config, &adv_coex_config); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/middleware/conn_mw_ant.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/middleware/conn_mw_ant.h new file mode 100644 index 0000000..93e9130 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/middleware/conn_mw_ant.h @@ -0,0 +1,793 @@ +/** + * Copyright (c) 2017 - 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 _CONN_MW_ANT_H +#define _CONN_MW_ANT_H + +#include <stdint.h> + +/** + * @addtogroup sercon_mw_ant Connectivity middleware codecs for S212 (connectivity side) + * @{ + * @ingroup ser_codecs_mw + */ + + +/**@brief Handles @ref sd_ant_enable command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ant_enable(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_channel_assign command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_channel_assign(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_channel_open command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_channel_open_with_offset(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_channel_id_set command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_channel_id_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_channel_period_set command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_channel_period_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_channel_radio_freq_set command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_channel_radio_freq_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_broadcast_message_tx command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_broadcast_message_tx(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_acknowledge_message_tx command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_acknowledge_message_tx(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_channel_unassign command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_channel_unassign(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_channel_close command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_channel_close(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_network_address_set command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_network_address_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_channel_radio_tx_power_set command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_channel_radio_tx_power_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_channel_rx_search_timeout_set command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_channel_rx_search_timeout_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_channel_low_priority_rx_search_timeout_set command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_channel_low_priority_rx_search_timeout_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_prox_search_set command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_prox_search_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_search_waveform_set command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_search_waveform_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_channel_id_get command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_channel_id_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_channel_radio_freq_get command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_channel_radio_freq_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_channel_period_get command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_channel_period_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_search_channel_priority_set command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_search_channel_priority_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_active_search_sharing_cycles_set command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_active_search_sharing_cycles_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_lib_config_set command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_lib_config_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_active_search_sharing_cycles_get command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_active_search_sharing_cycles_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_lib_config_get command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_lib_config_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_lib_config_clear command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_lib_config_clear(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_stack_reset command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_stack_reset(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_rx_scan_mode_start command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_rx_scan_mode_start(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_id_list_add command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_id_list_add(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_id_list_config command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_id_list_config(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_channel_status_get command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_channel_status_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_cw_test_mode_init command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_cw_test_mode_init(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_cw_test_mode command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_cw_test_mode(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_version_get command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_version_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_capabilities_get command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_capabilities_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_crypto_channel_enable command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_crypto_channel_enable(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_adv_burst_config_set command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_adv_burst_config_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_crypto_key_set command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_crypto_key_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_crypto_info_set command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_crypto_info_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_crypto_info_get command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_crypto_info_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_coex_config_set command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_coex_config_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ant_coex_config_get command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_ant_coex_config_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + + +/** @} */ + +#endif //_CONN_MW_ANT_H diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_acknowledge_message_tx.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_acknowledge_message_tx.c new file mode 100644 index 0000000..3e1fb20 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_acknowledge_message_tx.c @@ -0,0 +1,84 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_acknowledge_message_tx_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint8_t * const p_size, + uint8_t * * const pp_mesg) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_channel); + SER_ASSERT_NOT_NULL(p_size); + SER_ASSERT_NOT_NULL(*pp_mesg); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_size); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_vector_dec(p_buf, packet_len, &index, *pp_mesg, *p_size); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + + +uint32_t ant_acknowledge_message_tx_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_TX_ACKNOWLEDGED_MESSAGE, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_active_search_sharing_cycles_get.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_active_search_sharing_cycles_get.c new file mode 100644 index 0000000..baea0f9 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_active_search_sharing_cycles_get.c @@ -0,0 +1,89 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_active_search_sharing_cycles_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint8_t * const p_channel) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_channel); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + +uint32_t ant_active_search_sharing_cycles_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint8_t const * const p_cycles) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + uint32_t total_len = *p_buf_len; + + uint32_t err_code = ser_ble_cmd_rsp_status_code_enc(SVC_ANT_ACTIVE_SEARCH_SHARING_CYCLES_GET, return_code, + p_buf, p_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + if (return_code != NRF_SUCCESS) + { + return NRF_SUCCESS; + } + + err_code = uint8_t_enc(p_cycles, p_buf, total_len, p_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return NRF_SUCCESS; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_active_search_sharing_cycles_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_active_search_sharing_cycles_set.c new file mode 100644 index 0000000..230c93e --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_active_search_sharing_cycles_set.c @@ -0,0 +1,78 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_active_search_sharing_cycles_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint8_t * const p_cycles) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_channel); + SER_ASSERT_NOT_NULL(p_cycles); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_cycles); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + +uint32_t ant_active_search_sharing_cycles_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_ACTIVE_SEARCH_SHARING_CYCLES_SET, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_adv_burst_config_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_adv_burst_config_set.c new file mode 100644 index 0000000..70d9362 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_adv_burst_config_set.c @@ -0,0 +1,79 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_adv_burst_config_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_config, + uint8_t * const p_size) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_size); + SER_ASSERT_NOT_NULL(p_config); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_size); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_vector_dec(p_buf, packet_len, &index, p_config, *p_size); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + + +uint32_t ant_adv_burst_config_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_ADV_BURST_CONFIG_SET, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_broadcast_message_tx.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_broadcast_message_tx.c new file mode 100644 index 0000000..63bf6da --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_broadcast_message_tx.c @@ -0,0 +1,84 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_broadcast_message_tx_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint8_t * const p_size, + uint8_t * * const pp_mesg) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_channel); + SER_ASSERT_NOT_NULL(p_size); + SER_ASSERT_NOT_NULL(*pp_mesg); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_size); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_vector_dec(p_buf, packet_len, &index, *pp_mesg, *p_size); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + + +uint32_t ant_broadcast_message_tx_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_TX_BROADCAST_MESSAGE, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_capabilities_get.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_capabilities_get.c new file mode 100644 index 0000000..113a13e --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_capabilities_get.c @@ -0,0 +1,71 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_capabilities_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint8_t const * const p_capabilities) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + uint32_t total_len = *p_buf_len; + + uint32_t err_code = ser_ble_cmd_rsp_status_code_enc(SVC_ANT_CAPABILITIES, return_code, + p_buf, p_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + if (return_code != NRF_SUCCESS) + { + return NRF_SUCCESS; + } + + err_code = uint8_vector_enc(p_capabilities, MESG_CAPABILITIES_SIZE, p_buf, total_len, p_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return NRF_SUCCESS; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_assign.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_assign.c new file mode 100644 index 0000000..4121d2b --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_assign.c @@ -0,0 +1,89 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_channel_assign_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint8_t * const p_type, + uint8_t * const p_network, + uint8_t * const p_ext_assign) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_channel); + SER_ASSERT_NOT_NULL(p_type); + SER_ASSERT_NOT_NULL(p_network); + SER_ASSERT_NOT_NULL(p_ext_assign); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_type); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_network); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_ext_assign); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + + +uint32_t ant_channel_assign_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_CHANNEL_ASSIGN, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_close.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_close.c new file mode 100644 index 0000000..3ef78d0 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_close.c @@ -0,0 +1,73 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_channel_close_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_channel); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + +uint32_t ant_channel_close_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_CHANNEL_CLOSE, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_id_get.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_id_get.c new file mode 100644 index 0000000..5bc0fba --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_id_get.c @@ -0,0 +1,97 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_channel_id_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint8_t * const p_channel) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_channel); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + +uint32_t ant_channel_id_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint16_t const * const p_device_number, + uint8_t const * const p_device_type, + uint8_t const * const p_transmit_type) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + uint32_t total_len = *p_buf_len; + + uint32_t err_code = ser_ble_cmd_rsp_status_code_enc(SVC_ANT_CHANNEL_ID_GET, return_code, + p_buf, p_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + if (return_code != NRF_SUCCESS) + { + return NRF_SUCCESS; + } + + err_code = uint16_t_enc(p_device_number, p_buf, total_len, p_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_enc(p_device_type, p_buf, total_len, p_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_enc(p_transmit_type, p_buf, total_len, p_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return NRF_SUCCESS; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_id_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_id_set.c new file mode 100644 index 0000000..ec50390 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_id_set.c @@ -0,0 +1,89 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_channel_id_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint16_t * const p_device_number, + uint8_t * const p_device_type, + uint8_t * const p_transmission_type) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_channel); + SER_ASSERT_NOT_NULL(p_device_number); + SER_ASSERT_NOT_NULL(p_device_type); + SER_ASSERT_NOT_NULL(p_transmission_type); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint16_t_dec(p_buf, packet_len, &index, p_device_number); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_device_type); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_transmission_type); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + + +uint32_t ant_channel_id_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_CHANNEL_ID_SET, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_low_priority_rx_search_timout_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_low_priority_rx_search_timout_set.c new file mode 100644 index 0000000..ff17048 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_low_priority_rx_search_timout_set.c @@ -0,0 +1,78 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_channel_low_priority_rx_search_timeout_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint8_t * const p_timeout) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_channel); + SER_ASSERT_NOT_NULL(p_timeout); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_timeout); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + +uint32_t ant_channel_low_priority_rx_search_timeout_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_CHANNEL_LOW_PRIO_RX_SEARCH_TIMEOUT_SET, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_open_with_offset.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_open_with_offset.c new file mode 100644 index 0000000..784143f --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_open_with_offset.c @@ -0,0 +1,78 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_channel_open_with_offset_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint16_t * const p_usOffset) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_channel); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint16_t_dec(p_buf, packet_len, &index, p_usOffset); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + + +uint32_t ant_channel_open_with_offset_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_CHANNEL_OPEN, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_period_get.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_period_get.c new file mode 100644 index 0000000..f62da42 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_period_get.c @@ -0,0 +1,89 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_channel_period_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint8_t * const p_channel) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_channel); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + +uint32_t ant_channel_period_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint16_t const * const p_period) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + uint32_t total_len = *p_buf_len; + + uint32_t err_code = ser_ble_cmd_rsp_status_code_enc(SVC_ANT_CHANNEL_PERIOD_GET, return_code, + p_buf, p_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + if (return_code != NRF_SUCCESS) + { + return NRF_SUCCESS; + } + + err_code = uint16_t_enc(p_period, p_buf, total_len, p_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return NRF_SUCCESS; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_period_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_period_set.c new file mode 100644 index 0000000..719cac5 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_period_set.c @@ -0,0 +1,78 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_channel_period_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint16_t * const p_period) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_channel); + SER_ASSERT_NOT_NULL(p_period); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint16_t_dec(p_buf, packet_len, &index, p_period); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + +uint32_t ant_channel_period_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_CHANNEL_PERIOD_SET, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_radio_freq_get.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_radio_freq_get.c new file mode 100644 index 0000000..fde80af --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_radio_freq_get.c @@ -0,0 +1,89 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_channel_radio_freq_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint8_t * const p_channel) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_channel); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + +uint32_t ant_channel_radio_freq_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint8_t const * const p_r_freq) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + uint32_t total_len = *p_buf_len; + + uint32_t err_code = ser_ble_cmd_rsp_status_code_enc(SVC_ANT_CHANNEL_RADIO_FREQ_GET, return_code, + p_buf, p_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + if (return_code != NRF_SUCCESS) + { + return NRF_SUCCESS; + } + + err_code = uint8_t_enc(p_r_freq, p_buf, total_len, p_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return NRF_SUCCESS; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_radio_freq_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_radio_freq_set.c new file mode 100644 index 0000000..35248e9 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_radio_freq_set.c @@ -0,0 +1,78 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_channel_radio_freq_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint8_t * const p_freq) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_channel); + SER_ASSERT_NOT_NULL(p_freq); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_freq); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + +uint32_t ant_channel_radio_freq_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_CHANNEL_RADIO_FREQ_SET, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_radio_tx_power_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_radio_tx_power_set.c new file mode 100644 index 0000000..9bbcc32 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_radio_tx_power_set.c @@ -0,0 +1,83 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_channel_radio_tx_power_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint8_t * const p_tx_power, + uint8_t * const p_custom_tx_power) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_channel); + SER_ASSERT_NOT_NULL(p_tx_power); + SER_ASSERT_NOT_NULL(p_custom_tx_power); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_tx_power); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_custom_tx_power); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + +uint32_t ant_channel_radio_tx_power_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_CHANNEL_RADIO_TX_POWER_SET, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_rx_search_timeout_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_rx_search_timeout_set.c new file mode 100644 index 0000000..f7de11b --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_rx_search_timeout_set.c @@ -0,0 +1,78 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_channel_rx_search_timeout_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint8_t * const p_timeout) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_channel); + SER_ASSERT_NOT_NULL(p_timeout); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_timeout); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + +uint32_t ant_channel_rx_search_timeout_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_CHANNEL_SEARCH_TIMEOUT_SET, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_status_get.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_status_get.c new file mode 100644 index 0000000..3f77fd4 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_status_get.c @@ -0,0 +1,89 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_channel_status_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint8_t * const p_channel) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_channel); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + +uint32_t ant_channel_status_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint8_t const * const p_status) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + uint32_t total_len = *p_buf_len; + + uint32_t err_code = ser_ble_cmd_rsp_status_code_enc(SVC_ANT_CHANNEL_STATUS_GET, return_code, + p_buf, p_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + if (return_code != NRF_SUCCESS) + { + return NRF_SUCCESS; + } + + err_code = uint8_t_enc(p_status, p_buf, total_len, p_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return NRF_SUCCESS; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_unassign.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_unassign.c new file mode 100644 index 0000000..9c37cb9 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_channel_unassign.c @@ -0,0 +1,73 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_channel_unassign_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_channel); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + +uint32_t ant_channel_unassign_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_CHANNEL_UNASSIGN, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_coex_config_get.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_coex_config_get.c new file mode 100644 index 0000000..e15fbb2 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_coex_config_get.c @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_coex_config_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint8_t * const p_channel) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_channel); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + +uint32_t ant_coex_config_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + ANT_BUFFER_PTR * const p_coex_config, + ANT_BUFFER_PTR * const p_adv_coex_config) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + uint32_t total_len = *p_buf_len; + + uint32_t err_code = ser_ble_cmd_rsp_status_code_enc(SVC_ANT_COEX_CONFIG_GET, return_code, + p_buf, p_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + if (return_code != NRF_SUCCESS) + { + return NRF_SUCCESS; + } + + err_code = uint8_t_enc(&(p_coex_config->ucBufferSize), p_buf, total_len, p_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_vector_enc(p_coex_config->pucBuffer, + p_coex_config->ucBufferSize, + p_buf, + total_len, + p_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_enc(&(p_adv_coex_config->ucBufferSize), p_buf, total_len, p_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_vector_enc(p_adv_coex_config->pucBuffer, + p_adv_coex_config->ucBufferSize, + p_buf, + total_len, + p_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return NRF_SUCCESS; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_coex_config_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_coex_config_set.c new file mode 100644 index 0000000..730cb1e --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_coex_config_set.c @@ -0,0 +1,101 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_coex_config_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + ANT_BUFFER_PTR * const p_coex_config, + ANT_BUFFER_PTR * const p_adv_coex_config) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_channel); + SER_ASSERT_NOT_NULL(p_coex_config); + SER_ASSERT_NOT_NULL(p_adv_coex_config); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + // Decode coex config buffer size + err_code = uint8_t_dec(p_buf, packet_len, &index, &(p_coex_config->ucBufferSize)); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + // Decode coex config buffer + err_code = uint8_vector_dec(p_buf, + packet_len, + &index, + p_coex_config->pucBuffer, + p_coex_config->ucBufferSize); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + // Decode advanced coex config buffer size + err_code = uint8_t_dec(p_buf, packet_len, &index, &(p_adv_coex_config->ucBufferSize)); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + // Decode advanced coex config buffer + err_code = uint8_vector_dec(p_buf, + packet_len, + &index, + p_adv_coex_config->pucBuffer, + p_adv_coex_config->ucBufferSize); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + +uint32_t ant_coex_config_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_COEX_CONFIG_SET, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_conn.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_conn.h new file mode 100644 index 0000000..0f70413 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_conn.h @@ -0,0 +1,1591 @@ +/** + * Copyright (c) 2017 - 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 ANT_CONN_H__ +#define ANT_CONN_H__ + + +/** + * @addtogroup ser_conn_s212_codecs Connectivity codecs for S212 + * @ingroup ser_codecs_conn + */ + +/**@file + * + * @defgroup ant_conn Connectivity command request decoders and command response encoders + * @{ + * @ingroup ser_conn_s212_codecs + * + * @brief Connectivity command request decoders and command response encoders. + */ +#include "ant_interface.h" + +/**@brief Decodes @ref sd_ant_enable command request. + * + * @sa @ref ant_enable_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] pp_ant_enable_params Pointer to pointer to @ref ANT_ENABLE. + * \c It will be set to NULL if p_ant_enable_params is not + * present in the packet. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_enable_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ANT_ENABLE * * const pp_ant_enable_params); + +/**@brief Encodes @ref sd_ant_enable command response. + * + * @sa @ref ant_enable_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_enable_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_channel_assign command request. + * + * @sa @ref ant_channel_assign_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_channel Pointer to an unsigned char (1 octet) where the channel to be + * assigned will be set. + * @param[out] p_type Pointer to an unsigned char (1 octet) where the channel type + * to be assigned will be set. + * @param[out] p_network Pointer to an unsigned char (1 octet) where the network key to + * associate with the channel will be set. + * @param[out] p_ext_assign Pointer to a bit field (1 octet) where an extended assign will + * be set. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_assign_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint8_t * const p_type, + uint8_t * const p_network, + uint8_t * const p_ext_assign); + +/**@brief Encodes @ref sd_ant_channel_assign command response. + * + * @sa @ref ant_channel_assign_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_assign_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_channel_open command request. + * + * @sa @ref ant_channel_open_with_offset_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_channel Pointer to an unsigned char (1 octet) where the channel to be + * opened will be set. + * @param[out] p_usOffset Pointer to a channel start time offset value. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_open_with_offset_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint16_t * const p_usOffset); + +/**@brief Encodes @ref sd_ant_channel_open command response. + * + * @sa @ref ant_channel_open_with_offset_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_open_with_offset_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_channel_id_set command request. + * + * @sa @ref ant_channel_id_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_channel Pointer to an unsigned char (1 octet) where the channel number + * will be set. + * @param[out] p_device_number Pointer to an unsigned short (2 octets) where the device + * number will be set. + * @param[out] p_device_type Pointer to an an unsigned char (1 octet) where the device type + * will be set. + * @param[out] p_transmission_type Pointer to an unsigned char (1 octet) where the transmission + * type will be set. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_id_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint16_t * const p_device_number, + uint8_t * const p_device_type, + uint8_t * const p_transmission_type); + +/**@brief Encodes @ref sd_ant_channel_id_set command response. + * + * @sa @ref ant_channel_id_set_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_id_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_channel_period_set command request. + * + * @sa @ref ant_channel_period_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_channel Pointer to an unsigned char (1 octet) where the channel number + * associated with the period will be set. + * @param[out] p_period Pointer to an unsigned short (2 octets) where the period will + * be set. Value is in 32 kHz counts (usPeriod/32768 s). + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_period_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint16_t * const p_period); + +/**@brief Encodes @ref sd_ant_channel_period_set command response. + * + * @sa @ref ant_channel_period_set_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_period_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_channel_radio_freq_set command request. + * + * @sa @ref ant_channel_radio_freq_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_channel Pointer to an unsigned char (1 octet) where the channel number + * associated with the radio frequency will be set. + * @param[out] p_freq Pointer to an unsigned char (1 octet) where the radio + * frequency will be set. Value is offset from 2400 MHz + * (eg. 2466 MHz, ucFreq = 66). + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_radio_freq_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint8_t * const p_freq); + +/**@brief Encodes @ref sd_ant_channel_radio_freq_set command response. + * + * @sa @ref ant_channel_radio_freq_set_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_radio_freq_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_broadcast_message_tx command request. + * + * @sa @ref ant_broadcast_message_tx_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_channel Pointer to an unsigned char (1 octet) where the channel to + * send the data on will be set. + * @param[out] p_size Pointer to an unsigned char (1 octet) where the size of the + * message will be set. + * @param[out] pp_mesg Pointer to pointer to the buffer where the broadcast message + * will be set (array must be 8 octets). + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_broadcast_message_tx_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint8_t * const p_size, + uint8_t * * const pp_mesg); + +/**@brief Encodes @ref sd_ant_broadcast_message_tx command response. + * + * @sa @ref ant_broadcast_message_tx_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_broadcast_message_tx_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_acknowledge_message_tx command request. + * + * @sa @ref ant_acknowledge_message_tx_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_channel Pointer to an unsigned char (1 octet) where the channel to + * send the data on will be set. + * @param[out] p_size Pointer to an unsigned char (1 octet) where the size of the + * message will be set. + * @param[out] pp_mesg Pointer to pointer to the buffer where the acknowledge message + * will be set (array must be 8 octets). + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_acknowledge_message_tx_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint8_t * const p_size, + uint8_t * * const pp_mesg); + +/**@brief Encodes @ref sd_ant_acknowledge_message_tx command response. + * + * @sa @ref ant_acknowledge_message_tx_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_acknowledge_message_tx_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_channel_unassign command request. + * + * @sa @ref ant_channel_unassign_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_channel Pointer to an unsigned char (1 octet) where the channel to be + * unassigned will be set. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_unassign_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel); + +/**@brief Encodes @ref sd_ant_channel_unassign command response. + * + * @sa @ref ant_channel_unassign_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_unassign_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_channel_close command request. + * + * @sa @ref ant_channel_close_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_channel Pointer to an unsigned char (1 octet) where the channel to be + * closed will be set. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_close_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel); + +/**@brief Encodes @ref sd_ant_channel_close command response. + * + * @sa @ref ant_channel_close_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_close_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_network_address_set command request. + * + * @sa @ref ant_network_address_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_network Pointer to an unsigned char (1 octet) where the network number + * to assign the network address to will be set. + * @param[out] pp_network_key Pointer to a pointer to where the network key (8 octets in + * length) will be set. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_network_address_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_network, + uint8_t * * const pp_network_key); + +/**@brief Encodes @ref sd_ant_network_address_set command response. + * + * @sa @ref ant_network_address_set_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_network_address_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_channel_radio_tx_power_set command request. + * + * @sa @ref ant_channel_radio_tx_power_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_channel Pointer to an unsigned char (1 octet) where the channel number + * to assign the radio TX power will be set. + * @param[out] p_tx_power Pointer to an unsigned char (1 octet) where the ANT transmit + * power index will be set. See Radio TX Power Definitions in + * ant_parameters.h. + * @param[out] p_custom_tx_power Pointer to an unsigned char (1 octet) where the custom nRF + * transmit power as defined in nrf51_bitfields.h will be set. + * Only applicable if tx_power is set to custom TX power + * selection. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_radio_tx_power_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint8_t * const p_tx_power, + uint8_t * const p_custom_tx_power); + +/**@brief Encodes @ref sd_ant_channel_radio_tx_power_set command response. + * + * @sa @ref ant_channel_radio_tx_power_set_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_radio_tx_power_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_channel_rx_search_timeout_set command request. + * + * @sa @ref ant_channel_rx_search_timeout_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_channel Pointer to an unsigned char (1 octet) where the channel number + * will be set. + * @param[out] p_timeout Pointer to an unsigned char (1 octet) where the time-out value + * will be set. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_rx_search_timeout_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint8_t * const p_timeout); + +/**@brief Encodes @ref sd_ant_channel_rx_search_timeout_set command response. + * + * @sa @ref ant_channel_rx_search_timeout_set_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_rx_search_timeout_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_channel_low_priority_rx_search_timeout_set command request. + * + * @sa @ref ant_channel_low_priority_rx_search_timeout_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_channel Pointer to an unsigned char (1 octet) where the channel number + * will be set. + * @param[out] p_timeout Pointer to an unsigned char (1 octet) where the time-out value + * will be set. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_low_priority_rx_search_timeout_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint8_t * const p_timeout); + +/**@brief Encodes @ref sd_ant_channel_low_priority_rx_search_timeout_set command response. + * + * @sa @ref ant_channel_low_priority_rx_search_timeout_set_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_low_priority_rx_search_timeout_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_prox_search_set command request. + * + * @sa @ref ant_prox_search_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_channel Pointer to an unsigned char (1 octet) where the channel + * number will be set. + * @param[out] p_prox_threshold Pointer to an unsigned char (1 octet) where the minimum + * RSSI threshold required for acquisition during a search + * will be set. See Radio Proximity Search Threshold in + * ant_parameters.h. + * @param[out] p_custom_prox_threshold Pointer to an unsigned char (1 octet) where the custom + * minimum RSSI threshold for acquisition during a search + * will be set. Only applicable if prox_threshold is set to + * custom proximity selection. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_prox_search_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint8_t * const p_prox_threshold, + uint8_t * const p_custom_prox_threshold); + +/**@brief Encodes @ref sd_ant_prox_search_set command response. + * + * @sa @ref ant_prox_search_set_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_prox_search_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_search_waveform_set command request. + * + * @sa @ref ant_search_waveform_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_channel Pointer to an unsigned char (1 octet) where the channel + * number will be set. + * @param[out] p_waveform Pointer to an unsigned short (2 octets) where the channel + * waveform period (usWaveform/32768 s) will be set. + * Default = 316. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_search_waveform_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint16_t * const p_waveform); + +/**@brief Encodes @ref sd_ant_search_waveform_set command response. + * + * @sa @ref ant_search_waveform_set_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_search_waveform_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_channel_id_get command request. + * + * @sa @ref ant_channel_id_get_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_channel Pointer to an unsigned char (1 octet) where the channel + * number will be set. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_id_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint8_t * const p_channel); + +/**@brief Encodes @ref sd_ant_channel_id_get command response. + * + * @sa @ref ant_channel_id_get_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_device_number Pointer to device number + * @param[in] p_device_type Pointer to device type + * @param[in] p_transmit_type Pointer to transmit type + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_id_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint16_t const * const p_device_number, + uint8_t const * const p_device_type, + uint8_t const * const p_transmit_type); + +/**@brief Decodes @ref sd_ant_channel_radio_freq_get command request. + * + * @sa @ref ant_channel_radio_freq_get_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_channel Pointer to an unsigned char (1 octet) where the channel number + * will be set. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_radio_freq_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint8_t * const p_channel); + +/**@brief Encodes @ref sd_ant_channel_radio_freq_get command response. + * + * @sa @ref ant_channel_radio_freq_get_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_r_freq Pointer to radio frequency + * + * @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 ant_channel_radio_freq_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint8_t const * const p_r_freq); + +/**@brief Decodes @ref sd_ant_channel_period_get command request. + * + * @sa @ref ant_channel_period_get_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_channel Pointer to an unsigned char (1 octet) where the channel number + * will be set. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_period_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint8_t * const p_channel); + +/**@brief Encodes @ref sd_ant_channel_period_get command response. + * + * @sa @ref ant_channel_period_get_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_period Pointer to period + * + * @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 ant_channel_period_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint16_t const * const p_period); + +/**@brief Decodes @ref sd_ant_search_channel_priority_set command request. + * + * @sa @ref ant_search_channel_priority_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_channel Pointer to an unsigned char (1 octet) where the channel number + * will be set. + * @param[out] p_search_priority Pointer to an unsigned char (1 octet) where the search + * priority value will be set. 0 to 7 (Default = 0). + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_search_channel_priority_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint8_t * const p_search_priority); + +/**@brief Encodes @ref sd_ant_search_channel_priority_set command response. + * + * @sa @ref ant_search_channel_priority_set_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_search_channel_priority_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_active_search_sharing_cycles_set command request. + * + * @sa @ref ant_active_search_sharing_cycles_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_channel Pointer to an unsigned char (1 octet) where the channel number + * will be set. + * @param[out] p_cycles Pointer to an unsigned char (1 octet) where the numbe of + * cycles will be set. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_active_search_sharing_cycles_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint8_t * const p_cycles); + +/**@brief Encodes @ref sd_ant_active_search_sharing_cycles_set command response. + * + * @sa @ref ant_active_search_sharing_cycles_set_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_active_search_sharing_cycles_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_lib_config_set command request. + * + * @sa @ref ant_lib_config_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_ant_lib_config Pointer to an unsigned char (1 octet) where the ANT lib + * config bit flags will be set. See ANT Library Config in + * ant_parameters.h. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_lib_config_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_ant_lib_config); + +/**@brief Encodes @ref sd_ant_lib_config_set command response. + * + * @sa @ref ant_lib_config_set_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_lib_config_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_active_search_sharing_cycles_get command request. + * + * @sa @ref ant_active_search_sharing_cycles_get_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_channel Pointer to an unsigned char (1 octet) where the channel number + * will be set. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_active_search_sharing_cycles_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint8_t * const p_channel); + +/**@brief Encodes @ref sd_ant_active_search_sharing_cycles_get command response. + * + * @sa @ref ant_active_search_sharing_cycles_get_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_cycles Pointer to cycles. + * + * @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 ant_active_search_sharing_cycles_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint8_t const * const p_cycles); + +/**@brief Encodes @ref sd_ant_lib_config_get command response. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_ant_lib_config Pointer to ANT library configuration. + * + * @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 ant_lib_config_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint8_t const * const p_ant_lib_config); + +/**@brief Decodes @ref sd_ant_lib_config_clear command request. + * + * @sa @ref ant_lib_config_clear_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_ant_lib_config Pointer to an unsigned char (1 octet) where the ANT lib config + * bit(s) to clear will be set. See ANT Library Config in + * ant_parameters.h. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_lib_config_clear_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_ant_lib_config); + +/**@brief Encodes @ref sd_ant_lib_config_clear command response. + * + * @sa @ref ant_lib_config_clear_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_lib_config_clear_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Encodes @ref sd_ant_stack_reset command response. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @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 ant_stack_reset_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_rx_scan_mode_start command request. + * + * @sa @ref ant_rx_scan_mode_start_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_sync_channel_packets_only Pointer to an unsigned char (1 octet) where the + * synchronous channel only scanning mode will be set. + * 0 = disable, 1 = enable. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_rx_scan_mode_start_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_sync_channel_packets_only); + +/**@brief Encodes @ref sd_ant_rx_scan_mode_start command response. + * + * @sa @ref ant_rx_scan_mode_start_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_rx_scan_mode_start_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_id_list_add command request. + * + * @sa @ref ant_id_list_add_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_channel Pointer to an unsigned char (1 octet) where the channel + * number to add the list entry to will be set. + * @param[out] pp_dev_id Pointer to pointer to where the Dev ID will be stored. + * @param[out] p_list_index Pointer to an unsigned char (1 octet) where the list + * index (0-3), will be set. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_id_list_add_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint8_t * * const pp_dev_id, + uint8_t * const p_list_index); + +/**@brief Encodes @ref sd_ant_id_list_add command response. + * + * @sa @ref ant_id_list_add_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @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 ant_id_list_add_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_id_list_config command request. + * + * @sa @ref ant_id_list_config_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_channel Pointer to an unsigned char (1 octet) wher the channel number + * of the device ID list will be stored. + * @param[out] p_id_list_size Pointer to an unsigned char (1 octet) where the size of the + * inclusion or exclusion list (0-4) will be stored. + * @param[out] p_inc_exc_flag Pointer to an unsigned char (1 octet) where the type of list + * will be stored. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_id_list_config_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint8_t * const p_id_list_size, + uint8_t * const p_inc_exc_flag); + +/**@brief Encodes @ref sd_ant_id_list_add command response. + * + * @sa @ref ant_id_list_config_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_id_list_config_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_channel_status_get command request. + * + * @sa @ref ant_channel_status_get_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_channel Pointer to an unsigned char (1 octet) where the channel number + * will be set. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_status_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint8_t * const p_channel); + +/**@brief Encodes @ref sd_ant_channel_status_get command response. + * + * @sa @ref ant_channel_status_get_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_status Pointer to status + * + * @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 ant_channel_status_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint8_t const * const p_status); + +/**@brief Encodes @ref sd_ant_cw_test_mode_init command response. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @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 ant_cw_test_mode_init_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_cw_test_mode command request. + * + * @sa @ref ant_cw_test_mode_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_radio_freq Pointer to an unsigned char (1 octet) where the radio + * frequency offset from 2400 MHz for continuous wave mode will be + * set. (eg. 2466 MHz, ucRadioFreq = 66). + * @param[out] p_tx_power Pointer to an unsigned char (1 octet) where the ANT transmit + * power index for continuous wave mode will be set. See Radio + * TX Power Definitions in ant_parameters.h + * @param[out] p_custom_tx_power Pointer to an unsigned char (1 octet) where the custom nRF + * transmit power as defined in nrf51_bitfields.h will be set. Only + * applicable if ucTxPower is set to custom TX power selection. + * @param[out] p_mode Pointer to an unsigned char (1 octet) where the test mode type + * will be set. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_cw_test_mode_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_radio_freq, + uint8_t * const p_tx_power, + uint8_t * const p_custom_tx_power, + uint8_t * const p_mode); + +/**@brief Encodes @ref sd_ant_cw_test_mode command response. + * + * @sa @ref ant_cw_test_mode_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_cw_test_mode_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Encodes @ref sd_ant_version_get command response. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_version Pointer to version. + * + * @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 ant_version_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint8_t const * const p_version); + +/**@brief Encodes @ref sd_ant_capabilities_get command response. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_capabilities Pointer to ant capabilities buffer. + * + * @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 ant_capabilities_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint8_t const * const p_capabilities); + +/**@brief Decodes @ref sd_ant_crypto_channel_enable command request. + * + * @sa @ref ant_crypto_channel_enable_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_channel Pointer to an unsigned char (1 octet) where the channel in which + * encryption mode is set will be copied to. + * @param[out] p_enable Pointer to an unsigned char (1 octet) where the encryption + * mode will be set. + * @param[out] p_key_num Pointer to an unsigned char (1 octet) where the key index of the + * 128-bit key to be used for encryption will be set. + * @param[out] p_decimation_rate Pointer to an unsigned char (1 octet) where the decimate rate to + * apply for encrypted slave channel will be set. Must be > 0. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_crypto_channel_enable_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint8_t * const p_enable, + uint8_t * const p_key_num, + uint8_t * const p_decimation_rate); + +/**@brief Encodes @ref sd_ant_crypto_channel_enable command response. + * + * @sa @ref ant_crypto_channel_enable_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_crypto_channel_enable_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_adv_burst_config_set command request. + * + * @sa @ref ant_adv_burst_config_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_config Pointer to the buffer where advanced burst + * configuration will be set. + * @param[out] p_size Pointer to an unsigned char (1 octet) where the size of the + * configuration parameter buffer will be set. + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_adv_burst_config_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_config, + uint8_t * const p_size); + +/**@brief Encodes @ref sd_ant_adv_burst_config_set command response. + * + * @sa @ref ant_adv_burst_config_set_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_adv_burst_config_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_crypto_key_set command request. + * + * @sa @ref ant_crypto_key_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_key_num Pointer to an unsigned char (1 octet) where the key index for + * assignment will be set. + * @param[out] pp_key Pointer to pointer to buffer (16 octets) where the 128-bit + * AES key to be assigned to the key index will be set. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_crypto_key_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_key_num, + uint8_t * * const pp_key); + +/**@brief Encodes @ref sd_ant_crypto_key_set command response. + * + * @sa @ref ant_crypto_key_set_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_crypto_key_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_crypto_info_set command request. + * + * @sa @ref ant_crypto_info_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_type Pointer to an unsigned char (1 octet) where the type of + * information being set will be copied. + * @param[out] pp_info Pointer to pointer to buffer where information being set will be + * copied. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_crypto_info_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_type, + uint8_t * * const pp_info); + +/**@brief Encodes @ref sd_ant_crypto_info_set command response. + * + * @sa @ref ant_crypto_info_set_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_crypto_info_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_crypto_info_get command request. + * + * @sa @ref ant_crypto_info_get_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_type Pointer to an unsigned char (1 octet) where the type of + * information being set will be copied. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_crypto_info_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint8_t * const p_type); + +/**@brief Encodes @ref sd_ant_crypto_info_get command response. + * + * @sa @ref ant_crypto_info_get_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] type The type of information being set. + * @param[in] p_info Pointer to info buffer. + * + * @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 ant_crypto_info_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint8_t type, + uint8_t const * const p_info); + +/**@brief Decodes @ref sd_ant_coex_config_set command request. + * + * @sa @ref ant_coex_config_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[in] p_channel Pointer to an unsigned char (1 octet) where the channel for + * which the coexistence configuration is to be set will be copied. + * @param[in] p_coex_config Pointer to a buffer where the coexistence configuration to be set will + * be copied. + * @param[in] p_adv_coex_config Pointer to a buffer where the advanced coexistence configuration to be set will + * be copied. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_coex_config_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + ANT_BUFFER_PTR * const p_coex_config, + ANT_BUFFER_PTR * const p_adv_coex_config); + +/**@brief Encodes @ref sd_ant_coex_config_set command response. + * + * @sa @ref ant_coex_config_set_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_coex_config_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ant_coex_config_get command request. + * + * @sa @ref ant_channel_id_get_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @param[out] p_channel Pointer to an unsigned char (1 octet) where the channel + * number will be set. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_coex_config_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint8_t * const p_channel); + +/**@brief Encodes @ref sd_ant_coex_config_get command response. + * + * @sa @ref ant_channel_id_get_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_coex_config Pointer to the coexistence configuration. + * @param[in] p_adv_coex_config Pointer to the advanced coexistence configuration. + * + * @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 ant_coex_config_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + ANT_BUFFER_PTR * const p_coex_config, + ANT_BUFFER_PTR * const p_adv_coex_config); +/** @} */ + +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_crypto_channel_enable.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_crypto_channel_enable.c new file mode 100644 index 0000000..66db3cb --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_crypto_channel_enable.c @@ -0,0 +1,88 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_crypto_channel_enable_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint8_t * const p_enable, + uint8_t * const p_key_num, + uint8_t * const p_decimation_rate) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_channel); + SER_ASSERT_NOT_NULL(p_enable); + SER_ASSERT_NOT_NULL(p_key_num); + SER_ASSERT_NOT_NULL(p_decimation_rate); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_enable); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_key_num); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_decimation_rate); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + +uint32_t ant_crypto_channel_enable_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_CRYPTO_CHANNEL_ENABLE, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_crypto_info_get.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_crypto_info_get.c new file mode 100644 index 0000000..495aee0 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_crypto_info_get.c @@ -0,0 +1,96 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_crypto_info_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint8_t * const p_type) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_type); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_type); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + +uint32_t ant_crypto_info_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint8_t type, + uint8_t const * const p_info) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + uint32_t total_len = *p_buf_len; + + uint32_t err_code = ser_ble_cmd_rsp_status_code_enc(SVC_ANT_CRYPTO_INFO_GET, return_code, + p_buf, p_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + if (return_code != NRF_SUCCESS) + { + return NRF_SUCCESS; + } + + err_code = uint8_t_enc(&type, p_buf, total_len, p_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + uint8_t crypto_info_size = (MESG_CONFIG_ENCRYPT_REQ_CONFIG_USER_DATA_SIZE - + MESG_CHANNEL_NUM_SIZE); + + err_code = uint8_vector_enc(p_info, crypto_info_size, p_buf, total_len, p_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return NRF_SUCCESS; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_crypto_info_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_crypto_info_set.c new file mode 100644 index 0000000..d429119 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_crypto_info_set.c @@ -0,0 +1,84 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_crypto_info_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_type, + uint8_t * * const pp_info) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_type); + SER_ASSERT_NOT_NULL(*pp_info); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_type); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + uint8_t crypto_info_size = (MESG_CONFIG_ENCRYPT_REQ_CONFIG_USER_DATA_SIZE - + MESG_CHANNEL_NUM_SIZE) + + (MESG_CONFIG_ENCRYPT_REQ_CONFIG_ID_SIZE - + MESG_CHANNEL_NUM_SIZE); + + err_code = uint8_vector_dec(p_buf, packet_len, &index, *pp_info, crypto_info_size); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + + +uint32_t ant_crypto_info_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_CRYPTO_INFO_SET, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_crypto_key_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_crypto_key_set.c new file mode 100644 index 0000000..e5d0980 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_crypto_key_set.c @@ -0,0 +1,79 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_crypto_key_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_key_num, + uint8_t * * const pp_key) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_key_num); + SER_ASSERT_NOT_NULL(*pp_key); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_key_num); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_vector_dec(p_buf, packet_len, &index, *pp_key, SIZE_OF_ENCRYPTED_KEY); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + + +uint32_t ant_crypto_key_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_CRYPTO_KEY_SET, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_cw_test_mode.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_cw_test_mode.c new file mode 100644 index 0000000..0830ebe --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_cw_test_mode.c @@ -0,0 +1,88 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_cw_test_mode_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_radio_freq, + uint8_t * const p_tx_power, + uint8_t * const p_custom_tx_power, + uint8_t * const p_mode) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_radio_freq); + SER_ASSERT_NOT_NULL(p_tx_power); + SER_ASSERT_NOT_NULL(p_custom_tx_power); + SER_ASSERT_NOT_NULL(p_mode); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_radio_freq); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_tx_power); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_custom_tx_power); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_mode); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + +uint32_t ant_cw_test_mode_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_CW_TEST_MODE, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_cw_test_mode_init.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_cw_test_mode_init.c new file mode 100644 index 0000000..baf8699 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_cw_test_mode_init.c @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_cw_test_mode_init_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_INIT_CW_TEST_MODE, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_enable.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_enable.c new file mode 100644 index 0000000..9f38a38 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_enable.c @@ -0,0 +1,75 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_enable_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ANT_ENABLE * * const pp_ant_enable_params) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(pp_ant_enable_params); + SER_ASSERT_NOT_NULL(*pp_ant_enable_params); + + err_code = cond_field_dec(p_buf, packet_len, &index, (void * *)pp_ant_enable_params, ANT_ENABLE_dec); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + + +uint32_t ant_enable_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_ENABLE, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_event.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_event.c new file mode 100644 index 0000000..192784b --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_event.c @@ -0,0 +1,114 @@ +/** + * Copyright (c) 2017 - 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 "ant_parameters.h" +#include "nrf_sdh_ant.h" +#include "ant_struct_serialization.h" +#include "ble_serialization.h" +#include "ant_event_rx.h" +#include "app_util.h" +#include "cond_field_serialization.h" + + +uint32_t ant_event_enc(ant_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t ret_val = NRF_SUCCESS; + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + SER_ASSERT_NOT_NULL(p_event); + + switch (p_event->event) + { + case NO_EVENT: + case EVENT_RX_SEARCH_TIMEOUT: + case EVENT_RX_FAIL: + case EVENT_TRANSFER_RX_FAILED: + case EVENT_TRANSFER_TX_COMPLETED: + case EVENT_TRANSFER_TX_FAILED: + case EVENT_CHANNEL_CLOSED: + case EVENT_RX_FAIL_GO_TO_SEARCH: + case EVENT_CHANNEL_COLLISION: + case EVENT_TRANSFER_TX_START: + case EVENT_TRANSFER_NEXT_DATA_BLOCK: + case CHANNEL_IN_WRONG_STATE: + case CHANNEL_NOT_OPENED: + case CHANNEL_ID_NOT_SET: + case CLOSE_ALL_CHANNELS: + case TRANSFER_IN_PROGRESS: + case TRANSFER_SEQUENCE_NUMBER_ERROR: + case TRANSFER_IN_ERROR: + case TRANSFER_BUSY: + case MESSAGE_SIZE_EXCEEDS_LIMIT: + case INVALID_MESSAGE: + case INVALID_NETWORK_NUMBER: + case INVALID_LIST_ID: + case INVALID_SCAN_TX_CHANNEL: + case INVALID_PARAMETER_PROVIDED: + case EVENT_QUE_OVERFLOW: + case EVENT_ENCRYPT_NEGOTIATION_SUCCESS: + case EVENT_ENCRYPT_NEGOTIATION_FAIL: + case EVENT_RFACTIVE_NOTIFICATION: + case EVENT_CONNECTION_START: + case EVENT_CONNECTION_SUCCESS: + case EVENT_CONNECTION_FAIL: + case EVENT_CONNECTION_TIMEOUT: + case EVENT_CONNECTION_UPDATE: + case NO_RESPONSE_MESSAGE: + case EVENT_RX: + case EVENT_BLOCKED: + case EVENT_TX: + { + uint32_t index = 0; + // TO DO - SER_ASSERT_LENGTH_LEQ(index + SER_EVT_HEADER_SIZE + 2 + 1, *p_buf_len); + uint32_t err_code = ant_evt_t_enc(p_event, p_buf, *p_buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + *p_buf_len = index; + break; + } + default: + ret_val = NRF_ERROR_NOT_SUPPORTED; + break; + } + + return ret_val; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_event.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_event.h new file mode 100644 index 0000000..5b6ce1c --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_event.h @@ -0,0 +1,74 @@ +/** + * Copyright (c) 2017 - 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 __ANT_EVENT_H__ +#define __ANT_EVENT_H__ +#include "ant_parameters.h" +#include "app_util.h" +#include "nrf_sdh_ant.h" + +/** + * @addtogroup ser_conn_s212_codecs + * @{ + * @ingroup ser_codecs_conn + */ + +/**@brief Event encoding dispatcher. + * + * The event encoding dispatcher will route the event packet to the correct encoder which in turn + * encodes the contents of the event and updates the \p p_buf buffer. + * + * @param[in] p_event Pointer to the \ref ant_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + * @retval NRF_ERROR_NOT_SUPPORTED Event encoder is not implemented. + */ +uint32_t ant_event_enc(ant_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** @} */ +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_event_rx.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_event_rx.c new file mode 100644 index 0000000..b8dfed0 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_event_rx.c @@ -0,0 +1,70 @@ +/** + * Copyright (c) 2017 - 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 "ant_event_rx.h" +#include "ble_serialization.h" +#include "app_util.h" + +uint32_t ant_event_rx_enc(ant_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + ANT_MESSAGE * p_message; + uint32_t index = 0; + + + SER_ASSERT_NOT_NULL(p_event); + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + SER_ASSERT_LENGTH_LEQ(index + SER_EVT_HEADER_SIZE + 2 + 1, *p_buf_len); + p_message = (ANT_MESSAGE *)&p_event->message; + + index += uint16_encode(EVENT_RX, &(p_buf[index])); // Mesg ID + p_buf[index++] = p_message->ANT_MESSAGE_ucSize; // Mesg Size + memcpy(&(p_buf[index]), p_message->ANT_MESSAGE_aucPayload,p_message->ANT_MESSAGE_ucSize); // Payload + index += p_message->ANT_MESSAGE_ucSize; + + *p_buf_len = index; + + return NRF_SUCCESS; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_event_rx.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_event_rx.h new file mode 100644 index 0000000..72c346e --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_event_rx.h @@ -0,0 +1,72 @@ +/** + * Copyright (c) 2017 - 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 __ANT_EVENT_RX_H__ +#define __ANT_EVENT_RX_H__ + +#include <string.h> +#include "ant_parameters.h" +#include "nrf_sdh_ant.h" + +/** + * @addtogroup ser_conn_s212_codecs + * @{ + * @ingroup ser_codecs_conn + */ + +/** + * @brief Encodes ant_event_rx event. + * + * @param[in] p_event Pointer to the \ref ant_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_event_rx_enc(ant_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** @} */ +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_id_list_add.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_id_list_add.c new file mode 100644 index 0000000..49314c6 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_id_list_add.c @@ -0,0 +1,84 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_id_list_add_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint8_t * * const pp_dev_id, + uint8_t * const p_list_index) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_channel); + SER_ASSERT_NOT_NULL(*pp_dev_id); + SER_ASSERT_NOT_NULL(p_list_index); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_vector_dec(p_buf, packet_len, &index, *pp_dev_id, ANT_ID_SIZE); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_list_index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + + +uint32_t ant_id_list_add_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_ID_LIST_ADD, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_id_list_config.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_id_list_config.c new file mode 100644 index 0000000..d7f69ab --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_id_list_config.c @@ -0,0 +1,84 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_id_list_config_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint8_t * const p_id_list_size, + uint8_t * const p_inc_exc_flag) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_channel); + SER_ASSERT_NOT_NULL(p_id_list_size); + SER_ASSERT_NOT_NULL(p_inc_exc_flag); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_id_list_size); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_inc_exc_flag); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + + +uint32_t ant_id_list_config_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_ID_LIST_CONFIG, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_lib_config_clear.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_lib_config_clear.c new file mode 100644 index 0000000..387828d --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_lib_config_clear.c @@ -0,0 +1,73 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_lib_config_clear_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_ant_lib_config) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_ant_lib_config); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_ant_lib_config); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + +uint32_t ant_lib_config_clear_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_LIB_CONFIG_CLEAR, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_lib_config_get.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_lib_config_get.c new file mode 100644 index 0000000..cdb0980 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_lib_config_get.c @@ -0,0 +1,71 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_lib_config_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint8_t const * const p_ant_lib_config) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + uint32_t total_len = *p_buf_len; + + uint32_t err_code = ser_ble_cmd_rsp_status_code_enc(SVC_ANT_LIB_CONFIG_GET, return_code, + p_buf, p_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + if (return_code != NRF_SUCCESS) + { + return NRF_SUCCESS; + } + + err_code = uint8_t_enc(p_ant_lib_config, p_buf, total_len, p_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return NRF_SUCCESS; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_lib_config_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_lib_config_set.c new file mode 100644 index 0000000..01748a0 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_lib_config_set.c @@ -0,0 +1,73 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_lib_config_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_ant_lib_config) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_ant_lib_config); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_ant_lib_config); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + +uint32_t ant_lib_config_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_LIB_CONFIG_SET, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_network_address_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_network_address_set.c new file mode 100644 index 0000000..a81a556 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_network_address_set.c @@ -0,0 +1,79 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_network_address_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_network, + uint8_t * * const pp_network_key) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_network); + SER_ASSERT_NOT_NULL(*pp_network_key); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_network); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_vector_dec(p_buf, packet_len, &index, *pp_network_key, MESG_NETWORK_KEY_SIZE - MESG_CHANNEL_NUM_SIZE); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + + +uint32_t ant_network_address_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_NETWORK_KEY_SET, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_prox_search_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_prox_search_set.c new file mode 100644 index 0000000..5275843 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_prox_search_set.c @@ -0,0 +1,83 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_prox_search_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint8_t * const p_prox_threshold, + uint8_t * const p_custom_prox_threshold) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_channel); + SER_ASSERT_NOT_NULL(p_prox_threshold); + SER_ASSERT_NOT_NULL(p_custom_prox_threshold); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_prox_threshold); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_custom_prox_threshold); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + +uint32_t ant_prox_search_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_PROX_SEARCH_SET, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_rx_scan_mode_start.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_rx_scan_mode_start.c new file mode 100644 index 0000000..fde428c --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_rx_scan_mode_start.c @@ -0,0 +1,73 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_rx_scan_mode_start_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_sync_channel_packets_only) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_sync_channel_packets_only); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_sync_channel_packets_only); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + +uint32_t ant_rx_scan_mode_start_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_RX_SCAN_MODE_START, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_search_channel_priority_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_search_channel_priority_set.c new file mode 100644 index 0000000..9cf0ad7 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_search_channel_priority_set.c @@ -0,0 +1,78 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_search_channel_priority_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint8_t * const p_search_priority) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_channel); + SER_ASSERT_NOT_NULL(p_search_priority); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_search_priority); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + +uint32_t ant_search_channel_priority_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_SEARCH_CHANNEL_PRIORITY_SET, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_search_waveform_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_search_waveform_set.c new file mode 100644 index 0000000..b15df8a --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_search_waveform_set.c @@ -0,0 +1,78 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_search_waveform_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_channel, + uint16_t * const p_waveform) +{ + uint32_t index = SER_CMD_DATA_POS; + uint32_t err_code; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_channel); + SER_ASSERT_NOT_NULL(p_waveform); + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint16_t_dec(p_buf, packet_len, &index, p_waveform); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return err_code; +} + +uint32_t ant_search_waveform_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_SEARCH_WAVEFORM_SET, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_stack_reset.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_stack_reset.c new file mode 100644 index 0000000..aaed2dd --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_stack_reset.c @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_stack_reset_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + + return op_status_enc(SVC_ANT_STACK_INIT, return_code, p_buf, p_buf_len, &index); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_version_get.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_version_get.c new file mode 100644 index 0000000..3caabcb --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ant/serializers/ant_version_get.c @@ -0,0 +1,71 @@ +/** + * Copyright (c) 2017 - 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 "ant_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ant_struct_serialization.h" +#include "app_util.h" + +uint32_t ant_version_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint8_t const * const p_version) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + uint32_t total_len = *p_buf_len; + + uint32_t err_code = ser_ble_cmd_rsp_status_code_enc(SVC_ANT_VERSION, return_code, + p_buf, p_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + if (return_code != NRF_SUCCESS) + { + return NRF_SUCCESS; + } + + err_code = uint8_vector_enc(p_version, MESG_BUFFER_SIZE, p_buf, total_len, p_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return NRF_SUCCESS; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw.h new file mode 100644 index 0000000..974925a --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw.h @@ -0,0 +1,83 @@ +/** + * 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 _CONN_MW_H +#define _CONN_MW_H + +/** + * @addtogroup sercon_mw_s132 Connectivity middleware codecs for S132 and S140 (connectivity side) + * @{ + * @ingroup ser_codecs_mw + */ + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/**@brief Connectivity Middleware dispatcher function + * + * @details It handles decoding of the opcode from the RX buffer and based on the opcode, it searches + * for registered handler. Handler is called once it is found. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + * @retval NRF_ERROR_NOT_SUPPORTED Handler failure. Opcode not supported. + */ +uint32_t conn_mw_handler (uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +#ifdef __cplusplus +} +#endif + +/** @} */ + +#endif //_CONN_MW_H diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble.c new file mode 100644 index 0000000..4893059 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble.c @@ -0,0 +1,416 @@ +/** + * 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_conn.h" +#include "conn_mw_ble.h" +#include "ble_serialization.h" +#include "conn_ble_user_mem.h" +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION >= 5 +#include "nrf_sdh_ble.h" +#endif +#include <string.h> +extern sercon_ble_user_mem_t m_conn_user_mem_table[]; + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t conn_mw_ble_tx_packet_count_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t count; + uint16_t conn_handle; + uint8_t * p_count = &count; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_tx_packet_count_get_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_count); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_tx_packet_count_get(conn_handle, p_count); + + err_code = ble_tx_packet_count_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_count); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} +#endif +uint32_t conn_mw_ble_uuid_vs_add(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + ble_uuid128_t uuid; + ble_uuid128_t * p_uuid = &uuid; + uint8_t uuid_type; + uint8_t * p_uuid_type = &uuid_type; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_uuid_vs_add_req_dec(p_rx_buf, rx_buf_len, &p_uuid, &p_uuid_type); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_uuid_vs_add(p_uuid, p_uuid_type); + + err_code = ble_uuid_vs_add_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_uuid_type); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + return err_code; +} + +uint32_t conn_mw_ble_uuid_decode(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t raw_uuid[16]; + uint8_t uuid_len = sizeof (raw_uuid); + uint8_t * p_raw_uuid = raw_uuid; + ble_uuid_t uuid; + ble_uuid_t * p_uuid = &uuid; + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_uuid_decode_req_dec(p_rx_buf, rx_buf_len, &uuid_len, &p_raw_uuid, &p_uuid); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_uuid_decode(uuid_len, p_raw_uuid, p_uuid); + + err_code = ble_uuid_decode_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_uuid); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_uuid_encode(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t raw_uuid[16]; + uint8_t uuid_len = sizeof (raw_uuid); + uint8_t * p_uuid_len = &uuid_len; + uint8_t * p_raw_uuid = raw_uuid; + ble_uuid_t uuid; + ble_uuid_t * p_uuid = &uuid; + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + memset(&uuid, 0, sizeof(uuid)); + err_code = ble_uuid_encode_req_dec(p_rx_buf, rx_buf_len, &p_uuid, &p_uuid_len, &p_raw_uuid); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_uuid_encode(p_uuid, p_uuid_len, p_raw_uuid); + + err_code = ble_uuid_encode_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, uuid_len, p_raw_uuid); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_version_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + ble_version_t version; + ble_version_t * p_version = &version; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_version_get_req_dec(p_rx_buf, rx_buf_len, &p_version); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_version_get(p_version); + + err_code = ble_version_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_version); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} +uint32_t conn_mw_ble_opt_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t opt_id; + ble_opt_t opt; + ble_opt_t *p_opt = &opt; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_opt_get_req_dec(p_rx_buf, rx_buf_len, &opt_id, &p_opt); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + uint16_t act_latency; + uint8_t passkey[BLE_GAP_PASSKEY_LEN]; + /* Initialaize appropriate pointers inside opt union based on opt_id */ + switch (opt_id) + { + case BLE_GAP_OPT_LOCAL_CONN_LATENCY: + opt.gap_opt.local_conn_latency.p_actual_latency = &act_latency; + break; + case BLE_GAP_OPT_PASSKEY: + opt.gap_opt.passkey.p_passkey = passkey; + break; + } + sd_err_code = sd_ble_opt_get(opt_id, p_opt); + + err_code = ble_opt_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, opt_id, p_opt); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_opt_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t opt_id = 0xFFFFFFFF; + uint16_t act_latency; + uint8_t passkey[BLE_GAP_PASSKEY_LEN]; + uint32_t err_code = NRF_SUCCESS; + + /* Pre-decode type of ble_opt_t union */ + err_code = ble_opt_id_pre_dec(p_rx_buf, rx_buf_len, &opt_id); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + ble_opt_t opt; + ble_opt_t *p_opt = &opt; + /* Initialaize appropriate pointers inside opt union based on opt_id */ + switch (opt_id) + { + case BLE_GAP_OPT_LOCAL_CONN_LATENCY: + opt.gap_opt.local_conn_latency.p_actual_latency = &act_latency; + break; + case BLE_GAP_OPT_PASSKEY: + opt.gap_opt.passkey.p_passkey = passkey; + break; + } + + uint32_t sd_err_code; + + err_code = ble_opt_set_req_dec(p_rx_buf, rx_buf_len, &opt_id, &p_opt); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_opt_set(opt_id, p_opt); + + err_code = ble_opt_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + + +uint32_t conn_mw_ble_enable(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t app_ram_base; + +/*lint --e{10} --e{19} --e{27} --e{40} --e{529} -save suppress Error 27: Illegal character */ +#if defined(_WIN32) || defined(__unix) || defined(__APPLE__) + uint32_t ram_start = 0; +#elif defined ( __CC_ARM ) + extern uint32_t Image$$RW_IRAM1$$Base; + volatile uint32_t ram_start = (uint32_t) &Image$$RW_IRAM1$$Base; +#elif defined ( __ICCARM__ ) + extern uint32_t __ICFEDIT_region_RAM_start__; + volatile uint32_t ram_start = (uint32_t) &__ICFEDIT_region_RAM_start__; +#elif defined ( __GNUC__ ) + extern uint32_t __data_start__; + volatile uint32_t ram_start = (uint32_t) &__data_start__; +#endif + app_ram_base = ram_start; + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 + ble_enable_params_t params; + ble_enable_params_t * p_params = ¶ms; + ble_conn_bw_counts_t conn_bw_counts; + params.common_enable_params.p_conn_bw_counts = &conn_bw_counts; + + uint8_t gap_device_name_value[BLE_GAP_DEVNAME_MAX_LEN]; + ble_gap_device_name_t device_name; + device_name.max_len = BLE_GAP_DEVNAME_MAX_LEN; + device_name.p_value = gap_device_name_value; + params.gap_enable_params.p_device_name = &device_name; + + err_code = ble_enable_req_dec(p_rx_buf, rx_buf_len, &p_params); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_enable(p_params, &app_ram_base); +#else + err_code = ble_enable_req_dec(p_rx_buf, rx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION <= 4 + //Enable BLE SDH to enable events from BLE. + sd_err_code = sd_ble_enable(&app_ram_base); +#else + //Enable BLE SDH to enable events from BLE. + sd_err_code = nrf_sdh_ble_enable(&app_ram_base); +#endif +#endif + + err_code = ble_enable_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_user_mem_reply(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + ble_user_mem_block_t mem_block; + ble_user_mem_block_t * p_mem_block = &mem_block; + uint32_t err_code = NRF_SUCCESS; + uint32_t user_mem_tab_index; + uint16_t conn_handle; + /* Allocate user memory context for SoftDevice */ + + uint32_t sd_err_code; + + err_code = ble_user_mem_reply_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_mem_block); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + if (p_mem_block != NULL) + { + //Use the context if p_mem_block was not null + err_code = conn_ble_user_mem_context_create(&user_mem_tab_index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + m_conn_user_mem_table[user_mem_tab_index].conn_handle = conn_handle; + m_conn_user_mem_table[user_mem_tab_index].mem_block.len = p_mem_block->len; + p_mem_block = &(m_conn_user_mem_table[user_mem_tab_index].mem_block); + } + + sd_err_code = sd_ble_user_mem_reply(conn_handle, p_mem_block); + + err_code = ble_user_mem_reply_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} +#if NRF_SD_BLE_API_VERSION >= 4 +uint32_t conn_mw_ble_cfg_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t app_ram_base; + +/*lint --e{10} --e{19} --e{27} --e{40} --e{529} -save suppress Error 27: Illegal character */ +#if defined(_WIN32) || defined(__unix) || defined(__APPLE__) + uint32_t ram_start = 0; +#elif defined ( __CC_ARM ) + extern uint32_t Image$$RW_IRAM1$$Base; + volatile uint32_t ram_start = (uint32_t) &Image$$RW_IRAM1$$Base; +#elif defined ( __ICCARM__ ) + extern uint32_t __ICFEDIT_region_RAM_start__; + volatile uint32_t ram_start = (uint32_t) &__ICFEDIT_region_RAM_start__; +#elif defined ( __GNUC__ ) + extern uint32_t __data_start__; + volatile uint32_t ram_start = (uint32_t) &__data_start__; +#endif + app_ram_base = ram_start; + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + uint32_t cfg_id; + ble_cfg_t cfg; + uint8_t gap_device_name_value[BLE_GAP_DEVNAME_MAX_LEN]; + cfg.gap_cfg.device_name_cfg.p_value = gap_device_name_value; + cfg.gap_cfg.device_name_cfg.max_len = BLE_GAP_DEVNAME_MAX_LEN; + ble_cfg_t * p_cfg = &cfg; + + err_code = ble_cfg_set_req_dec(p_rx_buf, rx_buf_len, &cfg_id, &p_cfg); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_cfg_set(cfg_id,p_cfg, app_ram_base); + + err_code = ble_cfg_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble.h new file mode 100644 index 0000000..9d67e7e --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble.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. + * + */ +#ifndef _CONN_MW_BLE_H +#define _CONN_MW_BLE_H + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup sercon_mw_s132_ble Middleware command handlers + * @{ + * @ingroup sercon_mw_s132 + */ + +/**@brief Handles sd_ble_tx_packet_count_get command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_tx_packet_count_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_uuid_vs_add command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_uuid_vs_add(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_uuid_decode command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_uuid_decode(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_uuid_encode command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_uuid_encode(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_version_get command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_version_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_opt_get command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_opt_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_opt_set command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_opt_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_enable command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_enable(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_user_mem_reply command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_user_mem_reply(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); +#if NRF_SD_BLE_API_VERSION >= 4 +/**@brief Handles @ref sd_ble_cfg_set command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_cfg_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); +#endif + +#ifdef __cplusplus +} +#endif + +/** @} */ + +#endif //_CONN_MW_BLE_H diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble_gap.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble_gap.c new file mode 100644 index 0000000..6142d44 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble_gap.c @@ -0,0 +1,1290 @@ +/** + * 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_conn.h" +#include "ser_config.h" +#include "conn_mw_ble_gap.h" +#include "ble_serialization.h" +#include "conn_ble_gap_sec_keys.h" +#include <stddef.h> + +extern ser_ble_gap_conn_keyset_t m_conn_keys_table[SER_MAX_CONNECTIONS]; +#if NRF_SD_BLE_API_VERSION > 5 && !defined(S112) +static uint8_t * mp_scan_data; +#endif + +/* Id used to identify buffer allocated for scan reports. */ +#define SCAN_BUFFER_ID 1 +#ifndef S112 + +uint32_t conn_mw_ble_gap_connect(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + ble_gap_addr_t addr; + ble_gap_addr_t * p_addr = &addr; + + ble_gap_scan_params_t scan_params; + ble_gap_scan_params_t * p_scan_params = &scan_params; + + ble_gap_conn_params_t conn_params; + ble_gap_conn_params_t * p_conn_params = &conn_params; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + +#if NRF_SD_BLE_API_VERSION >= 4 + uint8_t conn_cfg_tag; + err_code = ble_gap_connect_req_dec(p_rx_buf, rx_buf_len, &p_addr, + &p_scan_params, &p_conn_params, &conn_cfg_tag); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_connect(p_addr, p_scan_params, p_conn_params, conn_cfg_tag); +#else + err_code = ble_gap_connect_req_dec(p_rx_buf, rx_buf_len, &p_addr, + &p_scan_params, &p_conn_params); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_connect(p_addr, p_scan_params, p_conn_params); +#endif + + err_code = ble_gap_connect_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gap_connect_cancel(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + sd_err_code = sd_ble_gap_connect_cancel(); + + err_code = ble_gap_connect_cancel_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gap_scan_start(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + ble_gap_scan_params_t scan_params; + ble_gap_scan_params_t * p_scan_params = &scan_params; +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 + ble_data_t adv_report_buffer; + ble_data_t * p_adv_report_buffer = &adv_report_buffer; + mp_scan_data = conn_ble_gap_ble_data_buf_alloc(SCAN_BUFFER_ID); + adv_report_buffer.p_data = mp_scan_data; + adv_report_buffer.len = SER_MAX_ADV_DATA; + err_code = ble_gap_scan_start_req_dec(p_rx_buf, rx_buf_len, &p_scan_params, &p_adv_report_buffer); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_scan_start(p_scan_params, p_adv_report_buffer); +#else + err_code = ble_gap_scan_start_req_dec(p_rx_buf, rx_buf_len, &p_scan_params); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_scan_start(p_scan_params); +#endif + err_code = ble_gap_scan_start_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + + +uint32_t conn_mw_ble_gap_scan_stop(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 + conn_ble_gap_ble_data_buf_free(mp_scan_data); +#endif + + sd_err_code = sd_ble_gap_scan_stop(); + + err_code = ble_gap_scan_stop_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gap_encrypt(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + uint16_t conn_handle; + + ble_gap_master_id_t master_id; + ble_gap_master_id_t *p_master_id = &master_id; + + ble_gap_enc_info_t enc_info; + ble_gap_enc_info_t *p_enc_info = &enc_info; + + err_code = ble_gap_encrypt_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_master_id, &p_enc_info); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_encrypt(conn_handle, p_master_id, p_enc_info); + + err_code = ble_gap_encrypt_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} +#endif //!S112 + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 6 +uint32_t conn_mw_ble_gap_adv_data_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t data[BLE_GAP_ADV_MAX_SIZE]; + uint8_t * p_data = data; + uint8_t dlen = sizeof (data); + + uint8_t sr_data[BLE_GAP_ADV_MAX_SIZE]; + uint8_t * p_sr_data = sr_data; + uint8_t srdlen = sizeof (sr_data); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gap_adv_data_set_req_dec(p_rx_buf, + rx_buf_len, + &p_data, + &dlen, + &p_sr_data, + &srdlen); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_adv_data_set(p_data, dlen, p_sr_data, srdlen); + + err_code = ble_gap_adv_data_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} +#endif + +uint32_t conn_mw_ble_gap_adv_start(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t conn_cfg_tag; + uint8_t adv_handle; + + err_code = ble_gap_adv_start_req_dec(p_rx_buf, rx_buf_len, &adv_handle, &conn_cfg_tag); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_adv_start(adv_handle, conn_cfg_tag); +#else + ble_gap_addr_t peer_addr; + ble_gap_adv_params_t adv_params; + ble_gap_adv_params_t * p_adv_params; + + adv_params.p_peer_addr = &peer_addr; + p_adv_params = &adv_params; +#if NRF_SD_BLE_API_VERSION >= 4 + uint8_t conn_cfg_tag; + err_code = ble_gap_adv_start_req_dec(p_rx_buf, rx_buf_len, &p_adv_params, &conn_cfg_tag); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_adv_start(p_adv_params, conn_cfg_tag); +#else + err_code = ble_gap_adv_start_req_dec(p_rx_buf, rx_buf_len, &p_adv_params); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_adv_start(p_adv_params); +#endif +#endif + err_code = ble_gap_adv_start_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gap_adv_stop(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t adv_handle; + err_code = ble_gap_adv_stop_req_dec(p_rx_buf, rx_buf_len, &adv_handle); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_adv_stop(adv_handle); +#else + sd_err_code = sd_ble_gap_adv_stop(); +#endif + + err_code = ble_gap_adv_stop_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gap_conn_param_update(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t conn_handle; + ble_gap_conn_params_t conn_params; + ble_gap_conn_params_t * p_conn_params = &conn_params; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gap_conn_param_update_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_conn_params); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_conn_param_update(conn_handle, p_conn_params); + + err_code = ble_gap_conn_param_update_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gap_disconnect(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t conn_handle; + uint8_t hci_status_code; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gap_disconnect_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &hci_status_code); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_disconnect(conn_handle, hci_status_code); + + err_code = ble_gap_disconnect_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gap_tx_power_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + int8_t tx_power; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t role; + uint16_t handle; + + err_code = ble_gap_tx_power_set_req_dec(p_rx_buf, rx_buf_len, &role, &handle, &tx_power); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_tx_power_set(role, handle, tx_power); +#else + err_code = ble_gap_tx_power_set_req_dec(p_rx_buf, rx_buf_len, &tx_power); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_tx_power_set(tx_power); +#endif + err_code = ble_gap_tx_power_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gap_appearance_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t appearance; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gap_appearance_set_req_dec(p_rx_buf, rx_buf_len, &appearance); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_appearance_set(appearance); + + err_code = ble_gap_appearance_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gap_appearance_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t appearance; + uint16_t * p_appearance = &appearance; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gap_appearance_get_req_dec(p_rx_buf, rx_buf_len, &p_appearance); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_appearance_get(p_appearance); + + err_code = ble_gap_appearance_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_appearance); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + + +uint32_t conn_mw_ble_gap_ppcp_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + ble_gap_conn_params_t conn_params; + ble_gap_conn_params_t * p_conn_params = &conn_params; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gap_ppcp_set_req_dec(p_rx_buf, rx_buf_len, &p_conn_params); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_ppcp_set(p_conn_params); + + err_code = ble_gap_ppcp_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gap_ppcp_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + ble_gap_conn_params_t conn_params; + ble_gap_conn_params_t * p_conn_params = &conn_params; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gap_ppcp_get_req_dec(p_rx_buf, rx_buf_len, &p_conn_params); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_ppcp_get(p_conn_params); + + err_code = ble_gap_ppcp_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_conn_params); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gap_device_name_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + uint8_t dev_name[BLE_GAP_DEVNAME_MAX_LEN]; + uint8_t * p_dev_name = dev_name; + + uint16_t len; + uint16_t * p_len = &len; + + err_code = ble_gap_device_name_get_req_dec(p_rx_buf, rx_buf_len, &p_dev_name, &p_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_device_name_get(p_dev_name, p_len); + + err_code = ble_gap_device_name_get_rsp_enc(sd_err_code, p_dev_name, p_len, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gap_device_name_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + ble_gap_conn_sec_mode_t write_perm; + ble_gap_conn_sec_mode_t * p_write_perm = &write_perm; + + uint8_t dev_name[BLE_GAP_DEVNAME_MAX_LEN]; + uint8_t * p_dev_name = dev_name; + + uint16_t len = BLE_GAP_DEVNAME_MAX_LEN; + + err_code = ble_gap_device_name_set_req_dec(p_rx_buf, + rx_buf_len, + &p_write_perm, + &p_dev_name, + &len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_device_name_set(p_write_perm, p_dev_name, len); + + err_code = ble_gap_device_name_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gap_authenticate(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + uint16_t conn_handle; + + ble_gap_sec_params_t sec_params; + ble_gap_sec_params_t * p_sec_params = &sec_params; + + err_code = ble_gap_authenticate_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_sec_params); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_authenticate(conn_handle, p_sec_params); + + err_code = ble_gap_authenticate_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gap_sec_params_reply(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + uint32_t sec_tab_index = 0; + + uint16_t * p_conn_handle; + uint8_t sec_status; + + ble_gap_sec_params_t sec_params; + ble_gap_sec_params_t * p_sec_params = &sec_params; + + // Allocate global security context for soft device + err_code = conn_ble_gap_sec_context_create(&sec_tab_index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + p_conn_handle = &(m_conn_keys_table[sec_tab_index].conn_handle); + + // Set up global structure for command decoder + ble_gap_sec_keyset_t * p_sec_keyset = &(m_conn_keys_table[sec_tab_index].keyset); + + p_sec_keyset->keys_own.p_enc_key = &(m_conn_keys_table[sec_tab_index].enc_key_own); + p_sec_keyset->keys_own.p_id_key = &(m_conn_keys_table[sec_tab_index].id_key_own); + p_sec_keyset->keys_own.p_sign_key = &(m_conn_keys_table[sec_tab_index].sign_key_own); + p_sec_keyset->keys_own.p_pk = &(m_conn_keys_table[sec_tab_index].pk_own); + p_sec_keyset->keys_peer.p_enc_key = &(m_conn_keys_table[sec_tab_index].enc_key_peer); + p_sec_keyset->keys_peer.p_id_key = &(m_conn_keys_table[sec_tab_index].id_key_peer); + p_sec_keyset->keys_peer.p_sign_key = &(m_conn_keys_table[sec_tab_index].sign_key_peer); + p_sec_keyset->keys_peer.p_pk = &(m_conn_keys_table[sec_tab_index].pk_peer); + + err_code = ble_gap_sec_params_reply_req_dec(p_rx_buf, + rx_buf_len, + p_conn_handle, + &sec_status, + &p_sec_params, + &p_sec_keyset); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + if (p_sec_keyset == NULL) + { + //If no keyset was sent destroy the context. + err_code = conn_ble_gap_sec_context_destroy(*p_conn_handle); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + } + sd_err_code = sd_ble_gap_sec_params_reply(*p_conn_handle, sec_status, p_sec_params, p_sec_keyset); + + err_code = ble_gap_sec_params_reply_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_sec_keyset); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gap_auth_key_reply(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + uint16_t conn_handle; + uint8_t key_type; + + uint8_t key[BLE_GAP_SEC_KEY_LEN]; + uint8_t * p_key = key; + + err_code = ble_gap_auth_key_reply_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &key_type, &p_key); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_auth_key_reply(conn_handle, key_type, p_key); + + err_code = ble_gap_auth_key_reply_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gap_sec_info_reply(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + uint16_t conn_handle; + + ble_gap_enc_info_t enc_info; + ble_gap_enc_info_t * p_enc_info = &enc_info; + + ble_gap_irk_t id_info; + ble_gap_irk_t * p_id_info = &id_info; + + ble_gap_sign_info_t sign_info; + ble_gap_sign_info_t * p_sign_info = &sign_info; + + err_code = ble_gap_sec_info_reply_req_dec(p_rx_buf, + rx_buf_len, + &conn_handle, + &p_enc_info, + &p_id_info, + &p_sign_info); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_sec_info_reply(conn_handle, p_enc_info, p_id_info, p_sign_info); + + err_code = ble_gap_sec_info_reply_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gap_conn_sec_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + uint16_t conn_handle; + + ble_gap_conn_sec_t conn_sec; + ble_gap_conn_sec_t * p_conn_sec = &conn_sec; + + err_code = ble_gap_conn_sec_get_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_conn_sec); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_conn_sec_get(conn_handle, p_conn_sec); + + err_code = ble_gap_conn_sec_get_rsp_enc(sd_err_code, p_conn_sec, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gap_rssi_start(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + uint16_t conn_handle; + uint8_t threshold_dbm; + uint8_t skip_count; + + err_code = ble_gap_rssi_start_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &threshold_dbm, &skip_count); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_rssi_start(conn_handle, threshold_dbm, skip_count); + + err_code = ble_gap_rssi_start_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gap_rssi_stop(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + uint16_t conn_handle; + + err_code = ble_gap_rssi_stop_req_dec(p_rx_buf, rx_buf_len, &conn_handle); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_rssi_stop(conn_handle); + + err_code = ble_gap_rssi_stop_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gap_rssi_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + uint16_t conn_handle; + int8_t rssi; + int8_t * p_rssi = &rssi; + +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t ch_index; + uint8_t * p_ch_index = &ch_index; + + err_code = ble_gap_rssi_get_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_rssi, &p_ch_index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_rssi_get(conn_handle, p_rssi, p_ch_index); + + err_code = ble_gap_rssi_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_rssi, p_ch_index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); +#else + err_code = ble_gap_rssi_get_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_rssi); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_rssi_get(conn_handle, p_rssi); + + err_code = ble_gap_rssi_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_rssi); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); +#endif + return err_code; +} + +uint32_t conn_mw_ble_gap_keypress_notify(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + uint16_t conn_handle; + uint8_t kp_not; + + err_code = ble_gap_keypress_notify_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &kp_not); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_keypress_notify(conn_handle, kp_not); + + err_code = ble_gap_keypress_notify_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gap_lesc_dhkey_reply(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + uint16_t conn_handle; + ble_gap_lesc_dhkey_t dhkey; + ble_gap_lesc_dhkey_t * p_dhkey = &dhkey; + + err_code = ble_gap_lesc_dhkey_reply_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_dhkey); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_lesc_dhkey_reply(conn_handle, p_dhkey); + + err_code = ble_gap_lesc_dhkey_reply_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gap_lesc_oob_data_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + uint16_t conn_handle; + ble_gap_lesc_oob_data_t own; + ble_gap_lesc_oob_data_t peer; + ble_gap_lesc_oob_data_t * p_own = &own; + ble_gap_lesc_oob_data_t * p_peer = &peer; + + err_code = ble_gap_lesc_oob_data_set_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_own, &p_peer); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_lesc_oob_data_set(conn_handle, p_own, p_peer); + + err_code = ble_gap_lesc_oob_data_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gap_lesc_oob_data_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + uint16_t conn_handle; + ble_gap_lesc_oob_data_t own; + ble_gap_lesc_oob_data_t * p_own = &own; + ble_gap_lesc_p256_pk_t pk; + ble_gap_lesc_p256_pk_t * p_pk = &pk; + + err_code = ble_gap_lesc_oob_data_get_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_pk, &p_own); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + sd_err_code = sd_ble_gap_lesc_oob_data_get(conn_handle, p_pk, p_own); + + err_code = ble_gap_lesc_oob_data_get_rsp_enc(sd_err_code, p_own, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gap_addr_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + ble_gap_addr_t addr; + ble_gap_addr_t * p_addr = &addr; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gap_addr_set_req_dec(p_rx_buf, rx_buf_len, &p_addr); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_addr_set(p_addr); + + err_code = ble_gap_addr_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} +uint32_t conn_mw_ble_gap_addr_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + ble_gap_addr_t addr; + ble_gap_addr_t * p_addr = &addr; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gap_addr_get_req_dec(p_rx_buf, rx_buf_len, &p_addr); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_addr_get(p_addr); + + err_code = ble_gap_addr_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_addr); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gap_privacy_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + ble_gap_privacy_params_t privacy_params; + ble_gap_privacy_params_t * p_privacy_params = &privacy_params; + + ble_gap_irk_t irk; + privacy_params.p_device_irk = &irk; + + err_code = ble_gap_privacy_set_req_dec(p_rx_buf, rx_buf_len, &p_privacy_params); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_privacy_set(p_privacy_params); + + err_code = ble_gap_privacy_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + + +uint32_t conn_mw_ble_gap_privacy_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + ble_gap_privacy_params_t privacy_params; + ble_gap_privacy_params_t * p_privacy_params = &privacy_params; + + ble_gap_irk_t irk; + privacy_params.p_device_irk = &irk; + + err_code = ble_gap_privacy_get_req_dec(p_rx_buf, rx_buf_len, &p_privacy_params); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_privacy_get(p_privacy_params); + + err_code = ble_gap_privacy_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_privacy_params); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gap_whitelist_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + uint8_t length; + ble_gap_addr_t wl_addr_array[BLE_GAP_WHITELIST_ADDR_MAX_COUNT]; + ble_gap_addr_t * p_wl_addrs_array[BLE_GAP_WHITELIST_ADDR_MAX_COUNT]; + + for (uint8_t i = 0; i < BLE_GAP_WHITELIST_ADDR_MAX_COUNT; ++i) + { + p_wl_addrs_array[i] = &wl_addr_array[i]; + } + + ble_gap_addr_t * * pp_wl_addrs = p_wl_addrs_array; + + err_code = ble_gap_whitelist_set_req_dec(p_rx_buf, rx_buf_len, &pp_wl_addrs, &length); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + sd_err_code = sd_ble_gap_whitelist_set((ble_gap_addr_t const * *)pp_wl_addrs, length); + + err_code = ble_gap_whitelist_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gap_device_identities_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + uint8_t length; + ble_gap_id_key_t id_key_array[BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT]; + ble_gap_id_key_t * p_id_key_array[BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT]; + ble_gap_irk_t irk_array[BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT]; + ble_gap_irk_t * p_irk_array[BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT]; + + for (uint8_t i = 0; i < BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT; ++i) + { + p_id_key_array[i] = &id_key_array[i]; + p_irk_array[i] = &irk_array[i]; + } + + ble_gap_id_key_t * * pp_id_keys = p_id_key_array; + ble_gap_irk_t * * pp_local_irks = p_irk_array; + + err_code = ble_gap_device_identities_set_req_dec(p_rx_buf, rx_buf_len, + &pp_id_keys, + &pp_local_irks, + &length); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_device_identities_set((ble_gap_id_key_t const * *) pp_id_keys, + (ble_gap_irk_t const * *) pp_local_irks, + length); + + err_code = ble_gap_device_identities_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +#if NRF_SD_BLE_API_VERSION >= 5 +uint32_t conn_mw_ble_gap_phy_update(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + uint16_t conn_handle; + + ble_gap_phys_t gap_phys; + ble_gap_phys_t * p_gap_phys = &gap_phys; + + err_code = ble_gap_phy_update_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_gap_phys); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_phy_update(conn_handle, p_gap_phys); + + err_code = ble_gap_phy_update_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} +#endif + +#if NRF_SD_BLE_API_VERSION >= 4 && !defined(S112) +uint32_t conn_mw_ble_gap_data_length_update(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + uint16_t conn_handle; + ble_gap_data_length_params_t dl_params; + ble_gap_data_length_params_t * p_dl_params = &dl_params; + ble_gap_data_length_limitation_t dl_limitation; + ble_gap_data_length_limitation_t * p_dl_limitation = &dl_limitation; + + err_code = ble_gap_data_length_update_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_dl_params, &p_dl_limitation); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_data_length_update(conn_handle, p_dl_params,p_dl_limitation ); + + err_code = ble_gap_data_length_update_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_dl_limitation); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} +#endif //NRF_SD_BLE_API_VERSION >= 4 && !defined(S112) + +#if NRF_SD_BLE_API_VERSION > 5 +uint32_t conn_mw_ble_gap_adv_set_configure(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + uint8_t adv_handle; + uint8_t * p_adv_handle = &adv_handle; + ble_gap_adv_data_t adv_data; + ble_gap_adv_data_t * p_adv_data = &adv_data; + adv_data.adv_data.len = SER_MAX_ADV_DATA; + adv_data.adv_data.p_data = NULL; + adv_data.scan_rsp_data.len = SER_MAX_ADV_DATA; + adv_data.scan_rsp_data.p_data = NULL; + ble_gap_addr_t addr; + ble_gap_adv_params_t adv_params; + adv_params.p_peer_addr = &addr; + ble_gap_adv_params_t * p_adv_params = &adv_params; + + + err_code = ble_gap_adv_set_configure_req_dec(p_rx_buf, rx_buf_len, &p_adv_handle, &p_adv_data, &p_adv_params); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_adv_set_configure(p_adv_handle, p_adv_data, p_adv_params); + + err_code = ble_gap_adv_set_configure_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_adv_handle); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +#ifndef S112 +uint32_t conn_mw_ble_gap_qos_channel_survey_start(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + uint32_t interval_us; + + err_code = ble_gap_qos_channel_survey_start_req_dec(p_rx_buf, rx_buf_len, &interval_us); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_qos_channel_survey_start(interval_us); + + err_code = ble_gap_qos_channel_survey_start_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gap_qos_channel_survey_stop(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gap_qos_channel_survey_stop_req_dec(p_rx_buf, rx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gap_qos_channel_survey_stop(); + + err_code = ble_gap_qos_channel_survey_stop_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} +#endif //!S112 +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble_gap.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble_gap.h new file mode 100644 index 0000000..0dcb602 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble_gap.h @@ -0,0 +1,820 @@ +/** + * 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 _CONN_MW_BLE_GAP_H +#define _CONN_MW_BLE_GAP_H + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup sercon_mw_s132_ble_gap GAP Middleware command handlers + * @{ + * @ingroup sercon_mw_s132 + */ + +#if defined(NRF_SD_BLE_API_VERSION) && (NRF_SD_BLE_API_VERSION <= 5) +/**@brief Handles @ref sd_ble_gap_adv_data_set command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_adv_data_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); +#endif + +/**@brief Handles @ref sd_ble_gap_adv_start command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_adv_start(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_adv_stop command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_adv_stop(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_conn_param_update command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_conn_param_update(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_disconnect command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_disconnect(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_tx_power_set command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_tx_power_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_appearance_set command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_appearance_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_appearance_get command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_appearance_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_ppcp_set command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_ppcp_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_ppcp_get command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_ppcp_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_device_name_get command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_device_name_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_device_name_set command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_device_name_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_authenticate command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_authenticate(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_sec_params_reply command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_sec_params_reply(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_auth_key_reply command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_auth_key_reply(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_sec_info_reply command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_sec_info_reply(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_conn_sec_get command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_conn_sec_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_rssi_start command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_rssi_start(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_rssi_stop command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_rssi_stop(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_rssi_get command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_rssi_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_connect command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_connect(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_connect_cancel command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_connect_cancel(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_scan_start command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_scan_start(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_scan_stop command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_scan_stop(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_encrypt command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ + +uint32_t conn_mw_ble_gap_encrypt(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_keypress_notify command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ + +uint32_t conn_mw_ble_gap_keypress_notify(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_lesc_dhkey_reply command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ + +uint32_t conn_mw_ble_gap_lesc_dhkey_reply(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_lesc_oob_data_set command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ + +uint32_t conn_mw_ble_gap_lesc_oob_data_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_lesc_oob_data_get command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ + +uint32_t conn_mw_ble_gap_lesc_oob_data_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Allocates instance in m_conn_keys_table[] for storage of encryption keys. + * + * @param[in] conn_handle Connection handle. + * @param[out] p_index Pointer to the index of allocated instance. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_NO_MEM No free instance available. + */ +uint32_t conn_mw_ble_gap_sec_context_create(uint16_t conn_handle, uint32_t *p_index); + +/**@brief Releases the instance identified by a connection handle. + * + * @param[in] conn_handle Connection handle. + + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_NOT_FOUND Instance with the @p conn_handle not found. + */ +uint32_t conn_mw_ble_gap_sec_context_destroy(uint16_t conn_handle); + +/**@brief Finds index of instance identified by a connection handle in m_conn_keys_table[]. + * + * @param[in] conn_handle Connection handle. + * @param[out] p_index Pointer to the index of the context instance. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_NOT_FOUND Instance with the @p conn_handle not found. + */ +uint32_t conn_mw_ble_gap_sec_context_find(uint16_t conn_handle, uint32_t *p_index); + +/**@brief Handles @ref sd_ble_gap_addr_set command request and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_addr_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_addr_get command request and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_addr_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_privacy_set command request and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_privacy_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_privacy_get command request and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_privacy_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_whitelist_set command request and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_whitelist_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_device_identities_set command request and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_device_identities_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_phy_update command request and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ + +#if NRF_SD_BLE_API_VERSION >= 5 +uint32_t conn_mw_ble_gap_phy_update(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); +#endif +#ifdef __cplusplus +} +#endif + +#if NRF_SD_BLE_API_VERSION >= 4 +/**@brief Handles @ref sd_ble_gap_data_length_update command request and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_data_length_update(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_adv_set_configure command request and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_adv_set_configure(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_qos_channel_survey_start command request and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_qos_channel_survey_start(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gap_qos_channel_survey_stop command request and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gap_qos_channel_survey_stop(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); +#endif +#endif //_CONN_MW_BLE_GAP_H + +/** @} */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble_gattc.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble_gattc.c new file mode 100644 index 0000000..904c67f --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble_gattc.c @@ -0,0 +1,389 @@ +/** + * 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_gattc_conn.h" +#include "conn_mw_ble_gattc.h" +#include "ble_serialization.h" + +#if defined(BLE_GATT_MTU_SIZE_DEFAULT) && !defined(GATT_MTU_SIZE_DEFAULT) +#define GATT_MTU_SIZE_DEFAULT BLE_GATT_MTU_SIZE_DEFAULT +#endif + +#if defined(BLE_GATT_ATT_MTU_DEFAULT) && !defined(GATT_MTU_SIZE_DEFAULT) +#define GATT_MTU_SIZE_DEFAULT BLE_GATT_ATT_MTU_DEFAULT +#endif + +#define BLE_GATTC_WRITE_P_VALUE_LEN_MAX (247 - 3) + +/** See Bluetooth 4.0 spec: 3.4.4.7. */ +#define BLE_GATTC_HANDLE_COUNT_LEN_MAX ((GATT_MTU_SIZE_DEFAULT - 1) / 2) + +uint32_t conn_mw_ble_gattc_primary_services_discover(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t conn_handle; + uint16_t start_handle; + ble_uuid_t srvc_uuid; + ble_uuid_t * p_srvc_uuid = &srvc_uuid; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gattc_primary_services_discover_req_dec(p_rx_buf, + rx_buf_len, + &conn_handle, + &start_handle, + &p_srvc_uuid); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gattc_primary_services_discover(conn_handle, start_handle, p_srvc_uuid); + + err_code = ble_gattc_primary_services_discover_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gattc_relationships_discover(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t conn_handle; + ble_gattc_handle_range_t handle_range; + ble_gattc_handle_range_t * p_handle_range = &handle_range; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gattc_relationships_discover_req_dec(p_rx_buf, rx_buf_len, + &conn_handle, &p_handle_range); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gattc_relationships_discover(conn_handle, p_handle_range); + + err_code = ble_gattc_relationships_discover_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gattc_characteristics_discover(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t conn_handle; + ble_gattc_handle_range_t handle_range; + ble_gattc_handle_range_t * p_handle_range = &handle_range; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gattc_characteristics_discover_req_dec(p_rx_buf, rx_buf_len, + &conn_handle, &p_handle_range); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gattc_characteristics_discover(conn_handle, p_handle_range); + + err_code = ble_gattc_characteristics_discover_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gattc_descriptors_discover(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t conn_handle; + ble_gattc_handle_range_t handle_range; + ble_gattc_handle_range_t * p_handle_range = &handle_range; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gattc_descriptors_discover_req_dec(p_rx_buf, rx_buf_len, + &conn_handle, &p_handle_range); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gattc_descriptors_discover(conn_handle, p_handle_range); + + err_code = ble_gattc_descriptors_discover_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gattc_char_value_by_uuid_read(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t conn_handle; + + ble_uuid_t uuid = {0}; + ble_uuid_t * p_uuid = &uuid; + + ble_gattc_handle_range_t handle_range; + ble_gattc_handle_range_t * p_handle_range = &handle_range; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gattc_char_value_by_uuid_read_req_dec(p_rx_buf, rx_buf_len, + &conn_handle, &p_uuid, &p_handle_range); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gattc_char_value_by_uuid_read(conn_handle, p_uuid, p_handle_range); + + err_code = ble_gattc_char_value_by_uuid_read_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gattc_read(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t conn_handle; + uint16_t * p_conn_handle = &conn_handle; + + uint16_t handle; + uint16_t * p_handle = &handle; + + uint16_t offset; + uint16_t * p_offset = &offset; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gattc_read_req_dec(p_rx_buf, rx_buf_len, p_conn_handle, p_handle, p_offset); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gattc_read(conn_handle, handle, offset); + + err_code = ble_gattc_read_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gattc_char_values_read(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t conn_handle; + uint16_t * p_conn_handle = &conn_handle; + + uint16_t handles[BLE_GATTC_HANDLE_COUNT_LEN_MAX]; + uint16_t * p_handles = handles; + + uint16_t handle_count = BLE_GATTC_HANDLE_COUNT_LEN_MAX; + uint16_t * p_handle_count = &handle_count; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gattc_char_values_read_req_dec(p_rx_buf, + rx_buf_len, + p_conn_handle, + &p_handles, + p_handle_count); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gattc_char_values_read(conn_handle, p_handles, handle_count); + + err_code = ble_gattc_char_values_read_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gattc_write(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t conn_handle; + uint16_t * p_conn_handle = &conn_handle; + + uint8_t value[BLE_GATTC_WRITE_P_VALUE_LEN_MAX]; + + ble_gattc_write_params_t write_params = {0}; + ble_gattc_write_params_t * p_write_params = &write_params; + + p_write_params->len = BLE_GATTC_WRITE_P_VALUE_LEN_MAX; + p_write_params->p_value = value; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gattc_write_req_dec(p_rx_buf, rx_buf_len, p_conn_handle, &p_write_params); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gattc_write(conn_handle, p_write_params); + + err_code = ble_gattc_write_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gattc_hv_confirm(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + uint16_t conn_handle; + uint16_t * p_conn_handle = &conn_handle; + + uint16_t handle; + uint16_t * p_handle = &handle; + + err_code = ble_gattc_hv_confirm_req_dec(p_rx_buf, rx_buf_len, p_conn_handle, p_handle); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gattc_hv_confirm(conn_handle, handle); + + err_code = ble_gattc_hv_confirm_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gattc_attr_info_discover(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t conn_handle; + uint16_t * p_conn_handle = &conn_handle; + + ble_gattc_handle_range_t range = {0}; + ble_gattc_handle_range_t * p_range = ⦥ + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gattc_attr_info_discover_req_dec(p_rx_buf, rx_buf_len, p_conn_handle, &p_range); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gattc_attr_info_discover(conn_handle, p_range); + + err_code = ble_gattc_attr_info_discover_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gattc_exchange_mtu_request(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t conn_handle; + uint16_t client_rx_mtu; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gattc_exchange_mtu_request_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &client_rx_mtu); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gattc_exchange_mtu_request(conn_handle, client_rx_mtu); + + err_code = ble_gattc_exchange_mtu_request_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble_gattc.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble_gattc.h new file mode 100644 index 0000000..61b6248 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble_gattc.h @@ -0,0 +1,259 @@ +/** + * 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 _CONN_MW_BLE_GATTC_H + #define _CONN_MW_BLE_GATTC_H + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup sercon_mw_s132_ble_gattc GATTC Middleware command handlers + * @{ + * @ingroup sercon_mw_s132 + */ + +/**@brief Handles @ref sd_ble_gattc_primary_services_discover command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gattc_primary_services_discover (uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gattc_relationships_discover command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gattc_relationships_discover(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gattc_characteristics_discover command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gattc_characteristics_discover(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gattc_descriptors_discover command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gattc_descriptors_discover(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gattc_char_value_by_uuid_read command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gattc_char_value_by_uuid_read(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gattc_read command and prepares response. + * + * @param[in] rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gattc_read (uint8_t const *const rx_buf, + uint32_t rx_buf_len, + uint8_t *const tx_buf, + uint32_t *const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gattc_char_values_read command and prepares response. + * + * @param[in] rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gattc_char_values_read (uint8_t const *const rx_buf, + uint32_t rx_buf_len, + uint8_t *const tx_buf, + uint32_t *const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gattc_write command and prepares response. + * + * @param[in] rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gattc_write (uint8_t const *const rx_buf, + uint32_t rx_buf_len, + uint8_t *const tx_buf, + uint32_t *const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gattc_hv_confirm command and prepares response. + * + * @param[in] rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gattc_hv_confirm (uint8_t const *const rx_buf, + uint32_t rx_buf_len, + uint8_t *const tx_buf, + uint32_t *const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gattc_attr_info_discover command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gattc_attr_info_discover(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gattc_exchange_mtu_request command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gattc_exchange_mtu_request(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif //_CONN_MW_BLE_GATTC_H diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble_gatts.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble_gatts.c new file mode 100644 index 0000000..d55626f --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble_gatts.c @@ -0,0 +1,517 @@ +/** + * 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_gatts_conn.h" +#include "conn_mw_ble_gatts.h" +#include "ble_serialization.h" + +uint32_t conn_mw_ble_gatts_service_add(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint8_t type; + ble_uuid_t uuid = {0}; + ble_uuid_t * p_uuid = &uuid; + uint16_t handle; + uint16_t * p_handle = &handle; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gatts_service_add_req_dec(p_rx_buf, rx_buf_len, &type, &p_uuid, &p_handle); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gatts_service_add(type, p_uuid, p_handle); + + err_code = ble_gatts_service_add_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_handle); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gatts_characteristic_add(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t service_handle; + + //Preparing char_md + ble_gatts_char_md_t char_md; + + uint8_t char_user_desc[BLE_GATTS_VAR_ATTR_LEN_MAX]; + ble_gatts_char_pf_t char_pf; + ble_gatts_attr_md_t user_desc_md; + ble_gatts_attr_md_t cccd_md; + ble_gatts_attr_md_t sccd_md; + + char_md.char_user_desc_size = sizeof (char_user_desc); + char_md.p_char_user_desc = char_user_desc; + char_md.p_char_pf = &char_pf; + char_md.p_user_desc_md = &user_desc_md; + char_md.p_cccd_md = &cccd_md; + char_md.p_sccd_md = &sccd_md; + + ble_gatts_char_md_t * p_char_md = &char_md; + + //Preparing attr_char_value + ble_gatts_attr_t attr_char_value; + ble_uuid_t uuid; + ble_gatts_attr_md_t attr_md; + uint8_t value[BLE_GATTS_VAR_ATTR_LEN_MAX]; + + attr_char_value.p_uuid = &uuid; + attr_char_value.p_attr_md = &attr_md; + attr_char_value.init_len = sizeof (value); + attr_char_value.p_value = value; + + ble_gatts_attr_t * p_attr_char_value = &attr_char_value; + + //Preparing handles + ble_gatts_char_handles_t handles; + ble_gatts_char_handles_t * p_handles = &handles; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gatts_characteristic_add_req_dec(p_rx_buf, rx_buf_len, &service_handle, + &p_char_md, &p_attr_char_value, &p_handles); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gatts_characteristic_add(service_handle, p_char_md, + p_attr_char_value, p_handles); + + err_code = ble_gatts_characteristic_add_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, + p_handles); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; + +} + +uint32_t conn_mw_ble_gatts_include_add(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t service_handle; + uint16_t inc_srvc_handle; + uint16_t handle; + uint16_t * p_handle = &handle; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gatts_include_add_req_dec(p_rx_buf, rx_buf_len, &service_handle, + &inc_srvc_handle, &p_handle); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gatts_include_add(service_handle, inc_srvc_handle, p_handle); + + err_code = ble_gatts_include_add_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_handle); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gatts_descriptor_add(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t char_handle; + uint8_t attr_value[BLE_GATTS_VAR_ATTR_LEN_MAX]; + ble_uuid_t char_uuid; + ble_gatts_attr_md_t metadata; + ble_gatts_attr_t attr; + ble_gatts_attr_t * p_attr = &attr; + + attr.p_uuid = &char_uuid; + attr.p_attr_md = &metadata; + attr.p_value = attr_value; + attr.init_len = sizeof (attr_value); + + uint16_t handle; + uint16_t * p_handle = &handle; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gatts_descriptor_add_req_dec(p_rx_buf, rx_buf_len, &char_handle, &p_attr, + &p_handle); + + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gatts_descriptor_add(char_handle, p_attr, p_handle); + + err_code = ble_gatts_descriptor_add_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_handle); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gatts_value_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t conn_handle; + uint16_t handle; + uint8_t attr_val_table[BLE_GATTS_VAR_ATTR_LEN_MAX]; + ble_gatts_value_t attr_val = + { + .len = sizeof (attr_val_table), + .offset = 0, + .p_value = attr_val_table + }; + ble_gatts_value_t * p_attr_val = &attr_val; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gatts_value_set_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &handle, &p_attr_val); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gatts_value_set(conn_handle, handle, p_attr_val); + + err_code = ble_gatts_value_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_attr_val); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gatts_value_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t conn_handle; + uint16_t handle; + uint8_t val[BLE_GATTS_VAR_ATTR_LEN_MAX]; + ble_gatts_value_t attr_value; + ble_gatts_value_t * p_attr_value = &attr_value; + + attr_value.p_value = val; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gatts_value_get_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &handle, &p_attr_value); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + sd_err_code = sd_ble_gatts_value_get(conn_handle, handle, p_attr_value); + + err_code = ble_gatts_value_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_attr_value); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gatts_hvx(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t conn_handle; + uint8_t data[BLE_GATTS_VAR_ATTR_LEN_MAX]; + uint8_t * p_data = data; + uint16_t len = sizeof data; + uint16_t * p_len = &len; + + ble_gatts_hvx_params_t hvx_params; + ble_gatts_hvx_params_t * p_hvx_params = &hvx_params; + + hvx_params.p_len = p_len; + hvx_params.p_data = p_data; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gatts_hvx_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_hvx_params); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + sd_err_code = sd_ble_gatts_hvx(conn_handle, p_hvx_params); + + p_len = (p_hvx_params) ? p_hvx_params->p_len : NULL; + err_code = ble_gatts_hvx_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gatts_service_changed(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t conn_handle; + uint16_t start_handle; + uint16_t end_handle; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gatts_service_changed_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &start_handle, + &end_handle); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gatts_service_changed(conn_handle, start_handle, end_handle); + + err_code = ble_gatts_service_changed_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gatts_rw_authorize_reply(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t conn_handle; + + uint8_t data[BLE_GATTS_VAR_ATTR_LEN_MAX]; + ble_gatts_rw_authorize_reply_params_t auth_params; + ble_gatts_rw_authorize_reply_params_t * p_auth_params = &auth_params; + + auth_params.params.read.p_data = data; + auth_params.params.read.len = sizeof (data); + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gatts_rw_authorize_reply_req_dec(p_rx_buf, rx_buf_len, &conn_handle, + &p_auth_params); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gatts_rw_authorize_reply(conn_handle, p_auth_params); + + err_code = ble_gatts_rw_authorize_reply_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gatts_sys_attr_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t conn_handle; + + uint8_t sys_attr[BLE_GATTS_VAR_ATTR_LEN_MAX]; + + uint8_t * p_sys_attr = sys_attr; + uint16_t sys_attr_len = sizeof (sys_attr); + + uint32_t flags; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gatts_sys_attr_set_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_sys_attr, + &sys_attr_len, &flags); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gatts_sys_attr_set(conn_handle, p_sys_attr, sys_attr_len, flags); + + err_code = ble_gatts_sys_attr_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gatts_sys_attr_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t conn_handle; + + uint8_t sys_attr[BLE_GATTS_VAR_ATTR_LEN_MAX]; + + uint8_t * p_sys_attr = sys_attr; + uint16_t sys_attr_len = sizeof (sys_attr); + uint16_t * p_sys_attr_len = &sys_attr_len; + + uint32_t flags; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gatts_sys_attr_get_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_sys_attr, + &p_sys_attr_len, &flags); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gatts_sys_attr_get(conn_handle, p_sys_attr, p_sys_attr_len, flags); + + err_code = ble_gatts_sys_attr_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_sys_attr, + p_sys_attr_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gatts_attr_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t handle; + + ble_gatts_attr_md_t md; + ble_gatts_attr_md_t * p_md = &md; + ble_uuid_t uuid; + ble_uuid_t * p_uuid = &uuid; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gatts_attr_get_req_dec(p_rx_buf, rx_buf_len, &handle, &p_uuid, &p_md); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gatts_attr_get(handle, p_uuid, p_md); + + err_code = ble_gatts_attr_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_uuid, p_md); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gatts_initial_user_handle_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t handle; + uint16_t * p_handle = &handle; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gatts_initial_user_handle_get_req_dec(p_rx_buf, rx_buf_len, &p_handle); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gatts_initial_user_handle_get(p_handle); + + err_code = ble_gatts_initial_user_handle_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_handle); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_gatts_exchange_mtu_reply(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t conn_handle; + uint16_t * p_conn_handle = &conn_handle; + uint16_t server_rx_mtu; + uint16_t * p_server_rx_mtu = &server_rx_mtu; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_gatts_exchange_mtu_reply_req_dec(p_rx_buf, rx_buf_len, p_conn_handle, p_server_rx_mtu); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_gatts_exchange_mtu_reply(conn_handle, server_rx_mtu); + + err_code = ble_gatts_exchange_mtu_reply_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble_gatts.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble_gatts.h new file mode 100644 index 0000000..d10609c --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble_gatts.h @@ -0,0 +1,314 @@ +/** + * 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 _CONN_MW_BLE_GATTS_H +#define _CONN_MW_BLE_GATTS_H + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup sercon_mw_s132_ble_gatts GATTS Middleware command handlers + * @{ + * @ingroup sercon_mw_s132 + */ + +/**@brief Handles @ref sd_ble_gatts_service_add command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gatts_service_add (uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ble_gatts_characteristic_add command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gatts_characteristic_add(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref conn_mw_ble_gatts_include_add command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gatts_include_add (uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref conn_mw_ble_gatts_descriptor_add command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gatts_descriptor_add(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref conn_mw_ble_gatts_value_set command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gatts_value_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref conn_mw_ble_gatts_value_get command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gatts_value_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref conn_mw_ble_gatts_hvx command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gatts_hvx(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref conn_mw_ble_gatts_service_changed command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gatts_service_changed(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref conn_mw_ble_gatts_rw_authorize_reply command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gatts_rw_authorize_reply(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref conn_mw_ble_gatts_sys_attr_set command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gatts_sys_attr_set(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref conn_mw_ble_gatts_sys_attr_get command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gatts_sys_attr_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref conn_mw_ble_gatts_attr_get command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gatts_attr_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref conn_mw_ble_gatts_initial_user_handle_get command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gatts_initial_user_handle_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref conn_mw_ble_gatts_exchange_mtu_reply command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_gatts_exchange_mtu_reply(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif //_CONN_MW_BLE_GATTS_H + diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble_l2cap.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble_l2cap.c new file mode 100644 index 0000000..8a88ceb --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble_l2cap.c @@ -0,0 +1,260 @@ +/** + * 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_l2cap_conn.h" +#include "conn_mw_ble_l2cap.h" +#include "ble_serialization.h" + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t conn_mw_ble_l2cap_cid_register(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t cid; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_l2cap_cid_register_req_dec(p_rx_buf, rx_buf_len, &cid); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_l2cap_cid_register(cid); + + err_code = ble_l2cap_cid_register_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_l2cap_cid_unregister(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t cid; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ble_l2cap_cid_unregister_req_dec(p_rx_buf, rx_buf_len, &cid); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_l2cap_cid_unregister(cid); + + err_code = ble_l2cap_cid_unregister_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ble_l2cap_tx(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t conn_handle; + ble_l2cap_header_t l2cap_header; + ble_l2cap_header_t * p_l2cap_header = &l2cap_header; + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + uint8_t const * p_data = NULL; + + err_code = ble_l2cap_tx_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_l2cap_header, &p_data); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_l2cap_tx(conn_handle, p_l2cap_header, p_data); + + err_code = ble_l2cap_tx_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} +#endif + +#if NRF_SD_BLE_API_VERSION >= 5 +uint32_t conn_mw_l2cap_ch_setup(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t conn_handle; + uint16_t local_cid; + uint16_t * p_local_cid = &local_cid; + ble_l2cap_ch_setup_params_t params; + ble_l2cap_ch_setup_params_t * p_params = ¶ms; + uint32_t sd_err_code; + uint32_t err_code = NRF_SUCCESS; + + err_code = ble_l2cap_ch_setup_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &p_local_cid, &p_params); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_l2cap_ch_setup(conn_handle, p_local_cid, p_params); + + err_code = ble_l2cap_ch_setup_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_local_cid); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_l2cap_ch_release(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t conn_handle; + uint16_t local_cid; + uint32_t sd_err_code; + uint32_t err_code = NRF_SUCCESS; + + err_code = ble_l2cap_ch_release_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &local_cid); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_l2cap_ch_release(conn_handle, local_cid); + + err_code = ble_l2cap_ch_release_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_l2cap_ch_rx(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t conn_handle; + uint16_t local_cid; + ble_data_t ble_data; + ble_data_t * p_ble_data = &ble_data; + uint32_t sd_err_code; + uint32_t err_code = NRF_SUCCESS; + + err_code = ble_l2cap_ch_rx_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &local_cid, &p_ble_data); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_l2cap_ch_rx(conn_handle, local_cid, p_ble_data); + + err_code = ble_l2cap_ch_rx_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_l2cap_ch_tx(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t conn_handle; + uint16_t local_cid; + ble_data_t ble_data; + ble_data_t * p_ble_data = &ble_data; + uint32_t sd_err_code; + uint32_t err_code = NRF_SUCCESS; + + err_code = ble_l2cap_ch_tx_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &local_cid, &p_ble_data); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_l2cap_ch_tx(conn_handle, local_cid, p_ble_data); + + err_code = ble_l2cap_ch_tx_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_l2cap_ch_flow_control(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint16_t conn_handle; + uint16_t local_cid; + uint16_t credits; + uint16_t out_credits; + uint16_t * p_out_credits = &out_credits; + uint32_t sd_err_code; + uint32_t err_code = NRF_SUCCESS; + + err_code = ble_l2cap_ch_flow_control_req_dec(p_rx_buf, rx_buf_len, + &conn_handle, &local_cid, &credits, &p_out_credits); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ble_l2cap_ch_flow_control(conn_handle, local_cid, credits, p_out_credits); + + err_code = ble_l2cap_ch_flow_control_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_out_credits); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble_l2cap.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble_l2cap.h new file mode 100644 index 0000000..76e2149 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/middleware/conn_mw_ble_l2cap.h @@ -0,0 +1,206 @@ +/** + * 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 _CONN_MW_BLE_L2CAP_H_ +#define _CONN_MW_BLE_L2CAP_H_ + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup sercon_mw_s132_ble_l2cap L2CAP Middleware command handlers + * @{ + * @ingroup sercon_mw_s132 + */ + +/**@brief Handles sd_ble_l2cap_cid_register command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_l2cap_cid_register(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles sd_ble_l2cap_cid_unregister command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_l2cap_cid_unregister(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles sd_ble_l2cap_tx command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_ble_l2cap_tx(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + + +/**@brief Handles sd_ble_l2cap_ch_setup command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_l2cap_ch_setup(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles sd_ble_l2cap_ch_release command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_l2cap_ch_release(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles sd_ble_l2cap_ch_rx command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_l2cap_ch_rx(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles sd_ble_l2cap_ch_tx command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_l2cap_ch_tx(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles sd_ble_l2cap_ch_flow_control command and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + */ +uint32_t conn_mw_l2cap_ch_flow_control(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_conn.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_conn.c new file mode 100644 index 0000000..a952886 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_conn.c @@ -0,0 +1,558 @@ +/** + * 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_conn.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ble_struct_serialization.h" +#include "ble_gap_struct_serialization.h" +#include "ble_gatt_struct_serialization.h" +#include "ble_gattc_struct_serialization.h" +#include "ble_gatts_struct_serialization.h" +#include "ble_l2cap_struct_serialization.h" +#include "app_util.h" + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t ble_enable_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_enable_params_t * * const pp_ble_enable_params) +{ + SER_REQ_DEC_BEGIN(SD_BLE_ENABLE); + SER_PULL_COND(pp_ble_enable_params, ble_enable_params_t_dec); + SER_REQ_DEC_END; +} +#else +uint32_t ble_enable_req_dec(uint8_t const * const p_buf, + uint32_t packet_len) +{ + SER_REQ_DEC_BEGIN(SD_BLE_ENABLE); + SER_REQ_DEC_END; +} +#endif + +uint32_t ble_enable_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_ENABLE); +} + + +uint32_t ble_opt_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint32_t * const p_opt_id, + ble_opt_t **const pp_opt ) +{ + SER_REQ_DEC_BEGIN(SD_BLE_OPT_GET); + + SER_ASSERT_NOT_NULL(p_opt_id); + SER_ASSERT_NOT_NULL(pp_opt); + SER_ASSERT_NOT_NULL(*pp_opt); + + SER_PULL_uint32(p_opt_id); + + SER_PULL_COND(pp_opt, NULL); + + SER_REQ_DEC_END; +} + + +uint32_t ble_opt_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint32_t opt_id, + ble_opt_t const * const p_opt) +{ + SER_RSP_ENC_BEGIN(SD_BLE_OPT_GET); + + SER_ASSERT_NOT_NULL(p_opt); + + SER_PUSH_uint32(&opt_id); + + field_encoder_handler_t fp_encoder = NULL; + void const * p_struct = NULL; + + switch (opt_id) + { +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 + case BLE_COMMON_OPT_CONN_BW: + fp_encoder = ble_common_opt_conn_bw_t_enc; + p_struct = &p_opt->common_opt.conn_bw; + break; +#endif + case BLE_COMMON_OPT_PA_LNA: + fp_encoder = ble_common_opt_pa_lna_t_enc; + p_struct = &p_opt->common_opt.pa_lna; + break; + case BLE_COMMON_OPT_CONN_EVT_EXT: + fp_encoder = ble_common_opt_conn_evt_ext_t_enc; + p_struct = &p_opt->common_opt.conn_evt_ext; + break; + case BLE_GAP_OPT_CH_MAP: + fp_encoder = ble_gap_opt_ch_map_t_enc; + p_struct = &p_opt->gap_opt.ch_map; + break; + case BLE_GAP_OPT_LOCAL_CONN_LATENCY: + fp_encoder = ble_gap_opt_local_conn_latency_t_enc; + p_struct = &p_opt->gap_opt.local_conn_latency; + break; + case BLE_GAP_OPT_PASSKEY: + fp_encoder = ble_gap_opt_passkey_t_enc; + p_struct = &p_opt->gap_opt.passkey; + break; + case BLE_GAP_OPT_AUTH_PAYLOAD_TIMEOUT: + fp_encoder = ble_gap_opt_auth_payload_timeout_t_enc; + p_struct = &p_opt->gap_opt.auth_payload_timeout; + break; +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 + case BLE_GAP_OPT_EXT_LEN: + fp_encoder = ble_gap_opt_ext_len_t_enc; + p_struct = &p_opt->gap_opt.ext_len; + break; +#endif +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 6 + case BLE_GAP_OPT_SCAN_REQ_REPORT: + fp_encoder = ble_gap_opt_scan_req_report_t_enc; + p_struct = &p_opt->gap_opt.scan_req_report; + break; +#endif +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 + case BLE_GAP_OPT_COMPAT_MODE: + fp_encoder = ble_gap_opt_compat_mode_t_enc; + p_struct = &p_opt->gap_opt.compat_mode; + break; +#else +#ifndef S112 + case BLE_GAP_OPT_COMPAT_MODE_1: + fp_encoder = ble_gap_opt_compat_mode_1_t_enc; + p_struct = &p_opt->gap_opt.compat_mode_1; + break; +#endif +#endif +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION == 4 + case BLE_GAP_OPT_COMPAT_MODE_2: + fp_encoder = ble_gap_opt_compat_mode_2_t_enc; + p_struct = &p_opt->gap_opt.compat_mode_2; + break; +#endif + default: + SER_ASSERT(NRF_ERROR_INVALID_PARAM, NRF_ERROR_INVALID_PARAM); + break; + } + + SER_PUSH_FIELD(p_struct, fp_encoder); + + SER_RSP_ENC_END; +} + + +uint32_t ble_opt_set_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint32_t * const p_opt_id, + ble_opt_t **const pp_opt ) +{ + SER_REQ_DEC_BEGIN(SD_BLE_OPT_SET); + + SER_ASSERT_NOT_NULL(p_opt_id); + SER_ASSERT_NOT_NULL(pp_opt); + SER_ASSERT_NOT_NULL(*pp_opt); + + SER_PULL_uint32(p_opt_id); + + SER_PULL_COND(pp_opt, NULL); + if (*pp_opt) + { + field_decoder_handler_t fp_decoder = NULL; + void * p_struct = NULL; + + switch (*p_opt_id) + { +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 + case BLE_COMMON_OPT_CONN_BW: + fp_decoder = ble_common_opt_conn_bw_t_dec; + p_struct = &((*pp_opt)->common_opt.conn_bw); + break; +#endif + case BLE_COMMON_OPT_PA_LNA: + fp_decoder = ble_common_opt_pa_lna_t_dec; + p_struct = &((*pp_opt)->common_opt.pa_lna); + break; + case BLE_COMMON_OPT_CONN_EVT_EXT: + fp_decoder = ble_common_opt_conn_evt_ext_t_dec; + p_struct = &((*pp_opt)->common_opt.conn_evt_ext); + break; + case BLE_GAP_OPT_CH_MAP: + fp_decoder = ble_gap_opt_ch_map_t_dec; + p_struct = &((*pp_opt)->gap_opt.ch_map); + break; + case BLE_GAP_OPT_LOCAL_CONN_LATENCY: + fp_decoder = ble_gap_opt_local_conn_latency_t_dec; + p_struct = &((*pp_opt)->gap_opt.local_conn_latency); + break; + case BLE_GAP_OPT_PASSKEY: + fp_decoder = ble_gap_opt_passkey_t_dec; + p_struct = &((*pp_opt)->gap_opt.passkey); + break; + case BLE_GAP_OPT_AUTH_PAYLOAD_TIMEOUT: + fp_decoder = ble_gap_opt_auth_payload_timeout_t_dec; + p_struct = &((*pp_opt)->gap_opt.auth_payload_timeout); + break; +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 + case BLE_GAP_OPT_EXT_LEN: + fp_decoder = ble_gap_opt_ext_len_t_dec; + p_struct = &((*pp_opt)->gap_opt.ext_len); + break; +#endif +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 6 + case BLE_GAP_OPT_SCAN_REQ_REPORT: + fp_decoder = ble_gap_opt_scan_req_report_t_dec; + p_struct = &((*pp_opt)->gap_opt.scan_req_report); + break; +#endif +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 + case BLE_GAP_OPT_COMPAT_MODE: + fp_decoder = ble_gap_opt_compat_mode_t_dec; + p_struct = &((*pp_opt)->gap_opt.compat_mode); + break; +#else +#ifndef S112 + case BLE_GAP_OPT_COMPAT_MODE_1: + fp_decoder = ble_gap_opt_compat_mode_1_t_dec; + p_struct = &((*pp_opt)->gap_opt.compat_mode_1); + break; +#endif + case BLE_GAP_OPT_SLAVE_LATENCY_DISABLE: + fp_decoder = ble_gap_opt_slave_latency_disable_t_dec; + p_struct = &((*pp_opt)->gap_opt.slave_latency_disable); + break; +#endif +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION == 4 + case BLE_GAP_OPT_COMPAT_MODE_2: + fp_decoder = ble_gap_opt_compat_mode_2_t_dec; + p_struct = &((*pp_opt)->gap_opt.compat_mode_2); + break; +#endif + default: + SER_ASSERT(NRF_ERROR_INVALID_PARAM,NRF_ERROR_INVALID_PARAM); + break; + } + + SER_PULL_FIELD(p_struct, fp_decoder); + } + + SER_REQ_DEC_END; +} + + +uint32_t ble_opt_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_OPT_SET); +} + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t ble_tx_packet_count_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_conn_handle, + uint8_t * * const pp_count) +{ + SER_REQ_DEC_BEGIN(SD_BLE_TX_PACKET_COUNT_GET); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_COND(pp_count, NULL); + + SER_REQ_DEC_END; +} + + +uint32_t ble_tx_packet_count_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint8_t const * const p_count) +{ + SER_RSP_ENC_BEGIN(SD_BLE_TX_PACKET_COUNT_GET); + SER_PUSH_COND(p_count, uint8_t_enc); + SER_RSP_ENC_END; +} +#endif + +uint32_t ble_user_mem_reply_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_conn_handle, + ble_user_mem_block_t * * const pp_mem_block) +{ + SER_REQ_DEC_BEGIN(SD_BLE_USER_MEM_REPLY); + + SER_ASSERT_NOT_NULL(p_conn_handle); + SER_ASSERT_NOT_NULL(pp_mem_block); + SER_ASSERT_NOT_NULL(*pp_mem_block); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_COND(pp_mem_block, ble_user_mem_block_t_dec); + + SER_REQ_DEC_END; +} + + +uint32_t ble_user_mem_reply_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_USER_MEM_REPLY); +} + +uint32_t ble_uuid_decode_req_dec(uint8_t const * const p_buf, + uint32_t const packet_len, + uint8_t * p_uuid_le_len, + uint8_t * * const pp_uuid_le, + ble_uuid_t * * const pp_uuid) +{ + SER_REQ_DEC_BEGIN(SD_BLE_UUID_DECODE); + + SER_PULL_len8data(pp_uuid_le, p_uuid_le_len); + SER_PULL_COND(pp_uuid, NULL); + + SER_REQ_DEC_END; +} + +uint32_t ble_uuid_decode_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + ble_uuid_t const * const p_uuid) +{ + SER_RSP_ENC_BEGIN(SD_BLE_UUID_DECODE); + SER_PUSH_COND(p_uuid, ble_uuid_t_enc); + SER_RSP_ENC_END; +} + +uint32_t ble_uuid_encode_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + ble_uuid_t * * const pp_uuid, + uint8_t * * const pp_uuid_le_len, + uint8_t * * const pp_uuid_le) +{ + SER_REQ_DEC_BEGIN(SD_BLE_UUID_ENCODE); + + SER_ASSERT_NOT_NULL(pp_uuid); + SER_ASSERT_NOT_NULL(pp_uuid_le_len); + SER_ASSERT_NOT_NULL(pp_uuid_le); + SER_ASSERT_NOT_NULL(*pp_uuid); + SER_ASSERT_NOT_NULL(*pp_uuid_le_len); + SER_ASSERT_NOT_NULL(*pp_uuid_le); + + SER_PULL_COND(pp_uuid, ble_uuid_t_dec); + SER_PULL_COND(pp_uuid_le_len, NULL); + SER_PULL_COND(pp_uuid_le, NULL); + + SER_REQ_DEC_END; +} + + +uint32_t ble_uuid_encode_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint8_t uuid_le_len, + uint8_t const * const p_uuid_le) +{ + SER_RSP_ENC_BEGIN(SD_BLE_UUID_ENCODE); + + SER_PUSH_uint8(&uuid_le_len); + if (p_uuid_le != NULL) + { + SER_PUSH_uint8array(p_uuid_le, uuid_le_len); + } + + SER_RSP_ENC_END; +} + +uint32_t ble_uuid_vs_add_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + ble_uuid128_t * * const pp_uuid, + uint8_t * * const pp_uuid_type) +{ + SER_REQ_DEC_BEGIN(SD_BLE_UUID_VS_ADD); + + SER_ASSERT_NOT_NULL(pp_uuid); + SER_ASSERT_NOT_NULL(pp_uuid_type); + SER_ASSERT_NOT_NULL(*pp_uuid); + SER_ASSERT_NOT_NULL(*pp_uuid_type); + + SER_PULL_COND(pp_uuid, ble_uuid128_t_dec); + SER_PULL_COND(pp_uuid_type, NULL); + + SER_REQ_DEC_END; +} + + +uint32_t ble_uuid_vs_add_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint8_t const * const p_uuid_type) +{ + SER_RSP_ENC_BEGIN(SD_BLE_UUID_VS_ADD); + SER_PUSH_COND(p_uuid_type, uint8_t_enc); + SER_RSP_ENC_END; +} + +uint32_t ble_version_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + ble_version_t * * const pp_version) +{ + SER_REQ_DEC_BEGIN(SD_BLE_VERSION_GET); + + SER_ASSERT_NOT_NULL(pp_version); + SER_ASSERT_NOT_NULL(*pp_version); + + SER_PULL_COND(pp_version, NULL); + + SER_REQ_DEC_END; +} + + +uint32_t ble_version_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + ble_version_t const * const p_version) +{ + SER_RSP_ENC_BEGIN(SD_BLE_VERSION_GET); + SER_PUSH_FIELD(p_version, ble_version_t_enc); + SER_RSP_ENC_END; +} + + + +uint32_t ble_opt_id_pre_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint32_t * const p_opt_id) +{ + SER_REQ_DEC_BEGIN(SD_BLE_OPT_SET); + + SER_ASSERT_NOT_NULL(p_opt_id); + SER_PULL_uint32(p_opt_id); + + // Pre-decoding; do not check if the whole packet was processed. + return NRF_SUCCESS; +} +#if NRF_SD_BLE_API_VERSION >= 4 + +uint32_t ble_cfg_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * p_cfg_id, + ble_cfg_t * * const pp_cfg) +{ + SER_REQ_DEC_BEGIN(SD_BLE_CFG_SET); + SER_PULL_uint32(p_cfg_id); + SER_PULL_COND(pp_cfg, NULL); + + if (*pp_cfg) + { + + field_decoder_handler_t fp_decoder = NULL; + void * p_struct = NULL; + + switch (*p_cfg_id) + { + case BLE_CONN_CFG_GAP: + fp_decoder = ble_gap_conn_cfg_t_dec; + p_struct = &((*pp_cfg)->conn_cfg.params.gap_conn_cfg); + break; + case BLE_CONN_CFG_GATTC: + fp_decoder = ble_gattc_conn_cfg_t_dec; + p_struct = &((*pp_cfg)->conn_cfg.params.gattc_conn_cfg); + break; + case BLE_CONN_CFG_GATTS: + fp_decoder = ble_gatts_conn_cfg_t_dec; + p_struct = &((*pp_cfg)->conn_cfg.params.gatts_conn_cfg); + break; + case BLE_CONN_CFG_GATT: + fp_decoder = ble_gatt_conn_cfg_t_dec; + p_struct = &((*pp_cfg)->conn_cfg.params.gatt_conn_cfg); + break; +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION >= 5 && !defined(S112) + case BLE_CONN_CFG_L2CAP: + fp_decoder = ble_l2cap_conn_cfg_t_dec; + p_struct = &((*pp_cfg)->conn_cfg.params.l2cap_conn_cfg); + break; +#endif + case BLE_COMMON_CFG_VS_UUID: + fp_decoder = ble_common_cfg_vs_uuid_t_dec; + p_struct = &((*pp_cfg)->common_cfg.vs_uuid_cfg); + break; + case BLE_GAP_CFG_ROLE_COUNT: + fp_decoder = ble_gap_cfg_role_count_t_dec; + p_struct = &((*pp_cfg)->gap_cfg.role_count_cfg); + break; + case BLE_GAP_CFG_DEVICE_NAME: + fp_decoder = ble_gap_cfg_device_name_t_dec; + p_struct = &((*pp_cfg)->gap_cfg.device_name_cfg); + break; + case BLE_GATTS_CFG_SERVICE_CHANGED: + fp_decoder = ble_gatts_cfg_service_changed_t_dec; + p_struct = &((*pp_cfg)->gatts_cfg.service_changed); + break; + case BLE_GATTS_CFG_ATTR_TAB_SIZE: + fp_decoder = ble_gatts_cfg_attr_tab_size_t_dec; + p_struct = &((*pp_cfg)->gatts_cfg.attr_tab_size); + break; + default: + SER_ASSERT(NRF_ERROR_INVALID_PARAM,NRF_ERROR_INVALID_PARAM); + break; + } + + if (*p_cfg_id >= BLE_CONN_CFG_BASE && *p_cfg_id <= BLE_CONN_CFG_GATT) + { + SER_PULL_uint8(&(*pp_cfg)->conn_cfg.conn_cfg_tag); + } + SER_PULL_FIELD(p_struct, fp_decoder); + } + SER_REQ_DEC_END; +} + + + +uint32_t ble_cfg_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_CFG_SET); +} + +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_conn.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_conn.h new file mode 100644 index 0000000..bcf4c73 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_conn.h @@ -0,0 +1,521 @@ +/** + * 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_CONN_H__ +#define BLE_CONN_H__ + +/** + * @addtogroup ser_conn_s130_codecs Connectivity codecs for S132 and S140 + * @ingroup ser_codecs_conn + */ + +/**@file + * + * @defgroup ble_conn Connectivity command request decoders and command response encoders + * @{ + * @ingroup ser_conn_s130_codecs + * + * @brief Connectivity command request decoders and command response encoders. + */ +#include "ble.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +/**@brief Decodes @ref sd_ble_tx_packet_count_get command request. + * + * @sa @ref ble_tx_packet_count_get_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_handle Pointer to connection handle. + * @param[out] pp_count Pointer to pointer to location for count. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_tx_packet_count_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_conn_handle, + uint8_t * * const pp_count); + +/**@brief Encodes @ref sd_ble_tx_packet_count_get command response. + * + * @sa @ref ble_tx_packet_count_get_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_count Pointer to count value. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_tx_packet_count_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint8_t const * const p_count); +#endif + +/**@brief Event encoding dispatcher. + * + * The event encoding dispatcher will route the event packet to the correct encoder which in turn + * encodes the contents of the event and updates the \p p_buf buffer. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + * @retval NRF_ERROR_NOT_SUPPORTED Event encoder is not implemented. + */ +uint32_t ble_event_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_version_get command request. + * + * @sa @ref ble_version_get_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] pp_version Pointer to pointer to @ref ble_version_t address. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_version_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + ble_version_t * * const pp_version); + +/**@brief Encodes @ref sd_ble_version_get command response. + * + * @sa @ref ble_version_get_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_version Pointer to @ref ble_version_t address. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_version_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + ble_version_t const * const p_version); + + +/**@brief Decodes @ref sd_ble_opt_get command request. + * + * @sa @ref ble_opt_get_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_opt_id Pointer to pointer to @ref ble_version_t address. + * @param[out] pp_opt Pointer to pointer to @ref ble_opt_t address. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_opt_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint32_t * const p_opt_id, + ble_opt_t **const pp_opt ); + + +/**@brief Encodes @ref sd_ble_opt_get command response. + * + * @sa @ref ble_opt_get_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] opt_id identifies type of ble_opt_t union + * @param[in] p_opt Pointer to @ref ble_opt_t union. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ + +uint32_t ble_opt_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint32_t opt_id, + ble_opt_t const * const p_opt); + + +/**@brief Decodes @ref sd_ble_opt_set command request. + * + * @sa @ref ble_opt_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_opt_id Pointer to @ref ble_opt_t union type identifier. + * @param[out] pp_opt Pointer to pointer to @ref ble_opt_t union. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_opt_set_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint32_t * const p_opt_id, + ble_opt_t **const pp_opt ); + + +/**@brief Encodes @ref sd_ble_opt_set command response. + * + * @sa @ref ble_opt_set_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ + +uint32_t ble_opt_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + + +/**@brief Decodes @ref sd_ble_uuid_encode command request. + * + * @sa @ref ble_uuid_encode_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] pp_uuid Pointer to pointer to @ref ble_uuid_t structure. + * @param[out] pp_uuid_le_len Pointer to pointer to the length of encoded UUID. + * @param[out] pp_uuid_le Pointer to pointer to buffer where encoded UUID will be stored. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_uuid_encode_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + ble_uuid_t * * const pp_uuid, + uint8_t * * const pp_uuid_le_len, + uint8_t * * const pp_uuid_le); + +/**@brief Encodes @ref sd_ble_uuid_encode command response. + * + * @sa @ref ble_uuid_encode_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] uuid_le_len Length of the encoded UUID. + * @param[in] p_uuid_le Pointer to the buffer with encoded UUID. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_uuid_encode_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint8_t uuid_le_len, + uint8_t const * const p_uuid_le); + +/**@brief Decodes @ref sd_ble_uuid_decode command request. + * + * @sa @ref ble_uuid_decode_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_uuid_le_len Pointer to the length of encoded UUID. + * @param[out] pp_uuid_le Pointer to pointer to buffer where encoded UUID will be stored. + * @param[out] pp_uuid Pointer to pointer to @ref ble_uuid_t structure. + * \c It will be set to NULL if p_uuid is not present in the packet. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ble_uuid_decode_req_dec(uint8_t const * const p_buf, + uint32_t const packet_len, + uint8_t * p_uuid_le_len, + uint8_t * * const pp_uuid_le, + ble_uuid_t * * const pp_uuid); + +/**@brief Encodes @ref sd_ble_uuid_decode command response. + * + * @sa @ref ble_uuid_decode_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_uuid Pointer to the buffer with encoded UUID. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_uuid_decode_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + ble_uuid_t const * const p_uuid); + +/**@brief Decodes @ref sd_ble_uuid_vs_add command request. + * + * @sa @ref ble_uuid_vs_add_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] pp_uuid Pointer to pointer to UUID. + * \c It will be set to NULL if p_uuid is not present in the packet. + * @param[out] pp_uuid_type Pointer to pointer to UUID type. + * \c It will be set to NULL if p_uuid_type is not present in the packet. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ble_uuid_vs_add_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + ble_uuid128_t * * const pp_uuid, + uint8_t * * const pp_uuid_type); + +/**@brief Encodes @ref sd_ble_uuid_vs_add command response. + * + * @sa @ref ble_uuid_vs_add_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_uuid_type Pointer to the UUID type. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_uuid_vs_add_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint8_t const * const p_uuid_type); + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +/**@brief Decodes @ref sd_ble_enable command request. + * + * @sa @ref ble_enable_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] pp_ble_enable_params Pointer to pointer to ble_enable_params_t. + * \c It will be set to NULL if p_ble_enable_params is not present in the packet. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ble_enable_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_enable_params_t * * const pp_ble_enable_params); +#else +/**@brief Decodes @ref sd_ble_enable command request. + * + * @sa @ref ble_enable_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ble_enable_req_dec(uint8_t const * const p_buf, + uint32_t packet_len); + +#endif +/**@brief Encodes @ref sd_ble_enable command response. + * + * @sa @ref ble_enable_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_enable_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Pre-decodes opt_id of @ref ble_opt_t for middleware. + * + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] packet_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in,out] p_opt_id Pointer to opt_id which identifies type of @ref ble_opt_t union. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_opt_id_pre_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint32_t * const p_opt_id); + +/**@brief Decodes @ref sd_ble_user_mem_reply command request. + * + * @sa @ref ble_user_mem_reply_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[in] p_conn_handle Pointer to Connection Handle. + * @param[in,out] pp_block Pointer to pointer to ble_user_mem_block_t. + * \c It will be set to NULL if p_block is not present in the packet. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ble_user_mem_reply_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_conn_handle, + ble_user_mem_block_t * * const pp_block); + +/**@brief Encodes @ref sd_ble_user_mem_reply command response. + * + * @sa @ref ble_user_mem_reply_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_user_mem_reply_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +#if NRF_SD_BLE_API_VERSION >= 4 +/**@brief Decodes @ref sd_ble_cfg_set command request. + * + * @sa @ref ble_cfg_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[in] p_cfg_id Pointer to ConfigurationId. + * @param[in,out] pp_cfg Pointer to pointer to configuration struct. + * \c It will be set to NULL if p_block is not present in the packet. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ble_cfg_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * p_cfg_id, + ble_cfg_t * * const pp_cfg); + +/**@brief Encodes @ref sd_ble_cfg_set command response. + * + * @sa @ref ble_cfg_set_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_cfg_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +#endif + +/** @} */ + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_event_enc.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_event_enc.c new file mode 100644 index 0000000..ff075f1 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_event_enc.c @@ -0,0 +1,295 @@ +/** + * 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_conn.h" +#include "ble_evt_conn.h" +#include "ble_gap_evt_conn.h" +#include "ble_gattc_evt_conn.h" +#include "ble_gatts_evt_conn.h" +#include "ble_l2cap_evt_conn.h" +#include "ble_serialization.h" +#include "app_util.h" +#include "nrf_log.h" + +uint32_t ble_event_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t ret_val = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + SER_ASSERT_NOT_NULL(p_event); + + switch (p_event->header.evt_id) + { +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 + case BLE_EVT_TX_COMPLETE: + ret_val = ble_evt_tx_complete_enc(p_event, event_len, p_buf, p_buf_len); + break; +#endif + case BLE_EVT_USER_MEM_RELEASE: + ret_val = ble_evt_user_mem_release_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_EVT_USER_MEM_REQUEST: + ret_val = ble_evt_user_mem_request_enc(p_event, event_len, p_buf, p_buf_len); + break; +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 + case BLE_EVT_DATA_LENGTH_CHANGED: + ret_val = ble_evt_data_length_changed_enc(p_event, event_len, p_buf, p_buf_len); + break; +#endif + + case BLE_GAP_EVT_CONN_PARAM_UPDATE: + ret_val = ble_gap_evt_conn_param_update_enc(p_event, event_len, p_buf, p_buf_len); + break; +#ifndef S112 + case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST: + ret_val = ble_gap_evt_conn_param_update_request_enc(p_event, event_len, p_buf, p_buf_len); + break; +#endif //!S112 + case BLE_GAP_EVT_SEC_PARAMS_REQUEST: + ret_val = ble_gap_evt_sec_params_request_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_GAP_EVT_SEC_INFO_REQUEST: + ret_val = ble_gap_evt_sec_info_request_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_GAP_EVT_AUTH_STATUS: + ret_val = ble_gap_evt_auth_status_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_GAP_EVT_PASSKEY_DISPLAY: + ret_val = ble_gap_evt_passkey_display_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_GAP_EVT_AUTH_KEY_REQUEST: + ret_val = ble_gap_evt_auth_key_request_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_GAP_EVT_CONN_SEC_UPDATE: + ret_val = ble_gap_evt_conn_sec_update_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_GAP_EVT_RSSI_CHANGED: + ret_val = ble_gap_evt_rssi_changed_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_GAP_EVT_TIMEOUT: + ret_val = ble_gap_evt_timeout_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_GAP_EVT_DISCONNECTED: + ret_val = ble_gap_evt_disconnected_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_GAP_EVT_CONNECTED: + ret_val = ble_gap_evt_connected_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_GAP_EVT_SEC_REQUEST: + ret_val = ble_gap_evt_sec_request_enc(p_event, event_len, p_buf, p_buf_len); + break; + case BLE_GAP_EVT_KEY_PRESSED: + ret_val = ble_gap_evt_key_pressed_enc(p_event, event_len, p_buf, p_buf_len); + break; + case BLE_GAP_EVT_LESC_DHKEY_REQUEST: + ret_val = ble_gap_evt_lesc_dhkey_request_enc(p_event, event_len, p_buf, p_buf_len); + break; +#if NRF_SD_BLE_API_VERSION >= 5 + case BLE_GAP_EVT_PHY_UPDATE: + ret_val = ble_gap_evt_phy_update_enc(p_event, event_len, p_buf, p_buf_len); + break; + case BLE_GAP_EVT_PHY_UPDATE_REQUEST: + ret_val = ble_gap_evt_phy_update_request_enc(p_event, event_len, p_buf, p_buf_len); + break; +#endif +#if NRF_SD_BLE_API_VERSION >= 4 && !defined(S112) + case BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST: + ret_val = ble_gap_evt_data_length_update_request_enc(p_event, event_len, p_buf, p_buf_len); + break; + case BLE_GAP_EVT_DATA_LENGTH_UPDATE: + ret_val = ble_gap_evt_data_length_update_enc(p_event, event_len, p_buf, p_buf_len); + break; +#endif //NRF_SD_BLE_API_VERSION >= 4 && !defined(S112) + case BLE_GATTC_EVT_CHAR_DISC_RSP: + ret_val = ble_gattc_evt_char_disc_rsp_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_GATTC_EVT_DESC_DISC_RSP: + ret_val = ble_gattc_evt_desc_disc_rsp_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP: + ret_val = ble_gattc_evt_char_val_by_uuid_read_rsp_enc(p_event, + event_len, + p_buf, + p_buf_len); + break; + + case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP: + ret_val = ble_gattc_evt_prim_srvc_disc_rsp_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_GATTC_EVT_HVX: + ret_val = ble_gattc_evt_hvx_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_GATTC_EVT_READ_RSP: + ret_val = ble_gattc_evt_read_rsp_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_GATTC_EVT_TIMEOUT: + ret_val = ble_gattc_evt_timeout_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_GATTC_EVT_WRITE_RSP: + ret_val = ble_gattc_evt_write_rsp_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_GATTC_EVT_REL_DISC_RSP: + ret_val = ble_gattc_evt_rel_disc_rsp_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_GATTC_EVT_CHAR_VALS_READ_RSP: + ret_val = ble_gattc_evt_char_vals_read_rsp_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_GATTC_EVT_ATTR_INFO_DISC_RSP: + ret_val = ble_gattc_evt_attr_info_disc_rsp_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_GATTC_EVT_EXCHANGE_MTU_RSP: + ret_val = ble_gattc_evt_exchange_mtu_rsp_enc(p_event, event_len, p_buf, p_buf_len); + break; +#if NRF_SD_BLE_API_VERSION >= 4 + case BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE: + ret_val = ble_gattc_evt_write_cmd_tx_complete_enc(p_event, event_len, p_buf, p_buf_len); + break; +#endif + + case BLE_GATTS_EVT_HVC: + ret_val = ble_gatts_evt_hvc_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_GATTS_EVT_TIMEOUT: + ret_val = ble_gatts_evt_timeout_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_GATTS_EVT_SC_CONFIRM: + ret_val = ble_gatts_evt_sc_confirm_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_GATTS_EVT_WRITE: + ret_val = ble_gatts_evt_write_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST: + ret_val = ble_gatts_evt_rw_authorize_request_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_GATTS_EVT_SYS_ATTR_MISSING: + ret_val = ble_gatts_evt_sys_attr_missing_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST: + ret_val = ble_gatts_evt_exchange_mtu_request_enc(p_event, event_len, p_buf, p_buf_len); + break; +#if NRF_SD_BLE_API_VERSION >= 4 + case BLE_GATTS_EVT_HVN_TX_COMPLETE: + ret_val = ble_gatts_evt_hvn_tx_complete_enc(p_event, event_len, p_buf, p_buf_len); + break; +#endif +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 + case BLE_L2CAP_EVT_RX: + ret_val = ble_l2cap_evt_rx_enc(p_event, event_len, p_buf, p_buf_len); + break; +#endif +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION >= 5 && !defined(S112) + case BLE_L2CAP_EVT_CH_SETUP_REQUEST: + ret_val = ble_l2cap_evt_ch_setup_request_enc(p_event, event_len, p_buf, p_buf_len); + break; + case BLE_L2CAP_EVT_CH_SETUP_REFUSED: + ret_val = ble_l2cap_evt_ch_setup_refused_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_L2CAP_EVT_CH_SETUP: + ret_val = ble_l2cap_evt_ch_setup_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_L2CAP_EVT_CH_RELEASED: + ret_val = ble_l2cap_evt_ch_released_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_L2CAP_EVT_CH_SDU_BUF_RELEASED: + ret_val = ble_l2cap_evt_ch_sdu_buf_released_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_L2CAP_EVT_CH_CREDIT: + ret_val = ble_l2cap_evt_ch_credit_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_L2CAP_EVT_CH_RX: + ret_val = ble_l2cap_evt_ch_rx_enc(p_event, event_len, p_buf, p_buf_len); + break; + + case BLE_L2CAP_EVT_CH_TX: + ret_val = ble_l2cap_evt_ch_tx_enc(p_event, event_len, p_buf, p_buf_len); + break; +#endif //defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION >= 5 && !defined(S112) +#ifndef S112 + case BLE_GAP_EVT_ADV_REPORT: + ret_val = ble_gap_evt_adv_report_enc(p_event, event_len, p_buf, p_buf_len); + break; +#endif //!S112 + case BLE_GAP_EVT_SCAN_REQ_REPORT: + ret_val = ble_gap_evt_scan_req_report_enc(p_event, event_len, p_buf, p_buf_len); + break; + + default: + ret_val = NRF_ERROR_NOT_SUPPORTED; + *p_buf_len = 0; + break; + } + + return ret_val; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_evt_conn.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_evt_conn.c new file mode 100644 index 0000000..1cc3654 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_evt_conn.c @@ -0,0 +1,108 @@ +/** + * 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_evt_conn.h" +#include <string.h> +#include "ble_serialization.h" +#include "ble_struct_serialization.h" +#include "app_util.h" +#include "conn_ble_user_mem.h" + +uint32_t ble_evt_user_mem_release_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_EVT_USER_MEM_RELEASE); + + SER_PUSH_uint16(&p_event->evt.common_evt.conn_handle); + SER_PUSH_uint8(&p_event->evt.common_evt.params.user_mem_release.type); + SER_PUSH_uint16(&p_event->evt.common_evt.params.user_mem_release.mem_block.len); + SER_PUSH_COND(p_event->evt.common_evt.params.user_mem_release.mem_block.p_mem, NULL); + + // Now user memory context can be released + err_code = conn_ble_user_mem_context_destroy(p_event->evt.common_evt.conn_handle); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_EVT_ENC_END; +} + + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t ble_evt_tx_complete_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_EVT_TX_COMPLETE); + + SER_PUSH_uint16(&p_event->evt.common_evt.conn_handle); + SER_PUSH_uint8(&p_event->evt.common_evt.params.tx_complete.count); + + SER_EVT_ENC_END; +} +#endif + +uint32_t ble_evt_user_mem_request_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_EVT_USER_MEM_REQUEST); + + SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PUSH_uint8(&p_event->evt.common_evt.params.user_mem_request.type); + + SER_EVT_ENC_END; +} + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t ble_evt_data_length_changed_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_EVT_DATA_LENGTH_CHANGED); + + SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PUSH_FIELD(&p_event->evt.common_evt.params.data_length_changed, ble_evt_data_length_changed_t_enc); + + SER_EVT_ENC_END; +} +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_evt_conn.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_evt_conn.h new file mode 100644 index 0000000..ea94c93 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_evt_conn.h @@ -0,0 +1,138 @@ +/** + * 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_CONN_H__ +#define BLE_EVT_CONN_H__ + + +/**@file + * + * @defgroup ble_evt_conn Connectivity event encoders + * @{ + * @ingroup ser_conn_s130_codecs + * + * @brief Connectivity event encoders. + */ +#include "ble.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +/** + * @brief Encodes ble_evt_tx_complete event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that will be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_evt_tx_complete_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); +#endif +/** + * @brief Encodes ble_evt_user_mem_release event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_evt_user_mem_release_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes ble_evt_user_mem_request event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that will be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_evt_user_mem_request_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +/** + * @brief Encodes ble_evt_data_length_changed event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that will be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_evt_data_length_changed_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); +#endif +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gap_conn.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gap_conn.c new file mode 100644 index 0000000..e99044f --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gap_conn.c @@ -0,0 +1,1111 @@ +/** + * 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_conn.h" +#include <string.h> +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ble_gap_struct_serialization.h" +#include "ble_struct_serialization.h" +#include "app_util.h" + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 6 +uint32_t ble_gap_adv_data_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * * const pp_data, + uint8_t * p_dlen, + uint8_t * * const pp_sr_data, + uint8_t * p_srdlen) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_ADV_DATA_SET); + + SER_ASSERT_NOT_NULL(p_dlen); + SER_ASSERT_NOT_NULL(p_srdlen); + SER_PULL_len8data(pp_data, p_dlen); + SER_PULL_len8data(pp_sr_data, p_srdlen); + + SER_REQ_DEC_END; +} + + +uint32_t ble_gap_adv_data_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_ADV_DATA_SET); +} +#endif + +uint32_t ble_gap_adv_start_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t * p_adv_handle +#else + ble_gap_adv_params_t * * const pp_adv_params +#endif +#if NRF_SD_BLE_API_VERSION >= 4 + ,uint8_t * p_conn_cfg_tag +#endif + ) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_ADV_START); +#if NRF_SD_BLE_API_VERSION > 5 + SER_PULL_uint8(p_adv_handle); +#else + SER_ASSERT_NOT_NULL(pp_adv_params); + SER_ASSERT_NOT_NULL(*pp_adv_params); + SER_ASSERT_NOT_NULL((*pp_adv_params)->p_peer_addr); + + SER_PULL_COND(pp_adv_params, ble_gap_adv_params_t_dec); +#endif +#if NRF_SD_BLE_API_VERSION >= 4 + SER_PULL_uint8(p_conn_cfg_tag); +#endif + SER_REQ_DEC_END; +} + + +uint32_t ble_gap_adv_start_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len + ) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_ADV_START); +} + +#if NRF_SD_BLE_API_VERSION > 5 +uint32_t ble_gap_adv_stop_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint8_t * p_adv_handle) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_ADV_STOP); + + SER_PULL_uint8(p_adv_handle); + + SER_REQ_DEC_END; +} +#endif + +uint32_t ble_gap_adv_stop_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_ADV_STOP); +} + + +uint32_t ble_gap_appearance_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * * const pp_appearance) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_APPEARANCE_GET); + + SER_ASSERT_NOT_NULL(pp_appearance); + SER_ASSERT_NOT_NULL(*pp_appearance); + SER_PULL_COND(pp_appearance, NULL); + + SER_REQ_DEC_END; +} + + +uint32_t ble_gap_appearance_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint16_t const * const p_appearance) +{ + SER_RSP_ENC_BEGIN(SD_BLE_GAP_APPEARANCE_GET); + + SER_PUSH_COND(p_appearance, uint16_t_enc); + SER_RSP_ENC_END; +} + +uint32_t ble_gap_appearance_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_appearance) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_APPEARANCE_SET); + + SER_ASSERT_NOT_NULL(p_appearance); + SER_PULL_uint16(p_appearance); + + SER_REQ_DEC_END; +} + + +uint32_t ble_gap_appearance_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_APPEARANCE_SET); +} + +uint32_t ble_gap_auth_key_reply_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * p_conn_handle, + uint8_t * p_key_type, + uint8_t * * const pp_key) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_AUTH_KEY_REPLY); + + SER_ASSERT_NOT_NULL(p_conn_handle); + SER_ASSERT_NOT_NULL(p_key_type); + SER_PULL_uint16(p_conn_handle); + SER_PULL_uint8(p_key_type); + + uint8_t key_len; + switch (*p_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_PULL_buf(pp_key, key_len, key_len); + SER_REQ_DEC_END; +} + +uint32_t ble_gap_auth_key_reply_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_AUTH_KEY_REPLY); +} + + +uint32_t ble_gap_authenticate_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_conn_handle, + ble_gap_sec_params_t * * const pp_sec_params) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_AUTHENTICATE); + + SER_ASSERT_NOT_NULL(p_conn_handle); + SER_ASSERT_NOT_NULL(pp_sec_params); + SER_ASSERT_NOT_NULL(*pp_sec_params); + SER_PULL_uint16(p_conn_handle); + SER_PULL_COND(pp_sec_params, ble_gap_sec_params_t_dec); + + SER_REQ_DEC_END; +} + + +uint32_t ble_gap_authenticate_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_AUTHENTICATE); +} + +uint32_t ble_gap_conn_param_update_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * p_conn_handle, + ble_gap_conn_params_t * * const pp_conn_params) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_CONN_PARAM_UPDATE); + + SER_ASSERT_NOT_NULL(p_conn_handle); + SER_ASSERT_NOT_NULL(pp_conn_params); + SER_ASSERT_NOT_NULL(*pp_conn_params); + SER_PULL_uint16(p_conn_handle); + SER_PULL_COND(pp_conn_params, ble_gap_conn_params_t_dec); + + SER_REQ_DEC_END; +} + + +uint32_t ble_gap_conn_param_update_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_CONN_PARAM_UPDATE); +} + +uint32_t ble_gap_conn_sec_get_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * p_conn_handle, + ble_gap_conn_sec_t * * const pp_conn_sec) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_CONN_SEC_GET); + + SER_ASSERT_NOT_NULL(p_conn_handle); + SER_PULL_uint16(p_conn_handle); + SER_PULL_COND(pp_conn_sec, NULL); + + SER_REQ_DEC_END; +} + +uint32_t ble_gap_conn_sec_get_rsp_enc(uint32_t return_code, + ble_gap_conn_sec_t * const p_conn_sec, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_BEGIN(SD_BLE_GAP_CONN_SEC_GET); + + SER_PUSH_COND(p_conn_sec, ble_gap_conn_sec_t_enc); + + SER_RSP_ENC_END; +} + +uint32_t ble_gap_device_name_get_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * * pp_name, + uint16_t * * pp_name_len) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_DEVICE_NAME_GET); + + SER_ASSERT_NOT_NULL(pp_name_len); + + SER_PULL_COND(pp_name_len, uint16_t_dec); + SER_PULL_COND(pp_name, NULL); + + SER_REQ_DEC_END; +} + + +uint32_t ble_gap_device_name_get_rsp_enc(uint32_t return_code, + uint8_t const * const p_dev_name, + uint16_t * p_dev_name_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_BEGIN(SD_BLE_GAP_DEVICE_NAME_GET); + + SER_PUSH_COND(p_dev_name_len, uint16_t_enc); + + if (p_dev_name_len) + { + SER_PUSH_uint8array(p_dev_name, *p_dev_name_len); + } + + SER_RSP_ENC_END; +} + +uint32_t ble_gap_device_name_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_conn_sec_mode_t * * const pp_write_perm, + uint8_t * * const pp_dev_name, + uint16_t * const p_dev_name_len) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_DEVICE_NAME_SET); + + SER_ASSERT_NOT_NULL(pp_write_perm); + SER_ASSERT_NOT_NULL(pp_dev_name); + SER_ASSERT_NOT_NULL(p_dev_name_len); + + SER_PULL_COND(pp_write_perm, ble_gap_conn_sec_mode_t_dec); + SER_PULL_len16data(pp_dev_name, p_dev_name_len); + + SER_REQ_DEC_END; +} + + +uint32_t ble_gap_device_name_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_DEVICE_NAME_SET); +} + +uint32_t ble_gap_disconnect_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_conn_handle, + uint8_t * const p_hci_status) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_DISCONNECT); + + SER_ASSERT_NOT_NULL(p_conn_handle); + SER_ASSERT_NOT_NULL(p_hci_status); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_uint8(p_hci_status); + + SER_REQ_DEC_END; +} + +uint32_t ble_gap_disconnect_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_DISCONNECT); +} + +#ifndef S112 +uint32_t ble_gap_encrypt_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_conn_handle, + ble_gap_master_id_t ** const pp_master_id, + ble_gap_enc_info_t ** const pp_enc_info) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_ENCRYPT); + + SER_ASSERT_NOT_NULL(p_conn_handle); + SER_ASSERT_NOT_NULL(pp_enc_info); + SER_ASSERT_NOT_NULL(pp_master_id); + SER_ASSERT_NOT_NULL(*pp_enc_info); + SER_ASSERT_NOT_NULL(*pp_master_id); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_COND(pp_master_id, ble_gap_master_id_t_dec); + SER_PULL_COND(pp_enc_info, ble_gap_enc_info_t_dec); + + SER_REQ_DEC_END; +} + +uint32_t ble_gap_encrypt_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_ENCRYPT); +} +#endif + +uint32_t ble_gap_keypress_notify_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * p_conn_handle, + uint8_t * p_kp_not) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_KEYPRESS_NOTIFY); + + SER_ASSERT_NOT_NULL(p_conn_handle); + SER_ASSERT_NOT_NULL(p_kp_not); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_uint8(p_kp_not); + + SER_REQ_DEC_END; +} + +uint32_t ble_gap_keypress_notify_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_KEYPRESS_NOTIFY); +} + +uint32_t ble_gap_lesc_dhkey_reply_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * p_conn_handle, + ble_gap_lesc_dhkey_t * * pp_dhkey) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_LESC_DHKEY_REPLY); + + SER_ASSERT_NOT_NULL(p_conn_handle); + SER_ASSERT_NOT_NULL(pp_dhkey); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_COND(pp_dhkey, ble_gap_lesc_dhkey_t_dec); + + SER_REQ_DEC_END; +} + +uint32_t ble_gap_lesc_dhkey_reply_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_LESC_DHKEY_REPLY); +} + +uint32_t ble_gap_lesc_oob_data_get_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * p_conn_handle, + ble_gap_lesc_p256_pk_t * * pp_pk_own, + ble_gap_lesc_oob_data_t * * pp_oobd_own) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_LESC_OOB_DATA_GET); + + SER_ASSERT_NOT_NULL(p_conn_handle); + SER_ASSERT_NOT_NULL(pp_oobd_own); + SER_ASSERT_NOT_NULL(pp_pk_own); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_COND(pp_pk_own, ble_gap_lesc_p256_pk_t_dec); + SER_PULL_COND(pp_oobd_own, NULL); + + SER_REQ_DEC_END; +} + +uint32_t ble_gap_lesc_oob_data_get_rsp_enc(uint32_t return_code, + ble_gap_lesc_oob_data_t * p_oobd_own, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_BEGIN(SD_BLE_GAP_LESC_OOB_DATA_GET); + + SER_PUSH_COND(p_oobd_own, ble_gap_lesc_oob_data_t_enc); + + SER_RSP_ENC_END; +} + +uint32_t ble_gap_lesc_oob_data_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * p_conn_handle, + ble_gap_lesc_oob_data_t * * pp_oobd_own, + ble_gap_lesc_oob_data_t * * pp_oobd_peer) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_LESC_OOB_DATA_SET); + + SER_ASSERT_NOT_NULL(p_conn_handle); + SER_ASSERT_NOT_NULL(pp_oobd_own); + SER_ASSERT_NOT_NULL(pp_oobd_peer); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_COND(pp_oobd_own, ble_gap_lesc_oob_data_t_dec); + SER_PULL_COND(pp_oobd_peer, ble_gap_lesc_oob_data_t_dec); + + SER_REQ_DEC_END; +} + +uint32_t ble_gap_lesc_oob_data_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_LESC_OOB_DATA_SET); +} + +uint32_t ble_gap_ppcp_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + ble_gap_conn_params_t * * const pp_conn_params) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_PPCP_GET); + + SER_ASSERT_NOT_NULL(pp_conn_params); + SER_ASSERT_NOT_NULL(*pp_conn_params); + SER_ASSERT_LENGTH_LEQ(2, packet_len); + + SER_PULL_COND(pp_conn_params, NULL); + + SER_REQ_DEC_END; +} + + +uint32_t ble_gap_ppcp_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + ble_gap_conn_params_t const * const p_conn_params) +{ + SER_RSP_ENC_BEGIN(SD_BLE_GAP_PPCP_GET); + + SER_PUSH_COND(p_conn_params, ble_gap_conn_params_t_enc); + + SER_RSP_ENC_END; +} + + +uint32_t ble_gap_ppcp_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_conn_params_t * * const pp_conn_params) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_PPCP_SET); + + SER_ASSERT_NOT_NULL(pp_conn_params); + SER_PULL_COND(pp_conn_params, ble_gap_conn_params_t_dec); + + SER_REQ_DEC_END; +} + + +uint32_t ble_gap_ppcp_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_PPCP_SET); +} + +uint32_t ble_gap_rssi_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * p_conn_handle, + int8_t * * const pp_rssi +#if NRF_SD_BLE_API_VERSION > 5 + ,uint8_t * * const pp_ch_index +#endif + ) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_RSSI_GET); + + SER_ASSERT_NOT_NULL(p_conn_handle); + SER_ASSERT_NOT_NULL(pp_rssi); + SER_ASSERT_NOT_NULL(*pp_rssi); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_COND(pp_rssi, NULL); +#if NRF_SD_BLE_API_VERSION > 5 + SER_ASSERT_NOT_NULL(pp_ch_index); + SER_ASSERT_NOT_NULL(*pp_ch_index); + SER_PULL_COND(pp_ch_index, NULL); +#endif + SER_REQ_DEC_END; +} + + +uint32_t ble_gap_rssi_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + int8_t * p_rssi +#if NRF_SD_BLE_API_VERSION > 5 + ,uint8_t * p_ch_index +#endif + ) +{ + SER_RSP_ENC_BEGIN(SD_BLE_GAP_RSSI_GET); + + SER_PUSH_COND(p_rssi, uint8_t_enc); +#if NRF_SD_BLE_API_VERSION > 5 + SER_PUSH_COND(p_ch_index, uint8_t_enc); +#endif + + SER_RSP_ENC_END; +} + +uint32_t ble_gap_rssi_start_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * p_conn_handle, + uint8_t * p_threshold_dbm, + uint8_t * p_skip_count) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_RSSI_START); + + SER_ASSERT_NOT_NULL(p_conn_handle); + SER_ASSERT_NOT_NULL(p_threshold_dbm); + SER_ASSERT_NOT_NULL(p_skip_count); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_uint8(p_threshold_dbm); + SER_PULL_uint8(p_skip_count); + + SER_REQ_DEC_END; +} + +uint32_t ble_gap_rssi_start_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_RSSI_START); +} + +uint32_t ble_gap_rssi_stop_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * p_conn_handle) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_RSSI_STOP); + + SER_ASSERT_NOT_NULL(p_conn_handle); + SER_PULL_uint16(p_conn_handle); + + SER_REQ_DEC_END; +} + +uint32_t ble_gap_rssi_stop_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_RSSI_STOP); +} + +#ifndef S112 +uint32_t ble_gap_scan_start_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_scan_params_t * * const pp_scan_params +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 + ,ble_data_t * * const pp_adv_report_buffer +#endif + ) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_SCAN_START); + + SER_ASSERT_NOT_NULL(pp_scan_params); + SER_ASSERT_NOT_NULL(*pp_scan_params); + + SER_PULL_COND(pp_scan_params, ble_gap_scan_params_t_dec); +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 + SER_PULL_COND(pp_adv_report_buffer, ble_data_t_dec); +#endif + + SER_REQ_DEC_END; +} + +uint32_t ble_gap_scan_start_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_SCAN_START); +} + +uint32_t ble_gap_scan_stop_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_SCAN_STOP); +} + +uint32_t ble_gap_connect_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_addr_t * * const pp_addr, + ble_gap_scan_params_t * * const pp_scan_params, + ble_gap_conn_params_t * * const pp_conn_params +#if NRF_SD_BLE_API_VERSION >= 4 + ,uint8_t * p_conn_cfg_tag +#endif + ) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_CONNECT); + + SER_ASSERT_NOT_NULL(pp_addr); + SER_ASSERT_NOT_NULL(*pp_addr); + SER_ASSERT_NOT_NULL(pp_scan_params); + SER_ASSERT_NOT_NULL(*pp_scan_params); + SER_ASSERT_NOT_NULL(pp_conn_params); + SER_ASSERT_NOT_NULL(*pp_conn_params); + + SER_PULL_COND(pp_addr, ble_gap_addr_t_dec); + SER_PULL_COND(pp_scan_params, ble_gap_scan_params_t_dec); + SER_PULL_COND(pp_conn_params, ble_gap_conn_params_t_dec); +#if NRF_SD_BLE_API_VERSION >= 4 + SER_PULL_uint8(p_conn_cfg_tag); +#endif + + SER_REQ_DEC_END; +} + +uint32_t ble_gap_connect_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_CONNECT); +} +uint32_t ble_gap_connect_cancel_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_CONNECT_CANCEL); +} +#endif //S112 + +uint32_t ble_gap_sec_info_reply_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * p_conn_handle, + ble_gap_enc_info_t * * const pp_enc_info, + ble_gap_irk_t * * const pp_id_info, + ble_gap_sign_info_t * * const pp_sign_info) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_SEC_INFO_REPLY); + + SER_ASSERT_NOT_NULL(p_conn_handle); + SER_ASSERT_NOT_NULL(pp_enc_info); + SER_ASSERT_NOT_NULL(pp_id_info); + SER_ASSERT_NOT_NULL(pp_sign_info); + SER_ASSERT_NOT_NULL(*pp_enc_info); + SER_ASSERT_NOT_NULL(*pp_id_info); + SER_ASSERT_NOT_NULL(*pp_sign_info); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_COND(pp_enc_info, ble_gap_enc_info_t_dec); + SER_PULL_COND(pp_id_info, ble_gap_irk_t_dec); + SER_PULL_COND(pp_sign_info, ble_gap_sign_info_t_dec); + + SER_REQ_DEC_END; +} + +uint32_t ble_gap_sec_info_reply_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_SEC_INFO_REPLY); +} + +uint32_t ble_gap_sec_params_reply_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * p_conn_handle, + uint8_t * p_sec_status, + ble_gap_sec_params_t * * const pp_sec_params, + ble_gap_sec_keyset_t * * const pp_sec_keyset) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_SEC_PARAMS_REPLY); + + SER_ASSERT_NOT_NULL(p_conn_handle); + SER_ASSERT_NOT_NULL(p_sec_status); + SER_ASSERT_NOT_NULL(pp_sec_params); + SER_ASSERT_NOT_NULL(*pp_sec_params); + SER_ASSERT_NOT_NULL(pp_sec_keyset); + SER_ASSERT_NOT_NULL(*pp_sec_keyset); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_uint8(p_sec_status); + SER_PULL_COND(pp_sec_params, ble_gap_sec_params_t_dec); + SER_PULL_COND(pp_sec_keyset, ble_gap_sec_keyset_t_dec); + + SER_REQ_DEC_END; +} + +uint32_t ble_gap_sec_params_reply_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + ble_gap_sec_keyset_t * const p_sec_keyset) +{ + SER_RSP_ENC_BEGIN(SD_BLE_GAP_SEC_PARAMS_REPLY); + SER_PUSH_COND(p_sec_keyset, ble_gap_sec_keyset_t_enc); + SER_RSP_ENC_END; +} + +uint32_t ble_gap_tx_power_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t * p_role, uint16_t * p_handle, +#endif + int8_t * p_tx_power) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_TX_POWER_SET); + + SER_ASSERT_NOT_NULL(p_tx_power); +#if NRF_SD_BLE_API_VERSION > 5 + SER_PULL_uint8(p_role); + SER_PULL_uint16(p_handle); +#endif + SER_PULL_int8(p_tx_power); + + SER_REQ_DEC_END; +} + +uint32_t ble_gap_tx_power_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_TX_POWER_SET); +} + + +uint32_t ble_gap_addr_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + ble_gap_addr_t * * const pp_address) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_ADDR_GET); + SER_PULL_COND(pp_address, NULL); + SER_REQ_DEC_END; +} + + +uint32_t ble_gap_addr_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + ble_gap_addr_t const * const p_address) +{ + SER_RSP_ENC_BEGIN(SD_BLE_GAP_ADDR_GET); + SER_PUSH_FIELD(p_address, ble_gap_addr_t_enc); + SER_RSP_ENC_END; +} + + +uint32_t ble_gap_addr_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_addr_t * * const pp_addr) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_ADDR_SET); + SER_PULL_COND(pp_addr, ble_gap_addr_t_dec); + SER_REQ_DEC_END; +} + + +uint32_t ble_gap_addr_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_ADDR_SET); +} + +uint32_t ble_gap_privacy_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_privacy_params_t * * const pp_privacy_params) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_PRIVACY_SET); + SER_PULL_COND(pp_privacy_params, ble_gap_privacy_params_t_dec); + SER_REQ_DEC_END; +} + +uint32_t ble_gap_privacy_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_PRIVACY_SET); +} + +uint32_t ble_gap_privacy_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + ble_gap_privacy_params_t * * const pp_privacy_params) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_PRIVACY_GET); + SER_PULL_COND(pp_privacy_params, ble_gap_privacy_params_t_dec); + SER_REQ_DEC_END; +} + +uint32_t ble_gap_privacy_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + ble_gap_privacy_params_t const * const p_privacy_params) +{ + SER_RSP_ENC_BEGIN(SD_BLE_GAP_PRIVACY_GET); + SER_PUSH_COND(p_privacy_params, ble_gap_privacy_params_t_enc); + SER_RSP_ENC_END; +} + +uint32_t ble_gap_whitelist_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_addr_t * * * const ppp_wl_addrs, + uint8_t * const p_len) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_WHITELIST_SET); + + SER_ASSERT_NOT_NULL(ppp_wl_addrs); + SER_ASSERT_NOT_NULL(*ppp_wl_addrs); + SER_ASSERT_NOT_NULL(**ppp_wl_addrs); + + uint8_t presence; + SER_PULL_uint8(p_len); + + SER_PULL_uint8(&presence); + if (presence == SER_FIELD_PRESENT) + { + ble_gap_addr_t * * const pp_wl_addrs = *ppp_wl_addrs; + for (uint32_t i = 0; i < *p_len; ++i) + { + SER_PULL_COND(&(pp_wl_addrs[i]), ble_gap_addr_t_dec); + } + } + else + { + *ppp_wl_addrs = NULL; + } + + SER_REQ_DEC_END; +} + +uint32_t ble_gap_whitelist_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_WHITELIST_SET); +} + +uint32_t ble_gap_device_identities_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_id_key_t * * * const ppp_id_keys, + ble_gap_irk_t * * * const ppp_local_irks, + uint8_t * const p_len) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_DEVICE_IDENTITIES_SET); + + SER_ASSERT_NOT_NULL(ppp_id_keys); + SER_ASSERT_NOT_NULL(*ppp_id_keys); + SER_ASSERT_NOT_NULL(**ppp_id_keys); + SER_ASSERT_NOT_NULL(ppp_local_irks); + SER_ASSERT_NOT_NULL(*ppp_local_irks); + SER_ASSERT_NOT_NULL(**ppp_local_irks); + + uint8_t presence; + SER_PULL_uint8(p_len); + + SER_PULL_uint8(&presence); + if (presence == SER_FIELD_PRESENT) + { + ble_gap_id_key_t * * const pp_id_keys = *ppp_id_keys; + for (uint32_t i = 0; i < *p_len; ++i) + { + SER_PULL_COND(&(pp_id_keys[i]), ble_gap_id_key_t_dec); + } + } + else + { + *ppp_id_keys = NULL; + } + SER_PULL_uint8(&presence); + if (presence == SER_FIELD_PRESENT) + { + ble_gap_irk_t * * const pp_local_irks = *ppp_local_irks; + for (uint32_t i = 0; i < *p_len; ++i) + { + SER_PULL_COND(&(pp_local_irks[i]), ble_gap_irk_t_dec); + } + } + else + { + *ppp_local_irks = NULL; + } + + SER_REQ_DEC_END; +} + +uint32_t ble_gap_device_identities_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_DEVICE_IDENTITIES_SET); +} + +#if NRF_SD_BLE_API_VERSION >= 4 && !defined(S112) +uint32_t ble_gap_data_length_update_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * p_conn_handle, + ble_gap_data_length_params_t * * const pp_dl_params, + ble_gap_data_length_limitation_t * * const pp_dl_limitation) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_DATA_LENGTH_UPDATE); + SER_PULL_uint16(p_conn_handle); + SER_PULL_COND(pp_dl_params, ble_gap_data_length_params_t_dec); + SER_PULL_COND(pp_dl_limitation, NULL); + SER_REQ_DEC_END; +} + + +uint32_t ble_gap_data_length_update_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + ble_gap_data_length_limitation_t const * const p_dl_limitation) +{ + SER_RSP_ENC_BEGIN(SD_BLE_GAP_DATA_LENGTH_UPDATE); + SER_PUSH_COND(p_dl_limitation, ble_gap_data_length_limitation_t_enc); + SER_RSP_ENC_END; +} +#endif //NRF_SD_BLE_API_VERSION >= 4 && !defined(S112) + +#if NRF_SD_BLE_API_VERSION >= 5 +uint32_t ble_gap_phy_update_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_conn_handle, + ble_gap_phys_t * * const pp_gap_phys) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_PHY_UPDATE); + + SER_ASSERT_NOT_NULL(p_conn_handle); + SER_ASSERT_NOT_NULL(pp_gap_phys); + SER_ASSERT_NOT_NULL(*pp_gap_phys); + SER_PULL_uint16(p_conn_handle); + SER_PULL_COND(pp_gap_phys, ble_gap_phys_t_dec); + + SER_REQ_DEC_END; +} + + +uint32_t ble_gap_phy_update_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_PHY_UPDATE); +} +#endif //RF_SD_BLE_API_VERSION >= 5 + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 +uint32_t ble_gap_adv_set_configure_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint8_t * * const pp_adv_handle, + ble_gap_adv_data_t **const pp_adv_data, + ble_gap_adv_params_t **const pp_adv_params) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_ADV_SET_CONFIGURE); + + SER_ASSERT_NOT_NULL(pp_adv_handle); + SER_ASSERT_NOT_NULL(*pp_adv_handle); + SER_ASSERT_NOT_NULL(pp_adv_data); + SER_ASSERT_NOT_NULL(*pp_adv_data); + SER_ASSERT_NOT_NULL(pp_adv_params); + SER_ASSERT_NOT_NULL(*pp_adv_params); + + SER_PULL_COND(pp_adv_handle, uint8_t_dec); + SER_PULL_COND(pp_adv_data, ble_gap_adv_data_t_dec); + SER_PULL_COND(pp_adv_params, ble_gap_adv_params_t_dec); + + SER_REQ_DEC_END; +} + + +uint32_t ble_gap_adv_set_configure_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint8_t const * const p_adv_handle) +{ + SER_RSP_ENC_BEGIN(SD_BLE_GAP_ADV_SET_CONFIGURE); + + SER_PUSH_COND(p_adv_handle, uint8_t_enc); + SER_RSP_ENC_END; +} + +#ifndef S112 +uint32_t ble_gap_qos_channel_survey_start_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_interval_us) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_QOS_CHANNEL_SURVEY_START); + + SER_ASSERT_NOT_NULL(p_interval_us); + SER_PULL_uint32(p_interval_us); + SER_REQ_DEC_END; +} + + +uint32_t ble_gap_qos_channel_survey_start_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_QOS_CHANNEL_SURVEY_START); +} + +uint32_t ble_gap_qos_channel_survey_stop_req_dec(uint8_t const * const p_buf, + uint32_t packet_len) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GAP_QOS_CHANNEL_SURVEY_STOP); + SER_REQ_DEC_END; +} + + +uint32_t ble_gap_qos_channel_survey_stop_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GAP_QOS_CHANNEL_SURVEY_STOP); +} +#endif +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gap_conn.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gap_conn.h new file mode 100644 index 0000000..4464552 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gap_conn.h @@ -0,0 +1,1526 @@ +/** + * 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_CONN_H__ +#define BLE_GAP_CONN_H__ + +/**@file + * + * @defgroup ble_gap_conn GAP Connectivity command request decoders and command response encoders + * @{ + * @ingroup ser_conn_s130_codecs + * + * @brief GAP Connectivity command request decoders and command response encoders + */ +#include "ble_gap.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/**@brief Decodes @ref sd_ble_gap_authenticate command request. + * + * @sa @ref ble_gap_authenticate_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_handle Pointer to connection handle + * @param[out] pp_sec_params Pointer to pointer to security parameters. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_gap_authenticate_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_conn_handle, + ble_gap_sec_params_t * * const pp_sec_params); + +/**@brief Encodes @ref sd_ble_gap_authenticate command response. + * + * @sa @ref ble_gap_authenticate_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_authenticate_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +#if defined(NRF_SD_BLE_API_VERSION) && (NRF_SD_BLE_API_VERSION <= 5) +/**@brief Decodes @ref sd_ble_gap_adv_data_set command request. + * + * @sa @ref ble_gap_adv_data_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of request packet. + * @param[out] pp_data Pointer to the buffer raw data to be placed in advertisement packet. + * @param[out] p_dlen Pointer to data length for p_data. + * @param[out] pp_sr_data Pointer to the buffer raw data to be placed in scan response packet. + * @param[out] p_srdlen Pointer to data length for p_sr_data. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_adv_data_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * * const pp_data, + uint8_t * p_dlen, + uint8_t * * const pp_sr_data, + uint8_t * p_srdlen); + +/**@brief Encodes @ref sd_ble_gap_adv_data_set command response. + * + * @sa @ref ble_gap_adv_data_set_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_adv_data_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); +#endif +/**@brief Decodes @ref sd_ble_gap_adv_start command request. + * + * @sa @ref ble_gap_adv_start_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] pp_adv_params Pointer to pointer to advertising parameters. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_gap_adv_start_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t * p_adv_handle +#else + ble_gap_adv_params_t * * const pp_adv_params +#endif +#if NRF_SD_BLE_API_VERSION >= 4 + ,uint8_t * p_conn_cfg_tag +#endif + ); + +/**@brief Encodes @ref sd_ble_gap_adv_start command response. + * + * @sa @ref ble_gap_adv_start_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_adv_start_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_gap_device_name_get command request. + * + * @sa @ref ble_gap_device_name_get_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] pp_dev_name Pointer to pointer to device name buffer. + * @param[out] pp_dev_name_len Pointer to pointer to device name length 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. + */ +uint32_t ble_gap_device_name_get_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * * pp_dev_name, + uint16_t * * pp_dev_name_len); + +/**@brief Encodes @ref sd_ble_gap_device_name_get command response. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[in] p_dev_name Pointer to device name buffer. + * @param[in] p_dev_name_len Length of device name buffer. + * @param[in] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_device_name_get_rsp_enc(uint32_t return_code, + uint8_t const * const p_dev_name, + uint16_t * p_dev_name_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_gap_conn_param_update command request. + * + * @sa @ref ble_gap_conn_param_update_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_handle Pointer to connection handle. + * @param[out] pp_conn_params Pointer to pointer to connection parameters. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Invalid value for connection + * parameters field present. + */ +uint32_t ble_gap_conn_param_update_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * p_conn_handle, + ble_gap_conn_params_t * * const pp_conn_params); + +/**@brief Encodes @ref sd_ble_gap_conn_param_update command response. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[in] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @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_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + + +/**@brief Decodes @ref sd_ble_gap_disconnect command request. + * + * @sa @ref ble_gap_disconnect_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[in] p_conn_handle Pointer to Connection Handle. + * @param[in] p_hci_status Pointer to HCI Status 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_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_gap_disconnect_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_conn_handle, + uint8_t * const p_hci_status); + +/**@brief Encodes @ref sd_ble_gap_disconnect command response. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[in] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @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_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_gap_tx_power_set command request. + * + * @sa @ref ble_gap_tx_power_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[in] p_tx_power Pointer to TX power value. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_gap_tx_power_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t * p_role, uint16_t * p_handle, +#endif + int8_t * p_tx_power); + +/**@brief Encodes @ref sd_ble_gap_tx_power_set command response. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[in] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @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_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_gap_ppcp_set command request. + * + * @sa @ref ble_gap_ppcp_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] pp_conn_params Pointer to pointer to connection parameters to be set. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Invalid value for connection + * parameters field present. + */ +uint32_t ble_gap_ppcp_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_conn_params_t * * const pp_conn_params); + +/**@brief Encodes @ref sd_ble_gap_ppcp_set command response. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[in] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @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_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + + +/**@brief Decodes @ref sd_ble_gap_ppcp_get command request. + * + * @sa @ref ble_gap_ppcp_get_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] pp_conn_params Pointer to pointer to ble_gap_conn_params_t. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_gap_ppcp_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + ble_gap_conn_params_t * * const pp_conn_params); + +/**@brief Encodes @ref sd_ble_gap_ppcp_get command response. + * + * @sa @ref ble_gap_ppcp_get_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_conn_params Pointer to ble_gap_conn_params_t. + * + * @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_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + ble_gap_conn_params_t const * const p_conn_params); + + +uint32_t ble_gap_adv_stop_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint8_t * p_adv_handle); +/**@brief Encodes @ref sd_ble_gap_adv_stop command response. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[in] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @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_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_gap_auth_key_reply command request. + * + * @sa @ref ble_gap_auth_key_reply_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_handle Pointer to connection handle. + * @param[out] p_key_type Pointer to key type. + * @param[out] pp_key Pointer to pointer to buffer for incoming key. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_gap_auth_key_reply_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * p_conn_handle, + uint8_t * p_key_type, + uint8_t * * const pp_key); + +/**@brief Encodes @ref sd_ble_gap_auth_key_reply command response. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[in] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @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_auth_key_reply_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_gap_sec_params_reply command request. + * + * @sa @ref ble_gap_sec_params_reply_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_handle Pointer to connection handle. + * @param[out] p_sec_status Pointer to security status. + * @param[out] pp_sec_params Pointer to pointer to security parameters structure. + * @param[out] pp_sec_keyset Pointer to pointer to security keyset structure. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Invalid value for connection + * parameters field present. + */ +uint32_t ble_gap_sec_params_reply_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * p_conn_handle, + uint8_t * p_sec_status, + ble_gap_sec_params_t * * const pp_sec_params, + ble_gap_sec_keyset_t * * const pp_sec_keyset); + +/**@brief Encodes @ref sd_ble_gap_sec_params_reply command response. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[in] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in] p_sec_keyset Pointer to security keyset structure. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_sec_params_reply_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + ble_gap_sec_keyset_t * const p_sec_keyset); + +/**@brief Decodes @ref sd_ble_gap_rssi_start command request. + * + * @sa @ref ble_gap_rssi_start_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_handle Pointer to connection handle. + * @param[out] p_threshold_dbm Pointer to threshold in dBm. + * @param[out] p_skip_count Pointer to sample skip count. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_gap_rssi_start_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * p_conn_handle, + uint8_t * p_threshold_dbm, + uint8_t * p_skip_count); + +/**@brief Encodes @ref sd_ble_gap_rssi_start command response. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[in] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @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_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_gap_rssi_stop command request. + * + * @sa @ref ble_gap_rssi_stop_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] conn_handle Pointer to connection handle. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ + +uint32_t ble_gap_rssi_stop_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * conn_handle); + +/**@brief Encodes @ref sd_ble_gap_rssi_stop command response. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[in] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @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_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_gap_appearance_get command request. + * + * @sa @ref ble_gap_appearance_get_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] pp_appearance Pointer to pointer to uint16_t appearance. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_gap_appearance_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * * const pp_appearance); + +/**@brief Encodes @ref sd_ble_gap_appearance_get command response. + * + * @sa @ref ble_gap_appearance_get_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_appearance Pointer to uint16_t appearance. + * + * @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_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint16_t const * const p_appearance); + + +/**@brief Decodes @ref sd_ble_gap_appearance_set command request. + * + * @sa @ref ble_gap_tx_power_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] buf_len Length (in bytes) of the packet. + * @param[out] p_appearance Pointer to the appearance. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_appearance_set_req_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint16_t * const p_appearance); + +/**@brief Encodes @ref sd_ble_gap_appearance_set command response. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[in] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @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_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + + +/**@brief Decodes @ref sd_ble_gap_sec_info_reply command request. + * + * @sa @ref ble_gap_sec_info_reply_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of the packet. + * @param[out] p_conn_handle Pointer to the Connection Handle. + * @param[out] pp_enc_info Pointer to pointer to Encryption Information. + * @param[out] pp_id_info Pointer to pointer to ID Information. + * @param[out] pp_sign_info Pointer to pointer to Signing Information. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_sec_info_reply_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * p_conn_handle, + ble_gap_enc_info_t * * const pp_enc_info, + ble_gap_irk_t * * const pp_id_info, + ble_gap_sign_info_t * * const pp_sign_info); + +/**@brief Encodes @ref sd_ble_gap_sec_info_reply command response. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[in] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @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_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_gap_device_name_set command request. + * + * @sa @ref ble_gap_device_name_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of the packet. + * @param[out] pp_write_perm Pointer to pointer to write permissions filed. + * @param[out] pp_dev_name Pointer to pointer to device name string. + * @param[out] p_dev_name_len Pointer to device name string length. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_device_name_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_conn_sec_mode_t * * const pp_write_perm, + uint8_t * * const pp_dev_name, + uint16_t * const p_dev_name_len); + + +/**@brief Encodes @ref sd_ble_gap_device_name_set command response. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[in] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @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_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_gap_conn_sec_get command request. + * + * @sa @ref ble_gap_conn_sec_get_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_handle Pointer to Connection Handle. + * @param[out] pp_conn_sec Pointer to pointer to @ref ble_gap_conn_sec_t to be filled by + * the SoftDevice. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_gap_conn_sec_get_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * p_conn_handle, + ble_gap_conn_sec_t * * const pp_conn_sec); + +/**@brief Encodes @ref sd_ble_gap_conn_sec_get command response. + * + * @sa @ref ble_gap_conn_sec_get_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[in] p_conn_sec Pointer to @ref ble_gap_conn_sec_t to be encoded. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_conn_sec_get_rsp_enc(uint32_t return_code, + ble_gap_conn_sec_t * const p_conn_sec, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +#ifndef S112 +/**@brief Encodes @ref sd_ble_gap_scan_stop command response. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[in] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @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_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_gap_connect command request. + * + * @sa @ref ble_gap_connect_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] pp_addr Pointer to pointer to peer address @ref ble_gap_addr_t. + * @param[out] pp_scan_params Pointer to pointer to @ref ble_gap_scan_params_t. + * @param[out] pp_conn_params Pointer to pointer to @ref ble_gap_conn_params_t. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_gap_connect_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_addr_t * * const pp_addr, + ble_gap_scan_params_t * * const pp_scan_params, + ble_gap_conn_params_t * * const pp_conn_params +#if NRF_SD_BLE_API_VERSION >= 4 + ,uint8_t * p_conn_cfg_tag +#endif + ); + +/**@brief Encodes @ref sd_ble_gap_connect command response. + * + * @sa @ref ble_gap_connect_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_connect_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_gap_scan_start command request. + * + * @sa @ref ble_gap_scan_start_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] pp_scan_params Pointer to pointer to @ref ble_gap_scan_params_t. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_gap_scan_start_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_scan_params_t * * const pp_scan_params +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 + ,ble_data_t * * const pp_adv_report_buffer +#endif + ); + +/**@brief Encodes @ref sd_ble_gap_scan_start command response. + * + * @sa @ref ble_gap_scan_start_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_scan_start_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Encodes @ref sd_ble_gap_connect_cancel command response. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @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_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + + +/**@brief Decodes @ref sd_ble_gap_encrypt command request. + * + * @sa @ref ble_gap_encrypt_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_handle Pointer connection_handle. + * @param[out] pp_master_id Pointer to pointer to @ref ble_gap_master_id_t. + * @param[out] pp_enc_info Pointer to pointer to @ref ble_gap_enc_info_t. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ + +uint32_t ble_gap_encrypt_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_conn_handle, + ble_gap_master_id_t ** const pp_master_id, + ble_gap_enc_info_t ** const pp_enc_info); + +/**@brief Encodes @ref sd_ble_gap_encrypt command response. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @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_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +#endif + +/**@brief Decodes @ref sd_ble_gap_rssi_get command request. + * + * @sa @ref ble_gap_rssi_get_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[in] p_conn_handle Connection handle. + * @param[out] pp_rssi Pointer to pointer to RSSI value. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_gap_rssi_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * p_conn_handle, + int8_t * * const pp_rssi +#if NRF_SD_BLE_API_VERSION > 5 + ,uint8_t * * const pp_ch_index +#endif + ); + +/**@brief Encodes @ref sd_ble_gap_rssi_get command response. + * + * @sa @ref ble_gap_rssi_get_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_rssi RSSI value. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_rssi_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + int8_t * p_rssi +#if NRF_SD_BLE_API_VERSION > 5 + ,uint8_t * p_ch_index +#endif + ); + +/**@brief Decodes @ref sd_ble_gap_keypress_notify command request. + * + * @sa @ref ble_gap_keypress_notify_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_handle Connection handle. + * @param[out] p_kp_not Pointer kp_not value. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_gap_keypress_notify_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * p_conn_handle, + uint8_t * p_kp_not); + +/**@brief Encodes @ref sd_ble_gap_keypress_notify command response. + * + * @sa @ref ble_gap_keypress_notify_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_keypress_notify_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_gap_lesc_dhkey_reply command request. + * + * @sa @ref ble_gap_lesc_dhkey_reply_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_handle Connection handle. + * @param[out] pp_dhkey Pointer to pointer to dhkey struct. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_gap_lesc_dhkey_reply_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * p_conn_handle, + ble_gap_lesc_dhkey_t * * pp_dhkey); + +/**@brief Encodes @ref sd_ble_gap_lesc_dhkey_reply command response. + * + * @sa @ref ble_gap_lesc_dhkey_reply_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_lesc_dhkey_reply_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_gap_lesc_oob_data_set command request. + * + * @sa @ref ble_gap_lesc_oob_data_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_handle Connection handle. + * @param[out] pp_oobd_own Pointer to pointer to own OOB data struct. + * @param[out] pp_oobd_peer Pointer to pointer to peer OOB data struct. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_gap_lesc_oob_data_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * p_conn_handle, + ble_gap_lesc_oob_data_t * * pp_oobd_own, + ble_gap_lesc_oob_data_t * * pp_oobd_peer); + +/**@brief Encodes @ref sd_ble_gap_lesc_oob_data_set command response. + * + * @sa @ref ble_gap_lesc_oob_data_set_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_lesc_oob_data_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_gap_lesc_oob_data_get command request. + * + * @sa @ref ble_gap_lesc_oob_data_get_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_handle Connection handle. + * @param[out] pp_pk_own Pointer to pointer to PK. + * @param[out] pp_oobd_own Pointer to pointer to own OOB data struct. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_gap_lesc_oob_data_get_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * p_conn_handle, + ble_gap_lesc_p256_pk_t * * pp_pk_own, + ble_gap_lesc_oob_data_t * * pp_oobd_own); + +/**@brief Encodes @ref sd_ble_gap_lesc_oob_data_get command response. + * + * @sa @ref ble_gap_lesc_oob_data_get_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[in] p_oobd_own Pointer to OOB data. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_lesc_oob_data_get_rsp_enc(uint32_t return_code, + ble_gap_lesc_oob_data_t * p_oobd_own, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_gap_addr_get command request. + * + * @sa @ref ble_gap_addr_get_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] pp_address Pointer to pointer to address. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_gap_addr_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + ble_gap_addr_t * * const pp_address); + +/**@brief Encodes @ref sd_ble_gap_addr_get command response. + * + * @sa @ref ble_gap_addr_get_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_address Pointer to @ref ble_gap_addr_t address + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_addr_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + ble_gap_addr_t const * const p_address); + +/** @brief Decodes @ref sd_ble_gap_addr_set command request. + * + * @sa @ref ble_gap_addr_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of request packet. + * @param[out] pp_addr Pointer to pointer to the address structure. + + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_addr_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_addr_t * * const pp_addr); + +/**@brief Encodes @ref sd_ble_gap_addr_set command response. + * + * @sa @ref ble_gap_addr_set_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_addr_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** @brief Decodes @ref sd_ble_gap_privacy_set command request. + * + * @sa @ref ble_gap_privacy_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of request packet. + * @param[out] pp_privacy_params Pointer to pointer to the privacy settings structure. + + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_privacy_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_privacy_params_t * * const pp_privacy_params); + +/**@brief Encodes @ref sd_ble_gap_privacy_set command response. + * + * @sa @ref ble_gap_privacy_set_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_privacy_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** @brief Decodes @ref sd_ble_gap_privacy_get command request. + * + * @sa @ref ble_gap_privacy_get_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of request packet. + * @param[out] pp_privacy_params Pointer to pointer to the privacy settings structure. + + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_privacy_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + ble_gap_privacy_params_t * * const pp_privacy_params); + +/**@brief Encodes @ref sd_ble_gap_privacy_set command response. + * + * @sa @ref ble_gap_privacy_set_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[out] p_privacy_params Pointer to privacy settings structure. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_privacy_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + ble_gap_privacy_params_t const * const p_privacy_params); + +/** @brief Decodes @ref sd_ble_gap_whitelist_set command request. + * + * @sa @ref ble_gap_whitelist_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of request packet. + * @param[out] ppp_wl_addrs Pointer to a whitelist of peer addresses. + * @param[out] p_len Pointer to a length of the whitelist. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_whitelist_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_addr_t * * * const ppp_wl_addrs, + uint8_t * const p_len); + +/**@brief Encodes @ref sd_ble_gap_whitelist_set command response. + * + * @sa @ref ble_gap_whitelist_set_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_whitelist_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** @brief Decodes @ref sd_ble_gap_device_identities_set command request. + * + * @sa @ref ble_gap_device_identities_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of request packet. + * @param[out] ppp_id_keys Pointer to an array of peer identity addresses and peer IRKs. + * @param[out] ppp_local_irks Pointer to an array of local IRKs. + * @param[out] p_len Pointer to a length of the device identity list. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_device_identities_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_id_key_t * * * const ppp_id_keys, + ble_gap_irk_t * * * const ppp_local_irks, + uint8_t * const p_len); + +/**@brief Encodes @ref sd_ble_gap_device_identities_set command response. + * + * @sa @ref ble_gap_device_identities_set_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_device_identities_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); +#if NRF_SD_BLE_API_VERSION >= 4 && !defined(S112) +/** @brief Decodes @ref sd_bble_gap_data_length_update command request. + * + * @sa @ref ble_gap_data_length_update_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of request packet. + * @param[out] p_conn_handle Pointer to a connection handle. + * @param[out] pp_dl_params Pointer to pointer to a data length params structure. + * @param[out] pp_dl_limitation Pointer to pointer to a data length limitation structure. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_data_length_update_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * p_conn_handle, + ble_gap_data_length_params_t * * const pp_dl_params, + ble_gap_data_length_limitation_t * * const pp_dl_limitation); + +/**@brief Encodes @ref sd_ble_gap_data_length_update command response. + * + * @sa @ref ble_gap_data_length_update_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_data_length_update_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + ble_gap_data_length_limitation_t const * const p_dl_limitation); +#endif +#if NRF_SD_BLE_API_VERSION >= 5 +/**@brief Decodes @ref sd_ble_gap_phy_update command request. + * + * @sa @ref ble_gap_phy_update_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_handle Pointer to connection handle + * @param[out] pp_gap_phys Pointer to pointer to the struct. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_gap_phy_update_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_conn_handle, + ble_gap_phys_t * * const pp_gap_phys); + +/**@brief Encodes @ref sd_ble_gap_phy_update command response. + * + * @sa @ref ble_gap_phy_update_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_phy_update_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); +#endif + +#if NRF_SD_BLE_API_VERSION >= 6 +/**@brief Decodes @ref sd_ble_gap_adv_set_configure command request. + * + * @sa @ref ble_gap_adv_set_configure_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_handle Pointer to connection handle + * @param[out] pp_adv_handle Pointer to pointer to the struct. + * @param[out] pp_adv_data Pointer to pointer to the struct. + * @param[out] pp_adv_params Pointer to pointer to the struct. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_gap_adv_set_configure_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint8_t * * const pp_adv_handle, + ble_gap_adv_data_t **const pp_adv_data, + ble_gap_adv_params_t **const pp_adv_params); + + +/**@brief Encodes @ref sd_ble_gap_adv_set_configure command response. + * + * @sa @ref ble_gap_adv_set_configure_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_adv_handle Pointer to the field to be encoded. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_adv_set_configure_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint8_t const * const p_adv_handle); + +#ifndef S112 +/**@brief Decodes @ref sd_ble_gap_qos_channel_survey_start command request. + * + * @sa @ref ble_gap_qos_channel_survey_start_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_interval_us Pointer to interval. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_gap_qos_channel_survey_start_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_interval_us); + +/**@brief Encodes @ref sd_ble_gap_qos_channel_survey_start command response. + * + * @sa @ref ble_gap_qos_channel_survey_start_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_qos_channel_survey_start_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_gap_qos_channel_survey_stop command request. + * + * @sa @ref ble_gap_qos_channel_survey_stop_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_gap_qos_channel_survey_stop_req_dec(uint8_t const * const p_buf, + uint32_t packet_len); + +/**@brief Encodes @ref sd_ble_gap_qos_channel_survey_stop command response. + * + * @sa @ref ble_gap_qos_channel_survey_stop_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_qos_channel_survey_stop_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); +#endif //!defined(S112) +#endif +/** @} */ +#ifdef __cplusplus +} +#endif + +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gap_evt_conn.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gap_evt_conn.c new file mode 100644 index 0000000..f1c67e8 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gap_evt_conn.c @@ -0,0 +1,401 @@ +/** + * 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_gap_evt_conn.h" +#include <string.h> +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "ble_gap_struct_serialization.h" +#include "conn_ble_gap_sec_keys.h" +#include "app_util.h" + +extern ser_ble_gap_conn_keyset_t m_conn_keys_table[]; + +#ifndef S112 +uint32_t ble_gap_evt_adv_report_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GAP_EVT_ADV_REPORT); + + SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PUSH_FIELD(&p_event->evt.gap_evt.params.adv_report, ble_gap_evt_adv_report_t_enc); + + SER_EVT_ENC_END; +} +#endif //!S112 + +uint32_t ble_gap_evt_auth_key_request_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GAP_EVT_AUTH_KEY_REQUEST); + + SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PUSH_uint8(&p_event->evt.gap_evt.params.auth_key_request.key_type); + + SER_EVT_ENC_END; +} + +uint32_t ble_gap_evt_auth_status_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GAP_EVT_AUTH_STATUS); + + SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PUSH_FIELD(&p_event->evt.gap_evt.params.auth_status, ble_gap_evt_auth_status_t_enc); + + // keyset is an extension of standard event data - used to synchronize keys at application + uint32_t conn_index; + err_code = conn_ble_gap_sec_context_find(p_event->evt.gap_evt.conn_handle, &conn_index); + if (err_code == NRF_SUCCESS) + { + SER_PUSH_FIELD(&(m_conn_keys_table[conn_index].keyset), ble_gap_sec_keyset_t_enc); + + err_code = conn_ble_gap_sec_context_destroy(p_event->evt.gap_evt.conn_handle); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + } + else + { + err_code = NRF_SUCCESS; + } + + SER_EVT_ENC_END; +} + + +uint32_t ble_gap_evt_conn_param_update_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GAP_EVT_CONN_PARAM_UPDATE); + + SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PUSH_FIELD(&p_event->evt.gap_evt.params.conn_param_update, ble_gap_evt_conn_param_update_t_enc); + + SER_EVT_ENC_END; +} + +#ifndef S112 +uint32_t ble_gap_evt_conn_param_update_request_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST); + + SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PUSH_FIELD(&p_event->evt.gap_evt.params.conn_param_update_request, + ble_gap_evt_conn_param_update_request_t_enc); + + SER_EVT_ENC_END; +} +#endif //!S112 + +uint32_t ble_gap_evt_conn_sec_update_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GAP_EVT_CONN_SEC_UPDATE); + + SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PUSH_FIELD(&p_event->evt.gap_evt.params.conn_sec_update, ble_gap_evt_conn_sec_update_t_enc); + + SER_EVT_ENC_END; +} + +uint32_t ble_gap_evt_connected_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GAP_EVT_CONNECTED); + + SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PUSH_FIELD(&p_event->evt.gap_evt.params.connected, ble_gap_evt_connected_t_enc); + + SER_EVT_ENC_END; +} + +uint32_t ble_gap_evt_disconnected_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GAP_EVT_DISCONNECTED); + + SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PUSH_FIELD(&p_event->evt.gap_evt.params.disconnected, ble_gap_evt_disconnected_t_enc); + + // If disconnected and context is not yet destroyed, destroy it now + uint32_t conn_index; + err_code = conn_ble_gap_sec_context_find(p_event->evt.gap_evt.conn_handle, &conn_index); + if (err_code == NRF_SUCCESS) + { + err_code = conn_ble_gap_sec_context_destroy(p_event->evt.gap_evt.conn_handle); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + } + err_code = NRF_SUCCESS; + + SER_EVT_ENC_END; +} + +uint32_t ble_gap_evt_key_pressed_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GAP_EVT_KEY_PRESSED); + + SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PUSH_uint8(&p_event->evt.gap_evt.params.key_pressed.kp_not); + + SER_EVT_ENC_END; +} + +uint32_t ble_gap_evt_lesc_dhkey_request_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GAP_EVT_LESC_DHKEY_REQUEST); + + uint8_t ser_data = p_event->evt.gap_evt.params.lesc_dhkey_request.oobd_req & 0x01; + SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PUSH_COND(p_event->evt.gap_evt.params.lesc_dhkey_request.p_pk_peer, ble_gap_lesc_p256_pk_t_enc); + SER_PUSH_uint8(&ser_data); + + SER_EVT_ENC_END; +} + +#define PASSKEY_LEN sizeof (p_event->evt.gap_evt.params.passkey_display.passkey) + + +uint32_t ble_gap_evt_passkey_display_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GAP_EVT_PASSKEY_DISPLAY); + + uint8_t ser_data = p_event->evt.gap_evt.params.passkey_display.match_request & 0x01; + SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PUSH_uint8array(p_event->evt.gap_evt.params.passkey_display.passkey, BLE_GAP_PASSKEY_LEN); + SER_PUSH_uint8(&ser_data); + + SER_EVT_ENC_END; +} + +uint32_t ble_gap_evt_rssi_changed_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GAP_EVT_RSSI_CHANGED); + + SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PUSH_int8(&p_event->evt.gap_evt.params.rssi_changed.rssi); +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 + SER_PUSH_uint8(&p_event->evt.gap_evt.params.rssi_changed.ch_index); +#endif + + SER_EVT_ENC_END; +} + +uint32_t ble_gap_evt_scan_req_report_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GAP_EVT_SCAN_REQ_REPORT); + + SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle); +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 + SER_PUSH_uint8(&p_event->evt.gap_evt.params.scan_req_report.adv_handle); +#endif + SER_PUSH_FIELD(&p_event->evt.gap_evt.params.scan_req_report.peer_addr, ble_gap_addr_t_enc); + SER_PUSH_int8(&p_event->evt.gap_evt.params.scan_req_report.rssi); + + SER_EVT_ENC_END; +} + +uint32_t ble_gap_evt_sec_info_request_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GAP_EVT_SEC_INFO_REQUEST); + + SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PUSH_FIELD(&p_event->evt.gap_evt.params.sec_info_request, ble_gap_evt_sec_info_request_t_enc); + + SER_EVT_ENC_END; +} + +uint32_t ble_gap_evt_sec_params_request_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GAP_EVT_SEC_PARAMS_REQUEST); + + SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PUSH_FIELD(&p_event->evt.gap_evt.params.sec_params_request, ble_gap_evt_sec_params_request_t_enc); + + SER_EVT_ENC_END; +} + +uint32_t ble_gap_evt_sec_request_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GAP_EVT_SEC_REQUEST); + + SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PUSH_FIELD(&p_event->evt.gap_evt.params.sec_request, ble_gap_evt_sec_request_t_enc); + + SER_EVT_ENC_END; +} + +uint32_t ble_gap_evt_timeout_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GAP_EVT_TIMEOUT); + + SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PUSH_uint8(&p_event->evt.gap_evt.params.timeout.src); +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 && !defined(S112) + if (p_event->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_SCAN) + { + SER_PUSH_uint16(&p_event->evt.gap_evt.params.timeout.params.adv_report_buffer.len); + } +#endif + SER_EVT_ENC_END; +} + +#if NRF_SD_BLE_API_VERSION >= 5 +uint32_t ble_gap_evt_phy_update_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GAP_EVT_PHY_UPDATE); + + SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PUSH_uint8(&p_event->evt.gap_evt.params.phy_update.status); + SER_PUSH_uint8(&p_event->evt.gap_evt.params.phy_update.tx_phy); + SER_PUSH_uint8(&p_event->evt.gap_evt.params.phy_update.rx_phy); + + SER_EVT_ENC_END; +} + +uint32_t ble_gap_evt_phy_update_request_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GAP_EVT_PHY_UPDATE_REQUEST); + + SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PUSH_FIELD(&p_event->evt.gap_evt.params.phy_update_request, ble_gap_phys_t_enc); + + SER_EVT_ENC_END; +} +#endif +#if NRF_SD_BLE_API_VERSION >= 4 && !defined(S112) +uint32_t ble_gap_evt_data_length_update_request_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST); + + SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PUSH_FIELD(&p_event->evt.gap_evt.params.data_length_update_request.peer_params, ble_gap_data_length_params_t_enc); + + SER_EVT_ENC_END; +} +uint32_t ble_gap_evt_data_length_update_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GAP_EVT_DATA_LENGTH_UPDATE); + + SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PUSH_FIELD(&p_event->evt.gap_evt.params.data_length_update.effective_params, ble_gap_data_length_params_t_enc); + + SER_EVT_ENC_END; +} +#endif // NRF_SD_BLE_API_VERSION >= 4 && !defined(S112) + +#if NRF_SD_BLE_API_VERSION > 5 +uint32_t ble_gap_evt_adv_set_terminated_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GAP_EVT_ADV_SET_TERMINATED); + + SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PUSH_FIELD(&p_event->evt.gap_evt.params.adv_set_terminated, ble_gap_evt_adv_set_terminated_t_enc); + + if (p_event->evt.gap_evt.params.adv_set_terminated.adv_data.adv_data.p_data) + { + conn_ble_gap_ble_data_buf_free(p_event->evt.gap_evt.params.adv_set_terminated.adv_data.adv_data.p_data); + } + + if (p_event->evt.gap_evt.params.adv_set_terminated.adv_data.scan_rsp_data.p_data) + { + conn_ble_gap_ble_data_buf_free(p_event->evt.gap_evt.params.adv_set_terminated.adv_data.scan_rsp_data.p_data); + } + + SER_EVT_ENC_END; +} +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gap_evt_conn.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gap_evt_conn.h new file mode 100644 index 0000000..889d0b6 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gap_evt_conn.h @@ -0,0 +1,443 @@ +/** + * 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_CONN_H__ +#define BLE_GAP_EVT_CONN_H__ + +/**@file + * + * @defgroup ble_gap_evt_conn GAP Connectivity event encoders + * @{ + * @ingroup ser_conn_s130_codecs + * + * @brief GAP Connectivity event encoders. + */ +#include "ble.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Encodes ble_gap_evt_auth_key_request event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_evt_auth_key_request_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes ble_gap_evt_auth_status event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_evt_auth_status_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes ble_gap_evt_conn_param_update event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_evt_conn_param_update_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes ble_gap_evt_conn_sec_update event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_evt_conn_sec_update_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes ble_gap_evt_connected event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_evt_connected_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes ble_gap_evt_disconnected event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_evt_disconnected_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes ble_gap_evt_passkey_display event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_evt_passkey_display_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes ble_gap_evt_rssi_changed event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_evt_rssi_changed_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes ble_gap_evt_sec_info_request event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_evt_sec_info_request_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes ble_gap_evt_sec_params_request event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_evt_sec_params_request_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes ble_gap_evt_timeout event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_evt_timeout_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes ble_gap_evt_sec_request event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_evt_sec_request_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes ble_gap_evt_conn_param_update_request event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_evt_conn_param_update_request_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes ble_gap_evt_adv_report event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_evt_adv_report_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes ble_gap_evt_scan_req_report event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_evt_scan_req_report_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + + uint32_t * const p_buf_len); +/** + * @brief Encodes ble_gap_evt_key_pressed event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_evt_key_pressed_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes ble_gap_evt_lesc_dhkey_request event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_evt_lesc_dhkey_request_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +#if NRF_SD_BLE_API_VERSION >= 5 +/** + * @brief Encodes ble_gap_evt_phy_update event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_evt_phy_update_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes ble_gap_evt_phy_update_request event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_evt_phy_update_request_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); +#endif + +#if NRF_SD_BLE_API_VERSION >= 4 +/** + * @brief Encodes ble_gap_evt_data_length_update_request event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_evt_data_length_update_request_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); +/** + * @brief Encodes ble_gap_evt_data_length_update event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_evt_data_length_update_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); +#endif +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gattc_conn.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gattc_conn.c new file mode 100644 index 0000000..a84e429 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gattc_conn.c @@ -0,0 +1,299 @@ +/** + * 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_gattc_conn.h" +#include "ble_serialization.h" +#include "ble_struct_serialization.h" +#include "ble_gattc_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" +#include <string.h> + + +uint32_t ble_gattc_attr_info_discover_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_conn_handle, + ble_gattc_handle_range_t * * const pp_handle_range) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GATTC_ATTR_INFO_DISCOVER); + + SER_ASSERT_NOT_NULL(p_conn_handle); + SER_ASSERT_NOT_NULL(pp_handle_range); + SER_ASSERT_NOT_NULL(*pp_handle_range); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_COND(pp_handle_range, ble_gattc_handle_range_t_dec); + + SER_REQ_DEC_END; +} + +uint32_t ble_gattc_attr_info_discover_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_ATTR_INFO_DISCOVER); +} + +uint32_t ble_gattc_char_value_by_uuid_read_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_conn_handle, + ble_uuid_t * * const pp_uuid, + ble_gattc_handle_range_t * * const + pp_handle_range) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ); + + SER_ASSERT_NOT_NULL(p_conn_handle); + SER_ASSERT_NOT_NULL(pp_uuid); + SER_ASSERT_NOT_NULL(*pp_uuid); + SER_ASSERT_NOT_NULL(pp_handle_range); + SER_ASSERT_NOT_NULL(*pp_handle_range); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_COND(pp_uuid, ble_uuid_t_dec); + SER_PULL_COND(pp_handle_range, ble_gattc_handle_range_t_dec); + + SER_REQ_DEC_END; +} + + +uint32_t ble_gattc_char_value_by_uuid_read_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ); +} + + +uint32_t ble_gattc_char_values_read_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_conn_handle, + uint16_t * * const pp_handles, + uint16_t * const p_handle_count) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GATTC_CHAR_VALUES_READ); + + SER_ASSERT_NOT_NULL(p_conn_handle); + SER_ASSERT_NOT_NULL(pp_handles); + SER_ASSERT_NOT_NULL(*pp_handles); + SER_ASSERT_NOT_NULL(p_handle_count); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_len16data16(pp_handles, p_handle_count); + + SER_REQ_DEC_END; +} + + +uint32_t ble_gattc_char_values_read_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_CHAR_VALUES_READ); +} + +uint32_t ble_gattc_characteristics_discover_req_dec( + uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_conn_handle, + ble_gattc_handle_range_t * * const pp_handle_range) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GATTC_CHARACTERISTICS_DISCOVER); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_COND(pp_handle_range, ble_gattc_handle_range_t_dec); + + SER_REQ_DEC_END; +} + + +uint32_t ble_gattc_characteristics_discover_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_CHARACTERISTICS_DISCOVER); +} + + +uint32_t ble_gattc_descriptors_discover_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_conn_handle, + ble_gattc_handle_range_t * * const pp_handle_range) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GATTC_DESCRIPTORS_DISCOVER); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_COND(pp_handle_range, ble_gattc_handle_range_t_dec); + + SER_REQ_DEC_END; +} + + +uint32_t ble_gattc_descriptors_discover_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_DESCRIPTORS_DISCOVER); +} + +uint32_t ble_gattc_hv_confirm_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_conn_handle, + uint16_t * const p_handle) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GATTC_HV_CONFIRM); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_uint16(p_handle); + + SER_REQ_DEC_END; +} + +uint32_t ble_gattc_hv_confirm_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_HV_CONFIRM); +} + +uint32_t ble_gattc_primary_services_discover_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_conn_handle, + uint16_t * const p_start_handle, + ble_uuid_t * * const pp_srvc_uuid) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_uint16(p_start_handle); + SER_PULL_COND(pp_srvc_uuid, ble_uuid_t_dec); + + SER_REQ_DEC_END; +} + + +uint32_t ble_gattc_primary_services_discover_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER); +} + +uint32_t ble_gattc_read_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_conn_handle, + uint16_t * const p_handle, + uint16_t * const p_offset) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GATTC_READ); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_uint16(p_handle); + SER_PULL_uint16(p_offset); + + SER_REQ_DEC_END; +} + +uint32_t ble_gattc_read_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_READ); +} + +uint32_t ble_gattc_relationships_discover_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_conn_handle, + ble_gattc_handle_range_t * * const pp_handle_range) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GATTC_RELATIONSHIPS_DISCOVER); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_COND(pp_handle_range, ble_gattc_handle_range_t_dec); + + SER_REQ_DEC_END; +} + + +uint32_t ble_gattc_relationships_discover_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_RELATIONSHIPS_DISCOVER); +} + +uint32_t ble_gattc_write_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_conn_handle, + ble_gattc_write_params_t * * const pp_write_params) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GATTC_WRITE); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_COND(pp_write_params, ble_gattc_write_params_t_dec); + + SER_REQ_DEC_END; +} + +uint32_t ble_gattc_write_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_WRITE); +} + +uint32_t ble_gattc_exchange_mtu_request_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_conn_handle, + uint16_t * const p_client_rx_mtu) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GATTC_EXCHANGE_MTU_REQUEST); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_uint16(p_client_rx_mtu); + + SER_REQ_DEC_END; +} + +uint32_t ble_gattc_exchange_mtu_request_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_EXCHANGE_MTU_REQUEST); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gattc_conn.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gattc_conn.h new file mode 100644 index 0000000..1654f9c --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gattc_conn.h @@ -0,0 +1,481 @@ +/** + * 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_CONN_H__ +#define BLE_GATTC_CONN_H__ + +/**@file + * + * @defgroup ble_gatc_conn GATTC connectivity command request decoders and command response encoders + * @{ + * @ingroup ser_conn_s130_codecs + * + * @brief GATTC Connectivity command request decoders and command response encoders + */ +#include "ble_gattc.h" +#include "ble.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/**@brief Decodes @ref sd_ble_gattc_characteristics_discover command request. + * + * @sa @ref ble_gattc_characteristics_discover_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_handle Pointer to connection handle. + * @param[out] pp_handle_range Pointer to pointer to handle range. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Invalid value for handle range field present. + */ +uint32_t ble_gattc_characteristics_discover_req_dec + (uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_conn_handle, + ble_gattc_handle_range_t * * const pp_handle_range); + +/**@brief Encodes @ref sd_ble_gattc_characteristics_discover command response. + * + * @sa @ref ble_gattc_characteristics_discover_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[in] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_characteristics_discover_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_gattc_descriptors_discover command request. + * + * @sa @ref ble_gattc_descriptors_discover_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_handle Pointer to connection handle. + * @param[out] pp_handle_range Pointer to pointer to handle range. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Invalid value for handle range field present. + */ +uint32_t ble_gattc_descriptors_discover_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_conn_handle, + ble_gattc_handle_range_t * * const pp_handle_range); + +/**@brief Encodes @ref sd_ble_gattc_descriptors_discover command response. + * + * @sa @ref ble_gattc_descriptors_discover_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[in] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_descriptors_discover_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_gattc_relationships_discover command request. + * + * @sa @ref ble_gattc_relationships_discover_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_handle Pointer to connection handle. + * @param[out] pp_handle_range Pointer to pointer to handle range. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Invalid value for handle range field present. + */ +uint32_t ble_gattc_relationships_discover_req_dec + (uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_conn_handle, + ble_gattc_handle_range_t * * const pp_handle_range); + +/**@brief Encodes @ref sd_ble_gattc_relationships_discover command response. + * + * @sa @ref ble_gattc_relationships_discover_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[in] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_relationships_discover_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_gattc_primary_services_discover command request. + * + * @sa @ref ble_gattc_primary_services_discover_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_handle Pointer to connection handle. + * @param[out] p_start_handle Pointer to start handle. + * @param[out] pp_srvc_uuid Pointer to pointer to service uuid. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Invalid value for uuid field present. + */ +uint32_t ble_gattc_primary_services_discover_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_conn_handle, + uint16_t * const p_start_handle, + ble_uuid_t * * const pp_srvc_uuid); + +/**@brief Encodes @ref sd_ble_gattc_primary_services_discover command response. + * + * @sa @ref ble_gattc_primary_services_discover_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[in] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_primary_services_discover_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_gattc_read command request. + * + * @sa @ref ble_gattc_read_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_handle Pointer to connection handle. + * @param[out] p_handle Pointer to handle. + * @param[out] p_offset Pointer to offset. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_read_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_conn_handle, + uint16_t * const p_handle, + uint16_t * const p_offset); + +/**@brief Encodes @ref sd_ble_gattc_read command response. + * + * @sa @ref ble_gattc_read_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[in] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_read_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_gattc_char_values_read command request. + * + * @sa @ref ble_gattc_char_values_read_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_handle Pointer to connection handle. + * @param[out] pp_handles Pointer to pointer to handle table. + * @param[out] p_handle_count Pointer to handle handle table count. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ + +uint32_t ble_gattc_char_values_read_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_conn_handle, + uint16_t * * const pp_handles, + uint16_t * const p_handle_count); + +/**@brief Encodes @ref sd_ble_gattc_char_values_read command response. + * + * @sa @ref ble_gattc_char_values_read_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[in] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_char_values_read_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_gattc_write command request. + * + * @sa @ref ble_gattc_write_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_handle Pointer to connection handle. + * @param[out] pp_write_params Pointer to pointer to write parameters. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_write_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_conn_handle, + ble_gattc_write_params_t * * const pp_write_params); + +/**@brief Encodes @ref sd_ble_gattc_write command response. + * + * @sa @ref ble_gattc_write_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[in] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_write_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_gattc_hv_confirm command request. + * + * @sa @ref ble_gattc_hv_confirm_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_handle Pointer to connection handle. + * @param[out] p_handle Pointer to handle of the attribute in the indication. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_hv_confirm_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_conn_handle, + uint16_t * const p_handle); + +/**@brief Encodes @ref sd_ble_gattc_hv_confirm command response. + * + * @sa @ref ble_gattc_hv_confirm_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[in] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_hv_confirm_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_gattc_char_value_by_uuid_read command request. + * + * @sa @ref ble_gattc_char_value_by_uuid_read_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of request packet. + * @param[out] p_conn_handle Pointer to connection handle of the connection. + * @param[out] pp_uuid Pointer to pointer to a characteristic value UUID to read. + * @param[out] pp_handle_range Pointer to pointer to the range of handles to perform this + * procedure on. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Invalid operation type. + */ +uint32_t ble_gattc_char_value_by_uuid_read_req_dec + (uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_conn_handle, + ble_uuid_t * * const pp_uuid, + ble_gattc_handle_range_t * * const pp_handle_range); + +/**@brief Encodes @ref sd_ble_gattc_char_value_by_uuid_read command response. + * + * @sa @ref ble_gattc_char_value_by_uuid_read_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[in] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_char_value_by_uuid_read_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_gattc_attr_info_discover command request. + * + * @sa @ref ble_gattc_attr_info_discover_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] buf_len Length (in bytes) of request packet. + * @param[out] p_conn_handle Pointer to connection handle of the connection. + * @param[out] pp_handle_range Pointer to pointer to the range of handles. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Invalid operation type. + */ +uint32_t ble_gattc_attr_info_discover_req_dec(uint8_t const * const p_buf, + uint16_t buf_len, + uint16_t * const p_conn_handle, + ble_gattc_handle_range_t * * const pp_handle_range); + +/**@brief Encodes @ref sd_ble_gattc_attr_info_discover command response. + * + * @sa @ref ble_gattc_attr_info_discover_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[in] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_attr_info_discover_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_gattc_exchange_mtu_request command request. + * + * @sa @ref ble_gattc_exchange_mtu_request_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of request packet. + * @param[out] p_conn_handle Pointer to connection handle of the connection. + * @param[out] p_client_rx_mtu Pointer to Client RX MTU size. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Invalid operation type. + */ +uint32_t ble_gattc_exchange_mtu_request_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_conn_handle, + uint16_t * const p_client_rx_mtu); + +/**@brief Encodes @ref sd_ble_gattc_exchange_mtu_request command response. + * + * @sa @ref ble_gattc_exchange_mtu_request_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[in] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_exchange_mtu_request_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gattc_evt_conn.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gattc_evt_conn.c new file mode 100644 index 0000000..307e6e2 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gattc_evt_conn.c @@ -0,0 +1,253 @@ +/** + * Copyright (c) 2016 - 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_conn.h" +#include "ble_serialization.h" +#include "ble_gattc_struct_serialization.h" +#include "app_util.h" +#include <string.h> + +uint32_t ble_gattc_evt_attr_info_disc_rsp_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_ATTR_INFO_DISC_RSP); + + SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle); + SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status); + SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle); + SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.attr_info_disc_rsp, + ble_gattc_evt_attr_info_disc_rsp_t_enc); + + SER_EVT_ENC_END; +} + +uint32_t ble_gattc_evt_char_disc_rsp_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_CHAR_DISC_RSP); + + SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle); + SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status); + SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle); + SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.char_disc_rsp, + ble_gattc_evt_char_disc_rsp_t_enc); + + SER_EVT_ENC_END; +} + +uint32_t ble_gattc_evt_char_val_by_uuid_read_rsp_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP); + + SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle); + SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status); + SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle); + SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.char_val_by_uuid_read_rsp, + ble_gattc_evt_char_val_by_uuid_read_rsp_t_enc); + + SER_EVT_ENC_END; +} + +uint32_t ble_gattc_evt_char_vals_read_rsp_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_CHAR_VALS_READ_RSP); + + SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle); + SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status); + SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle); + SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.char_vals_read_rsp, + ble_gattc_evt_char_vals_read_rsp_t_enc); + + SER_EVT_ENC_END; +} + +uint32_t ble_gattc_evt_desc_disc_rsp_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_DESC_DISC_RSP); + + SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle); + SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status); + SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle); + SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.desc_disc_rsp, + ble_gattc_evt_desc_disc_rsp_t_enc); + + SER_EVT_ENC_END; +} + +uint32_t ble_gattc_evt_hvx_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_HVX); + + SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle); + SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status); + SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle); + SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.hvx, ble_gattc_evt_hvx_t_enc); + + SER_EVT_ENC_END; +} + +uint32_t ble_gattc_evt_prim_srvc_disc_rsp_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP); + + SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle); + SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status); + SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle); + SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.prim_srvc_disc_rsp, + ble_gattc_evt_prim_srvc_disc_rsp_t_enc); + + SER_EVT_ENC_END; +} + +uint32_t ble_gattc_evt_read_rsp_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_READ_RSP); + + SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle); + SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status); + SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle); + SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.read_rsp, + ble_gattc_evt_read_rsp_t_enc); + + SER_EVT_ENC_END; +} + +uint32_t ble_gattc_evt_rel_disc_rsp_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_REL_DISC_RSP); + + SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle); + SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status); + SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle); + SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.rel_disc_rsp, + ble_gattc_evt_rel_disc_rsp_t_enc); + + SER_EVT_ENC_END; +} + +uint32_t ble_gattc_evt_timeout_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_TIMEOUT); + + SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle); + SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status); + SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle); + SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.timeout, + ble_gattc_evt_timeout_t_enc); + + SER_EVT_ENC_END; +} + +uint32_t ble_gattc_evt_write_rsp_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_WRITE_RSP); + + SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle); + SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status); + SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle); + SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.write_rsp, + ble_gattc_evt_write_rsp_t_enc); + + SER_EVT_ENC_END; +} + +uint32_t ble_gattc_evt_exchange_mtu_rsp_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_EXCHANGE_MTU_RSP); + + SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle); + SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status); + SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle); + SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.exchange_mtu_rsp, + ble_gattc_evt_exchange_mtu_rsp_t_enc); + + SER_EVT_ENC_END; +} + +#if NRF_SD_BLE_API_VERSION >= 4 + +uint32_t ble_gattc_evt_write_cmd_tx_complete_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE); + + SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle); + SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status); + SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle); + SER_PUSH_uint8(&p_event->evt.gattc_evt.params.write_cmd_tx_complete.count); + + SER_EVT_ENC_END; +} +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gattc_evt_conn.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gattc_evt_conn.h new file mode 100644 index 0000000..efecb20 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gattc_evt_conn.h @@ -0,0 +1,300 @@ +/** + * 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_CONN_H__ +#define BLE_GATTC_EVT_CONN_H__ + +/**@file + * + * @defgroup ble_gattc_evt_conn GATTC Connectivity event encoders + * @{ + * @ingroup ser_conn_s130_codecs + * + * @brief GATTC Connectivity event encoders. + */ +#include "ble.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Encodes ble_gattc_evt_char_disc_rsp event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_evt_char_disc_rsp_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes ble_gattc_evt_char_val_by_uuid_read_rsp event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_evt_char_val_by_uuid_read_rsp_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes ble_gattc_evt_char_vals_read_rsp event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_evt_char_vals_read_rsp_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes ble_gattc_evt_desc_disc_rsp event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_evt_desc_disc_rsp_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes ble_gattc_evt_hvx event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_evt_hvx_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes ble_gattc_evt_prim_srvc_disc_rsp event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_evt_prim_srvc_disc_rsp_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes ble_gattc_evt_read_rsp event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_evt_read_rsp_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes ble_gattc_evt_rel_disc_rsp event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_evt_rel_disc_rsp_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes ble_gattc_evt_timeout event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_evt_timeout_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes ble_gattc_evt_write_rsp event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_evt_write_rsp_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes ble_gattc_evt_attr_info_disc_rsp event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_evt_attr_info_disc_rsp_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes ble_gattc_evt_exchange_mtu_rsp event. + * + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ + +uint32_t ble_gattc_evt_exchange_mtu_rsp_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +#if NRF_SD_BLE_API_VERSION >= 4 +/** + * @brief Encodes @ref BLE_gattc_EVT_WRITE_CMD_TX_COMPLETE event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_evt_write_cmd_tx_complete_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); +#endif +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gatts_conn.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gatts_conn.c new file mode 100644 index 0000000..1feb000 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gatts_conn.c @@ -0,0 +1,421 @@ +/** + * 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_gatts_conn.h" +#include <string.h> +#include "ble_serialization.h" +#include "ble_struct_serialization.h" +#include "ble_gatts_struct_serialization.h" +#include "app_util.h" +#include "cond_field_serialization.h" + +uint32_t ble_gatts_attr_get_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * p_handle, + ble_uuid_t * * pp_uuid, + ble_gatts_attr_md_t * * pp_md) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GATTS_ATTR_GET); + + SER_PULL_uint16(p_handle); + SER_PULL_COND(pp_uuid, NULL); + SER_PULL_COND(pp_md, NULL); + + SER_REQ_DEC_END; +} + + +uint32_t ble_gatts_attr_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + ble_uuid_t * p_uuid, + ble_gatts_attr_md_t * p_md) +{ + SER_RSP_ENC_BEGIN(SD_BLE_GATTS_ATTR_GET); + + SER_PUSH_COND(p_uuid, ble_uuid_t_enc); + SER_PUSH_COND(p_md, ble_gatts_attr_md_t_enc); + + SER_RSP_ENC_END; +} + +uint32_t ble_gatts_characteristic_add_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * p_service_handle, + ble_gatts_char_md_t * * const pp_char_md, + ble_gatts_attr_t * * const pp_attr_char_value, + ble_gatts_char_handles_t * * const pp_handles) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GATTS_CHARACTERISTIC_ADD); + + SER_PULL_uint16(p_service_handle); + SER_PULL_COND(pp_char_md, ble_gatts_char_md_t_dec); + SER_PULL_COND(pp_attr_char_value, ble_gatts_attr_t_dec); + SER_PULL_COND(pp_handles, NULL); + + SER_REQ_DEC_END; +} + +uint32_t ble_gatts_characteristic_add_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + ble_gatts_char_handles_t const * const p_handles) +{ + SER_RSP_ENC_BEGIN(SD_BLE_GATTS_CHARACTERISTIC_ADD); + + SER_PUSH_COND(p_handles, ble_gatts_char_handles_t_enc); + + SER_RSP_ENC_END; +} + +uint32_t ble_gatts_descriptor_add_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_char_handle, + ble_gatts_attr_t * * const pp_attr, + uint16_t * * const pp_handle) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GATTS_DESCRIPTOR_ADD); + + SER_PULL_uint16(p_char_handle); + SER_PULL_COND(pp_attr, ble_gatts_attr_t_dec); + SER_PULL_COND(pp_handle, NULL); + + SER_REQ_DEC_END; +} + +uint32_t ble_gatts_descriptor_add_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint16_t * p_handle) +{ + SER_RSP_ENC_BEGIN(SD_BLE_GATTS_DESCRIPTOR_ADD); + + SER_PUSH_COND(p_handle,uint16_t_enc); + + SER_RSP_ENC_END; +} + +uint32_t ble_gatts_hvx_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_conn_handle, + ble_gatts_hvx_params_t * * const pp_hvx_params) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GATTS_HVX); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_COND(pp_hvx_params, ble_gatts_hvx_params_t_dec); + + SER_REQ_DEC_END; +} + +uint32_t ble_gatts_hvx_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint16_t const * const p_bytes_written) +{ + SER_RSP_ENC_BEGIN(SD_BLE_GATTS_HVX); + + SER_PUSH_COND(p_bytes_written, uint16_t_enc); + + SER_RSP_ENC_END; +} + +uint32_t ble_gatts_include_add_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_service_handle, + uint16_t * const p_inc_srvc_handle, + uint16_t * * const pp_include_handle) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GATTS_INCLUDE_ADD); + + SER_PULL_uint16(p_service_handle); + SER_PULL_uint16(p_inc_srvc_handle); + SER_PULL_COND(pp_include_handle, NULL); + + SER_REQ_DEC_END; +} + + +uint32_t ble_gatts_include_add_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint16_t const * const p_include_handle) +{ + SER_RSP_ENC_BEGIN(SD_BLE_GATTS_INCLUDE_ADD); + + SER_PUSH_COND(p_include_handle, uint16_t_enc); + + SER_RSP_ENC_END; +} + +uint32_t ble_gatts_initial_user_handle_get_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * * pp_handle) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GATTS_INITIAL_USER_HANDLE_GET); + + SER_PULL_COND(pp_handle, NULL); + + SER_REQ_DEC_END; +} + + +uint32_t ble_gatts_initial_user_handle_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint16_t * p_handle) +{ + SER_RSP_ENC_BEGIN(SD_BLE_GATTS_INITIAL_USER_HANDLE_GET); + + SER_PUSH_COND(p_handle, uint16_t_enc); + + SER_RSP_ENC_END; +} + +uint32_t ble_gatts_rw_authorize_reply_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * p_conn_handle, + ble_gatts_rw_authorize_reply_params_t * * const pp_reply_params) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GATTS_RW_AUTHORIZE_REPLY); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_COND(pp_reply_params, ble_gatts_rw_authorize_reply_params_t_dec); + SER_REQ_DEC_END; +} + +uint32_t ble_gatts_rw_authorize_reply_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTS_RW_AUTHORIZE_REPLY); +} + +uint32_t ble_gatts_service_add_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_type, + ble_uuid_t * * const pp_uuid, + uint16_t * * const pp_handle) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GATTS_SERVICE_ADD); + + SER_PULL_uint8(p_type); + SER_PULL_COND(pp_uuid, ble_uuid_t_dec); + SER_PULL_COND(pp_handle, NULL); + + SER_REQ_DEC_END; +} + +uint32_t ble_gatts_service_add_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint16_t const * const p_handle) +{ + SER_RSP_ENC_BEGIN(SD_BLE_GATTS_SERVICE_ADD); + + SER_PUSH_COND(p_handle, uint16_t_enc); + //SER_PUSH_uint16(p_handle); + + SER_RSP_ENC_END; +} + +uint32_t ble_gatts_service_changed_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * p_conn_handle, + uint16_t * p_start_handle, + uint16_t * p_end_handle) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GATTS_SERVICE_CHANGED); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_uint16(p_start_handle); + SER_PULL_uint16(p_end_handle); + + SER_REQ_DEC_END; +} + + +uint32_t ble_gatts_service_changed_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTS_SERVICE_CHANGED); +} + +uint32_t ble_gatts_sys_attr_get_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_conn_handle, + uint8_t * * const pp_sys_attr_data, + uint16_t * * const pp_sys_attr_data_len, + uint32_t * const p_flags) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GATTS_SYS_ATTR_GET); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_COND(pp_sys_attr_data_len, uint16_t_dec); + SER_PULL_COND(pp_sys_attr_data, NULL); + SER_PULL_uint32(p_flags); + + SER_REQ_DEC_END; +} + + +uint32_t ble_gatts_sys_attr_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint8_t const * const p_sys_attr_data, + uint16_t const * const p_sys_attr_data_len) +{ + SER_RSP_ENC_BEGIN(SD_BLE_GATTS_SYS_ATTR_GET); + + SER_PUSH_COND(p_sys_attr_data_len, uint16_t_enc); + if (p_sys_attr_data_len) + { + SER_PUSH_buf(p_sys_attr_data, *p_sys_attr_data_len); + } + + SER_RSP_ENC_END; +} + +uint32_t ble_gatts_sys_attr_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_conn_handle, + uint8_t * * const pp_sys_attr_data, + uint16_t * const p_sys_attr_data_len, + uint32_t * const p_flags) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GATTS_SYS_ATTR_SET); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_len16data(pp_sys_attr_data, p_sys_attr_data_len); + SER_PULL_uint32(p_flags); + + SER_REQ_DEC_END; +} + +uint32_t ble_gatts_sys_attr_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTS_SYS_ATTR_SET); +} + +uint32_t ble_gatts_value_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_conn_handle, + uint16_t * const p_handle, + ble_gatts_value_t * * const pp_value) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GATTS_VALUE_GET); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_uint16(p_handle); + + //Special case: skip the data. + SER_PULL_COND(pp_value, NULL); + if (*pp_value) + { + SER_PULL_uint16(&(*pp_value)->offset); + SER_PULL_uint16(&(*pp_value)->len); + SER_PULL_COND(&(*pp_value)->p_value, NULL); + } + + SER_REQ_DEC_END; +} + +uint32_t ble_gatts_value_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + ble_gatts_value_t * const p_value) +{ + SER_RSP_ENC_BEGIN(SD_BLE_GATTS_VALUE_GET); + + SER_PUSH_COND(p_value, ble_gatts_value_t_enc); + + SER_RSP_ENC_END; +} + +uint32_t ble_gatts_value_set_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * p_conn_handle, + uint16_t * p_handle, + ble_gatts_value_t * * const pp_value) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GATTS_VALUE_SET); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_uint16(p_handle); + SER_PULL_COND(pp_value, ble_gatts_value_t_dec); + + SER_REQ_DEC_END; +} + + +uint32_t ble_gatts_value_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + ble_gatts_value_t * p_value) +{ + SER_RSP_ENC_BEGIN(SD_BLE_GATTS_VALUE_SET); + + SER_PUSH_COND(p_value, ble_gatts_value_t_enc); + + SER_RSP_ENC_END; +} + + +uint32_t ble_gatts_exchange_mtu_reply_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_conn_handle, + uint16_t * const p_server_rx_mtu) +{ + SER_REQ_DEC_BEGIN(SD_BLE_GATTS_EXCHANGE_MTU_REPLY); + + SER_PULL_uint16(p_conn_handle); + SER_PULL_uint16(p_server_rx_mtu); + + SER_REQ_DEC_END; +} + +uint32_t ble_gatts_exchange_mtu_reply_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTS_EXCHANGE_MTU_REPLY); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gatts_conn.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gatts_conn.h new file mode 100644 index 0000000..0d56e0f --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gatts_conn.h @@ -0,0 +1,634 @@ +/** + * 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_CONN_H__ +#define BLE_GATTS_CONN_H__ + +/**@file + * + * @defgroup ble_gatts_conn GATTS Connectivity command request decoders and command response encoders + * @{ + * @ingroup ser_conn_s130_codecs + * + * @brief GATTS Connectivity command request decoders and command response encoders. + */ + +#include "ble_gatts.h" +#include "ble.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/**@brief Decodes @ref sd_ble_gatts_value_get command request. + * + * @sa @ref ble_gatts_value_get_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of request packet. + * @param[out] p_conn_handle Pointer to the connection_handle. + * @param[out] p_handle Pointer to the attribute_handle. + * @param[out] pp_value Pointer to pointer to the Attribute Value structure. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_value_get_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_conn_handle, + uint16_t * const p_handle, + ble_gatts_value_t * * const pp_value); + +/**@brief Encodes @ref sd_ble_gatts_value_get command response. + * + * @sa @ref ble_gatts_value_get_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_value Pointer to Attribute Value structure. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_value_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + ble_gatts_value_t * const p_value); + +/**@brief Decodes @ref sd_ble_gatts_characteristic_add command request. + * + * @sa @ref ble_gatts_characteristic_add_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of request packet. + * @param[out] p_service_handle Pointer to the service_handle. + * @param[out] constpp_char_md Pointer to pointer to the location where Characteristic metadata + * will be decoded. + * @param[out] pp_attr_char_value Pointer to pointer to the location where GATT Attribute will be + * decoded. + * @param[out] pp_handles Pointer to pointer to the location where Characteristic definition + * handles will be decoded. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_characteristic_add_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * p_service_handle, + ble_gatts_char_md_t * * constpp_char_md, + ble_gatts_attr_t * * const pp_attr_char_value, + ble_gatts_char_handles_t * * const pp_handles); + +/**@brief Encodes @ref ble_gatts_sys_attr_get_rsp_enc command response. + * + * @sa @ref ble_gatts_sys_attr_get_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_handles Pointer to handle struct to be encoded. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_characteristic_add_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + ble_gatts_char_handles_t const * const p_handles); + +/**@brief Decodes @ref sd_ble_gatts_include_add command request. + * + * @sa @ref ble_gatts_include_add_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of request packet. + * @param[out] p_service_handle Pointer to the service_handle. + * @param[out] p_inc_srvc_handle Pointer to the handle of the included service. + * @param[out] pp_include_handle Pointer to Pointer to 16-bit word where the assigned handle will be stored. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ + +uint32_t ble_gatts_include_add_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_service_handle, + uint16_t * const p_inc_srvc_handle, + uint16_t * * const pp_include_handle); + +/**@brief Encodes @ref ble_gatts_include_add_rsp_enc command response. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_include_handle Pointer to a 16-bit word where the assigned handle was stored. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ + +uint32_t ble_gatts_include_add_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint16_t const * const p_include_handle); + +/**@brief Decodes @ref sd_ble_gatts_service_add command request. + * + * @sa @ref ble_gatts_service_add_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of request packet. + * @param[out] p_type Pointer to the service type. + * @param[out] pp_uuid Pointer to pointer to service UUID. + * @param[out] pp_handle Pointer to pointer to a 16-bit word where the assigned handle will be stored. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ + +uint32_t ble_gatts_service_add_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_type, + ble_uuid_t * * const pp_uuid, + uint16_t * * const pp_handle); + +/**@brief Encodes @ref ble_gatts_service_add_rsp_enc command response. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_handle Pointer to a 16-bit word where the assigned handle was stored. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ + +uint32_t ble_gatts_service_add_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint16_t const * const p_handle); + +/**@brief Decodes @ref ble_gatts_sys_attr_get_req_dec command request. + * + * @sa @ref ble_gatts_sys_attr_get_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_handle Pointer to connectiton handle. + * @param[out] pp_sys_attr_data Pointer to pointer to buffer where system attributes data will be filled in. + * @param[out] pp_sys_attr_data_len Pointer to pointer to variable which contains size of buffer for system attributes. + * @param[out] p_flags Pointer to additional optional flags. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_gatts_sys_attr_get_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_conn_handle, + uint8_t * * const pp_sys_attr_data, + uint16_t * * const pp_sys_attr_data_len, + uint32_t * const p_flags); + +/**@brief Encodes @ref ble_gatts_sys_attr_get_rsp_enc command response. + * + * @sa @ref ble_gatts_sys_attr_get_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_sys_attr_data Pointer to buffer where system attributes data are stored. + * @param[in] p_sys_attr_data_len Pointer to variable which contains size of buffer for system attributes. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_sys_attr_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint8_t const * const p_sys_attr_data, + uint16_t const * const p_sys_attr_data_len); + +/**@brief Decodes @ref sd_ble_gatts_value_set command request. + * + * @sa @ref ble_gatts_value_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_handle Pointer to connection handle. + * @param[out] p_handle Pointer to attribute handle. + * @param[out] pp_value Pointer to pointer to attribute value structure. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ + +uint32_t ble_gatts_value_set_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * p_conn_handle, + uint16_t * p_handle, + ble_gatts_value_t * * const pp_value); + +/**@brief Encodes @ref sd_ble_gatts_value_set command response. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[in] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_value \c in: size of value returned when value was written with success + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_value_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + ble_gatts_value_t * p_value); + +/**@brief Decodes @ref sd_ble_gatts_sys_attr_set command request. + * + * @sa @ref ble_gatts_sys_attr_set_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of request packet. + * @param[out] p_conn_handle Pointer to the buffer raw data to be placed in advertisement packet. + * @param[out] pp_sys_attr_data Pointer to pointer to system attribute data. + * @param[out] p_sys_attr_data_len Pointer to data length for system attribute data. + * @param[out] p_flags Pointer to additional optional flags. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_sys_attr_set_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_conn_handle, + uint8_t * * const pp_sys_attr_data, + uint16_t * const p_sys_attr_data_len, + uint32_t * const p_flags); + +/**@brief Encodes @ref sd_ble_gatts_sys_attr_set command response. + * + * @sa @ref ble_gatts_sys_attr_set_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_sys_attr_set_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref ble_gatts_hvx_req_dec command request. + * + * @sa @ref ble_gatts_hvx_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of request packet. + * @param[out] p_conn_handle Pointer to the buffer raw data to be placed in advertisement packet. + * @param[out] pp_hvx_params Pointer to an HVx parameters structure. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_hvx_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_conn_handle, + ble_gatts_hvx_params_t * * const pp_hvx_params); + +/**@brief Encodes @ref ble_gatts_hvx_rsp_enc command response. + * + * @sa @ref ble_gatts_hvx_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_bytes_written Pointer to number of bytes written. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_hvx_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint16_t const * const p_bytes_written); + +/**@brief Decodes @ref sd_ble_gatts_descriptor_add command request. + * + * @sa @ref ble_gatts_descriptor_add_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of request packet. + * @param[out] p_char_handle Pointer to buffer where characteristic handle will be. + returned. + * @param[out] pp_attr Pointer to pointer to an attribute structure. + * @param[out] pp_handle Pointer to pointer to descriptor handle. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_descriptor_add_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_char_handle, + ble_gatts_attr_t * * const pp_attr, + uint16_t * * const pp_handle); + +/**@brief Encodes @ref sd_ble_gatts_descriptor_add command response. + * + * @sa @ref ble_gatts_descriptor_add_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_handle Pointer to descriptor handle value. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_descriptor_add_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint16_t * p_handle); + +/**@brief Decodes @ref sd_ble_gatts_rw_authorize_reply command request. + * + * @sa @ref ble_gatts_rw_authorize_reply_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_handle Pointer to connection handle. + * @param[out] pp_reply_params Pointer to pointer to \ref ble_gatts_rw_authorize_reply_params_t . + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ + +uint32_t ble_gatts_rw_authorize_reply_req_dec( + uint8_t const * const p_buf, + uint32_t + packet_len, + uint16_t * + p_conn_handle, + ble_gatts_rw_authorize_reply_params_t * * const + pp_reply_params); + +/**@brief Encodes @ref sd_ble_gatts_rw_authorize_reply command response. + * + * @sa @ref ble_gatts_rw_authorize_reply_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_rw_authorize_reply_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_gatts_service_changed command request. + * + * @sa @ref ble_gatts_service_changed_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_handle Pointer to connection handle. + * @param[out] p_start_handle Pointer to start handle. + * @param[out] p_end_handle Pointer to end handle. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_gatts_service_changed_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * p_conn_handle, + uint16_t * p_start_handle, + uint16_t * p_end_handle); + +/**@brief Encodes @ref sd_ble_gatts_service_changed command response. + * + * @sa @ref ble_gatts_service_changed_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_service_changed_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref ble_gatts_attr_get_req_dec command request. + * + * @sa @ref ble_gatts_attr_get_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_handle Pointer to handle. + * @param[out] pp_uuid Pointer to pointer to location for decoded uuid structure. + * @param[out] pp_md Pointer to pointer to location for md structure. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_gatts_attr_get_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * p_handle, + ble_uuid_t * * pp_uuid, + ble_gatts_attr_md_t * * pp_md); + +/**@brief Encodes @ref ble_gatts_attr_get_rsp_enc command response. + * + * @sa @ref ble_gatts_attr_get_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_uuid Pointer to structure to be encoded. + * @param[in] p_md Pointer to structure to be encoded. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_attr_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + ble_uuid_t * p_uuid, + ble_gatts_attr_md_t * p_md); + +/**@brief Decodes @ref ble_gatts_initial_user_handle_get_req_dec command request. + * + * @sa @ref ble_gatts_initial_user_handle_get_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] pp_handle Pointer to pointer to handle. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_gatts_initial_user_handle_get_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * * pp_handle); + +/**@brief Encodes @ref ble_gatts_initial_user_handle_get_rsp_enc command response. + * + * @sa @ref ble_gatts_initial_user_handle_get_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_handle Pointer to handle to be encoded. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_initial_user_handle_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint16_t * p_handle); + +/**@brief Decodes @ref sd_ble_gatts_rw_authorize_reply command request. + * + * @ref ble_gatts_exchange_mtu_reply_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_handle Pointer to connection handle. + * @param[out] p_server_rx_mtu Pointer to Server RX MTU size. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ + +uint32_t ble_gatts_exchange_mtu_reply_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * const p_conn_handle, + uint16_t * const p_server_rx_mtu); + +/**@brief Encodes @ref sd_ble_gatts_rw_authorize_reply command response. + * + * @ref ble_gatts_exchange_mtu_reply_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_exchange_mtu_reply_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif //BLE_GATTS_CONN_H__ + diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gatts_evt_conn.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gatts_evt_conn.c new file mode 100644 index 0000000..252c571 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gatts_evt_conn.c @@ -0,0 +1,178 @@ +/** + * 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_gatts_evt_conn.h" +#include "ble_serialization.h" +#include "ble_gatts_struct_serialization.h" +#include "conn_ble_user_mem.h" +#include "app_util.h" + +extern sercon_ble_user_mem_t m_conn_user_mem_table[]; + + +uint32_t ble_gatts_evt_rw_authorize_request_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST); + + SER_PUSH_uint16(&p_event->evt.gatts_evt.conn_handle); + SER_PUSH_FIELD(&p_event->evt.gatts_evt.params.authorize_request, ble_gatts_evt_rw_authorize_request_t_enc); + + if ((p_event->evt.gatts_evt.params.authorize_request.type == BLE_GATTS_AUTHORIZE_TYPE_WRITE) && + ((p_event->evt.gatts_evt.params.authorize_request.request.write.op == BLE_GATTS_OP_EXEC_WRITE_REQ_NOW) || + (p_event->evt.gatts_evt.params.authorize_request.request.write.op == BLE_GATTS_OP_PREP_WRITE_REQ))) + { + uint32_t conn_index; + + if (conn_ble_user_mem_context_find(p_event->evt.gatts_evt.conn_handle, &conn_index) != NRF_ERROR_NOT_FOUND) + { + err_code = len16data_enc(m_conn_user_mem_table[conn_index].mem_block.p_mem, m_conn_user_mem_table[conn_index].mem_block.len, p_buf, *p_buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + } + } + + SER_EVT_ENC_END; +} + + +uint32_t ble_gatts_evt_hvc_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GATTS_EVT_HVC); + + SER_PUSH_uint16(&p_event->evt.gatts_evt.conn_handle); + SER_PUSH_FIELD(&p_event->evt.gatts_evt.params.hvc, ble_gatts_evt_hvc_t_enc); + + SER_EVT_ENC_END; +} + + +uint32_t ble_gatts_evt_sc_confirm_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GATTS_EVT_HVC); + SER_PUSH_uint16(&p_event->evt.gatts_evt.conn_handle); + SER_EVT_ENC_END; +} + + +uint32_t ble_gatts_evt_sys_attr_missing_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GATTS_EVT_SYS_ATTR_MISSING); + + SER_PUSH_uint16(&p_event->evt.gatts_evt.conn_handle); + SER_PUSH_FIELD(&p_event->evt.gatts_evt.params.sys_attr_missing, ble_gatts_evt_sys_attr_missing_t_enc); + + SER_EVT_ENC_END; +} + + +uint32_t ble_gatts_evt_timeout_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GATTS_EVT_TIMEOUT); + + SER_PUSH_uint16(&p_event->evt.gatts_evt.conn_handle); + SER_PUSH_FIELD(&p_event->evt.gatts_evt.params.timeout, ble_gatts_evt_timeout_t_enc); + + SER_EVT_ENC_END; +} + + +uint32_t ble_gatts_evt_write_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GATTS_EVT_WRITE); + + SER_PUSH_uint16(&p_event->evt.gatts_evt.conn_handle); + SER_PUSH_FIELD(&p_event->evt.gatts_evt.params.write, ble_gatts_evt_write_t_enc); + + if ((p_event->evt.gatts_evt.params.write.op == BLE_GATTS_OP_WRITE_REQ) || (p_event->evt.gatts_evt.params.write.op == BLE_GATTS_OP_EXEC_WRITE_REQ_NOW)) + { + uint32_t conn_index; + if (conn_ble_user_mem_context_find(p_event->evt.gatts_evt.conn_handle, &conn_index) != NRF_ERROR_NOT_FOUND) + { + SER_PUSH_len16data(m_conn_user_mem_table[conn_index].mem_block.p_mem, m_conn_user_mem_table[conn_index].mem_block.len); + } + } + + SER_EVT_ENC_END; +} + + +uint32_t ble_gatts_evt_exchange_mtu_request_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST); + + SER_PUSH_uint16(&p_event->evt.gatts_evt.conn_handle); + SER_PUSH_FIELD(&p_event->evt.gatts_evt.params.exchange_mtu_request, ble_gatts_evt_exchange_mtu_request_t_enc); + + SER_EVT_ENC_END; +} + +#if NRF_SD_BLE_API_VERSION >= 4 +uint32_t ble_gatts_evt_hvn_tx_complete_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_GATTS_EVT_HVN_TX_COMPLETE); + + SER_PUSH_uint16(&p_event->evt.gatts_evt.conn_handle); + SER_PUSH_uint8(&p_event->evt.gatts_evt.params.hvn_tx_complete.count); + + SER_EVT_ENC_END; +} +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gatts_evt_conn.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gatts_evt_conn.h new file mode 100644 index 0000000..a7d1749 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_gatts_evt_conn.h @@ -0,0 +1,208 @@ +/** + * 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_CONN_H__ +#define BLE_GATTS_EVT_CONN_H__ + +/**@file + * + * @defgroup ble_gatts_evt_conn GATTS Connectivity event encoders + * @{ + * @ingroup ser_conn_s130_codecs + * + * @brief GATTS Connectivity event encoders. + */ +#include "ble.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Encodes @ref BLE_GATTS_EVT_HVC event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_evt_hvc_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes @ref BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_evt_rw_authorize_request_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes @ref BLE_GATTS_EVT_SC_CONFIRM event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_evt_sc_confirm_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes @ref BLE_GATTS_EVT_SYS_ATTR_MISSING event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_evt_sys_attr_missing_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes @ref BLE_GATTS_EVT_TIMEOUT event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_evt_timeout_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes @ref BLE_GATTS_EVT_WRITE event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_evt_write_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Encodes @ref BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_evt_exchange_mtu_request_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); +#if NRF_SD_BLE_API_VERSION >= 4 + +/** + * @brief Encodes @ref BLE_GATTS_EVT_HVN_TX_COMPLETE event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_evt_hvn_tx_complete_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); +#endif +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_l2cap_conn.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_l2cap_conn.c new file mode 100644 index 0000000..0a6a910 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_l2cap_conn.c @@ -0,0 +1,323 @@ +/** + * 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_l2cap_conn.h" +#include "ble_serialization.h" +#include "ble_struct_serialization.h" +#include "ble_l2cap_struct_serialization.h" +#include "cond_field_serialization.h" +#include "conn_ble_l2cap_sdu_pool.h" +#include "app_util.h" + + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t ble_l2cap_cid_register_req_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint16_t * p_cid) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_cid); + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_LENGTH_EQ(3, buf_len); + SER_ASSERT(p_buf[index] == SD_BLE_L2CAP_CID_REGISTER, NRF_ERROR_INVALID_PARAM); + + index++; + err_code = uint16_t_dec(p_buf, buf_len, &index, p_cid); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, buf_len); + + return err_code; +} + + +uint32_t ble_l2cap_cid_register_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + return ser_ble_cmd_rsp_status_code_enc(SD_BLE_L2CAP_CID_REGISTER, return_code, + p_buf, p_buf_len); +} + +uint32_t ble_l2cap_cid_unregister_req_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint16_t * p_cid) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_cid); + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_LENGTH_EQ(3, buf_len); + SER_ASSERT(p_buf[index] == SD_BLE_L2CAP_CID_UNREGISTER, NRF_ERROR_INVALID_PARAM); + + index++; + err_code = uint16_t_dec(p_buf, buf_len, &index, p_cid); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, buf_len); + + return err_code; +} + + +uint32_t ble_l2cap_cid_unregister_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + return ser_ble_cmd_rsp_status_code_enc(SD_BLE_L2CAP_CID_UNREGISTER, return_code, + p_buf, p_buf_len); +} + + +uint32_t ble_l2cap_tx_req_dec(uint8_t const * const p_buf, + uint32_t const buf_len, + uint16_t * p_conn_handle, + ble_l2cap_header_t * * const pp_l2cap_header, + uint8_t const * * pp_data) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_conn_handle); + SER_ASSERT_NOT_NULL(pp_l2cap_header); + SER_ASSERT_NOT_NULL(*pp_l2cap_header); + SER_ASSERT_NOT_NULL(pp_data); + //SER_ASSERT_NOT_NULL(*pp_data); + + uint32_t err_code = NRF_SUCCESS; + uint32_t index = SER_CMD_DATA_POS; + + err_code = uint16_t_dec(p_buf, buf_len, &index, p_conn_handle); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = cond_field_dec(p_buf, buf_len, &index, (void * *)pp_l2cap_header, + ble_l2cap_header_t_dec); + + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + if (*pp_l2cap_header != NULL) + { + *pp_data = p_buf + index + 1; + index += 1 + (*pp_l2cap_header)->len; + } + else + { + *pp_data = NULL; + index++; + } + + SER_ASSERT_LENGTH_EQ(index, buf_len); + + return err_code; +} + +uint32_t ble_l2cap_tx_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + return ser_ble_cmd_rsp_status_code_enc(SD_BLE_L2CAP_TX, return_code, + p_buf, p_buf_len); +} +#endif + +#if NRF_SD_BLE_API_VERSION >= 5 +uint32_t ble_l2cap_ch_setup_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * p_conn_handle, + uint16_t * * pp_local_cid, + ble_l2cap_ch_setup_params_t * * const pp_params) +{ + SER_REQ_DEC_BEGIN(SD_BLE_L2CAP_CH_SETUP); + SER_PULL_uint16(p_conn_handle); + SER_PULL_COND(pp_local_cid, uint16_t_dec); + SER_PULL_COND(pp_params, ble_l2cap_ch_setup_params_t_dec); + + if (*pp_params && (*pp_params)->rx_params.sdu_buf.p_data) + { + SER_ASSERT_LENGTH_LEQ((*pp_params)->rx_params.sdu_buf.len, CONN_BLE_L2CAP_SDU_MAX_BUFFER_SIZE); + uint8_t * p_data = conn_ble_l2cap_sdu_pool_alloc((*pp_params)->rx_params.sdu_buf.len, + (uint32_t)((*pp_params)->rx_params.sdu_buf.p_data)); + (*pp_params)->rx_params.sdu_buf.p_data = p_data; + } + SER_REQ_DEC_END; +} + +uint32_t ble_l2cap_ch_setup_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint16_t * p_local_cid) +{ + SER_RSP_ENC_BEGIN(SD_BLE_L2CAP_CH_SETUP); + + SER_PUSH_COND(p_local_cid, uint16_t_enc); + SER_RSP_ENC_END; +} + +uint32_t ble_l2cap_ch_release_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * p_conn_handle, + uint16_t * p_local_cid) +{ + SER_REQ_DEC_BEGIN(SD_BLE_L2CAP_CH_RELEASE); + SER_PULL_uint16(p_conn_handle); + SER_PULL_uint16(p_local_cid); + SER_REQ_DEC_END; +} + + +uint32_t ble_l2cap_ch_release_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_L2CAP_CH_RELEASE); +} + +uint32_t ble_l2cap_ch_rx_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * p_conn_handle, + uint16_t * p_local_cid, + ble_data_t * * pp_sdu_buf) +{ + SER_REQ_DEC_BEGIN(SD_BLE_L2CAP_CH_RX); + SER_PULL_uint16(p_conn_handle); + SER_PULL_uint16(p_local_cid); + + uint8_t * p_tmp = (uint8_t *)1; + SER_PULL_COND(&p_tmp, NULL); + if (p_tmp) + { + SER_PULL_uint16((uint16_t*)&(*pp_sdu_buf)->len); + uint32_t addr; + SER_PULL_uint32(&addr); + SER_ASSERT_LENGTH_LEQ((*pp_sdu_buf)->len, CONN_BLE_L2CAP_SDU_MAX_BUFFER_SIZE); + uint8_t * p_data = conn_ble_l2cap_sdu_pool_alloc((*pp_sdu_buf)->len, addr); + (*pp_sdu_buf)->p_data = p_data; + } + else + { + *pp_sdu_buf = NULL; + } + + SER_REQ_DEC_END; +} + + +uint32_t ble_l2cap_ch_rx_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_L2CAP_CH_RX); +} + +uint32_t ble_l2cap_ch_tx_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * p_conn_handle, + uint16_t * p_local_cid, + ble_data_t * * const pp_sdu_buf) +{ + SER_REQ_DEC_BEGIN(SD_BLE_L2CAP_CH_TX); + SER_PULL_uint16(p_conn_handle); + SER_PULL_uint16(p_local_cid); + + uint8_t * p_tmp = (uint8_t *)1; + SER_PULL_COND(&p_tmp, NULL); + + if (p_tmp) + { + uint32_t id; + uint16_t len; + SER_PULL_uint32(&id); + SER_PULL_uint16(&len); + + SER_ASSERT_LENGTH_LEQ(len, CONN_BLE_L2CAP_SDU_MAX_BUFFER_SIZE); + uint8_t * p_data = conn_ble_l2cap_sdu_pool_alloc(len, id); + if (p_data) + { + SER_PULL_buf(&p_data, len, len); + } + (*pp_sdu_buf)->p_data = p_data; + (*pp_sdu_buf)->len = len; + + } + else + { + *pp_sdu_buf = NULL; + } + + SER_REQ_DEC_END; +} + + +uint32_t ble_l2cap_ch_tx_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_RSP_ENC_RESULT_ONLY(SD_BLE_L2CAP_CH_TX); +} + +uint32_t ble_l2cap_ch_flow_control_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * p_conn_handle, + uint16_t * p_local_cid, + uint16_t * p_credits, + uint16_t * * pp_credits) +{ + SER_REQ_DEC_BEGIN(SD_BLE_L2CAP_CH_FLOW_CONTROL); + SER_PULL_uint16(p_conn_handle); + SER_PULL_uint16(p_local_cid); + SER_PULL_uint16(p_credits); + SER_PULL_COND(pp_credits, NULL); + SER_REQ_DEC_END; +} + + +uint32_t ble_l2cap_ch_flow_control_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint16_t const * const p_credits) +{ + SER_RSP_ENC_BEGIN(SD_BLE_L2CAP_CH_FLOW_CONTROL); + + SER_PUSH_COND(p_credits, uint16_t_enc); + SER_RSP_ENC_END; +} +#endif //NRF_SD_BLE_API_VERSION >= 5 diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_l2cap_conn.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_l2cap_conn.h new file mode 100644 index 0000000..b254cae --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_l2cap_conn.h @@ -0,0 +1,384 @@ +/** + * Copyright (c) 2011 - 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_conn L2CAP Connectivity command request decoders and command response encoders + * @{ + * @ingroup ser_conn_s130_codecs + * + * @brief L2CAP Connectivity command request decoders and command response encoders. + */ + +#ifndef BLE_L2CAP_CONN_H__ +#define BLE_L2CAP_CONN_H__ + +#include "ble.h" +#include "ble_types.h" +#include "ble_ranges.h" +#include "ble_err.h" +#include "ble_l2cap.h" + +#ifdef __cplusplus +extern "C" { +#endif +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +/**@brief Decodes @ref sd_ble_l2cap_cid_register command request. + * + * @sa @ref ble_l2cap_cid_register_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] buf_len Length (in bytes) of response packet. + * @param[in] p_cid Pointer to L2CAP CID. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_l2cap_cid_register_req_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint16_t * p_cid); + +/**@brief Encodes @ref sd_ble_l2cap_cid_register command response. + * + * @sa @ref ble_l2cap_cid_register_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_l2cap_cid_register_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_l2cap_cid_unregister command request. + * + * @sa @ref ble_l2cap_cid_unregister_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] buf_len Length (in bytes) of response packet. + * @param[in] p_cid Pointer to L2CAP CID. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_l2cap_cid_unregister_req_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint16_t * p_cid); + +/**@brief Encodes @ref sd_ble_l2cap_cid_unregister command response. + * + * @sa @ref ble_l2cap_cid_unregister_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_l2cap_cid_unregister_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_l2cap_tx command request. + * + * @sa @ref ble_l2cap_tx_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] buf_len Length (in bytes) of response packet. + * @param[in] p_conn_handle Pointer to connection handle. + * @param[in] pp_l2cap_header Pointer to pointer to L2CAP header. + * @param[in] pp_data Pointer to pointer L2CAP data. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_l2cap_tx_req_dec(uint8_t const * const p_buf, + uint32_t const buf_len, + uint16_t * p_conn_handle, + ble_l2cap_header_t * * const pp_l2cap_header, + uint8_t const * * pp_data); + +/**@brief Encodes @ref sd_ble_l2cap_tx command response. + * + * @sa @ref ble_l2cap_tx_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_l2cap_tx_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +#endif + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION >= 5 + +/**@brief Decodes @ref sd_ble_l2cap_ch_setup command request. + * + * @sa @ref ble_l2cap_ch_setup_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] buf_len Length (in bytes) of response packet. + * @param[in] p_conn_handle Pointer to connection handle. + * @param[in, out] pp_local_cid Pointer to pointer to local cid. + * @param[in, out] pp_params Pointer to pointer to params. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_l2cap_ch_setup_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * p_conn_handle, + uint16_t * * pp_local_cid, + ble_l2cap_ch_setup_params_t * * const pp_params); + +/**@brief Encodes @ref sd_ble_l2cap_ch_setup command response. + * + * @sa @ref ble_l2cap_ch_setup_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[p_local_cid Pointer to local cid. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_l2cap_ch_setup_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint16_t * p_local_cid); + +/**@brief Decodes @ref sd_ble_l2cap_ch_release command request. + * + * @sa @ref ble_l2cap_ch_release_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] buf_len Length (in bytes) of response packet. + * @param[in] p_conn_handle Pointer to connection handle. + * @param[in] p_local_cid Pointer to local cid. + * @param[in] pp_data Pointer to pointer L2CAP data. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_l2cap_ch_release_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * p_conn_handle, + uint16_t * p_local_cid); + +/**@brief Encodes @ref sd_ble_l2cap_ch_releasecommand response. + * + * @sa @ref ble_l2cap_ch_release_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_l2cap_ch_release_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_l2cap_ch_rx command request. + * + * @sa @ref ble_l2cap_ch_rx_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] buf_len Length (in bytes) of response packet. + * @param[in] p_conn_handle Pointer to connection handle. + * @param[in] p_local_cid Pointer to local cid. + * @param[in] pp_sdu_buf Pointer to pointer to SDU buf. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_l2cap_ch_rx_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * p_conn_handle, + uint16_t * p_local_cid, + ble_data_t * * pp_sdu_buf); + +/**@brief Encodes @ref sd_ble_l2cap_ch_rx command response. + * + * @sa @ref ble_l2cap_ch_rx_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_l2cap_ch_rx_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_l2cap_ch_tx command request. + * + * @sa @ref ble_l2cap_ch_tx_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] buf_len Length (in bytes) of response packet. + * @param[in] p_conn_handle Pointer to connection handle. + * @param[in] p_local_cid Pointer to local cid. + * @param[in] pp_sdu_buf Pointer to pointer to SDU buf. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_l2cap_ch_tx_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * p_conn_handle, + uint16_t * p_local_cid, + ble_data_t * * const pp_sdu_buf); + + +/**@brief Encodes @ref sd_ble_l2cap_ch_tx command response. + * + * @sa @ref ble_l2cap_ch_tx_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_l2cap_ch_tx_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes @ref sd_ble_l2cap_ch_flow_control command request. + * + * @sa @ref ble_l2cap_ch_flow_control_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] buf_len Length (in bytes) of response packet. + * @param[in] p_conn_handle Pointer to connection handle. + * @param[in] p_local_cid Pointer to local cid. + * @param[in] p_credits Pointer to credits. + * @param[in,out] pp_credits Pointer to pointer to credits. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type. + */ +uint32_t ble_l2cap_ch_flow_control_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + uint16_t * p_conn_handle, + uint16_t * p_local_cid, + uint16_t * p_credits, + uint16_t * * pp_credits); + +/**@brief Encodes @ref sd_ble_l2cap_ch_flow_control command response. + * + * @sa @ref ble_l2cap_ch_flow_control_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_credits Pointer to credits. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_l2cap_ch_flow_control_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + uint16_t const * const p_credits); +#endif +#ifdef __cplusplus +} +#endif + +#endif //BLE_L2CAP_CONN_H__ + +/** + @} + */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_l2cap_evt_conn.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_l2cap_evt_conn.c new file mode 100644 index 0000000..c4078f5 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_l2cap_evt_conn.c @@ -0,0 +1,199 @@ +/** + * 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_l2cap_evt_conn.h" +#include <string.h> +#include "ble_serialization.h" +#include "ble_struct_serialization.h" +#include "ble_l2cap_struct_serialization.h" +#include "app_util.h" +#include "conn_ble_l2cap_sdu_pool.h" + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t ble_l2cap_evt_rx_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_L2CAP_EVT_RX); + + SER_PUSH_uint16(&p_event->evt.l2cap_evt.conn_handle); + SER_PUSH_FIELD(&p_event->evt.l2cap_evt.params.rx, ble_l2cap_evt_rx_t_enc); + + SER_EVT_ENC_END; +} +#endif + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION >= 5 +uint32_t ble_l2cap_evt_ch_setup_request_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_L2CAP_EVT_CH_SETUP_REQUEST); + + SER_PUSH_uint16(&p_event->evt.l2cap_evt.conn_handle); + SER_PUSH_uint16(&p_event->evt.l2cap_evt.local_cid); + SER_PUSH_uint16(&p_event->evt.l2cap_evt.params.ch_setup_request.le_psm); + SER_PUSH_FIELD(&p_event->evt.l2cap_evt.params.ch_setup_request.tx_params, ble_l2cap_ch_tx_params_t_enc); + + SER_EVT_ENC_END; +} + +uint32_t ble_l2cap_evt_ch_setup_refused_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_L2CAP_EVT_CH_SETUP_REFUSED); + + SER_PUSH_uint16(&p_event->evt.l2cap_evt.conn_handle); + SER_PUSH_uint16(&p_event->evt.l2cap_evt.local_cid); + SER_PUSH_uint8(&p_event->evt.l2cap_evt.params.ch_setup_refused.source); + SER_PUSH_uint16(&p_event->evt.l2cap_evt.params.ch_setup_refused.status); + + SER_EVT_ENC_END; +} + +uint32_t ble_l2cap_evt_ch_setup_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_L2CAP_EVT_CH_SETUP); + + SER_PUSH_uint16(&p_event->evt.l2cap_evt.conn_handle); + SER_PUSH_uint16(&p_event->evt.l2cap_evt.local_cid); + SER_PUSH_FIELD(&p_event->evt.l2cap_evt.params.ch_setup.tx_params, ble_l2cap_ch_tx_params_t_enc); + + SER_EVT_ENC_END; +} + +uint32_t ble_l2cap_evt_ch_released_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_L2CAP_EVT_CH_RELEASED); + + SER_PUSH_uint16(&p_event->evt.l2cap_evt.conn_handle); + SER_PUSH_uint16(&p_event->evt.l2cap_evt.local_cid); + + SER_EVT_ENC_END; +} + +uint32_t ble_l2cap_evt_ch_sdu_buf_released_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_L2CAP_EVT_CH_SDU_BUF_RELEASED); + + SER_PUSH_uint16(&p_event->evt.l2cap_evt.conn_handle); + SER_PUSH_uint16(&p_event->evt.l2cap_evt.local_cid); + SER_PUSH_uint16(&p_event->evt.l2cap_evt.params.ch_sdu_buf_released.sdu_buf.len); + + uint32_t * p_data = (uint32_t *)p_event->evt.l2cap_evt.params.ch_sdu_buf_released.sdu_buf.p_data; + if (p_data) + { + uint32_t id = *(p_data - 1); + conn_ble_l2cap_sdu_pool_free(p_data); + SER_PUSH_uint32(&id); + } + + SER_EVT_ENC_END; +} + +uint32_t ble_l2cap_evt_ch_credit_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_L2CAP_EVT_CH_CREDIT); + + SER_PUSH_uint16(&p_event->evt.l2cap_evt.conn_handle); + SER_PUSH_uint16(&p_event->evt.l2cap_evt.local_cid); + SER_PUSH_uint16(&p_event->evt.l2cap_evt.params.credit.credits); + + SER_EVT_ENC_END; +} + +uint32_t ble_l2cap_evt_ch_rx_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_L2CAP_EVT_CH_RX); + + SER_PUSH_uint16(&p_event->evt.l2cap_evt.conn_handle); + SER_PUSH_uint16(&p_event->evt.l2cap_evt.local_cid); + SER_PUSH_uint16(&p_event->evt.l2cap_evt.params.rx.sdu_len); + SER_PUSH_uint16(&p_event->evt.l2cap_evt.params.rx.sdu_buf.len); + + uint32_t * p_data = (uint32_t *)p_event->evt.l2cap_evt.params.rx.sdu_buf.p_data; + uint32_t id = *(p_data - 1); + SER_PUSH_uint32(&id); + SER_PUSH_buf(p_event->evt.l2cap_evt.params.rx.sdu_buf.p_data, p_event->evt.l2cap_evt.params.rx.sdu_buf.len); + conn_ble_l2cap_sdu_pool_free(p_data); + + SER_EVT_ENC_END; +} + +uint32_t ble_l2cap_evt_ch_tx_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_EVT_ENC_BEGIN(BLE_L2CAP_EVT_CH_TX); + + SER_PUSH_uint16(&p_event->evt.l2cap_evt.conn_handle); + SER_PUSH_uint16(&p_event->evt.l2cap_evt.local_cid); + SER_PUSH_uint16(&p_event->evt.l2cap_evt.params.tx.sdu_buf.len); + + uint32_t * p_data = (uint32_t *)p_event->evt.l2cap_evt.params.tx.sdu_buf.p_data; + if (p_data) + { + uint32_t id = *(p_data - 1); + conn_ble_l2cap_sdu_pool_free(p_data); + SER_PUSH_uint32(&id); + } + + SER_EVT_ENC_END; +} +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_l2cap_evt_conn.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_l2cap_evt_conn.h new file mode 100644 index 0000000..65709ee --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/ble_l2cap_evt_conn.h @@ -0,0 +1,121 @@ +/** + * 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_CONN_H__ +#define BLE_L2CAP_EVT_CONN_H__ + +/**@file + * + * @defgroup ble_l2cap_evt_conn L2CAP Connectivity event encoders + * @{ + * @ingroup ser_conn_s130_codecs + * + * @brief L2CAP Connectivity event encoders. + */ +#include "ble.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Encodes ble_l2cap_evt_rx event. + * + * @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded. + * @param[in] event_len Size (in bytes) of \p p_event buffer. + * @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet. + * @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer. + * \c out: Length of encoded contents in \p p_buf. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_l2cap_evt_rx_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +uint32_t ble_l2cap_evt_ch_setup_request_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +uint32_t ble_l2cap_evt_ch_setup_refused_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +uint32_t ble_l2cap_evt_ch_setup_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + + +uint32_t ble_l2cap_evt_ch_released_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +uint32_t ble_l2cap_evt_ch_sdu_buf_released_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +uint32_t ble_l2cap_evt_ch_credit_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +uint32_t ble_l2cap_evt_ch_rx_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +uint32_t ble_l2cap_evt_ch_tx_enc(ble_evt_t const * const p_event, + uint32_t event_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/conn_ble_gap_sec_keys.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/conn_ble_gap_sec_keys.c new file mode 100644 index 0000000..1013d5e --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/conn_ble_gap_sec_keys.c @@ -0,0 +1,155 @@ +/** + * 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 "conn_ble_gap_sec_keys.h" +#include "ser_config.h" +#include "nrf_error.h" +#include "nordic_common.h" +#include <stddef.h> + +ser_ble_gap_conn_keyset_t m_conn_keys_table[SER_MAX_CONNECTIONS]; +#if NRF_SD_BLE_API_VERSION >= 6 + +typedef struct +{ + uint32_t id; + uint8_t ble_data[SER_MAX_ADV_DATA]; +} ble_data_item_t; + +ble_data_item_t m_ble_data_pool[8]; + +#endif +uint32_t conn_ble_gap_sec_context_create(uint32_t *p_index) +{ + uint32_t err_code = NRF_ERROR_NO_MEM; + uint32_t i; + + for (i=0; i<SER_MAX_CONNECTIONS; i++ ) + { + if ( ! m_conn_keys_table[i].conn_active ) + { + m_conn_keys_table[i].conn_active = 1; + *p_index = i; + err_code = NRF_SUCCESS; + break; + } + } + + return err_code; +} + +uint32_t conn_ble_gap_sec_context_destroy(uint16_t conn_handle) +{ + uint32_t err_code = NRF_ERROR_NOT_FOUND; + uint32_t i; + + for (i=0; i<SER_MAX_CONNECTIONS; i++ ) + { + if ( m_conn_keys_table[i].conn_handle == conn_handle ) + { + m_conn_keys_table[i].conn_active = 0; + err_code = NRF_SUCCESS; + break; + } + } + + return err_code; +} + +uint32_t conn_ble_gap_sec_context_find(uint16_t conn_handle, uint32_t *p_index) +{ + uint32_t err_code = NRF_ERROR_NOT_FOUND; + uint32_t i; + + for (i=0; i<SER_MAX_CONNECTIONS; i++ ) + { + if ( (m_conn_keys_table[i].conn_handle == conn_handle) && (m_conn_keys_table[i].conn_active == 1) ) + { + *p_index = i; + err_code = NRF_SUCCESS; + break; + } + } + + return err_code; +} + +#if NRF_SD_BLE_API_VERSION >= 6 +uint8_t * conn_ble_gap_ble_data_buf_alloc(uint32_t id) +{ + uint32_t i; + + /* First find if given id already allocated the buffer. */ + for (i = 0; i < ARRAY_SIZE(m_ble_data_pool); i++) + { + if (m_ble_data_pool[i].id == id) + { + return m_ble_data_pool[i].ble_data; + } + } + + for (i = 0; i < ARRAY_SIZE(m_ble_data_pool); i++) + { + if (m_ble_data_pool[i].id == 0) + { + m_ble_data_pool[i].id = id; + return m_ble_data_pool[i].ble_data; + } + } + + return NULL; +} + + +void conn_ble_gap_ble_data_buf_free(uint8_t * p_data) +{ + uint32_t i; + + /* First find if given id already allocated the buffer. */ + for (i = 0; i < ARRAY_SIZE(m_ble_data_pool); i++) + { + if (m_ble_data_pool[i].ble_data == p_data) + { + m_ble_data_pool[i].id = 0; + return; + } + } +} +#endif + diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/conn_ble_gap_sec_keys.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/conn_ble_gap_sec_keys.h new file mode 100644 index 0000000..9212457 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/conn_ble_gap_sec_keys.h @@ -0,0 +1,128 @@ +/** + * 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 _CONN_BLE_GAP_SEC_KEYS_H +#define _CONN_BLE_GAP_SEC_KEYS_H + +/**@file + * + * @defgroup conn_ble_gap_sec_keys GAP Functions for managing memory for security keys on connectivity device + * @{ + * @ingroup ser_conn_s130_codecs + * + * @brief GAP Connectivity auxiliary functions for providing static memory required by the SoftDevice. This memory is used to store GAP security keys. + */ + +#include "ble_gap.h" +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef SER_MAX_CONNECTIONS +#define SER_MAX_CONNECTIONS 8 +#endif + +/**@brief GAP connection - keyset mapping structure. + * + * @note This structure is used to map keysets to connection instances, and will be stored in a static table. + */ +typedef struct +{ + uint16_t conn_handle; /**< Connection handle. */ + uint8_t conn_active; /**< Indication that keys for this connection are used by the SoftDevice. 0: keys used; 1: keys not used. */ + ble_gap_sec_keyset_t keyset; /**< Keyset structure, see @ref ble_gap_sec_keyset_t. */ + ble_gap_enc_key_t enc_key_own; /**< Own Encryption Key, see @ref ble_gap_enc_key_t. */ + ble_gap_id_key_t id_key_own; /**< Own Identity Key, see @ref ble_gap_id_key_t. */ + ble_gap_sign_info_t sign_key_own; /**< Own Signing Information, see @ref ble_gap_sign_info_t. */ + ble_gap_lesc_p256_pk_t pk_own; /**< Own Public key, see @ref ble_gap_lesc_p256_pk_t. */ + ble_gap_enc_key_t enc_key_peer; /**< Peer Encryption Key, see @ref ble_gap_enc_key_t. */ + ble_gap_id_key_t id_key_peer; /**< Peer Identity Key, see @ref ble_gap_id_key_t. */ + ble_gap_sign_info_t sign_key_peer; /**< Peer Signing Information, see @ref ble_gap_sign_info_t. */ + ble_gap_lesc_p256_pk_t pk_peer; /**< Peer Public key, see @ref ble_gap_lesc_p256_pk_t. */ +} ser_ble_gap_conn_keyset_t; + +/**@brief Allocates instance in m_conn_keys_table[] for storage of encryption keys. + * + * @param[out] p_index Pointer to the index of allocated instance. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_NO_MEM No free instance available. + */ +uint32_t conn_ble_gap_sec_context_create(uint32_t *p_index); + +/**@brief Releases the instance identified by a connection handle. + * + * @param[in] conn_handle conn_handle + * + * @retval NRF_SUCCESS Context released. + * @retval NRF_ERROR_NOT_FOUND Instance with conn_handle not found. + */ +uint32_t conn_ble_gap_sec_context_destroy(uint16_t conn_handle); + +/**@brief Finds index of the instance identified by a connection handle in m_conn_keys_table[]. + * + * @param[in] conn_handle conn_handle + * + * @param[out] p_index Pointer to the index of entry in the context table corresponding to the given conn_handle. + * + * @retval NRF_SUCCESS Context table entry found. + * @retval NRF_ERROR_NOT_FOUND Instance with the conn_handle not found. + */ +uint32_t conn_ble_gap_sec_context_find(uint16_t conn_handle, uint32_t *p_index); +/** @} */ + +/** @brief Function allocates data from the pool. + * + * @param id ID used for buffer identification. If buffer with given ID is already allocated the pointer to that buffer is returned. + * @return Allocated buffer of NULL. + */ +uint8_t * conn_ble_gap_ble_data_buf_alloc(uint32_t id); + +/** @brief Function for freeing the buffer. + * @param p_data Buffer to be freed. + */ +void conn_ble_gap_ble_data_buf_free(uint8_t * p_data); + +#ifdef __cplusplus +} +#endif + +#endif //_CONN_BLE_GAP_SEC_KEYS_H diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/conn_ble_l2cap_sdu_pool.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/conn_ble_l2cap_sdu_pool.c new file mode 100644 index 0000000..7075577 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/conn_ble_l2cap_sdu_pool.c @@ -0,0 +1,84 @@ +/** + * 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 "conn_ble_l2cap_sdu_pool.h" +#include "app_util.h" +#include "nrf_balloc.h" + + +#define MAX_NUM_OF_BUFFERS 8 + +#define ID_SIZE 4 + +#define TOTAL_BUF_SIZE (CONN_BLE_L2CAP_SDU_MAX_BUFFER_SIZE+ID_SIZE) + +NRF_BALLOC_DEF(m_pool, TOTAL_BUF_SIZE, MAX_NUM_OF_BUFFERS); + +void conn_ble_l2cap_sdu_pool_init(void) +{ + (void)nrf_balloc_init(&m_pool); +} + +uint8_t * conn_ble_l2cap_sdu_pool_alloc(uint16_t length, uint32_t id) +{ + if (length > CONN_BLE_L2CAP_SDU_MAX_BUFFER_SIZE) + { + return NULL; + } + + uint32_t * p_buf = nrf_balloc_alloc(&m_pool); + *p_buf = id; + p_buf++; + return (uint8_t *)p_buf; +} + +uint32_t conn_ble_l2cap_sdu_pool_id_get(void * p_data) +{ + uint32_t * p_buf = (uint32_t *)p_data; + p_buf--; + return *p_buf; +} + +void conn_ble_l2cap_sdu_pool_free(void * p_data) +{ + uint32_t * p_buf = (uint32_t *)p_data; + p_buf--; + nrf_balloc_free(&m_pool, p_buf); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/conn_ble_l2cap_sdu_pool.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/conn_ble_l2cap_sdu_pool.h new file mode 100644 index 0000000..537d46b --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/conn_ble_l2cap_sdu_pool.h @@ -0,0 +1,53 @@ +/** + * 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 CONN_BLE_L2CAP_SDU_POOL_H +#define CONN_BLE_L2CAP_SDU_POOL_H + +#include <stdint.h> + +#define CONN_BLE_L2CAP_SDU_MAX_BUFFER_SIZE 124 + +void conn_ble_l2cap_sdu_pool_init(void); +uint8_t * conn_ble_l2cap_sdu_pool_alloc(uint16_t length, uint32_t id); +uint32_t conn_ble_l2cap_sdu_pool_id_get(void * p_data); +void conn_ble_l2cap_sdu_pool_free(void * p_data); + +#endif //CONN_BLE_L2CAP_SDU_POOL_H diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/conn_ble_user_mem.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/conn_ble_user_mem.c new file mode 100644 index 0000000..96f925b --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/conn_ble_user_mem.c @@ -0,0 +1,105 @@ +/** + * 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 "conn_ble_user_mem.h" +#include "ser_config.h" +#include "nrf_error.h" +#include <stddef.h> + + + +sercon_ble_user_mem_t m_conn_user_mem_table[SER_MAX_CONNECTIONS]; + +uint32_t conn_ble_user_mem_context_create(uint32_t *p_index) +{ + uint32_t err_code = NRF_ERROR_NO_MEM; + uint32_t i; + + for (i=0; i<SER_MAX_CONNECTIONS; i++ ) + { + if ( ! m_conn_user_mem_table[i].conn_active ) + { + m_conn_user_mem_table[i].conn_active = 1; + m_conn_user_mem_table[i].mem_block.p_mem = m_conn_user_mem_table[i].mem_table; + *p_index = i; + err_code = NRF_SUCCESS; + break; + } + } + + return err_code; +} + +uint32_t conn_ble_user_mem_context_destroy(uint16_t conn_handle) +{ + uint32_t err_code = NRF_ERROR_NOT_FOUND; + uint32_t i; + + for (i=0; i<SER_MAX_CONNECTIONS; i++ ) + { + if ( m_conn_user_mem_table[i].conn_handle == conn_handle ) + { + m_conn_user_mem_table[i].conn_active = 0; + m_conn_user_mem_table[i].mem_block.p_mem = NULL; + err_code = NRF_SUCCESS; + break; + } + } + + return err_code; +} + +uint32_t conn_ble_user_mem_context_find(uint16_t conn_handle, uint32_t *p_index) +{ + uint32_t err_code = NRF_ERROR_NOT_FOUND; + uint32_t i; + + for (i=0; i<SER_MAX_CONNECTIONS; i++ ) + { + if ( (m_conn_user_mem_table[i].conn_handle == conn_handle) && (m_conn_user_mem_table[i].conn_active == 1) ) + { + *p_index = i; + err_code = NRF_SUCCESS; + break; + } + } + + return err_code; +} + diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/conn_ble_user_mem.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/conn_ble_user_mem.h new file mode 100644 index 0000000..3cb0439 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/conn_ble_user_mem.h @@ -0,0 +1,108 @@ +/** + * 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 _CONN_BLE_USER_MEM_H +#define _CONN_BLE_USER_MEM_H + +/**@file + * + * @defgroup conn_ble_user_mem Functions for managing memory for user memory request on connectivity device. + * @{ + * @ingroup ser_conn_s130_codecs + * + * @brief Connectivity auxiliary functions for providing static memory required by the SoftDevice. + */ + +#include "ble.h" +#include "ser_config.h" +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/**@brief Connection - user memory mapping structure. + * + * @note This structure is used to map keysets to connection instances, and will be stored in a static table. + */ +//lint -esym(452,ser_ble_user_mem_t) +typedef struct +{ + uint16_t conn_handle; /**< Connection handle.*/ + uint8_t conn_active; /**< Indication that user memory for this connection is used by the SoftDevice. 0: memory used; 1: memory not used. */ + ble_user_mem_block_t mem_block; /**< User memory block structure, see @ref ble_user_mem_block_t. */ + uint8_t mem_table[64]; /**< Memory table. */ +} sercon_ble_user_mem_t; + +/**@brief Allocates instance in m_user_mem_table[] for storage. + * + * @param[out] p_index Pointer to the index of allocated instance. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_NO_MEM No free instance available. + */ +uint32_t conn_ble_user_mem_context_create(uint32_t *p_index); + +/**@brief Releases the instance identified by a connection handle. + * + * @param[in] conn_handle conn_handle + * + * @retval NRF_SUCCESS Context released. + * @retval NRF_ERROR_NOT_FOUND Instance with the conn_handle not found. + */ +uint32_t conn_ble_user_mem_context_destroy(uint16_t conn_handle); + +/**@brief Finds index of the instance identified by a connection handle in m_user_mem_table[]. + * + * @param[in] conn_handle conn_handle + * + * @param[out] p_index Pointer to the index of entry in the context table corresponding to the given conn_handle. + * + * @retval NRF_SUCCESS Context table entry found. + * @retval NRF_ERROR_NOT_FOUND Instance with the conn_handle not found. + */ +uint32_t conn_ble_user_mem_context_find(uint16_t conn_handle, uint32_t *p_index); +/** @} */ + + +#ifdef __cplusplus +} +#endif + +#endif //_CONN_BLE_USER_MEM_H diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/nrf_soc_conn.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/nrf_soc_conn.c new file mode 100644 index 0000000..b000f4b --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/nrf_soc_conn.c @@ -0,0 +1,89 @@ +/** + * 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 "nrf_soc_conn.h" +#include "nrf_error.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "nrf_soc_struct_serialization.h" + +uint32_t ecb_block_encrypt_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + nrf_ecb_hal_data_t * * const pp_ecb_data) +{ + SER_REQ_DEC_BEGIN(SD_ECB_BLOCK_ENCRYPT); + SER_PULL_COND(pp_ecb_data, nrf_ecb_hal_data_t_in_dec); + SER_REQ_DEC_END; +} + +uint32_t ecb_block_encrypt_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + nrf_ecb_hal_data_t * const p_ecb_data) +{ + SER_RSP_ENC_BEGIN(SD_ECB_BLOCK_ENCRYPT); + SER_PUSH_COND(p_ecb_data, nrf_ecb_hal_data_t_out_enc); + SER_RSP_ENC_END; +} +uint32_t power_system_off_req_dec(uint8_t const * const p_buf, + uint16_t packet_len) +{ + SER_REQ_DEC_BEGIN(SD_POWER_SYSTEM_OFF); + SER_REQ_DEC_END; +} + +uint32_t temp_get_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + int32_t * * const pp_temp) +{ + SER_REQ_DEC_BEGIN(SD_TEMP_GET); + SER_PULL_COND(pp_temp, NULL); + SER_REQ_DEC_END; +} + +uint32_t temp_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + int32_t * const p_temp) +{ + SER_RSP_ENC_BEGIN(SD_TEMP_GET); + SER_PUSH_COND(p_temp, uint32_t_enc); + SER_RSP_ENC_END; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/nrf_soc_conn.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/nrf_soc_conn.h new file mode 100644 index 0000000..d7c52bf --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/ble/serializers/nrf_soc_conn.h @@ -0,0 +1,148 @@ +/** + * 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 NRF_SOC_CONN_H__ +#define NRF_SOC_CONN_H__ + +/**@file + * + * @defgroup soc_conn SOC Connectivity command request decoders and command response encoders + * @{ + * @ingroup ser_conn_s130_codecs + * + * @brief SOC Connectivity command request decoders and command response encoders. + */ +#include "nrf_soc.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/**@brief Decodes @ref sd_power_system_off command request. + * + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in] packet_len Length (in bytes) of request packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_PARAM Encoding failure. Incorrect parameter. + */ +uint32_t power_system_off_req_dec(uint8_t const * const p_buf, uint16_t packet_len); + + +/**@brief Decodes @ref sd_temp_get command request. + * + * @sa @ref temp_get_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in] packet_len Length (in bytes) of request packet. + * @param[out] pp_temp Pointer to pointer to result of temperature measurement. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_PARAM Encoding failure. Incorrect parameter. + */ +uint32_t temp_get_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + int32_t * * const pp_temp); + +/**@brief Encodes @ref sd_temp_get command response. + * + * @sa @ref temp_get_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_temp Pointer to result of temperature measurement. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t temp_get_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + int32_t * const p_temp); + +/**@brief Decodes @ref sd_ecb_block_encrypt command request. + * + * @sa @ref ecb_block_encrypt_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in] packet_len Length (in bytes) of request packet. + * @param[out] pp_ecb_data Pointer to pointer to ECB data. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied + * @retval NRF_ERROR_INVALID_PARAM Encoding failure. Incorrect parameter. + */ +uint32_t ecb_block_encrypt_req_dec(uint8_t const * const p_buf, + uint32_t packet_len, + nrf_ecb_hal_data_t * * const pp_ecb_data); + +/**@brief Encodes @ref sd_ecb_block_encrypt command response. + * + * @sa @ref ecb_block_encrypt_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * @param[in] p_ecb_data Pointer to ECB data. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ecb_block_encrypt_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len, + nrf_ecb_hal_data_t * const p_ecb_data); + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/common/ble_dtm_conn.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/common/ble_dtm_conn.h new file mode 100644 index 0000000..53a80d2 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/common/ble_dtm_conn.h @@ -0,0 +1,113 @@ +/** + * 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_DTM_CONN_H__ +#define BLE_DTM_CONN_H__ + +/** + * @addtogroup ser_codecs_conn Connectivity codecs + * @ingroup ser_codecs + */ + +/** + * @addtogroup ser_conn_common_codecs Connectivity common codecs + * @ingroup ser_codecs_conn + */ + +/**@file + * + * @defgroup ble_dtm_conn DTM Connectivity command request decoder and command response encoder + * @{ + * @ingroup ser_conn_common_codecs + * + * @brief DTM Connectivity command request decoder and command response encoder. + */ + +#include "dtm_uart.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/**@brief Decodes @ref ble_dtm_init command request. + * + * @sa @ref encoding_data for packet format, + * @ref ble_dtm_init_rsp_enc for response encoding. + * + * @param[in] p_buf Pointer to beginning of command request packet. + * @param[in] packet_len Length (in bytes) of request packet. + * @param[in] p_comm_params Pointer to the structure with DTM UART configuration. + + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ble_dtm_init_req_dec(uint8_t const * const p_buf, + uint16_t packet_len, + app_uart_stream_comm_params_t * p_comm_params); + + +/**@brief Encodes @ref ble_dtm_init command response. + * + * @sa @ref encoding_data for packet format. + * @ref ble_dtm_init_req_dec for request decoding. + * + * @param[in] return_code Return code indicating if command was successful or not. + * @param[out] p_buf Pointer to buffer where encoded data command response will be + * returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command response packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_dtm_init_rsp_enc(uint32_t return_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif // BLE_DTM_CONN_H__ + diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/common/ble_dtm_init.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/common/ble_dtm_init.c new file mode 100644 index 0000000..e9dfefa --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/common/ble_dtm_init.c @@ -0,0 +1,83 @@ +/** + * 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_dtm_conn.h" +#include "dtm_uart.h" +#include "nrf_error.h" +#include "ble_serialization.h" + +uint32_t ble_dtm_init_req_dec(uint8_t const * const p_buf, uint16_t packet_len, + app_uart_stream_comm_params_t * p_comm_params) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_comm_params); + + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + err_code = uint8_t_dec(p_buf, packet_len, &index, &p_comm_params->tx_pin_no); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, packet_len, &index, &p_comm_params->rx_pin_no); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, packet_len, &index, &p_comm_params->baud_rate); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT(index == packet_len, NRF_ERROR_INVALID_LENGTH); + + return err_code; +} + +uint32_t ble_dtm_init_rsp_enc(uint32_t return_code, uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + err_code = uint32_t_enc(&return_code, p_buf, *p_buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + *p_buf_len = index; + + return err_code; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/common/conn_mw.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/common/conn_mw.c new file mode 100644 index 0000000..fcd780c --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/common/conn_mw.c @@ -0,0 +1,107 @@ +/** + * 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 <stddef.h> + +#include "ble_serialization.h" +#include "nrf_soc.h" + +/**@brief Connectivity middleware handler type. */ +typedef uint32_t (*conn_mw_handler_t)(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Connectivity middleware item. */ +typedef struct +{ + uint8_t opcode; /**< Opcode by which specific codec is identified */ + conn_mw_handler_t fp_handler; /**< Function pointer to handler associated with given opcode */ +} conn_mw_item_t; + +/* Include handlers for given softdevice */ +#include "conn_mw_items.c" + +/**@brief Number of registered connectivity middleware handlers. */ +static const uint32_t conn_mw_item_len = sizeof (conn_mw_item) / sizeof (conn_mw_item[0]); + +/**@brief Local function for finding connectivity middleware handler in the table.. */ +static conn_mw_handler_t conn_mw_handler_get(uint8_t opcode) +{ + conn_mw_handler_t fp_handler = NULL; + uint32_t i; + + for (i = 0; i < conn_mw_item_len; i++) + { + if (opcode == conn_mw_item[i].opcode) + { + fp_handler = conn_mw_item[i].fp_handler; + break; + } + } + + return fp_handler; +} + +uint32_t conn_mw_handler(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + conn_mw_handler_t fp_handler; + uint32_t err_code = NRF_SUCCESS; + uint8_t opcode = p_rx_buf[SER_CMD_OP_CODE_POS]; + + fp_handler = conn_mw_handler_get(opcode); + + if (fp_handler) + { + err_code = fp_handler(p_rx_buf, rx_buf_len, p_tx_buf, p_tx_buf_len); + } + else + { + err_code = NRF_ERROR_NOT_SUPPORTED; + } + + return err_code; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/common/conn_mw.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/common/conn_mw.h new file mode 100644 index 0000000..4ff3c8e --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/common/conn_mw.h @@ -0,0 +1,88 @@ +/** + * 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 _CONN_MW_H +#define _CONN_MW_H + +/** + * @addtogroup ser_codecs_mw Connectivity middleware codecs + * @ingroup ser_codecs + */ + +/** + * @addtogroup ser_mw_common_codecs Connectivity middleware common codecs + * @{ + * @ingroup ser_codecs_mw + */ + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/**@brief Connectivity Middleware dispatcher function + * + * @details It will handle decode the opcode from the RX buffer and based on the opcode it will search + * for registered handler. Handler is called once it is found. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + * @retval NRF_ERROR_NOT_SUPPORTED Handler failure. Opcode not supported. + */ +uint32_t conn_mw_handler (uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +#ifdef __cplusplus +} +#endif + +/** @} */ + +#endif //_CONN_MW_H diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/common/conn_mw_items.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/common/conn_mw_items.c new file mode 100644 index 0000000..0502ada --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/common/conn_mw_items.c @@ -0,0 +1,224 @@ +/** + * 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 "conn_mw_nrf_soc.h" +#if defined(BLE_STACK_SUPPORT_REQD) +#include "ble.h" +#include "ble_gap.h" +#include "ble_gattc.h" +#include "ble_gatts.h" + +#ifndef S112 +#include "ble_l2cap.h" +#endif //!S112 + +#include "conn_mw_ble.h" +#include "conn_mw_ble_l2cap.h" +#include "conn_mw_ble_gap.h" +#include "conn_mw_ble_gatts.h" +#include "conn_mw_ble_gattc.h" +#endif // defined(BLE_STACK_SUPPORT_REQD) +#if defined(ANT_STACK_SUPPORT_REQD) +#include "conn_mw_ant.h" +#include "ant_interface.h" +#endif // defined(ANT_STACK_SUPPORT_REQD) + +/**@brief Connectivity middleware handlers table. */ +static const conn_mw_item_t conn_mw_item[] = { + //Functions from nrf_soc.h + {SD_POWER_SYSTEM_OFF, conn_mw_power_system_off}, + {SD_TEMP_GET, conn_mw_temp_get}, + {SD_ECB_BLOCK_ENCRYPT, conn_mw_ecb_block_encrypt}, +#if defined(BLE_STACK_SUPPORT_REQD) + //Functions from ble.h +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 + {SD_BLE_TX_PACKET_COUNT_GET, conn_mw_ble_tx_packet_count_get}, +#endif + {SD_BLE_UUID_VS_ADD, conn_mw_ble_uuid_vs_add}, + {SD_BLE_UUID_DECODE, conn_mw_ble_uuid_decode}, + {SD_BLE_UUID_ENCODE, conn_mw_ble_uuid_encode}, + {SD_BLE_VERSION_GET, conn_mw_ble_version_get}, + {SD_BLE_OPT_GET, conn_mw_ble_opt_get}, + {SD_BLE_OPT_SET, conn_mw_ble_opt_set}, + {SD_BLE_ENABLE, conn_mw_ble_enable}, + {SD_BLE_USER_MEM_REPLY, conn_mw_ble_user_mem_reply}, +#if NRF_SD_BLE_API_VERSION >= 4 + {SD_BLE_CFG_SET, conn_mw_ble_cfg_set}, +#endif + //Functions from ble_l2cap.h +#ifndef S112 +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 + {SD_BLE_L2CAP_CID_REGISTER, conn_mw_ble_l2cap_cid_register}, + {SD_BLE_L2CAP_CID_UNREGISTER, conn_mw_ble_l2cap_cid_unregister}, + {SD_BLE_L2CAP_TX, conn_mw_ble_l2cap_tx}, +#elif defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION >= 5 + {SD_BLE_L2CAP_CH_SETUP, conn_mw_l2cap_ch_setup}, + {SD_BLE_L2CAP_CH_RELEASE, conn_mw_l2cap_ch_release}, + {SD_BLE_L2CAP_CH_RX, conn_mw_l2cap_ch_rx}, + {SD_BLE_L2CAP_CH_TX, conn_mw_l2cap_ch_tx}, + {SD_BLE_L2CAP_CH_FLOW_CONTROL, conn_mw_l2cap_ch_flow_control}, +#endif +#endif //!S112 + //Functions from ble_gap.h + {SD_BLE_GAP_ADDR_SET, conn_mw_ble_gap_addr_set}, + {SD_BLE_GAP_ADDR_GET, conn_mw_ble_gap_addr_get}, + {SD_BLE_GAP_PRIVACY_SET, conn_mw_ble_gap_privacy_set}, + {SD_BLE_GAP_PRIVACY_GET, conn_mw_ble_gap_privacy_get}, + {SD_BLE_GAP_WHITELIST_SET, conn_mw_ble_gap_whitelist_set}, + {SD_BLE_GAP_DEVICE_IDENTITIES_SET, conn_mw_ble_gap_device_identities_set}, +#ifndef S112 + {SD_BLE_GAP_SCAN_START, conn_mw_ble_gap_scan_start}, + {SD_BLE_GAP_SCAN_STOP, conn_mw_ble_gap_scan_stop}, + {SD_BLE_GAP_CONNECT, conn_mw_ble_gap_connect}, + {SD_BLE_GAP_CONNECT_CANCEL, conn_mw_ble_gap_connect_cancel}, + {SD_BLE_GAP_ENCRYPT, conn_mw_ble_gap_encrypt}, +#endif + {SD_BLE_GAP_SEC_INFO_REPLY, conn_mw_ble_gap_sec_info_reply}, +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 6 + {SD_BLE_GAP_ADV_DATA_SET, conn_mw_ble_gap_adv_data_set}, +#endif + {SD_BLE_GAP_ADV_START, conn_mw_ble_gap_adv_start}, + {SD_BLE_GAP_ADV_STOP, conn_mw_ble_gap_adv_stop}, + {SD_BLE_GAP_CONN_PARAM_UPDATE, conn_mw_ble_gap_conn_param_update}, + {SD_BLE_GAP_DISCONNECT, conn_mw_ble_gap_disconnect}, + {SD_BLE_GAP_TX_POWER_SET, conn_mw_ble_gap_tx_power_set}, + {SD_BLE_GAP_APPEARANCE_SET, conn_mw_ble_gap_appearance_set}, + {SD_BLE_GAP_APPEARANCE_GET, conn_mw_ble_gap_appearance_get}, + {SD_BLE_GAP_PPCP_SET, conn_mw_ble_gap_ppcp_set}, + {SD_BLE_GAP_PPCP_GET, conn_mw_ble_gap_ppcp_get}, + {SD_BLE_GAP_DEVICE_NAME_SET, conn_mw_ble_gap_device_name_set}, + {SD_BLE_GAP_DEVICE_NAME_GET, conn_mw_ble_gap_device_name_get}, + {SD_BLE_GAP_AUTHENTICATE, conn_mw_ble_gap_authenticate}, + {SD_BLE_GAP_SEC_PARAMS_REPLY, conn_mw_ble_gap_sec_params_reply}, + {SD_BLE_GAP_AUTH_KEY_REPLY, conn_mw_ble_gap_auth_key_reply}, + {SD_BLE_GAP_SEC_INFO_REPLY, conn_mw_ble_gap_sec_info_reply}, + {SD_BLE_GAP_CONN_SEC_GET, conn_mw_ble_gap_conn_sec_get}, + {SD_BLE_GAP_RSSI_START, conn_mw_ble_gap_rssi_start}, + {SD_BLE_GAP_RSSI_STOP, conn_mw_ble_gap_rssi_stop}, + {SD_BLE_GAP_KEYPRESS_NOTIFY, conn_mw_ble_gap_keypress_notify}, + {SD_BLE_GAP_LESC_DHKEY_REPLY, conn_mw_ble_gap_lesc_dhkey_reply}, + {SD_BLE_GAP_LESC_OOB_DATA_SET, conn_mw_ble_gap_lesc_oob_data_set}, + {SD_BLE_GAP_LESC_OOB_DATA_GET, conn_mw_ble_gap_lesc_oob_data_get}, + {SD_BLE_GAP_RSSI_GET, conn_mw_ble_gap_rssi_get}, +#if NRF_SD_BLE_API_VERSION >= 5 + {SD_BLE_GAP_PHY_UPDATE, conn_mw_ble_gap_phy_update}, +#endif +#if NRF_SD_BLE_API_VERSION >= 4 && !defined(S112) + {SD_BLE_GAP_DATA_LENGTH_UPDATE, conn_mw_ble_gap_data_length_update}, +#endif +#if NRF_SD_BLE_API_VERSION > 5 + {SD_BLE_GAP_ADV_SET_CONFIGURE, conn_mw_ble_gap_adv_set_configure}, +#ifndef S112 + {SD_BLE_GAP_QOS_CHANNEL_SURVEY_START, conn_mw_ble_gap_qos_channel_survey_start}, + {SD_BLE_GAP_QOS_CHANNEL_SURVEY_STOP, conn_mw_ble_gap_qos_channel_survey_stop}, +#endif //!S112 +#endif + //Functions from ble_gattc.h + {SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER, conn_mw_ble_gattc_primary_services_discover}, + {SD_BLE_GATTC_RELATIONSHIPS_DISCOVER, conn_mw_ble_gattc_relationships_discover}, + {SD_BLE_GATTC_CHARACTERISTICS_DISCOVER, conn_mw_ble_gattc_characteristics_discover}, + {SD_BLE_GATTC_DESCRIPTORS_DISCOVER, conn_mw_ble_gattc_descriptors_discover}, + {SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ, conn_mw_ble_gattc_char_value_by_uuid_read}, + {SD_BLE_GATTC_READ, conn_mw_ble_gattc_read}, + {SD_BLE_GATTC_CHAR_VALUES_READ, conn_mw_ble_gattc_char_values_read}, + {SD_BLE_GATTC_WRITE, conn_mw_ble_gattc_write}, + {SD_BLE_GATTC_HV_CONFIRM, conn_mw_ble_gattc_hv_confirm}, + {SD_BLE_GATTC_ATTR_INFO_DISCOVER, conn_mw_ble_gattc_attr_info_discover}, + {SD_BLE_GATTC_EXCHANGE_MTU_REQUEST, conn_mw_ble_gattc_exchange_mtu_request}, + //Functions from ble_gatts.h + {SD_BLE_GATTS_SERVICE_ADD, conn_mw_ble_gatts_service_add}, + {SD_BLE_GATTS_INCLUDE_ADD, conn_mw_ble_gatts_include_add}, + {SD_BLE_GATTS_CHARACTERISTIC_ADD, conn_mw_ble_gatts_characteristic_add}, + {SD_BLE_GATTS_DESCRIPTOR_ADD, conn_mw_ble_gatts_descriptor_add}, + {SD_BLE_GATTS_VALUE_SET, conn_mw_ble_gatts_value_set}, + {SD_BLE_GATTS_VALUE_GET, conn_mw_ble_gatts_value_get}, + {SD_BLE_GATTS_HVX, conn_mw_ble_gatts_hvx}, + {SD_BLE_GATTS_SERVICE_CHANGED, conn_mw_ble_gatts_service_changed}, + {SD_BLE_GATTS_RW_AUTHORIZE_REPLY, conn_mw_ble_gatts_rw_authorize_reply}, + {SD_BLE_GATTS_SYS_ATTR_SET, conn_mw_ble_gatts_sys_attr_set}, + {SD_BLE_GATTS_SYS_ATTR_GET, conn_mw_ble_gatts_sys_attr_get}, + {SD_BLE_GATTS_INITIAL_USER_HANDLE_GET, conn_mw_ble_gatts_initial_user_handle_get}, + {SD_BLE_GATTS_ATTR_GET, conn_mw_ble_gatts_attr_get}, + {SD_BLE_GATTS_EXCHANGE_MTU_REPLY, conn_mw_ble_gatts_exchange_mtu_reply}, +#endif // // defined(BLE_STACK_SUPPORT_REQD) +#if defined(ANT_STACK_SUPPORT_REQD) + //Functions from ant_interface.h + {SVC_ANT_ENABLE, conn_mw_ant_enable}, + {SVC_ANT_CHANNEL_ASSIGN, conn_ant_channel_assign}, + {SVC_ANT_CHANNEL_OPEN, conn_ant_channel_open_with_offset}, + {SVC_ANT_CHANNEL_ID_SET, conn_ant_channel_id_set}, + {SVC_ANT_CHANNEL_PERIOD_SET, conn_ant_channel_period_set}, + {SVC_ANT_CHANNEL_RADIO_FREQ_SET, conn_ant_channel_radio_freq_set}, + {SVC_ANT_TX_BROADCAST_MESSAGE, conn_ant_broadcast_message_tx}, + {SVC_ANT_TX_ACKNOWLEDGED_MESSAGE, conn_ant_acknowledge_message_tx}, + {SVC_ANT_CHANNEL_UNASSIGN, conn_ant_channel_unassign}, + {SVC_ANT_CHANNEL_CLOSE, conn_ant_channel_close}, + {SVC_ANT_NETWORK_KEY_SET, conn_ant_network_address_set}, + {SVC_ANT_CHANNEL_RADIO_TX_POWER_SET, conn_ant_channel_radio_tx_power_set}, + {SVC_ANT_CHANNEL_SEARCH_TIMEOUT_SET, conn_ant_channel_rx_search_timeout_set}, + {SVC_ANT_CHANNEL_LOW_PRIO_RX_SEARCH_TIMEOUT_SET, conn_ant_channel_low_priority_rx_search_timeout_set}, + {SVC_ANT_PROX_SEARCH_SET, conn_ant_prox_search_set}, + {SVC_ANT_SEARCH_WAVEFORM_SET, conn_ant_search_waveform_set}, + {SVC_ANT_CHANNEL_ID_GET, conn_ant_channel_id_get}, + {SVC_ANT_CHANNEL_RADIO_FREQ_GET, conn_ant_channel_radio_freq_get}, + {SVC_ANT_CHANNEL_PERIOD_GET, conn_ant_channel_period_get}, + {SVC_ANT_SEARCH_CHANNEL_PRIORITY_SET, conn_ant_search_channel_priority_set}, + {SVC_ANT_ACTIVE_SEARCH_SHARING_CYCLES_SET, conn_ant_active_search_sharing_cycles_set}, + {SVC_ANT_LIB_CONFIG_SET, conn_ant_lib_config_set}, + {SVC_ANT_ACTIVE_SEARCH_SHARING_CYCLES_GET, conn_ant_active_search_sharing_cycles_get}, + {SVC_ANT_LIB_CONFIG_GET, conn_ant_lib_config_get}, + {SVC_ANT_LIB_CONFIG_CLEAR, conn_ant_lib_config_clear}, + {SVC_ANT_STACK_INIT, conn_ant_stack_reset}, + {SVC_ANT_RX_SCAN_MODE_START, conn_ant_rx_scan_mode_start}, + {SVC_ANT_ID_LIST_ADD, conn_ant_id_list_add}, + {SVC_ANT_ID_LIST_CONFIG, conn_ant_id_list_config}, + {SVC_ANT_CHANNEL_STATUS_GET, conn_ant_channel_status_get}, + {SVC_ANT_INIT_CW_TEST_MODE, conn_ant_cw_test_mode_init}, + {SVC_ANT_CW_TEST_MODE, conn_ant_cw_test_mode}, + {SVC_ANT_VERSION, conn_ant_version_get}, + {SVC_ANT_CAPABILITIES, conn_ant_capabilities_get}, + {SVC_ANT_CRYPTO_CHANNEL_ENABLE, conn_ant_crypto_channel_enable}, + {SVC_ANT_ADV_BURST_CONFIG_SET, conn_ant_adv_burst_config_set}, + {SVC_ANT_CRYPTO_KEY_SET, conn_ant_crypto_key_set}, + {SVC_ANT_CRYPTO_INFO_SET, conn_ant_crypto_info_set}, + {SVC_ANT_CRYPTO_INFO_GET, conn_ant_crypto_info_get}, + {SVC_ANT_COEX_CONFIG_SET, conn_ant_coex_config_set}, + {SVC_ANT_COEX_CONFIG_GET, conn_ant_coex_config_get}, +#endif // // defined(ANT_STACK_SUPPORT_REQD) +}; diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/common/conn_mw_nrf_soc.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/common/conn_mw_nrf_soc.c new file mode 100644 index 0000000..62d034e --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/common/conn_mw_nrf_soc.c @@ -0,0 +1,114 @@ +/** + * 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_conn.h" +#include "conn_mw_nrf_soc.h" +#include "ble_serialization.h" + +uint32_t conn_mw_power_system_off(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + uint32_t err_code = NRF_SUCCESS; + + err_code = power_system_off_req_dec(p_rx_buf, rx_buf_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = sd_power_system_off(); + /* There should be no return from sd_power_system_off() */ + + return err_code; +} + +uint32_t conn_mw_temp_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + int32_t temperature; + int32_t * p_temperature = &temperature; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = temp_get_req_dec(p_rx_buf, rx_buf_len, &p_temperature); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_temp_get(p_temperature); + + err_code = temp_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_temperature); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t conn_mw_ecb_block_encrypt(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len) +{ + SER_ASSERT_NOT_NULL(p_rx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf); + SER_ASSERT_NOT_NULL(p_tx_buf_len); + + nrf_ecb_hal_data_t ecb_data; + nrf_ecb_hal_data_t * p_ecb_data = &ecb_data; + + uint32_t err_code = NRF_SUCCESS; + uint32_t sd_err_code; + + err_code = ecb_block_encrypt_req_dec(p_rx_buf, rx_buf_len, &p_ecb_data); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + sd_err_code = sd_ecb_block_encrypt(p_ecb_data); + + err_code = ecb_block_encrypt_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_ecb_data); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/common/conn_mw_nrf_soc.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/common/conn_mw_nrf_soc.h new file mode 100644 index 0000000..7e029db --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/codecs/common/conn_mw_nrf_soc.h @@ -0,0 +1,118 @@ +/** + * 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 CONN_MW_NRF_SOC_H__ +#define CONN_MW_NRF_SOC_H__ + +/** + * @addtogroup ser_mw_common_codecs + * @{ + */ + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/**@brief Handles @ref sd_power_system_off command request. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + * @retval NRF_ERROR_NOT_SUPPORTED Handler failure. Opcode not supported. + */ +uint32_t conn_mw_power_system_off(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_temp_get command request and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + * @retval NRF_ERROR_NOT_SUPPORTED Handler failure. Opcode not supported. + */ +uint32_t conn_mw_temp_get(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + +/**@brief Handles @ref sd_ecb_block_encrypt command request and prepares response. + * + * @param[in] p_rx_buf Pointer to input buffer. + * @param[in] rx_buf_len Size of @p p_rx_buf. + * @param[out] p_tx_buf Pointer to output buffer. + * @param[in,out] p_tx_buf_len \c in: Size of \p p_tx_buf buffer. + * \c out: Length of valid data in \p p_tx_buf. + * + * @retval NRF_SUCCESS Handler success. + * @retval NRF_ERROR_NULL Handler failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Handler failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Handler failure. Invalid operation type. + * @retval NRF_ERROR_NOT_SUPPORTED Handler failure. Opcode not supported. + */ +uint32_t conn_mw_ecb_block_encrypt(uint8_t const * const p_rx_buf, + uint32_t rx_buf_len, + uint8_t * const p_tx_buf, + uint32_t * const p_tx_buf_len); + + +#ifdef __cplusplus +} +#endif + +/** @} */ + +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/hal/dtm_uart.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/hal/dtm_uart.c new file mode 100644 index 0000000..ea4f9b3 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/hal/dtm_uart.c @@ -0,0 +1,268 @@ +/** + * Copyright (c) 2012 - 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. + * + */ +/** + @defgroup dtm_standalone main.c + @{ + @ingroup ble_sdk_app_dtm_serial + @brief Stand-alone DTM application for UART interface. + + */ + +#include <stdint.h> +#include <stdbool.h> +#include "nrf.h" +#include "ble_dtm.h" +#include "nrf_gpio.h" +#include "dtm_uart.h" +#include "nrf_error.h" +#include "app_util.h" +#include "nrf_drv_uart.h" +#include "nrf_peripherals.h" +#include "app_util_platform.h" + +//Configuration parameters. +#define BITRATE UART_BAUDRATE_BAUDRATE_Baud57600 /**< Serial bitrate on the UART */ + +//@note: The BLE DTM 2-wire UART standard specifies 8 data bits, 1 stop bit, no flow control. +//These parameters are not configurable in the BLE standard. + +/**@details Maximum iterations needed in the main loop between stop bit 1st byte and start bit 2nd + * byte. DTM standard allows 5000us delay between stop bit 1st byte and start bit 2nd byte. + * As the time is only known when a byte is received, then the time between between stop bit 1st + * byte and stop bit 2nd byte becomes: + * 5000us + transmission time of 2nd byte. + * + * Byte transmission time is (Baud rate of 19200): + * 10bits * 1/19200 = approx. 520 us/byte (8 data bits + start & stop bit). + * + * Loop time on polling UART register for received byte is defined in ble_dtm.c as: + * UART_POLL_CYCLE = 260 us + * + * The max time between two bytes thus becomes (loop time: 260us / iteration): + * (5000us + 520us) / 260us / iteration = 21.2 iterations. + * + * This is rounded down to 21. + * + * @note If UART bit rate is changed, this value should be recalculated as well. + */ + +static uint32_t m_baud_rates[] = {[UART_BAUD_RATE_1200] = NRF_UART_BAUDRATE_1200, + [UART_BAUD_RATE_2400] = NRF_UART_BAUDRATE_2400, + [UART_BAUD_RATE_4800] = NRF_UART_BAUDRATE_4800, + [UART_BAUD_RATE_9600] = NRF_UART_BAUDRATE_9600, + [UART_BAUD_RATE_14400] = NRF_UART_BAUDRATE_14400, + [UART_BAUD_RATE_19200] = NRF_UART_BAUDRATE_19200, + [UART_BAUD_RATE_28800] = NRF_UART_BAUDRATE_28800, + [UART_BAUD_RATE_38400] = NRF_UART_BAUDRATE_38400, + [UART_BAUD_RATE_57600] = NRF_UART_BAUDRATE_57600, + [UART_BAUD_RATE_76800] = NRF_UART_BAUDRATE_76800, + [UART_BAUD_RATE_115200] = NRF_UART_BAUDRATE_115200 }; + + +static uint32_t m_iteration[] = {[UART_BAUD_RATE_1200] = 51, + [UART_BAUD_RATE_2400] = 35, + [UART_BAUD_RATE_4800] = 27, + [UART_BAUD_RATE_9600] = 23, + [UART_BAUD_RATE_14400] = 21, + [UART_BAUD_RATE_19200] = 21, + [UART_BAUD_RATE_28800] = 20, + [UART_BAUD_RATE_38400] = 20, + [UART_BAUD_RATE_57600] = 19, + [UART_BAUD_RATE_76800] = 19, + [UART_BAUD_RATE_115200] = 19, }; + +static uint32_t m_iterations_next_byte_max = 51; + +static nrf_drv_uart_t m_dtm_uart_driver = NRF_DRV_UART_INSTANCE(0); + +/**@brief Function for UART initialization. + */ +static uint32_t uart_init(app_uart_stream_comm_params_t * p_comm_params) +{ + if (p_comm_params->baud_rate > UART_BAUD_RATE_115200) + { + return NRF_ERROR_INVALID_PARAM; + } + + nrf_drv_uart_config_t config = NRF_DRV_UART_DEFAULT_CONFIG; + + config.pselrxd = p_comm_params->rx_pin_no; + config.pseltxd = p_comm_params->tx_pin_no; + config.baudrate = (nrf_uart_baudrate_t) m_baud_rates[p_comm_params->baud_rate]; + config.hwfc = NRF_UART_HWFC_DISABLED; + config.parity = NRF_UART_PARITY_EXCLUDED; +#ifdef UART_PRESENT + //Current implementation of DTM requires legacy UART features and + // it will not work on nrf52810. + config.use_easy_dma = false; +#endif + nrf_drv_uart_uninit(&m_dtm_uart_driver); + uint32_t err_code = nrf_drv_uart_init(&m_dtm_uart_driver, &config, NULL); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + nrf_drv_uart_rx_enable(&m_dtm_uart_driver); + + m_iterations_next_byte_max = m_iteration[p_comm_params->baud_rate]; + + return NRF_SUCCESS; +} + + +/**@brief Function for splitting UART command bit fields into separate command parameters for the DTM library. + * + * @param[in] command The packed UART command. + * @return result status from dtmlib. + */ +static uint32_t dtm_cmd_put(uint16_t command) +{ + dtm_cmd_t command_code = (command >> 14) & 0x03; + dtm_freq_t freq = (command >> 8) & 0x3F; + uint32_t length = (command >> 2) & 0x3F; + dtm_pkt_type_t payload = command & 0x03; + + //Check for Vendor Specific payload. + if (payload == 0x03) + { + /* Note that in a HCI adaption layer, as well as in the DTM PDU format, + the value 0x03 is a distinct bit pattern (PRBS15). Even though BLE does not + support PRBS15, this implementation re-maps 0x03 to DTM_PKT_VENDORSPECIFIC, + to avoid the risk of confusion, should the code be extended to greater coverage. + */ + payload = DTM_PKT_VENDORSPECIFIC; + } + return dtm_cmd(command_code, freq, length, payload); +} + + +/**@brief Function for application main entry. + * + * @details This function serves as an adaptation layer between a 2-wire UART interface and the + * dtmlib. After initialization, DTM commands submitted through the UART are forwarded to + * dtmlib and events (i.e. results from the command) is reported back through the UART. + */ +uint32_t dtm_start(app_uart_stream_comm_params_t uart_comm_params) +{ + uint32_t current_time; + uint32_t dtm_error_code; + uint32_t msb_time = 0; //Time when MSB of the DTM command was read. Used to catch stray bytes from "misbehaving" testers. + bool is_msb_read = false; //True when MSB of the DTM command has been read and the application is waiting for LSB. + uint16_t dtm_cmd_from_uart = 0; //Packed command containing command_code:freqency:length:payload in 2:6:6:2 bits. + uint8_t rx_byte; //Last byte read from UART. + dtm_event_t result; //Result of a DTM operation. + uint32_t err_code; + + err_code = uart_init(&uart_comm_params); + + if (err_code != NRF_SUCCESS) + { + return err_code; + } + + dtm_error_code = dtm_init(); + + if (dtm_error_code != DTM_SUCCESS) + { + //If DTM cannot be correctly initialized, then we just return. + return NRF_ERROR_INTERNAL; + } + + for (;; ) + { + //Will return every timeout, 625 us. + current_time = dtm_wait(); + + if (NRF_SUCCESS != nrf_drv_uart_rx(&m_dtm_uart_driver, &rx_byte,1)) + { + return NRF_ERROR_INTERNAL; + } + + if (!is_msb_read) + { + //This is first byte of two-byte command. + is_msb_read = true; + dtm_cmd_from_uart = ((dtm_cmd_t)rx_byte) << 8; + msb_time = current_time; + + //Go back and wait for 2nd byte of command word. + continue; + } + + //This is the second byte read; combine it with the first and process command + if (current_time > (msb_time + m_iterations_next_byte_max)) + { + //More than ~5mS after msb: Drop old byte, take the new byte as MSB. + //The variable is_msb_read will remains true. + //Go back and wait for 2nd byte of the command word. + dtm_cmd_from_uart = ((dtm_cmd_t)rx_byte) << 8; + msb_time = current_time; + continue; + } + + //2-byte UART command received. + is_msb_read = false; + dtm_cmd_from_uart |= (dtm_cmd_t)rx_byte; + + if (dtm_cmd_put(dtm_cmd_from_uart) != DTM_SUCCESS) + { + //Extended error handling may be put here. + //Default behavior is to return the event on the UART (see below); + //the event report will reflect any lack of success. + } + + //Retrieve result of the operation. This implementation will busy-loop + //for the duration of the byte transmissions on the UART. + if (dtm_event_get(&result)) + { + //Report command status on the UART. + uint8_t tx_byte = (result >> 8) & 0xFF; + + //Transmit MSB of the result. + (void)nrf_drv_uart_tx(&m_dtm_uart_driver, &tx_byte, 1); + + //Transmit LSB of the result. + tx_byte = result & 0xFF; + (void)nrf_drv_uart_tx(&m_dtm_uart_driver, &tx_byte, 1); + } + } +} + +/// @} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/hal/dtm_uart.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/hal/dtm_uart.h new file mode 100644 index 0000000..081bfb0 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/hal/dtm_uart.h @@ -0,0 +1,59 @@ +/** + * 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 DTM_UART_H__ +#define DTM_UART_H__ + +#include <stdint.h> +#include "dtm_uart_params.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define UART_PIN_DISCONNECTED 0xFFFFFFFF /**< Value indicating that no pin is connected to this UART register. */ + +uint32_t dtm_start(app_uart_stream_comm_params_t uart_comm_params); + + +#ifdef __cplusplus +} +#endif + +#endif // DTM_UART_H__ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/pstorage_platform.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/pstorage_platform.h new file mode 100644 index 0000000..f9a542f --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/pstorage_platform.h @@ -0,0 +1,103 @@ +/** + * 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. + * + */ +/** @cond To make doxygen skip this file */ + +/** @file + * This header contains defines regarding persistent storage that are specific to + * persistent storage implementation and application use case. + */ +#ifndef PSTORAGE_PL_H__ +#define PSTORAGE_PL_H__ + +#include <stdint.h> +#include "nrf.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static __INLINE uint16_t pstorage_flash_page_size() +{ + return (uint16_t)NRF_FICR->CODEPAGESIZE; +} + +#define PSTORAGE_FLASH_PAGE_SIZE pstorage_flash_page_size() /**< Size of one flash page. */ +#define PSTORAGE_FLASH_EMPTY_MASK 0xFFFFFFFF /**< Bit mask that defines an empty address in flash. */ + +static __INLINE uint32_t pstorage_flash_page_end() +{ + uint32_t bootloader_addr = NRF_UICR->NRFFW[0]; + + return ((bootloader_addr != PSTORAGE_FLASH_EMPTY_MASK) ? + (bootloader_addr/ PSTORAGE_FLASH_PAGE_SIZE) : NRF_FICR->CODESIZE); +} + +#define PSTORAGE_FLASH_PAGE_END pstorage_flash_page_end() + +#define PSTORAGE_NUM_OF_PAGES 2 /**< Number of flash pages allocated for the pstorage module excluding the swap page, configurable based on system requirements. */ +#define PSTORAGE_MIN_BLOCK_SIZE 0x0010 /**< Minimum size of block that can be registered with the module. Should be configured based on system requirements, recommendation for this value is to have at least the size of a word. */ + +#define PSTORAGE_DATA_START_ADDR ((PSTORAGE_FLASH_PAGE_END - PSTORAGE_NUM_OF_PAGES) \ + * PSTORAGE_FLASH_PAGE_SIZE) /**< Start address for persistent data, configurable according to system requirements. */ +#define PSTORAGE_DATA_END_ADDR (PSTORAGE_FLASH_PAGE_END * PSTORAGE_FLASH_PAGE_SIZE) /**< End address for persistent data, configurable according to system requirements. */ +#define PSTORAGE_MAX_BLOCK_SIZE PSTORAGE_FLASH_PAGE_SIZE /**< Maximum size of block that can be registered with the module. Should be configured based on system requirements. Also, should be greater than or equal to the minimum size. */ +#define PSTORAGE_CMD_QUEUE_SIZE 30 /**< Maximum number of flash access commands that can be maintained by the module for all applications. Configurable. */ + + +/** Abstracts persistently memory block identifier. */ +typedef uint32_t pstorage_block_t; + +typedef struct +{ + uint32_t module_id; /**< Module ID.*/ + pstorage_block_t block_id; /**< Block ID.*/ +} pstorage_handle_t; + +typedef uint16_t pstorage_size_t; /** Size of length and offset fields. */ + + +#ifdef __cplusplus +} +#endif + +#endif // PSTORAGE_PL_H__ + +/** @} */ +/** @endcond */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_cmd_decoder.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_cmd_decoder.c new file mode 100644 index 0000000..4107666 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_cmd_decoder.c @@ -0,0 +1,138 @@ +/** + * 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 <string.h> +#include "nordic_common.h" +#include "app_error.h" +#include "ble_serialization.h" +#include "ser_config.h" +#include "conn_mw.h" +#include "ser_hal_transport.h" +#include "ser_conn_cmd_decoder.h" +#include "ser_conn_handlers.h" +#include "nrf_log_ctrl.h" + +#define NRF_LOG_MODULE_NAME ser_conn_dec +#include "nrf_log.h" +NRF_LOG_MODULE_REGISTER(); + +uint32_t ser_conn_command_process(uint8_t * p_command, uint16_t command_len) +{ + SER_ASSERT_NOT_NULL(p_command); + SER_ASSERT_LENGTH_LEQ(SER_OP_CODE_SIZE, command_len); + + uint32_t err_code = NRF_SUCCESS; + uint8_t * p_tx_buf = NULL; + uint32_t tx_buf_len = 0; + uint8_t opcode = p_command[SER_CMD_OP_CODE_POS]; + uint32_t index = 0; + + /* Allocate a memory buffer from HAL Transport layer for transmitting the Command Response. + * Loop until a buffer is available. */ + NRF_LOG_INFO("Command process start"); + do + { + err_code = ser_hal_transport_tx_pkt_alloc(&p_tx_buf, (uint16_t *)&tx_buf_len); + if (err_code == NRF_ERROR_NO_MEM) + { + ser_conn_on_no_mem_handler(); + } + } + while (NRF_ERROR_NO_MEM == err_code); + + NRF_LOG_INFO("Tx buffer allocated"); + if (NRF_SUCCESS == err_code) + { + /* Create a new response packet. */ + p_tx_buf[SER_PKT_TYPE_POS] = SER_PKT_TYPE_RESP; + tx_buf_len -= SER_PKT_TYPE_SIZE; + + /* Decode a request, pass a memory for a response command (opcode + data) and encode it. */ + err_code = conn_mw_handler + (p_command, command_len, &p_tx_buf[SER_PKT_OP_CODE_POS], &tx_buf_len); + + + /* Command decoder not found. */ + if (NRF_ERROR_NOT_SUPPORTED == err_code) + { + NRF_LOG_ERROR("Command not supported opcode:%d", p_tx_buf[SER_PKT_OP_CODE_POS]); + APP_ERROR_CHECK(SER_WARNING_CODE); + err_code = op_status_enc + (opcode, NRF_ERROR_NOT_SUPPORTED, + &p_tx_buf[SER_PKT_OP_CODE_POS], &tx_buf_len, &index); + if (NRF_SUCCESS == err_code) + { + tx_buf_len += SER_PKT_TYPE_SIZE; + err_code = ser_hal_transport_tx_pkt_send(p_tx_buf, (uint16_t)tx_buf_len); + /* TX buffer is going to be freed automatically in the HAL Transport layer. */ + if (NRF_SUCCESS != err_code) + { + err_code = NRF_ERROR_INTERNAL; + } + } + else + { + err_code = NRF_ERROR_INTERNAL; + } + } + else if (NRF_SUCCESS == err_code) /* Send a response. */ + { + tx_buf_len += SER_PKT_TYPE_SIZE; + err_code = ser_hal_transport_tx_pkt_send(p_tx_buf, (uint16_t)tx_buf_len); + + /* TX buffer is going to be freed automatically in the HAL Transport layer. */ + if (NRF_SUCCESS != err_code) + { + err_code = NRF_ERROR_INTERNAL; + } + } + else + { + NRF_LOG_ERROR("Internal error during command decoding."); + err_code = NRF_ERROR_INTERNAL; + } + } + else + { + err_code = NRF_ERROR_INTERNAL; + } + + return err_code; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_cmd_decoder.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_cmd_decoder.h new file mode 100644 index 0000000..0b3d505 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_cmd_decoder.h @@ -0,0 +1,89 @@ +/** + * 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. + * + */ +/** + * @addtogroup ser_conn Connectivity application code + * @ingroup ble_sdk_lib_serialization + */ + +/** @file + * + * @defgroup ser_cmd_decoder Command decoder in the Connectivity Chip + * @{ + * @ingroup ser_conn + * + * @brief Decoder for serialized commands from the Application Chip. + * + * @details This file contains declaration of common function used for commands decoding and sending + * responses back to the Application Chip after a command is processed. + */ + +#ifndef SER_CONN_CMD_DECODER_H__ +#define SER_CONN_CMD_DECODER_H__ + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/**@brief A function decodes an encoded command and sends a response to the Application Chip. + * + * @details The function decodes an encoded command and calls a SoftDevice API function when a + * command decoder is found or forms a common response with error code + * NRF_ERROR_NOT_SUPPORTED otherwise. Then the function sends a SoftDevice response or + * the response with NRF_ERROR_NOT_SUPPORTED error code to the Application Chip. + * + * @param[in] p_command The encoded command. + * @param[in] command_len Length of the encoded command including opcode. + * + * @retval NRF_SUCCESS Operation success. + * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied. + * @retval NRF_ERROR_INTERNAL Operation failure. Internal error ocurred. . + */ +uint32_t ser_conn_command_process(uint8_t * p_command, uint16_t command_len); + + +#ifdef __cplusplus +} +#endif + +#endif /* SER_CONN_CMD_DECODER_H__ */ + +/** @} */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_dtm_cmd_decoder.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_dtm_cmd_decoder.c new file mode 100644 index 0000000..8a76238 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_dtm_cmd_decoder.c @@ -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. + * + */ +#include "app_util.h" +#include "ble_dtm_conn.h" +#include "ble_serialization.h" +#include "nrf_error.h" +#include "nrf_sdm.h" +#include "ser_conn_dtm_cmd_decoder.h" +#include "ser_conn_handlers.h" +#include "ser_hal_transport.h" + +static bool m_is_ready_to_enter_dtm = false; +static app_uart_stream_comm_params_t m_comm_params = { 0 }; + +uint32_t ser_conn_dtm_command_process(uint8_t * p_command, uint16_t command_len) +{ + SER_ASSERT_NOT_NULL(p_command); + + uint32_t err_code = NRF_SUCCESS; + uint8_t * p_tx_buf = NULL; + uint32_t tx_buf_len = 0; + + /* Allocate a memory buffer from HAL Transport layer for transmitting the Command Response. + * Loop until a buffer is available. */ + do + { + err_code = ser_hal_transport_tx_pkt_alloc(&p_tx_buf, (uint16_t *)&tx_buf_len); + if (err_code == NRF_ERROR_NO_MEM) + { + ser_conn_on_no_mem_handler(); + } + } + while (NRF_ERROR_NO_MEM == err_code); + + if (err_code == NRF_SUCCESS) + { + p_tx_buf[SER_PKT_TYPE_POS] = SER_PKT_TYPE_DTM_RESP; + tx_buf_len -= SER_PKT_TYPE_SIZE; + + err_code = ble_dtm_init_req_dec(p_command, command_len, &m_comm_params); + + if (NRF_SUCCESS == err_code) + { + err_code = ble_dtm_init_rsp_enc(NRF_SUCCESS, + &p_tx_buf[SER_PKT_TYPE_SIZE], + &tx_buf_len); + + if (err_code != NRF_SUCCESS) + { + return NRF_ERROR_INTERNAL; + } + + tx_buf_len += SER_PKT_TYPE_SIZE; + + /* Set a flag that device is ready to enter DTM mode. */ + m_is_ready_to_enter_dtm = true; + + err_code = ser_hal_transport_tx_pkt_send(p_tx_buf, (uint16_t)tx_buf_len); + if (err_code != NRF_SUCCESS) + { + err_code = NRF_ERROR_INTERNAL; + } + + /* TX buffer is going to be freed automatically in the HAL Transport layer. */ + } + else + { + err_code = NRF_ERROR_INTERNAL; + } + } + + return err_code; +} + + +void ser_conn_is_ready_to_enter_dtm(void) +{ + if (m_is_ready_to_enter_dtm) + { + /* Disable SoftDevice. */ + (void)sd_softdevice_disable(); + + /* Close HAL Transport Layer. */ + ser_hal_transport_close(); + + /* Start DTM mode. */ + (void)dtm_start(m_comm_params); + } +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_dtm_cmd_decoder.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_dtm_cmd_decoder.h new file mode 100644 index 0000000..13e6bdb --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_dtm_cmd_decoder.h @@ -0,0 +1,98 @@ +/** + * 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. + * + */ +/** + * @addtogroup ser_conn Connectivity application code + * @ingroup ble_sdk_lib_serialization + */ + +/** @file + * + * @defgroup ser_dtm_decoder DTM Command Decoder in the Connectivity Chip + * @{ + * @ingroup ser_conn + * + * @brief Decoder for serialized DTM commands from the Application Chip. + * + * @details This file contains declaration of common function used for DTM commands decoding and + * sending responses back to the Application Chip after a DTM command is processed. + */ + +#ifndef SER_CONN_DTM_CMD_DECODER_H__ +#define SER_CONN_DTM_CMD_DECODER_H__ + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/**@brief A function for processing the encoded DTM commands from the Application Chip. + * + * @details The function decodes encoded DTM commands and calls the appropriate DTM API. + * Then creates a DTM Command Response packet with the return value from the + * DTM API encoded in it and sends it to the Application Chip. + * + * @param[in] p_command The encoded command. + * @param[in] command_len Length of the encoded command. + * + * @retval NRF_SUCCESS If the decoding of the command was successful, the DTM API + * was called, and the command response was sent to peer, otherwise an + * error code. + */ +uint32_t ser_conn_dtm_command_process(uint8_t * p_command, uint16_t command_len); + + +/**@brief A function for checking if the Connectivity Chip is ready to enter the DTM mode. + * + * @details The function checks if the Connectivity Chip is ready to enter into DTM mode. + * If it is ready, then it disables the SoftDevice, closes HAL Transport Layer, + * and starts DTM mode. + */ +void ser_conn_is_ready_to_enter_dtm(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* SER_CONN_DTM_CMD_DECODER_H__ */ + +/** @} */ + diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_error_handling.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_error_handling.c new file mode 100644 index 0000000..459bc14 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_error_handling.c @@ -0,0 +1,138 @@ +/** + * 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_assert.h" +#include "app_error.h" +#include "ser_config.h" + +#include "boards.h" + +/** @file + * + * @defgroup ser_conn_error_handling Errors handling for the Connectivity Chip. + * @{ + * @ingroup sdk_lib_serialization + * + * @brief A module to handle the Connectivity Chip errors and warnings. + * + * @details This file contains definitions of functions used for handling the Connectivity Chip + * errors and warnings. + */ + +/**@brief Function for handling the Connectivity Chip errors and warnings. + * + * @details This function will be called if the ASSERT macro in the connectivity application fails. + * Function declaration can be found in the app_error.h file. + * + * @param[in] error_code Error code supplied to the handler. + * @param[in] line_num Line number where the handler is called. + * @param[in] p_file_name Pointer to the file name. + */ + +#include "app_util_platform.h" +#include "nrf_soc.h" +#include "nrf_log.h" +#include "nrf_log_ctrl.h" + +// uint32_t m_error_code; +// uint32_t m_error_line_num; +// const uint8_t *m_p_error_file_name; + +/*lint -save -e14 */ +void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info) +{ + // disable INTs + CRITICAL_REGION_ENTER(); + + NRF_LOG_ERROR("Fatal error"); + NRF_LOG_FINAL_FLUSH(); + + #if LEDS_NUMBER > 0 + + /* Light a LED on error or warning. */ + // nrf_gpio_cfg_output(SER_CONN_ASSERT_LED_PIN); + // nrf_gpio_pin_set(SER_CONN_ASSERT_LED_PIN); + + #endif + + // m_p_error_file_name = p_file_name; + // m_error_code = error_code; + // m_error_line_num = line_num; + + /* Do not reset when warning. */ + if (SER_WARNING_CODE != id) + { + /* This call can be used for debug purposes during application development. + * @note CAUTION: Activating code below will write the stack to flash on an error. + * This function should NOT be used in a final product. + * It is intended STRICTLY for development/debugging purposes. + * The flash write will happen EVEN if the radio is active, thus interrupting any communication. + * Use with care. Un-comment the line below to use. */ + + /* ble_debug_assert_handler(error_code, line_num, p_file_name); */ + +#ifndef DEBUG + /* Reset the chip. Should be used in the release version. */ + NVIC_SystemReset(); +#else /* Debug version. */ + /* To be able to see function parameters in a debugger. */ + uint32_t temp = 1; + while (temp); +#endif + + } + + CRITICAL_REGION_EXIT(); +} +/*lint -restore */ + + +/**@brief Callback function for asserts in the SoftDevice. + * + * @details This function will be called if the ASSERT macro in the SoftDevice fails. Function + * declaration can be found in the nrf_assert.h file. + * + * @param[in] line_num Line number of the failing ASSERT call. + * @param[in] p_file_name File name of the failing ASSERT call. + */ +void assert_nrf_callback(uint16_t line_num, const uint8_t * p_file_name) +{ + app_error_handler(SER_SD_ERROR_CODE, line_num, p_file_name); +} +/** @} */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_event_encoder.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_event_encoder.c new file mode 100644 index 0000000..c6a0a37 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_event_encoder.c @@ -0,0 +1,169 @@ +/** + * 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 <stdint.h> +#include "app_error.h" +#include "app_scheduler.h" +#include "ble_serialization.h" +#include "ser_config.h" +#include "ser_hal_transport.h" +#include "ser_conn_event_encoder.h" +#include "ser_conn_handlers.h" +#ifdef BLE_STACK_SUPPORT_REQD +#include "ble_conn.h" +#endif // BLE_STACK_SUPPORT_REQD + +#ifdef ANT_STACK_SUPPORT_REQD +#include "ant_event.h" +#endif // ANT_STACK_SUPPORT_REQD + +#ifdef BLE_STACK_SUPPORT_REQD +void ser_conn_ble_event_encoder(void * p_event_data, uint16_t event_size) +{ + if (NULL == p_event_data) + { + APP_ERROR_CHECK(NRF_ERROR_NULL); + } + UNUSED_PARAMETER(event_size); + + uint32_t err_code = NRF_SUCCESS; + uint8_t * p_tx_buf = NULL; + uint32_t tx_buf_len = 0; + ble_evt_t * p_ble_evt = (ble_evt_t *)p_event_data; + + /* Allocate a memory buffer from HAL Transport layer for transmitting an event. + * Loop until a buffer is available. */ + do + { + err_code = ser_hal_transport_tx_pkt_alloc(&p_tx_buf, (uint16_t *)&tx_buf_len); + if (err_code == NRF_ERROR_NO_MEM) + { + ser_conn_on_no_mem_handler(); + } + } + while (err_code == NRF_ERROR_NO_MEM); + APP_ERROR_CHECK(err_code); + + /* Create a new packet. */ + p_tx_buf[SER_PKT_TYPE_POS] = SER_PKT_TYPE_EVT; + tx_buf_len -= SER_PKT_TYPE_SIZE; + + /* Pass a memory for an event (opcode + data) and encode it. */ + err_code = ble_event_enc(p_ble_evt, 0, &p_tx_buf[SER_PKT_OP_CODE_POS], &tx_buf_len); + + if (NRF_ERROR_NOT_SUPPORTED != err_code) + { + APP_ERROR_CHECK(err_code); + tx_buf_len += SER_PKT_TYPE_SIZE; + err_code = ser_hal_transport_tx_pkt_send(p_tx_buf, (uint16_t)tx_buf_len); + APP_ERROR_CHECK(err_code); + /* TX buffer is going to be freed automatically in the HAL Transport layer. + * Scheduler must be paused because this function returns before a packet is physically sent + * by transport layer. This can cause start processing of a next event from the application + * scheduler queue. In result the next event reserves the TX buffer before the current + * packet is sent. If in meantime a command arrives a command response cannot be sent in + * result. Pausing the scheduler temporary prevents processing a next event. */ + app_sched_pause(); + } + else + { + /* Event was NOT encoded, therefore the buffer is freed immediately. */ + err_code = ser_hal_transport_tx_pkt_free(p_tx_buf); + APP_ERROR_CHECK(err_code); + APP_ERROR_CHECK(SER_WARNING_CODE); + } +} +#endif // BLE_STACK_SUPPORT_REQD + +#ifdef ANT_STACK_SUPPORT_REQD +void ser_conn_ant_event_encoder(void * p_event_data, uint16_t event_size) +{ + + if (NULL == p_event_data) + { + APP_ERROR_CHECK(NRF_ERROR_NULL); + } + UNUSED_PARAMETER(event_size); + + uint32_t err_code = NRF_SUCCESS; + uint8_t * p_tx_buf = NULL; + uint32_t tx_buf_len = 0; + ant_evt_t * p_ant_evt = (ant_evt_t *)p_event_data; + + /* Allocate a memory buffer from HAL Transport layer for transmitting an event. + * Loop until a buffer is available. */ + do + { + err_code = ser_hal_transport_tx_pkt_alloc(&p_tx_buf, (uint16_t *)&tx_buf_len); + } + while (err_code == NRF_ERROR_NO_MEM); + APP_ERROR_CHECK(err_code); + + /* Create a new packet. */ + p_tx_buf[SER_PKT_TYPE_POS] = SER_PKT_TYPE_ANT_EVT; + tx_buf_len -= SER_PKT_TYPE_SIZE; + + /* Pass a memory for an event (opcode + data) and encode it. */ + err_code = ant_event_enc(p_ant_evt, 0, &p_tx_buf[SER_PKT_OP_CODE_POS], &tx_buf_len); + + if (NRF_ERROR_NOT_SUPPORTED != err_code) + { + APP_ERROR_CHECK(err_code); + tx_buf_len += SER_PKT_TYPE_SIZE; + err_code = ser_hal_transport_tx_pkt_send(p_tx_buf, (uint16_t)tx_buf_len); + APP_ERROR_CHECK(err_code); + /* TX buffer is going to be freed automatically in the HAL Transport layer. + * Scheduler must be paused because this function returns before a packet is physically sent + * by transport layer. This can cause start processing of a next event from the application + * scheduler queue. In result the next event reserves the TX buffer before the current + * packet is sent. If in meantime a command arrives a command response cannot be sent in + * result. Pausing the scheduler temporary prevents processing a next event. */ + app_sched_pause(); + } + else + { + /* Event was NOT encoded, therefore the buffer is freed immediately. */ + err_code = ser_hal_transport_tx_pkt_free(p_tx_buf); + APP_ERROR_CHECK(err_code); + APP_ERROR_CHECK(SER_WARNING_CODE); + } + +} +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_event_encoder.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_event_encoder.h new file mode 100644 index 0000000..b5bf698 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_event_encoder.h @@ -0,0 +1,99 @@ +/** + * 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. + * + */ +/** + * @addtogroup ser_conn Connectivity application code + * @ingroup ble_sdk_lib_serialization + * @brief Encoders, decoders, and event handlers related to the Connectivity Chip. + */ + +/** @file + * + * @defgroup ser_event_encoder Events encoder in the Connectivity Chip + * @{ + * @ingroup ser_conn + * + * @brief Events encoder for BLE SoftDevice. + * + * @details This file contains declaration of common function used for serializing BLE SoftDevice + * events. + * + */ +#ifndef SER_CONN_EVENT_ENCODER_H__ +#define SER_CONN_EVENT_ENCODER_H__ + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/**@brief A function for encoding a @ref ble_evt_t. The function passes the serialized byte stream + * to the transport layer after encoding. + * + * @details The function is called by the application scheduler to process an event previously + * pulled from BLE SoftDevice. + * The function creates a new packet, calls an appropriate event encoder and sends the + * packet to the Application Chip. + * + * @param[in] p_event_data Pointer to event data of type @ref ble_evt_t. + * @param[in] event_size Event data size. + */ +void ser_conn_ble_event_encoder(void * p_event_data, uint16_t event_size); + +/**@brief A function for encoding a @ref ant_evt_t. The function passes the serialized byte stream + * to the transport layer after encoding. + * + * @details The function is called by the application scheduler to process an event previously + * pulled from ANT SoftDevice. + * The function creates a new packet, calls an appropriate event encoder and sends the + * packet to the Application Chip. + * + * @param[in] p_event_data Pointer to event data of type @ref ant_evt_t. + * @param[in] event_size Event data size. + */ +void ser_conn_ant_event_encoder(void * p_event_data, uint16_t event_size); + +#ifdef __cplusplus +} +#endif + +#endif /* SER_CONN_EVENT_ENCODER_H__ */ + +/** @} */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_handlers.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_handlers.c new file mode 100644 index 0000000..fbcf901 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_handlers.c @@ -0,0 +1,207 @@ +/** + * 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 "app_error.h" +#include "app_scheduler.h" +#include "ser_config.h" +#include "ser_conn_handlers.h" +#include "ser_conn_event_encoder.h" +#include "ser_conn_pkt_decoder.h" +#include "ser_conn_dtm_cmd_decoder.h" +#include "nrf_sdh.h" +#ifdef BLE_STACK_SUPPORT_REQD +#include "conn_ble_gap_sec_keys.h" +#endif + +/** @file + * + * @defgroup ser_conn_handlers Events handlers for the Connectivity Chip. + * @{ + * @ingroup sdk_lib_serialization + * + * @brief A module to handle the Connectivity application events. + * + * @details There are two types of events in the Connectivity application: BLE events generated by + * the SoftDevice and events generated by the HAL Transport layer. + */ + +/** Parameters of a received packet. */ +static ser_hal_transport_evt_rx_pkt_received_params_t m_rx_pkt_received_params; + +/** Indicator of received packet that should be process. */ +static bool m_rx_pkt_to_process = false; + +static ser_conn_on_no_mem_t m_on_no_mem_handler; + +void ser_conn_on_no_mem_handler_set(ser_conn_on_no_mem_t handler) +{ + m_on_no_mem_handler = handler; +} + +void ser_conn_on_no_mem_handler(void) +{ + if (m_on_no_mem_handler) + { + m_on_no_mem_handler(); + } +} +void ser_conn_hal_transport_event_handle(ser_hal_transport_evt_t event) +{ + switch (event.evt_type) + { + case SER_HAL_TRANSP_EVT_TX_PKT_SENT: + { + /* SoftDevice event or response to received packet was sent, so unblock the application + * scheduler to process a next event. */ + app_sched_resume(); + + /* Check if chip is ready to enter DTM mode. */ + ser_conn_is_ready_to_enter_dtm(); + + break; + } + + case SER_HAL_TRANSP_EVT_RX_PKT_RECEIVING: + { + /* The connectivity side has started receiving a packet. Temporary block processing + * SoftDevice events. It is going to be unblocked when a response for the packet will + * be sent. This prevents communication block. */ + app_sched_pause(); + break; + } + + case SER_HAL_TRANSP_EVT_RX_PKT_RECEIVED: + { + /* We can NOT add received packets as events to the application scheduler queue because + * received packets have to be processed before SoftDevice events but the scheduler + * queue do not have priorities. */ + memcpy(&m_rx_pkt_received_params, &event.evt_params.rx_pkt_received, + sizeof (ser_hal_transport_evt_rx_pkt_received_params_t)); + m_rx_pkt_to_process = true; + break; + } + + case SER_HAL_TRANSP_EVT_RX_PKT_DROPPED: + { + APP_ERROR_CHECK(SER_WARNING_CODE); + break; + } + + case SER_HAL_TRANSP_EVT_PHY_ERROR: + { + APP_ERROR_CHECK(NRF_ERROR_FORBIDDEN); + break; + } + + default: + { + /* do nothing */ + break; + } + } +} + + +uint32_t ser_conn_rx_process(void) +{ + uint32_t err_code = NRF_SUCCESS; + + if (m_rx_pkt_to_process) + { + /* No critical section needed on m_rx_pkt_to_process parameter because it is not possible + * to get next packet before sending a response. */ + m_rx_pkt_to_process = false; + err_code = ser_conn_received_pkt_process(&m_rx_pkt_received_params); + } + + return err_code; +} + +#ifdef BLE_STACK_SUPPORT_REQD + +NRF_SDH_BLE_OBSERVER(m_ble_observer, 0, ser_conn_ble_event_handle, NULL); + +void ser_conn_ble_event_handle(ble_evt_t const * p_ble_evt, void * p_context) +{ + uint32_t err_code = NRF_SUCCESS; + + /* We can NOT encode and send BLE events here. SoftDevice handler implemented in + * softdevice_handler.c pull all available BLE events at once but we need to reschedule between + * encoding and sending every BLE event because sending a response on received packet has higher + * priority than sending a BLE event. Solution for that is to put BLE events into application + * scheduler queue to be processed at a later time. */ + err_code = app_sched_event_put(p_ble_evt, p_ble_evt->header.evt_len, + ser_conn_ble_event_encoder); + APP_ERROR_CHECK(err_code); + uint16_t free_space = app_sched_queue_space_get(); + if (!free_space) + { + // Queue is full. Do not pull new events. + nrf_sdh_suspend(); + } +} +#endif // BLE_STACK_SUPPORT_REQD + +#ifdef ANT_STACK_SUPPORT_REQD + +NRF_SDH_ANT_OBSERVER(m_ant_observer, 0, ser_conn_ant_event_handle, NULL); + +void ser_conn_ant_event_handle(ant_evt_t * p_ant_evt, void * p_context) +{ + uint32_t err_code = NRF_SUCCESS; + + /* We can NOT encode and send ANT events here. SoftDevice handler implemented in + * softdevice_handler.c pull all available ANT events at once but we need to reschedule between + * encoding and sending every ANT event because sending a response on received packet has higher + * priority than sending an ANT event. Solution for that is to put ANT events into application + * scheduler queue to be processed at a later time. */ + err_code = app_sched_event_put(p_ant_evt, sizeof (ant_evt_t), + ser_conn_ant_event_encoder); + APP_ERROR_CHECK(err_code); + uint16_t free_space = app_sched_queue_space_get(); + if (!free_space) + { + // Queue is full. Do not pull new events. + nrf_sdh_suspend(); + } +} +#endif // ANT_STACK_SUPPORT_REQD + +/** @} */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_handlers.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_handlers.h new file mode 100644 index 0000000..7843a71 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_handlers.h @@ -0,0 +1,162 @@ +/** + * 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. + * + */ +/** + * @addtogroup ser_conn Connectivity application code + * @ingroup ble_sdk_lib_serialization + */ + + +/** @file + * + * @defgroup ser_conn_handlers Events handlers in the Connectivity Chip + * @{ + * @ingroup ser_conn + * + * @brief Events handlers used to process high level events in the connectivity application. + * + * @details This file contains functions: processing the HAL Transport layer events, processing BLE + * SoftDevice events, starting processing received packets. + */ + +#ifndef SER_CONN_HANDLERS_H__ +#define SER_CONN_HANDLERS_H__ + +#include <stdint.h> +#include "nordic_common.h" +#include "app_util.h" +#include "ser_hal_transport.h" + +#ifdef BLE_STACK_SUPPORT_REQD +#include "ble.h" +#include "nrf_sdh_ble.h" +#endif // BLE_STACK_SUPPORT_REQD + +#ifdef ANT_STACK_SUPPORT_REQD +#include "nrf_sdh_ant.h" +#endif // ANT_STACK_SUPPORT_REQD + +#ifdef __cplusplus +extern "C" { +#endif + +/** Maximum number of events in the application scheduler queue. */ +#define SER_CONN_SCHED_QUEUE_SIZE 4u + +/** Maximum size of events data in the application scheduler queue aligned to 32 bits - this is + * size of the buffers of the SoftDevice handler, which stores events pulled from the SoftDevice. + */ + +#if defined(BLE_STACK_SUPPORT_REQD) && defined(ANT_STACK_SUPPORT_REQD) +#define STACK_EVENT_MAX_SIZE MAX(NRF_SDH_BLE_EVT_BUF_SIZE, NRF_SDH_ANT_EVT_BUF_SIZE) +#elif defined(BLE_STACK_SUPPORT_REQD) +#define STACK_EVENT_MAX_SIZE NRF_SDH_BLE_EVT_BUF_SIZE +#elif defined(ANT_STACK_SUPPORT_REQD) +#define STACK_EVENT_MAX_SIZE NRF_SDH_ANT_EVT_BUF_SIZE +#endif + + +#define SER_CONN_SCHED_MAX_EVENT_DATA_SIZE ((CEIL_DIV(MAX(STACK_EVENT_MAX_SIZE, \ + sizeof(uint32_t)), \ + sizeof(uint32_t))) * \ + sizeof(uint32_t)) + +/** @brief Prototype for function called when there is no free TX buffer and system is blocked */ +typedef void (*ser_conn_on_no_mem_t)(void); + +/** + * @brief A function for setting handler which should be called when serialization + * is blocked waiting for TX buffer. + * + * @param handler Handler to be called whenever serialization failed to allocate TX buffer + * + */ +void ser_conn_on_no_mem_handler_set(ser_conn_on_no_mem_t handler); + +/** + * @brief A function called when TX buffer allocation failed. Serialization is always allocating TX + * buffer in main context expecting that it will be freed from interrupt context. + */ +void ser_conn_on_no_mem_handler(void); + + +/**@brief A function for processing the HAL Transport layer events. + * + * @param[in] event HAL Transport layer event. + */ +void ser_conn_hal_transport_event_handle(ser_hal_transport_evt_t event); + + +/**@brief A function to call the function to process a packet when it is fully received. + * + * @retval NRF_SUCCESS Operation success. + * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied. + * @retval NRF_ERROR_INTERNAL Operation failure. Internal error ocurred. + */ +uint32_t ser_conn_rx_process(void); + + +#ifdef BLE_STACK_SUPPORT_REQD +/**@brief A function for processing BLE SoftDevice events. + * + * @details BLE events are put into application scheduler queue to be processed at a later time. + * + * @param[in] p_ble_evt A pointer to a BLE event. + * @param[in] p_context A parameter to the handler. Not used. + */ +void ser_conn_ble_event_handle(ble_evt_t const * p_ble_evt, void * p_context); +#endif // BLE_STACK_SUPPORT_REQD + +#ifdef ANT_STACK_SUPPORT_REQD +/**@brief A function for processing ANT SoftDevice events. + * + * @details ANT events are put into application scheduler queue to be processed at a later time. + * + * @param[in] p_ant_evt A pointer to a BLE event. + * @param[in] p_context A parameter to the handler. Not used. + */ +void ser_conn_ant_event_handle(ant_evt_t * p_ant_evt, void * p_context); +#endif // ANT_STACK_SUPPORT_REQD + +#ifdef __cplusplus +} +#endif + +#endif /* SER_CONN_HANDLERS_H__ */ +/** @} */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_pkt_decoder.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_pkt_decoder.c new file mode 100644 index 0000000..4ddd558 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_pkt_decoder.c @@ -0,0 +1,124 @@ +/** + * 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 <string.h> +#include "nordic_common.h" +#include "app_error.h" +#include "ble_serialization.h" +#include "ser_config.h" +#include "ser_hal_transport.h" +#include "ser_conn_pkt_decoder.h" +#include "ser_conn_cmd_decoder.h" +#include "ser_conn_dtm_cmd_decoder.h" +#include "ser_conn_reset_cmd_decoder.h" +#include "ser_dbg_sd_str.h" + +#define NRF_LOG_MODULE_NAME ser_conn +#include "nrf_log.h" +NRF_LOG_MODULE_REGISTER(); + +uint32_t ser_conn_received_pkt_process( + ser_hal_transport_evt_rx_pkt_received_params_t * p_rx_pkt_params) +{ + uint32_t err_code = NRF_SUCCESS; + + if (NULL != p_rx_pkt_params) + { + /* For further processing pass only command (opcode + data). */ + uint8_t * p_command = &p_rx_pkt_params->p_buffer[SER_PKT_OP_CODE_POS]; + uint16_t command_len = p_rx_pkt_params->num_of_bytes - SER_PKT_TYPE_SIZE; + + NRF_LOG_DEBUG("[SD_CALL]:%s", + (uint32_t)ser_dbg_sd_call_str_get(*p_command)); + + switch (p_rx_pkt_params->p_buffer[SER_PKT_TYPE_POS]) + { + #if defined(ANT_STACK_SUPPORT_REQD) + case SER_PKT_TYPE_ANT_CMD: + //!! INTENTIONAL FALLTHROUGH + #endif + case SER_PKT_TYPE_CMD: + { + err_code = ser_conn_command_process(p_command, command_len); + break; + } + + case SER_PKT_TYPE_DTM_CMD: + { + err_code = ser_conn_dtm_command_process(p_command, command_len); + break; + } + + case SER_PKT_TYPE_RESET_CMD: + { + ser_conn_reset_command_process(); + break; + } + + default: + { + APP_ERROR_CHECK(SER_WARNING_CODE); + break; + } + } + + if (NRF_SUCCESS == err_code) + { + /* Free a received packet. */ + err_code = ser_hal_transport_rx_pkt_free(p_rx_pkt_params->p_buffer); + + if (NRF_SUCCESS != err_code) + { + err_code = NRF_ERROR_INTERNAL; + } + } + else + { + NRF_LOG_ERROR("Command processing error:%d", err_code); + err_code = NRF_ERROR_INTERNAL; + } + } + else + { + err_code = NRF_ERROR_NULL; + } + + return err_code; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_pkt_decoder.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_pkt_decoder.h new file mode 100644 index 0000000..bf612ba --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_pkt_decoder.h @@ -0,0 +1,90 @@ +/** + * 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. + * + */ +/** + * @addtogroup ser_conn Connectivity application code + * @ingroup ble_sdk_lib_serialization + */ + +/** @file + * + * @defgroup ser_pkt_decoder Packets decoder in the Connectivity Chip + * @{ + * @ingroup ser_conn + * + * @brief Decoder for serialized packets from the Application Chip. + * + * @details This file contains declaration of common function used for processing packets (packets + * dispatcher) received by the transport layer. + */ + +#ifndef SER_CONN_PKT_DECODER_H__ +#define SER_CONN_PKT_DECODER_H__ + +#include <stdint.h> +#include "ser_hal_transport.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/**@brief A function for dispatching packets from the Application Chip to an appropriate decoder. + * + * @details The function is called to process received packets from a transport layer. + * The function analyzes packet type and calls appropriate command decoder which among + * other things processes command and sends a response. Then a received packet is freed. + * + * @param[in] p_rx_pkt_params A pointer to a transport layer event of type + * @ref ser_hal_transport_evt_rx_pkt_received_params_t. + * + * @retval NRF_SUCCESS Operation success. + * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied. + * @retval NRF_ERROR_INTERNAL Operation failure. Internal error ocurred. + */ +uint32_t ser_conn_received_pkt_process( + ser_hal_transport_evt_rx_pkt_received_params_t * p_rx_pkt_params); + + +#ifdef __cplusplus +} +#endif + +#endif /* SER_CONN_PKT_DECODER_H__ */ + +/** @} */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_reset_cmd_decoder.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_reset_cmd_decoder.c new file mode 100644 index 0000000..924a932 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_reset_cmd_decoder.c @@ -0,0 +1,47 @@ +/** + * 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_nvic.h" +#include "ser_conn_reset_cmd_decoder.h" + +void ser_conn_reset_command_process() +{ + (void)sd_nvic_SystemReset(); + while (1); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_reset_cmd_decoder.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_reset_cmd_decoder.h new file mode 100644 index 0000000..6d539cd --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/connectivity/ser_conn_reset_cmd_decoder.h @@ -0,0 +1,81 @@ +/** + * 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. + * + */ +/** + * @addtogroup ser_conn Connectivity application code + * @ingroup ble_sdk_lib_serialization + */ + +/** @file + * + * @defgroup ser_reset_cmd_decoder Reset Command Decoder in the connectivity chip + * @{ + * @ingroup ser_conn + * + * @brief Decoder for serialized reset command from the Application Chip. + * + * @details This file contains declaration of common function used for reset command decoding and + * sending responses back to the Application Chip after a command is processed. + */ + +#ifndef SER_CONN_RESET_CMD_DECODER_H__ +#define SER_CONN_RESET_CMD_DECODER_H__ + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/**@brief A function for processing the encoded reset commands from the Application Chip. + * + * @details The function decodes encoded system reset command and performs software reset. + * This command does not send back the Command Response packet to the Application Chip. + */ +void ser_conn_reset_command_process(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* SER_CONN_RESET_CMD_DECODER_H__ */ + +/** @} */ + |