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 | |
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')
246 files changed, 65488 insertions, 0 deletions
diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/middleware/app_mw_ant.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/middleware/app_mw_ant.c new file mode 100644 index 0000000..016fa67 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/middleware/app_mw_ant.c @@ -0,0 +1,1868 @@ +/** + * 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 <stdint.h> +#include "ant_interface.h" +#include "ble_serialization.h" +#include "ant_app.h" +#include "ser_sd_transport.h" +#include "app_error.h" + +static void * mp_out_params[3]; + +static void tx_buf_alloc(uint8_t * * p_data, uint32_t * p_len) +{ + uint32_t err_code; + uint16_t len16; + + do + { + err_code = ser_sd_transport_tx_alloc(p_data, &len16); + } + while (err_code != NRF_SUCCESS); + + *p_data[0] = SER_PKT_TYPE_ANT_CMD; + *p_len = (uint32_t)len16 - 1; +} + +/**@brief Command response callback function for @ref sd_ant_enable ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t enable_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_enable_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_enable(ANT_ENABLE * const p_ant_enable) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_enable_req_enc(p_ant_enable, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + enable_rsp_dec); + +} + +/**@brief Command response callback function for @ref sd_ant_channel_assign ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t channel_assign_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_channel_assign_rsp_dec(p_buffer, + length, + &result_code); + //@note: Should never fail. + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_channel_assign(uint8_t channel, uint8_t channel_type, uint8_t network, uint8_t ext_assign) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_channel_assign_req_enc(channel, + channel_type, + network, + ext_assign, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + channel_assign_rsp_dec); + +} + +/**@brief Command response callback function for @ref sd_ant_channel_open_with_offset ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t channel_open_with_offset_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_channel_open_with_offset_rsp_dec(p_buffer, + length, + &result_code); + //@note: Should never fail. + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_channel_open_with_offset(uint8_t channel, uint16_t usOffset) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_channel_open_with_offset_req_enc(channel, + usOffset, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + channel_open_with_offset_rsp_dec); + +} + +/**@brief Command response callback function for @ref sd_ant_channel_id_set ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t channel_id_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_channel_id_set_rsp_dec(p_buffer, + length, + &result_code); + //@note: Should never fail. + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_channel_id_set (uint8_t channel, uint16_t device_number, uint8_t device_type, uint8_t transmit_type) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_channel_id_set_req_enc(channel, + device_number, + device_type, + transmit_type, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + channel_id_set_rsp_dec); + +} + +/**@brief Command response callback function for @ref sd_ant_channel_period_set ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t channel_period_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_channel_period_set_rsp_dec(p_buffer, + length, + &result_code); + //@note: Should never fail. + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_channel_period_set(uint8_t channel, uint16_t period) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_channel_period_set_req_enc(channel, + period, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + channel_period_set_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_channel_radio_freq_set ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t channel_radio_freq_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_channel_radio_freq_set_rsp_dec(p_buffer, + length, + &result_code); + //@note: Should never fail. + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_channel_radio_freq_set (uint8_t channel, uint8_t freq) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_channel_radio_freq_set_req_enc(channel, + freq, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + channel_radio_freq_set_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_broadcast_message_tx ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t broadcast_message_tx_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_broadcast_message_tx_rsp_dec(p_buffer, + length, + &result_code); + //@note: Should never fail. + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_broadcast_message_tx(uint8_t channel, uint8_t size, uint8_t * p_mesg) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_broadcast_message_tx_req_enc(channel, + size, + p_mesg, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + broadcast_message_tx_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_acknowledge_message_tx ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t acknowledge_message_tx_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_acknowledge_message_tx_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_acknowledge_message_tx(uint8_t channel, uint8_t size, uint8_t * p_mesg) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_acknowledge_message_tx_req_enc(channel, + size, + p_mesg, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + acknowledge_message_tx_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_channel_unassign ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t channel_unassign_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_channel_unassign_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_channel_unassign(uint8_t channel) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_channel_unassign_req_enc(channel, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + channel_unassign_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_channel_close ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t channel_close_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_channel_close_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_channel_close(uint8_t channel) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_channel_close_req_enc(channel, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + channel_close_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_network_address_set ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t network_address_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_network_address_set_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_network_address_set(uint8_t network, const uint8_t * p_network_key) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_network_address_set_req_enc(network, + p_network_key, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + network_address_set_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_channel_radio_tx_power_set ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t channel_radio_tx_power_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_channel_radio_tx_power_set_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_channel_radio_tx_power_set(uint8_t channel, uint8_t tx_power, uint8_t custom_tx_power) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_channel_radio_tx_power_set_req_enc(channel, + tx_power, + custom_tx_power, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + channel_radio_tx_power_set_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_channel_rx_search_timeout_set ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t channel_rx_search_timeout_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_channel_rx_search_timeout_set_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_channel_rx_search_timeout_set(uint8_t channel, uint8_t timeout) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_channel_rx_search_timeout_set_req_enc(channel, + timeout, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + channel_rx_search_timeout_set_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_channel_low_priority_rx_search_timeout_set ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t channel_low_priority_rx_search_timeout_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_channel_low_priority_rx_search_timeout_set_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_channel_low_priority_rx_search_timeout_set(uint8_t channel, uint8_t timeout) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_channel_low_priority_rx_search_timeout_set_req_enc(channel, + timeout, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + channel_low_priority_rx_search_timeout_set_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_prox_search_set ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t prox_search_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_prox_search_set_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_prox_search_set(uint8_t channel, uint8_t prox_threshold, uint8_t custom_prox_threshold) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_prox_search_set_req_enc(channel, + prox_threshold, + custom_prox_threshold, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + prox_search_set_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_search_waveform_set ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t search_waveform_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_search_waveform_set_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_search_waveform_set(uint8_t channel, uint16_t waveform) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_search_waveform_set_req_enc(channel, + waveform, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + search_waveform_set_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_channel_id_get ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t channel_id_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_channel_id_get_rsp_dec(p_buffer, + length, + mp_out_params[0], + mp_out_params[1], + mp_out_params[2], + &result_code); + + //@note: Should never fail + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_channel_id_get(uint8_t channel, uint16_t * p_device_number, uint8_t * p_device_type, uint8_t * p_transmit_type) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + mp_out_params[0] = p_device_number; + mp_out_params[1] = p_device_type; + mp_out_params[2] = p_transmit_type; + + const uint32_t err_code = ant_channel_id_get_req_enc(channel, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + channel_id_get_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_channel_radio_freq_get ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t channel_radio_freq_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_channel_radio_freq_get_rsp_dec(p_buffer, + length, + mp_out_params[0], + &result_code); + + //@note: Should never fail + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_channel_radio_freq_get(uint8_t channel, uint8_t * p_r_freq) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + mp_out_params[0] = p_r_freq; + + const uint32_t err_code = ant_channel_radio_freq_get_req_enc(channel, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + channel_radio_freq_get_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_channel_period_get ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t channel_period_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_channel_period_get_rsp_dec(p_buffer, + length, + mp_out_params[0], + &result_code); + + //@note: Should never fail + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_channel_period_get(uint8_t channel, uint16_t * p_period) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + mp_out_params[0] = p_period; + + const uint32_t err_code = ant_channel_period_get_req_enc(channel, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + channel_period_get_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_search_channel_priority_set ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t search_channel_priority_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_search_channel_priority_set_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_search_channel_priority_set(uint8_t channel, uint8_t search_priority) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_search_channel_priority_set_req_enc(channel, + search_priority, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + search_channel_priority_set_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_active_search_sharing_cycles_set ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t active_search_sharing_cycles_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_active_search_sharing_cycles_set_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_active_search_sharing_cycles_set(uint8_t channel, uint8_t cycles) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_active_search_sharing_cycles_set_req_enc(channel, + cycles, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + active_search_sharing_cycles_set_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_lib_config_set ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t lib_config_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_lib_config_set_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_lib_config_set(uint8_t ant_lib_config) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_lib_config_set_req_enc(ant_lib_config, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + lib_config_set_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_active_search_sharing_channels_get ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t active_search_sharing_cycles_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_active_search_sharing_cycles_get_rsp_dec(p_buffer, + length, + mp_out_params[0], + &result_code); + + //@note: Should never fail + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_active_search_sharing_cycles_get(uint8_t channel, uint8_t * p_cycles) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + mp_out_params[0] = p_cycles; + + const uint32_t err_code = ant_active_search_sharing_cycles_get_req_enc(channel, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + active_search_sharing_cycles_get_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_lib_config_get ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t lib_config_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_lib_config_get_rsp_dec(p_buffer, + length, + mp_out_params[0], + &result_code); + + //@note: Should never fail + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_lib_config_get(uint8_t * p_ant_lib_config) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + mp_out_params[0] = p_ant_lib_config; + + const uint32_t err_code = ant_lib_config_get_req_enc(&(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + lib_config_get_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_lib_config_clear ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t lib_config_clear_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_lib_config_clear_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_lib_config_clear(uint8_t ant_lib_config) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_lib_config_clear_req_enc(ant_lib_config, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + lib_config_clear_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_stack_reset ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t stack_reset_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_stack_reset_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_stack_reset() +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_stack_reset_req_enc(&(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + stack_reset_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_rx_scan_mode_start ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t rx_scan_mode_start_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_rx_scan_mode_start_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_rx_scan_mode_start(uint8_t sync_channel_packets_only) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_rx_scan_mode_start_req_enc(sync_channel_packets_only, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + rx_scan_mode_start_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_id_list_add ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t id_list_add_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_id_list_add_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_id_list_add(uint8_t channel, uint8_t * p_dev_id, uint8_t list_index) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_id_list_add_req_enc(channel, + p_dev_id, + list_index, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + id_list_add_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_id_list_config ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t id_list_config_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_id_list_config_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_id_list_config(uint8_t channel, uint8_t id_list_size, uint8_t inc_exc_flag) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_id_list_config_req_enc(channel, + id_list_size, + inc_exc_flag, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + id_list_config_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_channel_status_get ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t channel_status_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_channel_status_get_rsp_dec(p_buffer, + length, + mp_out_params[0], + &result_code); + + //@note: Should never fail + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_channel_status_get(uint8_t channel, uint8_t * p_status) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + mp_out_params[0] = p_status; + + const uint32_t err_code = ant_channel_status_get_req_enc(channel, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + channel_status_get_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_cw_test_mode_init ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t cw_test_mode_init_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_cw_test_mode_init_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_cw_test_mode_init() +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_cw_test_mode_init_req_enc(&(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + cw_test_mode_init_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_cw_test_mode ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t cw_test_mode_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_cw_test_mode_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_cw_test_mode(uint8_t radio_freq, uint8_t tx_power, uint8_t custom_tx_power, uint8_t mode) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_cw_test_mode_req_enc(radio_freq, + tx_power, + custom_tx_power, + mode, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + cw_test_mode_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_version_get ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t version_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_version_get_rsp_dec(p_buffer, + length, + &mp_out_params[0], + &result_code); + + //@note: Should never fail + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_version_get(uint8_t * p_version) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + mp_out_params[0] = p_version; + + const uint32_t err_code = ant_version_get_req_enc(&(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + version_get_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_capabilities_get ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t capabilities_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_capabilities_get_rsp_dec(p_buffer, + length, + &mp_out_params[0], + &result_code); + + //@note: Should never fail + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_capabilities_get(uint8_t * p_capabilities) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + mp_out_params[0] = p_capabilities; + + const uint32_t err_code = ant_capabilities_get_req_enc(&(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + capabilities_get_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_crypto_channel_enable ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t crypto_channel_enable_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_crypto_channel_enable_rsp_dec(p_buffer, + length, + &result_code); + //@note: Should never fail. + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_crypto_channel_enable(uint8_t channel, uint8_t enable, uint8_t key_num, uint8_t decimation_rate) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_crypto_channel_enable_req_enc(channel, + enable, + key_num, + decimation_rate, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + crypto_channel_enable_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_adv_burst_config_set ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t adv_burst_config_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_adv_burst_config_set_rsp_dec(p_buffer, + length, + &result_code); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_adv_burst_config_set(uint8_t * p_config, uint8_t size) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_adv_burst_config_set_req_enc(p_config, + size, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + adv_burst_config_set_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_crypto_key_set ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t crypto_key_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_crypto_key_set_rsp_dec(p_buffer, + length, + &result_code); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_crypto_key_set(uint8_t key_num, uint8_t * p_key) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_crypto_key_set_req_enc(key_num, + p_key, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + crypto_key_set_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_crypto_info_set ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t crypto_info_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_crypto_info_set_rsp_dec(p_buffer, + length, + &result_code); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_crypto_info_set(uint8_t type, uint8_t * p_info) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_crypto_info_set_req_enc(type, + p_info, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + crypto_info_set_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_crypto_info_get ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t crypto_info_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_crypto_info_get_rsp_dec(p_buffer, + length, + mp_out_params[0], + &result_code); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_crypto_info_get(uint8_t type, uint8_t * p_info) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + mp_out_params[0] = p_info; + + const uint32_t err_code = ant_crypto_info_get_req_enc(type, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + crypto_info_get_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_coex_config_set ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t coex_config_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_coex_config_set_rsp_dec(p_buffer, + length, + &result_code); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_coex_config_set(uint8_t channel, ANT_BUFFER_PTR * p_coex_config, ANT_BUFFER_PTR * p_adv_coex_config) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ant_coex_config_set_req_enc(channel, + p_coex_config, + p_adv_coex_config, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + coex_config_set_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ant_coex_config_get ANT command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t coex_config_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ant_coex_config_get_rsp_dec(p_buffer, + length, + mp_out_params[0], + mp_out_params[1], + &result_code); + + //@note: Should never fail + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ant_coex_config_get(uint8_t channel, ANT_BUFFER_PTR * p_coex_config, ANT_BUFFER_PTR * p_adv_coex_config) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + mp_out_params[0] = p_coex_config; + mp_out_params[1] = p_adv_coex_config; + + const uint32_t err_code = ant_coex_config_get_req_enc(channel, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + coex_config_get_rsp_dec); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_acknowledge_message_tx.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_acknowledge_message_tx.c new file mode 100644 index 0000000..ee4e763 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_acknowledge_message_tx.c @@ -0,0 +1,90 @@ +/** + * 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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_acknowledge_message_tx_req_enc(uint8_t channel, + uint8_t size, + uint8_t const * const p_mesg, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + uint8_t svc_number = SVC_ANT_TX_ACKNOWLEDGED_MESSAGE; + uint32_t err_code = NRF_SUCCESS; + uint32_t buf_len = *p_buf_len; + uint32_t index = 0; + + err_code = uint8_t_enc(&svc_number, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_enc(&channel, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_enc(&size, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_vector_enc(p_mesg, size, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + + +uint32_t ant_acknowledge_message_tx_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_TX_ACKNOWLEDGED_MESSAGE, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_active_search_sharing_cycles_get.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_active_search_sharing_cycles_get.c new file mode 100644 index 0000000..f0312f3 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_active_search_sharing_cycles_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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_active_search_sharing_cycles_get_req_enc(uint8_t channel, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_ACTIVE_SEARCH_SHARING_CYCLES_GET; + p_buf[index++] = channel; + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ant_active_search_sharing_cycles_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + void * const p_cycles, + uint32_t * const p_result_code) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_result_code); + + uint32_t index = 0; + uint32_t err_code = ser_ble_cmd_rsp_result_code_dec(p_buf, &index, packet_len, + SVC_ANT_ACTIVE_SEARCH_SHARING_CYCLES_GET, p_result_code); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + if (*p_result_code != NRF_SUCCESS) + { + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return NRF_SUCCESS; + } + + 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 NRF_SUCCESS; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_active_search_sharing_cycles_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_active_search_sharing_cycles_set.c new file mode 100644 index 0000000..a0e27d8 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_active_search_sharing_cycles_set_req_enc(uint8_t channel, + uint8_t cycles, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_ACTIVE_SEARCH_SHARING_CYCLES_SET; + p_buf[index++] = channel; + p_buf[index++] = cycles; + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ant_active_search_sharing_cycles_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_ACTIVE_SEARCH_SHARING_CYCLES_SET, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_adv_burst_config_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_adv_burst_config_set.c new file mode 100644 index 0000000..74020ee --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_adv_burst_config_set.c @@ -0,0 +1,86 @@ +/** + * 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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_adv_burst_config_set_req_enc(uint8_t const * const p_config, + uint8_t size, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + uint8_t svc_number = SVC_ANT_ADV_BURST_CONFIG_SET; + uint32_t err_code = NRF_SUCCESS; + uint32_t buf_len = *p_buf_len; + uint32_t index = 0; + + err_code = uint8_t_enc(&svc_number, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_enc(&size, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_vector_enc(p_config, size, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + + +uint32_t ant_adv_burst_config_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_ADV_BURST_CONFIG_SET, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_app.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_app.h new file mode 100644 index 0000000..c3c7fd2 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_app.h @@ -0,0 +1,1652 @@ +/** + * 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_APP_H__ +#define ANT_APP_H__ + +/** + * @addtogroup ser_app_s212_codecs Application codecs for S212 + * @ingroup ser_codecs_app + */ + +/**@file + * + * @defgroup ant_app Application command request encoders and command response decoders + * @{ + * @ingroup ser_app_s212_codecs + * + * @brief Application command request encoders and command response decoders. + */ +//#include "ble.h" +#include "ant_interface.h" + +/**@brief Encodes @ref sd_ant_enable command request. + * + * @sa @ref ant_enable_rsp_dec for command response decoder. + * + * @param[in] p_ant_enable_params Pointer to an @ref ANT_ENABLE structure. + * @param[in] p_buf Pointer to buffer where encoded data command will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_enable_req_enc(ANT_ENABLE * p_ant_enable_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_enable command. + * + * @sa @ref ant_enable_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_enable_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_channel_assign command request. + * + * @sa @ref ant_channel_assign_rsp_dec for command response decoder. + * + * @param[in] channel Channel is an unsigned char (1 octet) denoting the channel + * to assign. + * @param[in] channel_type Channel Type is an unsigned char (1 octet) denoting the + * channel type. See Assign Channel Parameters/Assign Channel + * Types in ant_parameters.h. + * @param[in] network Network is an unsigned char (1 octet) denoting the network + * key to associate with the channel. + * @param[in] ext_assign Ext Assign is a bit field (1 octet) for an extended + * assign. See Ext. Assign Channel Parameters in + * ant_parameters.h. + * @param[in] p_buf Pointer to buffer where encoded data command will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_assign_req_enc(uint8_t channel, + uint8_t channel_type, + uint8_t network, + uint8_t ext_assign, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_channel_assign command. + * + * @sa @ref ant_channel_assign_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_channel_assign_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_channel_open command request. + * + * @sa @ref ant_channel_open_with_offset_rsp_dec for command response decoder. + * + * @param[in] channel Channel is an unsigned char (1 octet) denoting the channel to + * open. + * @param[in] usOffset Denote the offset from which to start the channel. + * + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_open_with_offset_req_enc(uint8_t channel, + uint16_t usOffset, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_channel_open command. + * + * @sa @ref ant_channel_open_with_offset_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_channel_open_with_offset_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_channel_id_set command request. + * + * @sa @ref ant_channel_id_set_rsp_dec for command response decoder. + * + * @param[in] channel Channel is an unsigned char (1 octet) denoting the channel + * number to set. + * @param[in] device_number Device Number is an unsigned short (2 octets) denoting the + * device number. + * @param[in] device_type Device Type is an unsigned char (1 octet) denoting the device + * type. + * @param[in] transmit_type Transmit Type is an unsigned char (1 octet) denoting the + * transmission type. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_id_set_req_enc(uint8_t channel, + uint16_t device_number, + uint8_t device_type, + uint8_t transmit_type, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_channel_id_set command. + * + * @sa @ref ant_channel_id_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_channel_id_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_channel_period_set command request. + * + * @sa @ref ant_channel_period_set_rsp_dec for command response decoder. + * + * @param[in] channel Channel is an unsigned char (1 octet) denoting the channel + * number to set the period to. + * @param[in] period Period is an unsigned short (2 octets) denoting the period in + * 32 kHz counts (usPeriod/32768 s). + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_period_set_req_enc(uint8_t channel, + uint16_t period, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_channel_period_set command. + * + * @sa @ref ant_channel_period_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_channel_period_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_channel_radio_freq_set command request. + * + * @sa @ref ant_channel_radio_freq_set_rsp_dec for command response decoder. + * + * @param[in] channel Channel is an unsigned char (1 octet) denoting the channel + * number to set to. + * @param[in] freq Freq is an unsigned char (1 octet) denoting the radio + * frequency offset from 2400 MHz (eg. 2466 MHz, ucFreq = 66). + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_radio_freq_set_req_enc(uint8_t channel, + uint8_t freq, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_channel_radio_freq_set command. + * + * @sa @ref ant_channel_radio_freq_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_channel_radio_freq_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_broadcast_message_tx command request. + * + * @sa @ref ant_broadcast_message_tx_rsp_dec for command response decoder. + * + * @param[in] channel Channel is an unsigned char (1 octet) denoting the channel to + * send the data on. + * @param[in] size Size is an unsigned char (1 octet) denoting the size of the + * message, ucSize must be 8. + * @param[in] p_mesg Mesg is the buffer where the message is located (array must be + * 8 octets). + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_broadcast_message_tx_req_enc(uint8_t channel, + uint8_t size, + uint8_t const * const p_mesg, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_broadcast_message_tx command. + * + * @sa @ref ant_broadcast_message_tx_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_broadcast_message_tx_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + + +/**@brief Encodes @ref sd_ant_acknowledge_message_tx command request. + * + * @sa @ref ant_acknowledge_message_tx_rsp_dec for command response decoder. + * + * @param[in] channel Channel is an unsigned char (1 octet) denoting the channel to + * send the data on. + * @param[in] size Size is an unsigned char (1 octet) denoting the size of the + * message, ucSize must be 8. + * @param[in] p_mesg Mesg is the buffer where the message is located (array must be + * 8 octets). + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_acknowledge_message_tx_req_enc(uint8_t channel, + uint8_t size, + uint8_t const * const p_mesg, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_acknowledge_message_tx command. + * + * @sa @ref ant_acknowledge_message_tx_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_acknowledge_message_tx_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_channel_unassign command request. + * + * @sa @ref ant_channel_unassign_rsp_dec for command response decoder. + * + * @param[in] channel Channel is an unsigned char (1 octet) denoting the channel + * to unassign. + * @param[in] p_buf Pointer to buffer where encoded data command will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_unassign_req_enc(uint8_t channel, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_channel_unassign command. + * + * @sa @ref ant_channel_unassign_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_channel_unassign_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_channel_close command request. + * + * @sa @ref ant_channel_close_rsp_dec for command response decoder. + * + * @param[in] channel Channel is an unsigned char (1 octet) denoting the channel + * to close. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_close_req_enc(uint8_t channel, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_channel_close command. + * + * @sa @ref ant_channel_close_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_channel_close_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_network_address_set command request. + * + * @sa @ref ant_network_address_set_rsp_dec for command response decoder. + * + * @param[in] network Network is an unsigned char (1 octet) denoting the network + * number to assign the network address to. + * @param[in] p_network_key Network key is the pointer to location of the Network Key (8 + * octets in length). + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_network_address_set_req_enc(uint8_t network, + uint8_t const * const p_network_key, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_network_address_set command. + * + * @sa @ref ant_network_address_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_network_address_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_channel_radio_tx_power_set command request. + * + * @sa @ref ant_channel_radio_tx_power_set_rsp_dec for command response decoder. + * + * @param[in] channel Channel is an unsigned char (1 octet) denoting the channel + * number to assign the radio TX power. + * @param[in] tx_power TX Power is an unsigned char (1 octet) denoting the ANT + * transmit power index. See Radio TX Power Definitions in + * ant_parameters.h. + * @param[in] custom_tx_power Custom TX Power is an unsigned char (1 octet) denoting the + * custom nRF transmit power as defined in nrf51_bitfields.h. + * Only applicable if tx_power is set to custom TX power + * selection. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_radio_tx_power_set_req_enc(uint8_t channel, + uint8_t tx_power, + uint8_t custom_tx_power, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_channel_radio_tx_power_set command. + * + * @sa @ref ant_channel_radio_tx_power_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_channel_radio_tx_power_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_channel_rx_search_timeout_set command request. + * + * @sa @ref ant_channel_rx_search_timeout_set_rsp_dec for command response decoder. + * + * @param[in] channel Channel is an unsigned char (1 octet) denoting the channel + * number to set. + * @param[in] timeout Timeout is an unsigned char (1 octet) denoting the time-out + * value. + * When applied to an assigned slave channel, ucTimeout is in 2.5 + * second increments. Default = 10 (25 s) at channel assignment. + * When applied to an assigned master channel, ucTimeout is in + * 250 ms increments. Default = 0 (disabled) at channel assignment + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_rx_search_timeout_set_req_enc(uint8_t channel, + uint8_t timeout, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_channel_rx_search_timeout_set command. + * + * @sa @ref ant_channel_rx_search_timeout_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_channel_rx_search_timeout_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_channel_low_priority_rx_search_timeout_set command request. + * + * @sa @ref ant_channel_low_priority_rx_search_timeout_set_rsp_dec for command response decoder. + * + * @param[in] channel Channel is an unsigned char (1 octet) denoting the channel + * number to set. + * @param[in] timeout Timeout is an unsigned char (1 octet) denoting the time-out + * value in 2.5 seconds increments. Default = 2 (5s). + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_low_priority_rx_search_timeout_set_req_enc(uint8_t channel, + uint8_t timeout, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_channel_low_priority_rx_search_timeout_set command. + * + * @sa @ref ant_channel_low_priority_rx_search_timeout_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_channel_low_priority_rx_search_timeout_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_prox_search_set command request. + * + * @sa @ref ant_prox_search_set_rsp_dec for command response decoder. + * + * @param[in] channel Channel is an unsigned char (1 octet) denoting the channel + * number. + * @param[in] prox_threshold Prox threshold is an unsigned char (1 octet) denoting the + * minimum RSSI threshold required for acquisition during a + * search. See Radio Proximity Search Threshold in + * ant_parameters.h. + * @param[in] custom_prox_threshold Custom prox threshold is an unsigned char (1 octet) denoting + * the custom minimum RSSI threshold for acquisition during a + * search. Only applicable if ucProxThreshold is set to custom + * proximity selection. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_prox_search_set_req_enc(uint8_t channel, + uint8_t prox_threshold, + uint8_t custom_prox_threshold, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_prox_search_set command. + * + * @sa @ref ant_prox_search_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_prox_search_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_search_waveform_set command request. + * + * @sa @ref ant_search_waveform_set_rsp_dec for command response decoder. + * + * @param[in] channel Channel is an unsigned char (1 octet) denoting the channel + * number. + * @param[in] waveform Waveform is an unsigned short (2 octets) denoting the channel + * waveform period (usWaveform/32768 s). Default = 316. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_search_waveform_set_req_enc(uint8_t channel, + uint16_t waveform, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_search_waveform_set command. + * + * @sa @ref ant_search_waveform_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_search_waveform_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_channel_id_get command request. + * + * @sa @ref ant_channel_id_get_rsp_dec for command response decoder. + * + * @param[in] channel Channel is an unsigned char (1 octet) denoting the channel + * number. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_id_get_req_enc(uint8_t channel, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_channel_id_get command. + * + * @sa @ref ant_channel_id_get_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[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. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_channel_id_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + void * const p_device_number, + void * const p_device_type, + void * const p_transmit_type, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_channel_radio_freq_get command request. + * + * @sa @ref ant_channel_radio_freq_get_rsp_dec for command response decoder. + * + * @param[in] channel Channel is an unsigned char (1 octet) denoting the channel + * number. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_radio_freq_get_req_enc(uint8_t channel, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_channel_radio_freq_get command. + * + * @sa @ref ant_channel_radio_freq_get_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[in] p_r_freq Pointer to radio frequency. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_channel_radio_freq_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + void * const p_r_freq, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_channel_period_get command request. + * + * @sa @ref ant_channel_period_get_rsp_dec for command response decoder. + * + * @param[in] channel Channel is an unsigned char (1 octet) denoting the channel + * number. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_period_get_req_enc(uint8_t channel, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_channel_period_get command. + * + * @sa @ref ant_channel_period_get_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[in] p_period Pointer to period + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_channel_period_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + void * p_period, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_search_channel_priority_set command request. + * + * @sa @ref ant_search_channel_priority_set_rsp_dec for command response decoder. + * + * @param[in] channel Channel is an unsigned char (1 octet) denoting the channel + * number. + * @param[in] search_priority Search Priority is an unsigned char (1 octet) denoting the + * search priority value. 0 to 7 (Default = 0). + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_search_channel_priority_set_req_enc(uint8_t channel, + uint8_t search_priority, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_search_channel_priority_set command. + * + * @sa @ref ant_search_channel_priority_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_search_channel_priority_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + + +/**@brief Encodes @ref sd_ant_active_search_sharing_cycles_set command request. + * + * @sa @ref ant_active_search_sharing_cycles_set_rsp_dec for command response decoder. + * + * @param[in] channel Channel is an unsigned char (1 octet) denoting the channel + * number. + * @param[in] cycles Cycles is an unsigned char (1 octet) denoting the number of + * cycles to set. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_active_search_sharing_cycles_set_req_enc(uint8_t channel, + uint8_t cycles, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_active_search_sharing_cycles_set command. + * + * @sa @ref ant_active_search_sharing_cycles_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_active_search_sharing_cycles_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_lib_config_set command request. + * + * @sa @ref ant_lib_config_set_rsp_dec for command response decoder. + * + * @param[in] ant_lib_config ANT Lib Config an unsigned char (1 octet) denoting the ANT lib + * config bit flags. See ANT Library Config in ant_parameters.h. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_lib_config_set_req_enc(uint8_t ant_lib_config, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_lib_config_set command. + * + * @sa @ref ant_lib_config_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_lib_config_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_active_search_sharing_cycles_get command request. + * + * @sa @ref ant_active_search_sharing_cycles_get_rsp_dec for command response decoder. + * + * @param[in] channel Channel is an unsigned char (1 octet) denoting the channel + * number. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_active_search_sharing_cycles_get_req_enc(uint8_t channel, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_active_search_sharing_cycles_get command. + * + * @sa @ref ant_active_search_sharing_cycles_get_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[in] p_cycles Pointer to cycles. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_active_search_sharing_cycles_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + void * const p_cycles, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_lib_config_get command request. + * + * @sa @ref ant_lib_config_get_rsp_dec for command response decoder. + * + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_lib_config_get_req_enc(uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_lib_config_get command. + * + * @sa @ref ant_lib_config_get_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[in] p_ant_lib_config Pointer to the ANT library configuration. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_lib_config_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + void * const p_ant_lib_config, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_lib_config_clear command request. + * + * @sa @ref ant_lib_config_clear_rsp_dec for command response decoder. + * + * @param[in] ant_lib_config ANT lib config is an unsigned char (1 octet) denoting the + * ANT lib config bit(s) to clear. See ANT Library Config in + * ant_parameters.h. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_lib_config_clear_req_enc(uint8_t ant_lib_config, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_lib_config_clear command. + * + * @sa @ref ant_lib_config_clear_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_lib_config_clear_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_stack_reset command request. + * + * @sa @ref ant_stack_reset_rsp_dec for command response decoder. + * + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_stack_reset_req_enc(uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_stack_reset command. + * + * @sa @ref ant_stack_reset_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_stack_reset_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_rx_scan_mode_start command request. + * + * @sa @ref ant_rx_scan_mode_start_rsp_dec for command response decoder. + * + * @param[in] sync_channel_packets_only Sync channel packets only is an unsigned char (1 octet) + * denoting synchronous channel only scanning mode. + * 0 = disable, 1 = enable. + * @param[in] p_buf Pointer to buffer where encoded data command will be + * returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_rx_scan_mode_start_req_enc(uint8_t sync_channel_packets_only, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_rx_scan_mode_start command. + * + * @sa @ref ant_rx_scan_mode_start_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_rx_scan_mode_start_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_id_list_add command request. + * + * @sa @ref ant_id_list_add_rsp_dec for command response decoder. + * + * @param[in] channel Channel is an unsigned char (1 octet) denoting the channel + * number to add the list entry to. + * @param[in] p_dev_id Dev ID is the pointer to the buffer (4 octets) containing + * device ID information with the following format: + * Byte0 = DeviceNumber_LSB + * Byte1 = DeviceNumber_MSB + * Byte2 = DeviceType + * Byte3 = TransType + * @param[in] list_index List index is an unsigned char (1 octet) denoting the index + * where the specified channel ID is to be placed in the list (0-3). + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_id_list_add_req_enc(uint8_t channel, + uint8_t const * const p_dev_id, + uint8_t list_index, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_id_list_add command. + * + * @sa @ref ant_id_list_add_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_id_list_add_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_id_list_config command request. + * + * @sa @ref ant_id_list_config_rsp_dec for command response decoder. + * + * @param[in] channel Channel is an unsigned char (1 octet) denoting the + * channel number of the device ID list. + * @param[in] id_list_size ID list size is an unsigned char (1 octet) denoting the size of + * the inclusion or exclusion list (0-4). + * @param[in] inc_exc_flag Inc exc flag is an unsigned char (1 octet) denoting the type of + * list as Include(0) or Exclude(1). + * @param[in] channel + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_id_list_config_req_enc(uint8_t channel, + uint8_t id_list_size, + uint8_t inc_exc_flag, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_id_list_config command. + * + * @sa @ref ant_id_list_config_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_id_list_config_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_channel_status_get command request. + * + * @sa @ref ant_channel_status_get_rsp_dec for command response decoder. + * + * @param[in] channel Channel is an unsigned char (1 octet) denoting the channel + * number. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_channel_status_get_req_enc(uint8_t channel, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_channel_status_get command. + * + * @sa @ref ant_channel_status_get_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[in] p_status Pointer to status + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_channel_status_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + void * const p_status, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_cw_test_mode_init command request. + * + * @sa @ref ant_cw_test_mode_init_rsp_dec for command response decoder. + * + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_cw_test_mode_init_req_enc(uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_cw_test_mode_init command. + * + * @sa @ref ant_cw_test_mode_init_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_cw_test_mode_init_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_cw_test_mode command request. + * + * @sa @ref ant_cw_test_mode_rsp_dec for command response decoder. + * + * @param[in] radio_freq Radio freq is an unsigned char (1 octet) denoting the radio + * frequency offset from 2400 MHz for continuous wave mode. + * (eg. 2466 MHz, ucRadioFreq = 66). + * @param[in] tx_power TX Power is an unsigned char (1 octet) denoting the ANT transmit + * power index for continuous wave mode. See Radio TX Power + * Definitions in ant_parameters.h + * @param[in] custom_tx_power Custom TX power is an unsigned char (1 octet) denoting the + * custom nRF transmit power as defined in nrf51_bitfields.h. Only + * applicable if ucTxPower is set to custom TX power selection. + * @param[in] mode Mode is an unsigned char (1 octet) denoting test mode type where + * 0 = cw tx carrier transmission, 1 = cw tx modulated transmission. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_cw_test_mode_req_enc(uint8_t radio_freq, + uint8_t tx_power, + uint8_t custom_tx_power, + uint8_t mode, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_cw_test_mode command. + * + * @sa @ref ant_cw_test_mode_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_cw_test_mode_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_version_get command request. + * + * @sa @ref ant_version_get_rsp_dec for command response decoder. + * + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_version_get_req_enc(uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_version_get command. + * + * @sa @ref ant_version_get_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[in] p_version Pointer to version string buffer. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_version_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + void * * const p_version, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_capabilities_get command request. + * + * @sa @ref ant_capabilities_get_rsp_dec for command response decoder. + * + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_capabilities_get_req_enc(uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_capabilities_get command. + * + * @sa @ref ant_capabilities_get_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[in] pp_capabilities Pointer to pointer to capabilities buffer. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_capabilities_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + void * * const pp_capabilities, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_crypto_channel_enable command request. + * + * @sa @ref ant_crypto_channel_enable_rsp_dec for command response decoder. + * + * @param[in] channel Channel is an unsigned char (1 octet) denoting the channel in + * which encryption mode is set. + * @param[in] enable Enable is an unsigned char (1 octet) denoting the encryption + * mode. See Encrypted Channel Defines in ant_parameters.h. + * @param[in] key_num Key num is an unsigned char (1 octet) denoting the key index of + * the 128-bit key to be used for encryption. The key index range + * is bound by the number of encrypted channels configured by + * sd_ant_enable(). If sd_ant_enable() is not used then by default + * key num is 0. Range is [0 to (num encrypted channels - 1)], if + * 1 or more encrypted channels are configured. + * @param[in] decimation_rate Decimation rate is an unsigned char (1 octet) denoting the + * decimate rate to apply for encrypted slave channel. Must be > 0. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_crypto_channel_enable_req_enc(uint8_t channel, + uint8_t enable, + uint8_t key_num, + uint8_t decimation_rate, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_crypto_channel_enable command. + * + * @sa @ref ant_crypto_channel_enable_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_crypto_channel_enable_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_adv_burst_config_set command request. + * + * @sa @ref ant_adv_burst_config_set_rsp_dec for command response decoder. + * + * @param[in] p_config Config is a buffer containing the advanced burst + * configuration to be set. + * @param[in] size Size is an unsigned char (1 octet) denoting the size of the + * configuration parameter buffer. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_adv_burst_config_set_req_enc(uint8_t const * const p_config, + uint8_t size, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_adv_burst_config_set command. + * + * @sa @ref ant_adv_burst_config_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_adv_burst_config_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_crypto_key_set command request. + * + * @sa @ref ant_crypto_key_set_rsp_dec for command response decoder. + * + * @param[in] key_num Key num is an unsigned char (1 octet) denoting the key index for + * assignment. + * @param[in] p_key Buffer (16 octets) containing the 128-bit AES key to be + * assigned to the key index. + * + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_crypto_key_set_req_enc(uint8_t key_num, + uint8_t const * const p_key, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_crypto_key_set command. + * + * @sa @ref ant_crypto_key_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_crypto_key_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_crypto_info_set command request. + * + * @sa @ref ant_crypto_info_set_rsp_dec for command response decoder. + * + * @param[in] type Type is an unsigned char (1 octet) denoting the type of + * information being set. + * @param[in] p_info Pointer to a buffer buffer containing the information being set. + * + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_crypto_info_set_req_enc(uint8_t type, + uint8_t const * const p_info, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_crypto_info_set command. + * + * @sa @ref ant_crypto_info_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_crypto_info_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_crypto_info_get command request. + * + * @sa @ref ant_crypto_info_get_rsp_dec for command response decoder. + * + * @param[in] type Type is an unsigned char (1 octet) denoting the type of + * information being set. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_crypto_info_get_req_enc(uint8_t type, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_crypto_info_get command. + * + * @sa @ref ant_crypto_info_get_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[in] p_info Pointer to the info buffer. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_crypto_info_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + void * const p_info, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_coex_config_set command request. + * + * @sa @ref ant_coex_config_set_rsp_dec for command response decoder. + * + * @param[in] channel Channel is an unsigned char (1 octet) denoting the channel for + * which the coexistence configuration is to be set + * @param[in] p_config Pointer to a buffer containing the configuration to be set. + * @param[in] p_adv_coex_config Pointer to a buffer containing the advanced coexistence configuration + * to be set. + * + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_coex_config_set_req_enc(uint8_t channel, + ANT_BUFFER_PTR const * const p_config, + ANT_BUFFER_PTR const * const p_adv_coex_config, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_coex_config_set command. + * + * @sa @ref ant_coex_config_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_coex_config_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ant_coex_config_get command request. + * + * @sa @ref ant_coex_config_get_rsp_dec for command response decoder. + * + * @param[in] channel Channel is an unsigned char (1 octet) denoting the channel to + * query. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ant_coex_config_get_req_enc(uint8_t channel, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ant_coex_config_get command. + * + * @sa @ref ant_coex_config_get_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[in] p_coex_config Pointer to the coexistence configuration buffer. + * @param[in] p_adv_coex_config Pointer to the advanced coexistence configuration buffer. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ant_coex_config_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + void * const p_coex_config, + void * const p_adv_coex_config, + uint32_t * const p_result_code); +/** @} */ +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_broadcast_message_tx.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_broadcast_message_tx.c new file mode 100644 index 0000000..86548e0 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_broadcast_message_tx.c @@ -0,0 +1,90 @@ +/** + * 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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_broadcast_message_tx_req_enc(uint8_t channel, + uint8_t size, + uint8_t const * const p_mesg, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + uint8_t svc_number = SVC_ANT_TX_BROADCAST_MESSAGE; + uint32_t err_code = NRF_SUCCESS; + uint32_t buf_len = *p_buf_len; + uint32_t index = 0; + + err_code = uint8_t_enc(&svc_number, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_enc(&channel, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_enc(&size, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_vector_enc(p_mesg, size, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + + +uint32_t ant_broadcast_message_tx_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_TX_BROADCAST_MESSAGE, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_capabilities_get.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_capabilities_get.c new file mode 100644 index 0000000..9d47722 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_capabilities_get.c @@ -0,0 +1,93 @@ +/** + * 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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_capabilities_get_req_enc(uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_CAPABILITIES; + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ant_capabilities_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + void * * const pp_capabilities, + uint32_t * const p_result_code) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_result_code); + + uint32_t index = 0; + uint32_t err_code = ser_ble_cmd_rsp_result_code_dec(p_buf, &index, packet_len, + SVC_ANT_CAPABILITIES, p_result_code); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + if (*p_result_code != NRF_SUCCESS) + { + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return NRF_SUCCESS; + } + + err_code = uint8_vector_dec(p_buf, packet_len, &index, (uint8_t *)*pp_capabilities, MESG_CAPABILITIES_SIZE); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return NRF_SUCCESS; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_assign.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_assign.c new file mode 100644 index 0000000..ca4a44a --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_assign.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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_channel_assign_req_enc(uint8_t channel, + uint8_t channel_type, + uint8_t network, + uint8_t ext_assign, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_CHANNEL_ASSIGN; + p_buf[index++] = channel; + p_buf[index++] = channel_type; + p_buf[index++] = network; + p_buf[index++] = ext_assign; + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + + +uint32_t ant_channel_assign_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_CHANNEL_ASSIGN, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_close.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_close.c new file mode 100644 index 0000000..bd3995d --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_close.c @@ -0,0 +1,76 @@ +/** + * 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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_channel_close_req_enc(uint8_t channel, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_CHANNEL_CLOSE; + p_buf[index++] = channel; + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ant_channel_close_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_CHANNEL_CLOSE, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_id_get.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_id_get.c new file mode 100644 index 0000000..a4b11cd --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_id_get.c @@ -0,0 +1,103 @@ +/** + * 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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_channel_id_get_req_enc(uint8_t channel, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_CHANNEL_ID_GET; + p_buf[index++] = channel; + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ant_channel_id_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + void * const p_device_number, + void * const p_device_type, + void * const p_transmit_type, + uint32_t * const p_result_code) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_result_code); + + uint32_t index = 0; + uint32_t err_code = ser_ble_cmd_rsp_result_code_dec(p_buf, &index, packet_len, + SVC_ANT_CHANNEL_ID_GET, p_result_code); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + if (*p_result_code != NRF_SUCCESS) + { + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return NRF_SUCCESS; + } + + 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_transmit_type); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return NRF_SUCCESS; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_id_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_id_set.c new file mode 100644 index 0000000..09563b3 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_id_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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_channel_id_set_req_enc(uint8_t channel, + uint16_t device_number, + uint8_t device_type, + uint8_t transmit_type, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_CHANNEL_ID_SET; + p_buf[index++] = channel; + index += uint16_encode(device_number, &p_buf[index]); + p_buf[index++] = device_type; + p_buf[index++] = transmit_type; + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + + +uint32_t ant_channel_id_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_CHANNEL_ID_SET, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_low_priority_rx_search_timeout_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_low_priority_rx_search_timeout_set.c new file mode 100644 index 0000000..135f470 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_low_priority_rx_search_timeout_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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_channel_low_priority_rx_search_timeout_set_req_enc(uint8_t channel, + uint8_t timeout, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_CHANNEL_LOW_PRIO_RX_SEARCH_TIMEOUT_SET; + p_buf[index++] = channel; + p_buf[index++] = timeout; + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + + +uint32_t ant_channel_low_priority_rx_search_timeout_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_CHANNEL_LOW_PRIO_RX_SEARCH_TIMEOUT_SET, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_open_with_offset.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_open_with_offset.c new file mode 100644 index 0000000..c4e30ef --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_open_with_offset.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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_channel_open_with_offset_req_enc(uint8_t channel, + uint16_t usOffset, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_CHANNEL_OPEN; + p_buf[index++] = channel; + index += uint16_encode(usOffset, &p_buf[index]); + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + + +uint32_t ant_channel_open_with_offset_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_CHANNEL_OPEN, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_period_get.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_period_get.c new file mode 100644 index 0000000..09576fe --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_period_get.c @@ -0,0 +1,94 @@ +/** + * 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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_channel_period_get_req_enc(uint8_t channel, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_CHANNEL_PERIOD_GET; + p_buf[index++] = channel; + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ant_channel_period_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + void * p_period, + uint32_t * const p_result_code) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_result_code); + + uint32_t index = 0; + uint32_t err_code = ser_ble_cmd_rsp_result_code_dec(p_buf, &index, packet_len, + SVC_ANT_CHANNEL_PERIOD_GET, p_result_code); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + if (*p_result_code != NRF_SUCCESS) + { + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return NRF_SUCCESS; + } + + 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 NRF_SUCCESS; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_period_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_period_set.c new file mode 100644 index 0000000..292f8f9 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_channel_period_set_req_enc(uint8_t channel, + uint16_t period, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_CHANNEL_PERIOD_SET; + p_buf[index++] = channel; + index += uint16_encode(period, &p_buf[index]); + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ant_channel_period_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_CHANNEL_PERIOD_SET, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_radio_freq_get.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_radio_freq_get.c new file mode 100644 index 0000000..6651862 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_radio_freq_get.c @@ -0,0 +1,95 @@ +/** + * 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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_channel_radio_freq_get_req_enc(uint8_t channel, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_CHANNEL_RADIO_FREQ_GET; + p_buf[index++] = channel; + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ant_channel_radio_freq_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + void * const p_r_freq, + uint32_t * const p_result_code) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_result_code); + + uint32_t index = 0; + uint32_t err_code = ser_ble_cmd_rsp_result_code_dec(p_buf, &index, packet_len, + SVC_ANT_CHANNEL_RADIO_FREQ_GET, p_result_code); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + if (*p_result_code != NRF_SUCCESS) + { + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return NRF_SUCCESS; + } + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_r_freq); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return NRF_SUCCESS; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_radio_freq_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_radio_freq_set.c new file mode 100644 index 0000000..5638e97 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_channel_radio_freq_set_req_enc(uint8_t channel, + uint8_t freq, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_CHANNEL_RADIO_FREQ_SET; + p_buf[index++] = channel; + p_buf[index++] = freq; + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ant_channel_radio_freq_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_CHANNEL_RADIO_FREQ_SET, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_radio_tx_power_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_radio_tx_power_set.c new file mode 100644 index 0000000..c7ea273 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_radio_tx_power_set.c @@ -0,0 +1,81 @@ +/** + * 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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_channel_radio_tx_power_set_req_enc(uint8_t channel, + uint8_t tx_power, + uint8_t custom_tx_power, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_CHANNEL_RADIO_TX_POWER_SET; + p_buf[index++] = channel; + p_buf[index++] = tx_power; + p_buf[index++] = custom_tx_power; + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + + +uint32_t ant_channel_radio_tx_power_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_CHANNEL_RADIO_TX_POWER_SET, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_rx_search_timeout_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_rx_search_timeout_set.c new file mode 100644 index 0000000..1ac542d --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_rx_search_timeout_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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_channel_rx_search_timeout_set_req_enc(uint8_t channel, + uint8_t timeout, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_CHANNEL_SEARCH_TIMEOUT_SET; + p_buf[index++] = channel; + p_buf[index++] = timeout; + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + + +uint32_t ant_channel_rx_search_timeout_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_CHANNEL_SEARCH_TIMEOUT_SET, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_status_get.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_status_get.c new file mode 100644 index 0000000..2ed53eb --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_status_get.c @@ -0,0 +1,95 @@ +/** + * 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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_channel_status_get_req_enc(uint8_t channel, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_CHANNEL_STATUS_GET; + p_buf[index++] = channel; + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ant_channel_status_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + void * const p_status, + uint32_t * const p_result_code) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_result_code); + + uint32_t index = 0; + uint32_t err_code = ser_ble_cmd_rsp_result_code_dec(p_buf, &index, packet_len, + SVC_ANT_CHANNEL_STATUS_GET, p_result_code); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + if (*p_result_code != NRF_SUCCESS) + { + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return NRF_SUCCESS; + } + + err_code = uint8_t_dec(p_buf, packet_len, &index, p_status); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return NRF_SUCCESS; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_unassign.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_unassign.c new file mode 100644 index 0000000..1c82fe9 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_channel_unassign.c @@ -0,0 +1,76 @@ +/** + * 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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_channel_unassign_req_enc(uint8_t channel, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_CHANNEL_UNASSIGN; + p_buf[index++] = channel; + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ant_channel_unassign_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_CHANNEL_UNASSIGN, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_coex_config_get.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_coex_config_get.c new file mode 100644 index 0000000..a38f497 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_coex_config_get.c @@ -0,0 +1,130 @@ +/** + * 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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" +#include "ant_interface.h" + +uint32_t ant_coex_config_get_req_enc(uint8_t channel, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + uint8_t svc_number = SVC_ANT_COEX_CONFIG_GET; + uint32_t err_code = NRF_SUCCESS; + uint32_t buf_len = *p_buf_len; + uint32_t index = 0; + + err_code = uint8_t_enc(&svc_number, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_enc(&channel, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ant_coex_config_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + void * const p_coex_config, + void * const p_adv_coex_config, + uint32_t * const p_result_code) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_result_code); + + uint32_t index = 0; + uint32_t err_code = ser_ble_cmd_rsp_result_code_dec(p_buf, &index, packet_len, + SVC_ANT_COEX_CONFIG_GET, p_result_code); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + if (*p_result_code != NRF_SUCCESS) + { + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return NRF_SUCCESS; + } + + uint8_t coex_config_size; + uint8_t coex_config_buffer[(MESG_BUFFER_SIZE / 2) - 1]; + + uint8_t adv_coex_config_size; + uint8_t adv_coex_config_buffer[(MESG_BUFFER_SIZE / 2) - 1]; + + err_code = uint8_t_dec(p_buf, packet_len, &index, &coex_config_size); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_vector_dec(p_buf, packet_len, &index, coex_config_buffer, coex_config_size); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, packet_len, &index, &(adv_coex_config_size)); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_vector_dec(p_buf, packet_len, &index, adv_coex_config_buffer, adv_coex_config_size); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + + if (p_coex_config) + { + ((ANT_BUFFER_PTR *)p_coex_config)->ucBufferSize = coex_config_size; + memcpy(((ANT_BUFFER_PTR *)p_coex_config)->pucBuffer, coex_config_buffer,((ANT_BUFFER_PTR *)p_coex_config)->ucBufferSize); + } + + if (p_adv_coex_config) + { + ((ANT_BUFFER_PTR *)p_adv_coex_config)->ucBufferSize = coex_config_size; + memcpy(((ANT_BUFFER_PTR *)p_adv_coex_config)->pucBuffer, coex_config_buffer,((ANT_BUFFER_PTR *)p_adv_coex_config)->ucBufferSize); + } + + SER_ASSERT_LENGTH_LEQ(index, packet_len); + + return NRF_SUCCESS; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_coex_config_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_coex_config_set.c new file mode 100644 index 0000000..4465abc --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_coex_config_set.c @@ -0,0 +1,109 @@ +/** + * 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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_coex_config_set_req_enc(uint8_t channel, + ANT_BUFFER_PTR const * const p_coex_config, + ANT_BUFFER_PTR const * const p_adv_coex_config, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + uint8_t svc_number = SVC_ANT_COEX_CONFIG_SET; + uint32_t err_code = NRF_SUCCESS; + uint32_t buf_len = *p_buf_len; + uint32_t index = 0; + + err_code = uint8_t_enc(&svc_number, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_enc(&channel, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + // Encode coex config buffer size + uint8_t coex_config_buffer_size = p_coex_config -> ucBufferSize; + err_code = uint8_t_enc(&coex_config_buffer_size, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + // Encode coex config buffer + err_code = uint8_vector_enc(p_coex_config -> pucBuffer, + coex_config_buffer_size, + p_buf, + buf_len, + &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + // Encode advanced coex config buffer size + uint8_t adv_coex_config_buffer_size = p_adv_coex_config -> ucBufferSize; + err_code = uint8_t_enc(&adv_coex_config_buffer_size, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + // Encode advanced coex config buffer + err_code = uint8_vector_enc(p_adv_coex_config -> pucBuffer, + adv_coex_config_buffer_size, + p_buf, + buf_len, + &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ant_coex_config_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_COEX_CONFIG_SET, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_crypto_channel_enable.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_crypto_channel_enable.c new file mode 100644 index 0000000..9071c89 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_crypto_channel_enable.c @@ -0,0 +1,82 @@ +/** + * 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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_crypto_channel_enable_req_enc(uint8_t channel, + uint8_t enable, + uint8_t key_num, + uint8_t decimation_rate, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_CRYPTO_CHANNEL_ENABLE; + p_buf[index++] = channel; + p_buf[index++] = enable; + p_buf[index++] = key_num; + p_buf[index++] = decimation_rate; + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ant_crypto_channel_enable_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_CRYPTO_CHANNEL_ENABLE, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_crypto_info_get.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_crypto_info_get.c new file mode 100644 index 0000000..6a2b5a4 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_crypto_info_get.c @@ -0,0 +1,123 @@ +/** + * 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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_crypto_info_get_req_enc(uint8_t type, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + uint8_t svc_number = SVC_ANT_CRYPTO_INFO_GET; + uint32_t err_code = NRF_SUCCESS; + uint32_t buf_len = *p_buf_len; + uint32_t index = 0; + + err_code = uint8_t_enc(&svc_number, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_enc(&type, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_LEQ(index, buf_len); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ant_crypto_info_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + void * const p_info, + uint32_t * const p_result_code) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_result_code); + + uint32_t index = 0; + uint32_t err_code = ser_ble_cmd_rsp_result_code_dec(p_buf, &index, packet_len, + SVC_ANT_CRYPTO_INFO_GET, p_result_code); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + if (*p_result_code != NRF_SUCCESS) + { + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return NRF_SUCCESS; + } + + uint8_t type; + uint8_t crypto_info_size; + + err_code = uint8_t_dec(p_buf, packet_len, &index, &type); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + switch (type) + { + case ENCRYPTION_INFO_GET_SUPPORTED_MODE: + crypto_info_size = MESG_CONFIG_ENCRYPT_REQ_CAPABILITIES_SIZE - MESG_CHANNEL_NUM_SIZE; + break; + case ENCRYPTION_INFO_GET_CRYPTO_ID: + crypto_info_size = MESG_CONFIG_ENCRYPT_REQ_CONFIG_ID_SIZE - MESG_CHANNEL_NUM_SIZE; + break; + case ENCRYPTION_INFO_GET_CUSTOM_USER_DATA: + crypto_info_size = (MESG_CONFIG_ENCRYPT_REQ_CONFIG_USER_DATA_SIZE - + MESG_CHANNEL_NUM_SIZE); + break; + default: + crypto_info_size = 0; + break; + } + + err_code = uint8_vector_dec(p_buf, packet_len, &index, (uint8_t *)p_info, crypto_info_size); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_LEQ(index, packet_len); + + return NRF_SUCCESS; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_crypto_info_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_crypto_info_set.c new file mode 100644 index 0000000..b56987a --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_crypto_info_set.c @@ -0,0 +1,90 @@ +/** + * 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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_crypto_info_set_req_enc(uint8_t type, + uint8_t const * const p_config, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + uint8_t svc_number = SVC_ANT_CRYPTO_INFO_SET; + uint32_t err_code = NRF_SUCCESS; + uint32_t buf_len = *p_buf_len; + uint32_t index = 0; + + err_code = uint8_t_enc(&svc_number, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_enc(&type, p_buf, buf_len, &index); + 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_enc(p_config, crypto_info_size, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ant_crypto_info_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_CRYPTO_INFO_SET, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_crypto_key_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_crypto_key_set.c new file mode 100644 index 0000000..4c1b05c --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_crypto_key_set.c @@ -0,0 +1,85 @@ +/** + * 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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_crypto_key_set_req_enc(uint8_t key_num, + uint8_t const * const p_key, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + uint8_t svc_number = SVC_ANT_CRYPTO_KEY_SET; + uint32_t err_code = NRF_SUCCESS; + uint32_t buf_len = *p_buf_len; + uint32_t index = 0; + + err_code = uint8_t_enc(&svc_number, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_enc(&key_num, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_vector_enc(p_key, SIZE_OF_ENCRYPTED_KEY, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ant_crypto_key_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_CRYPTO_KEY_SET, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_cw_test_mode.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_cw_test_mode.c new file mode 100644 index 0000000..c149907 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_cw_test_mode.c @@ -0,0 +1,82 @@ +/** + * 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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_cw_test_mode_req_enc(uint8_t radio_freq, + uint8_t tx_power, + uint8_t custom_tx_power, + uint8_t mode, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_CW_TEST_MODE; + p_buf[index++] = radio_freq; + p_buf[index++] = tx_power; + p_buf[index++] = custom_tx_power; + p_buf[index++] = mode; + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ant_cw_test_mode_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_CW_TEST_MODE, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_cw_test_mode_init.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_cw_test_mode_init.c new file mode 100644 index 0000000..706fd3b --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_cw_test_mode_init.c @@ -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. + * + */ + +#include <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_cw_test_mode_init_req_enc(uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_INIT_CW_TEST_MODE; + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ant_cw_test_mode_init_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_INIT_CW_TEST_MODE, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_enable.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_enable.c new file mode 100644 index 0000000..e8b9f20 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_enable.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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_enable_req_enc(ANT_ENABLE * const p_channel_enable, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_ENABLE; + + err_code = cond_field_enc(p_channel_enable, p_buf, *p_buf_len, &index, ANT_ENABLE_enc); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + + +uint32_t ant_enable_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_ENABLE, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_event.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_event.c new file mode 100644 index 0000000..afad594 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_event.c @@ -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. + * + */ + +//#include "ble_app.h" +//#include "ble_evt_app.h" +//#include "ble_gap_evt_app.h" +//#include "ble_gattc_evt_app.h" +//#include "ble_gatts_evt_app.h" +//#include "ble_l2cap_evt_app.h" +#include "ble_serialization.h" +#include "app_util.h" +#include "nrf_sdh_ant.h" +#include "ant_struct_serialization.h" +#include "ant_parameters.h" + +uint32_t ant_event_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ant_evt_t * const p_event, + uint32_t * const p_event_len) +{ + uint32_t index = SER_ANT_EVT_ID_POS; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_event_len); + SER_ASSERT_LENGTH_LEQ(SER_EVT_HEADER_SIZE, packet_len); + SER_ASSERT_NOT_NULL(p_event); + + err_code = ant_evt_t_dec(p_buf, packet_len, &index, p_event); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + *p_event_len = index; + + SER_ASSERT_LENGTH_LEQ(p_event->channel, MAX_ANT_CHANNELS); + + return err_code; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_event.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_event.h new file mode 100644 index 0000000..da62571 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_event.h @@ -0,0 +1,81 @@ +/** + * 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 "ble_serialization.h" +#include "app_util.h" +#include "nrf_sdh_ant.h" + +/** + * @addtogroup ser_app_s212_codecs + * @{ + */ + + +/**@brief Event decoding dispatcher. + * + * The event decoding dispatcher will route the event packet to the correct decoder, which in turn + * decodes the contents of the event and updates the \p p_event struct. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of the event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to the \ref ant_evt_t buffer where the decoded event will be + * stored. If NULL, the required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of the decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold the decoded event. + * @retval NRF_ERROR_NOT_FOUND Decoding failure. No event decoder is available. + */ +uint32_t ant_event_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ant_evt_t * const p_event, + uint32_t * const p_event_len); +/** @} */ + +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_id_list_add.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_id_list_add.c new file mode 100644 index 0000000..ef318e0 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_id_list_add.c @@ -0,0 +1,91 @@ +/** + * 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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" +#include "ant_parameters.h" + +uint32_t ant_id_list_add_req_enc(uint8_t channel, + uint8_t const * const p_dev_id, + uint8_t list_index, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + uint8_t svc_number = SVC_ANT_ID_LIST_ADD; + uint32_t err_code = NRF_SUCCESS; + uint32_t buf_len = *p_buf_len; + uint32_t index = 0; + + err_code = uint8_t_enc(&svc_number, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_enc(&channel, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_vector_enc(p_dev_id, ANT_ID_SIZE, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_enc(&list_index, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + + +uint32_t ant_id_list_add_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_ID_LIST_ADD, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_id_list_config.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_id_list_config.c new file mode 100644 index 0000000..305dec8 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_id_list_config.c @@ -0,0 +1,81 @@ +/** + * 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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_id_list_config_req_enc(uint8_t channel, + uint8_t id_list_size, + uint8_t inc_exc_flag, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_ID_LIST_CONFIG; + p_buf[index++] = channel; + p_buf[index++] = id_list_size; + p_buf[index++] = inc_exc_flag; + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + + +uint32_t ant_id_list_config_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_ID_LIST_CONFIG, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_lib_config_clear.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_lib_config_clear.c new file mode 100644 index 0000000..0a703b2 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_lib_config_clear.c @@ -0,0 +1,76 @@ +/** + * 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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_lib_config_clear_req_enc(uint8_t ant_lib_config, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_LIB_CONFIG_CLEAR; + p_buf[index++] = ant_lib_config; + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ant_lib_config_clear_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_LIB_CONFIG_CLEAR, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_lib_config_get.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_lib_config_get.c new file mode 100644 index 0000000..93f8819 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_lib_config_get.c @@ -0,0 +1,93 @@ +/** + * 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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_lib_config_get_req_enc(uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_LIB_CONFIG_GET; + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ant_lib_config_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + void * const p_ant_lib_config, + uint32_t * const p_result_code) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_result_code); + + uint32_t index = 0; + uint32_t err_code = ser_ble_cmd_rsp_result_code_dec(p_buf, &index, packet_len, + SVC_ANT_LIB_CONFIG_GET, p_result_code); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + if (*p_result_code != NRF_SUCCESS) + { + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return NRF_SUCCESS; + } + + 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 NRF_SUCCESS; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_lib_config_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_lib_config_set.c new file mode 100644 index 0000000..3f00546 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_lib_config_set.c @@ -0,0 +1,76 @@ +/** + * 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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_lib_config_set_req_enc(uint8_t ant_lib_config, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_LIB_CONFIG_SET; + p_buf[index++] = ant_lib_config; + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ant_lib_config_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_LIB_CONFIG_SET, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_network_address_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_network_address_set.c new file mode 100644 index 0000000..fade1d4 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_network_address_set.c @@ -0,0 +1,85 @@ +/** + * 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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_network_address_set_req_enc(uint8_t network, + uint8_t const * const p_network_key, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + uint8_t svc_number = SVC_ANT_NETWORK_KEY_SET; + uint32_t err_code = NRF_SUCCESS; + uint32_t buf_len = *p_buf_len; + uint32_t index = 0; + + err_code = uint8_t_enc(&svc_number, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_enc(&network, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_vector_enc(p_network_key, MESG_NETWORK_KEY_SIZE - MESG_CHANNEL_NUM_SIZE, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ant_network_address_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_NETWORK_KEY_SET, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_prox_search_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_prox_search_set.c new file mode 100644 index 0000000..45b5415 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_prox_search_set.c @@ -0,0 +1,81 @@ +/** + * 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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_prox_search_set_req_enc(uint8_t channel, + uint8_t prox_threshold, + uint8_t custom_prox_threshold, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_PROX_SEARCH_SET; + p_buf[index++] = channel; + p_buf[index++] = prox_threshold; + p_buf[index++] = custom_prox_threshold; + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + + +uint32_t ant_prox_search_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_PROX_SEARCH_SET, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_rx_scan_mode_start.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_rx_scan_mode_start.c new file mode 100644 index 0000000..6cdefe7 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_rx_scan_mode_start.c @@ -0,0 +1,76 @@ +/** + * 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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_rx_scan_mode_start_req_enc(uint8_t sync_scan_channel_packets_only, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_RX_SCAN_MODE_START; + p_buf[index++] = sync_scan_channel_packets_only; + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ant_rx_scan_mode_start_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_RX_SCAN_MODE_START, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_search_channel_priority_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_search_channel_priority_set.c new file mode 100644 index 0000000..0ad7a55 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_search_channel_priority_set_req_enc(uint8_t channel, + uint8_t search_priority, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_SEARCH_CHANNEL_PRIORITY_SET; + p_buf[index++] = channel; + p_buf[index++] = search_priority; + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ant_search_channel_priority_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_SEARCH_CHANNEL_PRIORITY_SET, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_search_waveform_set.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_search_waveform_set.c new file mode 100644 index 0000000..6204445 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_search_waveform_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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_search_waveform_set_req_enc(uint8_t channel, + uint16_t waveform, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_SEARCH_WAVEFORM_SET; + p_buf[index++] = channel; + index += uint16_encode(waveform, &p_buf[index]); + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + + +uint32_t ant_search_waveform_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_SEARCH_WAVEFORM_SET, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_stack_reset.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_stack_reset.c new file mode 100644 index 0000000..15fb65d --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_stack_reset.c @@ -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. + * + */ + +#include <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_stack_reset_req_enc(uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_STACK_INIT; + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ant_stack_reset_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + // Use the ble cmd rsp dec function because it is adequte to decode + // the command response as it is the same for both ant and ble. + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SVC_ANT_STACK_INIT, p_result_code); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_version_get.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_version_get.c new file mode 100644 index 0000000..f0159de --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ant/serializers/ant_version_get.c @@ -0,0 +1,93 @@ +/** + * 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 <stdlib.h> +#include <string.h> +#include "ant_app.h" +#include "ble_serialization.h" +#include "ant_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +uint32_t ant_version_get_req_enc(uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + p_buf[index++] = SVC_ANT_VERSION; + + SER_ASSERT_LENGTH_LEQ(index, *p_buf_len); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ant_version_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + void * * const p_version, + uint32_t * const p_result_code) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_result_code); + + uint32_t index = 0; + uint32_t err_code = ser_ble_cmd_rsp_result_code_dec(p_buf, &index, packet_len, + SVC_ANT_VERSION, p_result_code); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + if (*p_result_code != NRF_SUCCESS) + { + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return NRF_SUCCESS; + } + + err_code = uint8_vector_dec(p_buf, packet_len, &index, (uint8_t *)*p_version, MESG_BUFFER_SIZE); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT_LENGTH_EQ(index, packet_len); + + return NRF_SUCCESS; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble.c new file mode 100644 index 0000000..5aa5571 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble.c @@ -0,0 +1,621 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include "ble.h" +#include "ble_serialization.h" +#include <stdint.h> +#include "ble_app.h" +#include "ser_sd_transport.h" +#include "app_error.h" +#include "app_ble_user_mem.h" + +extern ser_ble_user_mem_t m_app_user_mem_table[]; + +/**@brief Structure containing @ref sd_ble_uuid_encode output parameters. */ +typedef struct +{ + uint8_t * p_uuid_le_len; /**< @ref sd_ble_uuid_encode appearance p_uuid_le_len output parameter. */ + uint8_t * p_uuid_le; /**< @ref sd_ble_uuid_encode appearance p_uuid_le output parameter. */ +} ble_uuid_encode_out_params_t; + +/**@brief Structure containing @ref sd_ble_user_mem_reply output parameters. */ +typedef struct +{ + uint16_t conn_handle; /**< @ref sd_ble_user_mem_reply conn_handle. */ + uint8_t context_allocated; /**< @ref sd_ble_user_mem_reply user memory context allocated flag. */ +} ble_user_mem_reply_out_params_t; + +/**@brief Union containing BLE command output parameters. */ +typedef union +{ + ble_uuid_encode_out_params_t ble_uuid_encode_out_params; /**< @ref sd_ble_uuid_encode output parameters. */ + ble_user_mem_reply_out_params_t ble_user_mem_reply_out_params; /**< @ref sd_ble_user_mem_reply output parameters. */ +} ble_command_output_params_t; + +static ble_command_output_params_t m_output_params; /**< BLE command output parameters. */ + +static void * mp_out_params[3]; +static uint32_t m_uint32_param; + +static void tx_buf_alloc(uint8_t * * p_data, uint32_t * p_len) +{ + uint32_t err_code; + uint16_t len16; + + do + { + err_code = ser_sd_transport_tx_alloc(p_data, &len16); + } + while (err_code != NRF_SUCCESS); + + *p_data[0] = SER_PKT_TYPE_CMD; + *p_len = (uint32_t)len16 - 1; +} + +/**@brief Command response callback function for @ref sd_ble_uuid_encode BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t uuid_encode_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = + ble_uuid_encode_rsp_dec(p_buffer, + length, + m_output_params.ble_uuid_encode_out_params.p_uuid_le_len, + m_output_params.ble_uuid_encode_out_params.p_uuid_le, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + return result_code; +} + +#ifndef _sd_ble_uuid_encode +#define _sd_ble_uuid_encode sd_ble_uuid_encode +#endif +uint32_t _sd_ble_uuid_encode(ble_uuid_t const * const p_uuid, + uint8_t * const p_uuid_le_len, + uint8_t * const p_uuid_le) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + m_output_params.ble_uuid_encode_out_params.p_uuid_le_len = p_uuid_le_len; + m_output_params.ble_uuid_encode_out_params.p_uuid_le = p_uuid_le; + + uint32_t err_code = ble_uuid_encode_req_enc(p_uuid, + p_uuid_le_len, + p_uuid_le, + &(p_buffer[1]), + &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + uuid_encode_rsp_dec); + +} + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +/**@brief Command response callback function for @ref sd_ble_tx_packet_count_get BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t tx_packet_count_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_tx_packet_count_get_rsp_dec(p_buffer, + length, + (uint8_t * *)&mp_out_params[0], + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_tx_packet_count_get +#define _sd_ble_tx_packet_count_get sd_ble_tx_packet_count_get +#endif +uint32_t _sd_ble_tx_packet_count_get(uint16_t conn_handle, uint8_t * p_count) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + mp_out_params[0] = p_count; + + const uint32_t err_code = ble_tx_packet_count_get_req_enc(conn_handle, + p_count, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + tx_packet_count_get_rsp_dec); + +} +#endif +/**@brief Command response callback function for @ref sd_ble_uuid_vs_add BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t uuid_vs_add_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_uuid_vs_add_rsp_dec(p_buffer, + length, + (uint8_t * *)&mp_out_params[0], + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_uuid_vs_add +#define _sd_ble_uuid_vs_add sd_ble_uuid_vs_add +#endif +uint32_t _sd_ble_uuid_vs_add(ble_uuid128_t const * const p_vs_uuid, uint8_t * const p_uuid_type) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + mp_out_params[0] = p_uuid_type; + + const uint32_t err_code = ble_uuid_vs_add_req_enc(p_vs_uuid, p_uuid_type, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + uuid_vs_add_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_uuid_decode BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t uuid_decode_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_uuid_decode_rsp_dec(p_buffer, + length, + (ble_uuid_t * *)&mp_out_params[0], + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_uuid_decode +#define _sd_ble_uuid_decode sd_ble_uuid_decode +#endif +uint32_t _sd_ble_uuid_decode(uint8_t uuid_le_len, + uint8_t const * const p_uuid_le, + ble_uuid_t * const p_uuid) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + mp_out_params[0] = p_uuid; + + const uint32_t err_code = ble_uuid_decode_req_enc(uuid_le_len, p_uuid_le, p_uuid, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + uuid_decode_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_version_get BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t version_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_version_get_rsp_dec(p_buffer, + length, + (ble_version_t *)mp_out_params[0], + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_version_get +#define _sd_ble_version_get sd_ble_version_get +#endif +uint32_t _sd_ble_version_get(ble_version_t * p_version) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + mp_out_params[0] = p_version; + + const uint32_t err_code = ble_version_get_req_enc(p_version, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + version_get_rsp_dec); + +} + +/**@brief Command response callback function for @ref sd_ble_opt_get BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t opt_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + uint32_t uint32_param; + uint32_t err_code = ble_opt_get_rsp_dec(p_buffer, + length, + &uint32_param, + (ble_opt_t *)mp_out_params[0], + &result_code); + + APP_ERROR_CHECK(err_code); + if ((result_code == NRF_SUCCESS) && (m_uint32_param != uint32_param)) // decoded id should be the same as encoded one + { + err_code = NRF_ERROR_INVALID_PARAM; + } + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_opt_get +#define _sd_ble_opt_get sd_ble_opt_get +#endif +uint32_t _sd_ble_opt_get(uint32_t opt_id, ble_opt_t *p_opt) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + mp_out_params[0] = p_opt; + m_uint32_param = opt_id; + + const uint32_t err_code = ble_opt_get_req_enc(opt_id, + p_opt, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + opt_get_rsp_dec); + +} + +/**@brief Command response callback function for @ref sd_ble_opt_set BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t opt_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_opt_set_rsp_dec(p_buffer, + length, + &result_code); + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_opt_set +#define _sd_ble_opt_set sd_ble_opt_set +#endif +uint32_t _sd_ble_opt_set(uint32_t opt_id, ble_opt_t const *p_opt) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ble_opt_set_req_enc(opt_id, + p_opt, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + opt_set_rsp_dec); + +} + +/**@brief Command response callback function for @ref sd_ble_enable BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t enable_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_enable_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_enable +#define _sd_ble_enable sd_ble_enable +#endif +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t _sd_ble_enable(ble_enable_params_t * p_params, uint32_t * p_app_ram_base) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + //Ignore ram_base parameter + (void)p_app_ram_base; + + tx_buf_alloc(&p_buffer, &buffer_length); + mp_out_params[0] = p_params; + + const uint32_t err_code = ble_enable_req_enc(p_params, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + enable_rsp_dec); + +} +#else +uint32_t _sd_ble_enable(uint32_t * p_app_ram_base) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + //Ignore ram_base parameter + (void)p_app_ram_base; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ble_enable_req_enc(&(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + enable_rsp_dec); + +} +#endif +/**@brief Command response callback function for @ref sd_ble_user_mem_reply BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t user_mem_reply_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + uint32_t err_code = ble_user_mem_reply_rsp_dec(p_buffer, + length, + &result_code); + APP_ERROR_CHECK(err_code); + + if ((result_code != NRF_SUCCESS) && + (m_output_params.ble_user_mem_reply_out_params.context_allocated)) + { + err_code = app_ble_user_mem_context_destroy( + m_output_params.ble_user_mem_reply_out_params.conn_handle); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + } + + return result_code; +} + +#ifndef _sd_ble_user_mem_reply +#define _sd_ble_user_mem_reply sd_ble_user_mem_reply +#endif +uint32_t _sd_ble_user_mem_reply(uint16_t conn_handle, ble_user_mem_block_t const *p_block) +{ + uint8_t * p_buffer; + uint32_t buffer_length, user_mem_table_index; + uint32_t err_code = NRF_SUCCESS; + + tx_buf_alloc(&p_buffer, &buffer_length); + + // Prepare User Memory Block context for later synchronization when SoftDevice updates + // the data in the memory block + if (p_block != NULL) + { + err_code = app_ble_user_mem_context_create(conn_handle, &user_mem_table_index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + m_app_user_mem_table[user_mem_table_index].mem_block.len = p_block->len; + m_app_user_mem_table[user_mem_table_index].mem_block.p_mem = p_block->p_mem; + // Save connection handle and context allocation flag for case if context destroy was needed + m_output_params.ble_user_mem_reply_out_params.conn_handle = conn_handle; + m_output_params.ble_user_mem_reply_out_params.context_allocated = 1; + } + else + { + m_output_params.ble_user_mem_reply_out_params.context_allocated = 0; + } + + err_code = ble_user_mem_reply_req_enc(conn_handle, + p_block, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + user_mem_reply_rsp_dec); +} +#if NRF_SD_BLE_API_VERSION >= 4 +/**@brief Command response callback function for @ref sd_ble_cfg_set BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t cfg_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_cfg_set_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_cfg_set +#define _sd_ble_cfg_set sd_ble_cfg_set +#endif +uint32_t _sd_ble_cfg_set(uint32_t cfg_id, ble_cfg_t const * p_cfg, uint32_t app_ram_base) +{ + uint8_t * p_buffer; + uint32_t buffer_length; + + //Ignore ram_base parameter + (void)app_ram_base; + + tx_buf_alloc(&p_buffer, &buffer_length); + + const uint32_t err_code = ble_cfg_set_req_enc(cfg_id, p_cfg, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + cfg_set_rsp_dec); +} +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble_gap.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble_gap.c new file mode 100644 index 0000000..55cc2fa --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble_gap.c @@ -0,0 +1,2025 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include "ble_gap.h" +#include <stdint.h> +#include <string.h> +#include "ble_serialization.h" +#include "ser_sd_transport.h" +#include "ble_gap_app.h" +#include "app_error.h" +#include "app_ble_gap_sec_keys.h" +#include "ser_config.h" + +extern ser_ble_gap_app_keyset_t m_app_keys_table[SER_MAX_CONNECTIONS]; + +/**@brief Structure containing @ref sd_ble_gap_device_name_get output parameters. */ +typedef struct +{ + uint8_t * p_dev_name; /**< @ref sd_ble_gap_device_name_get p_dev_name output parameter. */ + uint16_t * p_len; /**< @ref sd_ble_gap_device_name_get p_len output parameter. */ +} gap_device_name_get_output_params_t; + +/**@brief Structure containing @ref sd_ble_gap_appearance_get output parameters. */ +typedef struct +{ + uint16_t * p_appearance; /**< @ref sd_ble_gap_appearance_get p_appearance output parameter. */ +} gap_appearance_get_output_params_t; + +/**@brief Structure containing @ref sd_ble_gap_ppcp_get output parameters. */ +typedef struct +{ + ble_gap_conn_params_t * p_conn_params; /**< @ref sd_ble_gap_ppcp_get p_conn_params output parameter. */ +} gap_ppcp_get_out_params_t; + +/**@brief Structure containing @ref sd_ble_gap_sec_params_reply output parameters. */ +typedef struct +{ + ble_gap_sec_keyset_t const * p_sec_keyset; /**< @ref sd_ble_gap_sec_params_reply p_sec_keyset output parameter. */ + uint16_t conn_handle; /**< @ref sd_ble_gap_sec_params_reply p_conn_handle output parameter. */ +} gap_sec_params_reply_out_params_t; + +/**@brief Union containing BLE command output parameters. */ +typedef union +{ + gap_device_name_get_output_params_t gap_device_name_get_out_params; /**< @ref sd_ble_gap_device_name_get output parameters. */ + gap_appearance_get_output_params_t gap_appearance_get_out_params; /**< @ref sd_ble_gap_appearance_get output parameters. */ + gap_ppcp_get_out_params_t gap_ppcp_get_out_params; /**< @ref sd_ble_gap_ppcp_get output parameters. */ + gap_sec_params_reply_out_params_t gap_sec_params_reply_out_params;/**< @ref sd_ble_sec_params_reply output parameters. */ +} gap_command_output_params_t; + +static gap_command_output_params_t m_output_params; /**< BLE command output parameters. */ + +static void * mp_out_params[3]; + +static void tx_buf_alloc(uint8_t * * p_data, uint16_t * p_len) +{ + uint32_t err_code; + + do + { + err_code = ser_sd_transport_tx_alloc(p_data, p_len); + } + while (err_code != NRF_SUCCESS); + *p_data[0] = SER_PKT_TYPE_CMD; + *p_len -= 1; +} + +/**@brief Command response callback function for @ref sd_ble_gap_adv_start BLE command. + * + * Callback for decoding the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_adv_start_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gap_adv_start_rsp_dec(p_buffer, length, &result_code); + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_adv_start +#define _sd_ble_gap_adv_start sd_ble_gap_adv_start +#endif +uint32_t _sd_ble_gap_adv_start( +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t adv_handle +#else + ble_gap_adv_params_t const * const p_adv_params +#endif +#if NRF_SD_BLE_API_VERSION >= 4 + ,uint8_t conn_cfg_tag +#endif +) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + + const uint32_t err_code = ble_gap_adv_start_req_enc( +#if NRF_SD_BLE_API_VERSION > 5 + adv_handle, +#else + p_adv_params, +#endif +#if NRF_SD_BLE_API_VERSION >= 4 + conn_cfg_tag, +#endif + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_adv_start_rsp_dec); +} + +/**@brief Command response callback function for @ref ble_gap_device_name_get_req_enc BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_device_name_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = + ble_gap_device_name_get_rsp_dec(p_buffer, + length, + m_output_params.gap_device_name_get_out_params.p_dev_name, + m_output_params.gap_device_name_get_out_params.p_len, + &result_code); + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_device_name_get +#define _sd_ble_gap_device_name_get sd_ble_gap_device_name_get +#endif +uint32_t _sd_ble_gap_device_name_get(uint8_t * const p_dev_name, uint16_t * const p_len) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + m_output_params.gap_device_name_get_out_params.p_dev_name = p_dev_name; + m_output_params.gap_device_name_get_out_params.p_len = p_len; + + const uint32_t err_code = ble_gap_device_name_get_req_enc(p_dev_name, + p_len, + &(p_buffer[1]), + &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_device_name_get_rsp_dec); +} + + +/**@brief Command response callback function for @ref sd_ble_gap_appearance_get BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_appearance_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = + ble_gap_appearance_get_rsp_dec(p_buffer, + length, + m_output_params.gap_appearance_get_out_params.p_appearance, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_appearance_get +#define _sd_ble_gap_appearance_get sd_ble_gap_appearance_get +#endif +uint32_t _sd_ble_gap_appearance_get(uint16_t * const p_appearance) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + m_output_params.gap_appearance_get_out_params.p_appearance = p_appearance; + + const uint32_t err_code = ble_gap_appearance_get_req_enc(p_appearance, + &(p_buffer[1]), + &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_appearance_get_rsp_dec); +} + + +/**@brief Command response callback function for @ref sd_ble_gap_device_name_set BLE command. + * + * Callback for decoding the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_device_name_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gap_device_name_set_rsp_dec(p_buffer, length, &result_code); + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_device_name_set +#define _sd_ble_gap_device_name_set sd_ble_gap_device_name_set +#endif +uint32_t _sd_ble_gap_device_name_set(ble_gap_conn_sec_mode_t const * const p_write_perm, + uint8_t const * const p_dev_name, + uint16_t len) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_device_name_set_req_enc(p_write_perm, + p_dev_name, + len, + &(p_buffer[1]), + &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_device_name_set_rsp_dec); +} + + +/**@brief Command response callback function for @ref sd_ble_gap_appearance_set BLE command. + * + * Callback for decoding the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_appearance_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gap_appearance_set_rsp_dec(p_buffer, length, &result_code); + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_appearance_set +#define _sd_ble_gap_appearance_set sd_ble_gap_appearance_set +#endif +uint32_t _sd_ble_gap_appearance_set(uint16_t appearance) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_appearance_set_req_enc(appearance, + &(p_buffer[1]), + &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_appearance_set_rsp_dec); +} + + +/**@brief Command response callback function for @ref sd_ble_gap_ppcp_set BLE command. + * + * Callback for decoding the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_ppcp_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gap_ppcp_set_rsp_dec(p_buffer, length, &result_code); + + APP_ERROR_CHECK(err_code); + + + return result_code; +} + +#ifndef _sd_ble_gap_ppcp_set +#define _sd_ble_gap_ppcp_set sd_ble_gap_ppcp_set +#endif +uint32_t _sd_ble_gap_ppcp_set(ble_gap_conn_params_t const * const p_conn_params) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_ppcp_set_req_enc(p_conn_params, + &(p_buffer[1]), + &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_ppcp_set_rsp_dec); +} + + +/**@brief Command response callback function for @ref sd_ble_gap_adv_data_set BLE command. + * + * Callback for decoding the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +#if NRF_SD_BLE_API_VERSION <= 5 +static uint32_t gap_adv_data_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gap_adv_data_set_rsp_dec(p_buffer, length, &result_code); + + APP_ERROR_CHECK(err_code); + + return result_code; +} +#ifndef _sd_ble_gap_adv_data_set +#define _sd_ble_gap_adv_data_set sd_ble_gap_adv_data_set +#endif +uint32_t _sd_ble_gap_adv_data_set(uint8_t const * const p_data, + uint8_t dlen, + uint8_t const * const p_sr_data, + uint8_t srdlen) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_adv_data_set_req_enc(p_data, + dlen, + p_sr_data, + srdlen, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_adv_data_set_rsp_dec); +} +#endif + +/**@brief Command response callback function for @ref sd_ble_gap_conn_param_update BLE command. + * + * Callback for decoding the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_conn_param_update_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gap_conn_param_update_rsp_dec(p_buffer, length, &result_code); + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_conn_param_update +#define _sd_ble_gap_conn_param_update sd_ble_gap_conn_param_update +#endif +uint32_t _sd_ble_gap_conn_param_update(uint16_t conn_handle, + ble_gap_conn_params_t const * const p_conn_params) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_conn_param_update_req_enc(conn_handle, + p_conn_params, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_conn_param_update_rsp_dec); +} + + +/**@brief Command response callback function for @ref sd_ble_gap_disconnect BLE command. + * + * Callback for decoding the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_disconnect_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gap_disconnect_rsp_dec(p_buffer, length, &result_code); + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_disconnect +#define _sd_ble_gap_disconnect sd_ble_gap_disconnect +#endif +uint32_t _sd_ble_gap_disconnect(uint16_t conn_handle, uint8_t hci_status_code) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_disconnect_req_enc(conn_handle, + hci_status_code, + &(p_buffer[1]), + &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_disconnect_rsp_dec); +} + + +/**@brief Command response callback function for @ref sd_ble_gap_sec_info_reply BLE command. + * + * Callback for decoding the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_sec_info_reply_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gap_sec_info_reply_rsp_dec(p_buffer, length, &result_code); + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_sec_info_reply +#define _sd_ble_gap_sec_info_reply sd_ble_gap_sec_info_reply +#endif +uint32_t _sd_ble_gap_sec_info_reply(uint16_t conn_handle, + ble_gap_enc_info_t const * p_enc_info, + ble_gap_irk_t const * p_id_info, + ble_gap_sign_info_t const * p_sign_info) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_sec_info_reply_req_enc(conn_handle, + p_enc_info, + p_id_info, + p_sign_info, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_sec_info_reply_rsp_dec); +} + + +/**@brief Command response callback function for @ref sd_ble_gap_sec_params_reply BLE command. + * + * Callback for decoding the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_sec_params_reply_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + uint32_t err_code = ble_gap_sec_params_reply_rsp_dec(p_buffer, length, + m_output_params.gap_sec_params_reply_out_params.p_sec_keyset, &result_code); + APP_ERROR_CHECK(err_code); + + // If soft device returned error free security context + if (result_code) + { + err_code = app_ble_gap_sec_context_destroy(m_output_params.gap_sec_params_reply_out_params.conn_handle); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + } + + return result_code; +} + +#ifndef _sd_ble_gap_sec_params_reply +#define _sd_ble_gap_sec_params_reply sd_ble_gap_sec_params_reply +#endif +uint32_t _sd_ble_gap_sec_params_reply(uint16_t conn_handle, + uint8_t sec_status, + ble_gap_sec_params_t const * p_sec_params, + ble_gap_sec_keyset_t const * p_sec_keyset) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + uint32_t sec_tab_index = 0; + uint32_t err_code = NRF_SUCCESS; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + m_output_params.gap_sec_params_reply_out_params.p_sec_keyset = p_sec_keyset; + m_output_params.gap_sec_params_reply_out_params.conn_handle = conn_handle; + + // First allocate security context for serialization + if (p_sec_keyset) + { + err_code = app_ble_gap_sec_context_create(conn_handle, &sec_tab_index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + memcpy(&(m_app_keys_table[sec_tab_index].keyset), p_sec_keyset, sizeof(ble_gap_sec_keyset_t)); + } + + err_code = ble_gap_sec_params_reply_req_enc(conn_handle, + sec_status, + p_sec_params, + p_sec_keyset, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_sec_params_reply_rsp_dec); +} + + +/**@brief Command response callback function for @ref sd_ble_gap_ppcp_get BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_ppcp_get_reply_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_ppcp_get_rsp_dec( + p_buffer, + length, + m_output_params.gap_ppcp_get_out_params. + p_conn_params, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_ppcp_get +#define _sd_ble_gap_ppcp_get sd_ble_gap_ppcp_get +#endif +uint32_t _sd_ble_gap_ppcp_get(ble_gap_conn_params_t * const p_conn_params) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + m_output_params.gap_ppcp_get_out_params.p_conn_params = p_conn_params; + + const uint32_t err_code = ble_gap_ppcp_get_req_enc(p_conn_params, + &(p_buffer[1]), + &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_ppcp_get_reply_rsp_dec); +} + + +/**@brief Command response callback function for @ref sd_ble_gap_adv_stop BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_adv_stop_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_adv_stop_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_adv_stop +#define _sd_ble_gap_adv_stop sd_ble_gap_adv_stop +#endif +uint32_t _sd_ble_gap_adv_stop( +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t adv_handle +#else + void +#endif + ) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_adv_stop_req_enc( +#if NRF_SD_BLE_API_VERSION > 5 + adv_handle, +#endif + &(p_buffer[1]), + &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_adv_stop_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_auth_key_reply BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_auth_key_reply_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_auth_key_reply_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + + +#ifndef _sd_ble_gap_auth_key_reply +#define _sd_ble_gap_auth_key_reply sd_ble_gap_auth_key_reply +#endif +uint32_t _sd_ble_gap_auth_key_reply(uint16_t conn_handle, + uint8_t key_type, + uint8_t const * const key) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_auth_key_reply_req_enc(conn_handle, key_type, key, + &(p_buffer[1]), &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_auth_key_reply_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_authenticate BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_authenticate_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_authenticate_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gap_authenticate +#define _sd_ble_gap_authenticate sd_ble_gap_authenticate +#endif +uint32_t _sd_ble_gap_authenticate(uint16_t conn_handle, + ble_gap_sec_params_t const * const p_sec_params) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_authenticate_req_enc(conn_handle, p_sec_params, + &(p_buffer[1]), &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_authenticate_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_conn_sec_get BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_conn_sec_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_conn_sec_get_rsp_dec( + p_buffer, + length, + (ble_gap_conn_sec_t * *)&mp_out_params[0 + ], + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gap_conn_sec_get +#define _sd_ble_gap_conn_sec_get sd_ble_gap_conn_sec_get +#endif +uint32_t _sd_ble_gap_conn_sec_get(uint16_t conn_handle, ble_gap_conn_sec_t * const p_conn_sec) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + mp_out_params[0] = p_conn_sec; + + const uint32_t err_code = ble_gap_conn_sec_get_req_enc(conn_handle, p_conn_sec, + &(p_buffer[1]), &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_conn_sec_get_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_rssi_start BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_rssi_start_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_rssi_start_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gap_rssi_start +#define _sd_ble_gap_rssi_start sd_ble_gap_rssi_start +#endif +uint32_t _sd_ble_gap_rssi_start(uint16_t conn_handle, uint8_t threshold_dbm, uint8_t skip_count) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_rssi_start_req_enc(conn_handle, + threshold_dbm, + skip_count, + &(p_buffer[1]), &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_rssi_start_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_rssi_stop BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_rssi_stop_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_rssi_stop_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gap_rssi_stop +#define _sd_ble_gap_rssi_stop sd_ble_gap_rssi_stop +#endif +uint32_t _sd_ble_gap_rssi_stop(uint16_t conn_handle) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_rssi_stop_req_enc(conn_handle, + &(p_buffer[1]), &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_rssi_stop_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_tx_power_set BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_tx_power_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_tx_power_set_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gap_tx_power_set +#define _sd_ble_gap_tx_power_set sd_ble_gap_tx_power_set +#endif +uint32_t _sd_ble_gap_tx_power_set( +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t role, uint16_t handle, +#endif + int8_t tx_power) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); +#if NRF_SD_BLE_API_VERSION > 5 + const uint32_t err_code = ble_gap_tx_power_set_req_enc(role, handle, tx_power, + &(p_buffer[1]), &buffer_length); +#else + const uint32_t err_code = ble_gap_tx_power_set_req_enc(tx_power, + &(p_buffer[1]), &buffer_length); +#endif + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_tx_power_set_rsp_dec); +} + +#ifndef S112 +/**@brief Command response callback function for @ref sd_ble_gap_scan_stop BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_scan_stop_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_scan_stop_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gap_scan_stop +#define _sd_ble_gap_scan_stop sd_ble_gap_scan_stop +#endif +uint32_t _sd_ble_gap_scan_stop(void) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_scan_stop_req_enc(&(p_buffer[1]), + &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_scan_stop_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_connect BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_connect_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_connect_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gap_connect +#define _sd_ble_gap_connect sd_ble_gap_connect +#endif +uint32_t _sd_ble_gap_connect(ble_gap_addr_t const * const p_addr, + ble_gap_scan_params_t const * const p_scan_params, + ble_gap_conn_params_t const * const p_conn_params +#if NRF_SD_BLE_API_VERSION >= 4 + ,uint8_t conn_cfg_tag +#endif + ) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_connect_req_enc(p_addr, + p_scan_params, + p_conn_params, +#if NRF_SD_BLE_API_VERSION >= 4 + conn_cfg_tag, +#endif + &(p_buffer[1]), + &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_connect_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_connect_cancel BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_connect_cancel_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_connect_cancel_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gap_connect_cancel +#define _sd_ble_gap_connect_cancel sd_ble_gap_connect_cancel +#endif +uint32_t _sd_ble_gap_connect_cancel(void) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_connect_cancel_req_enc(&(p_buffer[1]), + &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_connect_cancel_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_scan_start BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_scan_start_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_scan_start_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_scan_start +#define _sd_ble_gap_scan_start sd_ble_gap_scan_start +#endif +uint32_t _sd_ble_gap_scan_start(ble_gap_scan_params_t const * const p_scan_params +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 + ,ble_data_t const * p_adv_report_buffer +#endif + ) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + uint32_t err_code; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 + if (p_adv_report_buffer) + { + err_code = app_ble_gap_scan_data_set(p_adv_report_buffer); + APP_ERROR_CHECK(err_code); + } +#endif + err_code = ble_gap_scan_start_req_enc(p_scan_params, +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 + p_adv_report_buffer, +#endif + &(p_buffer[1]), + &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_scan_start_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_encrypt BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_encrypt_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_encrypt_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_encrypt +#define _sd_ble_gap_encrypt sd_ble_gap_encrypt +#endif +uint32_t _sd_ble_gap_encrypt( uint16_t conn_handle, + ble_gap_master_id_t const * p_master_id, + ble_gap_enc_info_t const * p_enc_info) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_encrypt_req_enc( conn_handle, p_master_id, p_enc_info, &(p_buffer[1]), &buffer_length ); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_encrypt_rsp_dec); +} +#endif //!S112 + +/**@brief Command response callback function for @ref sd_ble_gap_rssi_get BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_rssi_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_rssi_get_rsp_dec(p_buffer, + length, + (int8_t *) mp_out_params[0], +#if NRF_SD_BLE_API_VERSION > 5 + (uint8_t *) mp_out_params[1], +#endif + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_rssi_get +#define _sd_ble_gap_rssi_get sd_ble_gap_rssi_get +#endif +uint32_t _sd_ble_gap_rssi_get(uint16_t conn_handle, + int8_t * p_rssi +#if NRF_SD_BLE_API_VERSION > 5 + ,uint8_t * p_ch_index +#endif +) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + mp_out_params[0] = p_rssi; + +#if NRF_SD_BLE_API_VERSION > 5 + mp_out_params[1] = p_ch_index; + const uint32_t err_code = ble_gap_rssi_get_req_enc(conn_handle, p_rssi, p_ch_index, &(p_buffer[1]), &buffer_length); +#else + const uint32_t err_code = ble_gap_rssi_get_req_enc(conn_handle, p_rssi, &(p_buffer[1]), &buffer_length); +#endif + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_rssi_get_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_keypress_notify BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_keypress_notify_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_keypress_notify_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_keypress_notify +#define _sd_ble_gap_keypress_notify sd_ble_gap_keypress_notify +#endif +uint32_t _sd_ble_gap_keypress_notify( uint16_t conn_handle, uint8_t kp_not) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_keypress_notify_req_enc( conn_handle, kp_not, &p_buffer[1], &buffer_length ); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_keypress_notify_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_lesc_dhkey_reply BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_lesc_dhkey_reply_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_lesc_dhkey_reply_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_lesc_dhkey_reply +#define _sd_ble_gap_lesc_dhkey_reply sd_ble_gap_lesc_dhkey_reply +#endif +uint32_t _sd_ble_gap_lesc_dhkey_reply( uint16_t conn_handle, ble_gap_lesc_dhkey_t const *p_dhkey) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_lesc_dhkey_reply_req_enc( conn_handle, p_dhkey, &(p_buffer[1]), &buffer_length ); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_lesc_dhkey_reply_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_lesc_oob_data_set BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_lesc_oob_data_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_lesc_oob_data_set_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_lesc_oob_data_set +#define _sd_ble_gap_lesc_oob_data_set sd_ble_gap_lesc_oob_data_set +#endif +uint32_t _sd_ble_gap_lesc_oob_data_set(uint16_t conn_handle, + ble_gap_lesc_oob_data_t const *p_oobd_own, + ble_gap_lesc_oob_data_t const *p_oobd_peer) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_lesc_oob_data_set_req_enc(conn_handle, p_oobd_own, p_oobd_peer, + &(p_buffer[1]), &buffer_length ); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_lesc_oob_data_set_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_lesc_oob_data_get BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_lesc_oob_data_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_lesc_oob_data_get_rsp_dec(p_buffer, + length, + (ble_gap_lesc_oob_data_t **) &mp_out_params[0], + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_lesc_oob_data_get +#define _sd_ble_gap_lesc_oob_data_get sd_ble_gap_lesc_oob_data_get +#endif +uint32_t _sd_ble_gap_lesc_oob_data_get(uint16_t conn_handle, + ble_gap_lesc_p256_pk_t const *p_pk_own, + ble_gap_lesc_oob_data_t *p_oobd_own) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + mp_out_params[0] = p_oobd_own; + const uint32_t err_code = ble_gap_lesc_oob_data_get_req_enc(conn_handle, p_pk_own, p_oobd_own, + &(p_buffer[1]), &buffer_length ); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_lesc_oob_data_get_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_addr_get BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_addr_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_addr_get_rsp_dec(p_buffer, + length, + (ble_gap_addr_t *)mp_out_params[0], + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + return result_code; +} + +#ifndef _sd_ble_gap_addr_get +#define _sd_ble_gap_addr_get sd_ble_gap_addr_get +#endif +uint32_t _sd_ble_gap_addr_get(ble_gap_addr_t * const p_addr) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + mp_out_params[0] = p_addr; + + const uint32_t err_code = ble_gap_addr_get_req_enc(p_addr, + &(p_buffer[1]), + &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_addr_get_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_addr_set BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_addr_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_addr_set_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + return result_code; +} + +#ifndef _sd_ble_gap_addr_set +#define _sd_ble_gap_addr_set sd_ble_gap_addr_set +#endif +uint32_t _sd_ble_gap_addr_set(ble_gap_addr_t const * const p_addr) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_addr_set_req_enc(p_addr, + &(p_buffer[1]), + &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_addr_set_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_privacy_set BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_privacy_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_privacy_set_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + return result_code; +} + +#ifndef _sd_ble_gap_privacy_set +#define _sd_ble_gap_privacy_set sd_ble_gap_privacy_set +#endif +uint32_t _sd_ble_gap_privacy_set(ble_gap_privacy_params_t const *p_privacy_params) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + + const uint32_t err_code = ble_gap_privacy_set_req_enc(p_privacy_params, + &(p_buffer[1]), &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_privacy_set_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_privacy_get BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_privacy_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_privacy_get_rsp_dec(p_buffer, + length, + (ble_gap_privacy_params_t *)mp_out_params[0], + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + return result_code; +} + +#ifndef _sd_ble_gap_privacy_get +#define _sd_ble_gap_privacy_get sd_ble_gap_privacy_get +#endif +uint32_t _sd_ble_gap_privacy_get(ble_gap_privacy_params_t *p_privacy_params) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + mp_out_params[0] = p_privacy_params; + + const uint32_t err_code = ble_gap_privacy_get_req_enc(p_privacy_params, + &(p_buffer[1]), &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_privacy_get_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_whitelist_set BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_whitelist_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_whitelist_set_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + return result_code; +} + +#ifndef _sd_ble_gap_whitelist_set +#define _sd_ble_gap_whitelist_set sd_ble_gap_whitelist_set +#endif +uint32_t _sd_ble_gap_whitelist_set(ble_gap_addr_t const * const * pp_wl_addrs, uint8_t len) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + + const uint32_t err_code = ble_gap_whitelist_set_req_enc(pp_wl_addrs, len, + &(p_buffer[1]), &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_whitelist_set_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_device_identities_set BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_device_identities_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_device_identities_set_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + return result_code; +} + +#ifndef _sd_ble_gap_device_identities_set +#define _sd_ble_gap_device_identities_set sd_ble_gap_device_identities_set +#endif +uint32_t _sd_ble_gap_device_identities_set(ble_gap_id_key_t const * const * pp_id_keys, ble_gap_irk_t const * const * pp_local_irks, uint8_t len) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + + const uint32_t err_code = ble_gap_device_identities_set_req_enc(pp_id_keys, + pp_local_irks, + len, + &(p_buffer[1]), &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_device_identities_set_rsp_dec); +} + +#if NRF_SD_BLE_API_VERSION >= 4 && !defined(S112) +/**@brief Command response callback function for @ref sd_ble_gap_data_length_update BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_data_length_update_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_data_length_update_rsp_dec(p_buffer, + length, + (ble_gap_data_length_limitation_t *)mp_out_params[0], + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + return result_code; +} + +#ifndef _sd_ble_gap_data_length_update +#define _sd_ble_gap_data_length_update sd_ble_gap_data_length_update +#endif +uint32_t _sd_ble_gap_data_length_update(uint16_t conn_handle, + ble_gap_data_length_params_t const *p_dl_params, + ble_gap_data_length_limitation_t *p_dl_limitation) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + mp_out_params[0] = p_dl_limitation; + + const uint32_t err_code = ble_gap_data_length_update_req_enc(conn_handle, p_dl_params,p_dl_limitation, + &(p_buffer[1]), &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_data_length_update_rsp_dec); +} + +#endif // NRF_SD_BLE_API_VERSION >= 4 && !defined(S112) + +#if NRF_SD_BLE_API_VERSION >= 5 +/**@brief Command response callback function for @ref sd_ble_gap_phy_update BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_phy_update_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + const uint32_t err_code = ble_gap_phy_update_rsp_dec(p_buffer, + length, + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gap_phy_update +#define _sd_ble_gap_phy_update sd_ble_gap_phy_update +#endif +uint32_t _sd_ble_gap_phy_update(uint16_t conn_handle, + ble_gap_phys_t const * const p_gap_phys) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gap_phy_update_req_enc(conn_handle, p_gap_phys, + &(p_buffer[1]), &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_phy_update_rsp_dec); +} +#endif + +#if NRF_SD_BLE_API_VERSION >= 6 +/**@brief Command response callback function for @ref sd_ble_gap_adv_set_configure BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_adv_set_configure_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + uint32_t err_code = ble_gap_adv_set_configure_rsp_dec(p_buffer, + length, + (uint8_t *)mp_out_params[0], + &result_code); + + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + err_code = app_ble_gap_adv_set_register(*(uint8_t *)mp_out_params[0], + (uint8_t *)mp_out_params[1], + (uint8_t *)mp_out_params[2]); + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_adv_set_configure +#define _sd_ble_gap_adv_set_configure sd_ble_gap_adv_set_configure +#endif +uint32_t _sd_ble_gap_adv_set_configure(uint8_t *p_adv_handle, + ble_gap_adv_data_t const *p_adv_data, + ble_gap_adv_params_t const *p_adv_params) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + + mp_out_params[0] = p_adv_handle; + mp_out_params[1] = p_adv_data ? p_adv_data->adv_data.p_data : NULL; + mp_out_params[2] = p_adv_data ? p_adv_data->scan_rsp_data.p_data : NULL; + const uint32_t err_code = ble_gap_adv_set_configure_req_enc(p_adv_handle, p_adv_data, p_adv_params, + &(p_buffer[1]), &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_adv_set_configure_rsp_dec); +} + +#ifndef S112 +/**@brief Command response callback function for @ref sd_ble_gap_qos_channel_survey_start BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_qos_channel_survey_start_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + uint32_t err_code = ble_gap_qos_channel_survey_start_rsp_dec(p_buffer, + length, + &result_code); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_qos_channel_survey_start +#define _sd_ble_gap_qos_channel_survey_start sd_ble_gap_qos_channel_survey_start +#endif +uint32_t _sd_ble_gap_qos_channel_survey_start(uint32_t interval_us) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + + const uint32_t err_code = ble_gap_qos_channel_survey_start_req_enc(interval_us, + &(p_buffer[1]), &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_qos_channel_survey_start_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gap_qos_channel_survey_stop BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gap_qos_channel_survey_stop_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = 0; + + uint32_t err_code = ble_gap_qos_channel_survey_stop_rsp_dec(p_buffer, + length, + &result_code); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gap_qos_channel_survey_stop +#define _sd_ble_gap_qos_channel_survey_stop sd_ble_gap_qos_channel_survey_stop +#endif +uint32_t _sd_ble_gap_qos_channel_survey_stop(void) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + + const uint32_t err_code = ble_gap_qos_channel_survey_stop_req_enc(&(p_buffer[1]), &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gap_qos_channel_survey_stop_rsp_dec); +} +#endif //!S112 +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble_gattc.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble_gattc.c new file mode 100644 index 0000000..7edf6ee --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble_gattc.c @@ -0,0 +1,566 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include <stdint.h> +#include "ble_gattc.h" +#include "ble_gattc_app.h" +#include "ble_serialization.h" +#include "ser_sd_transport.h" +#include "app_error.h" + +static void tx_buf_alloc(uint8_t * * p_data, uint16_t * p_len) +{ + uint32_t err_code; + + do + { + err_code = ser_sd_transport_tx_alloc(p_data, p_len); + } + while (err_code != NRF_SUCCESS); + *p_data[0] = SER_PKT_TYPE_CMD; + *p_len -= 1; +} +/**@brief Command response callback function for @ref sd_ble_gattc_primary_services_discover BLE command. + * + * Callback for decoding the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gattc_primary_services_discover_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gattc_primary_services_discover_rsp_dec(p_buffer, + length, + &result_code); + + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gattc_primary_services_discover +#define _sd_ble_gattc_primary_services_discover sd_ble_gattc_primary_services_discover +#endif +uint32_t _sd_ble_gattc_primary_services_discover(uint16_t conn_handle, + uint16_t start_handle, + ble_uuid_t const * const p_srvc_uuid) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + + const uint32_t err_code = ble_gattc_primary_services_discover_req_enc(conn_handle, + start_handle, + p_srvc_uuid, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gattc_primary_services_discover_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gattc_relationships_discover BLE command. + * + * Callback for decoding the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gattc_relationships_discover_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gattc_relationships_discover_rsp_dec(p_buffer, + length, + &result_code); + + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gattc_relationships_discover +#define _sd_ble_gattc_relationships_discover sd_ble_gattc_relationships_discover +#endif +uint32_t _sd_ble_gattc_relationships_discover(uint16_t conn_handle, + ble_gattc_handle_range_t const * const p_handle_range) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + + const uint32_t err_code = ble_gattc_relationships_discover_req_enc(conn_handle, + p_handle_range, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gattc_relationships_discover_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gattc_characteristics_discover BLE command. + * + * Callback for decoding the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gattc_characteristics_discover_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gattc_characteristics_discover_rsp_dec(p_buffer, + length, + &result_code); + + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gattc_characteristics_discover +#define _sd_ble_gattc_characteristics_discover sd_ble_gattc_characteristics_discover +#endif +uint32_t _sd_ble_gattc_characteristics_discover( + uint16_t conn_handle, + ble_gattc_handle_range_t const * const + p_handle_range) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + + const uint32_t err_code = ble_gattc_characteristics_discover_req_enc(conn_handle, + p_handle_range, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gattc_characteristics_discover_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gattc_descriptors_discover BLE command. + * + * Callback for decoding the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gattc_descriptors_discover_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gattc_descriptors_discover_rsp_dec(p_buffer, length, &result_code); + + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gattc_descriptors_discover +#define _sd_ble_gattc_descriptors_discover sd_ble_gattc_descriptors_discover +#endif +uint32_t _sd_ble_gattc_descriptors_discover(uint16_t conn_handle, + ble_gattc_handle_range_t const * const p_handle_range) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + + const uint32_t err_code = ble_gattc_descriptors_discover_req_enc(conn_handle, + p_handle_range, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gattc_descriptors_discover_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gattc_char_value_by_uuid_read BLE command. + * + * Callback for decoding the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gattc_char_value_by_uuid_read_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gattc_char_value_by_uuid_read_rsp_dec(p_buffer, + length, + &result_code); + + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gattc_char_value_by_uuid_read +#define _sd_ble_gattc_char_value_by_uuid_read sd_ble_gattc_char_value_by_uuid_read +#endif +uint32_t _sd_ble_gattc_char_value_by_uuid_read(uint16_t conn_handle, + ble_uuid_t const * const p_uuid, + ble_gattc_handle_range_t const * const p_handle_range) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + + const uint32_t err_code = ble_gattc_char_value_by_uuid_read_req_enc(conn_handle, + p_uuid, + p_handle_range, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gattc_char_value_by_uuid_read_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gattc_read BLE command. + * + * Callback for decoding the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gattc_read_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gattc_read_rsp_dec(p_buffer, length, &result_code); + + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gattc_read +#define _sd_ble_gattc_read sd_ble_gattc_read +#endif +uint32_t _sd_ble_gattc_read(uint16_t conn_handle, + uint16_t handle, + uint16_t offset) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + + const uint32_t err_code = ble_gattc_read_req_enc(conn_handle, + handle, + offset, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gattc_read_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gattc_char_values_read BLE command. + * + * Callback for decoding the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gattc_char_values_read_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gattc_char_values_read_rsp_dec(p_buffer, length, &result_code); + + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gattc_char_values_read +#define _sd_ble_gattc_char_values_read sd_ble_gattc_char_values_read +#endif +uint32_t _sd_ble_gattc_char_values_read(uint16_t conn_handle, + uint16_t const * const p_handles, + uint16_t handle_count) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + + const uint32_t err_code = ble_gattc_char_values_read_req_enc(conn_handle, + p_handles, + handle_count, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gattc_char_values_read_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gattc_write BLE command. + * + * Callback for decoding the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gattc_write_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gattc_write_rsp_dec(p_buffer, length, &result_code); + + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gattc_write +#define _sd_ble_gattc_write sd_ble_gattc_write +#endif +uint32_t _sd_ble_gattc_write(uint16_t conn_handle, + ble_gattc_write_params_t const * const p_write_params) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + + const uint32_t err_code = ble_gattc_write_req_enc(conn_handle, + p_write_params, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gattc_write_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gattc_hv_confirm BLE command. + * + * Callback for decoding the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gattc_hv_confirm_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gattc_hv_confirm_rsp_dec(p_buffer, length, &result_code); + + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gattc_hv_confirm +#define _sd_ble_gattc_hv_confirm sd_ble_gattc_hv_confirm +#endif +uint32_t _sd_ble_gattc_hv_confirm(uint16_t conn_handle, + uint16_t handle) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + + const uint32_t err_code = ble_gattc_hv_confirm_req_enc(conn_handle, + handle, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gattc_hv_confirm_rsp_dec); +} + + +/**@brief Command response callback function for @ref sd_ble_gattc_info_discover BLE command. + * + * Callback for decoding the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gattc_attr_info_discover_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gattc_attr_info_discover_rsp_dec(p_buffer, length, &result_code); + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gattc_attr_info_discover +#define _sd_ble_gattc_attr_info_discover sd_ble_gattc_attr_info_discover +#endif +uint32_t _sd_ble_gattc_attr_info_discover(uint16_t conn_handle, + ble_gattc_handle_range_t const * const p_handle_range) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + + const uint32_t err_code = ble_gattc_attr_info_discover_req_enc(conn_handle, + p_handle_range, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gattc_attr_info_discover_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gattc_write BLE command. + * + * Callback for decoding the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gattc_exchange_mtu_request_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gattc_exchange_mtu_request_rsp_dec(p_buffer, length, &result_code); + + APP_ERROR_CHECK(err_code); + return result_code; +} + +#ifndef _sd_ble_gattc_exchange_mtu_request +#define _sd_ble_gattc_exchange_mtu_request sd_ble_gattc_exchange_mtu_request +#endif +uint32_t _sd_ble_gattc_exchange_mtu_request(uint16_t conn_handle, + uint16_t client_rx_mtu) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + + const uint32_t err_code = ble_gattc_exchange_mtu_request_req_enc(conn_handle, + client_rx_mtu, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gattc_exchange_mtu_request_rsp_dec); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble_gatts.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble_gatts.c new file mode 100644 index 0000000..e4b3002 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble_gatts.c @@ -0,0 +1,773 @@ +/** + * Copyright (c) 2013 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include "ble_gatts.h" +#include <stdint.h> +#include "ble_serialization.h" +#include "ser_sd_transport.h" +#include "ble_gatts_app.h" +#include "app_error.h" + + +//Pointer for sd calls output params +static void * mp_out_params[3]; + +static void tx_buf_alloc(uint8_t * * p_data, uint16_t * p_len) +{ + uint32_t err_code; + + do + { + err_code = ser_sd_transport_tx_alloc(p_data, p_len); + } + while (err_code != NRF_SUCCESS); + *p_data[0] = SER_PKT_TYPE_CMD; + *p_len -= 1; +} + +/**@brief Command response callback function for @ref sd_ble_gatts_sys_attr_set BLE command. + * + * Callback for decoding the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gatts_sys_attr_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gatts_sys_attr_set_rsp_dec(p_buffer, length, &result_code); + + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gatts_sys_attr_set +#define _sd_ble_gatts_sys_attr_set sd_ble_gatts_sys_attr_set +#endif +uint32_t _sd_ble_gatts_sys_attr_set(uint16_t conn_handle, + uint8_t const * const p_sys_attr_data, + uint16_t len, + uint32_t flags) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gatts_sys_attr_set_req_enc(conn_handle, + p_sys_attr_data, + len, + flags, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gatts_sys_attr_set_rsp_dec); +} + + +/**@brief Command response callback function for @ref sd_ble_gatts_hvx BLE command. + * + * Callback for decoding the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gatts_hvx_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gatts_hvx_rsp_dec(p_buffer, length, &result_code, + (uint16_t * *)&mp_out_params[0]); + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gatts_hvx +#define _sd_ble_gatts_hvx sd_ble_gatts_hvx +#endif +uint32_t _sd_ble_gatts_hvx(uint16_t conn_handle, ble_gatts_hvx_params_t const * const p_hvx_params) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + mp_out_params[0] = (p_hvx_params) ? p_hvx_params->p_len : NULL; + + const uint32_t err_code = ble_gatts_hvx_req_enc(conn_handle, + p_hvx_params, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gatts_hvx_rsp_dec); +} + + +/**@brief Command response callback function for @ref sd_ble_gatts_service_add BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gatts_service_add_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = + ble_gatts_service_add_rsp_dec(p_buffer, + length, + (uint16_t *)mp_out_params[0], + &result_code); + + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gatts_service_add +#define _sd_ble_gatts_service_add sd_ble_gatts_service_add +#endif +uint32_t _sd_ble_gatts_service_add(uint8_t type, + ble_uuid_t const * const p_uuid, + uint16_t * const p_handle) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + mp_out_params[0] = p_handle; + + const uint32_t err_code = ble_gatts_service_add_req_enc(type, + p_uuid, + p_handle, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gatts_service_add_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gatts_service_add BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gatts_service_changed_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = NRF_SUCCESS; + + const uint32_t err_code = ble_gatts_service_changed_rsp_dec(p_buffer, + length, + &result_code); + + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gatts_service_changed +#define _sd_ble_gatts_service_changed sd_ble_gatts_service_changed +#endif +uint32_t _sd_ble_gatts_service_changed(uint16_t conn_handle, + uint16_t start_handle, + uint16_t end_handle) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_gatts_service_changed_req_enc(conn_handle, + start_handle, + end_handle, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gatts_service_changed_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gatts_include_add BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gatts_include_add_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = NRF_SUCCESS; + + const uint32_t err_code = + ble_gatts_include_add_rsp_dec(p_buffer, + length, + (uint16_t *) mp_out_params[0], + &result_code); + + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gatts_include_add +#define _sd_ble_gatts_include_add sd_ble_gatts_include_add +#endif +uint32_t _sd_ble_gatts_include_add(uint16_t service_handle, + uint16_t inc_serv_handle, + uint16_t * const p_include_handle) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + mp_out_params[0] = p_include_handle; + + const uint32_t err_code = ble_gatts_include_add_req_enc(service_handle, + inc_serv_handle, + p_include_handle, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gatts_include_add_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gatts_characteristic_add BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gatts_characteristic_add_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gatts_characteristic_add_rsp_dec( + p_buffer, + length, + (uint16_t * *)&mp_out_params[0], + &result_code); + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gatts_characteristic_add +#define _sd_ble_gatts_characteristic_add sd_ble_gatts_characteristic_add +#endif +uint32_t _sd_ble_gatts_characteristic_add(uint16_t service_handle, + ble_gatts_char_md_t const * const p_char_md, + ble_gatts_attr_t const * const p_attr_char_value, + ble_gatts_char_handles_t * const p_handles) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + mp_out_params[0] = p_handles; + + const uint32_t err_code = ble_gatts_characteristic_add_req_enc(service_handle, + p_char_md, + p_attr_char_value, + p_handles, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gatts_characteristic_add_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gatts_descriptor_add BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gatts_descriptor_add_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = NRF_SUCCESS; + + const uint32_t err_code = + ble_gatts_descriptor_add_rsp_dec(p_buffer, + length, + (uint16_t *) mp_out_params[0], + &result_code); + + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gatts_descriptor_add +#define _sd_ble_gatts_descriptor_add sd_ble_gatts_descriptor_add +#endif +uint32_t _sd_ble_gatts_descriptor_add(uint16_t char_handle, + ble_gatts_attr_t const * const p_attr, + uint16_t * const p_handle) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + mp_out_params[0] = p_handle; + + const uint32_t err_code = ble_gatts_descriptor_add_req_enc(char_handle, + p_attr, + p_handle, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gatts_descriptor_add_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gatts_rw_authorize_reply BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gatts_rw_authorize_reply_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code = NRF_SUCCESS; + + const uint32_t err_code = ble_gatts_rw_authorize_reply_rsp_dec(p_buffer, + length, + &result_code); + + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gatts_rw_authorize_reply +#define _sd_ble_gatts_rw_authorize_reply sd_ble_gatts_rw_authorize_reply +#endif +uint32_t _sd_ble_gatts_rw_authorize_reply( + uint16_t conn_handle, + ble_gatts_rw_authorize_reply_params_t const * const + p_rw_authorize_reply_params) +{ + + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + + const uint32_t err_code = ble_gatts_rw_authorize_reply_req_enc(conn_handle, + p_rw_authorize_reply_params, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gatts_rw_authorize_reply_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gatts_value_get BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gatts_value_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gatts_value_get_rsp_dec(p_buffer, + length, + (ble_gatts_value_t *)mp_out_params[0], + &result_code); + + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_gatts_value_get +#define _sd_ble_gatts_value_get sd_ble_gatts_value_get +#endif +uint32_t _sd_ble_gatts_value_get(uint16_t conn_handle, + uint16_t handle, + ble_gatts_value_t * p_value) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + mp_out_params[0] = p_value; + + const uint32_t err_code = ble_gatts_value_get_req_enc(conn_handle, + handle, + p_value, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gatts_value_get_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gatts_value_set BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gatts_value_set_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gatts_value_set_rsp_dec( + p_buffer, + length, + (ble_gatts_value_t *)mp_out_params[0], + &result_code); + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gatts_value_set +#define _sd_ble_gatts_value_set sd_ble_gatts_value_set +#endif +uint32_t _sd_ble_gatts_value_set(uint16_t conn_handle, + uint16_t handle, + ble_gatts_value_t * p_value) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + mp_out_params[0] = p_value; + + const uint32_t err_code = ble_gatts_value_set_req_enc(conn_handle, + handle, + p_value, + &(p_buffer[1]), + &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gatts_value_set_rsp_dec); +} + + +/**@brief Command response callback function for @ref sd_ble_gatts_sys_attr_get BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gatts_sys_attr_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gatts_sys_attr_get_rsp_dec( + p_buffer, + length, + (uint8_t * *) &mp_out_params[0], + (uint16_t * *) &mp_out_params[1], + &result_code); + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gatts_sys_attr_get +#define _sd_ble_gatts_sys_attr_get sd_ble_gatts_sys_attr_get +#endif +uint32_t _sd_ble_gatts_sys_attr_get(uint16_t conn_handle, + uint8_t * const p_sys_attr_data, + uint16_t * const p_len, + uint32_t flags) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + mp_out_params[0] = p_sys_attr_data; + mp_out_params[1] = p_len; + + const uint32_t err_code = ble_gatts_sys_attr_get_req_enc(conn_handle, + p_sys_attr_data, + p_len, + flags, + &(p_buffer[1]), + &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gatts_sys_attr_get_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gatts_attr_get BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gatts_attr_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gatts_attr_get_rsp_dec( + p_buffer, + length, + (ble_uuid_t **)&mp_out_params[0], + (ble_gatts_attr_md_t **)&mp_out_params[1], + &result_code); + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gatts_attr_get +#define _sd_ble_gatts_attr_get sd_ble_gatts_attr_get +#endif +uint32_t _sd_ble_gatts_attr_get(uint16_t handle, + ble_uuid_t * p_uuid, + ble_gatts_attr_md_t * p_md) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + mp_out_params[0] = p_uuid; + mp_out_params[1] = p_md; + + const uint32_t err_code = ble_gatts_attr_get_req_enc(handle, + p_uuid, + p_md, + &(p_buffer[1]), + &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gatts_attr_get_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gatts_initial_user_handle_get BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gatts_initial_user_handle_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gatts_initial_user_handle_get_rsp_dec( + p_buffer, + length, + (uint16_t **)&mp_out_params[0], + &result_code); + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gatts_initial_user_handle_get +#define _sd_ble_gatts_initial_user_handle_get sd_ble_gatts_initial_user_handle_get +#endif +uint32_t _sd_ble_gatts_initial_user_handle_get(uint16_t * p_handle) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + mp_out_params[0] = p_handle; + + const uint32_t err_code = ble_gatts_initial_user_handle_get_req_enc(p_handle, + &(p_buffer[1]), + &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gatts_initial_user_handle_get_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ble_gatts_exchange_mtu_reply BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t gatts_exchange_mtu_reply_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_gatts_exchange_mtu_reply_rsp_dec( + p_buffer, + length, + &result_code); + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_gatts_exchange_mtu_reply +#define _sd_ble_gatts_exchange_mtu_reply sd_ble_gatts_exchange_mtu_reply +#endif +uint32_t _sd_ble_gatts_exchange_mtu_reply(uint16_t conn_handle, uint16_t server_rx_mtu) +{ + + + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + + const uint32_t err_code = ble_gatts_exchange_mtu_reply_req_enc(conn_handle, + server_rx_mtu, + &(p_buffer[1]), + &buffer_length); + + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + gatts_exchange_mtu_reply_rsp_dec); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble_l2cap.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble_l2cap.c new file mode 100644 index 0000000..41aa555 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_ble_l2cap.c @@ -0,0 +1,453 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include "ble_gap.h" +#include <stdint.h> +#include "ble_serialization.h" +#include "ser_sd_transport.h" +#include "ble_l2cap_app.h" +#include "app_error.h" + +#if defined(NRF_SD_BLE_API_VERSION) && ((NRF_SD_BLE_API_VERSION < 4) || (NRF_SD_BLE_API_VERSION >=5)) +static void tx_buf_alloc(uint8_t * * p_data, uint16_t * p_len) +{ + uint32_t err_code; + + do + { + err_code = ser_sd_transport_tx_alloc(p_data, p_len); + } + while (err_code != NRF_SUCCESS); + *p_data[0] = SER_PKT_TYPE_CMD; + *p_len -= 1; +} + +#endif +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +/**@brief Command response callback function for @ref ble_l2cap_cid_register_req_enc BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t l2cap_cid_register_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = + ble_l2cap_cid_register_rsp_dec(p_buffer, + length, + &result_code); + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +#ifndef _sd_ble_l2cap_cid_register +#define _sd_ble_l2cap_cid_register sd_ble_l2cap_cid_register +#endif +uint32_t _sd_ble_l2cap_cid_register(uint16_t cid) +{ + + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_l2cap_cid_register_req_enc(cid, + &(p_buffer[1]), + &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + l2cap_cid_register_rsp_dec); +} + +/**@brief Command response callback function for @ref ble_l2cap_cid_unregister_req_enc BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t l2cap_cid_unregister_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = + ble_l2cap_cid_unregister_rsp_dec(p_buffer, + length, + &result_code); + + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_l2cap_cid_unregister +#define _sd_ble_l2cap_cid_unregister sd_ble_l2cap_cid_unregister +#endif +uint32_t _sd_ble_l2cap_cid_unregister(uint16_t cid) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_l2cap_cid_unregister_req_enc(cid, + &(p_buffer[1]), + &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + l2cap_cid_unregister_rsp_dec); +} + +/**@brief Command response callback function for @ref ble_l2cap_tx_req_enc BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t l2cap_tx_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = + ble_l2cap_tx_rsp_dec(p_buffer, + length, + &result_code); + + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_l2cap_tx +#define _sd_ble_l2cap_tx sd_ble_l2cap_tx +#endif +uint32_t _sd_ble_l2cap_tx(uint16_t conn_handle, + ble_l2cap_header_t const * const p_header, + uint8_t const * const p_data) +{ + + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_l2cap_tx_req_enc(conn_handle, p_header, p_data, + &(p_buffer[1]), + &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + l2cap_tx_rsp_dec); +} + +#endif + +#if NRF_SD_BLE_API_VERSION >= 5 +static void * mp_out_params[1]; +/**@brief Command response callback function for @ref ble_l2cap_ch_setup_req_enc BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t l2cap_ch_setup_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = + ble_l2cap_ch_setup_rsp_dec(p_buffer, + length, + (uint16_t *)mp_out_params[0], + &result_code); + + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_l2cap_ch_setup +#define _sd_ble_l2cap_ch_setup sd_ble_l2cap_ch_setup +#endif +uint32_t _sd_ble_l2cap_ch_setup(uint16_t conn_handle, + uint16_t * p_local_cid, + ble_l2cap_ch_setup_params_t const *p_params) +{ + + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + mp_out_params[0] = p_local_cid; + const uint32_t err_code = ble_l2cap_ch_setup_req_enc(conn_handle, p_local_cid, p_params, + &(p_buffer[1]), + &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + l2cap_ch_setup_rsp_dec); +} + +/**@brief Command response callback function for @ref ble_l2cap_ch_release_req_enc BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t l2cap_ch_release_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = + ble_l2cap_ch_release_rsp_dec(p_buffer, + length, + &result_code); + + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_l2cap_ch_release +#define _sd_ble_l2cap_ch_release sd_ble_l2cap_ch_release +#endif +uint32_t _sd_ble_l2cap_ch_release(uint16_t conn_handle, + uint16_t local_cid) +{ + + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_l2cap_ch_release_req_enc(conn_handle, local_cid, + &(p_buffer[1]), + &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + l2cap_ch_release_rsp_dec); +} + + +/**@brief Command response callback function for @ref ble_l2cap_ch_rx_req_enc BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t l2cap_ch_rx_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = + ble_l2cap_ch_rx_rsp_dec(p_buffer, + length, + &result_code); + + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_l2cap_ch_rx +#define _sd_ble_l2cap_ch_rx sd_ble_l2cap_ch_rx +#endif +uint32_t _sd_ble_l2cap_ch_rx(uint16_t conn_handle, uint16_t local_cid, ble_data_t const *p_sdu_buf) +{ + + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_l2cap_ch_rx_req_enc(conn_handle, local_cid, p_sdu_buf, + &(p_buffer[1]), + &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + l2cap_ch_rx_rsp_dec); +} + + +/**@brief Command response callback function for @ref ble_l2cap_ch_tx_req_enc BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t l2cap_ch_tx_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = + ble_l2cap_ch_tx_rsp_dec(p_buffer, + length, + &result_code); + + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_l2cap_ch_tx +#define _sd_ble_l2cap_ch_tx sd_ble_l2cap_ch_tx +#endif +uint32_t _sd_ble_l2cap_ch_tx(uint16_t conn_handle, uint16_t local_cid, ble_data_t const *p_sdu_buf) +{ + + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = ble_l2cap_ch_tx_req_enc(conn_handle, local_cid, p_sdu_buf, + &(p_buffer[1]), + &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + l2cap_ch_tx_rsp_dec); +} + +/**@brief Command response callback function for @ref ble_l2cap_ch_flow_control_req_enc BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ +static uint32_t l2cap_ch_flow_control_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = + ble_l2cap_ch_flow_control_rsp_dec(p_buffer, + length, + (uint16_t *)mp_out_params[0], + &result_code); + + APP_ERROR_CHECK(err_code); + + + + return result_code; +} + +#ifndef _sd_ble_l2cap_ch_flow_control +#define _sd_ble_l2cap_ch_flow_control sd_ble_l2cap_ch_flow_control +#endif +uint32_t _sd_ble_l2cap_ch_flow_control(uint16_t conn_handle, + uint16_t local_cid, + uint16_t credits, + uint16_t *p_credits) +{ + + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + mp_out_params[0] = p_credits; + const uint32_t err_code = ble_l2cap_ch_flow_control_req_enc(conn_handle, local_cid, credits, p_credits, + &(p_buffer[1]), + &buffer_length); + //@note: Should never fail. + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + l2cap_ch_flow_control_rsp_dec); +} +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_nrf_soc.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_nrf_soc.c new file mode 100644 index 0000000..0b0158e --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/middleware/app_mw_nrf_soc.c @@ -0,0 +1,171 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include "nrf_soc.h" +#include <stdint.h> +#include <string.h> +#include "ser_sd_transport.h" +#include "nrf_soc_app.h" +#include "nrf_error_soc.h" +#include "app_error.h" +#include "ble_serialization.h" + +#include "ser_app_power_system_off.h" + +static void * mp_out_param; + +static void tx_buf_alloc(uint8_t * * p_data, uint16_t * p_len) +{ + uint32_t err_code; + + do + { + err_code = ser_sd_transport_tx_alloc(p_data, p_len); + } + while (err_code != NRF_SUCCESS); + *p_data[0] = SER_PKT_TYPE_CMD; + *p_len -= 1; +} + + +uint32_t sd_power_system_off(void) +{ + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + const uint32_t err_code = power_system_off_req_enc(&(p_buffer[1]), &buffer_length); + APP_ERROR_CHECK(err_code); + + ser_app_power_system_off_set(); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + NULL); +} + + +/**@brief Command response callback function for @ref sd_temp_get BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ + +static uint32_t mw_temp_get_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = temp_get_rsp_dec(p_buffer, + length, + &result_code, + (int32_t * *) &mp_out_param); + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_temp_get(int32_t * p_temp) +{ + + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + mp_out_param = p_temp; + + const uint32_t err_code = temp_get_req_enc(p_temp, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + mw_temp_get_rsp_dec); +} + +/**@brief Command response callback function for @ref sd_ecb_block_encrypt BLE command. + * + * Callback for decoding the output parameters and the command response return code. + * + * @param[in] p_buffer Pointer to begin of command response buffer. + * @param[in] length Length of data in bytes. + * + * @return Decoded command response return code. + */ + +static uint32_t mw_ecb_block_encrypt_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ecb_block_encrypt_rsp_dec(p_buffer, + length, + (nrf_ecb_hal_data_t * *)&mp_out_param, + &result_code); + + APP_ERROR_CHECK(err_code); + + return result_code; +} + +uint32_t sd_ecb_block_encrypt(nrf_ecb_hal_data_t * p_ecb_data) +{ + + uint8_t * p_buffer; + uint32_t buffer_length = 0; + + tx_buf_alloc(&p_buffer, (uint16_t *)&buffer_length); + mp_out_param = p_ecb_data; + + const uint32_t err_code = ecb_block_encrypt_req_enc(p_ecb_data, + &(p_buffer[1]), + &buffer_length); + APP_ERROR_CHECK(err_code); + + //@note: Increment buffer length as internally managed packet type field must be included. + return ser_sd_transport_cmd_write(p_buffer, + (++buffer_length), + mw_ecb_block_encrypt_rsp_dec); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/app_ble_gap_sec_keys.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/app_ble_gap_sec_keys.c new file mode 100644 index 0000000..108231d --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/app_ble_gap_sec_keys.c @@ -0,0 +1,182 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include "app_ble_gap_sec_keys.h" +#include "ser_config.h" +#include "nrf_error.h" +#include "nordic_common.h" +#include <stddef.h> +#include <stdbool.h> +#include <string.h> + +#if NRF_SD_BLE_API_VERSION >= 6 +typedef struct { + bool active; + uint8_t adv_handle; + uint8_t * p_adv_data; + uint8_t * p_scan_rsp_data; +} adv_set_t; + +static adv_set_t m_adv_sets[4]; //todo configurable number of adv sets. + +static ble_data_t m_scan_data = {0}; +#endif +ser_ble_gap_app_keyset_t m_app_keys_table[SER_MAX_CONNECTIONS]; + +uint32_t app_ble_gap_sec_context_create(uint16_t conn_handle, uint32_t *p_index) +{ + uint32_t err_code = NRF_ERROR_NO_MEM; + uint32_t i; + + for (i=0; i<SER_MAX_CONNECTIONS; i++ ) + { + if ( ! m_app_keys_table[i].conn_active ) + { + m_app_keys_table[i].conn_active = 1; + m_app_keys_table[i].conn_handle = conn_handle; + *p_index = i; + err_code = NRF_SUCCESS; + break; + } + } + + return err_code; +} + +uint32_t app_ble_gap_sec_context_destroy(uint16_t conn_handle) +{ + uint32_t err_code = NRF_ERROR_NOT_FOUND; + uint32_t i; + + for (i=0; i<SER_MAX_CONNECTIONS; i++ ) + { + if ( m_app_keys_table[i].conn_handle == conn_handle ) + { + m_app_keys_table[i].conn_active = 0; + err_code = NRF_SUCCESS; + break; + } + } + + return err_code; +} + +uint32_t app_ble_gap_sec_context_find(uint16_t conn_handle, uint32_t *p_index) +{ + uint32_t err_code = NRF_ERROR_NOT_FOUND; + uint32_t i; + + for (i=0; i<SER_MAX_CONNECTIONS; i++ ) + { + if ( (m_app_keys_table[i].conn_handle == conn_handle) && (m_app_keys_table[i].conn_active == 1) ) + { + *p_index = i; + err_code = NRF_SUCCESS; + break; + } + } + + return err_code; +} +#if NRF_SD_BLE_API_VERSION >= 6 +uint32_t app_ble_gap_scan_data_set(ble_data_t const * p_data) +{ + if (m_scan_data.p_data) + { + return NRF_ERROR_BUSY; + } + else + { + memcpy(&m_scan_data, p_data, sizeof(ble_data_t)); + return NRF_SUCCESS; + } +} + + +uint32_t app_ble_gap_scan_data_fetch_clear(ble_data_t * p_data) +{ + memcpy(p_data, &m_scan_data, sizeof(ble_data_t)); + if (m_scan_data.p_data) + { + m_scan_data.p_data = NULL; + return NRF_SUCCESS; + } + else + { + return NRF_ERROR_NOT_FOUND; + } +} + +uint32_t app_ble_gap_adv_set_register(uint8_t adv_handle, uint8_t * p_adv_data, uint8_t * p_scan_rsp_data) +{ + uint32_t err_code = NRF_ERROR_NO_MEM; + uint32_t i; + for (i = 0; i < ARRAY_SIZE(m_adv_sets); i++) + { + if (m_adv_sets[i].active == false) + { + m_adv_sets[i].active = true; + m_adv_sets[i].adv_handle = adv_handle; + m_adv_sets[i].p_adv_data = p_adv_data; + m_adv_sets[i].p_scan_rsp_data = p_scan_rsp_data; + err_code = NRF_SUCCESS; + break; + } + } + return err_code; +} + +uint32_t app_ble_gap_adv_set_unregister(uint8_t adv_handle, uint8_t * * pp_adv_data, uint8_t **pp_scan_rsp_data) +{ + uint32_t err_code = NRF_ERROR_NOT_FOUND; + uint32_t i; + for (i = 0; i < ARRAY_SIZE(m_adv_sets); i++) + { + if ((m_adv_sets[i].active == true) && (m_adv_sets[i].adv_handle == adv_handle)) + { + m_adv_sets[i].active = false; + *pp_adv_data = m_adv_sets[i].p_adv_data; + *pp_scan_rsp_data = m_adv_sets[i].p_scan_rsp_data; + err_code = NRF_SUCCESS; + break; + } + } + return err_code; +} +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/app_ble_gap_sec_keys.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/app_ble_gap_sec_keys.h new file mode 100644 index 0000000..314a5f5 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/app_ble_gap_sec_keys.h @@ -0,0 +1,151 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef _APP_BLE_GAP_SEC_KEYS_H +#define _APP_BLE_GAP_SEC_KEYS_H + + /**@file + * + * @defgroup app_ble_gap_sec_keys GAP Functions for managing memory for security keys in the application device. + * @{ + * @ingroup ser_app_s130_codecs + * + * @brief GAP Application auxiliary functions for synchronizing the GAP security keys with the ones stored in the connectivity device. + */ + +#include "ble_gap.h" +#include "ble_types.h" + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/**@brief GAP connection - keyset mapping structure. + * + * @note This structure is used to map keysets to connection instances and store them in a static table. + */ +typedef struct +{ + uint16_t conn_handle; /**< Connection handle.*/ + uint8_t conn_active; /**< Indication that keys for this connection are used by the SoftDevice. 0: keys used; 1: keys not used. */ + ble_gap_sec_keyset_t keyset; /**< Keyset structure, see @ref ble_gap_sec_keyset_t.*/ +} ser_ble_gap_app_keyset_t; + +/**@brief Allocates the instance in m_app_keys_table[] for storage of encryption keys. + * + * @param[in] conn_handle conn_handle + * @param[out] p_index Pointer to the index of the allocated instance. + * + * @retval NRF_SUCCESS Context allocated. + * @retval NRF_ERROR_NO_MEM No free instance available. + */ +uint32_t app_ble_gap_sec_context_create(uint16_t conn_handle, uint32_t *p_index); + +/**@brief Release the instance identified by a connection handle. + * + * @param[in] conn_handle conn_handle + * + * @retval NRF_SUCCESS Context released. + * @retval NRF_ERROR_NOT_FOUND Instance with conn_handle not found. + */ +uint32_t app_ble_gap_sec_context_destroy(uint16_t conn_handle); + +/**@brief Finds index of instance identified by a connection handle in m_app_keys_table[]. + * + * @param[in] conn_handle conn_handle + * + * @param[out] p_index Pointer to the index of the entry in the context table corresponding to the given conn_handle. + * + * @retval NRF_SUCCESS Context found. + * @retval NRF_ERROR_NOT_FOUND Instance with conn_handle not found. + */ +uint32_t app_ble_gap_sec_context_find(uint16_t conn_handle, uint32_t *p_index); +/** @} */ + +#if NRF_SD_BLE_API_VERSION >= 6 +/** + * @brief Stores buffer for adv report data. + * + * @param p_data Pointer to the buffer. + * + * @return NRF_SUCCESS or error in case pointer is already set. + */ +uint32_t app_ble_gap_scan_data_set(ble_data_t const * p_data); + +/** + * @brief Returns pointer to the buffer for storing report data. Returns error if not paired with + * @ref app_ble_gap_scan_data_set call. + * + * @param[out] p_data Stored data. + * @return NRF_SUCCESS or error in case pointer is already cleared. + */ +uint32_t app_ble_gap_scan_data_fetch_clear(ble_data_t * p_data); + +/** + * @brief Function for registering data pointers related with given adv_handle. + * + * @param adv_handle Handle. + * @param p_adv_data Adv_data buffer. + * @param p_scan_rsp_data Scan_rsp_data buffer. + * + * @return NRF_SUCCESS or error. + * + */ +uint32_t app_ble_gap_adv_set_register(uint8_t adv_handle, uint8_t * p_adv_data, uint8_t * p_scan_rsp_data); + + +/** + * @brief Function for unregistering given . + * + * @param[in] adv_handle Handle. + * @param[out] pp_adv_data Pointer to adv_data buffer associated with given adv_handle. + * @param[out] pp_scan_rsp_data Pointer to adv_data buffer associated with given adv_handle. + * + * @return NRF_SUCCESS or error. + * + */ +uint32_t app_ble_gap_adv_set_unregister(uint8_t adv_handle, uint8_t * * pp_adv_data, uint8_t **pp_scan_rsp_data); +#endif +#ifdef __cplusplus +} +#endif + +#endif //_APP_BLE_GAP_SEC_KEYS_H diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/app_ble_user_mem.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/app_ble_user_mem.c new file mode 100644 index 0000000..dcb1371 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/app_ble_user_mem.c @@ -0,0 +1,101 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include "app_ble_user_mem.h" +#include "ser_config.h" +#include "nrf_error.h" +#include <stddef.h> + +ser_ble_user_mem_t m_app_user_mem_table[SER_MAX_CONNECTIONS]; + +uint32_t app_ble_user_mem_context_create(uint16_t conn_handle, uint32_t *p_index) +{ + uint32_t err_code = NRF_ERROR_NO_MEM; + uint32_t i; + + for (i=0; i<SER_MAX_CONNECTIONS; i++ ) + { + if ( ! m_app_user_mem_table[i].conn_active ) + { + m_app_user_mem_table[i].conn_active = 1; + m_app_user_mem_table[i].conn_handle = conn_handle; + *p_index = i; + err_code = NRF_SUCCESS; + break; + } + } + + return err_code; +} + +uint32_t app_ble_user_mem_context_destroy(uint16_t conn_handle) +{ + uint32_t err_code = NRF_ERROR_NOT_FOUND; + uint32_t i; + + for (i=0; i<SER_MAX_CONNECTIONS; i++ ) + { + if ( m_app_user_mem_table[i].conn_handle == conn_handle ) + { + m_app_user_mem_table[i].conn_active = 0; + err_code = NRF_SUCCESS; + break; + } + } + + return err_code; +} + +uint32_t app_ble_user_mem_context_find(uint16_t conn_handle, uint32_t *p_index) +{ + uint32_t err_code = NRF_ERROR_NOT_FOUND; + uint32_t i; + + for (i=0; i<SER_MAX_CONNECTIONS; i++ ) + { + if ( (m_app_user_mem_table[i].conn_handle == conn_handle) && (m_app_user_mem_table[i].conn_active == 1) ) + { + *p_index = i; + err_code = NRF_SUCCESS; + break; + } + } + + return err_code; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/app_ble_user_mem.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/app_ble_user_mem.h new file mode 100644 index 0000000..ac95b01 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/app_ble_user_mem.h @@ -0,0 +1,109 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef _APP_BLE_USER_MEM_H +#define _APP_BLE_USER_MEM_H + + + /**@file + * + * @defgroup app_ble_user_mem Functions for managing memory for user memory request in the application device. + * @{ + * @ingroup ser_app_s130_codecs + * + * @brief Application auxiliary functions for synchronizing user memory with the one stored in the connectivity device. + */ + +#include "ble.h" +#include "ser_config.h" +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/**@brief Connection - user memory mapping structure. + * + * @note This structure is used to map user memory to connection instances and store it in a static table. + */ +//lint -esym(452,ser_ble_user_mem_t) +typedef struct +{ + uint16_t conn_handle; /**< Connection handle. */ + uint8_t conn_active; /**< Indication that user memory for this connection is used by the SoftDevice. 0: memory used; 1: memory not used. */ + ble_user_mem_block_t mem_block; /**< User memory block structure, see @ref ble_user_mem_block_t. */ +} ser_ble_user_mem_t; + +/**@brief Allocates instance in m_user_mem_table[] for storage. + * + * @param[in] conn_handle conn_handle + * @param[out] p_index Pointer to the index of the allocated instance. + * + * @retval NRF_SUCCESS Context allocated. + * @retval NRF_ERROR_NO_MEM No free instance available. + */ +uint32_t app_ble_user_mem_context_create(uint16_t conn_handle, uint32_t *p_index); + +/**@brief Release instance identified by a connection handle. + * + * @param[in] conn_handle conn_handle + * + * @retval NRF_SUCCESS Context released. + * @retval NRF_ERROR_NOT_FOUND Instance with conn_handle not found. + */ +uint32_t app_ble_user_mem_context_destroy(uint16_t conn_handle); + +/**@brief Finds index of the instance identified by a connection handle in m_user_mem_table[]. + * + * @param[in] conn_handle conn_handle + * + * @param[out] p_index Pointer to the index of the entry in the context table corresponding to the given conn_handle. + * + * @retval NRF_SUCCESS Context found. + * @retval NRF_ERROR_NOT_FOUND Instance with conn_handle not found. + */ +uint32_t app_ble_user_mem_context_find(uint16_t conn_handle, uint32_t *p_index); +/** @} */ + + +#ifdef __cplusplus +} +#endif + +#endif //_APP_BLE_USER_MEM_H diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_app.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_app.c new file mode 100644 index 0000000..fcc71ab --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_app.c @@ -0,0 +1,513 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include <stdlib.h> +#include <string.h> +#include "ble_app.h" +#include "ble_serialization.h" +#include "ble_struct_serialization.h" +#include "ble_gap_struct_serialization.h" +#include "ble_gatt_struct_serialization.h" +#include "ble_gattc_struct_serialization.h" +#include "ble_gatts_struct_serialization.h" +#include "ble_l2cap_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t ble_enable_req_enc(ble_enable_params_t * p_ble_enable_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_ENABLE); + SER_PUSH_COND(p_ble_enable_params, ble_enable_params_t_enc); + SER_REQ_ENC_END; +} +#else +uint32_t ble_enable_req_enc(uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_ENABLE); + SER_REQ_ENC_END; +} +#endif + +uint32_t ble_enable_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_ENABLE); +} + +uint32_t ble_opt_get_req_enc(uint32_t opt_id, + ble_opt_t const * const p_opt, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_OPT_GET); + + SER_PUSH_uint32(&opt_id); + SER_PUSH_COND(p_opt, NULL); + + SER_REQ_ENC_END; +} + +uint32_t ble_opt_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_opt_id, + ble_opt_t * const p_opt, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_OPT_GET); + + SER_PULL_uint32(p_opt_id); + + field_decoder_handler_t fp_decoder = NULL; + void * p_struct = NULL; + + switch (*p_opt_id) + { +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 + case BLE_COMMON_OPT_CONN_BW: + fp_decoder = ble_common_opt_conn_bw_t_dec; + p_struct = &(p_opt->common_opt.conn_bw); + break; +#endif + case BLE_COMMON_OPT_PA_LNA: + fp_decoder = ble_common_opt_pa_lna_t_dec; + p_struct = &(p_opt->common_opt.pa_lna); + break; + case BLE_COMMON_OPT_CONN_EVT_EXT: + fp_decoder = ble_common_opt_conn_evt_ext_t_dec; + p_struct = &(p_opt->common_opt.conn_evt_ext); + break; + case BLE_GAP_OPT_CH_MAP: + fp_decoder = ble_gap_opt_ch_map_t_dec; + p_struct =&(p_opt->gap_opt.ch_map); + break; + case BLE_GAP_OPT_LOCAL_CONN_LATENCY: + fp_decoder = ble_gap_opt_local_conn_latency_t_dec; + p_struct = &(p_opt->gap_opt.local_conn_latency); + break; + case BLE_GAP_OPT_PASSKEY: + fp_decoder = ble_gap_opt_passkey_t_dec; + p_struct = &(p_opt->gap_opt.passkey); + break; + case BLE_GAP_OPT_AUTH_PAYLOAD_TIMEOUT: + fp_decoder = ble_gap_opt_auth_payload_timeout_t_dec; + p_struct = &(p_opt->gap_opt.auth_payload_timeout); + break; +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 + case BLE_GAP_OPT_EXT_LEN: + fp_decoder = ble_gap_opt_ext_len_t_dec; + p_struct = &(p_opt->gap_opt.ext_len); + break; +#endif +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 6 + case BLE_GAP_OPT_SCAN_REQ_REPORT: + fp_decoder = ble_gap_opt_scan_req_report_t_dec; + p_struct = &(p_opt->gap_opt.scan_req_report); + break; +#endif +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 + case BLE_GAP_OPT_COMPAT_MODE: + fp_decoder = ble_gap_opt_compat_mode_t_dec; + p_struct = &(p_opt->gap_opt.compat_mode); + break; +#else +#ifndef S112 + case BLE_GAP_OPT_COMPAT_MODE_1: + fp_decoder = ble_gap_opt_compat_mode_1_t_dec; + p_struct = &(p_opt->gap_opt.compat_mode_1); + break; +#endif +#endif +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION == 4 + case BLE_GAP_OPT_COMPAT_MODE_2: + fp_decoder = ble_gap_opt_compat_mode_2_t_dec; + p_struct = &(p_opt->gap_opt.compat_mode_2); + break; +#endif + default: + SER_ASSERT(NRF_ERROR_INVALID_PARAM, NRF_ERROR_INVALID_PARAM); + break; + } + + SER_PULL_FIELD(p_struct, fp_decoder); + + SER_RSP_DEC_END; +} + + + +uint32_t ble_opt_set_req_enc(uint32_t const opt_id, + ble_opt_t const * const p_opt, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_OPT_SET); + + SER_PUSH_uint32(&opt_id); + + field_encoder_handler_t fp_encoder = NULL; + void const * p_struct = NULL; + + SER_PUSH_COND(p_opt, NULL); + if (p_opt) + { + switch (opt_id) + { +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 + case BLE_COMMON_OPT_CONN_BW: + fp_encoder = ble_common_opt_conn_bw_t_enc; + p_struct = &(p_opt->common_opt.conn_bw); + break; +#endif + case BLE_COMMON_OPT_PA_LNA: + fp_encoder = ble_common_opt_pa_lna_t_enc; + p_struct = &(p_opt->common_opt.pa_lna); + break; + case BLE_COMMON_OPT_CONN_EVT_EXT: + fp_encoder = ble_common_opt_conn_evt_ext_t_enc; + p_struct = &(p_opt->common_opt.conn_evt_ext); + break; + case BLE_GAP_OPT_CH_MAP: + fp_encoder = ble_gap_opt_ch_map_t_enc; + p_struct = &(p_opt->gap_opt.ch_map); + break; + case BLE_GAP_OPT_LOCAL_CONN_LATENCY: + fp_encoder = ble_gap_opt_local_conn_latency_t_enc; + p_struct = &(p_opt->gap_opt.local_conn_latency); + break; + case BLE_GAP_OPT_PASSKEY: + fp_encoder = ble_gap_opt_passkey_t_enc; + p_struct = &(p_opt->gap_opt.passkey); + break; + case BLE_GAP_OPT_AUTH_PAYLOAD_TIMEOUT: + fp_encoder = ble_gap_opt_auth_payload_timeout_t_enc; + p_struct = &(p_opt->gap_opt.auth_payload_timeout); + break; +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 + case BLE_GAP_OPT_EXT_LEN: + fp_encoder = ble_gap_opt_ext_len_t_enc; + p_struct = &(p_opt->gap_opt.ext_len); + break; +#endif +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 6 + case BLE_GAP_OPT_SCAN_REQ_REPORT: + fp_encoder = ble_gap_opt_scan_req_report_t_enc; + p_struct = &(p_opt->gap_opt.scan_req_report); + break; +#endif +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 + case BLE_GAP_OPT_COMPAT_MODE: + fp_encoder = ble_gap_opt_compat_mode_t_enc; + p_struct = &(p_opt->gap_opt.compat_mode); + break; +#else +#ifndef S112 + case BLE_GAP_OPT_COMPAT_MODE_1: + fp_encoder = ble_gap_opt_compat_mode_1_t_enc; + p_struct = &(p_opt->gap_opt.compat_mode_1); + break; +#endif + case BLE_GAP_OPT_SLAVE_LATENCY_DISABLE: + fp_encoder = ble_gap_opt_slave_latency_disable_t_enc; + p_struct = &(p_opt->gap_opt.slave_latency_disable); + break; +#endif +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION == 4 + case BLE_GAP_OPT_COMPAT_MODE_2: + fp_encoder = ble_gap_opt_compat_mode_2_t_enc; + p_struct = &(p_opt->gap_opt.compat_mode_2); + break; +#endif + default: + SER_ASSERT(NRF_ERROR_INVALID_PARAM,NRF_ERROR_INVALID_PARAM); + break; + } + + SER_PUSH_FIELD(p_struct, fp_encoder); + } + + SER_REQ_ENC_END; +} + + +uint32_t ble_opt_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_OPT_SET); +} + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t ble_tx_packet_count_get_req_enc(uint16_t conn_handle, + uint8_t const * const p_count, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_TX_PACKET_COUNT_GET); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_count, NULL); + + SER_REQ_ENC_END; +} + + +uint32_t ble_tx_packet_count_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * * const pp_count, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_TX_PACKET_COUNT_GET); + SER_PULL_COND(pp_count, uint8_t_dec); + SER_RSP_DEC_END; +} +#endif + +uint32_t ble_user_mem_reply_req_enc(uint16_t conn_handle, + ble_user_mem_block_t const * p_block, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_USER_MEM_REPLY); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_block, ble_user_mem_block_t_enc); + + SER_REQ_ENC_END; +} + +uint32_t ble_user_mem_reply_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_USER_MEM_REPLY); +} + + + +uint32_t ble_uuid_decode_req_enc(uint8_t uuid_le_len, + uint8_t const * const p_uuid_le, + ble_uuid_t * const p_uuid, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_UUID_DECODE); + + SER_PUSH_len8data(p_uuid_le, uuid_le_len); + SER_PUSH_COND(p_uuid, NULL); + + SER_REQ_ENC_END; +} + + +uint32_t ble_uuid_decode_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_uuid_t * * const pp_uuid, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_UUID_DECODE); + SER_PULL_COND(pp_uuid, ble_uuid_t_dec); + SER_RSP_DEC_END; +} + + +uint32_t ble_uuid_encode_req_enc(ble_uuid_t const * const p_uuid, + uint8_t const * const p_uuid_le_len, + uint8_t const * const p_uuid_le, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_UUID_ENCODE); + + SER_PUSH_COND(p_uuid, ble_uuid_t_enc); + SER_PUSH_COND(p_uuid_le_len, NULL); + SER_PUSH_COND(p_uuid_le, NULL); + + SER_REQ_ENC_END; +} + + +uint32_t ble_uuid_encode_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_uuid_le_len, + uint8_t * const p_uuid_le, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_UUID_ENCODE); + + uint8_t uuid_le_len; + SER_PULL_uint8(&uuid_le_len); + if (p_uuid_le_len) + { + *p_uuid_le_len = uuid_le_len; + if (p_uuid_le) + { + SER_PULL_uint8array(p_uuid_le, uuid_le_len); + } + } + + SER_RSP_DEC_END; +} + +uint32_t ble_uuid_vs_add_req_enc(ble_uuid128_t const * const p_vs_uuid, + uint8_t * const p_uuid_type, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_UUID_VS_ADD); + + SER_PUSH_COND(p_vs_uuid, ble_uuid128_t_enc); + SER_PUSH_COND(p_uuid_type, NULL); + + SER_REQ_ENC_END; +} + + +uint32_t ble_uuid_vs_add_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * * const pp_uuid_type, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_UUID_VS_ADD); + + SER_ASSERT_NOT_NULL(pp_uuid_type); + SER_PULL_COND(pp_uuid_type, uint8_t_dec); + + SER_RSP_DEC_END; +} + +uint32_t ble_version_get_req_enc(ble_version_t const * const p_version, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_VERSION_GET); + SER_PUSH_COND(p_version, NULL); + SER_REQ_ENC_END; +} + +uint32_t ble_version_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_version_t * p_version, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_VERSION_GET); + SER_PULL_FIELD(p_version, ble_version_t_dec); + SER_RSP_DEC_END; +} +#if NRF_SD_BLE_API_VERSION >= 4 +uint32_t ble_cfg_set_req_enc(uint32_t cfg_id, + ble_cfg_t const * p_cfg, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_CFG_SET); + SER_PUSH_uint32(&cfg_id); + field_encoder_handler_t fp_encoder = NULL; + void const * p_struct = NULL; + + SER_PUSH_COND(p_cfg, NULL); + if (p_cfg) + { + + switch (cfg_id) + { + case BLE_CONN_CFG_GAP: + fp_encoder = ble_gap_conn_cfg_t_enc; + p_struct = &(p_cfg->conn_cfg.params.gap_conn_cfg); + break; + case BLE_CONN_CFG_GATTC: + fp_encoder = ble_gattc_conn_cfg_t_enc; + p_struct = &(p_cfg->conn_cfg.params.gattc_conn_cfg); + break; + case BLE_CONN_CFG_GATTS: + fp_encoder = ble_gatts_conn_cfg_t_enc; + p_struct = &(p_cfg->conn_cfg.params.gatts_conn_cfg); + break; + case BLE_CONN_CFG_GATT: + fp_encoder = ble_gatt_conn_cfg_t_enc; + p_struct = &(p_cfg->conn_cfg.params.gatt_conn_cfg); + break; +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION >= 5 && !defined(S112) + case BLE_CONN_CFG_L2CAP: + fp_encoder = ble_l2cap_conn_cfg_t_enc; + p_struct = &(p_cfg->conn_cfg.params.l2cap_conn_cfg); + break; +#endif + case BLE_COMMON_CFG_VS_UUID: + fp_encoder = ble_common_cfg_vs_uuid_t_enc; + p_struct = &(p_cfg->common_cfg.vs_uuid_cfg); + break; + case BLE_GAP_CFG_ROLE_COUNT: + fp_encoder = ble_gap_cfg_role_count_t_enc; + p_struct = &(p_cfg->gap_cfg.role_count_cfg); + break; + case BLE_GAP_CFG_DEVICE_NAME: + fp_encoder = ble_gap_cfg_device_name_t_enc; + p_struct = &(p_cfg->gap_cfg.device_name_cfg); + break; + case BLE_GATTS_CFG_SERVICE_CHANGED: + fp_encoder = ble_gatts_cfg_service_changed_t_enc; + p_struct = &(p_cfg->gatts_cfg.service_changed); + break; + case BLE_GATTS_CFG_ATTR_TAB_SIZE: + fp_encoder = ble_gatts_cfg_attr_tab_size_t_enc; + p_struct = &(p_cfg->gatts_cfg.attr_tab_size); + break; + } + if (cfg_id >= BLE_CONN_CFG_BASE && cfg_id <= BLE_CONN_CFG_GATT) + { + SER_PUSH_uint8(&p_cfg->conn_cfg.conn_cfg_tag); + } + SER_PUSH_FIELD(p_struct, fp_encoder); + } + SER_REQ_ENC_END; +} + + +uint32_t ble_cfg_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_CFG_SET); +} +#endif //NRF_SD_BLE_API_VERSION >= 4 diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_app.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_app.h new file mode 100644 index 0000000..a68cf0d --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_app.h @@ -0,0 +1,523 @@ +/** + * Copyright (c) 2013 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef BLE_APP_H__ +#define BLE_APP_H__ + +/** + * @addtogroup ser_codecs Serialization codecs + * @ingroup ble_sdk_lib_serialization + */ + +/** + * @addtogroup ser_app_s130_codecs Application codecs for S132 and S140 + * @ingroup ser_codecs_app + */ + +/**@file + * + * @defgroup ble_app Application command request encoders and command response decoders + * @{ + * @ingroup ser_app_s130_codecs + * + * @brief Application command request encoders and command response decoders. + */ +#include "ble.h" + +#ifdef __cplusplus +extern "C" { +#endif +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +/** + * @brief Encodes @ref sd_ble_tx_packet_count_get command request. + * + * @sa @ref ble_tx_packet_count_get_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle. + * @param[in] p_count Pointer to count value to be filled. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of the encoded command packet. + * + * @note \p p_count will not be updated by the command + * request encoder. Updated values are set by @ref ble_tx_packet_count_get_rsp_dec. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_tx_packet_count_get_req_enc(uint16_t conn_handle, + uint8_t const * const p_count, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes a response to @ref sd_ble_tx_packet_count_get command. + * + * @sa @ref ble_tx_packet_count_get_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to the beginning of a command response packet. + * @param[in] packet_len Length (in bytes) of the response packet. + * @param[out] pp_count Pointer to the pointer to count value. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_tx_packet_count_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * * const pp_count, + uint32_t * const p_result_code); +#endif +/**@brief Encodes the @ref sd_ble_uuid_encode command request. + * + * @sa @ref ble_uuid_encode_rsp_dec for command response decoder. + * + * @param[in] p_uuid Pointer to a @ref ble_uuid_t structure that will be encoded into bytes. + * @param[in] p_uuid_le_len Size of \p p_uuid_le, if \p p_uuid_le is not NULL + * @param[in] p_uuid_le Pointer to a buffer where the little endian raw UUID bytes(2 or 16) + * will be stored. Can be NULL to calculate the required size. + * @param[in] p_buf Pointer to a buffer where the encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of the encoded command packet. + * + * @note \p p_uuid_le_len and \p p_uuid_le will not be updated by the command + * request encoder. Updated values are set by @ref ble_uuid_encode_rsp_dec. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_uuid_encode_req_enc(ble_uuid_t const * const p_uuid, + uint8_t const * const p_uuid_le_len, + uint8_t const * const p_uuid_le, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes a response to the @ref sd_ble_uuid_encode command. + * + * @sa @ref ble_uuid_encode_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to the beginning of a command response packet. + * @param[in] packet_len Length (in bytes) of a response packet. + * @param[in,out] p_uuid_le_len \c in: Size (in bytes) of \p p_uuid_le buffer. + * \c out: Length of decoded contents of \p p_uuid_le. + * @param[out] p_uuid_le Pointer to a buffer where the encoded UUID will be stored. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Length of \p p_uuid_le is too small to hold the decoded + * value from response. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match the expected + * operation code. + */ +uint32_t ble_uuid_encode_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_uuid_le_len, + uint8_t * const p_uuid_le, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_uuid_decode command request. + * + * @sa @ref ble_uuid_decode_rsp_dec for command response decoder. + * + * @param[in] uuid_le_len Size of \p p_uuid_le if \p p_uuid_le is not NULL. + * @param[in] p_uuid_le Pointer to a buffer where the little endian raw UUID bytes(2 or 16) + * are stored. + * @param[out] p_uuid Pointer to a @ref ble_uuid_t structure were the raw UUID will be decoded. + * @param[in] p_buf Pointer to the buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of the encoded command packet. + * + * @note \p p_uuid will not be updated by the command request encoder. + * Updated values are set by @ref ble_uuid_decode_rsp_dec. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_uuid_decode_req_enc(uint8_t uuid_le_len, + uint8_t const * const p_uuid_le, + ble_uuid_t * const p_uuid, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes a response to the @ref sd_ble_uuid_decode command. + * + * @sa @ref ble_uuid_decode_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to the beginning of command response packet. + * @param[in] packet_len Length (in bytes) of the response packet. + * @param[out] p_uuid Pointer to a buffer where the decoded UUID will be stored. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match the expected + * operation code. + */ +uint32_t ble_uuid_decode_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_uuid_t * * const p_uuid, + uint32_t * const p_result_code); + +/**@brief Encodes the @ref sd_ble_uuid_vs_add command request. + * + * @sa @ref ble_uuid_vs_add_rsp_dec for command response decoder. + * + * @param[in] p_vs_uuid Pointer to a @ref ble_uuid128_t structure. + * @param[in] p_uuid_type Pointer to uint8_t where UUID type will be returned. + * @param[in] p_buf Pointer to buffer where the encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @note \p p_uuid_type will not be updated by the command request encoder. + * Updated values are set by @ref ble_uuid_vs_add_rsp_dec. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_uuid_vs_add_req_enc(ble_uuid128_t const * const p_vs_uuid, + uint8_t * const p_uuid_type, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to the @ref sd_ble_uuid_vs_add command. + * + * @sa @ref ble_uuid_vs_add_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to the beginning of command response packet. + * @param[in] packet_len Length (in bytes) of a response packet. + * @param[out] pp_uuid_type Pointer to a pointer to uint8_t where the decoded UUID type will be stored. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_uuid_vs_add_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * * const pp_uuid_type, + uint32_t * const p_result_code); + +/**@brief Encodes the @ref sd_ble_version_get command request. + * + * @sa @ref ble_version_get_rsp_dec for command response decoder. + * + * @param[in] p_version Pointer to a @ref ble_version_t structure to be filled by the response. + * @param[in] p_buf Pointer to a buffer where the encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_version_get_req_enc(ble_version_t const * const p_version, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to the @ref sd_ble_version_get command. + * + * @sa @ref ble_version_get_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to the beginning of a command response packet. + * @param[in] packet_len Length (in bytes) of the response packet. + * @param[out] p_version Pointer to a @ref ble_version_t where the decoded version will be stored. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Version information stored successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold the decoded event. + */ +uint32_t ble_version_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_version_t * p_version, + uint32_t * const p_result_code); + + +/**@brief Encodes the @ref sd_ble_opt_set command request. + * + * @sa @ref ble_opt_set_rsp_dec for command response decoder. + * + * @param[in] opt_id Identifies type of parameter in ble_opt_t union. + * @param[in] p_opt Pointer to the ble_opt_t union. + * @param[in] p_buf Pointer to a buffer where the encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of the encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Invalid opt id. + */ +uint32_t ble_opt_set_req_enc(uint32_t const opt_id, + ble_opt_t const * const p_opt, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to the @ref sd_ble_opt_set command. + * + * @sa @ref ble_opt_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to the beginning of a command response packet. + * @param[in] packet_len Length (in bytes) of the response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Version information stored successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ble_opt_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +/**@brief Encodes the @ref sd_ble_enable command request. + * + * @sa @ref ble_enable_rsp_dec for command response decoder. + * + * @param[in] p_ble_enable_params Pointer to the @ref ble_enable_params_t structure. + * @param[in] p_buf Pointer to the buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of the encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_enable_req_enc(ble_enable_params_t * p_ble_enable_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len); +#else +/**@brief Encodes the @ref sd_ble_enable command request. + * + * @sa @ref ble_enable_rsp_dec for command response decoder. + * + * @param[in] p_buf Pointer to the buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of the encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_enable_req_enc(uint8_t * const p_buf, + uint32_t * const p_buf_len); + +#endif + +/**@brief Decodes response to the @ref sd_ble_enable command. + * + * @sa @ref ble_enable_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to the beginning of a command response packet. + * @param[in] packet_len Length (in bytes) of the response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Success. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold the decoded event. + */ +uint32_t ble_enable_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); +/**@brief Encodes the @ref sd_ble_opt_get command request. + * + * @sa @ref ble_opt_get_rsp_dec for command response decoder. + * + * @param[in] opt_id Identifies the type of parameter in the ble_opt_t union. + * @param[in] p_opt Pointer to the @ref ble_opt_t union to be filled by the response. + * @param[in] p_buf Pointer to the buffer where the encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of the encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Invalid opt id. + */ +uint32_t ble_opt_get_req_enc(uint32_t opt_id, + ble_opt_t const * const p_opt, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to the @ref sd_ble_opt_get command. + * + * @sa @ref ble_opt_get_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to the beginning of a command response packet. + * @param[in] packet_len Length (in bytes) of the response packet. + * @param[out] p_opt_id Pointer to the decoded opt_id. + * @param[out] p_opt Pointer to the decoded @ref ble_opt_t union. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Opt stored successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold the decoded event. + * @retval NRF_ERROR_INVALID_PARAM Invalid opt id. + */ + +uint32_t ble_opt_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_opt_id, + ble_opt_t * const p_opt, + uint32_t * const p_result_code); + +/**@brief Encodes the @ref sd_ble_user_mem_reply command request. + * + * @sa @ref ble_user_mem_reply_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle. + * @param[in] p_block Pointer to the @ref ble_user_mem_block_t structure. + * @param[in] p_buf Pointer to the buffer where the encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of the encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Invalid opt id. + */ +uint32_t ble_user_mem_reply_req_enc(uint16_t conn_handle, + ble_user_mem_block_t const * p_block, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to the @ref sd_ble_user_mem_reply command. + * + * @sa @ref ble_user_mem_reply_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to the beginning of a command response packet. + * @param[in] packet_len Length (in bytes) of the response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Opt stored successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold the decoded event. + * @retval NRF_ERROR_INVALID_PARAM Invalid opt id. + */ +uint32_t ble_user_mem_reply_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); +#if NRF_SD_BLE_API_VERSION >= 4 +/**@brief Encodes the @ref sd_ble_cfg_set command request. + * + * @sa @ref ble_cfg_set_rsp_dec for command response decoder. + * + * @param[in] cfg_id Configuratio id. + * @param[in] p_cfg Pointer to the configuration. + * @param[in] p_buf Pointer to the buffer where the encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of the encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Invalid opt id. + */ +uint32_t ble_cfg_set_req_enc(uint32_t cfg_id, + ble_cfg_t const * p_cfg, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to the @ref sd_ble_cfg_set command. + * + * @sa @ref ble_cfg_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to the beginning of a command response packet. + * @param[in] packet_len Length (in bytes) of the response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Opt stored successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold the decoded event. + * @retval NRF_ERROR_INVALID_PARAM Invalid opt id. + */ +uint32_t ble_cfg_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); +#endif //NRF_SD_BLE_API_VERSION >= 4 + +/**@brief Event decoding dispatcher. + * + * The event decoding dispatcher will route the event packet to the correct decoder, which in turn + * decodes the contents of the event and updates the \p p_event struct. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of the event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to the \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, the required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of the decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold the decoded event. + * @retval NRF_ERROR_NOT_FOUND Decoding failure. No event decoder is available. + */ +uint32_t ble_event_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_event.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_event.c new file mode 100644 index 0000000..e32a905 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_event.c @@ -0,0 +1,316 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include "ble_serialization.h" +#include "ble_app.h" +#include "ble_evt_app.h" +#include "ble_gap_evt_app.h" +#include "ble_gattc_evt_app.h" +#include "ble_gatts_evt_app.h" +#include "ble_l2cap_evt_app.h" +#include "app_util.h" + +uint32_t ble_event_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + uint32_t err_code; + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_event_len); + SER_ASSERT_LENGTH_LEQ(SER_EVT_HEADER_SIZE, packet_len); + SER_ASSERT_NOT_NULL(p_event); + SER_ASSERT_LENGTH_LEQ(sizeof (ble_evt_hdr_t), *p_event_len); + *p_event_len -= sizeof (ble_evt_hdr_t); + + const uint16_t event_id = uint16_decode(&p_buf[SER_EVT_ID_POS]); + const uint8_t * p_sub_buffer = &p_buf[SER_EVT_HEADER_SIZE]; + const uint32_t sub_packet_len = packet_len - SER_EVT_HEADER_SIZE; + + uint32_t (*fp_event_decoder)(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) = NULL; + + switch (event_id) + { +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 + case BLE_EVT_TX_COMPLETE: + fp_event_decoder = ble_evt_tx_complete_dec; + break; + case BLE_EVT_DATA_LENGTH_CHANGED: + fp_event_decoder = ble_evt_data_length_changed_dec; + break; +#endif + case BLE_EVT_USER_MEM_REQUEST: + fp_event_decoder = ble_evt_user_mem_request_dec; + break; + + case BLE_EVT_USER_MEM_RELEASE: + fp_event_decoder = ble_evt_user_mem_release_dec; + break; + + + case BLE_GAP_EVT_PASSKEY_DISPLAY: + fp_event_decoder = ble_gap_evt_passkey_display_dec; + break; + + case BLE_GAP_EVT_AUTH_KEY_REQUEST: + fp_event_decoder = ble_gap_evt_auth_key_request_dec; + break; + + case BLE_GAP_EVT_CONN_PARAM_UPDATE: + fp_event_decoder = ble_gap_evt_conn_param_update_dec; + break; + +#ifndef S112 + case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST: + fp_event_decoder = ble_gap_evt_conn_param_update_request_dec; + break; +#endif + case BLE_GAP_EVT_CONN_SEC_UPDATE: + fp_event_decoder = ble_gap_evt_conn_sec_update_dec; + break; + + case BLE_GAP_EVT_CONNECTED: + fp_event_decoder = ble_gap_evt_connected_dec; + break; + + case BLE_GAP_EVT_DISCONNECTED: + fp_event_decoder = ble_gap_evt_disconnected_dec; + break; + + case BLE_GAP_EVT_TIMEOUT: + fp_event_decoder = ble_gap_evt_timeout_dec; + break; + + case BLE_GAP_EVT_RSSI_CHANGED: + fp_event_decoder = ble_gap_evt_rssi_changed_dec; + break; + + case BLE_GAP_EVT_SEC_INFO_REQUEST: + fp_event_decoder = ble_gap_evt_sec_info_request_dec; + break; + + case BLE_GAP_EVT_SEC_PARAMS_REQUEST: + fp_event_decoder = ble_gap_evt_sec_params_request_dec; + break; + + case BLE_GAP_EVT_AUTH_STATUS: + fp_event_decoder = ble_gap_evt_auth_status_dec; + break; + + case BLE_GAP_EVT_SEC_REQUEST: + fp_event_decoder = ble_gap_evt_sec_request_dec; + break; + + case BLE_GAP_EVT_KEY_PRESSED: + fp_event_decoder = ble_gap_evt_key_pressed_dec; + break; + + case BLE_GAP_EVT_LESC_DHKEY_REQUEST: + fp_event_decoder = ble_gap_evt_lesc_dhkey_request_dec; + break; +#if NRF_SD_BLE_API_VERSION >= 5 + case BLE_GAP_EVT_PHY_UPDATE: + fp_event_decoder = ble_gap_evt_phy_update_dec; + break; + case BLE_GAP_EVT_PHY_UPDATE_REQUEST: + fp_event_decoder = ble_gap_evt_phy_update_request_dec; + break; +#endif +#if NRF_SD_BLE_API_VERSION >= 4 && !defined(S112) + case BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST: + fp_event_decoder = ble_gap_evt_data_length_update_request_dec; + break; + case BLE_GAP_EVT_DATA_LENGTH_UPDATE: + fp_event_decoder = ble_gap_evt_data_length_update_dec; + break; +#endif + case BLE_GATTC_EVT_CHAR_DISC_RSP: + fp_event_decoder = ble_gattc_evt_char_disc_rsp_dec; + break; + + case BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP: + fp_event_decoder = ble_gattc_evt_char_val_by_uuid_read_rsp_dec; + break; + + case BLE_GATTC_EVT_DESC_DISC_RSP: + fp_event_decoder = ble_gattc_evt_desc_disc_rsp_dec; + break; + + case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP: + fp_event_decoder = ble_gattc_evt_prim_srvc_disc_rsp_dec; + break; + + case BLE_GATTC_EVT_READ_RSP: + fp_event_decoder = ble_gattc_evt_read_rsp_dec; + break; + + case BLE_GATTC_EVT_HVX: + fp_event_decoder = ble_gattc_evt_hvx_dec; + break; + + case BLE_GATTC_EVT_TIMEOUT: + fp_event_decoder = ble_gattc_evt_timeout_dec; + break; + + case BLE_GATTC_EVT_WRITE_RSP: + fp_event_decoder = ble_gattc_evt_write_rsp_dec; + break; + + case BLE_GATTC_EVT_CHAR_VALS_READ_RSP: + fp_event_decoder = ble_gattc_evt_char_vals_read_rsp_dec; + break; + + case BLE_GATTC_EVT_REL_DISC_RSP: + fp_event_decoder = ble_gattc_evt_rel_disc_rsp_dec; + break; + + case BLE_GATTC_EVT_ATTR_INFO_DISC_RSP: + fp_event_decoder = ble_gattc_evt_attr_info_disc_rsp_dec; + break; + + case BLE_GATTC_EVT_EXCHANGE_MTU_RSP: + fp_event_decoder = ble_gattc_evt_exchange_mtu_rsp_dec; + break; +#if NRF_SD_BLE_API_VERSION >= 4 + case BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE: + fp_event_decoder = ble_gattc_evt_write_cmd_tx_complete_dec; + break; +#endif + case BLE_GATTS_EVT_WRITE: + fp_event_decoder = ble_gatts_evt_write_dec; + break; + + case BLE_GATTS_EVT_TIMEOUT: + fp_event_decoder = ble_gatts_evt_timeout_dec; + break; + + case BLE_GATTS_EVT_SC_CONFIRM: + fp_event_decoder = ble_gatts_evt_sc_confirm_dec; + break; + + case BLE_GATTS_EVT_HVC: + fp_event_decoder = ble_gatts_evt_hvc_dec; + break; + + case BLE_GATTS_EVT_SYS_ATTR_MISSING: + fp_event_decoder = ble_gatts_evt_sys_attr_missing_dec; + break; + + case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST: + fp_event_decoder = ble_gatts_evt_rw_authorize_request_dec; + break; + + case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST: + fp_event_decoder = ble_gatts_evt_exchange_mtu_request_dec; + break; +#if NRF_SD_BLE_API_VERSION >= 4 + case BLE_GATTS_EVT_HVN_TX_COMPLETE: + fp_event_decoder = ble_gatts_evt_hvn_tx_complete_dec; + break; +#endif +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 + case BLE_L2CAP_EVT_RX: + fp_event_decoder = ble_l2cap_evt_rx_dec; + break; +#endif + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION >= 5 && !defined(S112) + case BLE_L2CAP_EVT_CH_SETUP_REQUEST: + fp_event_decoder = ble_l2cap_evt_ch_setup_request_dec; + break; + + case BLE_L2CAP_EVT_CH_SETUP_REFUSED: + fp_event_decoder = ble_l2cap_evt_ch_setup_refused_dec; + break; + + case BLE_L2CAP_EVT_CH_SETUP: + fp_event_decoder = ble_l2cap_evt_ch_setup_dec; + break; + + case BLE_L2CAP_EVT_CH_RELEASED: + fp_event_decoder = ble_l2cap_evt_ch_released_dec; + break; + + case BLE_L2CAP_EVT_CH_SDU_BUF_RELEASED: + fp_event_decoder = ble_l2cap_evt_ch_sdu_buf_released_dec; + break; + + case BLE_L2CAP_EVT_CH_CREDIT: + fp_event_decoder = ble_l2cap_evt_ch_credit_dec; + break; + + case BLE_L2CAP_EVT_CH_RX: + fp_event_decoder = ble_l2cap_evt_ch_rx_dec; + break; + + case BLE_L2CAP_EVT_CH_TX: + fp_event_decoder = ble_l2cap_evt_ch_tx_dec; + break; + +#endif +#ifndef S112 + case BLE_GAP_EVT_ADV_REPORT: + fp_event_decoder = ble_gap_evt_adv_report_dec; + break; +#endif + case BLE_GAP_EVT_SCAN_REQ_REPORT: + fp_event_decoder = ble_gap_evt_scan_req_report_dec; + break; + default: + break; + } + + if (fp_event_decoder) + { + err_code = fp_event_decoder(p_sub_buffer, sub_packet_len, p_event, p_event_len); + } + else + { + err_code = NRF_ERROR_NOT_FOUND; + } + + *p_event_len += offsetof(ble_evt_t, evt); + p_event->header.evt_id = (err_code == NRF_SUCCESS) ? event_id : 0; + p_event->header.evt_len = (err_code == NRF_SUCCESS) ? (uint16_t)*p_event_len : 0; + + return err_code; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_evt_app.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_evt_app.c new file mode 100644 index 0000000..a5964c6 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_evt_app.c @@ -0,0 +1,129 @@ +/** + * Copyright (c) 2015 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include "ble_serialization.h" +#include "ble_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" +#include "ble_evt_app.h" +#include "app_ble_user_mem.h" + + +// Helper definitions for common event type names to be compliant with +// event serialization macros. +#define ble_common_evt_tx_complete_t ble_evt_tx_complete_t +#define ble_common_evt_user_mem_request_t ble_evt_user_mem_request_t +#define ble_common_evt_user_mem_release_t ble_evt_user_mem_release_t +#define ble_common_evt_data_length_changed_t ble_evt_data_length_changed_t + + +extern ser_ble_user_mem_t m_app_user_mem_table[]; + +uint32_t ble_evt_user_mem_release_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_EVT_USER_MEM_RELEASE, common, user_mem_release); + + SER_PULL_uint16(&p_event->evt.common_evt.conn_handle); + SER_PULL_uint8(&p_event->evt.common_evt.params.user_mem_release.type); + SER_PULL_uint16(&p_event->evt.common_evt.params.user_mem_release.mem_block.len); + + //Set the memory pointer to not-null value. + p_event->evt.common_evt.params.user_mem_release.mem_block.p_mem = (uint8_t *)~0; + SER_PULL_COND(&p_event->evt.common_evt.params.user_mem_release.mem_block.p_mem, NULL); + if (p_event->evt.common_evt.params.user_mem_release.mem_block.p_mem) + { + // Using connection handle find which mem block to release in Application Processor + uint32_t user_mem_table_index; + err_code = app_ble_user_mem_context_find(p_event->evt.common_evt.conn_handle, &user_mem_table_index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + p_event->evt.common_evt.params.user_mem_release.mem_block.p_mem = + m_app_user_mem_table[user_mem_table_index].mem_block.p_mem; + } + + // Now user memory context can be released + err_code = app_ble_user_mem_context_destroy(p_event->evt.common_evt.conn_handle); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_EVT_DEC_END; +} + +uint32_t ble_evt_user_mem_request_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_EVT_USER_MEM_REQUEST, common, user_mem_request); + + SER_PULL_uint16(&p_event->evt.common_evt.conn_handle); + SER_PULL_uint8(&p_event->evt.common_evt.params.user_mem_request.type); + + SER_EVT_DEC_END; +} + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t ble_evt_tx_complete_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_EVT_TX_COMPLETE, common, tx_complete); + + SER_PULL_uint16(&p_event->evt.common_evt.conn_handle); + SER_PULL_uint8(&p_event->evt.common_evt.params.tx_complete.count); + + SER_EVT_DEC_END; +} + + +uint32_t ble_evt_data_length_changed_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_EVT_DATA_LENGTH_CHANGED, common, data_length_changed); + + SER_PULL_uint16(&p_event->evt.common_evt.conn_handle); + SER_PULL_FIELD(&p_event->evt.common_evt.params.data_length_changed, ble_evt_data_length_changed_t_dec); + + SER_EVT_DEC_END; +} +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_evt_app.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_evt_app.h new file mode 100644 index 0000000..67b6135 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_evt_app.h @@ -0,0 +1,157 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef BLE_EVT_APP_H__ +#define BLE_EVT_APP_H__ + +/**@file + * + * @defgroup ble_evt_app Application event decoders + * @{ + * @ingroup ser_app_s130_codecs + * + * @brief Application event decoders. + */ +#include "ble.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +/** + * @brief Decodes the ble_evt_tx_complete event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of the event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to the \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, the required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of the \p p_event buffer. + * \c out: Length of the decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold the decoded event. + */ +uint32_t ble_evt_tx_complete_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); +#endif +/** + * @brief Decodes the ble_evt_user_mem_request event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of the event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to the \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, the required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of the \p p_event buffer. + * \c out: Length of the decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold the decoded event. + */ +uint32_t ble_evt_user_mem_request_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes the ble_evt_user_mem_release event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of the event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to the \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, the required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of the \p p_event buffer. + * \c out: Length of the decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold the decoded event. + */ +uint32_t ble_evt_user_mem_release_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +/** + * @brief Decodes the ble_evt_data_length_changed event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of the event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to the \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, the required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of the \p p_event buffer. + * \c out: Length of the decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold the decoded event. + */ +uint32_t ble_evt_data_length_changed_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); +#endif + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gap_app.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gap_app.c new file mode 100644 index 0000000..ca227e0 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gap_app.c @@ -0,0 +1,1019 @@ +/** + * Copyright (c) 2013 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include "ble_gap_app.h" +#include <stdlib.h> +#include <string.h> +#include "ble_serialization.h" +#include "ble_gap_struct_serialization.h" +#include "ble_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 6 +uint32_t ble_gap_adv_data_set_req_enc(uint8_t const * const p_data, + uint8_t dlen, + uint8_t const * const p_sr_data, + uint8_t srdlen, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_ADV_DATA_SET); + + SER_PUSH_len8data(p_data, dlen); + SER_PUSH_len8data(p_sr_data, srdlen); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_adv_data_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_ADV_DATA_SET); +} +#endif + +uint32_t ble_gap_adv_start_req_enc( +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t adv_handle, +#else + ble_gap_adv_params_t const * const p_adv_params, +#endif +#if NRF_SD_BLE_API_VERSION >= 4 + uint8_t conn_cfg_tag, +#endif + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_ADV_START); + +#if NRF_SD_BLE_API_VERSION > 5 + SER_PUSH_uint8(&adv_handle); +#else + SER_PUSH_COND(p_adv_params, ble_gap_adv_params_t_enc); +#endif + +#if NRF_SD_BLE_API_VERSION >= 4 + SER_PUSH_uint8(&conn_cfg_tag); +#endif + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_adv_start_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_ADV_START); +} + + +uint32_t ble_gap_adv_stop_req_enc( +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t adv_handle, +#endif + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_ADV_STOP); +#if NRF_SD_BLE_API_VERSION > 5 + SER_PUSH_uint8(&adv_handle); +#endif + SER_REQ_ENC_END; +} + +uint32_t ble_gap_adv_stop_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_ADV_STOP); +} + + + +uint32_t ble_gap_appearance_get_req_enc(uint16_t const * const p_appearance, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_APPEARANCE_GET); + SER_PUSH_COND(p_appearance, NULL); + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_appearance_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_appearance, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GAP_APPEARANCE_GET); + SER_PULL_COND(&p_appearance, uint16_t_dec); + SER_RSP_DEC_END; +} + + +uint32_t ble_gap_appearance_set_req_enc(uint16_t appearance, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_APPEARANCE_SET); + SER_PUSH_uint16(&appearance); + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_appearance_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_APPEARANCE_SET); +} + + +uint32_t ble_gap_auth_key_reply_req_enc(uint16_t conn_handle, + uint8_t key_type, + uint8_t const * const p_key, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_AUTH_KEY_REPLY); + + uint8_t key_len; + switch (key_type) + { + case BLE_GAP_AUTH_KEY_TYPE_NONE: + key_len = 0; + break; + + case BLE_GAP_AUTH_KEY_TYPE_PASSKEY: + key_len = 6; + break; + + case BLE_GAP_AUTH_KEY_TYPE_OOB: + key_len = 16; + break; + + default: + return NRF_ERROR_INVALID_PARAM; + } + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_uint8(&key_type); + SER_PUSH_buf(p_key, key_len); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_auth_key_reply_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_AUTH_KEY_REPLY); +} + + + +uint32_t ble_gap_authenticate_req_enc(uint16_t conn_handle, + ble_gap_sec_params_t const * const p_sec_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_AUTHENTICATE); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_sec_params, ble_gap_sec_params_t_enc); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_authenticate_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_AUTHENTICATE); +} + + +uint32_t ble_gap_conn_param_update_req_enc(uint16_t conn_handle, + ble_gap_conn_params_t const * const p_conn_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_CONN_PARAM_UPDATE); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_conn_params, ble_gap_conn_params_t_enc); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_conn_param_update_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_CONN_PARAM_UPDATE); +} + + +uint32_t ble_gap_conn_sec_get_req_enc(uint16_t conn_handle, + ble_gap_conn_sec_t const * const p_conn_sec, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_CONN_SEC_GET); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_conn_sec, NULL); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_conn_sec_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_conn_sec_t * * const pp_conn_sec, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GAP_CONN_SEC_GET); + SER_PULL_COND(pp_conn_sec, ble_gap_conn_sec_t_dec); + SER_RSP_DEC_END; +} + +#ifndef S112 +uint32_t ble_gap_connect_req_enc(ble_gap_addr_t const * const p_peer_addr, + ble_gap_scan_params_t const * const p_scan_params, + ble_gap_conn_params_t const * const p_conn_params, +#if NRF_SD_BLE_API_VERSION >= 4 + uint8_t conn_cfg_tag, +#endif + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_CONNECT); + + SER_PUSH_COND(p_peer_addr, ble_gap_addr_t_enc); + SER_PUSH_COND(p_scan_params, ble_gap_scan_params_t_enc); + SER_PUSH_COND(p_conn_params, ble_gap_conn_params_t_enc); +#if NRF_SD_BLE_API_VERSION >= 4 + SER_PUSH_uint8(&conn_cfg_tag); +#endif + + SER_REQ_ENC_END; +} + +uint32_t ble_gap_connect_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_CONNECT); +} + + +uint32_t ble_gap_connect_cancel_req_enc(uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_CONNECT_CANCEL); + SER_REQ_ENC_END; +} + +uint32_t ble_gap_connect_cancel_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_CONNECT_CANCEL); +} +#endif + +uint32_t ble_gap_device_name_get_req_enc(uint8_t const * const p_dev_name, + uint16_t const * const p_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_DEVICE_NAME_GET); + + SER_PUSH_COND(p_len, uint16_t_enc); + SER_PUSH_COND(p_dev_name, NULL); + + SER_REQ_ENC_END; +} + +uint32_t ble_gap_device_name_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_dev_name, + uint16_t * const p_dev_name_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GAP_DEVICE_NAME_GET); + + SER_PULL_COND(&p_dev_name_len, uint16_t_dec); + if (p_dev_name_len) + { + SER_PULL_uint8array(p_dev_name, *p_dev_name_len); + } + + SER_RSP_DEC_END; +} + + +uint32_t ble_gap_device_name_set_req_enc(ble_gap_conn_sec_mode_t const * const p_write_perm, + uint8_t const * const p_dev_name, + uint16_t len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_DEVICE_NAME_SET); + + SER_ERROR_CHECK(len <= BLE_GAP_DEVNAME_MAX_LEN, NRF_ERROR_INVALID_PARAM); + + SER_PUSH_COND(p_write_perm, ble_gap_conn_sec_mode_t_enc); + SER_PUSH_len16data(p_dev_name, len); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_device_name_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_DEVICE_NAME_SET); +} + + +uint32_t ble_gap_disconnect_req_enc(uint16_t conn_handle, + uint8_t hci_status_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_DISCONNECT); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_uint8(&hci_status_code); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_disconnect_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_DISCONNECT); +} + +#ifndef S112 +uint32_t ble_gap_encrypt_req_enc(uint16_t conn_handle, + ble_gap_master_id_t const * const p_master_id, + ble_gap_enc_info_t const * const p_enc_info, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_ENCRYPT); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_master_id, ble_gap_master_id_t_enc); + SER_PUSH_COND(p_enc_info, ble_gap_enc_info_t_enc); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_encrypt_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_ENCRYPT); +} +#endif + +uint32_t ble_gap_keypress_notify_req_enc(uint16_t conn_handle, + uint8_t kp_not, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_KEYPRESS_NOTIFY); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_uint8(&kp_not); + + SER_REQ_ENC_END; +} + +uint32_t ble_gap_keypress_notify_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_KEYPRESS_NOTIFY); +} + + +uint32_t ble_gap_lesc_dhkey_reply_req_enc(uint16_t conn_handle, + ble_gap_lesc_dhkey_t const *p_dhkey, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_LESC_DHKEY_REPLY); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_dhkey, ble_gap_lesc_dhkey_t_enc); + + SER_REQ_ENC_END; +} + +uint32_t ble_gap_lesc_dhkey_reply_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_LESC_DHKEY_REPLY); +} + + +uint32_t ble_gap_lesc_oob_data_get_req_enc(uint16_t conn_handle, + ble_gap_lesc_p256_pk_t const *p_pk_own, + ble_gap_lesc_oob_data_t *p_oobd_own, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_LESC_OOB_DATA_GET); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_pk_own, ble_gap_lesc_p256_pk_t_enc); + SER_PUSH_COND(p_oobd_own, NULL); + + SER_REQ_ENC_END; +} + +uint32_t ble_gap_lesc_oob_data_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_lesc_oob_data_t * *pp_oobd_own, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GAP_LESC_OOB_DATA_GET); + SER_PULL_COND(pp_oobd_own, ble_gap_lesc_oob_data_t_dec); + SER_RSP_DEC_END; +} + + +uint32_t ble_gap_lesc_oob_data_set_req_enc(uint16_t conn_handle, + ble_gap_lesc_oob_data_t const *p_oobd_own, + ble_gap_lesc_oob_data_t const *p_oobd_peer, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_LESC_OOB_DATA_SET); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_oobd_own, ble_gap_lesc_oob_data_t_enc); + SER_PUSH_COND(p_oobd_peer, ble_gap_lesc_oob_data_t_enc); + + SER_REQ_ENC_END; +} + +uint32_t ble_gap_lesc_oob_data_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_LESC_OOB_DATA_SET); +} + + +uint32_t ble_gap_ppcp_get_req_enc(ble_gap_conn_params_t const * const p_conn_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_PPCP_GET); + SER_PUSH_COND(p_conn_params, NULL); + SER_REQ_ENC_END; +} + +uint32_t ble_gap_ppcp_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_conn_params_t * const p_conn_params, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GAP_PPCP_GET); + SER_PULL_COND(&p_conn_params, ble_gap_conn_params_t_dec); + SER_RSP_DEC_END; +} + + +uint32_t ble_gap_ppcp_set_req_enc(ble_gap_conn_params_t const * const p_conn_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_PPCP_SET); + SER_PUSH_COND(p_conn_params, ble_gap_conn_params_t_enc); + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_ppcp_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_PPCP_SET); +} + +uint32_t ble_gap_rssi_get_req_enc(uint16_t conn_handle, + int8_t const * const p_rssi, +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t const * const p_ch_index, +#endif + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_RSSI_GET); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_rssi, NULL); +#if NRF_SD_BLE_API_VERSION > 5 + SER_PUSH_COND(p_ch_index, NULL); +#endif + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_rssi_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + int8_t * const p_rssi, +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t * const p_ch_index, +#endif + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GAP_RSSI_GET); + SER_PULL_COND(&p_rssi, uint8_t_dec); +#if NRF_SD_BLE_API_VERSION > 5 + SER_PULL_COND(&p_ch_index, uint8_t_dec); +#endif + SER_RSP_DEC_END; +} + + +uint32_t ble_gap_rssi_start_req_enc(uint16_t conn_handle, + uint8_t threshold_dbm, + uint8_t skip_count, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_RSSI_START); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_uint8(&threshold_dbm); + SER_PUSH_uint8(&skip_count); + + SER_REQ_ENC_END; +} + +uint32_t ble_gap_rssi_start_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_RSSI_START); +} + + +uint32_t ble_gap_rssi_stop_req_enc(uint16_t conn_handle, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_RSSI_STOP); + SER_PUSH_uint16(&conn_handle); + SER_REQ_ENC_END; +} + +uint32_t ble_gap_rssi_stop_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_RSSI_STOP); +} + +#ifndef S112 +uint32_t ble_gap_scan_start_req_enc(ble_gap_scan_params_t const * p_scan_params, +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 + ble_data_t const * p_adv_report_buffer, +#endif + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_SCAN_START); + SER_PUSH_COND(p_scan_params, ble_gap_scan_params_t_enc); +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 + SER_PUSH_COND(p_adv_report_buffer, ble_data_t_enc); +#endif + SER_REQ_ENC_END; +} +uint32_t ble_gap_scan_start_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_SCAN_START); +} + + +uint32_t ble_gap_scan_stop_req_enc(uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_SCAN_STOP); + SER_REQ_ENC_END; +} + +uint32_t ble_gap_scan_stop_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_SCAN_STOP); +} +#endif + +uint32_t ble_gap_sec_info_reply_req_enc(uint16_t conn_handle, + ble_gap_enc_info_t const * p_enc_info, + ble_gap_irk_t const * p_id_info, + ble_gap_sign_info_t const * p_sign_info, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_SEC_INFO_REPLY); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_enc_info, ble_gap_enc_info_t_enc); + SER_PUSH_COND(p_id_info, ble_gap_irk_t_enc); + SER_PUSH_COND(p_sign_info, ble_gap_sign_info_t_enc); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_sec_info_reply_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_SEC_INFO_REPLY); +} + + +uint32_t ble_gap_sec_params_reply_req_enc(uint16_t conn_handle, + uint8_t sec_status, + ble_gap_sec_params_t const * const p_sec_params, + ble_gap_sec_keyset_t const * const p_sec_keyset, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_SEC_PARAMS_REPLY); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_uint8(&sec_status); + SER_PUSH_COND(p_sec_params, ble_gap_sec_params_t_enc); + SER_PUSH_COND(p_sec_keyset, ble_gap_sec_keyset_t_enc); + + SER_REQ_ENC_END; +} + +uint32_t ble_gap_sec_params_reply_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_sec_keyset_t const * const p_sec_keyset, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GAP_SEC_PARAMS_REPLY); + SER_PULL_COND(&p_sec_keyset, ble_gap_sec_keyset_t_dec); + SER_RSP_DEC_END; +} + + +uint32_t ble_gap_tx_power_set_req_enc( +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t role, uint16_t handle, +#endif + int8_t tx_power, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_TX_POWER_SET); +#if NRF_SD_BLE_API_VERSION > 5 + SER_PUSH_uint8(&role); + SER_PUSH_uint16(&handle); +#endif + SER_PUSH_int8(&tx_power); + SER_REQ_ENC_END; +} + +uint32_t ble_gap_tx_power_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_TX_POWER_SET); +} + +uint32_t ble_gap_addr_get_req_enc(ble_gap_addr_t const * const p_address, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_ADDR_GET); + SER_PUSH_COND(p_address, NULL); + SER_REQ_ENC_END; +} + +uint32_t ble_gap_addr_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_addr_t * const p_address, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GAP_ADDR_GET); + SER_PULL_FIELD(p_address, ble_gap_addr_t_dec); + SER_RSP_DEC_END; +} + +uint32_t ble_gap_addr_set_req_enc(ble_gap_addr_t const * const p_addr, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_ADDR_SET); + SER_PUSH_COND(p_addr, ble_gap_addr_t_enc); + SER_REQ_ENC_END; +} + +uint32_t ble_gap_addr_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_ADDR_SET); +} + +uint32_t ble_gap_privacy_set_req_enc(ble_gap_privacy_params_t const * p_privacy_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_PRIVACY_SET); + SER_PUSH_COND(p_privacy_params, ble_gap_privacy_params_t_enc); + SER_REQ_ENC_END; +} + +uint32_t ble_gap_privacy_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_PRIVACY_SET); +} + + +uint32_t ble_gap_privacy_get_req_enc(ble_gap_privacy_params_t const * const p_privacy_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_PRIVACY_GET); + SER_PUSH_COND(p_privacy_params, ble_gap_privacy_params_t_enc); + SER_REQ_ENC_END; +} + +uint32_t ble_gap_privacy_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_privacy_params_t const * const p_privacy_params, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GAP_PRIVACY_GET); + SER_PULL_COND((void **)&p_privacy_params, ble_gap_privacy_params_t_dec); + SER_RSP_DEC_END; +} + +uint32_t ble_gap_whitelist_set_req_enc(ble_gap_addr_t const * const * const pp_wl_addrs, + uint8_t const len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_WHITELIST_SET); + + uint8_t presence; + SER_PUSH_uint8(&len); + + if (pp_wl_addrs) + { + presence = SER_FIELD_PRESENT; + SER_PUSH_uint8(&presence); + + for (uint32_t i = 0; i < len; ++i) + { + SER_PUSH_COND(pp_wl_addrs[i], ble_gap_addr_t_enc); + } + } + else + { + presence = SER_FIELD_NOT_PRESENT; + SER_PUSH_uint8(&presence); + } + + SER_REQ_ENC_END; +} + +uint32_t ble_gap_whitelist_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_WHITELIST_SET); +} + +uint32_t ble_gap_device_identities_set_req_enc(ble_gap_id_key_t const * const * const pp_id_keys, + ble_gap_irk_t const * const * const pp_local_irks, + uint8_t const len, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_DEVICE_IDENTITIES_SET); + uint8_t presence; + SER_PUSH_uint8(&len); + + if (pp_id_keys) + { + presence = SER_FIELD_PRESENT; + SER_PUSH_uint8(&presence); + + for (uint32_t i = 0; i < len; ++i) + { + SER_PUSH_COND(pp_id_keys[i], ble_gap_id_key_t_enc); + } + } + else + { + presence = SER_FIELD_NOT_PRESENT; + SER_PUSH_uint8(&presence); + } + + if (pp_local_irks) + { + presence = SER_FIELD_PRESENT; + SER_PUSH_uint8(&presence); + + for (uint32_t i = 0; i < len; ++i) + { + SER_PUSH_COND(pp_local_irks[i], ble_gap_irk_t_enc); + } + } + else + { + presence = SER_FIELD_NOT_PRESENT; + SER_PUSH_uint8(&presence); + } + + SER_REQ_ENC_END; +} + +uint32_t ble_gap_device_identities_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_DEVICE_IDENTITIES_SET); +} +#if NRF_SD_BLE_API_VERSION >= 4 && !defined(S112) +uint32_t ble_gap_data_length_update_req_enc(uint16_t conn_handle, + ble_gap_data_length_params_t const * p_dl_params, + ble_gap_data_length_limitation_t * p_dl_limitation, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_DATA_LENGTH_UPDATE); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_dl_params, ble_gap_data_length_params_t_enc); + SER_PUSH_COND(p_dl_limitation, NULL); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_data_length_update_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_data_length_limitation_t * p_dl_limitation, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GAP_DATA_LENGTH_UPDATE); + SER_PULL_COND((void **)&p_dl_limitation, ble_gap_data_length_limitation_t_dec); + SER_RSP_DEC_END; +} +#endif +#if NRF_SD_BLE_API_VERSION >= 5 +uint32_t ble_gap_phy_update_req_enc(uint16_t conn_handle, + ble_gap_phys_t const * p_gap_phys, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_PHY_UPDATE); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_gap_phys, ble_gap_phys_t_enc); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_phy_update_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_PHY_UPDATE); +} +#endif + +#if NRF_SD_BLE_API_VERSION > 5 +uint32_t ble_gap_adv_set_configure_req_enc(uint8_t * p_adv_handle, + ble_gap_adv_data_t const * p_adv_data, + ble_gap_adv_params_t const *p_adv_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_ADV_SET_CONFIGURE); + + SER_PUSH_COND(p_adv_handle, uint8_t_enc); + SER_PUSH_COND(p_adv_data, ble_gap_adv_data_t_enc); + SER_PUSH_COND(p_adv_params, ble_gap_adv_params_t_enc); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_adv_set_configure_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * p_adv_handle, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GAP_ADV_SET_CONFIGURE); + SER_PULL_COND((void **)&p_adv_handle, uint8_t_dec); + SER_RSP_DEC_END; +} + +#ifndef S112 +uint32_t ble_gap_qos_channel_survey_start_req_enc(uint32_t interval_us, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_QOS_CHANNEL_SURVEY_START); + + SER_PUSH_uint32(&interval_us); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_qos_channel_survey_start_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_QOS_CHANNEL_SURVEY_START); +} + +uint32_t ble_gap_qos_channel_survey_stop_req_enc(uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GAP_QOS_CHANNEL_SURVEY_STOP); + SER_REQ_ENC_END; +} + + +uint32_t ble_gap_qos_channel_survey_stop_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GAP_QOS_CHANNEL_SURVEY_STOP); +} +#endif //!S112 +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gap_app.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gap_app.h new file mode 100644 index 0000000..715a8df --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gap_app.h @@ -0,0 +1,1667 @@ +/** + * Copyright (c) 2013 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef BLE_GAP_APP_H__ +#define BLE_GAP_APP_H__ + +/**@file + * + * @defgroup ble_gap_app GAP Application command request encoders and command response decoders + * @{ + * @ingroup ser_app_s130_codecs + * + * @brief GAP Application command request encoders and command response decoders. + */ +#include "ble.h" +#include "ble_gap.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(NRF_SD_BLE_API_VERSION) && (NRF_SD_BLE_API_VERSION <= 5) +/** + * @brief Encodes @ref sd_ble_gap_adv_data_set command request. + * + * @sa @ref ble_gap_adv_data_set_rsp_dec for command response decoder. + * + * @param[in] p_data Raw data to be placed in advertisement packet. If NULL, no changes + * are made to the current advertisement packet data. + * @param[in] dlen Data length for p_data. Max size: @ref BLE_GAP_ADV_SR_MAX_LEN_DEFAULT octets. + * Should be 0 if p_data is NULL, can be 0 if p_data is not NULL. + * @param[in] p_sr_data Raw data to be placed in scan response packet. If NULL, + * no changes are made to the current scan response packet data. + * @param[in] srdlen Data length for p_sr_data. Max size: @ref BLE_GAP_ADV_SR_MAX_LEN_DEFAULT octets. + * Should be 0 if p_sr_data is NULL, can be 0 if p_data is not NULL. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_adv_data_set_req_enc(uint8_t const * const p_data, + uint8_t dlen, + uint8_t const * const p_sr_data, + uint8_t srdlen, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_gap_adv_data_set command. + * + * @sa @ref ble_gap_adv_data_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_gap_adv_data_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); +#endif + +/** + * @brief Encodes @ref sd_ble_gap_adv_start command request. + * + * @sa @ref ble_gap_adv_start_rsp_dec for command response decoder. + * + * @param[in] p_adv_params Pointer to advertising parameters structure. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_adv_start_req_enc( +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t adv_handle, +#else + ble_gap_adv_params_t const * const p_adv_params, +#endif +#if NRF_SD_BLE_API_VERSION >= 4 + uint8_t conn_cfg_tag, +#endif + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_gap_adv_start command. + * + * @sa @ref ble_gap_adv_start_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_gap_adv_start_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/** + * @brief Encodes @ref sd_ble_gap_tx_power_set command request. + * + * @sa @ref ble_gap_tx_power_set_rsp_dec for command response decoder. + * + * @param[in] tx_power Radio transmit power in dBm (accepted values are -40, -30, -20, -16, -12, -8, -4, 0, and 4 dBm). + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_tx_power_set_req_enc( +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t role, uint16_t handle, +#endif + int8_t tx_power, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_gap_tx_power_set command. + * + * @sa @ref ble_gap_tx_power_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_gap_tx_power_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/** + * @brief Encodes @ref sd_ble_gap_appearance_get command request. + * + * @sa @ref ble_gap_appearance_get_rsp_dec for command response decoder. + * + * @param[in] p_appearance Appearance (16 bit), see @ref BLE_APPEARANCES. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @note \p p_appearance will not be updated by the command + * request encoder. Updated values are set by @ref ble_gap_appearance_get_rsp_dec. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_appearance_get_req_enc(uint16_t const * const p_appearance, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_gap_appearance_get command. + * + * @sa @ref ble_gap_appearance_get_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_appearance Appearance (16 bit), see @ref BLE_APPEARANCES. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_gap_appearance_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_appearance, + uint32_t * const p_result_code); + +/** + * @brief Encodes @ref sd_ble_gap_appearance_set command request. + * + * @sa @ref ble_gap_appearance_set_rsp_dec for command response decoder. + * + * @param[in] appearance Appearance (16 bit), see @ref BLE_APPEARANCES. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_appearance_set_req_enc(uint16_t appearance, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_gap_appearance_set command. + * + * @sa @ref ble_gap_appearance_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_gap_appearance_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/** + * @brief Encodes @ref sd_ble_gap_device_name_get command request. + * + * @sa @ref ble_gap_device_name_get_rsp_dec for command response decoder. + * + * @param[in] p_dev_name Pointer to an empty buffer where the UTF-8 <b>non NULL-terminated</b> + * string will be placed. Set to NULL to obtain the complete device + * name length. + * @param[in] p_dev_name_len Length of the buffer pointed by p_dev_name. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @note \p p_dev_name and \p p_len will not be updated by the command + * request encoder. Updated values are set by @ref ble_gap_device_name_get_rsp_dec. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_device_name_get_req_enc(uint8_t const * const p_dev_name, + uint16_t const * const p_dev_name_len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_gap_device_name_get command. + * + * @sa @ref ble_gap_device_name_get_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_dev_name Pointer to an empty buffer where the UTF-8 + * <b>non NULL-terminated</b> string will be placed. + * @param[in,out] p_dev_name_len Length of the buffer pointed by p_dev_name, complete device name + * length on output. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_gap_device_name_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * const p_dev_name, + uint16_t * const p_dev_name_len, + uint32_t * const p_result_code); + +/** + * @brief Encodes @ref sd_ble_gap_device_name_set command request. + * + * @sa @ref ble_gap_device_name_set_rsp_dec for command response decoder. + * + * @param[in] p_write_perm Write permissions for the Device Name characteristic, see + * @ref ble_gap_conn_sec_mode_t. + * @param[in] p_dev_name Pointer to a UTF-8 encoded, <b>non NULL-terminated</b> string. + * @param[in] len Length of the UTF-8, <b>non NULL-terminated</b> string pointed + * to by p_dev_name in octets (must be smaller or equal + * than @ref BLE_GAP_DEVNAME_MAX_LEN). + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_device_name_set_req_enc(ble_gap_conn_sec_mode_t const * const p_write_perm, + uint8_t const * const p_dev_name, + uint16_t len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_gap_device_name_set command. + * + * @sa @ref ble_gap_device_name_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_gap_device_name_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/** + * @brief Encodes @ref sd_ble_gap_ppcp_set command request. + * + * @sa @ref ble_gap_ppcp_set_rsp_dec for command response decoder. + * + * @param[in] p_conn_params Pointer to a @ref ble_gap_conn_params_t structure with the + * desired parameters. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_ppcp_set_req_enc(ble_gap_conn_params_t const * const p_conn_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_gap_ppcp_set command. + * + * @sa @ref ble_gap_ppcp_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_gap_ppcp_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_conn_param_update command request. + * + * @sa @ref ble_gap_conn_param_update_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] p_conn_params Pointer to desired connection parameters. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_conn_param_update_req_enc(uint16_t conn_handle, + ble_gap_conn_params_t const * const p_conn_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_conn_param_update command. + * + * @sa @ref ble_gap_conn_param_update_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gap_conn_param_update_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_disconnect command request. + * + * @sa @ref ble_gap_disconnect_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] hci_status_code HCI status code, see @ref BLE_HCI_STATUS_CODES. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_disconnect_req_enc(uint16_t conn_handle, + uint8_t hci_status_code, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_disconnect command. + * + * @sa @ref ble_gap_disconnect_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gap_disconnect_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + + +/**@brief Encodes @ref sd_ble_gap_rssi_stop command request. + * + * @sa @ref ble_gap_rssi_stop_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_rssi_stop_req_enc(uint16_t conn_handle, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_rssi_stop command. + * + * @sa @ref ble_gap_rssi_stop_rsp_dec for command response decoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gap_rssi_stop_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + + + + +/**@brief Encodes @ref sd_ble_gap_ppcp_get command request. + * + * @sa @ref ble_gap_ppcp_get_rsp_dec for command response decoder. + * + * @param[in] p_conn_params Pointer to a @ref ble_gap_conn_params_t structure where the + * parameters will be stored. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @note \p p_conn_params will not be updated by the command request encoder. Updated values are + * set by @ref ble_gap_ppcp_get_rsp_dec. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_ppcp_get_req_enc(ble_gap_conn_params_t const * const p_conn_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_ppcp_get command. + * + * @sa @ref ble_gap_ppcp_get_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_params Pointer to a @ref ble_gap_conn_params_t structure where the parameters + * will be stored. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gap_ppcp_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_conn_params_t * const p_conn_params, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_auth_key_reply command request. + * + * @sa @ref ble_gap_auth_key_reply_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] key_type Key type which defines length of key data as defined for + * @ref sd_ble_gap_auth_key_reply . + * @param[in] p_key Pointer to a buffer which contains key + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Encoding failure. Incorrect param provided (key_type). + */ +uint32_t ble_gap_auth_key_reply_req_enc(uint16_t conn_handle, + uint8_t key_type, + uint8_t const * const p_key, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_auth_key_reply command. + * + * @sa @ref ble_gap_auth_key_reply_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gap_auth_key_reply_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_sec_info_reply command request. + * + * @sa @ref ble_gap_sec_info_reply_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] p_enc_info Pointer to a @ref ble_gap_enc_info_t encryption information + * structure. + * @param[in] p_id_info Pointer to a @ref ble_gap_irk_t id information + * structure. + * @param[in] p_sign_info Pointer to a @ref ble_gap_sign_info_t signing information + * structure. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_sec_info_reply_req_enc(uint16_t conn_handle, + ble_gap_enc_info_t const * p_enc_info, + ble_gap_irk_t const * p_id_info, + ble_gap_sign_info_t const * p_sign_info, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_sec_info_reply command. + * + * @sa @ref ble_gap_sec_info_reply_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gap_sec_info_reply_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_sec_params_reply command request. + * + * @sa @ref ble_gap_sec_params_reply_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] sec_status Security status, see @ref BLE_GAP_SEC_STATUS. + * @param[in] p_sec_params Pointer to @ref ble_gap_sec_params_t security parameters + * structure. + * @param[in] p_sec_keyset Pointer to @ref ble_gap_sec_keyset_t security keys + * structure. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_sec_params_reply_req_enc(uint16_t conn_handle, + uint8_t sec_status, + ble_gap_sec_params_t const * const p_sec_params, + ble_gap_sec_keyset_t const * const p_sec_keyset, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_sec_params_reply command. + * + * @sa @ref ble_gap_sec_params_reply_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[in] p_sec_keyset Pointer to @ref ble_gap_sec_keyset_t security keys + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gap_sec_params_reply_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_sec_keyset_t const * const p_sec_keyset, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_authenticate command request. + * + * @sa @ref ble_gap_authenticate_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] p_sec_params Pointer to a @ref ble_gap_sec_params_t security parameters + * structure. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_authenticate_req_enc(uint16_t conn_handle, + ble_gap_sec_params_t const * const p_sec_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_authenticate command. + * + * @sa @ref ble_gap_authenticate_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gap_authenticate_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_adv_stop command request. + * + * @sa @ref ble_gap_adv_stop_rsp_dec for command response decoder. + * + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_adv_stop_req_enc( +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t adv_handle, +#endif + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_adv_stop command. + * + * @sa @ref ble_gap_adv_stop_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gap_adv_stop_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_conn_sec_get command request. + * + * @sa @ref ble_gap_conn_sec_get_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] p_conn_sec Pointer to \ref ble_gap_conn_sec_t which will be filled in + * response. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_conn_sec_get_req_enc(uint16_t conn_handle, + ble_gap_conn_sec_t const * const p_conn_sec, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_conn_sec_get command. + * + * @sa @ref ble_gap_conn_sec_get_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] pp_conn_sec Pointer to pointer to \ref ble_gap_conn_sec_t which will be filled by + * the decoded data (if present). + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gap_conn_sec_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_conn_sec_t * * const pp_conn_sec, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_rssi_start command request. + * + * @sa @ref ble_gap_rssi_start_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] threshold_dbm Threshold in dBm. + * @param[in] skip_count Sample skip count. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_rssi_start_req_enc(uint16_t conn_handle, + uint8_t threshold_dbm, + uint8_t skip_count, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_rssi_start command. + * + * @sa @ref ble_gap_rssi_start_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gap_rssi_start_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); +#ifndef S112 +/**@brief Encodes @ref sd_ble_gap_scan_stop command request. + * + * @sa @ref ble_gap_scan_stop_rsp_dec for command response decoder. + * + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_scan_stop_req_enc(uint8_t * const p_buf, uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_scan_stop command. + * + * @sa @ref ble_gap_scan_stop_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gap_scan_stop_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_scan_start command request. + * + * @sa @ref ble_gap_scan_start_rsp_dec for command response decoder. + * + * @param[in] p_scan_params Pointer to scan params structure. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_scan_start_req_enc(ble_gap_scan_params_t const * p_scan_params, +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 + ble_data_t const * p_adv_report_buffer, +#endif + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_scan_start command. + * + * @sa @ref ble_gap_scan_start_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gap_scan_start_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_connect command request. + * + * @sa @ref ble_gap_connect_rsp_dec for command response decoder. + * + * @param[in] p_peer_addr Pointer to peer address. + * @param[in] p_scan_params Pointer to scan params structure. + * @param[in] p_conn_params Pointer to desired connection parameters. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_connect_req_enc(ble_gap_addr_t const * const p_peer_addr, + ble_gap_scan_params_t const * const p_scan_params, + ble_gap_conn_params_t const * const p_conn_params, +#if NRF_SD_BLE_API_VERSION >= 4 + uint8_t conn_cfg_tag, +#endif + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_connect command. + * + * @sa @ref ble_gap_connect_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gap_connect_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_connect_cancel command request. + * + * @sa @ref ble_gap_connect_cancel_rsp_dec for command response decoder. + * + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_connect_cancel_req_enc(uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_connect_cancel command. + * + * @sa @ref ble_gap_connect_cancel_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gap_connect_cancel_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + + +/**@brief Encodes @ref sd_ble_gap_encrypt command request. + * + * @sa @ref ble_gap_encrypt_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle. + * @param[in] p_master_id Pointer to a master identification structure. + * @param[in] p_enc_info Pointer to desired connection parameters. + * @param[in] p_buf Pointer to a ble_gap_enc_info_t encryption information structure. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ + +uint32_t ble_gap_encrypt_req_enc(uint16_t conn_handle, + ble_gap_master_id_t const * const p_master_id, + ble_gap_enc_info_t const * const p_enc_info, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + + +/**@brief Decodes response to @ref sd_ble_gap_encrypt command. + * + * @sa @ref ble_gap_encrypt_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gap_encrypt_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); +#endif //!S112 + +/**@brief Encodes @ref sd_ble_gap_rssi_get command request. + * + * @sa @ref ble_gap_rssi_get_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle. + * @param[in] p_rssi Pointer to the RSSI value. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_rssi_get_req_enc(uint16_t conn_handle, + int8_t const * const p_rssi, +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t const * const p_ch_index, +#endif + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_rssi_get command. + * + * @sa @ref ble_gap_rssi_get_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_rssi Pointer to RSSI value. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gap_rssi_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + int8_t * const p_rssi, +#if NRF_SD_BLE_API_VERSION > 5 + uint8_t * const p_ch_index, +#endif + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_keypress_notify command request. + * + * @sa @ref ble_gap_keypress_notify_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle. + * @param[in] kp_not See @ref sd_ble_gap_keypress_notify. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_keypress_notify_req_enc(uint16_t conn_handle, + uint8_t kp_not, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_keypress_notify command. + * + * @sa @ref ble_gap_keypress_notify_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gap_keypress_notify_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_lesc_dhkey_reply command request. + * + * @sa @ref ble_gap_lesc_dhkey_reply_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle. + * @param[in] p_dhkey See @ref sd_ble_gap_lesc_dhkey_reply. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_lesc_dhkey_reply_req_enc(uint16_t conn_handle, + ble_gap_lesc_dhkey_t const *p_dhkey, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_lesc_dhkey_reply command. + * + * @sa @ref ble_gap_lesc_dhkey_reply_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gap_lesc_dhkey_reply_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_lesc_oob_data_set command request. + * + * @sa @ref ble_gap_lesc_oob_data_set_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle. + * @param[in] p_oobd_own See @ref sd_ble_gap_lesc_oob_data_set. + * @param[in] p_oobd_peer See @ref sd_ble_gap_lesc_oob_data_set. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_lesc_oob_data_set_req_enc(uint16_t conn_handle, + ble_gap_lesc_oob_data_t const *p_oobd_own, + ble_gap_lesc_oob_data_t const *p_oobd_peer, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_lesc_oob_data_set command. + * + * @sa @ref ble_gap_lesc_oob_data_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gap_lesc_oob_data_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_lesc_oob_data_get command request. + * + * @sa @ref ble_gap_lesc_oob_data_get_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle. + * @param[in] p_pk_own See @ref sd_ble_gap_lesc_oob_data_get. + * @param[in] p_oobd_own See @ref sd_ble_gap_lesc_oob_data_get. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_lesc_oob_data_get_req_enc(uint16_t conn_handle, + ble_gap_lesc_p256_pk_t const *p_pk_own, + ble_gap_lesc_oob_data_t *p_oobd_own, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_lesc_oob_data_get command. + * + * @sa @ref ble_gap_lesc_oob_data_get_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] pp_oobd_own Pointer to pointer to location where OOB data is decoded. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gap_lesc_oob_data_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_lesc_oob_data_t * *pp_oobd_own, + uint32_t * const p_result_code); + +/** + * @brief Encodes @ref sd_ble_gap_addr_get command request. + * + * @sa @ref ble_gap_addr_get_rsp_dec for command response decoder. + * + * @param[in] p_address Pointer to address. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @note \p p_address will not be updated by the command + * request encoder. Updated values are set by @ref ble_gap_addr_get_rsp_dec. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_addr_get_req_enc(ble_gap_addr_t const * const p_address, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_gap_addr_get command. + * + * @sa @ref ble_gap_addr_get_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_address Pointer to address. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_gap_addr_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_addr_t * const p_address, + uint32_t * const p_result_code); + +/** + * @brief Encodes @ref sd_ble_gap_addr_set command request. + * + * @sa @ref ble_gap_addr_set_rsp_dec for command response decoder. + * + * @param[in] p_addr Pointer to address structure. + * @param[in,out] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_addr_set_req_enc(ble_gap_addr_t const * const p_addr, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_gap_addr_set command. + * + * @sa @ref ble_gap_addr_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_gap_addr_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/** + * @brief Encodes @ref sd_ble_gap_privacy_set command request. + * + * @sa @ref ble_gap_privacy_set_rsp_dec for command response decoder. + * + * @param[in] p_privacy_params Pointer to privacy settings structure. + * @param[in,out] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_privacy_set_req_enc(ble_gap_privacy_params_t const * p_privacy_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_gap_privacy_set command. + * + * @sa @ref ble_gap_privacy_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_gap_privacy_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/** + * @brief Encodes @ref sd_ble_gap_privacy_get command request. + * + * @sa @ref ble_gap_privacy_get_rsp_dec for command response decoder. + * + * @param[in] p_privacy_params Pointer to privacy settings structure. + * @param[in,out] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_privacy_get_req_enc(ble_gap_privacy_params_t const * const p_privacy_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_gap_privacy_get command. + * + * @sa @ref ble_gap_privacy_get_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_privacy_params Pointer to privacy settings structure. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_gap_privacy_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_privacy_params_t const * const p_privacy_params, + uint32_t * const p_result_code); + +/** + * @brief Encodes @ref sd_ble_gap_whitelist_set command request. + * + * @sa @ref ble_gap_whitelist_set_rsp_dec for command response decoder. + * + * @param[in] pp_wl_addrs Pointer to a whitelist of peer addresses. + * @param[out] len Pointer to a length of the whitelist. + * @param[in,out] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_whitelist_set_req_enc(ble_gap_addr_t const * const * const pp_wl_addrs, + uint8_t const len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_gap_whitelist_set command. + * + * @sa @ref ble_gap_whitelist_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_gap_whitelist_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/** + * @brief Encodes @ref sd_ble_gap_device_identities_set command request. + * + * @sa @ref ble_gap_device_identities_set_rsp_dec for command response decoder. + * + * @param[in] pp_id_keys Pointer to an array of peer identity addresses and peer IRKs. + * @param[in] pp_local_irks Pointer to an array of local IRKs. + * @param[out] len Pointer to a length of the device identity list. + * @param[in,out] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_device_identities_set_req_enc(ble_gap_id_key_t const * const * const pp_id_keys, + ble_gap_irk_t const * const * const pp_local_irks, + uint8_t const len, + uint8_t * const p_buf, + uint32_t * const p_buf_len); +/** + * @brief Decodes response to @ref sd_ble_gap_device_identities_set command. + * + * @sa @ref ble_gap_device_identities_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_gap_device_identities_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +#if NRF_SD_BLE_API_VERSION >= 4 && !defined(S112) +/** + * @brief Encodes @ref sd_ble_gap_data_length_update command request. + * + * @sa @ref ble_gap_data_length_update_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle. + * @param[in] p_dl_params Pointer to a data length params structure. + * @param[out] p_dl_limitation Pointer to a data length limitation structure. + * @param[in,out] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_data_length_update_req_enc(uint16_t conn_handle, + ble_gap_data_length_params_t const * p_dl_params, + ble_gap_data_length_limitation_t * p_dl_limitation, + uint8_t * const p_buf, + uint32_t * const p_buf_len); +/** + * @brief Decodes response to @ref sd_ble_gap_data_length_update command. + * + * @sa @ref ble_gap_data_length_update_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_dl_limitation Pointer to a data length limitation structure. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_gap_data_length_update_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gap_data_length_limitation_t * p_dl_limitation, + uint32_t * const p_result_code); +#endif + +#if NRF_SD_BLE_API_VERSION >= 5 +/**@brief Encodes @ref sd_ble_gap_phy_update command request. + * + * @sa @ref ble_gap_phy_update_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] p_gap_phys Pointer to a @ref ble_gap_phys_t + * structure. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_phy_update_req_enc(uint16_t conn_handle, + ble_gap_phys_t const * p_gap_phys, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gap_phy_update command. + * + * @sa @ref ble_gap_phy_update_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gap_phy_update_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); +#endif + +#if NRF_SD_BLE_API_VERSION >= 6 +/**@brief Encodes @ref sd_ble_gap_adv_set_configure command request. + * + * @sa @ref ble_gap_adv_set_configure_rsp_dec for command response decoder. + * + * @param[in] p_adv_handle Advertising handle. + * @param[in] p_adv_data Pointer to a @ref ble_gap_adv_data_t structure. + * @param[in] p_adv_params Pointer to a @ref ble_gap_adv_params_t structure. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_adv_set_configure_req_enc(uint8_t * p_adv_handle, + ble_gap_adv_data_t const * p_adv_data, + ble_gap_adv_params_t const *p_adv_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + + +/**@brief Decodes response to @ref sd_ble_gap_adv_set_configure command. + * + * @sa @ref ble_gap_adv_set_configure_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_adv_handle Advertising handle. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gap_adv_set_configure_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * p_adv_handle, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_qos_channel_survey_start command request. + * + * @sa @ref ble_gap_qos_channel_survey_start_rsp_dec for command response decoder. + * + * @param[in] interval_us Interval. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_qos_channel_survey_start_req_enc(uint32_t interval_us, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + + +/**@brief Decodes response to @ref sd_ble_gap_qos_channel_survey_start command. + * + * @sa @ref ble_gap_qos_channel_survey_start_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gap_qos_channel_survey_start_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gap_qos_channel_survey_stop command request. + * + * @sa @ref ble_gap_qos_channel_survey_stop_rsp_dec for command response decoder. + * + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gap_qos_channel_survey_stop_req_enc(uint8_t * const p_buf, + uint32_t * const p_buf_len); + + +/**@brief Decodes response to @ref sd_ble_gap_qos_channel_survey_stop command. + * + * @sa @ref ble_gap_qos_channel_survey_stop_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gap_qos_channel_survey_stop_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); +#endif +/** @} */ +#ifdef __cplusplus +} +#endif + +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gap_evt_app.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gap_evt_app.c new file mode 100644 index 0000000..150a891 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gap_evt_app.c @@ -0,0 +1,415 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include "ble_gap_evt_app.h" +#include "ble_serialization.h" +#include "app_util.h" +#include "app_ble_gap_sec_keys.h" +#include "ble_gap_struct_serialization.h" +#include "cond_field_serialization.h" +#include <string.h> + +extern ser_ble_gap_app_keyset_t m_app_keys_table[]; + +#ifndef S112 +uint32_t ble_gap_evt_adv_report_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GAP_EVT_ADV_REPORT, gap, adv_report); + + SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle); + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION >= 6 + //get buffer stored during scan start. + err_code = app_ble_gap_scan_data_fetch_clear(&p_event->evt.gap_evt.params.adv_report.data); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); +#endif + SER_PULL_FIELD(&p_event->evt.gap_evt.params.adv_report, ble_gap_evt_adv_report_t_dec); + + SER_EVT_DEC_END; +} +#endif //!S112 + +uint32_t ble_gap_evt_auth_key_request_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GAP_EVT_AUTH_KEY_REQUEST, gap, auth_key_request); + + SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PULL_uint8(&p_event->evt.gap_evt.params.auth_key_request.key_type); + + SER_EVT_DEC_END; +} + + +extern ser_ble_gap_app_keyset_t m_app_keys_table[]; + +uint32_t ble_gap_evt_auth_status_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GAP_EVT_AUTH_STATUS, gap, auth_status); + + SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PULL_FIELD(&p_event->evt.gap_evt.params.auth_status, ble_gap_evt_auth_status_t_dec); + + // keyset is an extension of standard event data - used to synchronize keys at application + uint32_t conn_index; + err_code = app_ble_gap_sec_context_find(p_event->evt.gap_evt.conn_handle, &conn_index); + if (err_code == NRF_SUCCESS) + { + SER_PULL_FIELD(&(m_app_keys_table[conn_index].keyset), ble_gap_sec_keyset_t_dec); + + err_code = app_ble_gap_sec_context_destroy(p_event->evt.gap_evt.conn_handle); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + } + + SER_EVT_DEC_END; +} + + +uint32_t ble_gap_evt_conn_param_update_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GAP_EVT_CONN_PARAM_UPDATE, gap, conn_param_update); + + SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PULL_FIELD(&p_event->evt.gap_evt.params.conn_param_update, ble_gap_evt_conn_param_update_t_dec); + + SER_EVT_DEC_END; +} + + +#ifndef S112 +uint32_t ble_gap_evt_conn_param_update_request_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST, gap, conn_param_update_request); + + SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PULL_FIELD(&p_event->evt.gap_evt.params.conn_param_update_request, + ble_gap_evt_conn_param_update_request_t_dec); + + SER_EVT_DEC_END; +} +#endif + +uint32_t ble_gap_evt_conn_sec_update_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GAP_EVT_CONN_SEC_UPDATE, gap, conn_sec_update); + + SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PULL_FIELD(&p_event->evt.gap_evt.params.conn_sec_update, ble_gap_evt_conn_sec_update_t_dec); + + SER_EVT_DEC_END; +} + +uint32_t ble_gap_evt_connected_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GAP_EVT_CONNECTED, gap, connected); + + SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PULL_FIELD(&p_event->evt.gap_evt.params.connected, ble_gap_evt_connected_t_dec); +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 + if (BLE_GAP_ROLE_PERIPH == p_event->evt.gap_evt.params.connected.role) + { + err_code = app_ble_gap_adv_set_unregister(p_event->evt.gap_evt.params.connected.adv_handle, + &p_event->evt.gap_evt.params.connected.adv_data.adv_data.p_data, + &p_event->evt.gap_evt.params.connected.adv_data.scan_rsp_data.p_data); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + } +#endif + SER_EVT_DEC_END; +} + + +uint32_t ble_gap_evt_disconnected_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GAP_EVT_DISCONNECTED, gap, disconnected); + + SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PULL_FIELD(&p_event->evt.gap_evt.params.disconnected, ble_gap_evt_disconnected_t_dec); + + SER_EVT_DEC_END; +} + +uint32_t ble_gap_evt_key_pressed_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GAP_EVT_KEY_PRESSED, gap, key_pressed); + + SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PULL_uint8(&p_event->evt.gap_evt.params.key_pressed.kp_not); + + SER_EVT_DEC_END; +} + + +uint32_t ble_gap_evt_lesc_dhkey_request_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GAP_EVT_LESC_DHKEY_REQUEST, gap, lesc_dhkey_request); + + uint8_t ser_data; + SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle); + + // keyset is an extension of standard event data - used to synchronize keys at application + uint32_t conn_index; + err_code = app_ble_gap_sec_context_find(p_event->evt.gap_evt.conn_handle, &conn_index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + p_event->evt.gap_evt.params.lesc_dhkey_request.p_pk_peer = m_app_keys_table[conn_index].keyset.keys_peer.p_pk; + SER_PULL_COND(&p_event->evt.gap_evt.params.lesc_dhkey_request.p_pk_peer, ble_gap_lesc_p256_pk_t_dec); + + SER_PULL_uint8(&ser_data); + p_event->evt.gap_evt.params.lesc_dhkey_request.oobd_req = ser_data & 0x01; + + SER_EVT_DEC_END; +} + + +#define PASSKEY_LEN sizeof (p_event->evt.gap_evt.params.passkey_display.passkey) + + +uint32_t ble_gap_evt_passkey_display_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GAP_EVT_PASSKEY_DISPLAY, gap, passkey_display); + + uint8_t ser_data; + SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PULL_uint8array(p_event->evt.gap_evt.params.passkey_display.passkey, BLE_GAP_PASSKEY_LEN); + SER_PULL_uint8(&ser_data); + p_event->evt.gap_evt.params.passkey_display.match_request = (ser_data & 0x01); + + SER_EVT_DEC_END; +} + + + +uint32_t ble_gap_evt_rssi_changed_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GAP_EVT_RSSI_CHANGED, gap, rssi_changed); + + SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PULL_int8(&p_event->evt.gap_evt.params.rssi_changed.rssi); +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 + SER_PULL_uint8(&p_event->evt.gap_evt.params.rssi_changed.ch_index); +#endif + SER_EVT_DEC_END; +} + + +uint32_t ble_gap_evt_scan_req_report_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GAP_EVT_SCAN_REQ_REPORT, gap, scan_req_report); + + SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle); +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 + SER_PULL_uint8(&p_event->evt.gap_evt.params.scan_req_report.adv_handle); +#endif + SER_PULL_FIELD(&p_event->evt.gap_evt.params.scan_req_report.peer_addr, ble_gap_addr_t_dec); + SER_PULL_int8(&p_event->evt.gap_evt.params.scan_req_report.rssi); + + SER_EVT_DEC_END; +} + +uint32_t ble_gap_evt_sec_info_request_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GAP_EVT_SEC_INFO_REQUEST, gap, sec_info_request); + + SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PULL_FIELD(&p_event->evt.gap_evt.params.sec_info_request, ble_gap_evt_sec_info_request_t_dec); + + SER_EVT_DEC_END; +} + +uint32_t ble_gap_evt_sec_params_request_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GAP_EVT_SEC_PARAMS_REQUEST, gap, sec_params_request); + + SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PULL_FIELD(&p_event->evt.gap_evt.params.sec_params_request, ble_gap_evt_sec_params_request_t_dec); + + SER_EVT_DEC_END; +} + +uint32_t ble_gap_evt_sec_request_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GAP_EVT_SEC_REQUEST, gap, sec_request); + + SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PULL_FIELD(&p_event->evt.gap_evt.params.sec_request, ble_gap_evt_sec_request_t_dec); + + SER_EVT_DEC_END; +} + +uint32_t ble_gap_evt_timeout_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GAP_EVT_TIMEOUT, gap, timeout); + + SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PULL_uint8(&p_event->evt.gap_evt.params.timeout.src); +#if defined(NRF_SD_BLE_API_VERSION) && (NRF_SD_BLE_API_VERSION > 5) && !defined(S112) + if (p_event->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_SCAN) + { + SER_PULL_uint16(&p_event->evt.gap_evt.params.timeout.params.adv_report_buffer.len); + err_code = app_ble_gap_scan_data_fetch_clear(&p_event->evt.gap_evt.params.timeout.params.adv_report_buffer); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + } +#endif + SER_EVT_DEC_END; +} + +#if NRF_SD_BLE_API_VERSION >= 5 +uint32_t ble_gap_evt_phy_update_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GAP_EVT_PHY_UPDATE, gap, phy_update); + + SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PULL_uint8(&p_event->evt.gap_evt.params.phy_update.status); + SER_PULL_uint8(&p_event->evt.gap_evt.params.phy_update.tx_phy); + SER_PULL_uint8(&p_event->evt.gap_evt.params.phy_update.rx_phy); + + SER_EVT_DEC_END; +} + +uint32_t ble_gap_evt_phy_update_request_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GAP_EVT_PHY_UPDATE_REQUEST, gap, phy_update); + + SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PULL_FIELD(&p_event->evt.gap_evt.params.phy_update_request, ble_gap_phys_t_dec); + + SER_EVT_DEC_END; +} +#endif +#if NRF_SD_BLE_API_VERSION >= 4 && !defined(S112) +uint32_t ble_gap_evt_data_length_update_request_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST, gap, timeout); + + SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PULL_FIELD(&p_event->evt.gap_evt.params.data_length_update_request.peer_params, ble_gap_data_length_params_t_dec); + + SER_EVT_DEC_END; +} +uint32_t ble_gap_evt_data_length_update_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GAP_EVT_DATA_LENGTH_UPDATE, gap, timeout); + + SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PULL_FIELD(&p_event->evt.gap_evt.params.data_length_update.effective_params, ble_gap_data_length_params_t_dec); + + SER_EVT_DEC_END; +} +#endif //NRF_SD_BLE_API_VERSION >= 4 @@ !defined(S112) +#if NRF_SD_BLE_API_VERSION > 5 +uint32_t ble_gap_evt_adv_set_terminated_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GAP_EVT_ADV_SET_TERMINATED, gap, adv_set_terminated); + + SER_PULL_uint16(&p_event->evt.gap_evt.conn_handle); + SER_PULL_FIELD(&p_event->evt.gap_evt.params.adv_set_terminated, ble_gap_evt_adv_set_terminated_t_dec); + + err_code = app_ble_gap_adv_set_unregister( + p_event->evt.gap_evt.params.adv_set_terminated.adv_handle, + &p_event->evt.gap_evt.params.adv_set_terminated.adv_data.adv_data.p_data, + &p_event->evt.gap_evt.params.adv_set_terminated.adv_data.scan_rsp_data.p_data); + SER_ERROR_CHECK(err_code == NRF_SUCCESS, err_code); + + SER_EVT_DEC_END; +} +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gap_evt_app.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gap_evt_app.h new file mode 100644 index 0000000..b36e70b --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gap_evt_app.h @@ -0,0 +1,546 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef BLE_GAP_EVT_APP_H__ +#define BLE_GAP_EVT_APP_H__ + +/**@file + * + * @defgroup ble_gap_evt_app GAP Application event decoders + * @{ + * @ingroup ser_app_s130_codecs + * + * @brief GAP Application event decoders. + */ +#include "ble.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Decodes ble_gap_evt_auth_key_request event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gap_evt_auth_key_request_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gap_evt_auth_status event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gap_evt_auth_status_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gap_evt_conn_param_update event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gap_evt_conn_param_update_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gap_evt_conn_sec_update event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gap_evt_conn_sec_update_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gap_evt_connected event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gap_evt_connected_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gap_evt_disconnected event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gap_evt_disconnected_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gap_evt_passkey_display event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gap_evt_passkey_display_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gap_evt_rssi_changed event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gap_evt_rssi_changed_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gap_evt_sec_info_request event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gap_evt_sec_info_request_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gap_evt_sec_params_request event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gap_evt_sec_params_request_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gap_evt_timeout event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gap_evt_timeout_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gap_evt_sec_request event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gap_evt_sec_request_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gap_evt_conn_param_update_request event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gap_evt_conn_param_update_request_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); +/** + * @brief Decodes ble_gap_evt_adv_report event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gap_evt_adv_report_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gap_evt_scan_req_report event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gap_evt_scan_req_report_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gap_evt_key_pressed event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gap_evt_key_pressed_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); +/** + * @brief Decodes ble_gap_evt_lesc_dhkey_request event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gap_evt_lesc_dhkey_request_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +#if NRF_SD_BLE_API_VERSION >= 5 +/** + * @brief Decodes ble_gap_evt_phy_update event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gap_evt_phy_update_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gap_evt_phy_update_request event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gap_evt_phy_update_request_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); +#endif + +#if NRF_SD_BLE_API_VERSION >= 4 +/** + * @brief Decodes ble_gap_evt_data_length_update_request event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gap_evt_data_length_update_request_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); +/** + * @brief Decodes ble_gap_evt_data_length_update event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gap_evt_data_length_update_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); +#endif +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gattc_app.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gattc_app.c new file mode 100644 index 0000000..dc0057c --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gattc_app.c @@ -0,0 +1,286 @@ +/** + * Copyright (c) 2013 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include "ble_gattc_app.h" +#include <string.h> +#include "ble_serialization.h" +#include "ble_gattc_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" +#include "ble_struct_serialization.h" +#include "ble_types.h" + +uint32_t ble_gattc_attr_info_discover_req_enc(uint16_t conn_handle, + ble_gattc_handle_range_t const * const p_handle_range, + uint8_t * const p_buf, + uint32_t * p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GATTC_ATTR_INFO_DISCOVER); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_handle_range, ble_gattc_handle_range_t_enc); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gattc_attr_info_discover_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_ATTR_INFO_DISCOVER); +} + +uint32_t ble_gattc_char_value_by_uuid_read_req_enc(uint16_t conn_handle, + ble_uuid_t const * const p_uuid, + ble_gattc_handle_range_t const * const p_handle_range, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_uuid, ble_uuid_t_enc); + SER_PUSH_COND(p_handle_range, ble_gattc_handle_range_t_enc); + + SER_REQ_ENC_END; +} + +uint32_t ble_gattc_char_value_by_uuid_read_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ); +} + +uint32_t ble_gattc_char_values_read_req_enc(uint16_t conn_handle, + uint16_t const * const p_handles, + uint16_t handle_count, + uint8_t * const p_buf, + uint32_t * p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GATTC_CHAR_VALUES_READ); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_len16data16(p_handles, handle_count); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gattc_char_values_read_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_CHAR_VALUES_READ); +} + +uint32_t ble_gattc_characteristics_discover_req_enc( + uint16_t conn_handle, + ble_gattc_handle_range_t const * const p_handle_range, + uint8_t * const p_buf, + uint32_t * p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GATTC_CHARACTERISTICS_DISCOVER); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_handle_range, ble_gattc_handle_range_t_enc); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gattc_characteristics_discover_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_CHARACTERISTICS_DISCOVER); +} + +uint32_t ble_gattc_descriptors_discover_req_enc( + uint16_t conn_handle, + ble_gattc_handle_range_t const * const p_handle_range, + uint8_t * const p_buf, + uint32_t * p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GATTC_DESCRIPTORS_DISCOVER); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_handle_range, ble_gattc_handle_range_t_enc); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gattc_descriptors_discover_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_DESCRIPTORS_DISCOVER); +} + +uint32_t ble_gattc_hv_confirm_req_enc(uint16_t conn_handle, + uint16_t handle, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GATTC_HV_CONFIRM); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_uint16(&handle); + + SER_REQ_ENC_END; +} + +uint32_t ble_gattc_hv_confirm_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_HV_CONFIRM); +} + +uint32_t ble_gattc_primary_services_discover_req_enc(uint16_t conn_handle, + uint16_t start_handle, + ble_uuid_t const * const p_srvc_uuid, + uint8_t * const p_buf, + uint32_t * p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_uint16(&start_handle); + SER_PUSH_COND(p_srvc_uuid, ble_uuid_t_enc); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gattc_primary_services_discover_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER); +} + +uint32_t ble_gattc_read_req_enc(uint16_t conn_handle, + uint16_t handle, + uint16_t offset, + uint8_t * const p_buf, + uint32_t * p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GATTC_READ); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_uint16(&handle); + SER_PUSH_uint16(&offset); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gattc_read_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_READ); +} + +uint32_t ble_gattc_relationships_discover_req_enc( + uint16_t conn_handle, + ble_gattc_handle_range_t const * const p_handle_range, + uint8_t * const p_buf, + uint32_t * p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GATTC_RELATIONSHIPS_DISCOVER); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_handle_range, ble_gattc_handle_range_t_enc); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gattc_relationships_discover_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_RELATIONSHIPS_DISCOVER); +} + +uint32_t ble_gattc_write_req_enc(uint16_t conn_handle, + ble_gattc_write_params_t const * const p_write_params, + uint8_t * const p_buf, + uint32_t * p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GATTC_WRITE); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_write_params, ble_gattc_write_params_t_enc); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gattc_write_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_WRITE); +} + +uint32_t ble_gattc_exchange_mtu_request_req_enc(uint16_t conn_handle, + uint16_t client_rx_mtu, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GATTC_EXCHANGE_MTU_REQUEST); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_uint16(&client_rx_mtu); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gattc_exchange_mtu_request_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTC_EXCHANGE_MTU_REQUEST); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gattc_app.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gattc_app.h new file mode 100644 index 0000000..ddb237e --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gattc_app.h @@ -0,0 +1,491 @@ +/** + * Copyright (c) 2013 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef BLE_GATTC_APP_H__ +#define BLE_GATTC_APP_H__ + +/**@file + * + * @defgroup ble_gattc_app GATTC Application command request encoders and command response decoders + * @{ + * @ingroup ser_app_s130_codecs + * + * @brief GATTC Application command request encoders and command response decoders. + */ +#include "ble_gattc.h" +#include "ble.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/**@brief Encodes @ref sd_ble_gattc_primary_services_discover command request. + * + * @sa @ref ble_gattc_primary_services_discover_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] start_handle Handle to start searching from. + * @param[in] p_srvc_uuid Pointer to a @ref ble_uuid_t which indicates the service UUID to + * be found. If it is NULL, all primary services will be returned. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_primary_services_discover_req_enc(uint16_t conn_handle, + uint16_t start_handle, + ble_uuid_t const * const p_srvc_uuid, + uint8_t * const p_buf, + uint32_t * p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gattc_primary_services_discover command. + * + * @sa @ref ble_gattc_primary_services_discover_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gattc_primary_services_discover_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gattc_descriptors_discover command request. + * + * @sa @ref ble_gattc_descriptors_discover_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] p_handle_range A pointer to the range of handles of the Service to perform + * this procedure on. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_descriptors_discover_req_enc( + uint16_t conn_handle, + ble_gattc_handle_range_t const * const p_handle_range, + uint8_t * const p_buf, + uint32_t * p_buf_len); + + +/**@brief Decodes response to @ref sd_ble_gattc_descriptors_discover command. + * + * @sa @ref ble_gattc_primary_services_discover_rsp_dec for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gattc_descriptors_discover_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gattc_relationships_discover command request. + * + * @sa @ref ble_gattc_relationships_discover_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] p_handle_range A pointer to the range of handles of the Service to perform + * this procedure on. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_relationships_discover_req_enc( + uint16_t conn_handle, + ble_gattc_handle_range_t const * const p_handle_range, + uint8_t * const p_buf, + uint32_t * p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gattc_relationships_discover command. + * + * @sa @ref ble_gattc_relationships_discover_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gattc_relationships_discover_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gattc_characteristics_discover command request. + * + * @sa @ref ble_gattc_characteristics_discover_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] p_handle_range A pointer to the range of handles of the Service to perform + * this procedure on. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_characteristics_discover_req_enc + (uint16_t conn_handle, + ble_gattc_handle_range_t const * const p_handle_range, + uint8_t * const p_buf, + uint32_t * p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gattc_characteristics_discover command. + * + * @sa @ref ble_gattc_primary_services_discover_rsp_dec for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gattc_characteristics_discover_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gattc_read command request. + * + * @sa @ref ble_gattc_read_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] handle The handle of the attribute to be read. + * @param[in] offset Offset into the attribute value to be read. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_read_req_enc(uint16_t conn_handle, + uint16_t handle, + uint16_t offset, + uint8_t * const p_buf, + uint32_t * p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gattc_read command. + * + * @sa @ref ble_gattc_read_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gattc_read_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gattc_char_values_read command request. + * + * @sa @ref ble_gattc_char_values_read_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] p_handles A pointer to the handle(s) of the attribute(s) to be read. + * @param[in] handle_count The number of handles in p_handles. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_char_values_read_req_enc(uint16_t conn_handle, + uint16_t const * const p_handles, + uint16_t handle_count, + uint8_t * const p_buf, + uint32_t * p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gattc_char_values_read command. + * + * @sa @ref ble_gattc_char_values_read_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gattc_char_values_read_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gattc_write command request. + * + * @sa @ref ble_gattc_write_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] p_write_params Pointer to \ref sd_ble_gattc_write params. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_write_req_enc(uint16_t conn_handle, + ble_gattc_write_params_t const * const p_write_params, + uint8_t * const p_buf, + uint32_t * p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gattc_write command. + * + * @sa @ref ble_gattc_write_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gattc_write_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gattc_hv_confirm command request. + * + * @sa @ref ble_gattc_hv_confirm_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] handle Handle of the attribute in the indication. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_hv_confirm_req_enc(uint16_t conn_handle, + uint16_t handle, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gattc_hv_confirm command. + * + * @sa @ref ble_gattc_hv_confirm_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Pointer to command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gattc_hv_confirm_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gattc_char_value_by_uuid_read command request. + * + * @sa @ref ble_gattc_char_value_by_uuid_read_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] p_uuid Pointer to a characteristic value UUID to read. + * @param[in] p_handle_range Pointer to the range of handles to perform this procedure on. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_char_value_by_uuid_read_req_enc + (uint16_t conn_handle, + ble_uuid_t const * const p_uuid, + ble_gattc_handle_range_t const * const p_handle_range, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gattc_char_value_by_uuid_read command. + * + * @sa @ref ble_gattc_char_value_by_uuid_read_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Pointer to command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gattc_char_value_by_uuid_read_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gattc_attr_info_discover command request. + * + * @sa @ref ble_gattc_attr_info_discover_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] p_handle_range Pointer to the range of handles + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_attr_info_discover_req_enc(uint16_t conn_handle, + ble_gattc_handle_range_t const * const p_handle_range, + uint8_t * const p_buf, + uint32_t * p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gattc_attr_info_discover command. + * + * @sa @ref ble_gattc_attr_info_discover_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Pointer to command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gattc_attr_info_discover_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gattc_exchange_mtu_request command request. + * + * @sa @ref ble_gattc_exchange_mtu_request_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] client_rx_mtu Client MTU Size. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in, out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gattc_exchange_mtu_request_req_enc(uint16_t conn_handle, + uint16_t client_rx_mtu, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gattc_exchange_mtu_request command. + * + * @sa @ref ble_gattc_exchange_mtu_request_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Pointer to command response result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match expected + * operation code. + */ +uint32_t ble_gattc_exchange_mtu_request_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gattc_evt_app.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gattc_evt_app.c new file mode 100644 index 0000000..c049ed4 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gattc_evt_app.c @@ -0,0 +1,262 @@ +/** + * Copyright (c) 2013 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include "ble_gattc_evt_app.h" +#include <string.h> +#include "ble_serialization.h" +#include "ble_gattc_struct_serialization.h" +#include "app_util.h" + +uint32_t ble_gattc_evt_attr_info_disc_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_ATTR_INFO_DISC_RSP, gattc, attr_info_disc_rsp); + + SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle); + SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status); + SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle); + SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.attr_info_disc_rsp, + ble_gattc_evt_attr_info_disc_rsp_t_dec); + + SER_EVT_DEC_END; +} + +uint32_t ble_gattc_evt_char_disc_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_CHAR_DISC_RSP, gattc, char_disc_rsp); + + SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle); + SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status); + SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle); + SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.char_disc_rsp, + ble_gattc_evt_char_disc_rsp_t_dec); + + SER_EVT_DEC_END; +} + + + +uint32_t ble_gattc_evt_char_val_by_uuid_read_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP, gattc, char_val_by_uuid_read_rsp); + + SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle); + SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status); + SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle); + SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.char_val_by_uuid_read_rsp, + ble_gattc_evt_char_val_by_uuid_read_rsp_t_dec); + + SER_EVT_DEC_END; +} + + +uint32_t ble_gattc_evt_char_vals_read_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_CHAR_VALS_READ_RSP, gattc, char_vals_read_rsp); + + SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle); + SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status); + SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle); + SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.char_vals_read_rsp, + ble_gattc_evt_char_vals_read_rsp_t_dec); + + SER_EVT_DEC_END; +} + + +uint32_t ble_gattc_evt_desc_disc_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_DESC_DISC_RSP, gattc, desc_disc_rsp); + + SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle); + SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status); + SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle); + SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.desc_disc_rsp, + ble_gattc_evt_desc_disc_rsp_t_dec); + + SER_EVT_DEC_END; +} + +uint32_t ble_gattc_evt_hvx_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_HVX, gattc, hvx); + + SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle); + SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status); + SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle); + SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.hvx, + ble_gattc_evt_hvx_t_dec); + + SER_EVT_DEC_END; +} + + +uint32_t ble_gattc_evt_prim_srvc_disc_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP, gattc, prim_srvc_disc_rsp); + + SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle); + SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status); + SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle); + SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.prim_srvc_disc_rsp, + ble_gattc_evt_prim_srvc_disc_rsp_t_dec); + + SER_EVT_DEC_END; +} + +uint32_t ble_gattc_evt_read_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_READ_RSP, gattc, read_rsp); + + SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle); + SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status); + SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle); + SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.read_rsp, + ble_gattc_evt_read_rsp_t_dec); + + SER_EVT_DEC_END; +} + + +#define BLE_GATTC_EVT_REL_DISC_RSP_COUNT_POSITION 6 + + +uint32_t ble_gattc_evt_rel_disc_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_READ_RSP, gattc, rel_disc_rsp); + + SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle); + SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status); + SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle); + SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.rel_disc_rsp, + ble_gattc_evt_rel_disc_rsp_t_dec); + + SER_EVT_DEC_END; +} + + +uint32_t ble_gattc_evt_timeout_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_TIMEOUT, gattc, timeout); + + SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle); + SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status); + SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle); + SER_PULL_FIELD(&p_event->evt.gattc_evt.params.timeout, + ble_gattc_evt_timeout_t_dec); + + SER_EVT_DEC_END; +} + +uint32_t ble_gattc_evt_write_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_WRITE_RSP, gattc, write_rsp); + + SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle); + SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status); + SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle); + SER_PULL_FIELD_EXTENDED(&p_event->evt.gattc_evt.params.write_rsp, + ble_gattc_evt_write_rsp_t_dec); + + SER_EVT_DEC_END; +} + +uint32_t ble_gattc_evt_exchange_mtu_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_EXCHANGE_MTU_RSP, gattc, exchange_mtu_rsp); + + SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle); + SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status); + SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle); + SER_PULL_FIELD(&p_event->evt.gattc_evt.params.exchange_mtu_rsp, + ble_gattc_evt_exchange_mtu_rsp_t_dec); + + SER_EVT_DEC_END; +} + +#if NRF_SD_BLE_API_VERSION >= 4 +uint32_t ble_gattc_evt_write_cmd_tx_complete_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE, gattc, write_cmd_tx_complete); + SER_PULL_uint16(&p_event->evt.gattc_evt.conn_handle); + SER_PULL_uint16(&p_event->evt.gattc_evt.gatt_status); + SER_PULL_uint16(&p_event->evt.gattc_evt.error_handle); + SER_PULL_uint8(&p_event->evt.gattc_evt.params.write_cmd_tx_complete.count); + + SER_EVT_DEC_END; +} +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gattc_evt_app.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gattc_evt_app.h new file mode 100644 index 0000000..73a0c78 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gattc_evt_app.h @@ -0,0 +1,364 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef BLE_GATTC_EVT_APP_H__ +#define BLE_GATTC_EVT_APP_H__ + +/**@file + * + * @defgroup ble_gattc_evt_app GATTC Application event decoders + * @{ + * @ingroup ser_app_s130_codecs + * + * @brief GATTC Application event decoders. + */ +#include "ble.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Decodes ble_gattc_evt_char_disc_rsp event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gattc_evt_char_disc_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gattc_evt_char_val_by_uuid_read_rsp event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gattc_evt_char_val_by_uuid_read_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gattc_evt_char_vals_read_rsp event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gattc_evt_char_vals_read_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gattc_evt_desc_disc_rsp event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gattc_evt_desc_disc_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gattc_evt_hvx event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gattc_evt_hvx_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gattc_evt_prim_srvc_disc_rsp event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gattc_evt_prim_srvc_disc_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gattc_evt_read_rsp event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gattc_evt_read_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gattc_evt_rel_disc_rsp_dec event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gattc_evt_rel_disc_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gattc_evt_timeout event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gattc_evt_timeout_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gattc_evt_write_rsp event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gattc_evt_write_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gattc_evt_attr_info_disc_rsp event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gattc_evt_attr_info_disc_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gattc_evt_exchange_mtu_rsp event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gattc_evt_exchange_mtu_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +#if NRF_SD_BLE_API_VERSION >= 4 + +/** + * @brief Decodes ble_gattc_evt_write_cmd_tx_complete event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gattc_evt_write_cmd_tx_complete_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); +#endif +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gatts_app.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gatts_app.c new file mode 100644 index 0000000..eb7c76c --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gatts_app.c @@ -0,0 +1,439 @@ +/** + * Copyright (c) 2013 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include "ble_gatts_app.h" +#include <stdlib.h> +#include <string.h> +#include "ble_serialization.h" +#include "ble_gatts_struct_serialization.h" +#include "ble_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" + + +uint32_t ble_gatts_attr_get_req_enc(uint16_t handle, + ble_uuid_t * p_uuid, + ble_gatts_attr_md_t * p_md, + uint8_t * const p_buf, + uint32_t * p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GATTS_ATTR_GET); + + SER_PUSH_uint16(&handle); + SER_PUSH_COND(p_uuid, NULL); + SER_PUSH_COND(p_md, NULL); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gatts_attr_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_uuid_t ** pp_uuid, + ble_gatts_attr_md_t ** pp_md, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GATTS_ATTR_GET); + SER_PULL_COND(pp_uuid, ble_uuid_t_dec); + SER_PULL_COND(pp_md, ble_gatts_attr_md_t_dec); + SER_RSP_DEC_END; +} + + +uint32_t ble_gatts_characteristic_add_req_enc( + uint16_t service_handle, + ble_gatts_char_md_t const * const p_char_md, + ble_gatts_attr_t const * const p_attr_char_value, + ble_gatts_char_handles_t const * const p_handles, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GATTS_CHARACTERISTIC_ADD); + + SER_PUSH_uint16(&service_handle); + SER_PUSH_COND(p_char_md, ble_gatts_char_md_t_enc); + SER_PUSH_COND(p_attr_char_value, ble_gatts_attr_t_enc); + SER_PUSH_COND(p_handles, NULL); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gatts_characteristic_add_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * * const pp_handles, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GATTS_CHARACTERISTIC_ADD); + + SER_PULL_COND(pp_handles, ble_gatts_char_handles_t_dec); + + SER_RSP_DEC_END; +} + + + +uint32_t ble_gatts_descriptor_add_req_enc(uint16_t char_handle, + ble_gatts_attr_t const * const p_attr, + uint16_t * const p_handle, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GATTS_DESCRIPTOR_ADD); + + SER_PUSH_uint16(&char_handle); + SER_PUSH_COND(p_attr, ble_gatts_attr_t_enc); + SER_PUSH_COND(p_handle, NULL); + + SER_REQ_ENC_END; +} + +uint32_t ble_gatts_descriptor_add_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_handle, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GATTS_DESCRIPTOR_ADD); + + SER_PULL_COND(&p_handle, uint16_t_dec); + + SER_RSP_DEC_END; +} + + +uint32_t ble_gatts_hvx_req_enc(uint16_t conn_handle, + ble_gatts_hvx_params_t const * const p_hvx_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GATTS_HVX); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_hvx_params, ble_gatts_hvx_params_t_enc); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gatts_hvx_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code, + uint16_t * * const pp_bytes_written) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GATTS_HVX); + + SER_PULL_COND(pp_bytes_written, uint16_t_dec); + + SER_RSP_DEC_END; +} + + +uint32_t ble_gatts_include_add_req_enc(uint16_t service_handle, + uint16_t inc_srvc_handle, + uint16_t * const p_include_handle, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GATTS_INCLUDE_ADD); + + SER_PUSH_uint16(&service_handle); + SER_PUSH_uint16(&inc_srvc_handle); + SER_PUSH_COND(p_include_handle, NULL); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gatts_include_add_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_include_handle, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GATTS_INCLUDE_ADD); + + SER_PULL_COND(&p_include_handle, uint16_t_dec); + + SER_RSP_DEC_END; +} + + +uint32_t ble_gatts_initial_user_handle_get_req_enc(uint16_t * p_handle, + uint8_t * const p_buf, + uint32_t * p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GATTS_INITIAL_USER_HANDLE_GET); + + SER_PUSH_COND(p_handle, NULL); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gatts_initial_user_handle_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t ** pp_handle, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GATTS_INITIAL_USER_HANDLE_GET); + + SER_PULL_COND(pp_handle, uint16_t_dec); + + SER_RSP_DEC_END; +} + + +uint32_t ble_gatts_rw_authorize_reply_req_enc(uint16_t conn_handle, + ble_gatts_rw_authorize_reply_params_t const * const p_reply_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GATTS_RW_AUTHORIZE_REPLY); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_reply_params, ble_gatts_rw_authorize_reply_params_t_enc); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gatts_rw_authorize_reply_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTS_RW_AUTHORIZE_REPLY); +} + + +uint32_t ble_gatts_service_add_req_enc(uint8_t type, + ble_uuid_t const * const p_uuid, + uint16_t const * const p_conn_handle, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GATTS_SERVICE_ADD); + + SER_PUSH_uint8(&type); + SER_PUSH_COND(p_uuid, ble_uuid_t_enc); + SER_PUSH_COND(p_conn_handle, NULL); + + SER_REQ_ENC_END; +} + +uint32_t ble_gatts_service_add_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_conn_handle, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GATTS_SERVICE_ADD); + + SER_PULL_COND(&p_conn_handle, uint16_t_dec); + + SER_RSP_DEC_END; +} + + +uint32_t ble_gatts_service_changed_req_enc(uint16_t conn_handle, + uint16_t start_handle, + uint16_t end_handle, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GATTS_SERVICE_CHANGED); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_uint16(&start_handle); + SER_PUSH_uint16(&end_handle); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gatts_service_changed_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTS_SERVICE_CHANGED); +} + + +uint32_t ble_gatts_sys_attr_get_req_enc(uint16_t conn_handle, + uint8_t const * const p_sys_attr_data, + uint16_t const * const p_sys_attr_data_len, + uint32_t flags, + uint8_t * const p_buf, + uint32_t * p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GATTS_SYS_ATTR_GET); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_sys_attr_data_len, uint16_t_enc); + SER_PUSH_COND(p_sys_attr_data, NULL); + SER_PUSH_uint32(&flags); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gatts_sys_attr_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * * const pp_sys_attr_data, + uint16_t * * const pp_sys_attr_data_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GATTS_SYS_ATTR_GET); + + SER_PULL_COND(pp_sys_attr_data_len, uint16_t_dec); + if (*pp_sys_attr_data_len) + { + SER_PULL_buf(pp_sys_attr_data, **pp_sys_attr_data_len, **pp_sys_attr_data_len); + } + + SER_RSP_DEC_END; +} + + +uint32_t ble_gatts_sys_attr_set_req_enc(uint16_t conn_handle, + uint8_t const * const p_sys_attr_data, + uint16_t sys_attr_data_len, + uint32_t flags, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GATTS_SYS_ATTR_SET); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_len16data(p_sys_attr_data, sys_attr_data_len); + SER_PUSH_uint32(&flags); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gatts_sys_attr_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SD_BLE_GATTS_SYS_ATTR_SET, p_result_code); +} + + +uint32_t ble_gatts_value_get_req_enc(uint16_t conn_handle, + uint16_t handle, + ble_gatts_value_t const * const p_value, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GATTS_VALUE_GET); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_uint16(&handle); + + //Special case: skip the data. + SER_PUSH_COND(p_value, NULL); + if (p_value) + { + SER_PUSH_uint16(&p_value->offset); + SER_PUSH_uint16(&p_value->len); + SER_PUSH_COND(p_value->p_value, NULL); + } + + SER_REQ_ENC_END; +} + +uint32_t ble_gatts_value_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gatts_value_t * const p_value, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GATTS_VALUE_GET); + + SER_PULL_COND(&p_value, ble_gatts_value_t_dec); + + SER_RSP_DEC_END; +} + + +uint32_t ble_gatts_value_set_req_enc(uint16_t conn_handle, + uint16_t handle, + ble_gatts_value_t * p_value, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GATTS_VALUE_SET); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_uint16(&handle); + SER_PUSH_COND(p_value, ble_gatts_value_t_enc); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gatts_value_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gatts_value_t * const p_value, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_GATTS_VALUE_SET); + + SER_PULL_COND(&p_value, ble_gatts_value_t_dec); + + SER_RSP_DEC_END; +} + +uint32_t ble_gatts_exchange_mtu_reply_req_enc(uint16_t conn_handle, + uint16_t server_rx_mtu, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_GATTS_EXCHANGE_MTU_REPLY); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_uint16(&server_rx_mtu); + + SER_REQ_ENC_END; +} + + +uint32_t ble_gatts_exchange_mtu_reply_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_GATTS_EXCHANGE_MTU_REPLY); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gatts_app.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gatts_app.h new file mode 100644 index 0000000..3dcf5d5 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gatts_app.h @@ -0,0 +1,677 @@ +/** + * Copyright (c) 2013 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef BLE_GATTS_APP_H__ +#define BLE_GATTS_APP_H__ + +/**@file + * + * @defgroup ble_gatts_app GATTS Application command request encoders and command response decoders + * @{ + * @ingroup ser_app_s130_codecs + * + * @brief GATTS Application command request encoders and command response decoders. + */ +#include "ble_gatts.h" +#include "ble.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/**@brief Encodes @ref sd_ble_gatts_value_get command request. + * + * @sa @ref ble_gatts_value_get_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle. + * @param[in] handle Attribute handle. + * @param[in] p_value Pointer to attribute value information. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @note \p p_data_len and \p p_data will not be updated by the command + * request encoder. Updated values are set by @ref ble_gatts_value_get_rsp_dec. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_value_get_req_enc(uint16_t conn_handle, + uint16_t handle, + ble_gatts_value_t const * const p_value, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gatts_value_get command. + * + * @sa @ref ble_gatts_value_get_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_value Pointer to structure where the attribute value will be stored. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Length of \p p_value is too small to hold decoded + * value from response. + */ +uint32_t ble_gatts_value_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gatts_value_t * const p_value, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gatts_hvx command request. + * + * @sa @ref ble_gatts_hvx_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle. + * @param[in] p_hvx_params Pointer to an HVx parameters structure to be encoded. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @note \p p_hvx_params will not be updated by the command + * request encoder. Updated values are set by @ref ble_gatts_hvx_rsp_dec. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_hvx_req_enc(uint16_t conn_handle, + ble_gatts_hvx_params_t const * const p_hvx_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gatts_hvx command. + * + * @sa @ref ble_gatts_hvx_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * @param[out] pp_bytes_written Pointer to pointer to location where number of bytes is written. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_gatts_hvx_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code, + uint16_t * * const pp_bytes_written); + +/**@brief Encodes @ref sd_ble_gatts_characteristic_add command request. + * + * @sa @ref ble_gatts_characteristic_add_rsp_dec for command response decoder. + * + * @param[in] service_handle Handle of the service where the characteristic is to be placed. + * If @ref BLE_GATT_HANDLE_INVALID is used, it will be placed + * sequentially. + * @param[in] p_char_md Pointer to a @ref ble_gatts_char_md_t structure, characteristic + * metadata. + * @param[in] p_attr_char_value Pointer to a @ref ble_gatts_attr_t structure, corresponding to + * the characteristic value. + * @param[in] p_handles Pointer to a @ref ble_gatts_char_handles_t structure, where the + * assigned handles will be stored. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @note \p p_handles will not be updated by the command + * request encoder. Updated values are set by @ref ble_gatts_characteristic_add_rsp_dec. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_characteristic_add_req_enc + (uint16_t service_handle, + ble_gatts_char_md_t const * const p_char_md, + ble_gatts_attr_t const * const p_attr_char_value, + ble_gatts_char_handles_t const * const p_handles, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gatts_characteristic_add command. + * + * @sa @ref ble_gatts_characteristic_add_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] pp_handles Pointer to pointer to location where handles should be decoded. + * @param[out] p_result_code Pointer to command result code decode location. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_gatts_characteristic_add_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * * const pp_handles, + uint32_t * const p_result_code); + + +/**@brief Encodes @ref sd_ble_gatts_service_add command request. + * + * @sa @ref ble_gatts_service_add_rsp_dec for command response decoder. + * + * @param[in] type Toggles between primary and secondary services, + * see @ref BLE_GATTS_SRVC_TYPES. + * @param[in] p_uuid Pointer to service UUID. + * @param[in] p_conn_handle Pointer to a 16-bit word where the assigned handle will be stored. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @note \p p_conn_handle will not be updated by the command + * request encoder. Updated values are set by @ref ble_gatts_service_add_rsp_dec. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_service_add_req_enc(uint8_t type, + ble_uuid_t const * const p_uuid, + uint16_t const * const p_conn_handle, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gatts_service_add command. + * + * @sa @ref ble_gatts_service_add_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_conn_handle Connection handle. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_gatts_service_add_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_conn_handle, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gatts_sys_attr_set command request. + * + * @sa @ref ble_gatts_sys_attr_set_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle. + * @param[in] p_sys_attr_data Pointer to a buffer (at least \p sys_attr_data_len bytes long) + * containing the attribute value to write. + * @param[in] sys_attr_data_len Length (in bytes) of \p p_sys_attr_data. + * @param[in] flags Optional additional flags. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_sys_attr_set_req_enc(uint16_t conn_handle, + uint8_t const * const p_sys_attr_data, + uint16_t sys_attr_data_len, + uint32_t flags, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gatts_sys_attr_set command. + * + * @sa @ref ble_gatts_sys_attr_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_gatts_sys_attr_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gatts_value_set command request. + * + * @sa @ref ble_gatts_value_set_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle. + * @param[in] handle Attribute handle. + * @param[in] p_value Pointer to attribute value information. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_value_set_req_enc(uint16_t conn_handle, + uint16_t handle, + ble_gatts_value_t * p_value, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gatts_value_set command. + * + * @sa @ref ble_gatts_value_set_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_value Pointer to attribute value information. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_gatts_value_set_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_gatts_value_t * const p_value, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gatts_sys_attr_get command request. + * + * @sa @ref ble_gatts_sys_attr_get_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle of the connection. + * @param[in] p_sys_attr_data Pointer to buffer where updated information about system + * attributes will be stored. Can be NULL to calculate required + * size. + * @param[in] p_sys_attr_data_len Size of p_sys_attr_data buffer if \p p_sys_attr_data is + * not NULL. + * @param[in] flags Additional optional flags. + * @param[in,out] p_buf Pointer to buffer where encoded data command will + * be returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @note \p p_sys_attr_data and \p p_sys_attr_data_len will not be updated by the command + * request encoder. Updated values are set by @ref ble_gatts_sys_attr_get_rsp_dec. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_sys_attr_get_req_enc(uint16_t conn_handle, + uint8_t const * const p_sys_attr_data, + uint16_t const * const p_sys_attr_data_len, + uint32_t flags, + uint8_t * const p_buf, + uint32_t * p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gatts_sys_attr_get command. + * + * @sa @ref ble_gatts_sys_attr_get_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] pp_sys_attr_data Pointer to a buffer where updated information about system + * attributes will be stored. + * @param[in,out] pp_sys_attr_data_len \c in: Size (in bytes) of \p p_sys_attr_data buffer. + * \c out: Length of decoded contents of \p p_sys_attr_data. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Length of \p p_sys_attr_data is too small to hold decoded + * value from response. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_gatts_sys_attr_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t * * const pp_sys_attr_data, + uint16_t * * const pp_sys_attr_data_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gatts_descriptor_add command request. + * + * @sa @ref ble_gatts_descriptor_add_rsp_dec for command response decoder. + * + * @param[in] char_handle Handle of the characteristic where the description is to be placed. + * If @ref BLE_GATT_HANDLE_INVALID is used, it will be placed + * sequentially. + * @param[in] p_attr Pointer to a @ref ble_gatts_attr_t structure, characteristic + * metadata. + * @param[in] p_handle Pointer to a @ref ble_gatts_char_handles_t structure, where the + * assigned handles will be stored. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_descriptor_add_req_enc(uint16_t char_handle, + ble_gatts_attr_t const * const p_attr, + uint16_t * const p_handle, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gatts_descriptor_add command. + * + * @sa @ref ble_gatts_descriptor_add_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_handle Pointer to bufer where descriptor handle will be + returned. + * @param[out] p_result_code Pointer to command result code decode location. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_gatts_descriptor_add_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_handle, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gatts_include_add command request. + * + * @sa @ref ble_gatts_include_add_rsp_dec for command response decoder. + * + * @param[in] service_handle Handle of the service where the included service is to be placed. + * @param[in] inc_srvc_handle Handle of the included service + * @param[in] p_include_handle Pointer to Pointer to a 16-bit word where the assigned handle will be stored. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_include_add_req_enc(uint16_t service_handle, + uint16_t inc_srvc_handle, + uint16_t * const p_include_handle, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gatts_include_add command. + * + * @sa @ref ble_gatts_include_add_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_include_handle Pointer to a 16-bit word where the assigned handle will be stored. + * @param[out] p_result_code Pointer to command result code decode location. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_gatts_include_add_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * const p_include_handle, + uint32_t * const p_result_code); + + +/**@brief Encodes @ref sd_ble_gatts_rw_authorize_reply command request. + * + * @sa @ref ble_gatts_rw_authorize_reply_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle. + * @param[in] p_reply_params Pointer to \ref ble_gatts_rw_authorize_reply_params_t + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Encoding failure. Invalid param provided in p_reply_params. + */ +uint32_t ble_gatts_rw_authorize_reply_req_enc( + uint16_t conn_handle, + ble_gatts_rw_authorize_reply_params_t const * const + p_reply_params, + uint8_t * const + p_buf, + uint32_t * const + p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gatts_rw_authorize_reply command. + * + * @sa @ref ble_gatts_rw_authorize_reply_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_gatts_rw_authorize_reply_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gatts_service_changed command request. + * + * @sa @ref ble_gatts_service_changed_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle. + * @param[in] start_handle Start of affected attribute handle range. + * @param[in] end_handle End of affected attribute handle range. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Encoding failure. Invalid param provided in p_reply_params. + */ +uint32_t ble_gatts_service_changed_req_enc(uint16_t conn_handle, + uint16_t start_handle, + uint16_t end_handle, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gatts_service_changed command. + * + * @sa @ref ble_gatts_service_changed_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_gatts_service_changed_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gatts_attr_get command request. + * + * @sa @ref ble_gatts_attr_get_rsp_dec for command response decoder. + * + * @param[in] handle See @ref sd_ble_gatts_attr_get. + * @param[in] p_uuid See @ref sd_ble_gatts_attr_get. + * @param[out] p_md See @ref sd_ble_gatts_attr_get. + * @param[in,out] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_attr_get_req_enc(uint16_t handle, + ble_uuid_t * p_uuid, + ble_gatts_attr_md_t * p_md, + uint8_t * const p_buf, + uint32_t * p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gatts_attr_get command. + * + * @sa @ref ble_gatts_attr_get_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] pp_uuid Pointer to address where to put output data. + * @param[out] pp_md Pointer to address where to put output data. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_gatts_attr_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_uuid_t ** pp_uuid, + ble_gatts_attr_md_t ** pp_md, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gatts_initial_user_handle_get command request. + * + * @sa @ref ble_gatts_initial_user_handle_get_rsp_dec for command response decoder. + * + * @param[out] p_handle See @ref sd_ble_gatts_initial_user_handle_get. + * @param[in,out] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_gatts_initial_user_handle_get_req_enc(uint16_t * p_handle, + uint8_t * const p_buf, + uint32_t * p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gatts_initial_user_handle_get command. + * + * @sa @ref ble_gatts_initial_user_handle_get_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] pp_handle Pointer to address where to put output data. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_gatts_initial_user_handle_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t ** pp_handle, + uint32_t * const p_result_code); + +/**@brief Encodes @ref sd_ble_gatts_exchange_mtu_reply command request. + * + * @sa @ref ble_gatts_exchange_mtu_reply_rsp_dec for command response decoder. + * + * @param[in] conn_handle Connection handle. + * @param[in] server_rx_mtu Server MTU Size. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_PARAM Encoding failure. Invalid param provided in p_reply_params. + */ +uint32_t ble_gatts_exchange_mtu_reply_req_enc(uint16_t conn_handle, + uint16_t server_rx_mtu, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ble_gatts_exchange_mtu_reply command. + * + * @sa @ref ble_gatts_exchange_mtu_reply_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_gatts_exchange_mtu_reply_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif //BLE_GATTS_APP_H__ + + diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gatts_evt_app.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gatts_evt_app.c new file mode 100644 index 0000000..bbe71e8 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gatts_evt_app.c @@ -0,0 +1,190 @@ +/** + * Copyright (c) 2013 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include "ble_gatts_evt_app.h" +#include "ble_serialization.h" +#include "ble_gatts_struct_serialization.h" +#include "app_ble_user_mem.h" +#include "app_util.h" + +extern ser_ble_user_mem_t m_app_user_mem_table[]; + +uint32_t ble_gatts_evt_hvc_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GATTS_EVT_HVC, gatts, hvc); + + SER_PULL_uint16(&p_event->evt.gatts_evt.conn_handle); + SER_PULL_FIELD(&p_event->evt.gatts_evt.params.hvc, + ble_gatts_evt_hvc_t_dec); + + SER_EVT_DEC_END; +} + +uint32_t ble_gatts_evt_rw_authorize_request_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GATTS_EVT_HVC, gatts, rw_authorize_request); + + SER_PULL_uint16(&p_event->evt.gatts_evt.conn_handle); + SER_PULL_FIELD_EXTENDED(&p_event->evt.gatts_evt.params.authorize_request, ble_gatts_evt_rw_authorize_request_t_dec); + + //Correct event length / memory sync. + if (p_event->evt.gatts_evt.params.authorize_request.type == BLE_GATTS_AUTHORIZE_TYPE_READ) + { + evt_struct_len = offsetof(ble_evt_t, evt.gatts_evt.params.authorize_request.request.read) + - offsetof(ble_evt_t, evt) + + sizeof(ble_gatts_evt_read_t); + } + else if ((p_event->evt.gatts_evt.params.authorize_request.type == BLE_GATTS_AUTHORIZE_TYPE_WRITE) && + ( (p_event->evt.gatts_evt.params.authorize_request.request.write.op == BLE_GATTS_OP_EXEC_WRITE_REQ_NOW) || + (p_event->evt.gatts_evt.params.authorize_request.request.write.op == BLE_GATTS_OP_PREP_WRITE_REQ))) + { + uint32_t conn_index; + if (app_ble_user_mem_context_find(p_event->evt.gatts_evt.conn_handle, &conn_index) != NRF_ERROR_NOT_FOUND) + { + SER_PULL_len16data(&m_app_user_mem_table[conn_index].mem_block.p_mem, &m_app_user_mem_table[conn_index].mem_block.len); + } + } + + SER_EVT_DEC_END; +} + + +uint32_t ble_gatts_evt_sc_confirm_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN_NO_STRUCT(BLE_GATTS_EVT_SC_CONFIRM, gatts); + SER_PULL_uint16(&p_event->evt.gatts_evt.conn_handle); + SER_EVT_DEC_END; +} + + +uint32_t ble_gatts_evt_sys_attr_missing_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GATTS_EVT_SYS_ATTR_MISSING, gatts, sys_attr_missing); + + SER_PULL_uint16(&p_event->evt.gatts_evt.conn_handle); + SER_PULL_FIELD(&p_event->evt.gatts_evt.params.sys_attr_missing, + ble_gatts_evt_sys_attr_missing_t_dec); + + SER_EVT_DEC_END; +} + + +uint32_t ble_gatts_evt_timeout_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GATTS_EVT_TIMEOUT, gatts, timeout); + + SER_PULL_uint16(&p_event->evt.gatts_evt.conn_handle); + SER_PULL_FIELD(&p_event->evt.gatts_evt.params.timeout, + ble_gatts_evt_timeout_t_dec); + + SER_EVT_DEC_END; +} + + + + +uint32_t ble_gatts_evt_write_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GATTS_EVT_WRITE, gatts, write); + + SER_PULL_uint16(&p_event->evt.gatts_evt.conn_handle); + SER_PULL_FIELD_EXTENDED(&p_event->evt.gatts_evt.params.write, ble_gatts_evt_write_t_dec); + + if (p_event != NULL) + { + if (p_event->evt.gatts_evt.params.write.op == BLE_GATTS_OP_EXEC_WRITE_REQ_NOW) + { + uint32_t conn_index; + if (app_ble_user_mem_context_find(p_event->evt.gatts_evt.conn_handle, &conn_index) != NRF_ERROR_NOT_FOUND) + { + SER_PULL_len16data(&m_app_user_mem_table[conn_index].mem_block.p_mem, &m_app_user_mem_table[conn_index].mem_block.len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + } + } + } + + SER_EVT_DEC_END; +} + + +uint32_t ble_gatts_evt_exchange_mtu_request_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST, gatts, exchange_mtu_request); + + SER_PULL_uint16(&p_event->evt.gatts_evt.conn_handle); + SER_PULL_FIELD(&p_event->evt.gatts_evt.params.exchange_mtu_request, ble_gatts_evt_exchange_mtu_request_t_dec); + + SER_EVT_DEC_END; +} + +#if NRF_SD_BLE_API_VERSION >= 4 +uint32_t ble_gatts_evt_hvn_tx_complete_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_GATTS_EVT_HVN_TX_COMPLETE, gatts, hvn_tx_complete); + + SER_PULL_uint16(&p_event->evt.gatts_evt.conn_handle); + SER_PULL_uint8(&p_event->evt.gatts_evt.params.hvn_tx_complete.count); + + SER_EVT_DEC_END; +} +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gatts_evt_app.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gatts_evt_app.h new file mode 100644 index 0000000..d294b81 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_gatts_evt_app.h @@ -0,0 +1,249 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef BLE_GATTS_EVT_APP_H__ +#define BLE_GATTS_EVT_APP_H__ + +/**@file + * + * @defgroup ble_gatts_evt_app GATTS Application event decoders + * @{ + * @ingroup ser_app_s130_codecs + * + * @brief GATTS Application event decoders. + */ +#include "ble.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Decodes ble_gatts_evt_hvc event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gatts_evt_hvc_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gatts_evt_rw_authorize_request event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gatts_evt_rw_authorize_request_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gatts_evt_sc_confirm event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gatts_evt_sc_confirm_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gatts_evt_sys_attr_missing event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gatts_evt_sys_attr_missing_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gatts_evt_timeout event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gatts_evt_timeout_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gatts_evt_write event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gatts_evt_write_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +/** + * @brief Decodes ble_gatts_evt_exchange_mtu_request event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gatts_evt_exchange_mtu_request_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +#if NRF_SD_BLE_API_VERSION >= 4 + +/** + * @brief Decodes ble_gatts_evt_hvn_tx_complete event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_gatts_evt_hvn_tx_complete_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); +#endif +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_l2cap_app.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_l2cap_app.c new file mode 100644 index 0000000..8378c80 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_l2cap_app.c @@ -0,0 +1,279 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include <string.h> +#include "ble_l2cap_app.h" +#include "ble_serialization.h" +#include "ble_struct_serialization.h" +#include "ble_l2cap_struct_serialization.h" +#include "ble_gap.h" +#include "app_util.h" +#include "cond_field_serialization.h" + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t ble_l2cap_cid_register_req_enc(uint16_t cid, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + SER_ASSERT_LENGTH_LEQ(index + 3, *p_buf_len); + + p_buf[index++] = SD_BLE_L2CAP_CID_REGISTER; + err_code = uint16_t_enc(&cid, p_buf, *p_buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ble_l2cap_cid_register_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SD_BLE_L2CAP_CID_REGISTER, p_result_code); +} + +uint32_t ble_l2cap_cid_unregister_req_enc(uint16_t cid, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + SER_ASSERT_LENGTH_LEQ(index + 3, *p_buf_len); + + p_buf[index++] = SD_BLE_L2CAP_CID_UNREGISTER; + err_code = uint16_t_enc(&cid, p_buf, *p_buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + *p_buf_len = index; + + return err_code; +} + +uint32_t ble_l2cap_cid_unregister_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SD_BLE_L2CAP_CID_UNREGISTER, p_result_code); +} + + +uint32_t ble_l2cap_tx_req_enc(uint16_t conn_handle, + ble_l2cap_header_t const * const p_l2cap_header, + uint8_t const * const p_data, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + uint32_t index = 0; + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + + SER_ASSERT_LENGTH_LEQ(1, *p_buf_len); + p_buf[index++] = SD_BLE_L2CAP_TX; + + err_code = uint16_t_enc(&conn_handle, p_buf, *p_buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = cond_field_enc(p_l2cap_header, p_buf, *p_buf_len, &index, ble_l2cap_header_t_enc); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + if (p_l2cap_header != NULL) + { + err_code = buf_enc(p_data, p_l2cap_header->len, p_buf, *p_buf_len, &index); + } + else + { + err_code = buf_enc(NULL, 0, p_buf, *p_buf_len, &index); + } + + *p_buf_len = index; + + return err_code; +} + +uint32_t ble_l2cap_tx_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + return ser_ble_cmd_rsp_dec(p_buf, packet_len, SD_BLE_L2CAP_TX, p_result_code); +} +#endif + +#if NRF_SD_BLE_API_VERSION >= 5 +uint32_t ble_l2cap_ch_setup_req_enc(uint16_t conn_handle, + uint16_t * p_local_cid, + ble_l2cap_ch_setup_params_t const *p_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_L2CAP_CH_SETUP); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_COND(p_local_cid, uint16_t_enc); + SER_PUSH_COND(p_params, ble_l2cap_ch_setup_params_t_enc); + + SER_REQ_ENC_END; +} + +uint32_t ble_l2cap_ch_setup_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * p_local_cid, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_L2CAP_CH_SETUP); + SER_PULL_COND((void **)&p_local_cid, uint16_t_dec); + SER_RSP_DEC_END; +} + +uint32_t ble_l2cap_ch_release_req_enc(uint16_t conn_handle, + uint16_t local_cid, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_L2CAP_CH_RELEASE); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_uint16(&local_cid); + + SER_REQ_ENC_END; +} + +uint32_t ble_l2cap_ch_release_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_L2CAP_CH_RELEASE); +} + +uint32_t ble_l2cap_ch_rx_req_enc(uint16_t conn_handle, + uint16_t local_cid, + ble_data_t const *p_sdu_buf, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_L2CAP_CH_RX); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_uint16(&local_cid); + + SER_PUSH_COND(p_sdu_buf, NULL); + if (p_sdu_buf) + { + SER_PUSH_uint16(&p_sdu_buf->len); + SER_PUSH_uint32(&p_sdu_buf->p_data); + } + + SER_REQ_ENC_END; +} + +uint32_t ble_l2cap_ch_rx_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_L2CAP_CH_RX); +} + +uint32_t ble_l2cap_ch_tx_req_enc(uint16_t conn_handle, + uint16_t local_cid, + ble_data_t const *p_sdu_buf, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_L2CAP_CH_TX); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_uint16(&local_cid); + + SER_PUSH_COND(p_sdu_buf, NULL); + if (p_sdu_buf) + { + SER_PUSH_uint32(&p_sdu_buf->p_data); + SER_PUSH_uint16(&p_sdu_buf->len); + SER_PUSH_buf(p_sdu_buf->p_data, p_sdu_buf->len); + } + + SER_REQ_ENC_END; +} + +uint32_t ble_l2cap_ch_tx_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_RESULT_ONLY(SD_BLE_L2CAP_CH_TX); +} + +uint32_t ble_l2cap_ch_flow_control_req_enc(uint16_t conn_handle, + uint16_t local_cid, + uint16_t credits, + uint16_t *p_credits, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_BLE_L2CAP_CH_FLOW_CONTROL); + + SER_PUSH_uint16(&conn_handle); + SER_PUSH_uint16(&local_cid); + SER_PUSH_uint16(&credits); + SER_PUSH_COND(p_credits, NULL); + + SER_REQ_ENC_END; +} + +uint32_t ble_l2cap_ch_flow_control_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * p_credits, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_BLE_L2CAP_CH_FLOW_CONTROL); + SER_PULL_COND((void **)&p_credits, uint16_t_dec); + SER_RSP_DEC_END; +} +#endif //NRF_SD_BLE_API_VERSION >= 5 diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_l2cap_app.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_l2cap_app.h new file mode 100644 index 0000000..68d8f68 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_l2cap_app.h @@ -0,0 +1,242 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +/**@file + * + * @defgroup ble_l2cap_app L2CAP Application command request encoders and command response decoders + * @{ + * @ingroup ser_app_s130_codecs + * + * @brief L2CAP Application command request encoders and command response decoders. + */ + +#ifndef BLE_L2CAP_APP_H__ +#define BLE_L2CAP_APP_H__ + +#include "ble.h" +#include "ble_types.h" +#include "ble_ranges.h" +#include "ble_err.h" +#include "ble_l2cap.h" + +#ifdef __cplusplus +extern "C" { +#endif +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +/**@brief Register a CID with L2CAP. + * + * @details This registers a higher protocol layer with the L2CAP multiplexer, and is required prior to all operations on the CID. + * + * @param[in] cid L2CAP CID. + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_l2cap_cid_register_req_enc(uint16_t cid, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_l2cap_cid_register command. + * + * @sa @ref ble_l2cap_cid_register_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_l2cap_cid_register_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Unregister a CID with L2CAP. + * + * @details This unregisters a previously registered higher protocol layer with the L2CAP multiplexer. + * + * @param[in] cid L2CAP CID. + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_l2cap_cid_unregister_req_enc(uint16_t cid, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_l2cap_cid_unregister command. + * + * @sa @ref ble_l2cap_cid_unregister_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_l2cap_cid_unregister_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +/**@brief Transmit an L2CAP packet. + * + * @note It is important to note that a call to this function will <b>consume an application buffer</b>, and will therefore + * generate a @ref BLE_EVT_TX_COMPLETE event when the packet has been transmitted. + * See the documentation of @ref sd_ble_tx_packet_count_get for more details. + * + * @param[in] conn_handle Connection handle. + * @param[in] p_l2cap_header Pointer to a packet header containing length and CID. + * @param[in] p_data Pointer to the data to be transmitted. + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in,out] p_buf_len\ c in: Size of \p p_buf buffer. + * \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Successfully queued an L2CAP packet for transmission. + * @retval NRF_ERROR_INVALID_ADDR Invalid pointer supplied. + * @retval NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, CIDs must be registered beforehand with @ref sd_ble_l2cap_cid_register. + * @retval NRF_ERROR_NOT_FOUND CID not found. + * @retval NRF_ERROR_NO_MEM Not enough memory to complete operation. + * @retval NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, see @ref BLE_L2CAP_MTU_DEF. + */ +uint32_t ble_l2cap_tx_req_enc(uint16_t conn_handle, + ble_l2cap_header_t const * const p_l2cap_header, + uint8_t const * const p_data, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** + * @brief Decodes response to @ref sd_ble_l2cap_tx command. + * + * @sa @ref ble_l2cap_tx_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_INVALID_DATA Decoding failure. Decoded operation code does not match + * expected operation code. + */ +uint32_t ble_l2cap_tx_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); +#endif + +#if NRF_SD_BLE_API_VERSION >= 5 +uint32_t ble_l2cap_ch_setup_req_enc(uint16_t conn_handle, + uint16_t * p_local_cid, + ble_l2cap_ch_setup_params_t const *p_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +uint32_t ble_l2cap_ch_setup_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * p_local_cid, + uint32_t * const p_result_code); + +uint32_t ble_l2cap_ch_release_req_enc(uint16_t conn_handle, + uint16_t local_cid, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +uint32_t ble_l2cap_ch_release_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +uint32_t ble_l2cap_ch_rx_req_enc(uint16_t conn_handle, + uint16_t local_cid, + ble_data_t const *p_sdu_buf, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +uint32_t ble_l2cap_ch_rx_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +uint32_t ble_l2cap_ch_tx_req_enc(uint16_t conn_handle, + uint16_t local_cid, + ble_data_t const *p_sdu_buf, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +uint32_t ble_l2cap_ch_tx_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + +uint32_t ble_l2cap_ch_flow_control_req_enc(uint16_t conn_handle, + uint16_t local_cid, + uint16_t credits, + uint16_t *p_credits, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +uint32_t ble_l2cap_ch_flow_control_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint16_t * p_credits, + uint32_t * const p_result_code); +#endif //NRF_SD_BLE_API_VERSION >= 5 + +#ifdef __cplusplus +} +#endif + +#endif //BLE_L2CAP_APP_H__ + +/** + @} + */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_l2cap_evt_app.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_l2cap_evt_app.c new file mode 100644 index 0000000..392d860 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_l2cap_evt_app.c @@ -0,0 +1,183 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include "ble_serialization.h" +#include "ble_struct_serialization.h" +#include "ble_l2cap_struct_serialization.h" +#include "app_util.h" +#include "ble_l2cap_evt_app.h" + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t ble_l2cap_evt_rx_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_L2CAP_EVT_RX, l2cap, rx); + + SER_PULL_uint16(&p_event->evt.l2cap_evt.conn_handle); + SER_PULL_FIELD_EXTENDED(&p_event->evt.l2cap_evt.params.rx, ble_l2cap_evt_rx_t_dec); + + SER_EVT_DEC_END; +} +#endif + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION >= 5 + +uint32_t ble_l2cap_evt_ch_setup_request_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_L2CAP_EVT_CH_SETUP_REQUEST, l2cap, ch_setup_request); + + SER_PULL_uint16(&p_event->evt.l2cap_evt.conn_handle); + SER_PULL_uint16(&p_event->evt.l2cap_evt.local_cid); + SER_PULL_uint16(&p_event->evt.l2cap_evt.params.ch_setup_request.le_psm); + SER_PULL_FIELD(&p_event->evt.l2cap_evt.params.ch_setup_request.tx_params, ble_l2cap_ch_tx_params_t_dec); + + SER_EVT_DEC_END; +} + +uint32_t ble_l2cap_evt_ch_setup_refused_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_L2CAP_EVT_CH_SETUP_REFUSED, l2cap, ch_setup_refused); + + SER_PULL_uint16(&p_event->evt.l2cap_evt.conn_handle); + SER_PULL_uint16(&p_event->evt.l2cap_evt.local_cid); + SER_PULL_uint8(&p_event->evt.l2cap_evt.params.ch_setup_refused.source); + SER_PULL_uint16(&p_event->evt.l2cap_evt.params.ch_setup_refused.status); + + SER_EVT_DEC_END; +} + +uint32_t ble_l2cap_evt_ch_setup_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_L2CAP_EVT_CH_SETUP, l2cap, ch_setup); + + SER_PULL_uint16(&p_event->evt.l2cap_evt.conn_handle); + SER_PULL_uint16(&p_event->evt.l2cap_evt.local_cid); + SER_PULL_FIELD(&p_event->evt.l2cap_evt.params.ch_setup.tx_params, ble_l2cap_ch_tx_params_t_dec); + + SER_EVT_DEC_END; +} + +uint32_t ble_l2cap_evt_ch_released_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN_NO_STRUCT(BLE_L2CAP_EVT_CH_RELEASED, l2cap); + + SER_PULL_uint16(&p_event->evt.l2cap_evt.conn_handle); + SER_PULL_uint16(&p_event->evt.l2cap_evt.local_cid); + + SER_EVT_DEC_END; +} + +uint32_t ble_l2cap_evt_ch_sdu_buf_released_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_L2CAP_EVT_CH_SDU_BUF_RELEASED, l2cap, ch_sdu_buf_released); + + SER_PULL_uint16(&p_event->evt.l2cap_evt.conn_handle); + SER_PULL_uint16(&p_event->evt.l2cap_evt.local_cid); + SER_PULL_uint16(&p_event->evt.l2cap_evt.params.ch_sdu_buf_released.sdu_buf.len); + SER_PULL_uint32(&p_event->evt.l2cap_evt.params.ch_sdu_buf_released.sdu_buf.p_data); + + SER_EVT_DEC_END; +} + +uint32_t ble_l2cap_evt_ch_credit_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_L2CAP_EVT_CH_CREDIT, l2cap, ch_credit); + + SER_PULL_uint16(&p_event->evt.l2cap_evt.conn_handle); + SER_PULL_uint16(&p_event->evt.l2cap_evt.local_cid); + SER_PULL_uint16(&p_event->evt.l2cap_evt.params.credit.credits); + + SER_EVT_DEC_END; +} + +uint32_t ble_l2cap_evt_ch_rx_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_L2CAP_EVT_CH_RX, l2cap, ch_rx); + + SER_PULL_uint16(&p_event->evt.l2cap_evt.conn_handle); + SER_PULL_uint16(&p_event->evt.l2cap_evt.local_cid); + SER_PULL_uint16(&p_event->evt.l2cap_evt.params.rx.sdu_len); + SER_PULL_uint16(&p_event->evt.l2cap_evt.params.rx.sdu_buf.len); + + SER_PULL_uint32(&p_event->evt.l2cap_evt.params.rx.sdu_buf.p_data); + SER_PULL_buf(&p_event->evt.l2cap_evt.params.rx.sdu_buf.p_data, p_event->evt.l2cap_evt.params.rx.sdu_buf.len, p_event->evt.l2cap_evt.params.rx.sdu_buf.len); + + SER_EVT_DEC_END; +} + + +uint32_t ble_l2cap_evt_ch_tx_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len) +{ + SER_EVT_DEC_BEGIN(BLE_L2CAP_EVT_CH_TX, l2cap, ch_tx); + + SER_PULL_uint16(&p_event->evt.l2cap_evt.conn_handle); + SER_PULL_uint16(&p_event->evt.l2cap_evt.local_cid); + SER_PULL_uint16(&p_event->evt.l2cap_evt.params.tx.sdu_buf.len); + SER_PULL_uint32(&p_event->evt.l2cap_evt.params.tx.sdu_buf.p_data); + + SER_EVT_DEC_END; +} + +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_l2cap_evt_app.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_l2cap_evt_app.h new file mode 100644 index 0000000..e2d7958 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/ble_l2cap_evt_app.h @@ -0,0 +1,126 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef BLE_L2CAP_EVT_APP_H__ +#define BLE_L2CAP_EVT_APP_H__ + +/**@file + * + * @defgroup ble_l2cap_evt_app L2CAP Application event decoders + * @{ + * @ingroup ser_app_s130_codecs + * + * @brief L2CAP Application event decoders. + */ +#include "ble.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Decodes ble_l2cap_evt_rx event. + * + * If \p p_event is null, the required length of \p p_event is returned in \p p_event_len. + * + * @param[in] p_buf Pointer to the beginning of an event packet. + * @param[in] packet_len Length (in bytes) of the event packet. + * @param[in,out] p_event Pointer to a \ref ble_evt_t buffer where the decoded event will be + * stored. If NULL, required length will be returned in \p p_event_len. + * @param[in,out] p_event_len \c in: Size (in bytes) of \p p_event buffer. + * \c out: Length of decoded contents of \p p_event. + * + * @retval NRF_SUCCESS Decoding success. + * @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ble_l2cap_evt_rx_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +uint32_t ble_l2cap_evt_ch_setup_request_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +uint32_t ble_l2cap_evt_ch_setup_refused_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +uint32_t ble_l2cap_evt_ch_setup_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +uint32_t ble_l2cap_evt_ch_released_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +uint32_t ble_l2cap_evt_ch_sdu_buf_released_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +uint32_t ble_l2cap_evt_ch_credit_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + +uint32_t ble_l2cap_evt_ch_rx_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); + + +uint32_t ble_l2cap_evt_ch_tx_dec(uint8_t const * const p_buf, + uint32_t packet_len, + ble_evt_t * const p_event, + uint32_t * const p_event_len); +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/nrf_soc_app.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/nrf_soc_app.c new file mode 100644 index 0000000..dab842b --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/nrf_soc_app.c @@ -0,0 +1,95 @@ +/** + * Copyright (c) 2013 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include "nrf_soc_app.h" +#include "nrf_soc.h" +#include <stdlib.h> +#include <string.h> +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "nrf_soc_struct_serialization.h" +#include "app_util.h" + + +uint32_t ecb_block_encrypt_req_enc(nrf_ecb_hal_data_t * p_ecb_data, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_ECB_BLOCK_ENCRYPT); + SER_PUSH_COND(p_ecb_data, nrf_ecb_hal_data_t_in_enc); + SER_REQ_ENC_END; +} + + +uint32_t ecb_block_encrypt_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + nrf_ecb_hal_data_t * * const pp_ecb_data, + uint32_t * const p_result_code) +{ + SER_RSP_DEC_BEGIN(SD_ECB_BLOCK_ENCRYPT); + SER_PULL_COND(pp_ecb_data, nrf_ecb_hal_data_t_out_dec); + SER_RSP_DEC_END; +} + + +uint32_t power_system_off_req_enc(uint8_t * const p_buf, uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_POWER_SYSTEM_OFF); + SER_REQ_ENC_END; +} + + +uint32_t temp_get_req_enc(int32_t const * const p_temp, + uint8_t * const p_buf, + uint32_t * const p_buf_len) +{ + SER_REQ_ENC_BEGIN(SD_TEMP_GET); + SER_PUSH_COND(p_temp, NULL); + SER_REQ_ENC_END; +} + +uint32_t temp_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code, + int32_t * * const pp_temp) +{ + SER_RSP_DEC_BEGIN(SD_TEMP_GET); + SER_PULL_COND(pp_temp, uint32_t_dec); + SER_RSP_DEC_END; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/nrf_soc_app.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/nrf_soc_app.h new file mode 100644 index 0000000..ed1cb84 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/ble/serializers/nrf_soc_app.h @@ -0,0 +1,147 @@ +/** + * Copyright (c) 2013 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +/**@file + * + * @defgroup soc_app SOC Application command request encoders and command response decoders + * @{ + * @ingroup ser_app_s130_codecs + * + * @brief SOC Application command request encoders and command response decoders. + */ + +#ifndef NRF_SOC_APP_H__ +#define NRF_SOC_APP_H__ + +#include <stdint.h> +#include "nrf_soc.h" + +#ifdef __cplusplus +extern "C" { +#endif +/**@brief Encodes @ref sd_power_system_off command request. + * + * + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: size of p_buf buffer. \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t power_system_off_req_enc(uint8_t * const p_buf, uint32_t * const p_buf_len); + + +/**@brief Encodes @ref sd_temp_get command request. + * + * @sa @ref temp_get_rsp_dec for command response decoder. + * + * @param[in] p_temp Pointer to result of temperature measurement. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: size of p_buf buffer. \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t temp_get_req_enc(int32_t const * const p_temp, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_temp_get command. + * + * @sa @ref temp_get_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_result_code Command result code. + * @param[out] pp_temp Pointer to result of temperature measurement. + * + * @retval NRF_SUCCESS Version information stored successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t temp_get_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code, + int32_t * * const pp_temp); + +/**@brief Encodes @ref sd_ecb_block_encrypt command request. + * + * @sa @ref ecb_block_encrypt_rsp_dec for command response decoder. + * + * @param[in] p_ecb_data Pointer to ECB data. + * @param[in] p_buf Pointer to buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: size of p_buf buffer. \c out: Length of encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ecb_block_encrypt_req_enc(nrf_ecb_hal_data_t * p_ecb_data, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/**@brief Decodes response to @ref sd_ecb_block_encrypt command. + * + * @sa @ref ecb_block_encrypt_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to beginning of command response packet. + * @param[in] packet_len Length (in bytes) of response packet. + * @param[out] p_ecb_data Pointer to ECB data. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS Version information stored successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Length of \p p_event is too small to + * hold decoded event. + */ +uint32_t ecb_block_encrypt_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + nrf_ecb_hal_data_t * * const p_ecb_data, + uint32_t * const p_result_code); +/** @} */ + + +#ifdef __cplusplus +} +#endif + +#endif // NRF_SOC_APP_H__ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/common/ble_dtm_app.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/common/ble_dtm_app.c new file mode 100644 index 0000000..fe86167 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/common/ble_dtm_app.c @@ -0,0 +1,100 @@ +/** + * 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 "app_error.h" +#include "ble_dtm_app.h" +#include "ble_serialization.h" +#include "nrf_error.h" +#include "ser_config.h" +#include "ser_hal_transport.h" +#include "ser_sd_transport.h" + + +static uint32_t dtm_init_rsp_dec(const uint8_t * p_buffer, uint16_t length) +{ + uint32_t result_code; + + const uint32_t err_code = ble_dtm_init_rsp_dec(p_buffer, length, &result_code); + APP_ERROR_CHECK(err_code); + + return result_code; +} + + +uint32_t ble_dtm_init(app_uart_stream_comm_params_t * p_uart_comm_params) +{ + if (p_uart_comm_params == NULL) + { + return NRF_ERROR_NULL; + } + + uint32_t err_code = NRF_SUCCESS; + uint32_t index = 0; + + uint8_t * p_tx_buf = NULL; + uint32_t tx_buf_len = 0; + + err_code = ser_hal_transport_tx_pkt_alloc(&p_tx_buf, (uint16_t *)&tx_buf_len); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + + p_tx_buf[index++] = SER_PKT_TYPE_DTM_CMD; + tx_buf_len -= SER_PKT_TYPE_SIZE; + + err_code = ble_dtm_init_req_enc(p_uart_comm_params, &(p_tx_buf[SER_PKT_TYPE_SIZE]), &tx_buf_len); + if (err_code == NRF_SUCCESS) + { + tx_buf_len += SER_PKT_TYPE_SIZE; + + err_code = ser_sd_transport_cmd_write(p_tx_buf, tx_buf_len, dtm_init_rsp_dec); + if (err_code != NRF_SUCCESS) + { + 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/application/codecs/common/ble_dtm_app.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/common/ble_dtm_app.h new file mode 100644 index 0000000..3d008a3 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/common/ble_dtm_app.h @@ -0,0 +1,126 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef BLE_DTM_APP_H__ +#define BLE_DTM_APP_H__ + +/** + * @addtogroup ser_codecs Serialization codecs + * @ingroup ble_sdk_lib_serialization + * @brief Application and Connectivity codecs. + */ + +/** + * @addtogroup ser_codecs_app Application codecs + * @ingroup ser_codecs + */ + +/** + * @addtogroup ser_app_common_codecs Application common codecs + * @ingroup ser_codecs_app + */ + +/**@file + * + * @defgroup ble_dtm_app DTM Application command request encoders and command response decoders + * @{ + * @ingroup ser_app_common_codecs + * + * @brief DTM Application command request encoders and command response decoders. + */ + +#include "dtm_uart_params.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/**@brief Encodes the @ref ble_dtm_init command request. + * + * @sa @ref encoding_data for packet format, + * @ref ble_dtm_init_rsp_dec for command response decoder. + * + * @param[in] p_uart_comm_params Pointer to the UART configuration parameters. + * @param[in] p_buf Pointer to the buffer where encoded data command will be returned. + * @param[in,out] p_buf_len \c in: Size of \p p_buf buffer. + * \c out: Length of the encoded command packet. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length. + */ +uint32_t ble_dtm_init_req_enc(app_uart_stream_comm_params_t const * const p_uart_comm_params, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + + +/**@brief Decodes the response @ref ble_dtm_init command. + * + * @sa @ref encoding_data for packet format, + * @ref ble_dtm_init_req_enc for command request encoder. + * + * @param[in] p_buf Pointer to the beginning of a command response packet. + * @param[in] packet_len Length (in bytes) of the response packet. + * @param[out] p_result_code Command result code. + * + * @retval NRF_SUCCESS 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_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const p_result_code); + + +/**@brief Function to initializing the DTM mode. + * + * @param[in] p_uart_comm_params Pointer to the DTM UART configuration parameters. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied. + */ +uint32_t ble_dtm_init(app_uart_stream_comm_params_t * p_uart_comm_params); + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif // BLE_DTM_APP_H__ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/common/ble_dtm_init.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/common/ble_dtm_init.c new file mode 100644 index 0000000..16e3c47 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/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_app.h" +#include "ble_serialization.h" +#include "nrf_error.h" + +uint32_t ble_dtm_init_req_enc(app_uart_stream_comm_params_t const * const p_uart_comm_params, uint8_t * const p_buf, uint32_t * const p_buf_len) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_buf_len); + SER_ASSERT_NOT_NULL(p_uart_comm_params); + + uint32_t index = 0; + uint32_t buf_len = *p_buf_len; + uint32_t err_code; + + err_code = uint8_t_enc(&p_uart_comm_params->tx_pin_no, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_enc(&p_uart_comm_params->rx_pin_no, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_enc(&p_uart_comm_params->baud_rate, p_buf, buf_len, &index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + *p_buf_len = index; + + return err_code; +} + + +uint32_t ble_dtm_init_rsp_dec(uint8_t const * const p_buf, uint32_t packet_len, uint32_t * const p_result_code) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_result_code); + + uint32_t err_code; + uint32_t index = 0; + + err_code = uint32_t_dec(p_buf, packet_len, &index, p_result_code); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + SER_ASSERT(packet_len == index, NRF_ERROR_INVALID_LENGTH); + + return err_code; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/common/conn_systemreset.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/common/conn_systemreset.c new file mode 100644 index 0000000..b98e6d5 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/common/conn_systemreset.c @@ -0,0 +1,69 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include <stdint.h> +#include "ble_serialization.h" +#include "ser_hal_transport.h" +#include "ser_sd_transport.h" + + +uint32_t conn_systemreset(void) +{ + uint32_t err_code = NRF_SUCCESS; + uint8_t * p_tx_buf = NULL; + uint32_t tx_buf_len = 0; + + err_code = ser_hal_transport_tx_pkt_alloc(&p_tx_buf, (uint16_t *)&tx_buf_len); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + + SER_ASSERT_LENGTH_LEQ(SER_PKT_TYPE_SIZE, tx_buf_len); + p_tx_buf[SER_PKT_TYPE_POS] = SER_PKT_TYPE_RESET_CMD; + tx_buf_len = SER_PKT_TYPE_SIZE; + + err_code = ser_sd_transport_cmd_write(p_tx_buf, tx_buf_len, NULL); + if (err_code != NRF_SUCCESS) + { + err_code = NRF_ERROR_INTERNAL; + } + + return err_code; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/common/conn_systemreset.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/common/conn_systemreset.h new file mode 100644 index 0000000..00ea5f5 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/codecs/common/conn_systemreset.h @@ -0,0 +1,79 @@ +/** + * 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_SYSTEMRESET_H__ +#define CONN_SYSTEMRESET_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup ser_codecs Serialization codecs + * @ingroup ble_sdk_lib_serialization + */ + +/** + * @addtogroup ser_app_common_codecs Application common codecs + * @ingroup ser_codecs_app + */ + +/**@file + * + * @defgroup conn_systemreset Connectivity chip reset command request encoder + * @{ + * @ingroup ser_app_common_codecs + * + * @brief Connectivity chip reset command request encoder. + */ + +/**@brief Function for performing the connectivity chip reset. + * + * @retval NRF_SUCCESS Encoding success. + * @retval NRF_ERROR_INTERNAL Encoding failure. Transport error. + */ +uint32_t conn_systemreset(void); + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif // CONN_SYSTEMRESET_H__ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/hal/ser_app_hal.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/hal/ser_app_hal.h new file mode 100644 index 0000000..3c87057 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/hal/ser_app_hal.h @@ -0,0 +1,116 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +/**@file + * + * @defgroup ser_app_hal Serialization Application Hardware Abstraction Layer (HAL) + * @{ + * @ingroup ble_sdk_lib_serialization + * + * @brief Functions that set up hardware on Application Board and perform the reset of the Connectivity Board. + */ + +#ifndef SER_APP_HAL_H_ +#define SER_APP_HAL_H_ + +#include <stdint.h> +#include <stdbool.h> + +#ifdef __cplusplus +extern "C" { +#endif +typedef void (*ser_app_hal_flash_op_done_handler_t)(bool success); +/**@brief Function for initializing hardware modules. + * + * @details Function can initialize hardware modules on the Application Chip. It is optional to + * implement. It is called once the Connectivity Chip is initialized. + * + * @param handler Flash operation event handler. + * + * @return @ref NRF_SUCCESS HAL initialized successfully. + * @return @ref nrf_error "NRF_ERROR_..." HAL initialization failed. + * + */ +uint32_t ser_app_hal_hw_init(ser_app_hal_flash_op_done_handler_t handler); + +/**@brief Function for waiting for a given amount of time. + * + * @param[in] ms Number of milliseconds to wait. + * + */ +void ser_app_hal_delay(uint32_t ms); + +/**@brief Function for clearing the Connectivity Chip reset pin. + * + */ +void ser_app_hal_nrf_reset_pin_clear(void); + +/**@brief Function for setting the Connectivity Chip reset pin. + * + */ +void ser_app_hal_nrf_reset_pin_set(void); + + +/**@brief Function for setting the SoftDevice event interrupt priority that serves the events incoming + * from the Connectivity Chip. + * + * @note Serialization solution on the application side mimics a SoC solution where events are handled in + * the interrupt context in two ways: either directly in the interrupt context or with a message being posted to + * the scheduler. However, it is possible that the Application Chip does not use a dedicated interrupt + * for connectivity events. In that case, this function can be left empty and + * \ref ser_app_hal_nrf_evt_pending will directly call an interrupt handler function. + */ +void ser_app_hal_nrf_evt_irq_priority_set(void); + +/**@brief Function for setting a pending interrupt for serving events incoming from the Connectivity Chip. + * + * @note The interrupt used for event from the Connectivity Chip mimics behavior of SoC and it is not + * intended to be triggered by any hardware event. This function should be the only source of + * interrupt triggering. + */ +void ser_app_hal_nrf_evt_pending(void); + + + +#ifdef __cplusplus +} +#endif + +#endif /* SER_APP_HAL_H_ */ +/** @} */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/hal/ser_app_hal_nrf5x.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/hal/ser_app_hal_nrf5x.c new file mode 100644 index 0000000..7304a12 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/hal/ser_app_hal_nrf5x.c @@ -0,0 +1,163 @@ +/** + * 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_platform.h" +#include "ser_app_hal.h" +#include "nrf.h" +#include "nrf_gpio.h" +#include "nrf_soc.h" +#include "nrf_delay.h" +#include "nrf_nvmc.h" +#include "boards.h" +#include "ser_phy.h" +#include "ser_phy_config_app.h" +#include "nrf_drv_clock.h" + +#define SOFTDEVICE_EVT_IRQ SD_EVT_IRQn /**< SoftDevice Event IRQ number. Used for both protocol events and SoC events. */ +#define FLASH_WRITE_MAX_LENGTH ((uint16_t)NRF_FICR->CODEPAGESIZE) +#define BLE_FLASH_PAGE_SIZE ((uint16_t)NRF_FICR->CODEPAGESIZE) /**< Size of one flash page. */ + +static ser_app_hal_flash_op_done_handler_t m_flash_op_handler; +uint32_t ser_app_hal_hw_init(ser_app_hal_flash_op_done_handler_t handler) +{ + nrf_gpio_cfg_output(CONN_CHIP_RESET_PIN_NO); + + if (NRF_SUCCESS != nrf_drv_clock_init()) + { + return NRF_ERROR_INTERNAL; + } + + nrf_drv_clock_lfclk_request(NULL); + nrf_drv_clock_hfclk_request(NULL); + + while (false == nrf_drv_clock_hfclk_is_running()); + while (false == nrf_drv_clock_lfclk_is_running()); + + m_flash_op_handler = handler; + + return NRF_SUCCESS; +} + +void ser_app_hal_delay(uint32_t ms) +{ + nrf_delay_ms(ms); +} + +void ser_app_hal_nrf_reset_pin_clear() +{ + nrf_gpio_pin_clear(CONN_CHIP_RESET_PIN_NO); +} + +void ser_app_hal_nrf_reset_pin_set() +{ + nrf_gpio_pin_set(CONN_CHIP_RESET_PIN_NO); +} + +void ser_app_hal_nrf_evt_irq_priority_set() +{ + NVIC_SetPriority(SOFTDEVICE_EVT_IRQ, APP_IRQ_PRIORITY_LOWEST); +} + +void ser_app_hal_nrf_evt_pending() +{ + NVIC_SetPendingIRQ(SOFTDEVICE_EVT_IRQ); +} + +uint32_t sd_ppi_channel_enable_get(uint32_t * p_channel_enable) +{ + *p_channel_enable = NRF_PPI->CHEN; + return NRF_SUCCESS; +} + +uint32_t sd_ppi_channel_enable_set(uint32_t channel_enable_set_msk) +{ + NRF_PPI->CHEN = channel_enable_set_msk; + return NRF_SUCCESS; +} + +uint32_t sd_ppi_channel_assign(uint8_t channel_num, + const volatile void * evt_endpoint, + const volatile void * task_endpoint) +{ + NRF_PPI->CH[channel_num].TEP = (uint32_t)task_endpoint; + NRF_PPI->CH[channel_num].EEP = (uint32_t)evt_endpoint; + return NRF_SUCCESS; +} +/** + * @brief Check if given address is in device FLASH range. + * + * @param[in] ptr Address to check. + * @retval true Given address is located in FLASH. + * @retval false Given address is not located in FLASH. + */ +__STATIC_INLINE bool addr_is_in_FLASH(void const * const ptr) +{ + return ((((uintptr_t)ptr) & 0xFF000000u) == 0x00000000u); +} + +uint32_t sd_flash_page_erase(uint32_t page_number) +{ + uint32_t * p_page = (uint32_t *)(BLE_FLASH_PAGE_SIZE * page_number); + + if (!addr_is_in_FLASH(p_page)) + { + return NRF_ERROR_INVALID_ADDR; + } + + nrf_nvmc_page_erase((uint32_t) p_page); + m_flash_op_handler(true); + return NRF_SUCCESS; +} + +uint32_t sd_flash_write(uint32_t * const p_dst, uint32_t const * const p_src, uint32_t size) +{ + if (size > FLASH_WRITE_MAX_LENGTH) + { + return NRF_ERROR_INVALID_LENGTH; + } + + if (!addr_is_in_FLASH(p_dst)) + { + return NRF_ERROR_INVALID_ADDR; + } + + nrf_nvmc_write_words((uint32_t) p_dst, p_src, size); + m_flash_op_handler(true); + return NRF_SUCCESS; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/hal/ser_app_power_system_off.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/hal/ser_app_power_system_off.c new file mode 100644 index 0000000..056636f --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/hal/ser_app_power_system_off.c @@ -0,0 +1,62 @@ +/** + * 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.h" +#include "ser_app_power_system_off.h" + +static bool m_power_system_off = false; + + +void ser_app_power_system_off_set(void) +{ + m_power_system_off = true; +} + +bool ser_app_power_system_off_get(void) +{ + return m_power_system_off; +} + +void ser_app_power_system_off_enter(void) +{ + NRF_POWER->SYSTEMOFF = POWER_SYSTEMOFF_SYSTEMOFF_Enter; + + /*Only for debugging purpose, will not be reached without connected debugger*/ + while (1); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/hal/ser_app_power_system_off.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/hal/ser_app_power_system_off.h new file mode 100644 index 0000000..914a59e --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/hal/ser_app_power_system_off.h @@ -0,0 +1,60 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef APP_POWER_SYSTEM_OFF_H +#define APP_POWER_SYSTEM_OFF_H + +#include <stdbool.h> + +#ifdef __cplusplus +extern "C" { +#endif + +void ser_app_power_system_off_set(void); + +bool ser_app_power_system_off_get(void); + +void ser_app_power_system_off_enter(void); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/transport/ser_sd_transport.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/transport/ser_sd_transport.c new file mode 100644 index 0000000..8f0118a --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/transport/ser_sd_transport.c @@ -0,0 +1,325 @@ +/** + * 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 <stdbool.h> +#include <stdint.h> +#include <stddef.h> +#include "ser_sd_transport.h" +#include "ser_hal_transport.h" +#include "nrf_error.h" +#include "app_error.h" +#include "ble_serialization.h" +#include "ser_dbg_sd_str.h" +#include "ser_app_power_system_off.h" +#include "app_util.h" +#define NRF_LOG_MODULE_NAME ser_xfer +#include "nrf_log.h" +NRF_LOG_MODULE_REGISTER(); + +#ifdef BLE_STACK_SUPPORT_REQD +/** SoftDevice event handler. */ +static ser_sd_transport_evt_handler_t m_ble_evt_handler = NULL; +#endif // BLE_STACK_SUPPORT_REQD + +#ifdef ANT_STACK_SUPPORT_REQD +/** SoftDevice event handler for ANT events. */ +static ser_sd_transport_evt_handler_t m_ant_evt_handler = NULL; +#endif // ANT_STACK_SUPPORT_REQD + +/** 'One time' handler called in task context while waiting for response to scheduled command. */ +static ser_sd_transport_rsp_wait_handler_t m_ot_rsp_wait_handler = NULL; + +/** Handler called in task context while waiting for response to scheduled command. */ +static ser_sd_transport_rsp_wait_handler_t m_os_rsp_wait_handler = NULL; + +/** Handler called in serial peripheral interrupt context when response is received. */ +static ser_sd_transport_rsp_set_handler_t m_os_rsp_set_handler = NULL; + +/** Handler called when hal_transport notifies that packet reception has started. */ +static ser_sd_transport_rx_notification_handler_t m_rx_notify_handler = NULL; + +/** User decoder handler for expected response packet. */ +static ser_sd_transport_rsp_handler_t m_rsp_dec_handler = NULL; + +/** Flag indicated whether module is waiting for response packet. */ +static volatile bool m_rsp_wait = false; + +/** SoftDevice call return value decoded by user decoder handler. */ +static uint32_t m_return_value; + +/**@brief Function for handling the rx packets comming from hal_transport. + * + * @details + * This function is called in serial peripheral interrupt context. Response packets are handled in + * this context. Events are passed to the application and it is up to application in which context + * they are handled. + * + * @param[in] p_data Pointer to received data. + * @param[in] length Size of data. + */ +static void ser_sd_transport_rx_packet_handler(uint8_t * p_data, uint16_t length) +{ + if (p_data && (length >= SER_PKT_TYPE_SIZE)) + { + const uint8_t packet_type = p_data[SER_PKT_TYPE_POS]; + p_data += SER_PKT_TYPE_SIZE; + length -= SER_PKT_TYPE_SIZE; + + switch (packet_type) + { + case SER_PKT_TYPE_RESP: + case SER_PKT_TYPE_DTM_RESP: +#ifdef ANT_STACK_SUPPORT_REQD + case SER_PKT_TYPE_ANT_RESP: +#endif // ANT_STACK_SUPPORT_REQD + if (m_rsp_wait) + { + m_return_value = m_rsp_dec_handler(p_data, length); + (void)ser_sd_transport_rx_free(p_data); + + /* Reset response flag - cmd_write function is pending on it.*/ + m_rsp_wait = false; + + /* If os handler is set, signal os that response has arrived.*/ + if (m_os_rsp_set_handler) + { + m_os_rsp_set_handler(); + } + } + else + { + /* Unexpected packet. */ + (void)ser_sd_transport_rx_free(p_data); + APP_ERROR_HANDLER(packet_type); + } + break; + +#ifdef BLE_STACK_SUPPORT_REQD + case SER_PKT_TYPE_EVT: + /* It is ensured during opening that handler is not NULL. No check needed. */ + NRF_LOG_DEBUG("[EVT]: %s ", (uint32_t)ser_dbg_sd_evt_str_get(uint16_decode(&p_data[SER_EVT_ID_POS]))); // p_data points to EVT_ID + m_ble_evt_handler(p_data, length); + break; +#endif // BLE_STACK_SUPPORT_REQD + +#ifdef ANT_STACK_SUPPORT_REQD + case SER_PKT_TYPE_ANT_EVT: + /* It is ensured during opening that handler is not NULL. No check needed. */ + NRF_LOG_DEBUG("[ANT_EVT_ID]: %s ", (uint32_t)ser_dbg_sd_evt_str_get(uint16_decode(&p_data[SER_EVT_ID_POS]))); // p_data points to EVT_ID + m_ant_evt_handler(p_data, length); + break; +#endif // ANT_STACK_SUPPORT_REQD + + default: + (void)ser_sd_transport_rx_free(p_data); + APP_ERROR_HANDLER(packet_type); + break; + } + } +} + +/**@brief Function for handling the event from hal_transport. + * + * @param[in] event Event from hal_transport. + */ +static void ser_sd_transport_hal_handler(ser_hal_transport_evt_t event) +{ + switch (event.evt_type) + { + case SER_HAL_TRANSP_EVT_RX_PKT_RECEIVED: + ser_sd_transport_rx_packet_handler(event.evt_params.rx_pkt_received.p_buffer, + event.evt_params.rx_pkt_received.num_of_bytes); + break; + case SER_HAL_TRANSP_EVT_RX_PKT_RECEIVING: + if (m_rx_notify_handler) + { + m_rx_notify_handler(); + } + break; + case SER_HAL_TRANSP_EVT_TX_PKT_SENT: + if (ser_app_power_system_off_get() == true) + { + ser_app_power_system_off_enter(); + } + break; + case SER_HAL_TRANSP_EVT_PHY_ERROR: + + if (m_rsp_wait) + { + m_return_value = NRF_ERROR_INTERNAL; + + /* Reset response flag - cmd_write function is pending on it.*/ + m_rsp_wait = false; + + /* If os handler is set, signal os that response has arrived.*/ + if (m_os_rsp_set_handler) + { + m_os_rsp_set_handler(); + } + } + break; + default: + break; + } +} + +uint32_t ser_sd_transport_open(ser_sd_transport_evt_handler_t ble_evt_handler, + ser_sd_transport_evt_handler_t ant_evt_handler, + ser_sd_transport_rsp_wait_handler_t os_rsp_wait_handler, + ser_sd_transport_rsp_set_handler_t os_rsp_set_handler, + ser_sd_transport_rx_notification_handler_t rx_not_handler) +{ + m_os_rsp_wait_handler = os_rsp_wait_handler; + m_os_rsp_set_handler = os_rsp_set_handler; + m_rx_notify_handler = rx_not_handler; + m_ot_rsp_wait_handler = NULL; + +#ifdef ANT_STACK_SUPPORT_REQD + m_ant_evt_handler = ant_evt_handler; + + if (m_ant_evt_handler == NULL) + { + return NRF_ERROR_INVALID_PARAM; + } +#else + UNUSED_PARAMETER(ant_evt_handler); +#endif // ANT_STACK_SUPPORT_REQD + +#ifdef BLE_STACK_SUPPORT_REQD + m_ble_evt_handler = ble_evt_handler; + + if (m_ble_evt_handler == NULL) + { + return NRF_ERROR_INVALID_PARAM; + } +#else + UNUSED_PARAMETER(ble_evt_handler); +#endif // BLE_STACK_SUPPORT_REQD + + return ser_hal_transport_open(ser_sd_transport_hal_handler); +} + +uint32_t ser_sd_transport_close(void) +{ +#ifdef ANT_STACK_SUPPORT_REQD + m_ant_evt_handler = NULL; +#endif // ANT_STACK_SUPPORT_REQD + +#ifdef BLE_STACK_SUPPORT_REQD + m_ble_evt_handler = NULL; +#endif // BLE_STACK_SUPPORT_REQD + + m_os_rsp_wait_handler = NULL; + m_os_rsp_set_handler = NULL; + m_ot_rsp_wait_handler = NULL; + + ser_hal_transport_close(); + + return NRF_SUCCESS; +} + +uint32_t ser_sd_transport_ot_rsp_wait_handler_set(ser_sd_transport_rsp_wait_handler_t handler) +{ + m_ot_rsp_wait_handler = handler; + + return NRF_SUCCESS; +} + +bool ser_sd_transport_is_busy(void) +{ + return m_rsp_wait; +} + +uint32_t ser_sd_transport_tx_alloc(uint8_t * * pp_data, uint16_t * p_len) +{ + uint32_t err_code; + + if (m_rsp_wait) + { + err_code = NRF_ERROR_BUSY; + } + else + { + err_code = ser_hal_transport_tx_pkt_alloc(pp_data, p_len); + } + return err_code; +} + +uint32_t ser_sd_transport_tx_free(uint8_t * p_data) +{ + return ser_hal_transport_tx_pkt_free(p_data); +} + +uint32_t ser_sd_transport_rx_free(uint8_t * p_data) +{ + p_data -= SER_PKT_TYPE_SIZE; + return ser_hal_transport_rx_pkt_free(p_data); +} + +uint32_t ser_sd_transport_cmd_write(const uint8_t * p_buffer, + uint16_t length, + ser_sd_transport_rsp_handler_t cmd_rsp_decode_callback) +{ + uint32_t err_code = NRF_SUCCESS; + + m_rsp_wait = true; + m_rsp_dec_handler = cmd_rsp_decode_callback; + err_code = ser_hal_transport_tx_pkt_send(p_buffer, length); + APP_ERROR_CHECK(err_code); + + /* Execute callback for response decoding only if one was provided.*/ + if ((err_code == NRF_SUCCESS) && cmd_rsp_decode_callback) + { + if (m_ot_rsp_wait_handler) + { + m_ot_rsp_wait_handler(); + m_ot_rsp_wait_handler = NULL; + } + + m_os_rsp_wait_handler(); + err_code = m_return_value; + } + else + { + m_rsp_wait = false; + } + + NRF_LOG_DEBUG("[SD_CALL]:%s, err_code= 0x%X", (uint32_t)ser_dbg_sd_call_str_get(p_buffer[1]), err_code); + return err_code; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/transport/ser_sd_transport.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/transport/ser_sd_transport.h new file mode 100644 index 0000000..77dadf2 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/transport/ser_sd_transport.h @@ -0,0 +1,193 @@ +/** + * 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_app Application side code + * @ingroup ble_sdk_lib_serialization + * @brief SoftDevice handler and transport on the application side. + */ + +/** @file + * + * @defgroup ser_sd_transport Serialization SoftDevice Transport + * @{ + * @ingroup ser_app + * + * @brief Serialization SoftDevice Transport on application side. + * + * @details This file contains declarations of functions and definitions of data structures and + * identifiers (typedef enum) used as API of the serialization of SoftDevice. This layer + * ensures atomic nature of SoftDevice calls (command and waiting for response). Packet + * type field of incoming packets is handled in this layer - responses are handled by + * ser_sd_transport (using response decoder handler provided for each SoftDevice call), but + * events are forwarded to the user so it is up to the user to free the RX buffer. + * + */ +#ifndef SER_SD_TRANSPORT_H_ +#define SER_SD_TRANSPORT_H_ + +#include <stdint.h> +#include <stdbool.h> + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (*ser_sd_transport_evt_handler_t)(uint8_t * p_buffer, uint16_t length); +typedef void (*ser_sd_transport_rsp_wait_handler_t)(void); +typedef void (*ser_sd_transport_rsp_set_handler_t)(void); +typedef void (*ser_sd_transport_rx_notification_handler_t)(void); + +typedef uint32_t (*ser_sd_transport_rsp_handler_t)(const uint8_t * p_buffer, uint16_t length); + +/**@brief Function for opening the module. + * + * @note 'Wait for response' and 'Response set' callbacks can be set in RTOS environment. + * It enables rescheduling while waiting for the Connectivity Chip response. In a nonOS environment, + * usually 'Wait for response' will only be used for handling incoming events or forcing the + * application to low power mode. + * + * @param[in] ble_evt_handler Handler to be called when ble event packet is received. + * @param[in] ant_evt_handler Handler to be called when ant event packet is received. + * @param[in] os_rsp_wait_handler Handler to be called after the request is send. It should + * implement a 'Wait for signal' functionality in an OS environment. + * @param[in] os_rsp_set_handler Handler to be called after response reception. It should + * implement a 'Signal Set' functionality in an OS environment. + * @param[in] rx_not_handler Handler to be called after the transport layer notifies that + * an incoming RX packet is detected. + * + * @retval NRF_SUCCESS Operation success. + * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_PARAM Operation failure. Parameter propagated from ser_hal_transport + * opening or timer creation. + * @retval NRF_ERROR_INVALID_STATE Operation failure. Parameter propagated from ser_hal_transport + * opening or timer creation. + * @retval NRF_ERROR_INTERNAL Operation failure. Parameter propagated from ser_hal_transport + * opening or timer creation. + * @retval NRF_ERROR_NO_MEM Operation failure. Parameter propagated from timer creation. + */ +uint32_t ser_sd_transport_open(ser_sd_transport_evt_handler_t ble_evt_handler, + ser_sd_transport_evt_handler_t ant_evt_handler, + ser_sd_transport_rsp_wait_handler_t os_rsp_wait_handler, + ser_sd_transport_rsp_set_handler_t os_rsp_set_handler, + ser_sd_transport_rx_notification_handler_t rx_not_handler); + + +/**@brief Function setting a 'One Time' handler to be called between sending the next request packet and + * receiving the response packet. + * @note It is intended to be used in a nonOS environment to implement concurrency. + * @note It is a 'One Time' handler meaning that it is valid only for the next SoftDevice call processing. + * + * + * @param[in] wait_handler Handler to be called after the request packet is sent. + * + * @retval NRF_SUCCESS Operation success. + */ +uint32_t ser_sd_transport_ot_rsp_wait_handler_set(ser_sd_transport_rsp_wait_handler_t wait_handler); + + +/**@brief Function for closing the module. + * + * @retval NRF_SUCCESS Operation success. + */ +uint32_t ser_sd_transport_close(void); + +/**@brief Function for allocating a TX packet to be used for request command. + * + * @param[out] pp_data Pointer to the data pointer to be set to point to allocated buffer. + * @param[out] p_len Pointer to allocated buffer length. + * + * @retval NRF_SUCCESS Operation success. + */ +uint32_t ser_sd_transport_tx_alloc(uint8_t * * pp_data, uint16_t * p_len); + + +/**@brief Function for freeing a TX packet. + * + * @note Function should be called once the command is processed. + * + * @param[out] p_data Pointer to the allocated TX buffer. + * + * @retval NRF_SUCCESS Operation success. + */ +uint32_t ser_sd_transport_tx_free(uint8_t * p_data); + + +/**@brief Function for freeing an RX event packet. + * + * @note Function should be called once the SoftDevice event buffer is processed. + * + * @param[out] p_data Pointer to the allocated RX buffer. + * + * @retval NRF_SUCCESS Operation success. + */ +uint32_t ser_sd_transport_rx_free(uint8_t * p_data); + + +/**@brief Function for checking if module is busy waiting for response from connectivity side. + * + * @retval true Module busy. Cannot accept the next command. + * @retval false Module not busy. Can accept next the command. + */ +bool ser_sd_transport_is_busy(void); + +/**@brief Function for handling a SoftDevice command. + * + * @note Function blocks task context until response is received and processed. + * @note Non-blocking functionality can be achieved using OS handlers or a 'One Time' handler + * @warning Function should not be called from interrupt context, which would block switching to + * serial port interrupt. + * + * @param[in] p_buffer Pointer to command. + * @param[in] length Pointer to allocated buffer length. + * @param[in] cmd_resp_decode_callback Pointer to a function for decoding the response packet. + * + * @retval NRF_SUCCESS Operation success. + */ +uint32_t ser_sd_transport_cmd_write(const uint8_t * p_buffer, + uint16_t length, + ser_sd_transport_rsp_handler_t cmd_resp_decode_callback); + + +#ifdef __cplusplus +} +#endif + +#endif /* SER_SD_TRANSPORT_H_ */ +/** @} */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/transport/ser_softdevice_handler.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/transport/ser_softdevice_handler.c new file mode 100644 index 0000000..57db847 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/transport/ser_softdevice_handler.c @@ -0,0 +1,311 @@ +/** + * 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 "nrf_queue.h" +#include "app_scheduler.h" +#include "nrf_sdh.h" +#include "nrf_sdm.h" +#include "ser_sd_transport.h" +#include "ser_app_hal.h" +#include "ser_config.h" +#include "nrf_soc.h" +#include "ble_serialization.h" +#if defined(BLE_STACK_SUPPORT_REQD) +#include "ble_app.h" +#include "nrf_sdh_ble.h" +#endif +#if defined(ANT_STACK_SUPPORT_REQD) +#include "ant_event.h" +#endif + +#define SD_BLE_EVT_MAILBOX_QUEUE_SIZE 5 /**< Size of mailbox queue. */ + +/** @brief Structure used to pass packet details through mailbox. + */ +#if defined(BLE_STACK_SUPPORT_REQD) +typedef struct +{ + //lint -save -e666 + uint32_t evt_data[CEIL_DIV(NRF_SDH_BLE_EVT_BUF_SIZE, sizeof (uint32_t))]; /**< Buffer for decoded event */ + //lint -restore +} ser_sd_handler_evt_data_t; +#endif + +#if defined(ANT_STACK_SUPPORT_REQD) +typedef struct +{ + uint32_t evt_data[CEIL_DIV(sizeof(ant_evt_t), sizeof (uint32_t))]; /**< Buffer for decoded event */ +} ser_ant_sd_handler_evt_data_t; +#endif + +/** @brief + * Mailbox used for communication between event handler (called from serial stream + * interrupt context) and event processing function (called from scheduler or interrupt context). + */ +#if defined(BLE_STACK_SUPPORT_REQD) +NRF_QUEUE_DEF(ser_sd_handler_evt_data_t, + m_sd_ble_evt_mailbox, + SD_BLE_EVT_MAILBOX_QUEUE_SIZE, + NRF_QUEUE_MODE_NO_OVERFLOW); +#endif + +#if defined(ANT_STACK_SUPPORT_REQD) +NRF_QUEUE_DEF(ser_ant_sd_handler_evt_data_t, + m_sd_ant_evt_mailbox, + SD_BLE_EVT_MAILBOX_QUEUE_SIZE, + NRF_QUEUE_MODE_NO_OVERFLOW); +#endif + +NRF_QUEUE_DEF(uint32_t, + m_sd_soc_evt_mailbox, + SD_BLE_EVT_MAILBOX_QUEUE_SIZE, + NRF_QUEUE_MODE_NO_OVERFLOW); + +/** + * @brief Function to be replaced by user implementation if needed. + * + * Weak function - user can add different implementation of this function if application needs it. + */ +__WEAK void os_rsp_set_handler(void) +{ + +} + +static void connectivity_reset_low(void) +{ + //Signal a reset to the connectivity chip by setting the reset pin low. + ser_app_hal_nrf_reset_pin_clear(); + ser_app_hal_delay(CONN_CHIP_RESET_TIME); + +} + +static void connectivity_reset_high(void) +{ + + //Set the reset level to high again. + ser_app_hal_nrf_reset_pin_set(); + + //Wait for connectivity chip to be ready. + ser_app_hal_delay(CONN_CHIP_WAKEUP_TIME); +} + +#if defined(BLE_STACK_SUPPORT_REQD) +static void ser_softdevice_ble_evt_handler(uint8_t * p_data, uint16_t length) +{ + ser_sd_handler_evt_data_t item; + uint32_t err_code; + uint32_t len32 = sizeof (item.evt_data); + + err_code = ble_event_dec(p_data, length, (ble_evt_t *)item.evt_data, &len32); + APP_ERROR_CHECK(err_code); + + err_code = ser_sd_transport_rx_free(p_data); + APP_ERROR_CHECK(err_code); + + err_code = nrf_queue_push(&m_sd_ble_evt_mailbox, &item); + APP_ERROR_CHECK(err_code); + + ser_app_hal_nrf_evt_pending(); +} +#endif + +#if defined(ANT_STACK_SUPPORT_REQD) +static void ser_softdevice_ant_evt_handler(uint8_t * p_data, uint16_t length) +{ + ser_ant_sd_handler_evt_data_t item; + uint32_t err_code; + uint32_t len32 = sizeof (item.evt_data); + + err_code = ant_event_dec(p_data, length, (ant_evt_t *)item.evt_data, &len32); + APP_ERROR_CHECK(err_code); + + err_code = ser_sd_transport_rx_free(p_data); + APP_ERROR_CHECK(err_code); + + err_code = nrf_queue_push(&m_sd_ant_evt_mailbox, &item); + APP_ERROR_CHECK(err_code); + + ser_app_hal_nrf_evt_pending(); +} +#endif + +void ser_softdevice_flash_operation_success_evt(bool success) +{ + uint32_t evt_type = success ? NRF_EVT_FLASH_OPERATION_SUCCESS : + NRF_EVT_FLASH_OPERATION_ERROR; + + uint32_t err_code = nrf_queue_push(&m_sd_soc_evt_mailbox, &evt_type); + APP_ERROR_CHECK(err_code); + + ser_app_hal_nrf_evt_pending(); +} + +/** + * @brief Function called while waiting for connectivity chip response. It handles incoming events. + */ +static void ser_sd_rsp_wait(void) +{ + do + { + (void)sd_app_evt_wait(); + + //intern_softdevice_events_execute(); + } + while (ser_sd_transport_is_busy()); +} + +uint32_t sd_evt_get(uint32_t * p_evt_id) +{ + return nrf_queue_pop(&m_sd_soc_evt_mailbox, p_evt_id); +} + +#if defined(BLE_STACK_SUPPORT_REQD) +uint32_t sd_ble_evt_get(uint8_t * p_data, uint16_t * p_len) +{ + uint32_t err_code = nrf_queue_pop(&m_sd_ble_evt_mailbox, p_data); + + if (err_code == NRF_SUCCESS) //if anything in the mailbox + { + if (((ble_evt_t *)p_data)->header.evt_len > *p_len) + { + err_code = NRF_ERROR_DATA_SIZE; + } + else + { + *p_len = ((ble_evt_t *)p_data)->header.evt_len; + } + } + else + { + err_code = NRF_ERROR_NOT_FOUND; + } + + return err_code; +} +#endif + +#if defined(ANT_STACK_SUPPORT_REQD) +uint32_t sd_ant_event_get(uint8_t* p_channel, uint8_t* p_event, uint8_t* p_ant_mesg) +{ + SER_ASSERT_NOT_NULL(p_channel); + SER_ASSERT_NOT_NULL(p_event); + SER_ASSERT_NOT_NULL(p_ant_mesg); + + uint32_t err_code; + + ser_ant_sd_handler_evt_data_t item; + + err_code = nrf_queue_pop(&m_sd_ant_evt_mailbox, &item); + + if (err_code == NRF_SUCCESS) + { + *p_event = ((ant_evt_t *)item.evt_data) -> event; + *p_channel = ((ant_evt_t *)item.evt_data) -> channel; + memcpy(p_ant_mesg, ((ant_evt_t *)item.evt_data)->message.aucMessage, MESG_BUFFER_SIZE); + } else { + err_code = NRF_ERROR_NOT_FOUND; + } + + return err_code; +} +#endif + +#if defined(BLE_STACK_SUPPORT_REQD) +uint32_t sd_ble_evt_mailbox_length_get(uint32_t * p_mailbox_length) +{ + *p_mailbox_length = nrf_queue_utilization_get(&m_sd_ble_evt_mailbox); + return NRF_SUCCESS; +} +#endif + +#if (defined(S332) || defined(S212)) +uint32_t sd_softdevice_enable(nrf_clock_lf_cfg_t const * p_clock_lf_cfg, + nrf_fault_handler_t fault_handler, + const char* p_license_key) +#else +uint32_t sd_softdevice_enable(nrf_clock_lf_cfg_t const * p_clock_lf_cfg, + nrf_fault_handler_t assertion_handler) +#endif +{ + uint32_t err_code; + + err_code = ser_app_hal_hw_init(ser_softdevice_flash_operation_success_evt); + + if (err_code == NRF_SUCCESS) + { + connectivity_reset_low(); + + nrf_queue_reset(&m_sd_soc_evt_mailbox); + ser_sd_transport_evt_handler_t ble_evt_handler = NULL; + ser_sd_transport_evt_handler_t ant_evt_handler = NULL; + +#ifdef BLE_STACK_SUPPORT_REQD + ble_evt_handler = ser_softdevice_ble_evt_handler; + nrf_queue_reset(&m_sd_ble_evt_mailbox); +#endif // BLE_STACK_SUPPORT_REQD + +#ifdef ANT_STACK_SUPPORT_REQD + ant_evt_handler = ser_softdevice_ant_evt_handler; + nrf_queue_reset(&m_sd_ant_evt_mailbox); +#endif // ANT_STACK_SUPPORT_REQD + err_code = ser_sd_transport_open(ble_evt_handler, + ant_evt_handler, + ser_sd_rsp_wait, + os_rsp_set_handler, + NULL); + + if (err_code == NRF_SUCCESS) + { + connectivity_reset_high(); + } + + ser_app_hal_nrf_evt_irq_priority_set(); + } + + return err_code; +} + + +uint32_t sd_softdevice_disable(void) +{ + return ser_sd_transport_close(); +} + diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/transport/ser_softdevice_handler.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/transport/ser_softdevice_handler.h new file mode 100644 index 0000000..a07bf51 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/application/transport/ser_softdevice_handler.h @@ -0,0 +1,80 @@ +/** + * 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_app Application side code + * @ingroup ble_sdk_lib_serialization + */ + +/** @file + * + * @defgroup ser_softdevice_handler Serialization SoftDevice Handler + * @{ + * @ingroup ser_app + * + * @brief Serialization SoftDevice Handler on application side. + * + */ +#ifndef SER_SOFTDEVICE_HANDLER_H_ +#define SER_SOFTDEVICE_HANDLER_H_ + +#include <stdint.h> +#include <stdbool.h> + +#ifdef __cplusplus +extern "C" { +#endif + + +/**@brief Function for checking if there are any more events in the internal mailbox. + * + * @param[in] p_mailbox_length Pointer to mailbox length. + * + * @retval ::NRF_SUCCESS Length succesfully obtained. + * @retval ::NRF_ERROR_NULL Null pointer provided. + */ +uint32_t sd_ble_evt_mailbox_length_get(uint32_t * p_mailbox_length); + + +#ifdef __cplusplus +} +#endif + +#endif /* SER_SOFTDEVICE_HANDLER_H_ */ +/** @} */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/ble_serialization.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/ble_serialization.c new file mode 100644 index 0000000..de2b51f --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/ble_serialization.c @@ -0,0 +1,549 @@ +/** + * 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_serialization.h" +#include "nrf_error.h" +#include "app_util.h" +#include <stddef.h> +#include <string.h> + +uint32_t ser_ble_cmd_rsp_status_code_enc(uint8_t op_code, + uint32_t command_status, + 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; + + SER_ASSERT_LENGTH_LEQ(SER_CMD_RSP_HEADER_SIZE, *p_buf_len); + + //Encode Op Code. + p_buf[index++] = op_code; + + //Encode Status. + index += uint32_encode(command_status, &(p_buf[index])); + *p_buf_len = index; + + return NRF_SUCCESS; +} + + +uint32_t ser_ble_cmd_rsp_result_code_dec(uint8_t const * const p_buf, + uint32_t * const p_pos, + uint32_t packet_len, + uint8_t op_code, + uint32_t * const p_result_code) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_pos); + SER_ASSERT_NOT_NULL(p_result_code); + + if (packet_len < SER_CMD_RSP_HEADER_SIZE) + { + return NRF_ERROR_DATA_SIZE; + } + + if (p_buf[(*p_pos)] != op_code) + { + return NRF_ERROR_INVALID_DATA; + } + + *p_result_code = uint32_decode(&(p_buf[(*p_pos) + SER_CMD_RSP_STATUS_CODE_POS])); + *p_pos += SER_CMD_RSP_HEADER_SIZE; + + return NRF_SUCCESS; +} + + +uint32_t ser_ble_cmd_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t op_code, + uint32_t * const p_result_code) +{ + uint32_t index = 0; + uint32_t result_code = ser_ble_cmd_rsp_result_code_dec(p_buf, &index, packet_len, op_code, + p_result_code); + + if (result_code != NRF_SUCCESS) + { + return result_code; + } + + if (index != packet_len) + { + return NRF_ERROR_DATA_SIZE; + } + + return NRF_SUCCESS; +} + +uint32_t uint32_t_enc(void const * const p_field, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_field); + SER_ASSERT_NOT_NULL(p_index); + + uint32_t * p_uint32 = (uint32_t *)p_field; + + SER_ASSERT_LENGTH_LEQ(4, buf_len - *p_index); + + *p_index += uint32_encode(*p_uint32, &p_buf[*p_index]); + + return NRF_SUCCESS; +} + +uint32_t uint32_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * p_field) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_index); + SER_ASSERT_NOT_NULL(p_field); + + uint32_t * p_uint32 = (uint32_t *)p_field; + + SER_ASSERT_LENGTH_LEQ(4, ((int32_t)buf_len - *p_index)); + + *p_uint32 = uint32_decode(&p_buf[*p_index]); + *p_index += 4; + + return NRF_SUCCESS; +} + +uint32_t uint16_t_enc(const void * const p_field, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + uint16_t * p_u16 = (uint16_t *)p_field; + + SER_ASSERT_LENGTH_LEQ(2, buf_len - *p_index); + + *p_index += uint16_encode(*p_u16, &p_buf[*p_index]); + + return NRF_SUCCESS; +} + +uint32_t uint16_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * p_field) +{ + uint16_t * p_u16 = (uint16_t *)p_field; + + SER_ASSERT_LENGTH_LEQ(2, ((int32_t)buf_len - *p_index)); + + *p_u16 = uint16_decode(&p_buf[*p_index]); + *p_index += 2; + + return NRF_SUCCESS; +} + +void uint16_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const index, + uint16_t * const value) +{ + SER_ASSERT_VOID_RETURN(*index + 2 <= buf_len); + *value = uint16_decode(&p_buf[*index]); + *index += 2; +} + +uint32_t uint8_t_enc(const void * const p_field, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_ASSERT_LENGTH_LEQ(1, buf_len - *p_index); + + uint8_t * p_u8 = (uint8_t *)p_field; + p_buf[*p_index] = *p_u8; + *p_index += 1; + + return NRF_SUCCESS; +} + +uint32_t uint8_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * p_field) +{ + uint8_t * p_u8 = (uint8_t *)p_field; + + SER_ASSERT_LENGTH_LEQ(1, ((int32_t)buf_len - *p_index)); + *p_u8 = p_buf[*p_index]; + *p_index += 1; + + return NRF_SUCCESS; +} + +void uint8_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const index, + uint8_t * const value) +{ + SER_ASSERT_VOID_RETURN(*index + 1 <= buf_len); + *value = p_buf[*index]; + *index += 1; +} + + +void int8_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const index, + int8_t * const value) +{ + SER_ASSERT_VOID_RETURN(*index + 1 <= buf_len); + *value = p_buf[*index]; + *index += 1; +} + +uint32_t len8data_enc(uint8_t const * const p_data, + uint8_t const dlen, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + uint32_t err_code = NRF_SUCCESS; + + err_code = uint8_t_enc(&dlen, p_buf, buf_len, p_index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = buf_enc(p_data, dlen, p_buf, buf_len, p_index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t len8data_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint8_t * * const pp_data, + uint8_t * const p_len) +{ + uint32_t err_code = NRF_SUCCESS; + uint16_t out_buf_len = *p_len; + + err_code = uint8_t_dec(p_buf, buf_len, p_index, p_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = buf_dec(p_buf, buf_len, p_index, pp_data, out_buf_len, *p_len); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t len16data_enc(uint8_t const * const p_data, + uint16_t const dlen, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + uint32_t err_code = NRF_SUCCESS; + + err_code = uint16_t_enc(&dlen, p_buf, buf_len, p_index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = buf_enc(p_data, dlen, p_buf, buf_len, p_index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t len16data_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint8_t * * const pp_data, + uint16_t * const p_dlen) +{ + uint32_t err_code = NRF_SUCCESS; + uint16_t out_buf_len = *p_dlen; + + err_code = uint16_t_dec(p_buf, buf_len, p_index, p_dlen); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = buf_dec(p_buf, buf_len, p_index, pp_data, out_buf_len, *p_dlen); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t count16_cond_data16_enc(uint16_t const * const p_data, + uint16_t const count, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + uint32_t i = 0; + + SER_ASSERT_LENGTH_LEQ(3, ((int32_t)buf_len - *p_index)); + *p_index += uint16_encode(count, &p_buf[*p_index]); + + if (p_data) + { + SER_ASSERT_LENGTH_LEQ((int32_t)(2 * count + 1), ((int32_t)buf_len - (int32_t) * p_index)); + p_buf[*p_index] = SER_FIELD_PRESENT; + *p_index += 1; + + //memcpy may fail in case of Endianness difference between application and connectivity processor + for (i = 0; i < count; i++) + { + *p_index += uint16_encode(p_data[i], &p_buf[*p_index]); + } + } + else + { + SER_ASSERT_LENGTH_LEQ((1), ((int32_t)buf_len - *p_index)); + p_buf[*p_index] = SER_FIELD_NOT_PRESENT; + *p_index += 1; + } + + return NRF_SUCCESS; +} + +uint32_t count16_cond_data16_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint16_t * * const pp_data, + uint16_t * const p_count) + +{ + uint16_t count = 0; + uint8_t is_present = 0; + uint16_t i; + + SER_ASSERT_NOT_NULL(p_count); + SER_ASSERT_NOT_NULL(pp_data); + SER_ASSERT_NOT_NULL(*pp_data); + + SER_ASSERT_LENGTH_LEQ(3, ((int32_t)buf_len - (*p_index))); + + uint16_dec(p_buf, buf_len, p_index, &count); + + if (count > *p_count) + { + return NRF_ERROR_DATA_SIZE; + } + + SER_ASSERT_LENGTH_LEQ(count, *p_count); + + uint8_dec(p_buf, buf_len, p_index, &is_present); + + if (!is_present) + { + *p_count = count; + *pp_data = NULL; + return NRF_SUCCESS; + } + else + { + for (i = 0; i < count; i++ ) + { + uint16_dec(p_buf, buf_len, p_index, &((&(**pp_data))[i]) ); + } + *p_count = i; + } + return NRF_SUCCESS; +} + + + +uint32_t cond_len16_cond_data_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint8_t * * const pp_data, + uint16_t * * const pp_len) +{ + SER_ASSERT_NOT_NULL(pp_len); + SER_ASSERT_NOT_NULL(*pp_len); + SER_ASSERT_NOT_NULL(pp_data); + SER_ASSERT_NOT_NULL(*pp_data); + + SER_ASSERT_LENGTH_LEQ(2, ((int32_t)buf_len - (*p_index))); + uint8_t is_present = 0; + + uint8_dec(p_buf, buf_len, p_index, &is_present); + + if (!is_present) + { + *pp_len = NULL; //if length field is not present + (*p_index)++; //then data can not be present + *pp_data = NULL; + return NRF_SUCCESS; + } + else + { + return len16data_dec(p_buf, buf_len, p_index, pp_data, *pp_len); + } +} + +uint32_t op_status_enc(uint8_t op_code, + uint32_t return_code, + uint8_t * const p_buff, + uint32_t * const p_buff_len, + uint32_t * const p_index) +{ + SER_ASSERT_NOT_NULL(p_buff); + SER_ASSERT_NOT_NULL(p_buff_len); + SER_ASSERT_NOT_NULL(p_index); + SER_ASSERT_LENGTH_LEQ(SER_CMD_RSP_HEADER_SIZE, *p_buff_len - *p_index); + + //Encode Op Code. + p_buff[(*p_index)++] = op_code; + //Encode Status. + *p_index += uint32_encode(return_code, &(p_buff[*p_index])); + //update size of used buffer + *p_buff_len = *p_index; + + return NRF_SUCCESS; +} + +uint32_t op_status_cond_uint16_enc(uint8_t op_code, + uint32_t return_code, + uint16_t value, + uint8_t * const p_buff, + uint32_t * const p_buff_len, + uint32_t * const p_index) +{ + uint32_t status_code; + uint32_t init_buff_len = *p_buff_len; + + status_code = op_status_enc(op_code, return_code, p_buff, p_buff_len, p_index); + SER_ASSERT(status_code == NRF_SUCCESS, status_code); + + if (return_code == NRF_SUCCESS) //Add 16bit value when return_code is a success + { + *p_buff_len = init_buff_len; //restore original value - it has been modified by op_status_enc + status_code = uint16_t_enc(&value, p_buff, *p_buff_len, p_index); + *p_buff_len = *p_index; + SER_ASSERT(status_code == NRF_SUCCESS, status_code); + } + + return status_code; +} + +uint32_t buf_enc(uint8_t const * const p_data, + uint16_t const dlen, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + uint32_t err_code = NRF_SUCCESS; + uint8_t is_present = (p_data == NULL) ? SER_FIELD_NOT_PRESENT : SER_FIELD_PRESENT; + + err_code = uint8_t_enc(&is_present, p_buf, buf_len, p_index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + if (p_data) + { + SER_ASSERT_LENGTH_LEQ(dlen, ((int32_t)buf_len - *p_index)); + memcpy(&p_buf[*p_index], p_data, dlen); + *p_index += dlen; + } + + return err_code; +} + +uint32_t buf_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint8_t * * const pp_data, + uint16_t data_len, + uint16_t dlen) +{ + uint8_t is_present = 0; + + SER_ASSERT_LENGTH_LEQ(1, ((int32_t)buf_len - *p_index)); + uint8_dec(p_buf, buf_len, p_index, &is_present); + + if (is_present == SER_FIELD_PRESENT) + { + SER_ASSERT_NOT_NULL(pp_data); + SER_ASSERT_NOT_NULL(*pp_data); + SER_ASSERT_LENGTH_LEQ(dlen, data_len); + SER_ASSERT_LENGTH_LEQ(dlen, ((int32_t)buf_len - *p_index)); + memcpy(*pp_data, &p_buf[*p_index], dlen); + *p_index += dlen; + } + else + { + if (pp_data) + { + *pp_data = NULL; + } + } + return NRF_SUCCESS; +} + +uint32_t uint8_vector_enc(uint8_t const * const p_data, + uint16_t const dlen, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + + SER_ASSERT_NOT_NULL(p_data); + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_index); + SER_ASSERT_LENGTH_LEQ(dlen, ((int32_t)buf_len - *p_index)); + memcpy(&p_buf[*p_index], p_data, dlen); + *p_index += dlen; + + return NRF_SUCCESS; +} + +uint32_t uint8_vector_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint8_t * const p_data, + uint16_t dlen) +{ + SER_ASSERT_NOT_NULL(p_data); + SER_ASSERT_LENGTH_LEQ(dlen, ((int32_t)buf_len - *p_index)); + memcpy(p_data, &p_buf[*p_index], dlen); + *p_index += dlen; + + return NRF_SUCCESS; +} + diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/ble_serialization.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/ble_serialization.h new file mode 100644 index 0000000..d66c95a --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/ble_serialization.h @@ -0,0 +1,1097 @@ +/** + * 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_SERIALIZATION_H__ +#define BLE_SERIALIZATION_H__ + +#include "nordic_common.h" +#include "nrf_error.h" +#include <stdint.h> +#include <stddef.h> +#include "cond_field_serialization.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/**@brief Types of serialization packets. */ +typedef enum +{ + SER_PKT_TYPE_CMD = 0, /**< Command packet type. */ + SER_PKT_TYPE_RESP, /**< Command Response packet type. */ + SER_PKT_TYPE_EVT, /**< Event packet type. */ + SER_PKT_TYPE_DTM_CMD, /**< DTM Command packet type. */ + SER_PKT_TYPE_DTM_RESP, /**< DTM Response packet type. */ + SER_PKT_TYPE_RESET_CMD, /**< System Reset Command packet type. */ +#if defined(ANT_STACK_SUPPORT_REQD) + SER_PKT_TYPE_ANT_CMD, /**< ANT Command packet type. */ + SER_PKT_TYPE_ANT_RESP, /**< ANT Response packet type. */ + SER_PKT_TYPE_ANT_EVT, /**< ANT Event packet type. */ +#endif + SER_PKT_TYPE_MAX /**< Upper bound. */ +} ser_pkt_type_t; + +#define LOW16(a) ((uint16_t)((a & 0x0000FFFF) >> 0)) +#define HIGH16(a) ((uint16_t)((a & 0xFFFF0000) >> 16)) + +//lint -esym(516,__INTADDR__) Symbol '__INTADDR__()' has arg. type conflict +//lint -esym(628,__INTADDR__) no argument information provided for function '__INTADDR__()' + +/** Size in bytes of the Error Code field in a Command Response packet. */ +#define SER_ERR_CODE_SIZE 4 +/** Size in bytes of the Packet Type field (@ref ser_pkt_type_t). */ +#define SER_PKT_TYPE_SIZE 1 +/** Size in bytes of the Operation Code field. */ +#define SER_OP_CODE_SIZE 1 + +/** Position of the Packet Type field in a serialized packet buffer. */ +#define SER_PKT_TYPE_POS 0 +/** Position of the Operation Code field in a serialized packet buffer. */ +#define SER_PKT_OP_CODE_POS (SER_PKT_TYPE_SIZE) +/** Position of the Data in a serialized packet buffer. */ +#define SER_PKT_DATA_POS (SER_PKT_TYPE_SIZE + SER_OP_CODE_SIZE) + +/** Position of the Operation Code field in a command buffer. */ +#define SER_CMD_OP_CODE_POS 0 +/** Position of the Data in a command buffer.*/ +#define SER_CMD_DATA_POS (SER_OP_CODE_SIZE) +/** Size of the Command header. */ +#define SER_CMD_HEADER_SIZE (SER_OP_CODE_SIZE) +/** Size of the Command Response header. */ +#define SER_CMD_RSP_HEADER_SIZE (SER_OP_CODE_SIZE + SER_ERR_CODE_SIZE) +/** Position of the Command Response code. */ +#define SER_CMD_RSP_STATUS_CODE_POS (SER_OP_CODE_SIZE) + +/** Size of event ID field. */ +#define SER_EVT_ID_SIZE 2 +/** Position of event ID field. */ +#define SER_EVT_ID_POS 0 +/** Size of event header. */ +#define SER_EVT_HEADER_SIZE (SER_EVT_ID_SIZE) +/** Size of event connection handler. */ +#define SER_EVT_CONN_HANDLE_SIZE 2 + +#if defined(ANT_STACK_SUPPORT_REQD) +/** Size of event ID field. */ +#define SER_ANT_EVT_ID_SIZE 2 +/** Position of event ID field. */ +#define SER_ANT_EVT_ID_POS 0 +/** Size of event header. */ +#define SER_ANT_EVT_HEADER_SIZE (SER_ANT_EVT_ID_SIZE) +#endif + +/** Position of the Op Code in the DTM command buffer.*/ +#define SER_DTM_CMD_OP_CODE_POS 0 +/** Position of the data in the DTM command buffer.*/ +#define SER_DTM_CMD_DATA_POS 1 + +/** Position of the Op Code in the DTM command response buffer.*/ +#define SER_DTM_RESP_OP_CODE_POS 1 +/** Position of the status field in the DTM command response buffer.*/ +#define SER_DTM_RESP_STATUS_POS 2 + +/** Value to indicate that an optional field is encoded in the serialized packet, e.g. white list.*/ +#define SER_FIELD_PRESENT 0x01 +/** Value to indicate that an optional field is not encoded in the serialized packet. */ +#define SER_FIELD_NOT_PRESENT 0x00 + + +/** Enable SER_ASSERT<*> asserts */ +#define SER_ASSERTS_ENABLED 1 + +/** Returns with error code if expr is not true. It is used for checking error which should be + * checked even when SER_ASSERTS_ENABLED is not set. */ +#define SER_ERROR_CHECK(expr, error_code) do { if (!(expr)) return (error_code); } while (0) + + +#ifdef SER_ASSERTS_ENABLED +/** Returns with error code if expr is not true. */ +#define SER_ASSERT(expr, error_code) SER_ERROR_CHECK(expr, error_code) +/** Returns if expression is not true. */ +#define SER_ASSERT_VOID_RETURN(expr) do { if (!(expr)) return; } while (0) +/** Returns with \ref NRF_ERROR_INVALID_LENGTH if len is not less or equal to maxlen. */ +#define SER_ASSERT_LENGTH_LEQ(len, maxlen) \ + SER_ASSERT((len) <= (maxlen), NRF_ERROR_INVALID_LENGTH) +/** Returns with \ref NRF_ERROR_INVALID_LENGTH if actual_len is not equal to expected_len. */ +#define SER_ASSERT_LENGTH_EQ(actual_len, expected_len) \ + SER_ASSERT((actual_len) == (expected_len), NRF_ERROR_INVALID_LENGTH) +/** Returns with \ref NRF_ERROR_NULL if pointer is null. */ +#define SER_ASSERT_NOT_NULL(ptr) SER_ASSERT((ptr) != NULL, NRF_ERROR_NULL) +#else +#define SER_ASSERT(expr, error_code) +#define SER_ASSERT_VOID_RETURN(expr) +#define SER_ASSERT_LENGTH_LEQ(len, maxlen) UNUSED_VARIABLE(maxlen) +#define SER_ASSERT_LENGTH_EQ(actual_len, expected_len) +#define SER_ASSERT_NOT_NULL(ptr) +#endif + +#if defined(BLE_GATT_MTU_SIZE_DEFAULT) && !defined(GATT_MTU_SIZE_DEFAULT) +#define GATT_MTU_SIZE_DEFAULT BLE_GATT_MTU_SIZE_DEFAULT +#endif + +/** See Bluetooth 4.0 spec: 3.4.4.7. */ +#define BLE_GATTC_HANDLE_COUNT_LEN_MAX ((GATT_MTU_SIZE_DEFAULT - 1) / 2) + +/** Subtract 1 from X if X is greater than 0. */ +#define SUB1(X) (((X)>0) ? ((X)-1) : (X)) + +static inline void static_force_impl_castable_p_void(void const * const p) {} +/** Force the argument to be a double pointer. */ +#define STATIC_FORCE_PP(PP) static_force_impl_castable_p_void(*(PP)) + +/** Field decoder for special structures containing variable length data. */ +typedef uint32_t (*field_ext_decoder_handler_t)(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint32_t * const p_ext_length, + void * p_field); + + +/** Push uint8_t field into the output packet. */ +#define SER_PUSH_uint8(P_VAR) do { \ + err_code = uint8_t_enc((P_VAR), p_buf, buf_len, p_index); \ + SER_ASSERT(err_code == NRF_SUCCESS, err_code); \ + } while (0) + +/** Push uint16_t field into the output packet. */ +#define SER_PUSH_uint16(P_VAR) do { \ + err_code = uint16_t_enc((P_VAR), p_buf, buf_len, p_index); \ + SER_ASSERT(err_code == NRF_SUCCESS, err_code); \ + } while (0) + +/** Push uint32_t field into the output packet. */ +#define SER_PUSH_uint32(P_VAR) do { \ + err_code = uint32_t_enc((P_VAR), p_buf, buf_len, p_index); \ + SER_ASSERT(err_code == NRF_SUCCESS, err_code); \ + } while (0) + +/** Push int8_t field into the output packet. */ +#define SER_PUSH_int8(P_VAR) SER_PUSH_uint8(P_VAR) + +/** Push uint16_t field into the output packet. */ +#define SER_PUSH_int16(P_VAR) SER_PUSH_uint16(P_VAR) + +/** Push uint32_t field into the output packet. */ +#define SER_PUSH_int32(P_VAR) SER_PUSH_uint32(P_VAR) + +/** Push a constant length array of bytes into the output packet. */ +#define SER_PUSH_uint8array(P_DATA, LEN) do { \ + err_code = uint8_vector_enc((P_DATA), (LEN), p_buf, buf_len, p_index); \ + SER_ASSERT(err_code == NRF_SUCCESS, err_code); \ + } while (0) + +/** Push a variable length (8-bit) array of bytes into the output packet. */ +#define SER_PUSH_len8data(P_DATA, LEN) do { \ + err_code = len8data_enc((P_DATA), (LEN), p_buf, buf_len, p_index); \ + SER_ASSERT(err_code == NRF_SUCCESS, err_code); \ + } while (0) + +/** Push a variable length (16-bit) array of bytes into the output packet. */ +#define SER_PUSH_len16data(P_DATA, LEN) do { \ + err_code = len16data_enc((P_DATA), (LEN), p_buf, buf_len, p_index); \ + SER_ASSERT(err_code == NRF_SUCCESS, err_code); \ + } while (0) + +/** Push a variable length (16-bit) array of 16-bit words into the output packet. */ +#define SER_PUSH_len16data16(P_DATA, LEN) do { \ + err_code = count16_cond_data16_enc((P_DATA), (LEN), p_buf, buf_len, p_index); \ + SER_ASSERT(err_code == NRF_SUCCESS, err_code); \ + } while (0) + +/** Push a buffer into the output packet. */ +#define SER_PUSH_buf(P_DATA, LEN) do { \ + err_code = buf_enc((P_DATA), (LEN), p_buf, buf_len, p_index); \ + SER_ASSERT(err_code == NRF_SUCCESS, err_code); \ + } while (0) + +/** Push a structure into the output packet. */ +#define SER_PUSH_FIELD(P_VAR, P_ENCODER) do { \ + err_code = field_enc((P_VAR), p_buf, buf_len, p_index, (P_ENCODER)); \ + SER_ASSERT(err_code == NRF_SUCCESS, err_code); \ + } while (0) + +/** Push an array of structures into the output packet. */ +#define SER_PUSH_FIELD_ARRAY(P_ARRAY, P_ENCODER, COUNT) do { \ + for (uint32_t _idx = 0; _idx < (COUNT); ++_idx) \ + { \ + SER_PUSH_FIELD(&((P_ARRAY)[_idx]),P_ENCODER);\ + } \ + } while (0) + +/** Conditionally push a field if the specified pointer is not null. */ +#define SER_PUSH_COND(P_VAR, P_ENCODER) do { \ + err_code = cond_field_enc((P_VAR), p_buf, buf_len, p_index, (P_ENCODER)); \ + SER_ASSERT(err_code == NRF_SUCCESS, err_code); \ + } while (0) + + +/** Pull a uint8_t field from the input packet. */ +#define SER_PULL_uint8(P_VAR) do { \ + err_code = uint8_t_dec(p_buf, packet_len, p_index, (P_VAR)); \ + SER_ASSERT(err_code == NRF_SUCCESS, err_code); \ + } while (0) + +/** Pull a uint16_t field from the input packet. */ +#define SER_PULL_uint16(P_VAR) do { \ + err_code = uint16_t_dec(p_buf, packet_len, p_index, (P_VAR)); \ + SER_ASSERT(err_code == NRF_SUCCESS, err_code); \ + } while (0) + +/** Pull a uint32_t field from the input packet. */ +#define SER_PULL_uint32(P_VAR) do { \ + err_code = uint32_t_dec(p_buf, packet_len, p_index, (P_VAR)); \ + SER_ASSERT(err_code == NRF_SUCCESS, err_code); \ + } while (0) + +/** Pull an int8_t field from the input packet. */ +#define SER_PULL_int8(P_VAR) SER_PULL_uint8(P_VAR) + +/** Pull an int16_t field from the input packet. */ +#define SER_PULL_int16(P_VAR) SER_PULL_uint16(P_VAR) + +/** Pull an int32_t field from the input packet. */ +#define SER_PULL_int32(P_VAR) SER_PULL_uint32(P_VAR) + +/** Pull a constant length byte array from the input packet. */ +#define SER_PULL_uint8array(P_DATA, LEN) do { \ + err_code = uint8_vector_dec(p_buf, packet_len, p_index, (P_DATA), (LEN)); \ + SER_ASSERT(err_code == NRF_SUCCESS, err_code); \ + } while (0) + +/** Pull a variable length (8-bit) byte array from the input packet. */ +#define SER_PULL_len8data(PP_DATA, LEN) do { \ + STATIC_FORCE_PP(PP_DATA); \ + err_code = len8data_dec(p_buf, packet_len, p_index, (PP_DATA), (LEN)); \ + SER_ASSERT(err_code == NRF_SUCCESS, err_code); \ + } while (0) + +/** Pull a variable length (16-bit) byte array from the input packet. */ +#define SER_PULL_len16data(PP_DATA, P_LEN) do { \ + STATIC_FORCE_PP(PP_DATA); \ + err_code = len16data_dec(p_buf, packet_len, p_index, (PP_DATA), (P_LEN)); \ + SER_ASSERT(err_code == NRF_SUCCESS, err_code); \ + } while (0) + +/** Pull a variable length (16-bit) word (16-bit) array from the input packet. */ +#define SER_PULL_len16data16(PP_DATA, P_LEN) do { \ + STATIC_FORCE_PP(PP_DATA); \ + err_code = count16_cond_data16_dec(p_buf, packet_len, p_index, (PP_DATA), (P_LEN)); \ + SER_ASSERT(err_code == NRF_SUCCESS, err_code); \ + } while (0) + +/** Pull a buffer from the input packet. */ +#define SER_PULL_buf(PP_DATA, OUT_BUF_LEN, LEN) do { \ + STATIC_FORCE_PP(PP_DATA); \ + err_code = buf_dec(p_buf, packet_len, p_index, (PP_DATA), (OUT_BUF_LEN), (LEN)); \ + SER_ASSERT(err_code == NRF_SUCCESS, err_code); \ + } while (0) + +/** Pull a structure from the input packet. */ +#define SER_PULL_FIELD(P_VAR, P_DECODER) do { \ + err_code = field_dec(p_buf, packet_len, p_index, (P_VAR), (P_DECODER)); \ + SER_ASSERT(err_code == NRF_SUCCESS, err_code); \ + } while (0) + +/** Pull an array of structures from the input packet. */ +#define SER_PULL_FIELD_ARRAY(P_ARRAY, P_DECODER, COUNT) do { \ + for (uint32_t _idx = 0; _idx < (COUNT); ++_idx) \ + { \ + SER_PULL_FIELD(&((P_ARRAY)[_idx]),P_DECODER); \ + } \ + } while (0) + +/** Conditionally pull a structure from the input packet. */ +#define SER_PULL_COND(PP_VAR, P_DECODER) do { \ + STATIC_FORCE_PP(PP_VAR); \ + err_code = cond_field_dec(p_buf, packet_len, p_index, (void * *)(PP_VAR), (P_DECODER)); \ + SER_ASSERT(err_code == NRF_SUCCESS, err_code); \ + } while (0) + + +/** Start the encoding of a structure and prepare local variables for the usage of SER_PUSH_ macros. */ +#define SER_STRUCT_ENC_BEGIN(STRUCT_TYPE) \ + SER_ASSERT_NOT_NULL(p_buf); \ + SER_ASSERT_NOT_NULL(p_index); \ + SER_ASSERT_NOT_NULL(p_void_struct); \ + STRUCT_TYPE * p_struct = (STRUCT_TYPE *) p_void_struct; \ + uint32_t err_code = NRF_SUCCESS + +/** End the encoding of a structure. */ +#define SER_STRUCT_ENC_END return err_code + +/** Start the decoding of a structure and prepare local variables for the usage of SER_PULL_ macros. */ +#define SER_STRUCT_DEC_BEGIN(STRUCT_TYPE) \ + SER_ASSERT_NOT_NULL(p_buf); \ + SER_ASSERT_NOT_NULL(p_index); \ + SER_ASSERT_NOT_NULL(p_void_struct); \ + STRUCT_TYPE * p_struct = (STRUCT_TYPE *) p_void_struct; \ + uint32_t err_code = NRF_SUCCESS; \ + uint32_t packet_len = buf_len + +/** End the encoding of a structure. */ +#define SER_STRUCT_DEC_END return err_code + + +/** Start the encoding of command request and prepare local variables for the usage of SER_PUSH_ macros. */ +#define SER_REQ_ENC_BEGIN(OPCODE) \ + SER_ASSERT_NOT_NULL(p_buf); \ + SER_ASSERT_NOT_NULL(p_buf_len); \ + \ + uint32_t index = 0; \ + uint32_t * const p_index = &index; \ + uint32_t err_code = NRF_SUCCESS; \ + uint32_t buf_len = *p_buf_len; \ + \ + uint8_t opcode = (OPCODE); \ + SER_PUSH_uint8(&opcode) + +/** End the encoding of command request. */ +#define SER_REQ_ENC_END \ + *p_buf_len = index; \ + return NRF_SUCCESS \ + +/** Start the decoding of command response that does not contain any data except the result code. */ +#define SER_RSP_DEC_RESULT_ONLY(OPCODE) \ + return ser_ble_cmd_rsp_dec(p_buf, packet_len, (OPCODE), p_result_code) + +/** Start the decoding of command response and prepare local variables for the usage of SER_PULL_ macros. */ +#define SER_RSP_DEC_BEGIN(OPCODE) \ + SER_ASSERT_NOT_NULL(p_buf); \ + SER_ASSERT_NOT_NULL(p_result_code); \ + uint32_t err_code = NRF_SUCCESS; \ + uint32_t index = 0; \ + uint32_t * const p_index = &index; \ + /* Decode the result code and exit if decoding has failed or \ + the decoded result is not NRF_SUCCESS. */ \ + err_code = ser_ble_cmd_rsp_result_code_dec(p_buf, &index, packet_len, (OPCODE), p_result_code); \ + \ + SER_ASSERT(err_code == NRF_SUCCESS, err_code); \ + if (*p_result_code != NRF_SUCCESS) \ + { \ + SER_ASSERT_LENGTH_EQ(index, packet_len); \ + return NRF_SUCCESS; \ + } + +/** End the decoding of command response. */ +#define SER_RSP_DEC_END \ + /* Require all data to be pulled. */ \ + SER_ASSERT_LENGTH_EQ(index, packet_len); \ + return err_code + + +/** Start the decoding of command request and prepare local variables for the usage of SER_PULL_ macros. */ +#define SER_REQ_DEC_BEGIN(OPCODE) \ + SER_ASSERT_NOT_NULL(p_buf); \ + SER_ASSERT(packet_len>0, NRF_ERROR_INVALID_PARAM); \ + uint32_t index = 0; \ + uint32_t * const p_index = &index; \ + uint32_t err_code = NRF_SUCCESS; \ + SER_ASSERT(p_buf[index] == (OPCODE), NRF_ERROR_INVALID_PARAM); \ + (void)err_code; \ + (void)p_index; \ + ++index + +/** End the decoding of command request. */ +#define SER_REQ_DEC_END \ + SER_ASSERT_LENGTH_EQ(index, packet_len); \ + return NRF_SUCCESS + +/** Start the encoding of command response and prepare local variables for the usage of SER_PUSH_ macros. */ +#define SER_RSP_ENC_BEGIN(OPCODE) \ + SER_ASSERT_NOT_NULL(p_buf); \ + SER_ASSERT_NOT_NULL(p_buf_len); \ + uint32_t index = 0; \ + uint32_t * const p_index = &index; \ + uint32_t err_code = NRF_SUCCESS; \ + uint32_t buf_len = *p_buf_len; \ + /* Push the opcode + result and exit if result \ + is not NRF_SUCCESS. */ \ + uint8_t opcode = (OPCODE); \ + SER_PUSH_uint8(&opcode); \ + SER_PUSH_uint32(&return_code); \ + \ + SER_ASSERT(err_code == NRF_SUCCESS, err_code); \ + if (return_code != NRF_SUCCESS) \ + { \ + SER_RSP_ENC_END; \ + } + +/** Start the encoding of command response that contains the result code only. */ +#define SER_RSP_ENC_RESULT_ONLY(OPCODE) \ + return ser_ble_cmd_rsp_status_code_enc((OPCODE), return_code, p_buf, p_buf_len) + +/** End the encoding of command response. */ +#define SER_RSP_ENC_END \ + *p_buf_len = index; \ + return NRF_SUCCESS + + +/** Start the encoding of an event and prepare local variables for the usage of SER_PUSH_ macros. */ +#define SER_EVT_ENC_BEGIN(EVT_HEADER) \ + SER_ASSERT_NOT_NULL(p_event); \ + SER_ASSERT_NOT_NULL(p_buf); \ + SER_ASSERT_NOT_NULL(p_buf_len); \ + SER_ASSERT(p_event->header.evt_id == (EVT_HEADER), NRF_ERROR_INVALID_PARAM); \ + uint32_t index = 0; \ + uint32_t * p_index = &index; \ + uint32_t buf_len = *p_buf_len; \ + uint32_t err_code = NRF_SUCCESS; \ + uint16_t evt_header = (EVT_HEADER); \ + /* Push event header. */ \ + SER_PUSH_uint16(&evt_header) + +/** End the encoding of an event. */ +#define SER_EVT_ENC_END \ + *p_buf_len = index; \ + return err_code + + +/** Start the decoding of an event that has an event-specific data structure + and prepare local variables for the usage of SER_PULL_ macros. */ +#define SER_EVT_DEC_BEGIN(EVT_CODE, EVT_GROUP, EVT_NAME) \ + uint32_t err_code = NRF_SUCCESS; \ + uint32_t index = 0; \ + uint32_t * p_index = &index; \ + SER_ASSERT_NOT_NULL(p_buf); \ + SER_ASSERT_NOT_NULL(p_event_len); \ + /* Calculate the base event structure length */ \ + /* and make sure that there is enough free space */ \ + /* in the output buffer. */ \ + uint32_t evt_struct_len = \ + offsetof(ble_evt_t, evt.EVT_GROUP##_evt.params) \ + - offsetof(ble_evt_t, evt) \ + + sizeof(ble_##EVT_GROUP##_evt_##EVT_NAME##_t); \ + SER_ASSERT_LENGTH_LEQ(evt_struct_len, *p_event_len); \ + *p_event_len -= evt_struct_len; \ + /* Some structures contains variable length arrays */ \ + /* and the overall size may be greater. */ \ + uint32_t evt_extended_len = 0; \ + (void) evt_extended_len; \ + p_event->header.evt_id = EVT_CODE + +/** Start the decoding of an event that has no event-specific data structure. + and prepare local variables for the usage of SER_PULL_ macros. */ +#define SER_EVT_DEC_BEGIN_NO_STRUCT(EVT_CODE, EVT_GROUP) \ + uint32_t err_code = NRF_SUCCESS; \ + uint32_t index = 0; \ + uint32_t * p_index = &index; \ + SER_ASSERT_NOT_NULL(p_buf); \ + SER_ASSERT_NOT_NULL(p_event_len); \ + /* Calculate the base event structure length */ \ + /* and make sure that there is enough free space */ \ + /* in the output buffer. */ \ + uint32_t evt_struct_len = \ + offsetof(ble_evt_t, evt.EVT_GROUP##_evt.params) \ + - offsetof(ble_evt_t, evt) ; \ + SER_ASSERT_LENGTH_LEQ(evt_struct_len, *p_event_len); \ + *p_event_len -= evt_struct_len; \ + /* Some structures contain variable length arrays */ \ + /* and the overall size may be greater. */ \ + uint32_t evt_extended_len = 0; \ + (void) evt_extended_len; \ + p_event->header.evt_id = EVT_CODE + +/** End the decoding of an event. */ +#define SER_EVT_DEC_END \ + SER_ASSERT_LENGTH_EQ(index, packet_len); \ + /*p_event_len = index; */ \ + /*p_event->header.evt_len = index; */ \ + *p_event_len = evt_struct_len + evt_extended_len; \ + return NRF_SUCCESS + +/** Push an event-specific special field that contains variable length fields and get the extended data size. */ +#define SER_PULL_FIELD_EXTENDED(P_VAR, P_DECODER) \ + do \ + { \ + uint32_t field_ext_len = *p_event_len; \ + err_code = field_ext_dec(p_buf, packet_len, p_index, &field_ext_len, (P_VAR), (P_DECODER)); \ + SER_ASSERT(err_code == NRF_SUCCESS, err_code); \ + *p_event_len -= field_ext_len; \ + evt_extended_len += field_ext_len; \ + } while (0) \ + + +/** Generic command response status code encoder. */ +uint32_t ser_ble_cmd_rsp_status_code_enc(uint8_t op_code, + uint32_t command_status, + uint8_t * const p_buf, + uint32_t * const p_buf_len); + +/** Generic command response result code decoder. */ +uint32_t ser_ble_cmd_rsp_result_code_dec(uint8_t const * const p_buf, + uint32_t * const p_pos, + uint32_t packet_len, + uint8_t op_code, + uint32_t * const p_result_code); + +/** Generic command response decoder. */ +uint32_t ser_ble_cmd_rsp_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint8_t op_code, + uint32_t * const p_result_code); + + + +/**@brief Function for safe field encoding field. + * + * @param[in] p_field Pointer to the input struct. Must not be a null. + * @param[in] p_buf Pointer to the beginning of the output buffer. + * @param[in] buf_len Size of the buffer. + * @param[in,out] p_index \c in: Index to start of uint8 value in buffer. + * \c out: Index in the buffer to the first byte after the encoded data. + * @param[in] fp_field_encoder Pointer to the function that implements fields encoding. + * + * @return NRF_SUCCESS Field encoded successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_NULL p_field or fp_field_encoder is NULL. + */ +static inline uint32_t field_enc(void const * const p_field, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + field_encoder_handler_t fp_field_encoder) +{ + SER_ASSERT_NOT_NULL(fp_field_encoder); + SER_ASSERT_NOT_NULL(p_field); + + return fp_field_encoder(p_field, p_buf, buf_len, p_index); +} + +/**@brief Function for safe field decoding. + * + * Function checks if conditional field is present in the input buffer and if it is set, it calls + * the provided parser function that attempts to parse the buffer content to the known field. + * + * @param[in] p_buf Pointer to the beginning of the input buffer. + * @param[in] buf_len Size of the buffer. + * @param[in,out] p_index \c in: Index to the start of uint8 value in buffer. + * \c out: Index in the buffer to the first byte after the decoded data. + * @param[in] p_field Pointer to the output location. + * @param[in] fp_field_decoder Pointer to the function that implements field decoding. + * + * @return NRF_SUCCESS Field decoded successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_NULL p_field or fp_field_decoder is NULL. + */ +static inline uint32_t field_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_field, + field_decoder_handler_t fp_field_decoder) +{ + SER_ASSERT_NOT_NULL(fp_field_decoder); + SER_ASSERT_NOT_NULL(p_field); + + return fp_field_decoder(p_buf, buf_len, p_index, p_field); +} + +/**@brief Function for safe decoding of an event-specific field that contains extended data. + * + * Some event structures contain a variable length array (extended data), + * that may be written next to the event structure. + * + * @param[in] p_buf Pointer to the beginning of the input buffer. + * @param[in] buf_len Size of the buffer. + * @param[in,out] p_index \c in: Index to the start of uint8 value in the buffer. + * \c out: Index in the buffer to the first byte after the decoded data. + * @param[in,out] p_ext_length \c in: Maximum size of extended data. + * \c out: Extended data length in bytes. + * @param[in] p_field Pointer to output location. + * @param[in] fp_field_decoder Pointer to the function that implements field decoding. + * + * @return NRF_SUCCESS Field decoded successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_NULL p_field or fp_field_decoder is NULL. + */ +static inline uint32_t field_ext_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint32_t * const p_ext_length, + void * const p_field, + field_ext_decoder_handler_t fp_field_decoder) +{ + SER_ASSERT_NOT_NULL(fp_field_decoder); + SER_ASSERT_NOT_NULL(p_field); + + return fp_field_decoder(p_buf, buf_len, p_index, p_ext_length, p_field); +} + +/**@brief Function for safe encoding an uint16 value. + * + * Safe decoding of a uint16 value. Range checks will be done if @ref SER_ASSERTS_ENABLED is set. + * + * @param[in] p_field A uint16 value to be encoded. + * @param[out] p_buf Buffer containing the value. + * @param[in] buf_len Size of the buffer. + * @param[in,out] p_index \c in: Index to the start of the uint16 value in the buffer. + * \c out: Index in the buffer to the first byte after the decoded value. + * + * @return NRF_SUCCESS Fields decoded successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t uint16_t_enc(const void * const p_field, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +/**@brief Function for safe decoding of a uint16 value. + * + * Safe decoding of a uint16 value. Range checks will be done if @ref SER_ASSERTS_ENABLED is set. + * + * @param[in] p_buf Buffer containing the value. + * @param[in] buf_len Size of the buffer. + * @param[in,out] p_index \c in: Index to the start of the uint16 value in the buffer. + * \c out: Index in the buffer to the first byte after the decoded value. + * @param[out] p_field Pointer to the location where the uint16 value will be decoded. + */ +uint32_t uint16_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * p_field); + +/**@brief Function for safe decoding of a uint16 value. + * + * Safe decoding of a uint16 value. Range checks will be done if @ref SER_ASSERTS_ENABLED is set. + * + * @param[in] p_buf Buffer containing the value. + * @param[in] buf_len Size of the buffer. + * @param[in,out] index \c in: Index to the start of the uint16 value in buffer. + * \c out: Index in the buffer to the first byte after the decoded value. + * @param[out] value Decoded uint16 value. + */ +void uint16_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const index, + uint16_t * const value); + +/**@brief Function for safe encoding of a uint18 value. + * + * Safe decoding of a uint8 value. Range checks will be done if @ref SER_ASSERTS_ENABLED is set. + * + * @param[in] p_buf Buffer containing the value. + * @param[in] buf_len Size of the buffer. + * @param[in,out] p_index \c in: Index to the start of the uint8 value in the buffer. + * \c out: Index in the buffer to the first byte after the decoded value. + * @param[out] p_field Pointer to uint8 value to be encoded. + * + * @return NRF_SUCCESS Fields decoded successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t uint8_t_enc(const void * const p_field, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +/**@brief Function for safe decoding of a uint8 value. + * + * Safe decoding of a uint8 value. Range checks will be done if @ref SER_ASSERTS_ENABLED is set. + * + * @param[in] p_buf Buffer containing the value. + * @param[in] buf_len Size of the buffer. + * @param[in,out] p_index \c in: Index to the start of the uint8 value in buffer. + * \c out: Index in the buffer to the first byte after the decoded value. + * @param[out] p_field Pointer to the location for decoded uint8 value. + * + * @return NRF_SUCCESS Fields decoded successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t uint8_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * p_field); + +/**@brief Function for safe decoding of a uint8 value. + * + * Safe decoding of a uint8 value. Range checks will be done if @ref SER_ASSERTS_ENABLED is set. + * + * @param[in] p_buf Buffer containing the value. + * @param[in] buf_len Size of the buffer. + * @param[in,out] index \c in: Index to the start of the uint8 value in the buffer. + * \c out: Index in the buffer to the first byte after the decoded value. + * @param[out] value Decoded uint8 value. + */ +void uint8_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const index, + uint8_t * const value); + +/**@brief Function for safe decoding of a uint18 value. + * + * Safe decoding of a uint8 value. Range checks will be done if @ref SER_ASSERTS_ENABLED is set. + * + * @param[in] p_buf Buffer containing the value. + * @param[in] buf_len Size of the buffer. + * @param[in,out] index \c in: Index to the start of the uint8 value in the buffer. + * \c out: Index in the buffer to the first byte after the decoded value. + * @param[out] value Decoded uint8 value. + */ +void int8_dec(uint8_t const * const p_buf, + uint32_t packet_len, + uint32_t * const index, + int8_t * const value); + +/**@brief Function for safe encoding of a variable length field encoded as length(8bit) + data. + * + * Safe encoding of a variable length field. Range checks will be done if @ref SER_ASSERTS_ENABLED is set. + * + * @param[out] p_data Pointer to data to encode. + * @param[in] dlen Length of data to encode (0-255). + * @param[out] p_buf Buffer containing the value. + * @param[in] buf_len Size of the buffer. + * @param[in,out] p_index \c in: Index to the start of the uint8 value in the buffer. + * \c out: Index in the buffer to the first byte after the decoded value. + * + * @return NRF_SUCCESS Fields decoded successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t len8data_enc(uint8_t const * const p_data, + uint8_t const dlen, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +/**@brief Function for safe decoding of a variable length field encoded as length(8bit) + data. + * + * Safe decoding of a variable length field. Range checks will be done if @ref SER_ASSERTS_ENABLED is set. + * + * @param[in] p_buf Buffer containing the value. + * @param[in] buf_len Size of the buffer. + * @param[in,out] p_index \c in: Index to the start of the uint8 value in the buffer. + * \c out: Index in the buffer to the first byte after the decoded value. + * @param[out] pp_data Pointer to decoded data (p_data is set to NULL in + * case data is not present in the buffer). + * @param[out] p_len Decoded length (0-255). + * + * @return NRF_SUCCESS Fields decoded successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t len8data_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint8_t * * const pp_data, + uint8_t * const p_len); + +/**@brief Function for safe encoding of a variable length field encoded as length(16 bit) + data. + * + * Safe encoding of a variable length field. Range checks will be done if @ref SER_ASSERTS_ENABLED is set. + * It is possible that provided p_data is NULL. In that case, length is encoded and it is followed by + * SER_FIELD_NOT_PRESENT flag. Otherwise, the SER_FIELD_PRESENT flag precedes the data. + * + * @param[in] p_data Data to encode. + * @param[in] dlen Input data length (16 bit). + * @param[in] p_buf Pointer to the beginning of the output buffer. + * @param[in] buf_len Size of the buffer. + * @param[in,out] p_index \c in: Index to the start of the uint8 value in the buffer. + * \c out: Index in the buffer to the first byte after the encoded data. + * + * @return NRF_SUCCESS Fields decoded successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t len16data_enc(uint8_t const * const p_data, + uint16_t const dlen, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +/**@brief Function for safe decoding of a variable length field encoded as length(16 bit) + data. + * + * Safe decoding of a variable length field. Range checks will be done if @ref SER_ASSERTS_ENABLED is set. + * Encoded data consists of a length field, a presence flag, and conditional data (present only if the presence flag + * is set). The p_data pointer cannot be NULL if the presence flag is set. + * + * @param[in] p_buf Pointer to the beginning of the input buffer. + * @param[in] buf_len Size of the buffer. + * @param[in,out] p_index \c in: Index to the start of the uint8 value in the buffer. + * \c out: Index in the buffer to the first byte after the decoded data. + * @param[in] pp_data Pointer to decoded data. + * @param[in] p_dlen Data length (16 bit). + * + * @return NRF_SUCCESS Fields decoded successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t len16data_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint8_t * * const pp_data, + uint16_t * const p_dlen); + + +/**@brief Function for safe encoding of a uint16 table with a given element count. + * + * Safe encoding of a variable length field. Range checks will be done if @ref SER_ASSERTS_ENABLED is set. + * It is possible that the provided p_data is NULL. In that case, length is encoded and it is followed by a + * SER_FIELD_NOT_PRESENT flag. Otherwise, the SER_FIELD_PRESENT flag precedes the data. + * + * @param[in] p_data Data table to encode. + * @param[in] count Table element count. + * @param[in] p_buf Pointer to the beginning of the output buffer. + * @param[in] buf_len Size of the buffer. + * @param[in,out] p_index \c in: Index to the start of the uint8 value in the buffer. + * \c out: Index in the buffer to the first byte after the encoded data. + * + * @return NRF_SUCCESS Fields decoded successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ + +uint32_t count16_cond_data16_enc(uint16_t const * const p_data, + uint16_t const count, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +/**@brief Function for safe decoding of a uint16 table with a given element count. + * + * Safe encoding of a variable length field. Range checks will be done if @ref SER_ASSERTS_ENABLED is set. + * It is possible that the provided p_data is NULL. In that case, length is encoded and it is followed by a + * SER_FIELD_NOT_PRESENT flag. Otherwise, the SER_FIELD_PRESENT flag precedes the data. + * + * @param[in] p_buf Pointer to the beginning of the output buffer. + * @param[in] buf_len Size of the buffer. + * @param[in,out] p_index \c in: Index to the start of the uint8 value in the buffer. + * \c out: Index in the buffer to the first byte after the encoded data. + * @param[in] pp_data Pointer to the table to encode. + * @param[in,out] p_count Pointer to table element count - initialised with max count. + * + * @return NRF_SUCCESS Fields decoded successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_DATA_SIZE Decoding failure. Initial count is smaller than actual. + */ + +uint32_t count16_cond_data16_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint16_t * * const pp_data, + uint16_t * const p_count); + + +/**@brief Function for safe decoding of a variable length field encoded as length(16 bit) + data. + * + * Safe decoding of a variable length field. Range checks will be done if @ref SER_ASSERTS_ENABLED is set. + * Encoded data consists of a presence flag, an optional length field, a second presence flag, and optional data. + * + * + * @param[in] p_buf Pointer to the beginning of the input buffer. + * @param[in] buf_len Size of the buffer. + * @param[in,out] p_index \c in: Index to the start of the uint8 value in the buffer. + * \c out: Index in the buffer to the first byte after the decoded data. + * @param[out] pp_data Pointer to decoded data. + * @param[out] pp_len Data length (16 bit). + * + * @return NRF_SUCCESS Fields decoded successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ + +uint32_t cond_len16_cond_data_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint8_t * * const pp_data, + uint16_t * * const pp_len); + +/**@brief Command response encoder - replacement of ser_ble_cmd_rsp_status_code_enc + * with layout aligned to the rest of encoder functions. + * + * @param[in] op_code Operation code - see BLE_GAP_SVCS. + * @param[in] return_code nRF error code. + * @param[in] p_buff Pointer to the start of pointer to decoded data. + * @param[in,out] p_buff_len \c in: Size of the buffer. + * \c out: Used bytes in the buffer. + * @param[in,out] p_buff_len \c in: Initial offset in the buffer. + * \c out: Final offset in the buffer. + * + * @return NRF_SUCCESS Fields decoded successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_NULL Invalid pointer. + */ +uint32_t op_status_enc(uint8_t op_code, + uint32_t return_code, + uint8_t * const p_buff, + uint32_t * const p_buff_len, + uint32_t * const p_index); + +/**@brief Command response encoder with a conditional 16-bit field. + * + * @param[in] op_code Operation code - see BLE_GAP_SVCS. + * @param[in] return_code nRF error code. + * @param[in] value Optional 16-bit field encoded for return code == NRF_SUCCESS. + * @param[in] p_buff Pointer to the start of pointer to decoded data. + * @param[in,out] p_buff_len \c in: Size of the buffer. + * \c out: Used bytes in the buffer. + * @param[in,out] p_buff_len \c in: Initial offset in the buffer. + * \c out: Final offset in the buffer. + * + * @return NRF_SUCCESS Fields decoded successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + * @retval NRF_ERROR_NULL Invalid pointer. + */ + +uint32_t op_status_cond_uint16_enc(uint8_t op_code, + uint32_t return_code, + uint16_t value, + uint8_t * const p_buff, + uint32_t * const p_buff_len, + uint32_t * const p_index); + +/**@brief Function for safe encoding of a buffer of known size. + * + * Safe encoding of a buffer. Encoder assumes that the size is known to the decoder and it is not + * encoded here. Range checks will be done if @ref SER_ASSERTS_ENABLED is set. + * + * @param[in] p_data Data to encode. + * @param[in] dlen Input data length (16 bit). + * @param[in] p_buf Pointer to the beginning of the output buffer. + * @param[in] buf_len Size of the buffer. + * @param[in,out] p_index \c in: Index to the start of the uint8 value in the buffer. + * \c out: Index in the buffer to the first byte after the encoded data. + * + * @return NRF_SUCCESS Fields decoded successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t buf_enc(uint8_t const * const p_data, + uint16_t const dlen, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +/**@brief Function for safe decoding of a buffer of known size. + * + * Safe decoding of a buffer of known size. Range checks will be done if @ref SER_ASSERTS_ENABLED is set. + * Encoded data consists of a presence flag and conditional data (present only if the presence flag + * is set). The p_data pointer cannot be NULL only if the presence flag is set. Length is provided + * as input to the function. + * + * @param[in] p_buf Pointer to the beginning of the input buffer. + * @param[in] buf_len Size of the buffer. + * @param[in,out] p_index \c in: Index to the start of the uint8 value in the buffer. + * \c out: Index in the buffer to the first byte after the decoded data. + * @param[in] pp_data Pointer to decoded data. + * @param[in] data_len Length of the buffer for decoded data (16 bit). + * @param[in] dlen Length of the data to decode (16 bit). + * + * @return NRF_SUCCESS Fields decoded successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t buf_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint8_t * * const pp_data, + uint16_t data_len, + uint16_t dlen); + +/**@brief Function for safe encoding of a uint32 value. + * + * Safe decoding of a uint32 value. Range checks will be done if @ref SER_ASSERTS_ENABLED is set. + * + * @param[in] p_field A uint32 value to be encoded. + * @param[out] p_buf Buffer containing the value. + * @param[in] buf_len Size of the buffer. + * @param[in,out] p_index \c in: Index to the start of the uint32 value in the buffer. + * \c out: Index in the buffer to the first byte after the decoded value. + * + * @return NRF_SUCCESS Fields decoded successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t uint32_t_enc(void const * const p_field, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +/**@brief Function for safe decoding of a uint32 value. + * + * Safe decoding of a uint32 value. Range checks will be done if @ref SER_ASSERTS_ENABLED is set. + * + * @param[in] p_buf Buffer containing the value. + * @param[in] buf_len Size of the buffer. + * @param[in,out] p_index \c in: Index to the start of the uint32 value in the buffer. + * \c out: Index in the buffer to the first byte after the decoded value. + * @param[out] value Decoded uint32 value. + */ +uint32_t uint32_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * p_field); + +/**@brief Function for safe encoding of a uint8 vector. + * + * Range checks will be done if @ref SER_ASSERTS_ENABLED is set. + * * + * @param[in] p_data Data to encode. + * @param[in] dlen Input data length (16 bit). + * @param[in] p_buf Pointer to the beginning of the output buffer. + * @param[in] buf_len Size of the buffer. + * @param[in,out] p_index \c in: Index to the start of the uint8 value in the buffer. + * \c out: Index in the buffer to the first byte after the encoded data. + * + * @return NRF_SUCCESS Fields decoded successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t uint8_vector_enc(uint8_t const * const p_data, + uint16_t const dlen, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +/**@brief Function for safe decoding a uint8 vector. + * + * Safe decoding of a buffer of known size. Range checks will be done if @ref SER_ASSERTS_ENABLED is set. + * Vector length is provided as input to the function. + * + * @param[in] p_buf Pointer to the beginning of the input buffer. + * @param[in] buf_len Size of the buffer. + * @param[in,out] p_index \c in: Index to the start of the uint8 value in the buffer. + * \c out: Index in the buffer to the first byte after the decoded data. + * @param[in] p_data Pointer to decoded data. + * @param[in] dlen Length of data to decode (16 bit). + * + * @return NRF_SUCCESS Fields decoded successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t uint8_vector_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint8_t * const p_data, + uint16_t dlen); + + +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/cond_field_serialization.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/cond_field_serialization.c new file mode 100644 index 0000000..049dc27 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/cond_field_serialization.c @@ -0,0 +1,101 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include "nrf_error.h" +#include "cond_field_serialization.h" +#include "ble_serialization.h" +#include <stddef.h> + +uint32_t cond_field_enc(void const * const p_field, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + field_encoder_handler_t fp_field_encoder) +{ + uint32_t err_code = NRF_SUCCESS; + + SER_ASSERT_LENGTH_LEQ(*p_index + 1, buf_len); + p_buf[*p_index] = (p_field == NULL) ? SER_FIELD_NOT_PRESENT : SER_FIELD_PRESENT; + *p_index += 1; + + if (p_field && (fp_field_encoder != NULL)) + { + err_code = fp_field_encoder(p_field, p_buf, buf_len, p_index); + } + + return err_code; +} + + +uint32_t cond_field_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * * const pp_field, + field_decoder_handler_t fp_field_decoder) +{ + uint32_t err_code = NRF_SUCCESS; + uint8_t is_present; + + SER_ASSERT_LENGTH_LEQ(1, buf_len - *p_index); + uint8_dec(p_buf, buf_len, p_index, &is_present); + + if (is_present == SER_FIELD_PRESENT) + { + SER_ASSERT_NOT_NULL(pp_field); + SER_ASSERT_NOT_NULL(*pp_field); + + if (fp_field_decoder != NULL) + { + err_code = fp_field_decoder(p_buf, buf_len, p_index, *pp_field); + } + } + else if (is_present == SER_FIELD_NOT_PRESENT) + { + if (pp_field != NULL) + { + *pp_field = NULL; + } + } + else + { + err_code = NRF_ERROR_INVALID_DATA; + } + + return err_code; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/cond_field_serialization.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/cond_field_serialization.h new file mode 100644 index 0000000..b3103b1 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/cond_field_serialization.h @@ -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. + * + */ +#ifndef COND_FIELD_SERIALIZATION_H__ +#define COND_FIELD_SERIALIZATION_H__ + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +typedef uint32_t (*field_encoder_handler_t)(void const * const p_field, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +typedef uint32_t (*field_decoder_handler_t)(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * p_field); + +/**@brief Function for safe encoding of a conditional field. + * + * Function sets a presence flag and checks if conditional field is provided. If the field is not NULL, + * it calls the provided parser function which attempts to encode the field content to the buffer stream. + * + * @param[in] p_field Pointer to the input struct. + * @param[in] p_buf Pointer to the beginning of the output buffer. + * @param[in] buf_len Size of the buffer. + * @param[in,out] p_index \c in: Index to the start of the uint8 value in the buffer. + * \c out: Index in the buffer to the first byte after the encoded data. + * @param[in] fp_field_encoder Pointer to the function which implements fields encoding. + * + * @return NRF_SUCCESS Fields encoded successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t cond_field_enc(void const * const p_field, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + field_encoder_handler_t fp_field_encoder); + +/**@brief Function for safe decoding of a conditional field. + * + * Function checks if conditional field is present in the input buffer. If it is set, it calls + * the provided parser function which attempts to parse the buffer content to the known field. + * + * @param[in] p_buf Pointer to the beginning of the input buffer. + * @param[in] buf_len Size of the buffer. + * @param[in,out] p_index \c in: Index to the start of the uint8 value in the buffer. + * \c out: Index in the buffer to the first byte after the decoded data. + * @param[in] pp_field Pointer to output location. + * @param[in] fp_field_decoder Pointer to the function which implements field decoding. + * + * @return NRF_SUCCESS Fields decoded successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t cond_field_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * * const pp_field, + field_decoder_handler_t fp_field_decoder); + +#ifdef __cplusplus +} +#endif + +#endif // COND_FIELD_SERIALIZATION_H__ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/ser_config.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/ser_config.h new file mode 100644 index 0000000..a432d2e --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/ser_config.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 SER_CONFIG_H__ +#define SER_CONFIG_H__ + +#include <stdint.h> + +#include "nrf.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/***********************************************************************************************//** + * General parameters configuration. + **************************************************************************************************/ + +/** Value used as error code on SoftDevice stack dump. Can be used to identify stack location on + * stack unwind.*/ +#define SER_SD_ERROR_CODE (0xDEADBEEFUL) + +/** Value used as error code indicating warning - unusual situation but not critical so system + * should NOT be reset. */ +#define SER_WARNING_CODE (0xBADDCAFEUL) + +/***********************************************************************************************//** + * HAL Transport layer configuration. + **************************************************************************************************/ + +/** Max packets size in serialization HAL Transport layer (packets before adding PHY header i.e. + * packet length). */ +#define SER_HAL_TRANSPORT_APP_TO_CONN_MAX_PKT_SIZE (512UL) +#define SER_HAL_TRANSPORT_CONN_TO_APP_MAX_PKT_SIZE (512UL) + +#define SER_HAL_TRANSPORT_MAX_PKT_SIZE ((SER_HAL_TRANSPORT_APP_TO_CONN_MAX_PKT_SIZE) >= \ + (SER_HAL_TRANSPORT_CONN_TO_APP_MAX_PKT_SIZE) \ + ? \ + (SER_HAL_TRANSPORT_APP_TO_CONN_MAX_PKT_SIZE) : \ + (SER_HAL_TRANSPORT_CONN_TO_APP_MAX_PKT_SIZE)) +#ifdef SER_CONNECTIVITY + #define SER_HAL_TRANSPORT_TX_MAX_PKT_SIZE SER_HAL_TRANSPORT_CONN_TO_APP_MAX_PKT_SIZE + #define SER_HAL_TRANSPORT_RX_MAX_PKT_SIZE SER_HAL_TRANSPORT_APP_TO_CONN_MAX_PKT_SIZE + +#else /* APPLICATION SIDE */ + #define SER_HAL_TRANSPORT_TX_MAX_PKT_SIZE SER_HAL_TRANSPORT_APP_TO_CONN_MAX_PKT_SIZE + #define SER_HAL_TRANSPORT_RX_MAX_PKT_SIZE SER_HAL_TRANSPORT_CONN_TO_APP_MAX_PKT_SIZE +#endif /* SER_CONNECTIVITY */ + + +/***********************************************************************************************//** + * SER_PHY layer configuration. + **************************************************************************************************/ + +#define SER_PHY_HEADER_SIZE 2 + +#define SER_PHY_HCI_SLIP_TX_BUF_SIZE 30 + +#define SER_PHY_SPI_FREQUENCY NRF_DRV_SPI_FREQ_1M + +/** Max transfer unit for SPI MASTER and SPI SLAVE. */ +#define SER_PHY_SPI_MTU_SIZE 255 + +/** UART transmission parameters */ +#define SER_PHY_UART_FLOW_CTRL NRF_UART_HWFC_ENABLED +#define SER_PHY_UART_PARITY NRF_UART_PARITY_INCLUDED +#define SER_PHY_UART_BAUDRATE_VAL 1000000 + +#define SER_PHY_UART_BAUDRATE CONCAT_2(NRF_UART_BAUDRATE_,SER_PHY_UART_BAUDRATE_VAL) + +/** Configuration timeouts of connectivity MCU. */ +#define CONN_CHIP_RESET_TIME 50 /**< Time to keep the reset line to the connectivity chip low (in milliseconds). */ +#define CONN_CHIP_WAKEUP_TIME 500 /**< Time for the connectivity chip to reset and become ready to receive serialized commands (in milliseconds). */ + +#define SER_MAX_CONNECTIONS 8 + +#ifndef SER_MAX_ADV_DATA +#define SER_MAX_ADV_DATA 256 +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* SER_CONFIG_H__ */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/ser_dbg_sd_str.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/ser_dbg_sd_str.c new file mode 100644 index 0000000..5d4bc89 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/ser_dbg_sd_str.c @@ -0,0 +1,320 @@ +/** + * 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 "ser_dbg_sd_str.h" +#include "nrf_soc.h" +#include "nrf_log.h" +#include <string.h> +#include "sdk_common.h" + +#ifdef BLE_STACK_SUPPORT_REQD +#include "ble_ranges.h" +#endif + +#ifdef ANT_STACK_SUPPORT_REQD +#include "ant_interface.h" +#include "ant_parameters.h" +#endif + +#if NRF_MODULE_ENABLED(NRF_LOG) && defined(BLE_STACK_SUPPORT_REQD) +static const char * sd_events[] = { + "BLE_EVT_TX_COMPLETE", /*0x01*/ + "BLE_EVT_USER_MEM_REQUEST", /*0x02*/ + "BLE_EVT_USER_MEM_RELEASE", /*0x03*/ + "BLE_EVT_DATA_LENGTH_CHANGED", /*0x04*/ + "SD_EVT_UNKNOWN", /*0x05*/ + "SD_EVT_UNKNOWN", /*0x06*/ + "SD_EVT_UNKNOWN", /*0x07*/ + "SD_EVT_UNKNOWN", /*0x08*/ + "SD_EVT_UNKNOWN", /*0x09*/ + "SD_EVT_UNKNOWN", /*0x0a*/ + "SD_EVT_UNKNOWN", /*0x0b*/ + "SD_EVT_UNKNOWN", /*0x0c*/ + "SD_EVT_UNKNOWN", /*0x0d*/ + "SD_EVT_UNKNOWN", /*0x0e*/ + "SD_EVT_UNKNOWN", /*0x0f*/ + "BLE_GAP_EVT_CONNECTED", /*0x10*/ + "BLE_GAP_EVT_DISCONNECTED", /*0x11*/ + "BLE_GAP_EVT_CONN_PARAM_UPDATE", /*0x12*/ + "BLE_GAP_EVT_SEC_PARAMS_REQUEST", /*0x13*/ + "BLE_GAP_EVT_SEC_INFO_REQUEST", /*0x14*/ + "BLE_GAP_EVT_PASSKEY_DISPLAY", /*0x15*/ + "BLE_GAP_EVT_KEY_PRESxSED", /*0x16*/ + "BLE_GAP_EVT_AUTH_KEY_REQUEST", /*0x17*/ + "BLE_GAP_EVT_LESC_DHKEY_REQUEST", /*0x18*/ + "BLE_GAP_EVT_AUTH_STATUS", /*0x19*/ + "BLE_GAP_EVT_CONN_SEC_UPDATE", /*0x1a*/ + "BLE_GAP_EVT_TIMEOUT", /*0x1b*/ + "BLE_GAP_EVT_RSSI_CHANGED", /*0x1c*/ + "BLE_GAP_EVT_ADV_REPORT", /*0x1d*/ + "BLE_GAP_EVT_SEC_REQUEST", /*0x1e*/ + "BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST", /*0x1f*/ + "BLE_GAP_EVT_SCAN_REQ_REPORT", /*0x20*/ + "SD_EVT_UNKNOWN", /*0x21*/ + "SD_EVT_UNKNOWN", /*0x22*/ + "SD_EVT_UNKNOWN", /*0x23*/ + "SD_EVT_UNKNOWN", /*0x24*/ + "SD_EVT_UNKNOWN", /*0x25*/ + "SD_EVT_UNKNOWN", /*0x26*/ + "SD_EVT_UNKNOWN", /*0x27*/ + "SD_EVT_UNKNOWN", /*0x28*/ + "SD_EVT_UNKNOWN", /*0x29*/ + "SD_EVT_UNKNOWN", /*0x2a*/ + "SD_EVT_UNKNOWN", /*0x2b*/ + "SD_EVT_UNKNOWN", /*0x2c*/ + "SD_EVT_UNKNOWN", /*0x2d*/ + "SD_EVT_UNKNOWN", /*0x2e*/ + "SD_EVT_UNKNOWN", /*0x2f*/ + "BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP", /*0x30*/ + "BLE_GATTC_EVT_REL_DISC_RSP", /*0x31*/ + "BLE_GATTC_EVT_CHAR_DISC_RSP", /*0x32*/ + "BLE_GATTC_EVT_DESC_DISC_RSP", /*0x33*/ + "BLE_GATTC_EVT_ATTR_INFO_DISC_RSP", /*0x34*/ + "BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP", /*0x35*/ + "BLE_GATTC_EVT_READ_RSP", /*0x36*/ + "BLE_GATTC_EVT_CHAR_VALS_READ_RSP", /*0x37*/ + "BLE_GATTC_EVT_WRITE_RSP", /*0x38*/ + "BLE_GATTC_EVT_HVX", /*0x39*/ + "BLE_GATTC_EVT_EXCHANGE_MTU_RSP", /*0x3a*/ + "BLE_GATTC_EVT_TIMEOUT", /*0x3b*/ + "SD_EVT_UNKNOWN", /*0x3c*/ + "SD_EVT_UNKNOWN", /*0x3d*/ + "SD_EVT_UNKNOWN", /*0x3e*/ + "SD_EVT_UNKNOWN", /*0x3f*/ + "SD_EVT_UNKNOWN", /*0x40*/ + "SD_EVT_UNKNOWN", /*0x41*/ + "SD_EVT_UNKNOWN", /*0x42*/ + "SD_EVT_UNKNOWN", /*0x43*/ + "SD_EVT_UNKNOWN", /*0x44*/ + "SD_EVT_UNKNOWN", /*0x45*/ + "SD_EVT_UNKNOWN", /*0x46*/ + "SD_EVT_UNKNOWN", /*0x47*/ + "SD_EVT_UNKNOWN", /*0x48*/ + "SD_EVT_UNKNOWN", /*0x49*/ + "SD_EVT_UNKNOWN", /*0x4a*/ + "SD_EVT_UNKNOWN", /*0x4b*/ + "SD_EVT_UNKNOWN", /*0x4c*/ + "SD_EVT_UNKNOWN", /*0x4d*/ + "SD_EVT_UNKNOWN", /*0x4e*/ + "SD_EVT_UNKNOWN", /*0x4f*/ + "BLE_GATTS_EVT_WRITE", /*0x50*/ + "BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST", /*0x51*/ + "BLE_GATTS_EVT_SYS_ATTR_MISSING", /*0x52*/ + "BLE_GATTS_EVT_HVC", /*0x53*/ + "BLE_GATTS_EVT_SC_CONFIRM", /*0x54*/ + "BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST", /*0x55*/ + "BLE_GATTS_EVT_TIMEOUT", /*0x56*/ +}; + +static const char * sd_functions[] = { + /* 0x60 offset */ + "SD_BLE_ENABLE", /*0x60*/ + "SD_BLE_EVT_GET", /*0x61*/ + "SD_BLE_UUID_VS_ADD", /*0x62*/ + "SD_BLE_UUID_DECODE", /*0x63*/ + "SD_BLE_UUID_ENCODE", /*0x64*/ + "SD_BLE_VERSION_GET", /*0x65*/ + "SD_BLE_USER_MEM_REPLY", /*0x66*/ + "SD_BLE_OPT_SET", /*0x67*/ + "SD_BLE_OPT_GET", /*0x68*/ + "SD_BLE_CFG_SET", /*0x69*/ + "SD_UNKNOWN", /*0x6A*/ + "SD_UNKNOWN", /*0x6B*/ + "SD_BLE_GAP_ADDR_SET" , /*0x6C*/ + "SD_BLE_GAP_ADDR_GET" , /*0x6D*/ + "SD_BLE_GAP_WHITELIST_SET" , /*0x6E*/ + "SD_BLE_GAP_DEVICE_IDENTITIES_SET" , /*0x6F*/ + "SD_BLE_GAP_PRIVACY_SET" , /*0x70*/ + "SD_BLE_GAP_PRIVACY_GET" , /*0x71*/ + "SD_BLE_GAP_ADV_SET_CONFIGURE" , /*0x72*/ + "SD_BLE_GAP_ADV_START" , /*0x73*/ + "SD_BLE_GAP_ADV_STOP" , /*0x74*/ + "SD_BLE_GAP_CONN_PARAM_UPDATE" , /*0x75*/ + "SD_BLE_GAP_DISCONNECT" , /*0x76*/ + "SD_BLE_GAP_TX_POWER_SET" , /*0x77*/ + "SD_BLE_GAP_APPEARANCE_SET" , /*0x78*/ + "SD_BLE_GAP_APPEARANCE_GET" , /*0x79*/ + "SD_BLE_GAP_PPCP_SET" , /*0x7a*/ + "SD_BLE_GAP_PPCP_GET" , /*0x7b*/ + "SD_BLE_GAP_DEVICE_NAME_SET" , /*0x7c*/ + "SD_BLE_GAP_DEVICE_NAME_GET" , /*0x7d*/ + "SD_BLE_GAP_AUTHENTICATE" , /*0x7e*/ + "SD_BLE_GAP_SEC_PARAMS_REPLY" , /*0x7f*/ + "SD_BLE_GAP_AUTH_KEY_REPLY" , /*0x80*/ + "SD_BLE_GAP_LESC_DHKEY_REPLY" , /*0x81*/ + "SD_BLE_GAP_KEYPRESS_NOTIFY" , /*0x82*/ + "SD_BLE_GAP_LESC_OOB_DATA_GET" , /*0x83*/ + "SD_BLE_GAP_LESC_OOB_DATA_SET" , /*0x84*/ + "SD_BLE_GAP_ENCRYPT" , /*0x85*/ + "SD_BLE_GAP_SEC_INFO_REPLY" , /*0x86*/ + "SD_BLE_GAP_CONN_SEC_GET" , /*0x87*/ + "SD_BLE_GAP_RSSI_START" , /*0x88*/ + "SD_BLE_GAP_RSSI_STOP" , /*0x89*/ + "SD_BLE_GAP_SCAN_START" , /*0x8a*/ + "SD_BLE_GAP_SCAN_STOP" , /*0x8b*/ + "SD_BLE_GAP_CONNECT" , /*0x8c*/ + "SD_BLE_GAP_CONNECT_CANCEL " , /*0x8d*/ + "SD_BLE_GAP_RSSI_GET" , /*0x8e*/ + "SD_BLE_GAP_PHY_UPDATE" , /*0x8f*/ + "SD_BLE_GAP_DATA_LENGTH_UPDATE" , /*0x90*/ + "SD_BLE_GAP_QOS_CHANNEL_SURVEY_START", /*0x91*/ + "SD_BLE_GAP_QOS_CHANNEL_SURVEY_STOP" , /*0x92*/ + "SD_UNKNOWN", /*0x93*/ + "SD_UNKNOWN", /*0x94*/ + "SD_UNKNOWN", /*0x95*/ + "SD_UNKNOWN", /*0x96*/ + "SD_UNKNOWN", /*0x97*/ + "SD_UNKNOWN", /*0x98*/ + "SD_UNKNOWN", /*0x99*/ + "SD_UNKNOWN", /*0x9A*/ + "SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER", /*0x9B*/ + "SD_BLE_GATTC_RELATIONSHIPS_DISCOVER", /*0x9C*/ + "SD_BLE_GATTC_CHARACTERISTICS_DISCOVER", /*0x9D*/ + "SD_BLE_GATTC_DESCRIPTORS_DISCOVER", /*0x9E*/ + "SD_BLE_GATTC_ATTR_INFO_DISCOVER", /*0x9F*/ + "SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ", /*0xA0*/ + "SD_BLE_GATTC_READ", /*0xA1*/ + "SD_BLE_GATTC_CHAR_VALUES_READ", /*0xA2*/ + "SD_BLE_GATTC_WRITE", /*0xA3*/ + "SD_BLE_GATTC_HV_CONFIRM", /*0xA4*/ + "SD_BLE_GATTC_EXCHANGE_MTU_REQUEST", /*0xA5*/ + "SD_UNKNOWN", /*0xA6*/ + "SD_UNKNOWN", /*0xA7*/ + "SD_BLE_GATTS_SERVICE_ADD", /*0xA8*/ + "SD_BLE_GATTS_INCLUDE_ADD", /*0xA9*/ + "SD_BLE_GATTS_CHARACTERISTIC_ADD", /*0xAA*/ + "SD_BLE_GATTS_DESCRIPTOR_ADD", /*0xAB*/ + "SD_BLE_GATTS_VALUE_SET", /*0xAC*/ + "SD_BLE_GATTS_VALUE_GET", /*0xAD*/ + "SD_BLE_GATTS_HVX", /*0xAE*/ + "SD_BLE_GATTS_SERVICE_CHANGED", /*0xAF*/ + "SD_BLE_GATTS_RW_AUTHORIZE_REPLY", /*0xB0*/ + "SD_BLE_GATTS_SYS_ATTR_SET", /*0xB1*/ + "SD_BLE_GATTS_SYS_ATTR_GET", /*0xB2*/ + "SD_BLE_GATTS_INITIAL_USER_HANDLE_GET", /*0xB3*/ + "SD_BLE_GATTS_ATTR_GET", /*0xB4*/ + "SD_BLE_GATTS_EXCHANGE_MTU_REPLY", /*0xB5*/ +}; +#endif // NRF_MODULE_ENABLED(NRF_LOG) && defined(BLE_STACK_SUPPORT_REQD) + +#ifdef ANT_STACK_SUPPORT_REQD +const char * string[] = +{ + "ANT SVC", + "ANT_EVT", +}; +#endif // ANT_STACK_SUPPORT_REQD + +const char * ser_dbg_sd_call_str_get(uint8_t opcode) +{ +#if NRF_MODULE_ENABLED(NRF_LOG) + const char * p_str = "SD_CALL_UNKNOWN"; +#ifdef BLE_STACK_SUPPORT_REQD + if (opcode >= BLE_SVC_BASE && opcode <= BLE_GATTS_SVC_LAST) + { + uint32_t idx = opcode-BLE_SVC_BASE; + if (idx < ARRAY_SIZE(sd_functions) ) + { + p_str = sd_functions[idx]; + } + } +#endif // BLE_STACK_SUPPORT_REQD + +#ifdef ANT_STACK_SUPPORT_REQD + // Check if opcode is within the range of the ANT Stack API SVC numbers +#ifdef BLE_STACK_SUPPORT_REQD + else if (opcode >= STK_SVC_BASE_2) +#else + if (opcode >= STK_SVC_BASE_2) +#endif // BLE_STACK_SUPPORT_REQD + { + p_str = string[0]; + } +#endif // ANT_STACK_SUPPORT_REQD + else + { + switch (opcode) + { + case SD_ECB_BLOCK_ENCRYPT: + p_str = "SD_ECB_BLOCK_ENCRYPT"; + break; + case SD_TEMP_GET: + p_str = "SD_TEMP_GET"; + break; + default: + break; + } + } + return p_str; +#else + return NULL; +#endif +} + +const char * ser_dbg_sd_evt_str_get(uint16_t opcode) +{ +#if NRF_MODULE_ENABLED(NRF_LOG) + const char * p_str = "SD_EVT_UNKNOWN"; +#ifdef BLE_STACK_SUPPORT_REQD + if (opcode >= BLE_EVT_BASE && opcode <= BLE_GATTS_EVT_LAST) + { + uint32_t idx = opcode - BLE_EVT_BASE; + if (idx < ARRAY_SIZE(sd_events)) + { + p_str = sd_events[idx]; + } + } +#endif // BLE_STACK_SUPPORT_REQD + +#ifdef ANT_STACK_SUPPORT_REQD + // Check if opcode is within the range of the ANT Stack API SVC numbers +#ifdef BLE_STACK_SUPPORT_REQD + else if (opcode <= EVENT_BLOCKED) +#else + if (opcode <= EVENT_BLOCKED) +#endif // BLE_STACK_SUPPORT_REQD + { + p_str = string[1]; + } +#endif + return p_str; +#else + return NULL; +#endif // NRF_MODULE_ENABLED(NRF_LOG) +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/ser_dbg_sd_str.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/ser_dbg_sd_str.h new file mode 100644 index 0000000..3e386e7 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/ser_dbg_sd_str.h @@ -0,0 +1,45 @@ +/** + * 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. + * + */ +#ifndef SER_DBG_SD_STR_H +#define SER_DBG_SD_STR_H +#include <stdint.h> +const char * ser_dbg_sd_call_str_get(uint8_t opcode); +const char * ser_dbg_sd_evt_str_get(uint16_t opcode); +#endif //SER_DBG_SD_STR_H diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ant/ant_struct_serialization.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ant/ant_struct_serialization.c new file mode 100644 index 0000000..c0129b3 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ant/ant_struct_serialization.c @@ -0,0 +1,159 @@ +/** + * 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_interface.h" +#include "ant_struct_serialization.h" +#include "nrf_sdh_ant.h" +#include "ble_serialization.h" +#include "app_util.h" +#include "cond_field_serialization.h" +#include <string.h> + + +uint32_t ANT_ENABLE_enc(void const * const p_void_enable_params, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_index); + SER_ASSERT_NOT_NULL(p_void_enable_params); + + ANT_ENABLE * p_enable_params = (ANT_ENABLE *)p_void_enable_params; + uint32_t err_code = NRF_SUCCESS; + + err_code = uint8_t_enc(&p_enable_params->ucTotalNumberOfChannels, p_buf, buf_len, p_index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_enc(&p_enable_params->ucNumberOfEncryptedChannels, p_buf, buf_len, p_index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint16_t_enc(&p_enable_params->usNumberOfEvents, p_buf, buf_len, p_index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint32_t_enc(&p_enable_params->pucMemoryBlockStartLocation, p_buf, buf_len, p_index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint16_t_enc(&p_enable_params->usMemoryBlockByteSize, p_buf, buf_len, p_index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + + +uint32_t ANT_ENABLE_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_enable_params) + +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_index); + SER_ASSERT_NOT_NULL(p_void_enable_params); + + ANT_ENABLE * p_enable_params = (ANT_ENABLE *)p_void_enable_params; + uint32_t err_code = NRF_SUCCESS; + + err_code = uint8_t_dec(p_buf, buf_len, p_index, &p_enable_params->ucTotalNumberOfChannels); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, buf_len, p_index, &p_enable_params->ucNumberOfEncryptedChannels); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint16_t_dec(p_buf, buf_len, p_index, &p_enable_params->usNumberOfEvents); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint32_t_dec(p_buf, buf_len, p_index, &p_enable_params->pucMemoryBlockStartLocation); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint16_t_dec(p_buf, buf_len, p_index, &p_enable_params->usMemoryBlockByteSize); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} + +uint32_t ant_evt_t_enc(void const * const p_void_ant_evt, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_index); + SER_ASSERT_NOT_NULL(p_void_ant_evt); + + ant_evt_t * p_ant_evt = (ant_evt_t *)p_void_ant_evt; + uint32_t err_code = NRF_SUCCESS; + + memcpy(&p_buf[*p_index], p_ant_evt->message.aucMessage, MESG_BUFFER_SIZE); // Size + sizeof(size) & sizeof(msg id) + *p_index += MESG_BUFFER_SIZE; + + err_code = uint8_t_enc(&p_ant_evt->event, p_buf, buf_len, p_index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_enc(&p_ant_evt->channel, p_buf, buf_len, p_index); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return(err_code); +} + +uint32_t ant_evt_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_ant_evt) + +{ + SER_ASSERT_NOT_NULL(p_buf); + SER_ASSERT_NOT_NULL(p_index); + SER_ASSERT_NOT_NULL(p_void_ant_evt); + + ant_evt_t * p_ant_evt = (ant_evt_t *)p_void_ant_evt; + uint32_t err_code = NRF_SUCCESS; + + memcpy(p_ant_evt->message.aucMessage, &p_buf[*p_index], MESG_BUFFER_SIZE); // Size + sizeof(size) & sizeof(msg id) + *p_index += MESG_BUFFER_SIZE; + + err_code = uint8_t_dec(p_buf, buf_len, p_index, &p_ant_evt->event); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + err_code = uint8_t_dec(p_buf, buf_len, p_index, &p_ant_evt->channel); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + + return err_code; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ant/ant_struct_serialization.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ant/ant_struct_serialization.h new file mode 100644 index 0000000..8f405fa --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ant/ant_struct_serialization.h @@ -0,0 +1,110 @@ +/** + * 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_STRUCT_SERIALIZATION_ +#define _ANT_STRUCT_SERIALIZATION_ + +/**@brief Function for safe encoding of an ANT_ENABLE struct. + * + * Safe decoding of an ANT_ENABLE struct. Range checks will be done if @ref SER_ASSERTS_ENABLED is set. + * + * @param[in] p_void_enable_params An ANT_ENABLE struct to be encoded. + * @param[out] p_buf Buffer containing the struct. + * @param[in] buf_len Size of the buffer. + * @param[in,out] p_index \c in: Index to the start of the ANT_ENABLE struct in the buffer. + * \c out: Index in the buffer to the first byte after the decoded struct. + * + * @return NRF_SUCCESS Fields decoded successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ANT_ENABLE_enc( void const * const p_void_enable_params, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +/**@brief Function for safe decoding of an ANT_ENABLE struct. + * + * Safe decoding of a ANT_ENABLE struct. Range checks will be done if @ref SER_ASSERTS_ENABLED is set. + * + * @param[in] p_buf Buffer containing the struct. + * @param[in] buf_len Size of the buffer. + * @param[in,out] p_index \c in: Index to the start of the ANT_ENABLE struct in the buffer. + * \c out: Index in the buffer to the first byte after the decoded struct. + * @param[out] p_void_enable_params Decoded ANT_ENABLE struct. + */ +uint32_t ANT_ENABLE_dec( uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_enable_params); + +/**@brief Function for safe encoding of an ant_evt_t struct. + * + * Safe decoding of an ant_evt_t struct. Range checks will be done if @ref SER_ASSERTS_ENABLED is set. + * + * @param[in] p_void_ant_evt An ant_evt_t struct to be encoded. + * @param[out] p_buf Buffer containing the struct. + * @param[in] buf_len Size of the buffer. + * @param[in,out] p_index \c in: Index to the start of the ant_evt_t struct in the buffer. + * \c out: Index in the buffer to the first byte after the decoded struct. + * + * @return NRF_SUCCESS Fields decoded successfully. + * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length. + */ +uint32_t ant_evt_t_enc( void const * const p_void_ant_evt, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +/**@brief Function for safe decoding of an ant_evt_t struct. + * + * Safe decoding of a ant_evt_t struct. Range checks will be done if @ref SER_ASSERTS_ENABLED is set. + * + * @param[in] p_buf Buffer containing the struct. + * @param[in] buf_len Size of the buffer. + * @param[in,out] p_index \c in: Index to the start of the ant_evt_t struct in the buffer. + * \c out: Index in the buffer to the first byte after the decoded struct. + * @param[out] p_void_ant_evt Decoded ant_evt_t struct. + */ +uint32_t ant_evt_t_dec( uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_ant_evt); + +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_gap_struct_serialization.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_gap_struct_serialization.c new file mode 100644 index 0000000..9071ad7 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_gap_struct_serialization.c @@ -0,0 +1,1749 @@ +/** + * 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_struct_serialization.h" +#include "ble_struct_serialization.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" +#include "string.h" +#include "ble_gatts.h" + +#ifndef S112 +uint32_t ble_gap_evt_adv_report_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_evt_adv_report_t); +#if NRF_SD_BLE_API_VERSION > 5 + SER_PUSH_FIELD(&p_struct->type, ble_gap_adv_report_type_t_enc); + SER_PUSH_FIELD(&p_struct->peer_addr, ble_gap_addr_t_enc); + SER_PUSH_FIELD(&p_struct->direct_addr, ble_gap_addr_t_enc); + SER_PUSH_uint8(&p_struct->primary_phy); + SER_PUSH_uint8(&p_struct->secondary_phy); + SER_PUSH_int8(&p_struct->tx_power); + SER_PUSH_int8(&p_struct->rssi); + SER_PUSH_uint8(&p_struct->ch_index); + SER_PUSH_uint8(&p_struct->set_id); + uint16_t temp = p_struct->data_id; + SER_PUSH_uint16(&temp); + SER_PUSH_FIELD(&p_struct->data, ble_data_t_enc); + SER_PUSH_FIELD(&p_struct->aux_pointer, ble_gap_aux_pointer_t_enc); +#else + uint8_t ser_data = (p_struct->scan_rsp & 0x01) + | ((p_struct->type & 0x03) << 1); + uint8_t data_len = (p_struct->dlen & 0x1F); + SER_PUSH_FIELD(&p_struct->peer_addr, ble_gap_addr_t_enc); + SER_PUSH_FIELD(&p_struct->direct_addr, ble_gap_addr_t_enc); + SER_PUSH_int8(&p_struct->rssi); + SER_PUSH_uint8(&ser_data); + SER_PUSH_len8data(p_struct->data, data_len); +#endif + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_evt_adv_report_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_evt_adv_report_t); + +#if NRF_SD_BLE_API_VERSION > 5 + SER_PULL_FIELD(&p_struct->type, ble_gap_adv_report_type_t_dec); + SER_PULL_FIELD(&p_struct->peer_addr, ble_gap_addr_t_dec); + SER_PULL_FIELD(&p_struct->direct_addr, ble_gap_addr_t_dec); + SER_PULL_uint8(&p_struct->primary_phy); + SER_PULL_uint8(&p_struct->secondary_phy); + SER_PULL_int8(&p_struct->tx_power); + SER_PULL_int8(&p_struct->rssi); + SER_PULL_uint8(&p_struct->ch_index); + SER_PULL_uint8(&p_struct->set_id); + uint16_t temp; + SER_PULL_uint16(&temp); + p_struct->data_id = temp & 0x0FFF; + SER_PULL_FIELD(&p_struct->data, ble_data_t_dec); + SER_PULL_FIELD(&p_struct->aux_pointer, ble_gap_aux_pointer_t_dec); +#else + uint8_t ser_data; + uint8_t data_len = BLE_GAP_ADV_MAX_SIZE; + uint8_t * p_field_data = p_struct->data; + SER_PULL_FIELD(&p_struct->peer_addr, ble_gap_addr_t_dec); + SER_PULL_FIELD(&p_struct->direct_addr, ble_gap_addr_t_dec); + SER_PULL_int8(&p_struct->rssi); + SER_PULL_uint8(&ser_data); + SER_PULL_len8data(&p_field_data, &data_len); + + p_struct->scan_rsp = ser_data & 0x01; + p_struct->type = (ser_data >> 1) & 0x03; + p_struct->dlen = data_len; +#endif + SER_STRUCT_DEC_END; +} +#endif + +uint32_t ble_gap_irk_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_irk_t); + SER_PUSH_uint8array(p_struct->irk, BLE_GAP_SEC_KEY_LEN); + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_irk_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_irk_t); + SER_PULL_uint8array(p_struct->irk, BLE_GAP_SEC_KEY_LEN); + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_addr_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_addr_t); + + uint8_t ser_data = (p_struct->addr_id_peer & 0x01) + | ((p_struct->addr_type & 0x7F) << 1); + SER_PUSH_uint8(&ser_data); + SER_PUSH_uint8array(p_struct->addr, BLE_GAP_ADDR_LEN); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_addr_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_addr_t); + + uint8_t ser_data; + SER_PULL_uint8(&ser_data); + SER_PULL_uint8array(p_struct->addr, BLE_GAP_ADDR_LEN); + + p_struct->addr_id_peer = ser_data & 0x01; + p_struct->addr_type = (ser_data >> 1) & 0x7F; + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_sec_levels_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_sec_levels_t); + + uint8_t sec_levels_serialized = (p_struct->lv1 << 0) | (p_struct->lv2 << 1) + | (p_struct->lv3 << 2) | (p_struct->lv4 << 3); + SER_PUSH_uint8(&sec_levels_serialized); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_sec_levels_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_sec_levels_t); + + uint32_t sec_levels_serialized; + SER_PULL_uint8(&sec_levels_serialized); + + p_struct->lv1 = sec_levels_serialized & 0x01; + p_struct->lv2 = (sec_levels_serialized >> 1) & 0x01; + p_struct->lv3 = (sec_levels_serialized >> 2) & 0x01; + p_struct->lv4 = (sec_levels_serialized >> 3) & 0x01; + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_sec_keys_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_sec_keys_t); + + SER_PUSH_COND(p_struct->p_enc_key, ble_gap_enc_key_t_enc); + SER_PUSH_COND(p_struct->p_id_key, ble_gap_id_key_t_enc); + SER_PUSH_COND(p_struct->p_sign_key, ble_gap_sign_info_t_enc); + SER_PUSH_COND(p_struct->p_pk, ble_gap_lesc_p256_pk_t_enc); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_sec_keys_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_sec_keys_t); + + SER_PULL_COND(&(p_struct->p_enc_key), ble_gap_enc_key_t_dec); + SER_PULL_COND(&(p_struct->p_id_key), ble_gap_id_key_t_dec); + SER_PULL_COND(&(p_struct->p_sign_key), ble_gap_sign_info_t_dec); + SER_PULL_COND(&(p_struct->p_pk), ble_gap_lesc_p256_pk_t_dec); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_enc_info_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_enc_info_t); + + SER_PUSH_uint8array(p_struct->ltk, BLE_GAP_SEC_KEY_LEN); + uint8_t ser_data = (p_struct->lesc & 0x01) + | ((p_struct->auth & 0x01) << 1) + | ((p_struct->ltk_len & 0x3F) << 2); + SER_PUSH_uint8(&ser_data); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_enc_info_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_enc_info_t); + + uint8_t ser_data; + SER_PULL_uint8array(p_struct->ltk, BLE_GAP_SEC_KEY_LEN); + SER_PULL_uint8(&ser_data); + p_struct->lesc = ser_data & 0x01; + p_struct->auth = (ser_data >> 1) & 0x01; + p_struct->ltk_len = (ser_data >> 2) & 0x3F; + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_sign_info_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_sign_info_t); + SER_PUSH_uint8array(p_struct->csrk, BLE_GAP_SEC_KEY_LEN); + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_sign_info_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_sign_info_t); + SER_PULL_uint8array(p_struct->csrk, BLE_GAP_SEC_KEY_LEN); + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_evt_auth_status_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_evt_auth_status_t); + uint8_t ser_data = (p_struct->error_src) | ((p_struct->bonded) << 2); +#if NRF_SD_BLE_API_VERSION >= 5 + ser_data |= ((p_struct->lesc) << 3); +#endif + SER_PUSH_uint8(&(p_struct->auth_status)); + SER_PUSH_uint8(&ser_data); + + SER_PUSH_FIELD(&(p_struct->sm1_levels), ble_gap_sec_levels_t_enc); + SER_PUSH_FIELD(&(p_struct->sm2_levels), ble_gap_sec_levels_t_enc); + SER_PUSH_FIELD(&(p_struct->kdist_own), ble_gap_sec_kdist_t_enc); + SER_PUSH_FIELD(&(p_struct->kdist_peer), ble_gap_sec_kdist_t_enc); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_evt_auth_status_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_evt_auth_status_t); + + uint8_t ser_data; + SER_PULL_uint8(&(p_struct->auth_status)); + SER_PULL_uint8(&ser_data); + p_struct->error_src = ser_data & 0x03; + p_struct->bonded = (ser_data >> 2) & 0x01; +#if NRF_SD_BLE_API_VERSION >= 5 + p_struct->lesc = (ser_data >> 3) & 0x01; +#endif + + SER_PULL_FIELD(&(p_struct->sm1_levels), ble_gap_sec_levels_t_dec); + SER_PULL_FIELD(&(p_struct->sm2_levels), ble_gap_sec_levels_t_dec); + SER_PULL_FIELD(&(p_struct->kdist_own), ble_gap_sec_kdist_t_dec); + SER_PULL_FIELD(&(p_struct->kdist_peer), ble_gap_sec_kdist_t_dec); + + SER_STRUCT_DEC_END; +} + + +uint32_t ble_gap_conn_sec_mode_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_conn_sec_mode_t); + + uint8_t ser_data = (p_struct->sm & 0x0F) + | ((p_struct->lv & 0x0F) << 4); + SER_PUSH_uint8(&ser_data); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_conn_sec_mode_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_conn_sec_mode_t); + + uint8_t ser_data; + SER_PULL_uint8(&ser_data); + p_struct->sm = ser_data & 0x0F; + p_struct->lv = (ser_data >> 4) & 0x0F; + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_evt_conn_sec_update_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_evt_conn_sec_update_t); + SER_PUSH_FIELD(&(p_struct->conn_sec), ble_gap_conn_sec_t_enc); + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_evt_conn_sec_update_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_evt_conn_sec_update_t); + SER_PULL_FIELD(&(p_struct->conn_sec), ble_gap_conn_sec_t_dec); + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_conn_sec_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_conn_sec_t); + + SER_PUSH_FIELD(&p_struct->sec_mode, ble_gap_conn_sec_mode_t_enc); + SER_PUSH_uint8(&p_struct->encr_key_size); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_conn_sec_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_conn_sec_t); + + SER_PULL_FIELD(&p_struct->sec_mode, ble_gap_conn_sec_mode_t_dec); + SER_PULL_uint8(&p_struct->encr_key_size); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_evt_sec_info_request_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_evt_sec_info_request_t); + + uint8_t ser_data = (p_struct->enc_info & 0x01) + | ((p_struct->id_info & 0x01) << 1) + | ((p_struct->sign_info& 0x01) << 2); + SER_PUSH_FIELD(&p_struct->peer_addr, ble_gap_addr_t_enc); + SER_PUSH_FIELD(&p_struct->master_id, ble_gap_master_id_t_enc); + SER_PUSH_uint8(&ser_data); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_evt_sec_info_request_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_evt_sec_info_request_t); + + uint8_t ser_data; + SER_PULL_FIELD(&p_struct->peer_addr, ble_gap_addr_t_dec); + SER_PULL_FIELD(&p_struct->master_id, ble_gap_master_id_t_dec); + SER_PULL_uint8(&ser_data); + p_struct->enc_info = ser_data & 0x01; + p_struct->id_info = (ser_data >> 1) & 0x01; + p_struct->sign_info = (ser_data >> 2) & 0x01; + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_evt_connected_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_evt_connected_t); + + SER_PUSH_FIELD(&p_struct->peer_addr, ble_gap_addr_t_enc); + SER_PUSH_uint8(&p_struct->role); + SER_PUSH_FIELD(&p_struct->conn_params, ble_gap_conn_params_t_enc); +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 + SER_PUSH_uint8(&p_struct->adv_handle); + SER_PUSH_uint16(&p_struct->adv_data.adv_data.len); + SER_PUSH_uint16(&p_struct->adv_data.scan_rsp_data.len); +#endif + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_evt_connected_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_evt_connected_t); + + SER_PULL_FIELD(&p_struct->peer_addr, ble_gap_addr_t_dec); + SER_PULL_uint8(&p_struct->role); + SER_PULL_FIELD(&p_struct->conn_params, ble_gap_conn_params_t_dec); +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 + SER_PULL_uint8(&p_struct->adv_handle); + SER_PULL_uint16(&p_struct->adv_data.adv_data.len); + SER_PULL_uint16(&p_struct->adv_data.scan_rsp_data.len); +#endif + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_sec_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_sec_params_t); + + uint8_t ser_data = (p_struct->bond & 0x01) + | ((p_struct->mitm & 0x01) << 1) + | ((p_struct->lesc & 0x01) << 2) + | ((p_struct->keypress & 0x01) << 3) + | ((p_struct->io_caps & 0x07) << 4) + | ((p_struct->oob & 0x01) << 7); + SER_PUSH_uint8(&ser_data); + SER_PUSH_uint8(&p_struct->min_key_size); + SER_PUSH_uint8(&p_struct->max_key_size); + SER_PUSH_FIELD(&p_struct->kdist_own, ble_gap_sec_kdist_t_enc); + SER_PUSH_FIELD(&p_struct->kdist_peer, ble_gap_sec_kdist_t_enc); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_sec_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_sec_params_t); + + uint8_t ser_data; + SER_PULL_uint8(&ser_data); + SER_PULL_uint8(&p_struct->min_key_size); + SER_PULL_uint8(&p_struct->max_key_size); + SER_PULL_FIELD(&p_struct->kdist_own, ble_gap_sec_kdist_t_dec); + SER_PULL_FIELD(&p_struct->kdist_peer, ble_gap_sec_kdist_t_dec); + p_struct->bond = ser_data & 0x01; + p_struct->mitm = (ser_data >> 1) & 0x01; + p_struct->lesc = (ser_data >> 2) & 0x01; + p_struct->keypress = (ser_data >> 3) & 0x01; + p_struct->io_caps = (ser_data >> 4) & 0x07; + p_struct->oob = (ser_data >> 7) & 0x01; + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_evt_sec_params_request_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_evt_sec_params_request_t); + SER_PUSH_FIELD(&(p_struct->peer_params), ble_gap_sec_params_t_enc); + SER_STRUCT_ENC_END; +} + + uint32_t ble_gap_evt_sec_params_request_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_evt_sec_params_request_t); + SER_PULL_FIELD(&(p_struct->peer_params), ble_gap_sec_params_t_dec); + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_evt_conn_param_update_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_evt_conn_param_update_t); + SER_PUSH_FIELD(&(p_struct->conn_params), ble_gap_conn_params_t_enc); + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_evt_conn_param_update_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_evt_conn_param_update_t); + SER_PULL_FIELD(&(p_struct->conn_params), ble_gap_conn_params_t_dec); + SER_STRUCT_DEC_END; +} + +#ifndef S112 +uint32_t ble_gap_evt_conn_param_update_request_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_evt_conn_param_update_request_t); + SER_PUSH_FIELD(&(p_struct->conn_params), ble_gap_conn_params_t_enc); + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_evt_conn_param_update_request_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_evt_conn_param_update_request_t); + SER_PULL_FIELD(&(p_struct->conn_params), ble_gap_conn_params_t_dec); + SER_STRUCT_DEC_END; +} +#endif //!S112 + +uint32_t ble_gap_conn_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_conn_params_t); + + SER_PUSH_uint16(&p_struct->min_conn_interval); + SER_PUSH_uint16(&p_struct->max_conn_interval); + SER_PUSH_uint16(&p_struct->slave_latency); + SER_PUSH_uint16(&p_struct->conn_sup_timeout); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_conn_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_conn_params_t); + + SER_PULL_uint16(&p_struct->min_conn_interval); + SER_PULL_uint16(&p_struct->max_conn_interval); + SER_PULL_uint16(&p_struct->slave_latency); + SER_PULL_uint16(&p_struct->conn_sup_timeout); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_evt_disconnected_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_evt_disconnected_t); + SER_PUSH_uint8(&p_struct->reason); + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_evt_disconnected_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_evt_disconnected_t); + SER_PULL_uint8(&p_struct->reason); + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_master_id_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_master_id_t); + SER_PUSH_uint16(&p_struct->ediv); + SER_PUSH_uint8array(p_struct->rand, BLE_GAP_SEC_RAND_LEN); + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_master_id_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_master_id_t); + SER_PULL_uint16(&p_struct->ediv); + SER_PULL_uint8array(p_struct->rand, BLE_GAP_SEC_RAND_LEN); + SER_STRUCT_DEC_END; +} + +#ifndef S112 +uint32_t ble_gap_scan_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_scan_params_t); + uint8_t ser_data; +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 6 + ser_data = (p_struct->active & 0x01) + | ((p_struct->use_whitelist & 0x01) << 1) + | ((p_struct->adv_dir_report & 0x01) << 2); + SER_PUSH_uint8(&ser_data); +#else + ser_data = + ((p_struct->extended & 0x01) << 0) | + ((p_struct->report_incomplete_evts & 0x01) << 1) | + ((p_struct->active & 0x01) << 2) | + ((p_struct->filter_policy & 0x03) << 3); + SER_PUSH_uint8(&ser_data); + SER_PUSH_uint8(&p_struct->scan_phys); + SER_PUSH_buf(p_struct->channel_mask, 5); +#endif + SER_PUSH_uint16(&p_struct->interval); + SER_PUSH_uint16(&p_struct->window); + SER_PUSH_uint16(&p_struct->timeout); + + SER_STRUCT_ENC_END; +} +uint32_t ble_gap_scan_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_scan_params_t); + + uint8_t ser_data; +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 6 + SER_PULL_uint8(&ser_data); + p_struct->active = ser_data & 0x01; + p_struct->use_whitelist = (ser_data >> 1) & 0x01; + p_struct->adv_dir_report = (ser_data >> 2) & 0x01; +#else + SER_PULL_uint8(&ser_data); + p_struct->extended = ser_data & 0x01; + p_struct->report_incomplete_evts = (ser_data >> 1) & 0x01; + p_struct->active = (ser_data >> 2) & 0x01; + p_struct->filter_policy = (ser_data >> 3) & 0x03; + + SER_PULL_uint8(&p_struct->scan_phys); + uint8_t * p_channel_mask = (uint8_t *)p_struct->channel_mask; + SER_PULL_buf(&p_channel_mask, 5, 5); +#endif + SER_PULL_uint16(&p_struct->interval); + SER_PULL_uint16(&p_struct->window); + SER_PULL_uint16(&p_struct->timeout); + + SER_STRUCT_DEC_END; +} +#endif //!S112 + +uint32_t ble_gap_enc_key_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_enc_key_t); + + SER_PUSH_FIELD(&p_struct->enc_info, ble_gap_enc_info_t_enc); + SER_PUSH_FIELD(&p_struct->master_id, ble_gap_master_id_t_enc); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_enc_key_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_enc_key_t); + + SER_PULL_FIELD(&p_struct->enc_info, ble_gap_enc_info_t_dec); + SER_PULL_FIELD(&p_struct->master_id, ble_gap_master_id_t_dec); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_id_key_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_id_key_t); + + SER_PUSH_FIELD(&p_struct->id_info, ble_gap_irk_t_enc); + SER_PUSH_FIELD(&p_struct->id_addr_info, ble_gap_addr_t_enc); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_id_key_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_id_key_t); + + SER_PULL_FIELD(&p_struct->id_info, ble_gap_irk_t_dec); + SER_PULL_FIELD(&p_struct->id_addr_info, ble_gap_addr_t_dec); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_sec_keyset_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_sec_keyset_t); + + SER_PUSH_FIELD(&p_struct->keys_own, ble_gap_sec_keys_t_enc); + SER_PUSH_FIELD(&p_struct->keys_peer, ble_gap_sec_keys_t_enc); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_sec_keyset_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_sec_keyset_t); + + SER_PULL_FIELD(&p_struct->keys_own, ble_gap_sec_keys_t_dec); + SER_PULL_FIELD(&p_struct->keys_peer, ble_gap_sec_keys_t_dec); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_evt_sec_request_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_evt_sec_request_t); + + uint8_t ser_data = (p_struct->bond & 0x01) + | ((p_struct->mitm & 0x01) << 1) + | ((p_struct->lesc & 0x01) << 2) + | ((p_struct->keypress & 0x01) << 3); + SER_PUSH_uint8(&ser_data); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_evt_sec_request_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_evt_sec_request_t); + + uint8_t ser_data; + SER_PULL_uint8(&ser_data); + p_struct->bond = ser_data & 0x01; + p_struct->mitm = (ser_data >> 1) & 0x01; + p_struct->lesc = (ser_data >> 2) & 0x01; + p_struct->keypress = (ser_data >> 3) & 0x01; + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_sec_kdist_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_sec_kdist_t); + + uint8_t ser_data = (p_struct->enc & 0x01) + | (p_struct->id & 0x01) << 1 + | (p_struct->sign & 0x01) << 2 + | (p_struct->link & 0x01) << 3; + SER_PUSH_uint8(&ser_data); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_sec_kdist_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_sec_kdist_t); + + uint8_t ser_data; + SER_PULL_uint8(&ser_data); + p_struct->enc = ser_data & 0x01; + p_struct->id = (ser_data >> 1) & 0x01; + p_struct->sign = (ser_data >> 2) & 0x01; + p_struct->link = (ser_data >> 3) & 0x01; + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_opt_ch_map_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_opt_ch_map_t); + + SER_PUSH_uint16(&p_struct->conn_handle); + SER_PUSH_uint8array(p_struct->ch_map, 5); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_opt_ch_map_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_opt_ch_map_t); + + SER_PULL_uint16(&p_struct->conn_handle); + SER_PULL_uint8array(p_struct->ch_map, 5); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_opt_local_conn_latency_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_opt_local_conn_latency_t); + + SER_PUSH_uint16(&p_struct->conn_handle); + SER_PUSH_uint16(&p_struct->requested_latency); + SER_PUSH_COND(p_struct->p_actual_latency, uint16_t_enc); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_opt_local_conn_latency_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_opt_local_conn_latency_t); + + SER_PULL_uint16(&p_struct->conn_handle); + SER_PULL_uint16(&p_struct->requested_latency); + SER_PULL_COND(&p_struct->p_actual_latency, uint16_t_dec); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_opt_passkey_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_opt_passkey_t); + SER_PUSH_buf(p_struct->p_passkey, BLE_GAP_PASSKEY_LEN); + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_opt_passkey_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_opt_passkey_t); + SER_PULL_buf((uint8_t**)&p_struct->p_passkey, BLE_GAP_PASSKEY_LEN, BLE_GAP_PASSKEY_LEN); + SER_STRUCT_DEC_END; +} +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 6 +uint32_t ble_gap_opt_scan_req_report_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_opt_scan_req_report_t); + + uint8_t ser_data = p_struct->enable & 0x01; + SER_PUSH_uint8(&ser_data); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_opt_scan_req_report_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_opt_scan_req_report_t); + + uint8_t ser_data; + SER_PULL_uint8(&ser_data); + p_struct->enable = ser_data & 0x01; + + SER_STRUCT_DEC_END; +} +#endif + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t ble_gap_opt_compat_mode_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_opt_compat_mode_t); + + uint8_t ser_data = p_struct->mode_1_enable & 0x01; + SER_PUSH_uint8(&ser_data); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_opt_compat_mode_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_opt_compat_mode_t); + + uint8_t ser_data; + SER_PULL_uint8(&ser_data); + p_struct->mode_1_enable = ser_data & 0x01; + + SER_STRUCT_DEC_END; +} +#endif + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 6 +uint32_t ble_gap_adv_ch_mask_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_adv_ch_mask_t); + + uint8_t ser_data = (p_struct->ch_37_off & 0x01) + | ((p_struct->ch_38_off & 0x01) << 1) + | ((p_struct->ch_39_off & 0x01) << 2); + SER_PUSH_uint8(&ser_data); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_adv_ch_mask_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_adv_ch_mask_t); + + uint8_t ser_data; + SER_PULL_uint8(&ser_data); + p_struct->ch_37_off = ser_data & 0x01; + p_struct->ch_38_off = (ser_data >> 1) & 0x01; + p_struct->ch_39_off = (ser_data >> 2) & 0x01; + + SER_STRUCT_DEC_END; +} +#endif + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t ble_gap_enable_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_enable_params_t); + + SER_PUSH_uint8(&p_struct->periph_conn_count); + SER_PUSH_uint8(&p_struct->central_conn_count); + SER_PUSH_uint8(&p_struct->central_sec_count); + SER_PUSH_COND(p_struct->p_device_name, ble_gap_device_name_t_enc); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_enable_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_enable_params_t); + + SER_PULL_uint8(&p_struct->periph_conn_count); + SER_PULL_uint8(&p_struct->central_conn_count); + SER_PULL_uint8(&p_struct->central_sec_count); + SER_PULL_COND(&p_struct->p_device_name, ble_gap_device_name_t_dec); + + SER_STRUCT_DEC_END; +} +#endif + +uint32_t ble_gap_lesc_p256_pk_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_lesc_p256_pk_t); + SER_PUSH_uint8array(p_struct->pk, BLE_GAP_LESC_P256_PK_LEN); + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_lesc_p256_pk_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_lesc_p256_pk_t); + SER_PULL_uint8array(p_struct->pk, BLE_GAP_LESC_P256_PK_LEN); + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_lesc_dhkey_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_lesc_dhkey_t); + SER_PUSH_uint8array(p_struct->key, BLE_GAP_LESC_DHKEY_LEN); + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_lesc_dhkey_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_lesc_dhkey_t); + SER_PULL_uint8array(p_struct->key, BLE_GAP_LESC_DHKEY_LEN); + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_lesc_oob_data_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_lesc_oob_data_t); + + SER_PUSH_FIELD(&p_struct->addr, ble_gap_addr_t_enc); + SER_PUSH_uint8array(p_struct->r, BLE_GAP_SEC_KEY_LEN); + SER_PUSH_uint8array(p_struct->c, BLE_GAP_SEC_KEY_LEN); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_lesc_oob_data_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_lesc_oob_data_t); + + SER_PULL_FIELD(&p_struct->addr, ble_gap_addr_t_dec); + SER_PULL_uint8array(p_struct->r, BLE_GAP_SEC_KEY_LEN); + SER_PULL_uint8array(p_struct->c, BLE_GAP_SEC_KEY_LEN); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_adv_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_adv_params_t); +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 6 + SER_PUSH_uint8(&p_struct->type); + SER_PUSH_COND(p_struct->p_peer_addr, ble_gap_addr_t_enc); + SER_PUSH_uint8(&p_struct->fp); + SER_PUSH_uint16(&p_struct->interval); + SER_PUSH_uint16(&p_struct->timeout); + SER_PUSH_FIELD(&p_struct->channel_mask, ble_gap_adv_ch_mask_t_enc); +#else + SER_PUSH_FIELD(&p_struct->properties, ble_gap_adv_properties_t_enc); + SER_PUSH_COND(p_struct->p_peer_addr, ble_gap_addr_t_enc); + SER_PUSH_uint32(&p_struct->interval); + SER_PUSH_uint16(&p_struct->duration); + SER_PUSH_uint8(&p_struct->max_adv_evts); + SER_PUSH_buf(p_struct->channel_mask, 5); + SER_PUSH_uint8(&p_struct->filter_policy); + SER_PUSH_uint8(&p_struct->primary_phy); + SER_PUSH_uint8(&p_struct->secondary_phy); + uint8_t temp = p_struct->set_id | (p_struct->scan_req_notification << 4); + SER_PUSH_uint8(&temp); + +#endif + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_adv_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_adv_params_t); + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 6 + SER_PULL_uint8(&p_struct->type); + SER_PULL_COND(&p_struct->p_peer_addr, ble_gap_addr_t_dec); + SER_PULL_uint8(&p_struct->fp); + SER_PULL_uint16(&p_struct->interval); + SER_PULL_uint16(&p_struct->timeout); + SER_PULL_FIELD(&p_struct->channel_mask, ble_gap_adv_ch_mask_t_dec); +#else + SER_PULL_FIELD(&p_struct->properties, ble_gap_adv_properties_t_dec); + SER_PULL_COND(&p_struct->p_peer_addr, ble_gap_addr_t_dec); + SER_PULL_uint32(&p_struct->interval); + SER_PULL_uint16(&p_struct->duration); + SER_PULL_uint8(&p_struct->max_adv_evts); + uint8_t * p_channel_mask = p_struct->channel_mask; + SER_PULL_buf((uint8_t **)&p_channel_mask, 5, 5); + SER_PULL_uint8(&p_struct->filter_policy); + SER_PULL_uint8(&p_struct->primary_phy); + SER_PULL_uint8(&p_struct->secondary_phy); + + uint8_t temp; + SER_PULL_uint8(&temp); + p_struct->set_id = temp & 0x0F; + p_struct->scan_req_notification = (temp & 0x10) ? 1 : 0; + +#endif + + SER_STRUCT_DEC_END; +} +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t ble_gap_opt_ext_len_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_opt_ext_len_t); + SER_PUSH_uint8(&p_struct->rxtx_max_pdu_payload_size); + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_opt_ext_len_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_opt_ext_len_t); + SER_PULL_uint8(&p_struct->rxtx_max_pdu_payload_size); + SER_STRUCT_DEC_END; +} +#endif +uint32_t ble_gap_opt_auth_payload_timeout_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_opt_auth_payload_timeout_t); + + SER_PUSH_uint16(&p_struct->conn_handle); + SER_PUSH_uint16(&p_struct->auth_payload_timeout); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_opt_auth_payload_timeout_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_opt_auth_payload_timeout_t); + + SER_PULL_uint16(&p_struct->conn_handle); + SER_PULL_uint16(&p_struct->auth_payload_timeout); + + SER_STRUCT_DEC_END; +} + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t ble_gap_device_name_t_enc +#else +uint32_t ble_gap_cfg_device_name_t_enc +#endif + (void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) + +{ +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 + SER_STRUCT_ENC_BEGIN(ble_gap_device_name_t); +#else + SER_STRUCT_ENC_BEGIN(ble_gap_cfg_device_name_t); +#endif + /* serializer does not support attributes on stack */ + if (p_struct->vloc != BLE_GATTS_VLOC_STACK) + { + err_code = NRF_ERROR_INVALID_PARAM; + } + + SER_PUSH_FIELD(&p_struct->write_perm, ble_gap_conn_sec_mode_t_enc); + + uint8_t ser_data = p_struct->vloc & 0x03; + SER_PUSH_uint8(&ser_data); + SER_PUSH_uint16(&p_struct->current_len); + SER_PUSH_uint16(&p_struct->max_len); + SER_PUSH_buf(p_struct->p_value, p_struct->current_len); + + SER_STRUCT_ENC_END; +} + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t ble_gap_device_name_t_dec +#else +uint32_t ble_gap_cfg_device_name_t_dec +#endif + (uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 + SER_STRUCT_DEC_BEGIN(ble_gap_device_name_t); +#else + SER_STRUCT_DEC_BEGIN(ble_gap_cfg_device_name_t); +#endif + + uint16_t value_max_len = p_struct->max_len; + uint8_t ser_data; + SER_PULL_FIELD(&p_struct->write_perm, ble_gap_conn_sec_mode_t_dec); + SER_PULL_uint8(&ser_data); + p_struct->vloc = ser_data & 0x03; + SER_PULL_uint16(&p_struct->current_len); + SER_PULL_uint16(&p_struct->max_len); + SER_PULL_buf(&p_struct->p_value,value_max_len, p_struct->current_len); + + SER_STRUCT_DEC_END; +} + + + +uint32_t ble_gap_privacy_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_privacy_params_t); + + SER_PUSH_uint8(&p_struct->privacy_mode); + SER_PUSH_uint8(&p_struct->private_addr_type); + SER_PUSH_uint16(&p_struct->private_addr_cycle_s); + SER_PUSH_COND(p_struct->p_device_irk, ble_gap_irk_t_enc); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_privacy_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_privacy_params_t); + + SER_PULL_uint8(&p_struct->privacy_mode); + SER_PULL_uint8(&p_struct->private_addr_type); + SER_PULL_uint16(&p_struct->private_addr_cycle_s); + SER_PULL_COND(&p_struct->p_device_irk, ble_gap_irk_t_dec); + + SER_STRUCT_DEC_END; +} + + + + +#if NRF_SD_BLE_API_VERSION >= 4 +#ifndef S112 +uint32_t ble_gap_opt_compat_mode_1_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_opt_compat_mode_1_t); + + uint8_t enable = p_struct->enable; + SER_PUSH_uint8(&enable); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_opt_compat_mode_1_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_opt_compat_mode_1_t); + + uint8_t enable; + SER_PULL_uint8(&enable); + p_struct->enable = enable; + + SER_STRUCT_DEC_END; +} +#endif //!S112 + +uint32_t ble_gap_opt_slave_latency_disable_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_opt_slave_latency_disable_t); + + SER_PUSH_uint16(&p_struct->conn_handle); + uint8_t disable = p_struct->disable; + SER_PUSH_uint8(&disable); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_opt_slave_latency_disable_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_opt_slave_latency_disable_t); + + SER_PULL_uint16(&p_struct->conn_handle); + uint8_t disable; + SER_PULL_uint8(&disable); + p_struct->disable = disable; + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_conn_cfg_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_conn_cfg_t); + + SER_PUSH_uint8(&p_struct->conn_count); + SER_PUSH_uint16(&p_struct->event_length); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_conn_cfg_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_conn_cfg_t); + + SER_PULL_uint8(&p_struct->conn_count); + SER_PULL_uint16(&p_struct->event_length); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_cfg_role_count_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_cfg_role_count_t); + + SER_PUSH_uint8(&p_struct->periph_role_count); +#ifndef S112 + SER_PUSH_uint8(&p_struct->central_role_count); + SER_PUSH_uint8(&p_struct->central_sec_count); +#endif //!S112 +#if NRF_SD_BLE_API_VERSION > 5 + SER_PUSH_uint8(&p_struct->adv_set_count); +#ifndef S112 + uint32_t temp = p_struct->qos_channel_survey_role_available; + SER_PUSH_uint8(&temp); +#endif //!S112 +#endif + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_cfg_role_count_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_cfg_role_count_t); + + SER_PULL_uint8(&p_struct->periph_role_count); +#ifndef S112 + SER_PULL_uint8(&p_struct->central_role_count); + SER_PULL_uint8(&p_struct->central_sec_count); +#endif //!S112 +#if NRF_SD_BLE_API_VERSION > 5 + SER_PULL_uint8(&p_struct->adv_set_count); +#ifndef S112 + uint8_t temp; + SER_PULL_uint8(&temp); + p_struct->qos_channel_survey_role_available = temp; +#endif //!S112 +#endif + SER_STRUCT_DEC_END; +} + +#ifndef S112 +uint32_t ble_gap_data_length_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_data_length_params_t); + + SER_PUSH_uint16(&p_struct->max_tx_octets); + SER_PUSH_uint16(&p_struct->max_rx_octets); + SER_PUSH_uint16(&p_struct->max_tx_time_us); + SER_PUSH_uint16(&p_struct->max_rx_time_us); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_data_length_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_data_length_params_t); + + SER_PULL_uint16(&p_struct->max_tx_octets); + SER_PULL_uint16(&p_struct->max_rx_octets); + SER_PULL_uint16(&p_struct->max_tx_time_us); + SER_PULL_uint16(&p_struct->max_rx_time_us); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_data_length_limitation_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_data_length_limitation_t); + + SER_PUSH_uint16(&p_struct->tx_payload_limited_octets); + SER_PUSH_uint16(&p_struct->rx_payload_limited_octets); + SER_PUSH_uint16(&p_struct->tx_rx_time_limited_us); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_data_length_limitation_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_data_length_limitation_t); + + SER_PULL_uint16(&p_struct->tx_payload_limited_octets); + SER_PULL_uint16(&p_struct->rx_payload_limited_octets); + SER_PULL_uint16(&p_struct->tx_rx_time_limited_us); + + SER_STRUCT_DEC_END; +} +#endif //!S112 +#endif + +#if NRF_SD_BLE_API_VERSION == 4 + +uint32_t ble_gap_opt_compat_mode_2_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_opt_compat_mode_2_t); + + uint8_t enable = p_struct->enable; + SER_PUSH_uint8(&enable); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_opt_compat_mode_2_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_opt_compat_mode_2_t); + + uint8_t enable; + SER_PULL_uint8(&enable); + p_struct->enable = enable; + + SER_STRUCT_DEC_END; +} + +#endif + +#if NRF_SD_BLE_API_VERSION >= 5 +uint32_t ble_gap_phys_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_phys_t); + + SER_PUSH_uint8(&p_struct->tx_phys); + SER_PUSH_uint8(&p_struct->rx_phys); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_phys_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_phys_t); + + SER_PULL_uint8(&p_struct->tx_phys); + SER_PULL_uint8(&p_struct->rx_phys); + + SER_STRUCT_DEC_END; +} +#endif + +#if NRF_SD_BLE_API_VERSION > 5 +uint32_t ble_gap_adv_properties_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_adv_properties_t); + + SER_PUSH_uint8(&p_struct->type); + uint8_t temp = p_struct->anonymous | (p_struct->include_tx_power << 1); + SER_PUSH_uint8(&temp); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_adv_properties_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_adv_properties_t); + + SER_PULL_uint8(&p_struct->type); + uint8_t temp; + SER_PULL_uint8(&temp); + p_struct->anonymous = temp & 0x01; + p_struct->include_tx_power = (temp & 0x02) ? 1 : 0; + + SER_STRUCT_DEC_END; +} + +#ifndef S112 +uint32_t ble_gap_adv_report_type_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_adv_report_type_t); + + uint16_t temp = + (p_struct->connectable << 0) | + (p_struct->scannable << 1) | + (p_struct->directed << 2) | + (p_struct->scan_response << 3) | + (p_struct->extended_pdu << 4) | + (p_struct->status << 5) | + (p_struct->reserved << 7); + SER_PUSH_uint16(&temp); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_adv_report_type_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_adv_report_type_t); + + uint16_t temp; + SER_PULL_uint16(&temp); + p_struct->connectable = (temp >> 0) & 0x01; + p_struct->scannable = (temp >> 1) & 0x01; + p_struct->directed = (temp >> 2) & 0x01; + p_struct->scan_response = (temp >> 3) & 0x01; + p_struct->extended_pdu = (temp >> 4) & 0x01; + p_struct->status = (temp >> 5) & 0x03; + p_struct->reserved = (temp >> 7) & 0x1FF; + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_aux_pointer_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_aux_pointer_t); + + SER_PUSH_uint16(&p_struct->aux_offset); + SER_PUSH_uint8(&p_struct->aux_phy); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_aux_pointer_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_aux_pointer_t); + + SER_PULL_uint16(&p_struct->aux_offset); + SER_PULL_uint8(&p_struct->aux_phy); + + SER_STRUCT_DEC_END; +} +#endif //!S112 + +uint32_t ble_gap_adv_data_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_adv_data_t); + + SER_PUSH_FIELD(&p_struct->adv_data, ble_data_t_enc); + SER_PUSH_FIELD(&p_struct->scan_rsp_data, ble_data_t_enc); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_adv_data_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_adv_data_t); + + SER_PULL_FIELD(&p_struct->adv_data, ble_data_t_dec); + SER_PULL_FIELD(&p_struct->scan_rsp_data, ble_data_t_dec); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gap_evt_adv_set_terminated_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gap_evt_adv_set_terminated_t); + + SER_PUSH_uint8(&p_struct->reason); + SER_PUSH_uint8(&p_struct->adv_handle); + SER_PUSH_uint8(&p_struct->num_completed_adv_events); + SER_PUSH_uint16(&p_struct->adv_data.adv_data.len); + SER_PUSH_COND(&p_struct->adv_data.adv_data.p_data, NULL); + SER_PUSH_uint16(&p_struct->adv_data.scan_rsp_data.len); + SER_PUSH_COND(&p_struct->adv_data.scan_rsp_data.p_data, NULL); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gap_evt_adv_set_terminated_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gap_evt_adv_set_terminated_t); + + SER_PULL_uint8(&p_struct->reason); + SER_PULL_uint8(&p_struct->adv_handle); + SER_PULL_uint8(&p_struct->num_completed_adv_events); + SER_PULL_uint16(&p_struct->adv_data.adv_data.len); + SER_PULL_COND(&p_struct->adv_data.adv_data.p_data, NULL); + SER_PULL_uint16(&p_struct->adv_data.scan_rsp_data.len); + SER_PULL_COND(&p_struct->adv_data.scan_rsp_data.p_data, NULL); + + SER_STRUCT_DEC_END; +} +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_gap_struct_serialization.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_gap_struct_serialization.h new file mode 100644 index 0000000..918d6f5 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_gap_struct_serialization.h @@ -0,0 +1,612 @@ +/** + * 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_STRUCT_SERIALIZATION_H__ +#define BLE_GAP_STRUCT_SERIALIZATION_H__ + +#include "ble_gap.h" + +#ifdef __cplusplus +extern "C" { +#endif + +uint32_t ble_gap_evt_adv_report_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_evt_adv_report_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_irk_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_irk_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_addr_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_addr_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_sec_levels_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_sec_levels_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_sec_keys_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_sec_keys_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_enc_info_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_enc_info_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_sign_info_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_sign_info_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_evt_auth_status_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_evt_auth_status_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_conn_sec_mode_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_conn_sec_mode_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_conn_sec_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_conn_sec_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_evt_conn_sec_update_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_evt_conn_sec_update_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_evt_sec_info_request_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_evt_sec_info_request_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_evt_connected_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_evt_connected_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_sec_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_sec_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_evt_sec_params_request_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_evt_sec_params_request_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_conn_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_conn_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_evt_conn_param_update_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_evt_conn_param_update_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_evt_conn_param_update_request_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_evt_conn_param_update_request_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_evt_disconnected_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_evt_disconnected_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_scan_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_scan_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_data); + +uint32_t ble_gap_master_id_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_master_id_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_enc_key_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_enc_key_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_id_key_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_id_key_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_sec_keyset_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_sec_keyset_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_evt_sec_request_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_evt_sec_request_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_sec_kdist_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_sec_kdist_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_opt_ch_map_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_opt_ch_map_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_opt_local_conn_latency_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_opt_local_conn_latency_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_opt_passkey_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_opt_passkey_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_opt_scan_req_report_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_opt_scan_req_report_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t ble_gap_opt_compat_mode_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_opt_compat_mode_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); +#endif +uint32_t ble_gap_adv_ch_mask_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_adv_ch_mask_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_enable_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_enable_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_lesc_p256_pk_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_lesc_p256_pk_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_lesc_dhkey_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_lesc_dhkey_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_lesc_oob_data_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_lesc_oob_data_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_adv_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_adv_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t ble_gap_opt_ext_len_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_opt_ext_len_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); +#endif + +uint32_t ble_gap_opt_auth_payload_timeout_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_opt_auth_payload_timeout_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t ble_gap_device_name_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_device_name_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); +#else +uint32_t ble_gap_cfg_device_name_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_cfg_device_name_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); +#endif + +uint32_t ble_gap_privacy_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_privacy_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +#if NRF_SD_BLE_API_VERSION >= 4 +uint32_t ble_gap_opt_compat_mode_1_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_opt_compat_mode_1_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_opt_compat_mode_2_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_opt_compat_mode_2_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); +uint32_t ble_gap_opt_slave_latency_disable_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_opt_slave_latency_disable_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_conn_cfg_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_conn_cfg_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_cfg_role_count_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_cfg_role_count_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_data_length_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_data_length_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_data_length_limitation_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_data_length_limitation_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); +#endif + +#if NRF_SD_BLE_API_VERSION >= 5 +uint32_t ble_gap_phys_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_phys_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); +#endif + +#if NRF_SD_BLE_API_VERSION > 5 +uint32_t ble_gap_adv_properties_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_adv_properties_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_adv_report_type_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_adv_report_type_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_aux_pointer_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_aux_pointer_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_adv_data_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_adv_data_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gap_evt_adv_set_terminated_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gap_evt_adv_set_terminated_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); +#endif + +#ifdef __cplusplus +} +#endif + +#endif // BLE_GAP_STRUCT_SERIALIZATION_H__ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_gatt_struct_serialization.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_gatt_struct_serialization.c new file mode 100644 index 0000000..f308ea8 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_gatt_struct_serialization.c @@ -0,0 +1,158 @@ +/** + * 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_serialization.h" +#include "ble_struct_serialization.h" +#include "ble_gatt_struct_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" +#include "ble_gatt.h" +#include <string.h> + +uint32_t ble_gatt_char_props_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gatt_char_props_t); + + uint8_t ser_data = (p_struct->broadcast & 0x01) + | ((p_struct->read & 0x01) << 1) + | ((p_struct->write_wo_resp & 0x01) << 2) + | ((p_struct->write & 0x01) << 3) + | ((p_struct->notify & 0x01) << 4) + | ((p_struct->indicate & 0x01) << 5) + | ((p_struct->auth_signed_wr & 0x01) << 6); + SER_PUSH_uint8(&ser_data); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gatt_char_props_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gatt_char_props_t); + + uint8_t ser_data; + SER_PULL_uint8(&ser_data); + p_struct->broadcast = ser_data & 0x01; + p_struct->read = (ser_data >> 1) & 0x01; + p_struct->write_wo_resp = (ser_data >> 2) & 0x01; + p_struct->write = (ser_data >> 3) & 0x01; + p_struct->notify = (ser_data >> 4) & 0x01; + p_struct->indicate = (ser_data >> 5) & 0x01; + p_struct->auth_signed_wr = (ser_data >> 6) & 0x01; + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gatt_char_ext_props_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gatt_char_ext_props_t); + + uint8_t ser_data = (p_struct->reliable_wr & 0x01) + | ((p_struct->wr_aux & 0x01) << 1); + SER_PUSH_uint8(&ser_data); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gatt_char_ext_props_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gatt_char_ext_props_t); + + uint8_t ser_data; + SER_PULL_uint8(&ser_data); + p_struct->reliable_wr = ser_data & 0x01; + p_struct->wr_aux = (ser_data >> 1) & 0x01; + + SER_STRUCT_DEC_END; +} + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t ble_gatt_enable_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gatt_enable_params_t); + SER_PUSH_uint16(&p_struct->att_mtu); + SER_STRUCT_ENC_END; +} + + +uint32_t ble_gatt_enable_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gatt_enable_params_t); + SER_PULL_uint16(&p_struct->att_mtu); + SER_STRUCT_DEC_END; +} +#else +uint32_t ble_gatt_conn_cfg_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gatt_conn_cfg_t); + SER_PUSH_uint16(&p_struct->att_mtu); + SER_STRUCT_ENC_END; +} + + +uint32_t ble_gatt_conn_cfg_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gatt_conn_cfg_t); + SER_PULL_uint16(&p_struct->att_mtu); + SER_STRUCT_DEC_END; +} +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_gatt_struct_serialization.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_gatt_struct_serialization.h new file mode 100644 index 0000000..d61eaa7 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_gatt_struct_serialization.h @@ -0,0 +1,94 @@ +/** + * 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. + * + */ +#ifndef BLE_GATT_STRUCT_SERIALIZATION_H +#define BLE_GATT_STRUCT_SERIALIZATION_H + +#include "ble_gatt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +uint32_t ble_gatt_char_props_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gatt_char_props_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gatt_char_ext_props_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gatt_char_ext_props_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t ble_gatt_enable_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gatt_enable_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); +#else +uint32_t ble_gatt_conn_cfg_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gatt_conn_cfg_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); +#endif +#ifdef __cplusplus +} +#endif + +#endif /*BLE_GATT_STRUCT_SERIALIZATION_H*/ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_gattc_struct_serialization.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_gattc_struct_serialization.c new file mode 100644 index 0000000..b1b9db6 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_gattc_struct_serialization.c @@ -0,0 +1,715 @@ +/** + * 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_gatt_struct_serialization.h" +#include "ble_gattc_struct_serialization.h" +#include "ble_struct_serialization.h" +#include "ble_serialization.h" +#include "app_util.h" +#include "ble_gattc.h" +#include "cond_field_serialization.h" +#include <string.h> + +uint32_t ble_gattc_evt_char_val_by_uuid_read_rsp_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gattc_evt_char_val_by_uuid_read_rsp_t); + + SER_PUSH_uint16(&p_struct->count); + SER_PUSH_uint16(&p_struct->value_len); + + // Copy the whole packed list. + uint16_t list_length = (p_struct->value_len + sizeof(uint16_t)) * p_struct->count; + SER_PUSH_uint8array(p_struct->handle_value, list_length); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gattc_evt_char_val_by_uuid_read_rsp_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint32_t * const p_ext_len, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gattc_evt_char_val_by_uuid_read_rsp_t); + + SER_PULL_uint16(&p_struct->count); + SER_PULL_uint16(&p_struct->value_len); + + uint16_t list_length = (p_struct->value_len + sizeof(uint16_t)) * p_struct->count; + SER_ASSERT_LENGTH_LEQ(list_length, *p_ext_len); + SER_PULL_uint8array(p_struct->handle_value, list_length); + *p_ext_len = list_length; + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gattc_evt_char_vals_read_rsp_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gattc_evt_char_vals_read_rsp_t); + + SER_PUSH_uint16(&p_struct->len); + SER_PUSH_uint8array(p_struct->values, p_struct->len); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gattc_evt_char_vals_read_rsp_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint32_t * const p_ext_len, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gattc_evt_char_vals_read_rsp_t); + + SER_PULL_uint16(&p_struct->len); + + SER_ASSERT_LENGTH_LEQ(p_struct->len, *p_ext_len); + SER_PULL_uint8array(p_struct->values, p_struct->len); + *p_ext_len = p_struct->len; + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gattc_handle_range_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gattc_handle_range_t); + + SER_PUSH_uint16(&p_struct->start_handle); + SER_PUSH_uint16(&p_struct->end_handle); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gattc_handle_range_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gattc_handle_range_t); + + SER_PULL_uint16(&p_struct->start_handle); + SER_PULL_uint16(&p_struct->end_handle); + + SER_STRUCT_DEC_END; +} + + +uint32_t ble_gattc_service_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gattc_service_t); + + SER_PUSH_FIELD(&p_struct->uuid, ble_uuid_t_enc); + SER_PUSH_FIELD(&p_struct->handle_range, ble_gattc_handle_range_t_enc); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gattc_service_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gattc_service_t); + + SER_PULL_FIELD(&p_struct->uuid, ble_uuid_t_dec); + SER_PULL_FIELD(&p_struct->handle_range, ble_gattc_handle_range_t_dec); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gattc_include_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gattc_include_t); + + SER_PUSH_uint16(&p_struct->handle); + SER_PUSH_FIELD(&p_struct->included_srvc, ble_gattc_service_t_enc); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gattc_include_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gattc_include_t); + + SER_PULL_uint16(&p_struct->handle); + SER_PULL_FIELD(&p_struct->included_srvc, ble_gattc_service_t_dec); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gattc_evt_rel_disc_rsp_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gattc_evt_rel_disc_rsp_t); + + SER_PUSH_uint16(&p_struct->count); + + ble_gattc_include_t * p_include = &(p_struct->includes[0]); + uint32_t i; + + for (i = 0; i < p_struct->count; i++) + { + SER_PUSH_FIELD(p_include, ble_gattc_include_t_enc); + ++p_include; + } + + SER_STRUCT_ENC_END; +} + + + +uint32_t ble_gattc_evt_rel_disc_rsp_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint32_t * const p_ext_len, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gattc_evt_rel_disc_rsp_t); + + SER_PULL_uint16(&p_struct->count); + + uint32_t data_len = (SUB1(p_struct->count) * sizeof(ble_gattc_include_t)); + SER_ASSERT_LENGTH_LEQ(data_len, *p_ext_len); + + ble_gattc_include_t * p_include = &(p_struct->includes[0]); + uint32_t i; + + for (i = 0; i < p_struct->count; i++) + { + SER_PULL_FIELD(p_include, ble_gattc_include_t_dec); + ++p_include; + } + + *p_ext_len = data_len; + SER_STRUCT_DEC_END; +} + +uint32_t ble_gattc_write_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gattc_write_params_t); + + SER_PUSH_uint8(&p_struct->write_op); + SER_PUSH_uint8(&p_struct->flags); + SER_PUSH_uint16(&p_struct->handle); + SER_PUSH_uint16(&p_struct->offset); + SER_PUSH_len16data(p_struct->p_value, p_struct->len); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gattc_write_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gattc_write_params_t); + + SER_PULL_uint8(&p_struct->write_op); + SER_PULL_uint8(&p_struct->flags); + SER_PULL_uint16(&p_struct->handle); + SER_PULL_uint16(&p_struct->offset); + SER_PULL_len16data((uint8_t **) &p_struct->p_value, &p_struct->len); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gattc_attr_info16_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gattc_attr_info16_t); + + SER_PUSH_uint16(&p_struct->handle); + SER_PUSH_FIELD(&(p_struct->uuid), ble_uuid_t_enc); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gattc_attr_info16_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gattc_attr_info16_t); + + SER_PULL_uint16(&p_struct->handle); + SER_PULL_FIELD(&(p_struct->uuid), ble_uuid_t_dec); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gattc_attr_info128_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gattc_attr_info128_t); + + SER_PUSH_uint16(&p_struct->handle); + SER_PUSH_FIELD(&(p_struct->uuid), ble_uuid128_t_enc); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gattc_attr_info128_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gattc_attr_info128_t); + + SER_PULL_uint16(&p_struct->handle); + SER_PULL_FIELD(&(p_struct->uuid), ble_uuid128_t_dec); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gattc_evt_attr_info_disc_rsp_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gattc_evt_attr_info_disc_rsp_t); + + SER_PUSH_uint16(&p_struct->count); + SER_PUSH_uint8(&p_struct->format); + + field_encoder_handler_t fp_encoder = (p_struct->format == BLE_GATTC_ATTR_INFO_FORMAT_16BIT) ? + ble_gattc_attr_info16_t_enc : ble_gattc_attr_info128_t_enc; + + uint32_t i; + for (i = 0; i < p_struct->count; ++i) + { + void * uuid_struct; + uuid_struct = (p_struct->format == BLE_GATTC_ATTR_INFO_FORMAT_16BIT) ? + (void *)&(p_struct->info.attr_info16[i]) : (void *)&(p_struct->info.attr_info128[i]); + SER_PUSH_FIELD(uuid_struct, fp_encoder); + } + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gattc_evt_attr_info_disc_rsp_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint32_t * const p_ext_len, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gattc_evt_attr_info_disc_rsp_t); + + SER_PULL_uint16(&p_struct->count); + SER_PULL_uint8(&p_struct->format); + + uint32_t i; + uint32_t data_len; + field_decoder_handler_t fp_decoder; + if (p_struct->format == BLE_GATTC_ATTR_INFO_FORMAT_16BIT) + { + fp_decoder = ble_gattc_attr_info16_t_dec; + data_len = (SUB1(p_struct->count) * sizeof(ble_gattc_attr_info16_t)); + } + else + { + fp_decoder = ble_gattc_attr_info128_t_dec; + data_len = (SUB1(p_struct->count) * sizeof(ble_gattc_attr_info128_t)); + } + SER_ASSERT_LENGTH_LEQ(data_len, *p_ext_len); + + for (i = 0; i < p_struct->count; i++) + { + void * uuid_struct; + uuid_struct = (p_struct->format == BLE_GATTC_ATTR_INFO_FORMAT_16BIT) ? + (void *)&(p_struct->info.attr_info16[i]) : (void *)&(p_struct->info.attr_info128[i]); + SER_PULL_FIELD(uuid_struct, fp_decoder); + } + + *p_ext_len = data_len; + SER_STRUCT_DEC_END; +} + +uint32_t ble_gattc_char_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gattc_char_t); + + uint8_t ser_data; + SER_PUSH_FIELD(&p_struct->uuid, ble_uuid_t_enc); + SER_PUSH_FIELD(&p_struct->char_props, ble_gatt_char_props_t_enc); + ser_data = p_struct->char_ext_props & 0x01; + SER_PUSH_uint8(&ser_data); + SER_PUSH_uint16(&p_struct->handle_decl); + SER_PUSH_uint16(&p_struct->handle_value); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gattc_char_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gattc_char_t); + + uint8_t ser_data; + SER_PULL_FIELD(&p_struct->uuid, ble_uuid_t_dec); + SER_PULL_FIELD(&p_struct->char_props, ble_gatt_char_props_t_dec); + SER_PULL_uint8(&ser_data); + p_struct->char_ext_props = ser_data & 0x01; + SER_PULL_uint16(&p_struct->handle_decl); + SER_PULL_uint16(&p_struct->handle_value); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gattc_evt_char_disc_rsp_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gattc_evt_char_disc_rsp_t); + + SER_PUSH_uint16(&p_struct->count); + SER_PUSH_FIELD_ARRAY(p_struct->chars, ble_gattc_char_t_enc, p_struct->count); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gattc_evt_char_disc_rsp_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint32_t * const p_ext_len, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gattc_evt_char_disc_rsp_t); + + SER_PULL_uint16(&p_struct->count); + uint32_t data_len = (SUB1(p_struct->count) * sizeof(ble_gattc_char_t)); + SER_ASSERT_LENGTH_LEQ(data_len, *p_ext_len); + + SER_PULL_FIELD_ARRAY(p_struct->chars, ble_gattc_char_t_dec, p_struct->count); + + *p_ext_len = data_len; + SER_STRUCT_DEC_END; +} + +uint32_t ble_gattc_desc_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gattc_desc_t); + + SER_PUSH_uint16(&p_struct->handle); + SER_PUSH_FIELD(&p_struct->uuid, ble_uuid_t_enc); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gattc_desc_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gattc_desc_t); + + SER_PULL_uint16(&p_struct->handle); + SER_PULL_FIELD(&p_struct->uuid, ble_uuid_t_dec); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gattc_evt_desc_disc_rsp_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gattc_evt_desc_disc_rsp_t); + + SER_PUSH_uint16(&p_struct->count); + SER_PUSH_FIELD_ARRAY(p_struct->descs, ble_gattc_desc_t_enc, p_struct->count); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gattc_evt_desc_disc_rsp_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint32_t * const p_ext_len, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gattc_evt_desc_disc_rsp_t); + + SER_PULL_uint16(&p_struct->count); + uint32_t data_len = (SUB1(p_struct->count) * sizeof(ble_gattc_desc_t)); + SER_ASSERT_LENGTH_LEQ(data_len, *p_ext_len); + + SER_PULL_FIELD_ARRAY(p_struct->descs, ble_gattc_desc_t_dec, p_struct->count); + + *p_ext_len = data_len; + SER_STRUCT_DEC_END; +} + +uint32_t ble_gattc_evt_hvx_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gattc_evt_hvx_t); + + SER_PUSH_uint16(&p_struct->handle); + SER_PUSH_uint8(&p_struct->type); + SER_PUSH_uint16(&p_struct->len); + SER_PUSH_uint8array(p_struct->data, p_struct->len); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gattc_evt_hvx_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint32_t * const p_ext_len, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gattc_evt_hvx_t); + + SER_PULL_uint16(&p_struct->handle); + SER_PULL_uint8(&p_struct->type); + SER_PULL_uint16(&p_struct->len); + + uint32_t data_len = (SUB1(p_struct->len)); + SER_ASSERT_LENGTH_LEQ(data_len, *p_ext_len); + + SER_PULL_uint8array(p_struct->data, p_struct->len); + + *p_ext_len = data_len; + SER_STRUCT_DEC_END; +} + +uint32_t ble_gattc_evt_prim_srvc_disc_rsp_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gattc_evt_prim_srvc_disc_rsp_t); + + SER_PUSH_uint16(&p_struct->count); + SER_PUSH_FIELD_ARRAY(p_struct->services, ble_gattc_service_t_enc, p_struct->count); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gattc_evt_prim_srvc_disc_rsp_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint32_t * const p_ext_len, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gattc_evt_prim_srvc_disc_rsp_t); + + SER_PULL_uint16(&p_struct->count); + uint32_t data_len = (SUB1(p_struct->count) * sizeof(ble_gattc_service_t)); + SER_ASSERT_LENGTH_LEQ(data_len, *p_ext_len); + + SER_PULL_FIELD_ARRAY(p_struct->services, ble_gattc_service_t_dec, p_struct->count); + + *p_ext_len = data_len; + SER_STRUCT_DEC_END; +} + +uint32_t ble_gattc_evt_read_rsp_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gattc_evt_read_rsp_t); + + SER_PUSH_uint16(&p_struct->handle); + SER_PUSH_uint16(&p_struct->offset); + SER_PUSH_uint16(&p_struct->len); + SER_PUSH_uint8array(p_struct->data, p_struct->len); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gattc_evt_read_rsp_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint32_t * const p_ext_len, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gattc_evt_read_rsp_t); + + SER_PULL_uint16(&p_struct->handle); + SER_PULL_uint16(&p_struct->offset); + SER_PULL_uint16(&p_struct->len); + + uint32_t data_len = (SUB1(p_struct->len)); + SER_ASSERT_LENGTH_LEQ(data_len, *p_ext_len); + + SER_PULL_uint8array(p_struct->data, p_struct->len); + + *p_ext_len = data_len; + SER_STRUCT_DEC_END; +} + +uint32_t ble_gattc_evt_timeout_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gattc_evt_timeout_t); + SER_PUSH_uint8(&p_struct->src); + SER_STRUCT_ENC_END; +} + +uint32_t ble_gattc_evt_timeout_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gattc_evt_timeout_t); + SER_PULL_uint8(&p_struct->src); + SER_STRUCT_DEC_END; +} + +uint32_t ble_gattc_evt_write_rsp_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gattc_evt_write_rsp_t); + + SER_PUSH_uint16(&p_struct->handle); + SER_PUSH_uint8(&p_struct->write_op); + SER_PUSH_uint16(&p_struct->offset); + SER_PUSH_uint16(&p_struct->len); + SER_PUSH_uint8array(p_struct->data, p_struct->len); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gattc_evt_write_rsp_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint32_t * const p_ext_len, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gattc_evt_write_rsp_t); + + SER_PULL_uint16(&p_struct->handle); + SER_PULL_uint8(&p_struct->write_op); + SER_PULL_uint16(&p_struct->offset); + SER_PULL_uint16(&p_struct->len); + + uint32_t data_len = (SUB1(p_struct->len)); + SER_ASSERT_LENGTH_LEQ(data_len, *p_ext_len); + + SER_PULL_uint8array(p_struct->data, p_struct->len); + + *p_ext_len = data_len; + SER_STRUCT_DEC_END; +} + +uint32_t ble_gattc_evt_exchange_mtu_rsp_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gattc_evt_exchange_mtu_rsp_t); + SER_PUSH_uint16(&p_struct->server_rx_mtu); + SER_STRUCT_ENC_END; +} + +uint32_t ble_gattc_evt_exchange_mtu_rsp_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gattc_evt_exchange_mtu_rsp_t); + SER_PULL_uint16(&p_struct->server_rx_mtu); + SER_STRUCT_DEC_END; +} + +#if NRF_SD_BLE_API_VERSION >= 4 +uint32_t ble_gattc_conn_cfg_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gattc_conn_cfg_t); + SER_PUSH_uint8(&p_struct->write_cmd_tx_queue_size); + SER_STRUCT_ENC_END; +} + +uint32_t ble_gattc_conn_cfg_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gattc_conn_cfg_t); + SER_PULL_uint8(&p_struct->write_cmd_tx_queue_size); + SER_STRUCT_DEC_END; +} +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_gattc_struct_serialization.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_gattc_struct_serialization.h new file mode 100644 index 0000000..f17e58f --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_gattc_struct_serialization.h @@ -0,0 +1,293 @@ +/** + * 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_STRUCT_SERIALIZATION_H +#define BLE_GATTC_STRUCT_SERIALIZATION_H + +#include "ble_gattc.h" + +#ifdef __cplusplus +extern "C" { +#endif + +uint32_t ble_gattc_evt_char_val_by_uuid_read_rsp_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gattc_evt_char_val_by_uuid_read_rsp_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint32_t * const p_ext_len, + void * const p_void_struct); + +uint32_t ble_gattc_evt_char_vals_read_rsp_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gattc_evt_char_vals_read_rsp_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint32_t * const p_ext_len, + void * const p_void_struct); + +uint32_t ble_gattc_handle_range_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gattc_handle_range_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gattc_service_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gattc_service_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gattc_include_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gattc_include_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gattc_evt_rel_disc_rsp_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gattc_evt_rel_disc_rsp_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint32_t * const p_ext_len, + void * const p_void_struct); + +uint32_t ble_gattc_write_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gattc_write_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gattc_attr_info16_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gattc_attr_info16_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gattc_attr_info128_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gattc_attr_info128_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gattc_evt_attr_info_disc_rsp_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gattc_evt_attr_info_disc_rsp_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint32_t * const p_ext_len, + void * const p_void_struct); + +uint32_t ble_gatt_char_props_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gatt_char_props_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gatt_char_ext_props_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gatt_char_ext_props_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gattc_char_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gattc_char_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gattc_evt_char_disc_rsp_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gattc_evt_char_disc_rsp_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint32_t * const p_ext_len, + void * const p_void_struct); + +uint32_t ble_gattc_desc_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gattc_desc_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gattc_evt_desc_disc_rsp_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gattc_evt_desc_disc_rsp_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint32_t * const p_ext_len, + void * const p_void_struct); + +uint32_t ble_gattc_evt_hvx_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gattc_evt_hvx_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint32_t * const p_ext_len, + void * const p_void_struct); + +uint32_t ble_gattc_evt_prim_srvc_disc_rsp_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gattc_evt_prim_srvc_disc_rsp_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint32_t * const p_ext_len, + void * const p_void_struct); + +uint32_t ble_gattc_evt_read_rsp_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gattc_evt_read_rsp_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint32_t * const p_ext_len, + void * const p_void_struct); + +uint32_t ble_gattc_evt_timeout_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gattc_evt_timeout_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gattc_evt_write_rsp_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gattc_evt_write_rsp_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint32_t * const p_ext_len, + void * const p_void_struct); + +uint32_t ble_gattc_evt_exchange_mtu_rsp_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gattc_evt_exchange_mtu_rsp_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); +#if NRF_SD_BLE_API_VERSION >= 4 +uint32_t ble_gattc_conn_cfg_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gattc_conn_cfg_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); +#endif +#ifdef __cplusplus +} +#endif + +#endif /*BLE_GATTC_STRUCT_SERIALIZATION_H*/ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_gatts_struct_serialization.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_gatts_struct_serialization.c new file mode 100644 index 0000000..476a11d --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_gatts_struct_serialization.c @@ -0,0 +1,689 @@ +/** + * 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_gatt_struct_serialization.h" +#include "ble_gatts_struct_serialization.h" +#include "ble_gap_struct_serialization.h" +#include "ble_struct_serialization.h" +#include "ble_serialization.h" +#include "app_util.h" +#include "ble_gatts.h" +#include "cond_field_serialization.h" +#include <string.h> + +uint32_t ble_gatts_char_pf_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gatts_char_pf_t); + + SER_PUSH_uint8(&p_struct->format); + SER_PUSH_int8(&p_struct->exponent); + SER_PUSH_uint16(&p_struct->unit); + SER_PUSH_uint8(&p_struct->name_space); + SER_PUSH_uint16(&p_struct->desc); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gatts_char_pf_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gatts_char_pf_t); + + SER_PULL_uint8(&p_struct->format); + SER_PULL_int8(&p_struct->exponent); + SER_PULL_uint16(&p_struct->unit); + SER_PULL_uint8(&p_struct->name_space); + SER_PULL_uint16(&p_struct->desc); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gatts_attr_md_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gatts_attr_md_t); + + SER_PUSH_FIELD(&p_struct->read_perm, ble_gap_conn_sec_mode_t_enc); + SER_PUSH_FIELD(&p_struct->write_perm, ble_gap_conn_sec_mode_t_enc); + uint8_t ser_data = (p_struct->vlen & 0x01) + | ((p_struct->vloc & 0x03) << 1) + | ((p_struct->rd_auth & 0x01) << 3) + | ((p_struct->wr_auth & 0x01) << 4); + SER_PUSH_uint8(&ser_data); + + // Serializer does not support attributes on stack. + if (p_struct->vloc != BLE_GATTS_VLOC_STACK) + { + err_code = NRF_ERROR_INVALID_PARAM; + } + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gatts_attr_md_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gatts_attr_md_t); + + uint8_t ser_data; + SER_PULL_FIELD(&p_struct->read_perm, ble_gap_conn_sec_mode_t_dec); + SER_PULL_FIELD(&p_struct->write_perm, ble_gap_conn_sec_mode_t_dec); + SER_PULL_uint8(&ser_data); + + p_struct->vlen = ser_data & 0x01; + p_struct->vloc = (ser_data >> 1) & 0x03; + p_struct->rd_auth = (ser_data >> 3) & 0x01; + p_struct->wr_auth = (ser_data >> 4) & 0x01; + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gatts_char_md_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gatts_char_md_t); + + SER_PUSH_FIELD(&p_struct->char_props, ble_gatt_char_props_t_enc); + SER_PUSH_FIELD(&p_struct->char_ext_props, ble_gatt_char_ext_props_t_enc); + SER_PUSH_uint16(&p_struct->char_user_desc_max_size); + SER_ERROR_CHECK(p_struct->char_user_desc_size <= BLE_GATTS_VAR_ATTR_LEN_MAX, + NRF_ERROR_INVALID_PARAM); + SER_PUSH_len16data(p_struct->p_char_user_desc, p_struct->char_user_desc_size); + SER_PUSH_COND(p_struct->p_char_pf, ble_gatts_char_pf_t_enc); + SER_PUSH_COND(p_struct->p_user_desc_md, ble_gatts_attr_md_t_enc); + SER_PUSH_COND(p_struct->p_cccd_md, ble_gatts_attr_md_t_enc); + SER_PUSH_COND(p_struct->p_sccd_md, ble_gatts_attr_md_t_enc); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gatts_char_md_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gatts_char_md_t); + + SER_PULL_FIELD(&p_struct->char_props, ble_gatt_char_props_t_dec); + SER_PULL_FIELD(&p_struct->char_ext_props, ble_gatt_char_ext_props_t_dec); + SER_PULL_uint16(&p_struct->char_user_desc_max_size); +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 + SER_PULL_len16data(&p_struct->p_char_user_desc, &p_struct->char_user_desc_size); +#else + SER_PULL_len16data((uint8_t * * )&p_struct->p_char_user_desc, &p_struct->char_user_desc_size); +#endif + SER_PULL_COND(&p_struct->p_char_pf, ble_gatts_char_pf_t_dec); + SER_PULL_COND(&p_struct->p_user_desc_md, ble_gatts_attr_md_t_dec); + SER_PULL_COND(&p_struct->p_cccd_md, ble_gatts_attr_md_t_dec); + SER_PULL_COND(&p_struct->p_sccd_md, ble_gatts_attr_md_t_dec); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gatts_attr_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gatts_attr_t); + + SER_PUSH_COND(p_struct->p_uuid, ble_uuid_t_enc); + SER_PUSH_COND(p_struct->p_attr_md, ble_gatts_attr_md_t_enc); + SER_PUSH_uint16(&p_struct->init_offs); + SER_PUSH_uint16(&p_struct->max_len); + SER_ERROR_CHECK(p_struct->init_len <= BLE_GATTS_VAR_ATTR_LEN_MAX, NRF_ERROR_INVALID_PARAM); + SER_PUSH_len16data(p_struct->p_value, p_struct->init_len); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gatts_attr_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gatts_attr_t); + + SER_PULL_COND(&p_struct->p_uuid, ble_uuid_t_dec); + SER_PULL_COND(&p_struct->p_attr_md, ble_gatts_attr_md_t_dec); + SER_PULL_uint16(&p_struct->init_offs); + SER_PULL_uint16(&p_struct->max_len); + SER_PULL_len16data(&p_struct->p_value, &p_struct->init_len); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gatts_char_handles_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gatts_char_handles_t); + + SER_PUSH_uint16(&p_struct->value_handle); + SER_PUSH_uint16(&p_struct->user_desc_handle); + SER_PUSH_uint16(&p_struct->cccd_handle); + SER_PUSH_uint16(&p_struct->sccd_handle); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gatts_char_handles_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gatts_char_handles_t); + + SER_PULL_uint16(&p_struct->value_handle); + SER_PULL_uint16(&p_struct->user_desc_handle); + SER_PULL_uint16(&p_struct->cccd_handle); + SER_PULL_uint16(&p_struct->sccd_handle); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gatts_hvx_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gatts_hvx_params_t); + + SER_PUSH_uint16(&p_struct->handle); + SER_PUSH_uint8(&p_struct->type); + SER_PUSH_uint16(&p_struct->offset); + SER_PUSH_COND(p_struct->p_len, uint16_t_enc); + if (p_struct->p_len) + { + SER_PUSH_buf(p_struct->p_data, *p_struct->p_len); + } + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gatts_hvx_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gatts_hvx_params_t); + + SER_PULL_uint16(&p_struct->handle); + SER_PULL_uint8(&p_struct->type); + SER_PULL_uint16(&p_struct->offset); + SER_PULL_COND(&p_struct->p_len, uint16_t_dec); + if (p_struct->p_len) + { +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 + SER_PULL_buf(&p_struct->p_data, *p_struct->p_len, *p_struct->p_len); +#else + SER_PULL_buf((uint8_t**)&p_struct->p_data, *p_struct->p_len, *p_struct->p_len); +#endif + } + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gatts_evt_write_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gatts_evt_write_t); + + SER_PUSH_uint16(&p_struct->handle); + SER_PUSH_FIELD(&p_struct->uuid, ble_uuid_t_enc); + SER_PUSH_uint8(&p_struct->op); + SER_PUSH_uint8(&p_struct->auth_required); + SER_PUSH_uint16(&p_struct->offset); + SER_PUSH_uint16(&p_struct->len); + SER_PUSH_uint8array(p_struct->data, p_struct->len); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gatts_evt_write_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint32_t * const p_ext_len, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gatts_evt_write_t); + + SER_PULL_uint16(&p_struct->handle); + SER_PULL_FIELD(&p_struct->uuid, ble_uuid_t_dec); + SER_PULL_uint8(&p_struct->op); + SER_PULL_uint8(&p_struct->auth_required); + SER_PULL_uint16(&p_struct->offset); + SER_PULL_uint16(&p_struct->len); + + // Data field is defined as 1-element array, so the first element + // is always allocated in the structure. + SER_ASSERT_LENGTH_LEQ(p_struct->len, *p_ext_len + 1); + SER_PULL_uint8array(p_struct->data, p_struct->len); + *p_ext_len = (p_struct->len > 1) ? p_struct->len - 1 : 0; + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gatts_evt_read_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gatts_evt_read_t); + + SER_PUSH_uint16(&p_struct->handle); + SER_PUSH_FIELD(&p_struct->uuid, ble_uuid_t_enc); + SER_PUSH_uint16(&p_struct->offset); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gatts_evt_read_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gatts_evt_read_t); + + SER_PULL_uint16(&p_struct->handle); + SER_PULL_FIELD(&p_struct->uuid, ble_uuid_t_dec); + SER_PULL_uint16(&p_struct->offset); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gatts_evt_rw_authorize_request_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gatts_evt_rw_authorize_request_t); + + SER_PUSH_uint8(&p_struct->type); + + switch (p_struct->type) + { + case BLE_GATTS_AUTHORIZE_TYPE_READ: + SER_PUSH_FIELD(&p_struct->request.read, ble_gatts_evt_read_t_enc); + break; + + case BLE_GATTS_AUTHORIZE_TYPE_WRITE: + SER_PUSH_FIELD(&p_struct->request.write, ble_gatts_evt_write_t_enc); + break; + + default: + case BLE_GATTS_AUTHORIZE_TYPE_INVALID: + err_code = NRF_ERROR_INVALID_PARAM; + break; + } + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gatts_evt_rw_authorize_request_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint32_t * const p_ext_len, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gatts_evt_rw_authorize_request_t); + + SER_PULL_uint8(&p_struct->type); + + switch (p_struct->type) + { + case BLE_GATTS_AUTHORIZE_TYPE_READ: + SER_PULL_FIELD(&p_struct->request.read, ble_gatts_evt_read_t_dec); + break; + + case BLE_GATTS_AUTHORIZE_TYPE_WRITE: + err_code = ble_gatts_evt_write_t_dec(p_buf, + buf_len, + p_index, + p_ext_len, + &p_struct->request.write); + SER_ASSERT(err_code == NRF_SUCCESS, err_code); + break; + + default: + case BLE_GATTS_AUTHORIZE_TYPE_INVALID: + return NRF_ERROR_INVALID_DATA; + } + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gatts_authorize_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gatts_authorize_params_t); + + uint8_t ser_data = p_struct->update & 0x01; + SER_PUSH_uint16(&p_struct->gatt_status); + SER_PUSH_uint8(&ser_data); + SER_PUSH_uint16(&p_struct->offset); + SER_PUSH_len16data(p_struct->p_data, p_struct->len); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gatts_authorize_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gatts_authorize_params_t); + + uint8_t ser_data; + SER_PULL_uint16(&p_struct->gatt_status); + SER_PULL_uint8(&ser_data); + SER_PULL_uint16(&p_struct->offset); + SER_PULL_len16data((uint8_t **) &p_struct->p_data, &p_struct->len); + + p_struct->update = ser_data & 0x01; + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gatts_rw_authorize_reply_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gatts_rw_authorize_reply_params_t); + + SER_PUSH_uint8(&p_struct->type); + if (p_struct->type == BLE_GATTS_AUTHORIZE_TYPE_READ) + { + SER_PUSH_FIELD(&p_struct->params.read, ble_gatts_authorize_params_t_enc); + } + else if (p_struct->type == BLE_GATTS_AUTHORIZE_TYPE_WRITE) + { + SER_PUSH_FIELD(&p_struct->params.write, ble_gatts_authorize_params_t_enc); + } + else + { + return NRF_ERROR_INVALID_PARAM; + } + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gatts_rw_authorize_reply_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gatts_rw_authorize_reply_params_t); + + SER_PULL_uint8(&p_struct->type); + if (p_struct->type == BLE_GATTS_AUTHORIZE_TYPE_READ) + { + SER_PULL_FIELD(&p_struct->params.read, ble_gatts_authorize_params_t_dec); + } + else if (p_struct->type == BLE_GATTS_AUTHORIZE_TYPE_WRITE) + { + SER_PULL_FIELD(&p_struct->params.write, ble_gatts_authorize_params_t_dec); + } + else + { + return NRF_ERROR_INVALID_PARAM; + } + + SER_STRUCT_DEC_END; +} +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t ble_gatts_enable_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gatts_enable_params_t); + + uint8_t ser_data = p_struct->service_changed & 0x01; + SER_PUSH_uint8(&ser_data); + SER_PUSH_uint32(&p_struct->attr_tab_size); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gatts_enable_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gatts_enable_params_t); + + uint8_t ser_data; + SER_PULL_uint8(&ser_data); + SER_PULL_uint32(&p_struct->attr_tab_size); + + p_struct->service_changed = ser_data & 0x01; + + SER_STRUCT_DEC_END; +} +#endif + +uint32_t ble_gatts_value_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gatts_value_t); + + SER_PUSH_uint16(&p_struct->offset); + SER_PUSH_len16data(p_struct->p_value, p_struct->len); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_gatts_value_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gatts_value_t); + + SER_PULL_uint16(&p_struct->offset); + SER_PULL_len16data(&p_struct->p_value, &p_struct->len); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_gatts_evt_exchange_mtu_request_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gatts_evt_exchange_mtu_request_t); + SER_PUSH_uint16(&p_struct->client_rx_mtu); + SER_STRUCT_ENC_END; +} + +uint32_t ble_gatts_evt_exchange_mtu_request_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gatts_evt_exchange_mtu_request_t); + SER_PULL_uint16(&p_struct->client_rx_mtu); + SER_STRUCT_DEC_END; +} + +uint32_t ble_gatts_evt_hvc_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gatts_evt_hvc_t); + SER_PUSH_uint16(&p_struct->handle); + SER_STRUCT_ENC_END; +} + +uint32_t ble_gatts_evt_hvc_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gatts_evt_hvc_t); + SER_PULL_uint16(&p_struct->handle); + SER_STRUCT_DEC_END; +} + +uint32_t ble_gatts_evt_sys_attr_missing_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gatts_evt_sys_attr_missing_t); + SER_PUSH_uint8(&p_struct->hint); + SER_STRUCT_ENC_END; +} + +uint32_t ble_gatts_evt_sys_attr_missing_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gatts_evt_sys_attr_missing_t); + SER_PULL_uint8(&p_struct->hint); + SER_STRUCT_DEC_END; +} + +uint32_t ble_gatts_evt_timeout_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gatts_evt_timeout_t); + SER_PUSH_uint8(&p_struct->src); + SER_STRUCT_ENC_END; +} + +uint32_t ble_gatts_evt_timeout_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gatts_evt_timeout_t); + SER_PULL_uint8(&p_struct->src); + SER_STRUCT_DEC_END; +} + +#if NRF_SD_BLE_API_VERSION >= 4 +uint32_t ble_gatts_conn_cfg_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gatts_conn_cfg_t); + SER_PUSH_uint8(&p_struct->hvn_tx_queue_size); + SER_STRUCT_ENC_END; +} + +uint32_t ble_gatts_conn_cfg_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gatts_conn_cfg_t); + SER_PULL_uint8(&p_struct->hvn_tx_queue_size); + SER_STRUCT_DEC_END; +} + +uint32_t ble_gatts_cfg_service_changed_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gatts_cfg_service_changed_t); + uint8_t service_changed = p_struct->service_changed; + SER_PUSH_uint8(&service_changed); + SER_STRUCT_ENC_END; +} + +uint32_t ble_gatts_cfg_service_changed_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gatts_cfg_service_changed_t); + uint8_t service_changed; + SER_PULL_uint8(&service_changed); + p_struct->service_changed = service_changed; + SER_STRUCT_DEC_END; +} +uint32_t ble_gatts_cfg_attr_tab_size_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_gatts_cfg_attr_tab_size_t); + SER_PUSH_uint32(&p_struct->attr_tab_size); + SER_STRUCT_ENC_END; +} + +uint32_t ble_gatts_cfg_attr_tab_size_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_gatts_cfg_attr_tab_size_t); + SER_PULL_uint32(&p_struct->attr_tab_size); + SER_STRUCT_DEC_END; +} + + +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_gatts_struct_serialization.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_gatts_struct_serialization.h new file mode 100644 index 0000000..4a93913 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_gatts_struct_serialization.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 BLE_GATTS_STRUCT_SERIALIZATION_H +#define BLE_GATTS_STRUCT_SERIALIZATION_H + +#include "ble_gatts.h" + +#ifdef __cplusplus +extern "C" { +#endif + +uint32_t ble_gatts_char_pf_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gatts_char_pf_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gatts_attr_md_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gatts_attr_md_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gatts_char_md_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gatts_char_md_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gatts_attr_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gatts_attr_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gatts_char_handles_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gatts_char_handles_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gatts_evt_write_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gatts_evt_write_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint32_t * const p_ext_len, + void * const p_void_struct); + +uint32_t ble_gatts_hvx_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gatts_hvx_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gatts_evt_read_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gatts_evt_read_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gatts_evt_rw_authorize_request_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gatts_evt_rw_authorize_request_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint32_t * const p_ext_len, + void * const p_void_struct); + +uint32_t ble_gatts_authorize_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gatts_authorize_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gatts_rw_authorize_reply_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gatts_rw_authorize_reply_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t ble_gatts_enable_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gatts_enable_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); +#endif + +uint32_t ble_gatts_value_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gatts_value_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gatts_evt_exchange_mtu_request_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gatts_evt_exchange_mtu_request_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gatts_evt_hvc_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gatts_evt_hvc_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gatts_evt_sys_attr_missing_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gatts_evt_sys_attr_missing_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gatts_evt_timeout_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gatts_evt_timeout_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +#if NRF_SD_BLE_API_VERSION >= 4 +uint32_t ble_gatts_conn_cfg_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gatts_conn_cfg_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gatts_cfg_service_changed_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gatts_cfg_service_changed_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_gatts_cfg_attr_tab_size_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_gatts_cfg_attr_tab_size_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +#endif +#ifdef __cplusplus +} +#endif + +#endif /* BLE_GATTS_STRUCT_SERIALIZATION_H */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_l2cap_struct_serialization.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_l2cap_struct_serialization.c new file mode 100644 index 0000000..cc48f80 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_l2cap_struct_serialization.c @@ -0,0 +1,227 @@ +/** + * 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_struct_serialization.h" +#include "ble_struct_serialization.h" +#include "ble_serialization.h" +#include "app_util.h" +#include "cond_field_serialization.h" +#include <string.h> + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t ble_l2cap_header_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_l2cap_header_t); + + SER_PUSH_uint16(&p_struct->len); + SER_PUSH_uint16(&p_struct->cid); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_l2cap_header_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_l2cap_header_t); + + SER_PULL_uint16(&p_struct->len); + SER_PULL_uint16(&p_struct->cid); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_l2cap_evt_rx_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_l2cap_evt_rx_t); + + SER_PUSH_FIELD(&p_struct->header, ble_l2cap_header_t_enc); + SER_PUSH_uint8array(p_struct->data, p_struct->header.len); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_l2cap_evt_rx_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint32_t * const p_ext_len, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_l2cap_evt_rx_t); + + SER_PULL_FIELD(&p_struct->header, ble_l2cap_header_t_dec); + + uint32_t data_len = (SUB1(p_struct->header.len)); + SER_ASSERT_LENGTH_LEQ(data_len, *p_ext_len); + + SER_PULL_uint8array(p_struct->data, p_struct->header.len); + + *p_ext_len = data_len; + SER_STRUCT_DEC_END; +} +#endif + +#if NRF_SD_BLE_API_VERSION >= 5 +uint32_t ble_l2cap_conn_cfg_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_l2cap_conn_cfg_t); + + SER_PUSH_uint16(&p_struct->rx_mps); + SER_PUSH_uint16(&p_struct->tx_mps); + SER_PUSH_uint8(&p_struct->rx_queue_size); + SER_PUSH_uint8(&p_struct->tx_queue_size); + SER_PUSH_uint8(&p_struct->ch_count); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_l2cap_conn_cfg_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_l2cap_conn_cfg_t); + + SER_PULL_uint16(&p_struct->rx_mps); + SER_PULL_uint16(&p_struct->tx_mps); + SER_PULL_uint8(&p_struct->rx_queue_size); + SER_PULL_uint8(&p_struct->tx_queue_size); + SER_PULL_uint8(&p_struct->ch_count); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_l2cap_ch_rx_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_l2cap_ch_rx_params_t); + + SER_PUSH_uint16(&p_struct->rx_mtu); + SER_PUSH_uint16(&p_struct->rx_mps); + SER_PUSH_uint16(&p_struct->sdu_buf.len); + SER_PUSH_uint32(&p_struct->sdu_buf.p_data); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_l2cap_ch_rx_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_l2cap_ch_rx_params_t); + + SER_PULL_uint16(&p_struct->rx_mtu); + SER_PULL_uint16(&p_struct->rx_mps); + SER_PULL_uint16(&p_struct->sdu_buf.len); + SER_PULL_uint32(&p_struct->sdu_buf.p_data); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_l2cap_ch_setup_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_l2cap_ch_setup_params_t); + + SER_PUSH_FIELD(&p_struct->rx_params, ble_l2cap_ch_rx_params_t_enc); + SER_PUSH_uint16(&p_struct->le_psm); + SER_PUSH_uint16(&p_struct->status); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_l2cap_ch_setup_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_l2cap_ch_setup_params_t); + + SER_PULL_FIELD(&p_struct->rx_params, ble_l2cap_ch_rx_params_t_dec); + SER_PULL_uint16(&p_struct->le_psm); + SER_PULL_uint16(&p_struct->status); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_l2cap_ch_tx_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_l2cap_ch_tx_params_t); + + SER_PUSH_uint16(&p_struct->tx_mtu); + SER_PUSH_uint16(&p_struct->peer_mps); + SER_PUSH_uint16(&p_struct->tx_mps); + SER_PUSH_uint16(&p_struct->credits); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_l2cap_ch_tx_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_l2cap_ch_tx_params_t); + + SER_PULL_uint16(&p_struct->tx_mtu); + SER_PULL_uint16(&p_struct->peer_mps); + SER_PULL_uint16(&p_struct->tx_mps); + SER_PULL_uint16(&p_struct->credits); + + SER_STRUCT_DEC_END; +} +#endif //NRF_SD_BLE_API_VERSION >= 5 diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_l2cap_struct_serialization.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_l2cap_struct_serialization.h new file mode 100644 index 0000000..a8c7bc1 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_l2cap_struct_serialization.h @@ -0,0 +1,119 @@ +/** + * 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_STRUCT_SERIALIZATION_H +#define BLE_L2CAP_STRUCT_SERIALIZATION_H + +#ifndef S112 +#include "ble_l2cap.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t ble_l2cap_header_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_l2cap_header_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_l2cap_evt_rx_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_l2cap_evt_rx_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + uint32_t * const p_ext_len, + void * const p_void_struct); +#endif + +#if NRF_SD_BLE_API_VERSION >= 5 +uint32_t ble_l2cap_conn_cfg_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_l2cap_conn_cfg_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_l2cap_ch_rx_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_l2cap_ch_rx_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_l2cap_ch_setup_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_l2cap_ch_setup_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_l2cap_ch_tx_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_l2cap_ch_tx_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); +#endif +#endif +#ifdef __cplusplus +} +#endif + +#endif /*BLE_L2CAP_STRUCT_SERIALIZATION_H*/ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_struct_serialization.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_struct_serialization.c new file mode 100644 index 0000000..5687801 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_struct_serialization.c @@ -0,0 +1,500 @@ +/** + * 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_struct_serialization.h" +#include "ble_gap_struct_serialization.h" +#include "ble_gatt_struct_serialization.h" +#include "ble_gatts_struct_serialization.h" +#include "ble_serialization.h" +#include "app_util.h" +#include "ble_types.h" +#include "ble.h" +#include "cond_field_serialization.h" +#ifdef SER_CONNECTIVITY +#include "conn_ble_gap_sec_keys.h" +#endif +#include <string.h> + + +uint32_t ble_uuid_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_uuid_t); + + SER_PUSH_uint16(&p_struct->uuid); + SER_PUSH_uint8(&p_struct->type); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_uuid_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_uuid_t); + + SER_PULL_uint16(&p_struct->uuid); + SER_PULL_uint8(&p_struct->type); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_uuid128_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_uuid128_t); + SER_PUSH_uint8array(p_struct->uuid128, sizeof (p_struct->uuid128)); + SER_STRUCT_ENC_END; +} + +uint32_t ble_uuid128_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_uuid128_t); + SER_PULL_uint8array(p_struct->uuid128, sizeof (p_struct->uuid128)); + SER_STRUCT_DEC_END; +} + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t ble_enable_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_enable_params_t); + + SER_PUSH_FIELD(&p_struct->common_enable_params, ble_common_enable_params_t_enc); + SER_PUSH_FIELD(&p_struct->gap_enable_params, ble_gap_enable_params_t_enc); + SER_PUSH_FIELD(&p_struct->gatt_enable_params, ble_gatt_enable_params_t_enc); + SER_PUSH_FIELD(&p_struct->gatts_enable_params, ble_gatts_enable_params_t_enc); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_enable_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_enable_params_t); + + SER_PULL_FIELD(&p_struct->common_enable_params, ble_common_enable_params_t_dec); + SER_PULL_FIELD(&p_struct->gap_enable_params, ble_gap_enable_params_t_dec); + SER_PULL_FIELD(&p_struct->gatt_enable_params, ble_gatt_enable_params_t_dec); + SER_PULL_FIELD(&p_struct->gatts_enable_params, ble_gatts_enable_params_t_dec); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_conn_bw_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_conn_bw_t); + + SER_PUSH_uint8(&p_struct->conn_bw_rx); + SER_PUSH_uint8(&p_struct->conn_bw_tx); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_conn_bw_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_conn_bw_t); + + SER_PULL_uint8(&p_struct->conn_bw_rx); + SER_PULL_uint8(&p_struct->conn_bw_tx); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_common_opt_conn_bw_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_common_opt_conn_bw_t); + + SER_PUSH_uint8(&p_struct->role); + SER_PUSH_FIELD(&p_struct->conn_bw, ble_conn_bw_t_enc); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_common_opt_conn_bw_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_common_opt_conn_bw_t); + + SER_PULL_uint8(&p_struct->role); + SER_PULL_FIELD(&p_struct->conn_bw, ble_conn_bw_t_dec); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_conn_bw_count_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_conn_bw_count_t); + + SER_PUSH_uint8(&p_struct->high_count); + SER_PUSH_uint8(&p_struct->mid_count); + SER_PUSH_uint8(&p_struct->low_count); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_conn_bw_count_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_conn_bw_count_t); + + SER_PULL_uint8(&p_struct->high_count); + SER_PULL_uint8(&p_struct->mid_count); + SER_PULL_uint8(&p_struct->low_count); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_conn_bw_counts_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_conn_bw_counts_t); + + SER_PUSH_FIELD(&p_struct->tx_counts, ble_conn_bw_count_t_enc); + SER_PUSH_FIELD(&p_struct->rx_counts, ble_conn_bw_count_t_enc); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_conn_bw_counts_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_conn_bw_counts_t); + + SER_PULL_FIELD(&p_struct->tx_counts, ble_conn_bw_count_t_dec); + SER_PULL_FIELD(&p_struct->rx_counts, ble_conn_bw_count_t_dec); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_common_enable_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_common_enable_params_t); + + SER_PUSH_uint16(&p_struct->vs_uuid_count); + SER_PUSH_COND(p_struct->p_conn_bw_counts, ble_conn_bw_counts_t_enc); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_common_enable_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_common_enable_params_t); + + SER_PULL_uint16(&p_struct->vs_uuid_count); + SER_PULL_COND(&p_struct->p_conn_bw_counts, ble_conn_bw_counts_t_dec); + + SER_STRUCT_DEC_END; +} +#endif +uint32_t ble_common_opt_pa_lna_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_common_opt_pa_lna_t); + + SER_PUSH_FIELD(&p_struct->pa_cfg, ble_pa_lna_cfg_t_enc); + SER_PUSH_FIELD(&p_struct->lna_cfg, ble_pa_lna_cfg_t_enc); + SER_PUSH_uint8(&p_struct->ppi_ch_id_set); + SER_PUSH_uint8(&p_struct->ppi_ch_id_clr); + SER_PUSH_uint8(&p_struct->gpiote_ch_id); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_common_opt_pa_lna_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_common_opt_pa_lna_t); + + SER_PULL_FIELD(&p_struct->pa_cfg, ble_pa_lna_cfg_t_dec); + SER_PULL_FIELD(&p_struct->lna_cfg, ble_pa_lna_cfg_t_dec); + SER_PULL_uint8(&p_struct->ppi_ch_id_set); + SER_PULL_uint8(&p_struct->ppi_ch_id_clr); + SER_PULL_uint8(&p_struct->gpiote_ch_id); + + SER_STRUCT_DEC_END; +} + + +uint32_t ble_pa_lna_cfg_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_pa_lna_cfg_t); + + uint8_t ser_data = (p_struct->enable & 0x01) + | ((p_struct->active_high & 0x01) << 1) + | ((p_struct->gpio_pin & 0x3F) << 2); + SER_PUSH_uint8(&ser_data); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_pa_lna_cfg_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_pa_lna_cfg_t); + + uint8_t ser_data; + SER_PULL_uint8(&ser_data); + p_struct->enable = ser_data & 0x01; + p_struct->active_high = (ser_data >> 1) & 0x01; + p_struct->gpio_pin = (ser_data >> 2) & 0x3F; + + SER_STRUCT_DEC_END; +} + + +uint32_t ble_user_mem_block_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_user_mem_block_t); + + SER_PUSH_uint16(&p_struct->len); + SER_PUSH_COND(p_struct->p_mem, NULL); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_user_mem_block_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_user_mem_block_t); + + SER_PULL_uint16(&p_struct->len); + SER_PULL_COND(&p_struct->p_mem, NULL); + + SER_STRUCT_DEC_END; +} + +uint32_t ble_version_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_version_t); + + SER_PUSH_uint8(&p_struct->version_number); + SER_PUSH_uint16(&p_struct->company_id); + SER_PUSH_uint16(&p_struct->subversion_number); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_version_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_version_t); + + SER_PULL_uint8(&p_struct->version_number); + SER_PULL_uint16(&p_struct->company_id); + SER_PULL_uint16(&p_struct->subversion_number); + + SER_STRUCT_DEC_END; +} +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4 +uint32_t ble_evt_data_length_changed_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_evt_data_length_changed_t); + + SER_PUSH_uint16(&p_struct->max_tx_octets); + SER_PUSH_uint16(&p_struct->max_tx_time); + SER_PUSH_uint16(&p_struct->max_rx_octets); + SER_PUSH_uint16(&p_struct->max_rx_time); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_evt_data_length_changed_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_evt_data_length_changed_t); + + SER_PULL_uint16(&p_struct->max_tx_octets); + SER_PULL_uint16(&p_struct->max_tx_time); + SER_PULL_uint16(&p_struct->max_rx_octets); + SER_PULL_uint16(&p_struct->max_rx_time); + + SER_STRUCT_DEC_END; +} +#endif +uint32_t ble_common_opt_conn_evt_ext_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_common_opt_conn_evt_ext_t); + + uint8_t ser_data = p_struct->enable & 0x01; + SER_PUSH_uint8(&ser_data); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_common_opt_conn_evt_ext_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_common_opt_conn_evt_ext_t); + + uint8_t ser_data; + SER_PULL_uint8(&ser_data); + p_struct->enable = ser_data & 0x01; + + SER_STRUCT_DEC_END; +} +#if NRF_SD_BLE_API_VERSION >= 4 +uint32_t ble_common_cfg_vs_uuid_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_common_cfg_vs_uuid_t); + + SER_PUSH_uint8(&p_struct->vs_uuid_count); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_common_cfg_vs_uuid_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_common_cfg_vs_uuid_t); + + SER_PULL_uint8(&p_struct->vs_uuid_count); + + SER_STRUCT_DEC_END; +} + +#endif + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 4 +uint32_t ble_data_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(ble_data_t); + + uint32_t buf_id = (uint32_t)p_struct->p_data; + SER_PUSH_uint32(&buf_id); + SER_PUSH_len16data(p_struct->p_data, p_struct->len); + + SER_STRUCT_ENC_END; +} + +uint32_t ble_data_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(ble_data_t); + + uint32_t buf_id; + SER_PULL_uint32(&buf_id); +#if defined(SER_CONNECTIVITY) && NRF_SD_BLE_API_VERSION > 5 + if (buf_id && (p_struct->p_data == NULL)) + { + p_struct->p_data = conn_ble_gap_ble_data_buf_alloc(buf_id); + } +#endif + SER_PULL_len16data(&p_struct->p_data, &p_struct->len); + + SER_STRUCT_DEC_END; +} +#endif diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_struct_serialization.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_struct_serialization.h new file mode 100644 index 0000000..66c05a9 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/ble_struct_serialization.h @@ -0,0 +1,217 @@ +/** + * 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_STRUCT_SERIALIZATION_H__ +#define BLE_STRUCT_SERIALIZATION_H__ + +#include "ble_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +uint32_t ble_uuid_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_uuid_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_uuid128_t_enc(const void * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_uuid128_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_enable_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_enable_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_conn_bw_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_conn_bw_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_common_opt_conn_bw_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_common_opt_conn_bw_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_conn_bw_count_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_conn_bw_count_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_conn_bw_counts_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_conn_bw_counts_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_common_enable_params_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_common_enable_params_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_common_opt_pa_lna_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_common_opt_pa_lna_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_pa_lna_cfg_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_pa_lna_cfg_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_user_mem_block_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_user_mem_block_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_version_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_version_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_evt_data_length_changed_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_evt_data_length_changed_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t ble_common_opt_conn_evt_ext_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_common_opt_conn_evt_ext_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); +#if NRF_SD_BLE_API_VERSION >= 4 +uint32_t ble_common_cfg_vs_uuid_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_common_cfg_vs_uuid_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +#endif + +#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 4 +uint32_t ble_data_t_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t ble_data_t_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); +#endif +#ifdef __cplusplus +} +#endif + +#endif // BLE_STRUCT_SERIALIZATION_H__ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/nrf_soc_struct_serialization.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/nrf_soc_struct_serialization.c new file mode 100644 index 0000000..47a0aac --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/nrf_soc_struct_serialization.c @@ -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. + * + */ +#include "nrf_soc_struct_serialization.h" +#include "ble_serialization.h" +#include "cond_field_serialization.h" +#include "app_util.h" +#include "string.h" + +uint32_t nrf_ecb_hal_data_t_in_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(nrf_ecb_hal_data_t); + + SER_PUSH_uint8array(p_struct->key, SOC_ECB_KEY_LENGTH); + SER_PUSH_uint8array(p_struct->cleartext, SOC_ECB_CLEARTEXT_LENGTH); + + SER_STRUCT_DEC_END; +} + +uint32_t nrf_ecb_hal_data_t_in_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(nrf_ecb_hal_data_t); + + SER_PULL_uint8array(p_struct->key, SOC_ECB_KEY_LENGTH); + SER_PULL_uint8array(p_struct->cleartext, SOC_ECB_CLEARTEXT_LENGTH); + + SER_STRUCT_DEC_END; +} + +uint32_t nrf_ecb_hal_data_t_out_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index) +{ + SER_STRUCT_ENC_BEGIN(nrf_ecb_hal_data_t); + SER_PUSH_uint8array(p_struct->ciphertext, SOC_ECB_CIPHERTEXT_LENGTH); + SER_STRUCT_DEC_END; +} + +uint32_t nrf_ecb_hal_data_t_out_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct) +{ + SER_STRUCT_DEC_BEGIN(nrf_ecb_hal_data_t); + SER_PULL_uint8array(p_struct->ciphertext, SOC_ECB_CIPHERTEXT_LENGTH); + SER_STRUCT_DEC_END; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/nrf_soc_struct_serialization.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/nrf_soc_struct_serialization.h new file mode 100644 index 0000000..b6923e9 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/struct_ser/ble/nrf_soc_struct_serialization.h @@ -0,0 +1,73 @@ +/** + * 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_STRUCT_SERIALIZATION_H__ +#define NRF_SOC_STRUCT_SERIALIZATION_H__ + +#include "nrf_soc.h" + +#ifdef __cplusplus +extern "C" { +#endif + +uint32_t nrf_ecb_hal_data_t_in_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t nrf_ecb_hal_data_t_in_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +uint32_t nrf_ecb_hal_data_t_out_enc(void const * const p_void_struct, + uint8_t * const p_buf, + uint32_t buf_len, + uint32_t * const p_index); + +uint32_t nrf_ecb_hal_data_t_out_dec(uint8_t const * const p_buf, + uint32_t buf_len, + uint32_t * const p_index, + void * const p_void_struct); + +#ifdef __cplusplus +} +#endif + +#endif // NRF_SOC_STRUCT_SERIALIZATION_H__ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/dtm_uart_params.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/dtm_uart_params.h new file mode 100644 index 0000000..1c79923 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/dtm_uart_params.h @@ -0,0 +1,93 @@ +/** + * 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_PARAMS_H__ +#define DTM_UART_PARAMS_H__ + +#include <stdbool.h> +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** @ingroup ble_dtm_app + */ + + +/**@brief Enumeration of supported baud rates. */ +typedef enum +{ + UART_BAUD_RATE_1200, /**< Baud rate 1200. */ + UART_BAUD_RATE_2400, /**< Baud rate 2400. */ + UART_BAUD_RATE_4800, /**< Baud rate 4800. */ + UART_BAUD_RATE_9600, /**< Baud rate 9600. */ + UART_BAUD_RATE_14400, /**< Baud rate 14400. */ + UART_BAUD_RATE_19200, /**< Baud rate 19200. */ + UART_BAUD_RATE_28800, /**< Baud rate 28800. */ + UART_BAUD_RATE_38400, /**< Baud rate 38400. */ + UART_BAUD_RATE_57600, /**< Baud rate 57600. */ + UART_BAUD_RATE_76800, /**< Baud rate 76800. */ + UART_BAUD_RATE_115200, /**< Baud rate 115200. */ + UART_BAUD_RATE_230400, /**< Baud rate 230400. */ + UART_BAUD_RATE_250000, /**< Baud rate 250000. */ + UART_BAUD_RATE_460800, /**< Baud rate 460800. */ + UART_BAUD_RATE_921600, /**< Baud rate 921600. */ + UART_BAUD_RATE_1000000, /**< Baud rate 1000000. */ + UART_BAUD_RATE_MAX /**< Enumeration upper bound. */ +} app_uart_stream_baud_rate_t; + +/**@brief UART communication structure holding configuration settings for the peripheral. + */ +typedef struct +{ + uint8_t rx_pin_no; /**< RX pin number. */ + uint8_t tx_pin_no; /**< TX pin number. */ + uint8_t rts_pin_no; /**< RTS pin number, only used if flow control is enabled. */ + uint8_t cts_pin_no; /**< CTS pin number, only used if flow control is enabled. */ + bool use_parity; /**< Even parity if TRUE, no parity if FALSE. */ + app_uart_stream_baud_rate_t baud_rate; /**< Baud rate configuration. */ +} app_uart_stream_comm_params_t; + + +#ifdef __cplusplus +} +#endif + +#endif // DTM_UART_PARAMS_H__ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_hal_transport.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_hal_transport.c new file mode 100644 index 0000000..0a8bc16 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_hal_transport.c @@ -0,0 +1,503 @@ +/** + * 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 <stdbool.h> +#include <string.h> +#include "app_error.h" +#include "sdk_config.h" +#include "ser_config.h" +#include "ser_phy.h" +#include "ser_hal_transport.h" + +#define NRF_LOG_MODULE_NAME ser_hal_transport +#if SER_HAL_TRANSPORT_CONFIG_LOG_ENABLED + #define NRF_LOG_LEVEL SER_HAL_TRANSPORT_CONFIG_LOG_LEVEL + #define NRF_LOG_INFO_COLOR SER_HAL_TRANSPORT_CONFIG_INFO_COLOR + #define NRF_LOG_DEBUG_COLOR SER_HAL_TRANSPORT_CONFIG_DEBUG_COLOR +#else //SER_HAL_TRANSPORT_CONFIG_LOG_ENABLED + #define NRF_LOG_LEVEL 0 +#endif //SER_HAL_TRANSPORT_CONFIG_LOG_ENABLED +#include "nrf_log.h" +NRF_LOG_MODULE_REGISTER(); + +/** + * @brief States of the RX state machine. + */ +typedef enum +{ + HAL_TRANSP_RX_STATE_CLOSED = 0, + HAL_TRANSP_RX_STATE_IDLE, + HAL_TRANSP_RX_STATE_RECEIVING, + HAL_TRANSP_RX_STATE_DROPPING, + HAL_TRANSP_RX_STATE_RECEIVED, + HAL_TRANSP_RX_STATE_RECEIVED_PENDING_BUF_REQ, + HAL_TRANSP_RX_STATE_RECEIVED_DROPPING, + HAL_TRANSP_RX_STATE_MAX +}ser_hal_transp_rx_states_t; + +/** + * @brief States of the TX state machine. + */ +typedef enum +{ + HAL_TRANSP_TX_STATE_CLOSED = 0, + HAL_TRANSP_TX_STATE_IDLE, + HAL_TRANSP_TX_STATE_TX_ALLOCATED, + HAL_TRANSP_TX_STATE_TRANSMITTING, + HAL_TRANSP_TX_STATE_TRANSMITTED, + HAL_TRANSP_TX_STATE_MAX +}ser_hal_transp_tx_states_t; + +/** + * @brief RX state. + */ +static ser_hal_transp_rx_states_t m_rx_state = HAL_TRANSP_RX_STATE_CLOSED; +/** + * @brief TX state. + */ +static ser_hal_transp_tx_states_t m_tx_state = HAL_TRANSP_TX_STATE_CLOSED; + +/** + * @brief Transmission buffer. + */ +static uint8_t m_tx_buffer[SER_HAL_TRANSPORT_TX_MAX_PKT_SIZE]; +/** + * @brief Reception buffer. + */ +static uint8_t m_rx_buffer[SER_HAL_TRANSPORT_RX_MAX_PKT_SIZE]; + +/** + * @brief Callback function handler for Serialization HAL Transport layer events. + */ +static ser_hal_transport_events_handler_t m_events_handler = NULL; + + +/** + * @brief A callback function to be used to handle a PHY module events. This function is called in + * an interrupt context. + */ +static void phy_events_handler(ser_phy_evt_t phy_event) +{ + uint32_t err_code = 0; + ser_hal_transport_evt_t hal_transp_event; + + memset(&hal_transp_event, 0, sizeof (ser_hal_transport_evt_t)); + hal_transp_event.evt_type = SER_HAL_TRANSP_EVT_TYPE_MAX; + + NRF_LOG_INFO("phy evt:%d", phy_event.evt_type); + switch (phy_event.evt_type) + { + case SER_PHY_EVT_TX_PKT_SENT: + { + if (HAL_TRANSP_TX_STATE_TRANSMITTING == m_tx_state) + { + m_tx_state = HAL_TRANSP_TX_STATE_TRANSMITTED; + NRF_LOG_INFO("tx free"); + err_code = ser_hal_transport_tx_pkt_free(m_tx_buffer); + APP_ERROR_CHECK(err_code); + /* An event to an upper layer that a packet has been transmitted. */ + hal_transp_event.evt_type = SER_HAL_TRANSP_EVT_TX_PKT_SENT; + m_events_handler(hal_transp_event); + } + else + { + /* Lower layer should not generate this event in current state. */ + APP_ERROR_CHECK_BOOL(false); + } + break; + } + + case SER_PHY_EVT_RX_BUF_REQUEST: + { + /* An event to an upper layer that a packet is being scheduled to receive or to drop. */ + hal_transp_event.evt_type = SER_HAL_TRANSP_EVT_RX_PKT_RECEIVING; + + /* Receive or drop a packet. */ + if (phy_event.evt_params.rx_buf_request.num_of_bytes <= sizeof (m_rx_buffer)) + { + if (HAL_TRANSP_RX_STATE_IDLE == m_rx_state) + { + m_events_handler(hal_transp_event); + err_code = ser_phy_rx_buf_set(m_rx_buffer); + APP_ERROR_CHECK(err_code); + m_rx_state = HAL_TRANSP_RX_STATE_RECEIVING; + } + else if (HAL_TRANSP_RX_STATE_RECEIVED == m_rx_state) + { + /* It is OK to get know higher layer at this point that we are going to receive + * a new packet even though we will start receiving when rx buffer is freed. */ + m_events_handler(hal_transp_event); + m_rx_state = HAL_TRANSP_RX_STATE_RECEIVED_PENDING_BUF_REQ; + } + else + { + /* Lower layer should not generate this event in current state. */ + APP_ERROR_CHECK_BOOL(false); + } + } + else + { + /* There is not enough memory but packet has to be received to dummy location. */ + if (HAL_TRANSP_RX_STATE_IDLE == m_rx_state) + { + m_events_handler(hal_transp_event); + err_code = ser_phy_rx_buf_set(NULL); + APP_ERROR_CHECK(err_code); + m_rx_state = HAL_TRANSP_RX_STATE_DROPPING; + } + else if (HAL_TRANSP_RX_STATE_RECEIVED == m_rx_state) + { + m_events_handler(hal_transp_event); + err_code = ser_phy_rx_buf_set(NULL); + APP_ERROR_CHECK(err_code); + m_rx_state = HAL_TRANSP_RX_STATE_RECEIVED_DROPPING; + } + else + { + /* Lower layer should not generate this event in current state. */ + APP_ERROR_CHECK_BOOL(false); + } + } + break; + } + + case SER_PHY_EVT_RX_PKT_RECEIVED: + { + if (HAL_TRANSP_RX_STATE_RECEIVING == m_rx_state) + { + m_rx_state = HAL_TRANSP_RX_STATE_RECEIVED; + /* Generate the event to an upper layer. */ + hal_transp_event.evt_type = + SER_HAL_TRANSP_EVT_RX_PKT_RECEIVED; + hal_transp_event.evt_params.rx_pkt_received.p_buffer = + phy_event.evt_params.rx_pkt_received.p_buffer; + hal_transp_event.evt_params.rx_pkt_received.num_of_bytes = + phy_event.evt_params.rx_pkt_received.num_of_bytes; + m_events_handler(hal_transp_event); + } + else + { + /* Lower layer should not generate this event in current state. */ + APP_ERROR_CHECK_BOOL(false); + } + break; + } + + case SER_PHY_EVT_RX_PKT_DROPPED: + { + if (HAL_TRANSP_RX_STATE_DROPPING == m_rx_state) + { + /* Generate the event to an upper layer. */ + hal_transp_event.evt_type = SER_HAL_TRANSP_EVT_RX_PKT_DROPPED; + m_events_handler(hal_transp_event); + m_rx_state = HAL_TRANSP_RX_STATE_IDLE; + } + else if (HAL_TRANSP_RX_STATE_RECEIVED_DROPPING == m_rx_state) + { + /* Generate the event to an upper layer. */ + hal_transp_event.evt_type = SER_HAL_TRANSP_EVT_RX_PKT_DROPPED; + m_events_handler(hal_transp_event); + m_rx_state = HAL_TRANSP_RX_STATE_RECEIVED; + } + else + { + /* Lower layer should not generate this event in current state. */ + APP_ERROR_CHECK_BOOL(false); + } + break; + } + + case SER_PHY_EVT_RX_OVERFLOW_ERROR: + { + /* Generate the event to an upper layer. */ + hal_transp_event.evt_type = SER_HAL_TRANSP_EVT_PHY_ERROR; + hal_transp_event.evt_params.phy_error.error_type = + SER_HAL_TRANSP_PHY_ERROR_RX_OVERFLOW; + m_events_handler(hal_transp_event); + break; + } + + case SER_PHY_EVT_TX_OVERREAD_ERROR: + { + /* Generate the event to an upper layer. */ + hal_transp_event.evt_type = SER_HAL_TRANSP_EVT_PHY_ERROR; + hal_transp_event.evt_params.phy_error.error_type = + SER_HAL_TRANSP_PHY_ERROR_TX_OVERREAD; + m_events_handler(hal_transp_event); + break; + } + + case SER_PHY_EVT_HW_ERROR: + { + /* Generate the event to an upper layer. */ + hal_transp_event.evt_type = SER_HAL_TRANSP_EVT_PHY_ERROR; + hal_transp_event.evt_params.phy_error.error_type = + SER_HAL_TRANSP_PHY_ERROR_HW_ERROR; + hal_transp_event.evt_params.phy_error.hw_error_code = + phy_event.evt_params.hw_error.error_code; + if (HAL_TRANSP_TX_STATE_TRANSMITTING == m_tx_state) + { + m_tx_state = HAL_TRANSP_TX_STATE_TRANSMITTED; + err_code = ser_hal_transport_tx_pkt_free(phy_event.evt_params.hw_error.p_buffer); + APP_ERROR_CHECK(err_code); + /* An event to an upper layer that a packet has been transmitted. */ + } + else if (HAL_TRANSP_RX_STATE_RECEIVING == m_rx_state) + { + m_rx_state = HAL_TRANSP_RX_STATE_RECEIVED; + err_code = ser_hal_transport_rx_pkt_free(phy_event.evt_params.hw_error.p_buffer); + APP_ERROR_CHECK(err_code); + } + m_events_handler(hal_transp_event); + + break; + } + + default: + { + APP_ERROR_CHECK_BOOL(false); + break; + } + } +} + +uint32_t ser_hal_transport_open(ser_hal_transport_events_handler_t events_handler) +{ + uint32_t err_code = NRF_SUCCESS; + + if ((HAL_TRANSP_RX_STATE_CLOSED != m_rx_state) || (HAL_TRANSP_TX_STATE_CLOSED != m_tx_state)) + { + err_code = NRF_ERROR_INVALID_STATE; + } + else if (NULL == events_handler) + { + err_code = NRF_ERROR_NULL; + } + else + { + /* We have to change states before calling lower layer because ser_phy_open() function is + * going to enable interrupts. On success an event from PHY layer can be emitted immediately + * after return from ser_phy_open(). */ + m_rx_state = HAL_TRANSP_RX_STATE_IDLE; + m_tx_state = HAL_TRANSP_TX_STATE_IDLE; + + m_events_handler = events_handler; + + /* Initialize a PHY module. */ + err_code = ser_phy_open(phy_events_handler); + + if (NRF_SUCCESS != err_code) + { + m_rx_state = HAL_TRANSP_RX_STATE_CLOSED; + m_tx_state = HAL_TRANSP_TX_STATE_CLOSED; + m_events_handler = NULL; + + if (NRF_ERROR_INVALID_PARAM != err_code) + { + err_code = NRF_ERROR_INTERNAL; + } + } + } + + return err_code; +} + + +void ser_hal_transport_close(void) +{ + /* Reset generic handler for all events, reset internal states and close PHY module. */ + ser_phy_interrupts_disable(); + m_rx_state = HAL_TRANSP_RX_STATE_CLOSED; + m_tx_state = HAL_TRANSP_TX_STATE_CLOSED; + + m_events_handler = NULL; + + ser_phy_close(); +} + + +uint32_t ser_hal_transport_rx_pkt_free(uint8_t * p_buffer) +{ + + NRF_LOG_INFO("rx pkt free:%d", p_buffer); + uint32_t err_code = NRF_SUCCESS; + + ser_phy_interrupts_disable(); + + if (NULL == p_buffer) + { + err_code = NRF_ERROR_NULL; + } + else if (p_buffer != m_rx_buffer) + { + err_code = NRF_ERROR_INVALID_ADDR; + } + else if (HAL_TRANSP_RX_STATE_RECEIVED == m_rx_state) + { + m_rx_state = HAL_TRANSP_RX_STATE_IDLE; + } + else if (HAL_TRANSP_RX_STATE_RECEIVED_DROPPING == m_rx_state) + { + m_rx_state = HAL_TRANSP_RX_STATE_DROPPING; + } + else if (HAL_TRANSP_RX_STATE_RECEIVED_PENDING_BUF_REQ == m_rx_state) + { + err_code = ser_phy_rx_buf_set(m_rx_buffer); + + if (NRF_SUCCESS == err_code) + { + m_rx_state = HAL_TRANSP_RX_STATE_RECEIVING; + } + else + { + err_code = NRF_ERROR_INTERNAL; + } + } + else + { + /* Upper layer should not call this function in current state. */ + err_code = NRF_ERROR_INVALID_STATE; + } + ser_phy_interrupts_enable(); + + return err_code; +} + + +uint32_t ser_hal_transport_tx_pkt_alloc(uint8_t * * pp_memory, uint16_t * p_num_of_bytes) +{ + uint32_t err_code = NRF_SUCCESS; + + if ((NULL == pp_memory) || (NULL == p_num_of_bytes)) + { + err_code = NRF_ERROR_NULL; + } + else if (HAL_TRANSP_TX_STATE_CLOSED == m_tx_state) + { + err_code = NRF_ERROR_INVALID_STATE; + } + else if (HAL_TRANSP_TX_STATE_IDLE == m_tx_state) + { + m_tx_state = HAL_TRANSP_TX_STATE_TX_ALLOCATED; + *pp_memory = &m_tx_buffer[0]; + *p_num_of_bytes = (uint16_t)sizeof (m_tx_buffer); + } + else + { + err_code = NRF_ERROR_NO_MEM; + } + + return err_code; +} + + +uint32_t ser_hal_transport_tx_pkt_send(const uint8_t * p_buffer, uint16_t num_of_bytes) +{ + uint32_t err_code = NRF_SUCCESS; + + /* The buffer provided to this function must be allocated through ser_hal_transport_tx_alloc() + * function - this assures correct state and that correct memory buffer is used. */ + if (NULL == p_buffer) + { + err_code = NRF_ERROR_NULL; + } + else if (0 == num_of_bytes) + { + err_code = NRF_ERROR_INVALID_PARAM; + } + else if (p_buffer != m_tx_buffer) + { + err_code = NRF_ERROR_INVALID_ADDR; + } + else if (num_of_bytes > sizeof (m_tx_buffer)) + { + err_code = NRF_ERROR_DATA_SIZE; + } + else if (HAL_TRANSP_TX_STATE_TX_ALLOCATED == m_tx_state) + { + ser_phy_interrupts_disable(); + err_code = ser_phy_tx_pkt_send(p_buffer, num_of_bytes); + + if (NRF_SUCCESS == err_code) + { + m_tx_state = HAL_TRANSP_TX_STATE_TRANSMITTING; + } + else + { + if (NRF_ERROR_BUSY != err_code) + { + err_code = NRF_ERROR_INTERNAL; + } + } + ser_phy_interrupts_enable(); + } + else + { + err_code = NRF_ERROR_INVALID_STATE; + } + + return err_code; +} + + +uint32_t ser_hal_transport_tx_pkt_free(uint8_t * p_buffer) +{ + uint32_t err_code = NRF_SUCCESS; + + if (NULL == p_buffer) + { + err_code = NRF_ERROR_NULL; + } + else if (p_buffer != m_tx_buffer) + { + err_code = NRF_ERROR_INVALID_ADDR; + } + else if ((HAL_TRANSP_TX_STATE_TX_ALLOCATED == m_tx_state) || + (HAL_TRANSP_TX_STATE_TRANSMITTED == m_tx_state)) + { + /* Release TX buffer for use. */ + m_tx_state = HAL_TRANSP_TX_STATE_IDLE; + } + else + { + err_code = NRF_ERROR_INVALID_STATE; + } + + return err_code; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_hal_transport.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_hal_transport.h new file mode 100644 index 0000000..e0b78be --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_hal_transport.h @@ -0,0 +1,266 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +/** @file + * + * @defgroup ser_hal_transport Serialization HAL Transport + * @{ + * @ingroup ble_sdk_lib_serialization + * + * @brief HAL Transport layer for serialization. + * + * @details The @ref ser_hal_transport declares functions and typedefs used as API of the HAL + * transport layer for serialization. This layer is fully hardware-independent. + * Currently, the HAL transport layer is responsible for controlling the PHY layer and + * memory management. In the future, more features might be added to it, such as CRC + * or retransmission. + * + * \n \n + * \image html ser_hal_transport_rx_state_machine.svg "RX state machine" + * \n \n + * \image html ser_hal_transport_tx_state_machine.svg "TX state machine" + * \n + */ + +#ifndef SER_HAL_TRANSPORT_H__ +#define SER_HAL_TRANSPORT_H__ + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + + +/**@brief Serialization HAL Transport layer event types. */ +typedef enum +{ + SER_HAL_TRANSP_EVT_TX_PKT_SENT = 0, /**< An event indicating that TX packet has been + transmitted. */ + SER_HAL_TRANSP_EVT_RX_PKT_RECEIVING, /**< An event indicating that RX packet is being + scheduled to receive or to drop. */ + SER_HAL_TRANSP_EVT_RX_PKT_RECEIVED, /**< An event indicating that RX packet is ready for + read. */ + SER_HAL_TRANSP_EVT_RX_PKT_DROPPED, /**< An event indicating that RX packet was dropped + because it was longer than available buffer. */ + SER_HAL_TRANSP_EVT_PHY_ERROR, /**< An event indicating error on PHY layer. */ + SER_HAL_TRANSP_EVT_TYPE_MAX /**< Enumeration upper bound. */ +} ser_hal_transport_evt_type_t; + + +/**@brief Serialization PHY layer error types. */ +typedef enum +{ + SER_HAL_TRANSP_PHY_ERROR_RX_OVERFLOW = 0, /**< An error indicating that more information has + been transmitted than the PHY module could handle. */ + SER_HAL_TRANSP_PHY_ERROR_TX_OVERREAD, /**< An error indicating that the PHY module was forced to + transmit more information than possessed. */ + SER_HAL_TRANSP_PHY_ERROR_HW_ERROR, /**< An error indicating a hardware error in the PHY + module. */ + SER_HAL_TRANSP_PHY_ERROR_TYPE_MAX /**< Enumeration upper bound. */ +} ser_hal_transport_phy_error_type_t; + + +/**@brief Struct containing parameters of event of type + * @ref SER_HAL_TRANSP_EVT_RX_PKT_RECEIVED. + */ +typedef struct +{ + uint8_t * p_buffer; /**< Pointer to a buffer containing a packet to read. */ + uint16_t num_of_bytes; /**< Length of a received packet in octets. */ +} ser_hal_transport_evt_rx_pkt_received_params_t; + + +/**@brief Struct containing parameters of event of type @ref SER_HAL_TRANSP_EVT_PHY_ERROR. */ +typedef struct +{ + ser_hal_transport_phy_error_type_t error_type; /**< Type of the PHY error. */ + uint32_t hw_error_code; /**< Hardware error code - specific for a microcontroller. Parameter + is valid only for the PHY error of type + @ref SER_HAL_TRANSP_PHY_ERROR_HW_ERROR. */ +} ser_hal_transport_evt_phy_error_params_t; + + +/**@brief Struct containing events from the Serialization HAL Transport layer. + * + * @note Some events do not have parameters, then the whole information is contained in the evt_type. + */ +typedef struct +{ + ser_hal_transport_evt_type_t evt_type; /**< Type of event. */ + union /**< Union alternative identified by evt_type in the enclosing struct. */ + { + ser_hal_transport_evt_rx_pkt_received_params_t rx_pkt_received; /**< Parameters of event of type @ref SER_HAL_TRANSP_EVT_RX_PKT_RECEIVED. */ + ser_hal_transport_evt_phy_error_params_t phy_error; /**< Parameters of event of type @ref SER_HAL_TRANSP_EVT_PHY_ERROR. */ + } evt_params; +} ser_hal_transport_evt_t; + + +/**@brief Generic callback function type to be used by all Serialization HAL Transport layer + * events. + * + * @param[in] event Serialization HAL Transport layer event. + */ +typedef void (*ser_hal_transport_events_handler_t)(ser_hal_transport_evt_t event); + + +/**@brief Function for opening and initializing the Serialization HAL Transport layer. + * + * @note The function opens the transport channel, initializes a PHY layer, and registers the callback + * function to be used by all Serialization HAL Transport layer events. + * + * @warning If the function has been already called, the function @ref ser_hal_transport_close has + * to be called before ser_hal_transport_open can be called again. + * + * @param[in] events_handler Generic callback function to be used by all Serialization HAL + * Transport layer events. + * + * @retval NRF_SUCCESS Operation success. + * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_PARAM Operation failure. Hardware initialization parameters taken from + * the configuration file are wrong. + * @retval NRF_ERROR_INVALID_STATE Operation failure. The function has been already called. To call + * it again the function @ref ser_hal_transport_close has to be + * called first. + * @retval NRF_ERROR_INTERNAL Operation failure. Internal error ocurred. + */ +uint32_t ser_hal_transport_open(ser_hal_transport_events_handler_t events_handler); + + +/**@brief Function for closing a transport channel. + * + * @note The function disables the hardware, resets internal module states, and unregisters the events + * callback function. Can be called multiple times, also for a channel that is not opened. + */ +void ser_hal_transport_close(void); + + +/**@brief Function for freeing memory allocated for an RX packet. + * + * @note The function should be called as a response to an event of type + * @ref SER_HAL_TRANSP_EVT_RX_PKT_RECEIVED when the received data has beed processed. The function + * frees the RX memory pointed by p_buffer. The memory, immediately or at a later time, is + * reused by the underlying transport layer. + * + * @param[in] p_buffer A pointer to the beginning of the buffer that has been processed (has to be + * the same address as provided in the event of type + * @ref SER_HAL_TRANSP_EVT_RX_PKT_RECEIVED). + * + * @retval NRF_SUCCESS Operation success. + * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_ADDR Operation failure. Not a valid pointer (provided address is not + * the starting address of a buffer managed by HAL Transport layer). + * @retval NRF_ERROR_INVALID_STATE Operation failure. The function should be called as a response + * to an event of type @ref SER_HAL_TRANSP_EVT_RX_PKT_RECEIVED. + * @retval NRF_ERROR_INTERNAL Operation failure. Internal error ocurred. + */ +uint32_t ser_hal_transport_rx_pkt_free(uint8_t * p_buffer); + + +/**@brief Function for allocating memory for a TX packet. + * + * @param[out] pp_memory A pointer to pointer to which an address of the beginning of the + * allocated buffer is written. + * @param[out] p_num_of_bytes A pointer to a variable to which size in octets of the allocated + * buffer is written. + * + * @retval NRF_SUCCESS Operation success. Memory was allocated. + * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied. + * @retval NRF_ERROR_NO_MEM Operation failure. No memory available. + * @retval NRF_ERROR_INVALID_STATE Operation failure. The function was called before calling + * @ref ser_hal_transport_open function. + */ +uint32_t ser_hal_transport_tx_pkt_alloc(uint8_t ** pp_memory, uint16_t * p_num_of_bytes); + +/**@brief Function for transmitting a packet. + * + * @note The function adds a packet pointed by the p_buffer parameter to a transmission queue. A buffer + * provided to this function must be allocated by the @ref ser_hal_transport_tx_pkt_alloc function. + * + * @warning Completion of this method does not guarantee that actual peripheral transmission will be completed. + * + * @param[in] p_buffer Pointer to the buffer to transmit. + * @param[in] num_of_bytes Number of octets to transmit. Must be more than 0. + * + * @retval NRF_SUCCESS Operation success. Packet was added to the transmission queue. + * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_PARAM Operation failure. num_of_bytes is equal to 0. + * @retval NRF_ERROR_INVALID_ADDR Operation failure. Not a valid pointer (provided address is not + * the starting address of a buffer managed by HAL Transport layer). + * @retval NRF_ERROR_DATA_SIZE Operation failure. Packet size exceeds limit. + * @retval NRF_ERROR_BUSY Operation failure. Transmission queue is full so packet was not + * added to the transmission queue. + * @retval NRF_ERROR_INVALID_STATE Operation failure. Transmittion channel was not opened by + * @ref ser_hal_transport_open function or provided buffer was not + * allocated by @ref ser_hal_transport_tx_pkt_alloc function. + * @retval NRF_ERROR_INTERNAL Operation failure. Internal error ocurred. + */ +uint32_t ser_hal_transport_tx_pkt_send(const uint8_t * p_buffer, uint16_t num_of_bytes); + + +/**@brief Function for freeing memory allocated for a TX packet. + * + * @note The function frees the TX memory pointed by p_buffer. Freeing a TX buffer is possible only if + * the buffer was allocated by @ref ser_hal_transport_tx_pkt_alloc function and transmittion + * is not in progress. When transmittion has finished, this function is automatically called by + * the Serialization HAL Transport layer, so the only case when this function should be used + * from outside is when a TX buffer was allocated but a transmittion has not been started + * (@ref ser_hal_transport_tx_pkt_send function has not been called). + * + * @param[in] p_buffer Pointer to the beginning of a buffer that has been allocated by + * @ref ser_hal_transport_tx_pkt_alloc function. + * + * @retval NRF_SUCCESS Operation success. Memory was freed. + * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_ADDR Operation failure. Not a valid pointer (provided address is not + * the starting address of a buffer managed by HAL Transport layer). + * @retval NRF_ERROR_INVALID_STATE Operation failure. Freeing a TX buffer is possible only if the + * buffer was allocated by @ref ser_hal_transport_tx_pkt_alloc + * function and transmittion is not in progress. + */ +uint32_t ser_hal_transport_tx_pkt_free(uint8_t * p_buffer); + + + +#ifdef __cplusplus +} +#endif + +#endif /* SER_HAL_TRANSPORT_H__ */ +/** @} */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/config/ser_config_5W_app.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/config/ser_config_5W_app.h new file mode 100644 index 0000000..c9081e1 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/config/ser_config_5W_app.h @@ -0,0 +1,52 @@ +/** + * 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 SER_CONFIG_5W_APP_H__ +#define SER_CONFIG_5W_APP_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifdef __cplusplus +} +#endif + +#endif // SER_CONFIG_5W_APP_H__ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/config/ser_phy_config_app.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/config/ser_phy_config_app.h new file mode 100644 index 0000000..04f9f74 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/config/ser_phy_config_app.h @@ -0,0 +1,106 @@ +/** + * 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 SER_PHY_CONFIG_APP_H__ +#define SER_PHY_CONFIG_APP_H__ + +#include "boards.h" +#include "ser_config.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(SPI_MASTER_0_ENABLE) +#define SER_PHY_SPI_MASTER SPI_MASTER_0 +#endif +#if defined(SPI_MASTER_1_ENABLE) +#define SER_PHY_SPI_MASTER SPI_MASTER_1 +#endif +#if defined(SPI_MASTER_2_ENABLE) +#define SER_PHY_SPI_MASTER SPI_MASTER_2 +#endif + +#if (defined(SPI0_ENABLED) && (SPI0_ENABLED == 1)) || defined(SPI_MASTER_0_ENABLE) + +#define SER_PHY_SPI_MASTER_INSTANCE NRF_DRV_SPI_INSTANCE(0) +#define SER_PHY_SPI_MASTER_PIN_SCK SER_APP_SPIM0_SCK_PIN +#define SER_PHY_SPI_MASTER_PIN_MISO SER_APP_SPIM0_MISO_PIN +#define SER_PHY_SPI_MASTER_PIN_MOSI SER_APP_SPIM0_MOSI_PIN +#define SER_PHY_SPI_MASTER_PIN_SLAVE_SELECT SER_APP_SPIM0_SS_PIN +#define SER_PHY_SPI_MASTER_PIN_SLAVE_REQUEST SER_APP_SPIM0_REQ_PIN +#define SER_PHY_SPI_MASTER_PIN_SLAVE_READY SER_APP_SPIM0_RDY_PIN + +#elif (defined(SPI1_ENABLED) && (SPI1_ENABLED == 1)) || defined(SPI_MASTER_1_ENABLE) + +#define SER_PHY_SPI_MASTER_INSTANCE NRF_DRV_SPI_INSTANCE(1) +#define SER_PHY_SPI_MASTER_PIN_SCK SER_APP_SPIM1_SCK_PIN +#define SER_PHY_SPI_MASTER_PIN_MISO SER_APP_SPIM1_MISO_PIN +#define SER_PHY_SPI_MASTER_PIN_MOSI SER_APP_SPIM1_MOSI_PIN +#define SER_PHY_SPI_MASTER_PIN_SLAVE_SELECT SER_APP_SPIM1_SS_PIN +#define SER_PHY_SPI_MASTER_PIN_SLAVE_REQUEST SER_APP_SPIM1_REQ_PIN +#define SER_PHY_SPI_MASTER_PIN_SLAVE_READY SER_APP_SPIM1_RDY_PIN + +#elif (defined(SPI2_ENABLED) && (SPI2_ENABLED == 1)) || defined(SPI_MASTER_2_ENABLE) + +#define SER_PHY_SPI_MASTER_INSTANCE NRF_DRV_SPI_INSTANCE(2) +#define SER_PHY_SPI_MASTER_PIN_SCK SER_APP_SPIM2_SCK_PIN +#define SER_PHY_SPI_MASTER_PIN_MISO SER_APP_SPIM2_MISO_PIN +#define SER_PHY_SPI_MASTER_PIN_MOSI SER_APP_SPIM2_MOSI_PIN +#define SER_PHY_SPI_MASTER_PIN_SLAVE_SELECT SER_APP_SPIM2_SS_PIN +#define SER_PHY_SPI_MASTER_PIN_SLAVE_REQUEST SER_APP_SPIM2_REQ_PIN +#define SER_PHY_SPI_MASTER_PIN_SLAVE_READY SER_APP_SPIM2_RDY_PIN + +#endif + +#define CONN_CHIP_RESET_PIN_NO SER_CONN_CHIP_RESET_PIN /**< Pin used for reseting the connectivity. */ + +/* UART configuration */ +#define UART_IRQ_PRIORITY APP_IRQ_PRIORITY_MID +#define SER_PHY_UART_RX SER_APP_RX_PIN +#define SER_PHY_UART_TX SER_APP_TX_PIN +#define SER_PHY_UART_CTS SER_APP_CTS_PIN +#define SER_PHY_UART_RTS SER_APP_RTS_PIN + + +#ifdef __cplusplus +} +#endif + +#endif // SER_PHY_CONFIG_APP_H__ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/config/ser_phy_config_conn.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/config/ser_phy_config_conn.h new file mode 100644 index 0000000..baff210 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/config/ser_phy_config_conn.h @@ -0,0 +1,82 @@ +/** + * 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 SER_PHY_CONFIG_CONN_H__ +#define SER_PHY_CONFIG_CONN_H__ + +#include "boards.h" +#include "ser_config.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/***********************************************************************************************//** + * SER_PHY layer configuration. + **************************************************************************************************/ +#define SER_PHY_SPI_PPI_RDY_CH 0 +#define SER_PHY_SPI_GPIOTE_RDY_CH 0 + +#ifdef NRF_SPIS0 +#define SER_PHY_SPI_SLAVE_INSTANCE 0 +#else +#define SER_PHY_SPI_SLAVE_INSTANCE 1 +#endif + +#define SER_PHY_SPI_SLAVE_REQ_PIN SER_CON_SPIS_REQ_PIN +#define SER_PHY_SPI_SLAVE_RDY_PIN SER_CON_SPIS_RDY_PIN +#define SER_PHY_SPI_SLAVE_SCK_PIN SER_CON_SPIS_SCK_PIN +#define SER_PHY_SPI_SLAVE_MISO_PIN SER_CON_SPIS_MISO_PIN +#define SER_PHY_SPI_SLAVE_MOSI_PIN SER_CON_SPIS_MOSI_PIN +#define SER_PHY_SPI_SLAVE_SS_PIN SER_CON_SPIS_CSN_PIN + +/* UART configuration */ +#define UART_IRQ_PRIORITY APP_IRQ_PRIORITY_LOWEST + +#define SER_PHY_UART_RX SER_CON_RX_PIN +#define SER_PHY_UART_TX SER_CON_TX_PIN +#define SER_PHY_UART_CTS SER_CON_CTS_PIN +#define SER_PHY_UART_RTS SER_CON_RTS_PIN + + +#ifdef __cplusplus +} +#endif + +#endif // SER_PHY_CONFIG_CONN_H__ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/config/ser_phy_debug_app.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/config/ser_phy_debug_app.h new file mode 100644 index 0000000..d60f15c --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/config/ser_phy_debug_app.h @@ -0,0 +1,198 @@ +/** + * 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 SER_PHY_DEBUG_APP_H__ +#define SER_PHY_DEBUG_APP_H__ + +#ifndef SER_PHY_DEBUG_APP_ENABLE + +#define DEBUG_EVT_SPI_MASTER_RAW_REQUEST(data) +#define DEBUG_EVT_SPI_MASTER_RAW_READY(data) +#define DEBUG_EVT_SPI_MASTER_RAW_XFER_DONE(data) +#define DEBUG_EVT_SPI_MASTER_RAW_API_CALL(data) +#define DEBUG_EVT_SPI_MASTER_RAW_READY_EDGE(data) +#define DEBUG_EVT_SPI_MASTER_RAW_REQUEST_EDGE(data) +#define DEBUG_EVT_SPI_MASTER_PHY_TX_PKT_SENT(data) +#define DEBUG_EVT_SPI_MASTER_PHY_RX_PKT_DROPPED(data) +#define DEBUG_EVT_SPI_MASTER_PHY_RX_PKT_RECEIVED(data) +#define DEBUG_EVT_SPI_MASTER_PHY_BUF_REQUEST(data) + +#define DEBUG_EVT_SPI_MASTER_RAW_XFER_GUARDED(data) +#define DEBUG_EVT_SPI_MASTER_RAW_XFER_PASSED(data) +#define DEBUG_EVT_SPI_MASTER_RAW_XFER_ABORTED(data) +#define DEBUG_EVT_SPI_MASTER_RAW_XFER_RESTARTED(data) + +#else +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +//Low level hardware events +typedef enum +{ + SPI_MASTER_RAW_READY, + SPI_MASTER_RAW_REQUEST, + SPI_MASTER_RAW_XFER_DONE, + SPI_MASTER_RAW_API_CALL, + SPI_MASTER_RAW_READY_EDGE, + SPI_MASTER_RAW_REQUEST_EDGE, + SPI_MASTER_RAW_XFER_STARTED, + SPI_MASTER_RAW_XFER_GUARDED, + SPI_MASTER_RAW_XFER_PASSED, + SPI_MASTER_RAW_XFER_ABORTED, + SPI_MASTER_RAW_XFER_RESTARTED, + SPI_MASTER_PHY_TX_PKT_SENT, + SPI_MASTER_PHY_BUF_REQUEST, + SPI_MASTER_PHY_RX_PKT_RECEIVED, + SPI_MASTER_PHY_RX_PKT_DROPPED, + SPI_MASTER_EVT_MAX +} spi_master_raw_evt_type_t; + + +//Low level hardware event definition +typedef struct +{ + spi_master_raw_evt_type_t evt; + uint32_t data; +} spi_master_raw_evt_t; + +typedef void (*spi_master_raw_callback_t)(spi_master_raw_evt_t event); + +void debug_init(spi_master_raw_callback_t spi_master_raw_evt_callback); + +void debug_evt(spi_master_raw_evt_type_t evt, uint32_t data); + + +#define DEBUG_EVT(evt, data) \ +do { \ + debug_evt(evt, data); \ +} while (0); + + +#define DEBUG_EVT_SPI_MASTER_RAW_REQUEST(data) \ +do { \ + DEBUG_EVT(SPI_MASTER_RAW_REQUEST, data); \ +} while (0); + + +#define DEBUG_EVT_SPI_MASTER_RAW_READY(data) \ +do { \ + DEBUG_EVT(SPI_MASTER_RAW_READY, data); \ +} while (0); + + +#define DEBUG_EVT_SPI_MASTER_RAW_XFER_DONE(data) \ +do { \ + DEBUG_EVT(SPI_MASTER_RAW_XFER_DONE, data); \ +} while (0); + + +#define DEBUG_EVT_SPI_MASTER_RAW_API_CALL(data) \ +do { \ + DEBUG_EVT(SPI_MASTER_RAW_API_CALL, data); \ +} while (0); + + +#define DEBUG_EVT_SPI_MASTER_RAW_READY_EDGE(data) \ +do { \ + DEBUG_EVT(SPI_MASTER_RAW_READY_EDGE, data); \ +} while (0); + + +#define DEBUG_EVT_SPI_MASTER_RAW_REQUEST_EDGE(data) \ +do { \ + DEBUG_EVT(SPI_MASTER_RAW_REQUEST_EDGE, data); \ +} while (0); + + +#define DEBUG_EVT_SPI_MASTER_PHY_TX_PKT_SENT(data) \ +do { \ + DEBUG_EVT(SPI_MASTER_PHY_TX_PKT_SENT, data); \ +} while (0); + + +#define DEBUG_EVT_SPI_MASTER_PHY_RX_PKT_DROPPED(data) \ +do { \ + DEBUG_EVT(SPI_MASTER_PHY_RX_PKT_DROPPED, data); \ +} while (0); + + +#define DEBUG_EVT_SPI_MASTER_PHY_RX_PKT_RECEIVED(data) \ +do { \ + DEBUG_EVT(SPI_MASTER_PHY_RX_PKT_RECEIVED, data); \ +} while (0); + + +#define DEBUG_EVT_SPI_MASTER_PHY_BUF_REQUEST(data) \ +do { \ + DEBUG_EVT(SPI_MASTER_PHY_BUF_REQUEST, data); \ +} while (0); + +#define DEBUG_EVT_SPI_MASTER_RAW_XFER_GUARDED(data) \ +do { \ + DEBUG_EVT(SPI_MASTER_RAW_XFER_GUARDED, data); \ +} while (0); + +#define DEBUG_EVT_SPI_MASTER_RAW_XFER_PASSED(data) \ +do { \ + DEBUG_EVT(SPI_MASTER_RAW_XFER_PASSED, data); \ +} while (0); + +#define DEBUG_EVT_SPI_MASTER_RAW_XFER_ABORTED(data) \ +do { \ + DEBUG_EVT(SPI_MASTER_RAW_XFER_ABORTED, data); \ +} while (0); + +#define DEBUG_EVT_SPI_MASTER_RAW_XFER_RESTARTED(data) \ +do { \ + DEBUG_EVT(SPI_MASTER_RAW_XFER_RESTARTED, data); \ +} while (0); + + + +#endif + + +#ifdef __cplusplus +} +#endif + +#endif //SER_PHY_DEBUG_APP_H__ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/config/ser_phy_debug_conn.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/config/ser_phy_debug_conn.h new file mode 100644 index 0000000..f79b2d0 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/config/ser_phy_debug_conn.h @@ -0,0 +1,166 @@ +/** + * 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 SER_PHY_DEBUG_CONN_H__ +#define SER_PHY_DEBUG_CONN_H__ + +#ifndef SER_PHY_DEBUG_CONN_ENABLE + +#define DEBUG_EVT_SPI_SLAVE_RAW_RX_XFER_DONE(data); + +#define DEBUG_EVT_SPI_SLAVE_RAW_TX_XFER_DONE(data); + +#define DEBUG_EVT_SPI_SLAVE_RAW_BUFFERS_SET(data); + +#define DEBUG_EVT_SPI_SLAVE_RAW_REQ_SET(data); + +#define DEBUG_EVT_SPI_SLAVE_RAW_REQ_CLEARED(data); + +#define DEBUG_EVT_SPI_SLAVE_PHY_BUF_REQUEST(data); + +#define DEBUG_EVT_SPI_SLAVE_PHY_PKT_RECEIVED(data); + +#define DEBUG_EVT_SPI_SLAVE_PHY_PKT_DROPPED(data); + +#define DEBUG_EVT_SPI_SLAVE_PHY_PKT_SENT(data); + +#else + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +// low level hardware event types +typedef enum +{ + SPI_SLAVE_RAW_BUFFERS_SET, + SPI_SLAVE_RAW_RX_XFER_DONE, + SPI_SLAVE_RAW_TX_XFER_DONE, + SPI_SLAVE_RAW_REQ_SET, + SPI_SLAVE_RAW_REQ_CLEARED, + SPI_SLAVE_PHY_BUF_REQUEST, + SPI_SLAVE_PHY_PKT_SENT, + SPI_SLAVE_PHY_PKT_RECEIVED, + SPI_SLAVE_PHY_PKT_DROPPED, + SPI_SLAVE_RAW_EVT_TYPE_MAX +} spi_slave_raw_evt_type_t; + +// low level hardware event definition +typedef struct +{ + spi_slave_raw_evt_type_t evt_type; + uint32_t data; +} spi_slave_raw_evt_t; + +typedef void (*spi_slave_raw_callback_t)(spi_slave_raw_evt_t event); + +void debug_init(spi_slave_raw_callback_t spi_slave_raw_evt_callback); + +void debug_evt(spi_slave_raw_evt_type_t evt_type, uint32_t data); + +#define DEBUG_EVT(evt, data) \ +do { \ + debug_evt(evt, data); \ +} while (0); + + +#define DEBUG_EVT_SPI_SLAVE_RAW_RX_XFER_DONE(data) \ +do { \ + DEBUG_EVT(SPI_SLAVE_RAW_RX_XFER_DONE, data); \ +} while (0); + + +#define DEBUG_EVT_SPI_SLAVE_RAW_TX_XFER_DONE(data) \ +do { \ + DEBUG_EVT(SPI_SLAVE_RAW_TX_XFER_DONE, data); \ +} while (0); + + +#define DEBUG_EVT_SPI_SLAVE_RAW_BUFFERS_SET(data) \ +do { \ + DEBUG_EVT(SPI_SLAVE_RAW_BUFFERS_SET, data); \ +} while (0); + + +#define DEBUG_EVT_SPI_SLAVE_RAW_REQ_SET(data) \ +do { \ + DEBUG_EVT(SPI_SLAVE_RAW_REQ_SET, data); \ +} while (0); + + +#define DEBUG_EVT_SPI_SLAVE_RAW_REQ_CLEARED(data) \ +do { \ + DEBUG_EVT(SPI_SLAVE_RAW_REQ_CLEARED, data); \ +} while (0); + + +#define DEBUG_EVT_SPI_SLAVE_PHY_BUF_REQUEST(data) \ +do { \ + DEBUG_EVT(SPI_SLAVE_PHY_BUF_REQUEST, data); \ +} while (0); + + +#define DEBUG_EVT_SPI_SLAVE_PHY_PKT_RECEIVED(data) \ +do { \ + DEBUG_EVT(SPI_SLAVE_PHY_PKT_RECEIVED, data); \ +} while (0); + + +#define DEBUG_EVT_SPI_SLAVE_PHY_PKT_DROPPED(data) \ +do { \ + DEBUG_EVT(SPI_SLAVE_PHY_PKT_DROPPED, data); \ +} while (0); + + +#define DEBUG_EVT_SPI_SLAVE_PHY_PKT_SENT(data) \ +do { \ + DEBUG_EVT(SPI_SLAVE_PHY_PKT_SENT, data); \ +} while (0); + + +#endif + + +#ifdef __cplusplus +} +#endif + +#endif //SER_PHY_DEBUG_CONN_H__ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy.c new file mode 100644 index 0000000..57220fe --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy.c @@ -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. + * + */ +#include "ser_phy.h" +#include "app_error.h" + + +__weak uint32_t ser_phy_open(ser_phy_events_handler_t events_handler) +{ + /* A function stub. Function should be implemented according to ser_phy.h API. */ + APP_ERROR_CHECK_BOOL(false); + + return NRF_SUCCESS; +} + +__weak uint32_t ser_phy_tx_pkt_send(const uint8_t * p_buffer, uint16_t num_of_bytes) +{ + /* A function stub. Function should be implemented according to ser_phy.h API. */ + APP_ERROR_CHECK_BOOL(false); + + return NRF_SUCCESS; +} + +__weak uint32_t ser_phy_rx_buf_set(uint8_t * p_buffer) +{ + /* A function stub. Function should be implemented according to ser_phy.h API. */ + APP_ERROR_CHECK_BOOL(false); + + return NRF_SUCCESS; +} + +__weak void ser_phy_close(void) +{ + /* A function stub. Function should be implemented according to ser_phy.h API. */ + APP_ERROR_CHECK_BOOL(false); +} + + +__weak void ser_phy_interrupts_enable(void) +{ + /* A function stub. Function should be implemented according to ser_phy.h API. */ + APP_ERROR_CHECK_BOOL(false); +} + + +__weak void ser_phy_interrupts_disable(void) +{ + /* A function stub. Function should be implemented according to ser_phy.h API. */ + APP_ERROR_CHECK_BOOL(false); +} + + diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy.h new file mode 100644 index 0000000..d40c06e --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy.h @@ -0,0 +1,308 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +/** @file + * + * @defgroup ser_phy Serialization PHY + * @{ + * @ingroup ble_sdk_lib_serialization + * + * @brief PHY layer for serialization. + * + * @details The @ref ser_phy library declares functions and definitions of data structures and + * identifiers (typedef enum) that are used as API of the serialization PHY layer. + * + * \par Rationale + * Each specific PHY layer (SPI, I2C, UART, low power UART etc.) should provide the same API. This + * allows the layer above (the HAL Transport layer), which is responsible for controlling the PHY + * layer, memory management, CRC, retransmission etc., to be hardware independent. + * + * + * \par Interlayer communication and control + * The PHY layer is controlled by the HAL transport layer by calling functions declared in + * the @ref ser_phy library. + * + * @par + * The PHY layer communicates events to the HAL transport layer by calling a callback function. + * A handler to this function is passed in the @ref ser_phy_open function. This callback function + * should be called with a parameter of type @ref ser_phy_evt_t, filled accordingly to an event to be + * passed. Types of supported events are defined in @ref ser_phy_evt_type_t. + * + * @par + * For example, to pass an event indicating that an RX packet has been successfully received, first a + * struct of type @ref ser_phy_evt_t must be filled: + * @code + * ser_phy_evt_t phy_evt; + * phy_evt.evt_type = SER_PHY_EVT_RX_PKT_RECEIVED; + * phy_evt.evt_params.rx_pkt_received.p_buffer = (pointer to the RX buffer); + * phy_evt.evt_params.rx_pkt_received.num_of_bytes = (number of received bytes); + * @endcode + * Then, the callback function must be called: + * @code + * events_handler(phy_evt); + * @endcode + * All functions declared in the @ref ser_phy file (ser_phy.h) must be implemented. Some events specified in + * @ref ser_phy_evt_type_t are optional to implement. + * + * \par Transmitting a packet + * Each PHY layer is responsible for adding the PHY header to a packet to be sent. This header + * consists of a 16-bit field that carries the packet length (the uint16_encode function defined in + * app_util.h should be used to ensure endianness independence). A pointer to a packet to be sent + * and length of the packet are parameters of the @ref ser_phy_tx_pkt_send function. When a packet + * has been transmitted, an event of type @ref SER_PHY_EVT_TX_PKT_SENT should be emitted. + * + * \image html ser_phy_transport_tx.svg "TX - interlayer communication" + * + * \par Receiving a packet + * The PHY layer should be able to store only the PHY header (16-bit field carrying the packet + * length). After the PHY header has been received, the transmission is stopped and the PHY + * layer must send a request to the HAL transport layer for memory to store the packet - an event + * of type @ref SER_PHY_EVT_RX_BUF_REQUEST with event parameters defined in + * @ref ser_phy_evt_rx_buf_request_params_t (the uint16_decode function defined in app_util.h should + * be used for header decoding to ensure endianness independence). The transmission should be + * resumed when the @ref ser_phy_rx_buf_set function has been called. + * + * @par + * When the @ref ser_phy_rx_buf_set function parameter equals NULL, there is not + * enough memory to store the packet. However, the packet will be received to a dummy location to + * ensure continuous communication. After receiving has finished, an event of type + * @ref SER_PHY_EVT_RX_PKT_DROPPED is generated. + * + * \image html ser_phy_transport_rx_dropped.svg "RX dropping - interlayer communication" + * + * @par + * When the @ref ser_phy_rx_buf_set function parameter is different than NULL, the packet is + * received to a buffer pointed to by it. After receiving has finished, an event of type + * @ref SER_PHY_EVT_RX_PKT_RECEIVED is generated with event parameters defined in + * @ref ser_phy_evt_rx_pkt_received_params_t. + * + * \image html ser_phy_transport_rx_received.svg "RX - interlayer communication" + * + * \par PHY layer errors + * PHY layer errors can be signaled by an event of type @ref SER_PHY_EVT_RX_OVERFLOW_ERROR or + * @ref SER_PHY_EVT_TX_OVERREAD_ERROR or @ref SER_PHY_EVT_HW_ERROR with event parameters defined in + * @ref ser_phy_evt_hw_error_params_t. + * + * @par Available PHY layers + * The following PHY layers are available: + * - @ref ser_phy_spi_page + * - @ref ser_phy_spi_5W_page + * - @ref ser_phy_uart_page + * - @ref ser_phy_uart_hci_page + * <!-- - @ref ser_phy_usb_hci_page --> + * + */ + +#ifndef SER_PHY_H__ +#define SER_PHY_H__ + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/**@brief Serialization PHY module event types. */ +typedef enum +{ + SER_PHY_EVT_TX_PKT_SENT = 0, /**< Obligatory to implement. An event indicating that a TX packet + * has been transmitted. */ + SER_PHY_EVT_RX_BUF_REQUEST, /**< Obligatory to implement. An event indicating that the PHY layer + * needs a buffer for an RX packet. The PHY flow should be blocked + * until the @ref ser_phy_rx_buf_set function is called. */ + SER_PHY_EVT_RX_PKT_RECEIVED, /**< Obligatory to implement. An event indicating that an RX packet + * has been successfully received. */ + SER_PHY_EVT_RX_PKT_DROPPED, /**< Obligatory to implement. An event indicating that the RX packet + * receiving has been finished but the packet was discarded because + * it was longer than available the buffer. */ + + SER_PHY_EVT_RX_OVERFLOW_ERROR, /**< Optional to implement. An event indicating that more + * information has been transmitted than the PHY module could + * handle. */ + SER_PHY_EVT_TX_OVERREAD_ERROR, /**< Optional to implement. An event indicating that the PHY module + * was forced to transmit more information than possessed. */ + SER_PHY_EVT_HW_ERROR, /**< Optional to implement. An event indicating a hardware error + * in the PHY module. */ + SER_PHY_EVT_TYPE_MAX /**< Enumeration upper bound. */ +} ser_phy_evt_type_t; + + +/**@brief A struct containing parameters of event of type @ref SER_PHY_EVT_RX_BUF_REQUEST. */ +typedef struct +{ + uint16_t num_of_bytes; /**< Length of a buffer in octets that the layer above the PHY module should + * deliver, so that the PHY module can receive a packet. */ +} ser_phy_evt_rx_buf_request_params_t; + + +/**@brief A struct containing parameters of event of type @ref SER_PHY_EVT_RX_PKT_RECEIVED. */ +typedef struct +{ + uint8_t * p_buffer; /**< Pointer to a buffer containing the received packet. */ + uint16_t num_of_bytes; /**< Length of the received packet in octets. */ +} ser_phy_evt_rx_pkt_received_params_t; + + +/**@brief A struct containing parameters of event of type @ref SER_PHY_EVT_HW_ERROR. */ +typedef struct +{ + uint32_t error_code; /**< Hardware error code - specific for a microcontroller. */ + uint8_t * p_buffer; /**< Pointer to the buffer that was processed when error occured. */ +} ser_phy_evt_hw_error_params_t; + + +/**@brief A struct containing events from a Serialization PHY module. + * + * @note Some events do not have parameters, then whole information is contained in the evt_type. + */ +typedef struct +{ + ser_phy_evt_type_t evt_type; /**< Type of event. */ + + union /**< Union alternative identified by evt_type in enclosing struct. */ + { + /** Parameters of event of type @ref SER_PHY_EVT_RX_BUF_REQUEST. */ + ser_phy_evt_rx_buf_request_params_t rx_buf_request; + /** Parameters of event of type @ref SER_PHY_EVT_RX_PKT_RECEIVED. */ + ser_phy_evt_rx_pkt_received_params_t rx_pkt_received; + /** Parameters of the event of type @ref SER_PHY_EVT_HW_ERROR. */ + ser_phy_evt_hw_error_params_t hw_error; + } evt_params; +} ser_phy_evt_t; + + +/**@brief A type of generic callback function handler to be used by all PHY module events. + * + * @param[in] event Serialization PHY module event. + */ +typedef void (*ser_phy_events_handler_t)(ser_phy_evt_t event); + + +/**@brief Function for opening and initializing the PHY module. + * + * @note The function initializes hardware and internal module states, and registers callback + * function to be used by all PHY module events. + * + * @warning If the function has been already called, the function @ref ser_phy_close has to be + * called before ser_phy_open can be called again. + * + * @param[in] events_handler Generic callback function handler to be used by all PHY module + * events. + * + * @retval NRF_SUCCESS Operation success. + * @retval NRF_ERROR_INVALID_STATE Operation failure. The function has been already called. + * To call it again, the function @ref ser_phy_close has to be + * called first. + * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_PARAM Operation failure. Hardware initialization parameters are not + * supported. + */ +uint32_t ser_phy_open(ser_phy_events_handler_t events_handler); + + +/**@brief Function for transmitting a packet. + * + * @note The function adds a packet pointed by p_buffer parameter to a transmission queue and + * schedules generation of an event of type @ref SER_PHY_EVT_TX_PKT_SENT upon transmission + * completion. + * + * @param[in] p_buffer Pointer to a buffer to transmit. + * @param[in] num_of_bytes Number of octets to transmit. Must be more than 0. + * + * @retval NRF_SUCCESS Operation success. Packet was added to the transmission queue + * and event will be send upon transmission completion. + * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_PARAM Operation failure. The num_of_bytes parameter equal to 0. + * @retval NRF_ERROR_BUSY Operation failure. Transmitting of a packet in progress. + */ +uint32_t ser_phy_tx_pkt_send(const uint8_t * p_buffer, uint16_t num_of_bytes); + + +/**@brief Function for setting an RX buffer and enabling reception of data (the PHY flow). + * + * @note The function has to be called as a response to an event of type + * @ref SER_PHY_EVT_RX_BUF_REQUEST. The function sets an RX buffer and enables reception of + * data (enables the PHY flow). + * Size of a buffer pointed by the p_buffer parameter should be at least equal to the + * num_of_bytes parameter passed within the event (@ref ser_phy_evt_rx_buf_request_params_t), + * or p_buffer should be equal to NULL if there is not enough memory. + * When p_buffer is different from NULL and num_of_bytes octets have been received, an event of + * type @ref SER_PHY_EVT_RX_PKT_RECEIVED is generated + * (@ref ser_phy_evt_rx_pkt_received_params_t). + * When p_buffer is equal to NULL, data is received to dummy location to ensure continuous + * communication. Then, if num_of_bytes octets have been received, an event of type + * @ref SER_PHY_EVT_RX_PKT_DROPPED is generated. + * + * @param[in] p_buffer Pointer to an RX buffer in which to receive. + * + * @retval NRF_SUCCESS Operation success. + * @retval NRF_ERROR_INVALID_STATE Operation failure. A buffer was set without request. + */ +uint32_t ser_phy_rx_buf_set(uint8_t * p_buffer); + + +/**@brief Function for closing the PHY module. + * + * @note The function disables hardware, resets internal module states, and unregisters the events + * callback function. + */ +void ser_phy_close(void); + + +/**@brief Function for enabling the PHY module interrupts. + * + * @note The function enables all interrupts that are used by the PHY module (and only those). + */ +void ser_phy_interrupts_enable(void); + + +/**@brief Function for disabling the PHY module interrupts. + * + * @note The function disables all interrupts that are used by the PHY module (and only those). + */ +void ser_phy_interrupts_disable(void); + + + +#ifdef __cplusplus +} +#endif + +#endif /* SER_PHY_H__ */ +/** @} */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_hci.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_hci.c new file mode 100644 index 0000000..4e1f85a --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_hci.c @@ -0,0 +1,1704 @@ +/** + * 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 <string.h> + +#include "app_error.h" +#include "app_util.h" +#include "app_util_platform.h" +#include "app_timer.h" +#include "nrf_queue.h" +#include "ser_phy.h" +#include "ser_phy_hci.h" +#include "crc16.h" +#include "nrf_soc.h" +#include "ser_config.h" +#include "ser_phy_debug_comm.h" +#define NRF_LOG_MODULE_NAME sphy_hci +#include "nrf_log.h" +NRF_LOG_MODULE_REGISTER(); +// hide globals for release version, expose for debug version +#if defined(SER_PHY_HCI_DEBUG_ENABLE) +#define _static +#else +#define _static static +#endif + +#define PKT_HDR_SIZE 4 /**< Packet header size in number of bytes. */ +#define PKT_CRC_SIZE 2 /**< Packet CRC size in number of bytes. */ +#define MAX_PACKET_SIZE_IN_BITS (11uL * \ + (SER_HAL_TRANSPORT_MAX_PKT_SIZE + PKT_HDR_SIZE + PKT_CRC_SIZE)) +#define BAUD_TIME_us (1000000uL / SER_PHY_UART_BAUDRATE_VAL) + +#define TX_EVT_QUEUE_SIZE 16 +#define RX_EVT_QUEUE_SIZE 16 +#define PKT_TYPE_VENDOR_SPECIFIC 14 /**< Packet type vendor specific. */ +#define PKT_TYPE_ACK 0 /**< Packet type acknowledgement. */ +#define PKT_TYPE_LINK_CONTROL 15 /**< Packet type link control. */ +#define PKT_TYPE_RESET 5 /**< Packet type reset. */ +#define DATA_INTEGRITY_MASK (1 << 6) /**< Mask for data integrity bit in the packet header. */ +#define RELIABLE_PKT_MASK (1 << 7) /**< Mask for reliable packet bit in the packet header. */ +#define INITIAL_ACK_NUMBER_EXPECTED 0 /**< Initial acknowledge number expected. */ +#define INITIAL_SEQ_NUMBER INITIAL_ACK_NUMBER_EXPECTED /**< Initial acknowledge number transmitted. */ +#define INVALID_PKT_TYPE 0xFFFFFFFFu /**< Internal invalid packet type value. */ +#define MAX_TRANSMISSION_TIME_ms (MAX_PACKET_SIZE_IN_BITS * BAUD_TIME_us / 1000uL) /**< Max transmission time of a single application packet over UART in units of mseconds. */ +#define RETRANSMISSION_TIMEOUT_IN_ms (50uL * MAX_TRANSMISSION_TIME_ms) /**< Retransmission timeout for application packet in units of mseconds. */ + +#ifdef HCI_LINK_CONTROL +#define HCI_PKT_SYNC 0x7E01u /**< Link Control Packet: type SYNC */ +#define HCI_PKT_SYNC_RSP 0x7D02u /**< Link Control Packet: type SYNC RESPONSE */ +#define HCI_PKT_CONFIG 0xFC03u /**< Link Control Packet: type CONFIG */ +#define HCI_PKT_CONFIG_RSP 0x7B04u /**< Link Control Packet: type CONFIG RESPONSE */ +#define HCI_CONFIG_FIELD 0x11u /**< Configuration field of CONFIG and CONFIG_RSP packet */ +#define HCI_PKT_SYNC_SIZE 6u /**< Size of SYNC and SYNC_RSP packet */ +#define HCI_PKT_CONFIG_SIZE 7u /**< Size of CONFIG and CONFIG_RSP packet */ +#define HCI_LINK_CONTROL_PKT_INVALID 0xFFFFu /**< Size of CONFIG and CONFIG_RSP packet */ +#define HCI_LINK_CONTROL_TIMEOUT 1u /**< Default link control timeout. */ +#endif /* HCI_LINK_CONTROL */ + + +#define RETRANSMISSION_TIMEOUT_IN_TICKS (APP_TIMER_TICKS(RETRANSMISSION_TIMEOUT_IN_ms)) /**< Retransmission timeout for application packet in units of timer ticks. */ +#define MAX_RETRY_COUNT 5 /**< Max retransmission retry count for application packets. */ + +#if (defined(HCI_TIMER0)) +#define HCI_TIMER NRF_TIMER0 +#define HCI_TIMER_IRQn TIMER0_IRQn +#define HCI_TIMER_IRQHandler TIMER0_IRQHandler +#elif (defined(HCI_TIMER1)) +#define HCI_TIMER NRF_TIMER1 +#define HCI_TIMER_IRQn TIMER1_IRQn +#define HCI_TIMER_IRQHandler TIMER1_IRQHandler +#elif (defined(HCI_TIMER2)) +#define HCI_TIMER NRF_TIMER2 +#define HCI_TIMER_IRQn TIMER2_IRQn +#define HCI_TIMER_IRQHandler TIMER2_IRQHandler +#else +#define HCI_APP_TIMER +#endif + + +/**@brief States of the hci event driven state machine. */ +typedef enum +{ + HCI_TX_STATE_DISABLE, + HCI_TX_STATE_SEND, + HCI_TX_STATE_WAIT_FOR_FIRST_TX_END, + HCI_TX_STATE_WAIT_FOR_ACK_OR_TX_END, + HCI_TX_STATE_WAIT_FOR_ACK, + HCI_TX_STATE_WAIT_FOR_TX_END +} hci_tx_fsm_state_t; + +typedef enum +{ + HCI_RX_STATE_DISABLE, + HCI_RX_STATE_RECEIVE, + HCI_RX_STATE_WAIT_FOR_MEM, + HCI_RX_STATE_WAIT_FOR_SLIP_ACK_END, + HCI_RX_STATE_WAIT_FOR_SLIP_NACK_END, +} hci_rx_fsm_state_t; + +typedef enum +{ + HCI_EVT_TIMEOUT, +} hci_timer_evt_type_t; + +typedef enum +{ + HCI_SER_PHY_TX_REQUEST, + HCI_SER_PHY_RX_BUF_GRANTED, + HCI_SER_PHY_EVT_GEN_ENABLE, + HCI_SER_PHY_EVT_GEN_DISABLE +} ser_phy_int_evt_type_t; + +typedef enum +{ + HCI_SER_PHY_EVT, + HCI_SLIP_EVT, + HCI_TIMER_EVT, +} hci_evt_source_t; + +#ifdef HCI_LINK_CONTROL +typedef enum +{ + HCI_MODE_DISABLE, + HCI_MODE_UNINITIALIZED, + HCI_MODE_INITIALIZED, + HCI_MODE_ACTIVE, +} hci_mode_t; +#endif /*HCI_LINK_CONTROL */ + +typedef struct +{ + hci_timer_evt_type_t evt_type; /**< Type of an event. */ +} hci_timer_evt_t; + +typedef struct +{ + ser_phy_int_evt_type_t evt_type; /**< Type of an event. */ +} ser_phy_int_evt_t; + +typedef struct +{ + hci_evt_source_t evt_source; /**< source of an event. */ + union + { + ser_phy_int_evt_t ser_phy_evt; /**< ser_phy event. */ + ser_phy_hci_slip_evt_t ser_phy_slip_evt; /**< ser_phy_hci event. */ + hci_timer_evt_t timer_evt; /**< timer event. */ + } evt; +} hci_evt_t; + +_static uint8_t m_tx_packet_header[PKT_HDR_SIZE]; +_static uint8_t m_tx_packet_crc[PKT_CRC_SIZE]; +_static uint8_t m_tx_ack_packet[PKT_HDR_SIZE]; +#ifdef HCI_LINK_CONTROL +_static uint8_t m_tx_link_control_header[PKT_HDR_SIZE]; +_static uint8_t m_tx_link_control_payload[HCI_PKT_CONFIG_SIZE - PKT_HDR_SIZE]; +#endif /* HCI_LINK_CONTROL */ + +_static uint32_t m_packet_ack_number; // Sequence number counter of the packet expected to be received +_static uint32_t m_packet_seq_number; // Sequence number counter of the transmitted packet for which acknowledgement packet is waited for + + +_static uint32_t m_tx_retry_count; + + +// _static uint32_t m_tx_retx_counter = 0; +// _static uint32_t m_rx_drop_counter = 0; + +NRF_QUEUE_DEF(hci_evt_t, + m_tx_evt_queue, + TX_EVT_QUEUE_SIZE, + NRF_QUEUE_MODE_NO_OVERFLOW); + +NRF_QUEUE_DEF(hci_evt_t, + m_rx_evt_queue, + RX_EVT_QUEUE_SIZE, + NRF_QUEUE_MODE_NO_OVERFLOW); + +_static hci_tx_fsm_state_t m_hci_tx_fsm_state = HCI_TX_STATE_DISABLE; +_static hci_rx_fsm_state_t m_hci_rx_fsm_state = HCI_RX_STATE_DISABLE; + +#ifdef HCI_LINK_CONTROL +_static hci_mode_t m_hci_mode = HCI_MODE_DISABLE; +_static uint16_t m_hci_link_control_next_pkt = HCI_PKT_SYNC; +_static bool m_hci_other_side_active = false; +#endif /* HCI_LINK_CONTROL */ + +#ifdef HCI_APP_TIMER +APP_TIMER_DEF(m_app_timer_id); +#endif + +_static bool m_tx_fsm_idle_flag = true; +_static bool m_rx_fsm_idle_flag = true; + +_static bool m_buffer_reqested_flag = false; + +_static uint8_t * m_p_rx_buffer = NULL; +_static uint16_t m_rx_packet_length; +_static uint8_t * m_p_rx_packet; +_static uint8_t * m_p_tx_payload = NULL; +_static uint16_t m_tx_payload_length; + +_static ser_phy_events_handler_t m_ser_phy_callback = NULL; + +static void hci_tx_event_handler(hci_evt_t * p_event); +static void hci_rx_event_handler(hci_evt_t * p_event); +#ifdef HCI_LINK_CONTROL +static void hci_link_control_event_handler(hci_evt_t * p_event); +#endif /* HCI_LINK_CONTROL */ + +_static bool m_hci_timer_enabled_flag = true; +_static bool m_hci_timout_pending_flag = false; +_static bool m_hci_global_enable_flag = true; + +#define ser_phy_hci_assert(cond) APP_ERROR_CHECK_BOOL(cond) + +static void hci_signal_timeout_event(void) +{ + hci_evt_t event; + + event.evt_source = HCI_TIMER_EVT; + event.evt.timer_evt.evt_type = HCI_EVT_TIMEOUT; + DEBUG_EVT_TIMEOUT(0); + +#ifndef HCI_LINK_CONTROL + hci_tx_event_handler(&event); +#else + hci_link_control_event_handler(&event); + if ((m_hci_mode == HCI_MODE_ACTIVE) && m_hci_other_side_active) + { + hci_tx_event_handler(&event); + } +#endif /* HCI_LINK_CONTROL */ +} + + +#ifndef HCI_APP_TIMER + +void HCI_TIMER_IRQHandler(void) +{ + + if ((HCI_TIMER->EVENTS_COMPARE[1] == 1) && (HCI_TIMER->INTENSET & TIMER_INTENSET_COMPARE1_Msk)) + { + HCI_TIMER->EVENTS_COMPARE[1] = 0; + HCI_TIMER->TASKS_CLEAR = 1; + + if (m_hci_timer_enabled_flag) + { + hci_signal_timeout_event(); + } + else + { + m_hci_timout_pending_flag = true; + } + } +} + + +static void hci_timeout_setup(uint32_t count) +{ + + uint32_t time_msec; + + if (count) + { + HCI_TIMER->INTENCLR = TIMER_INTENCLR_COMPARE1_Msk; + time_msec = count * RETRANSMISSION_TIMEOUT_IN_ms; + HCI_TIMER->CC[1] = time_msec * 31; + HCI_TIMER->CC[1] += time_msec / 4; + HCI_TIMER->TASKS_CLEAR = 1; // < Clear TIMER + HCI_TIMER->EVENTS_COMPARE[1] = 0; + HCI_TIMER->TASKS_START = 1; // < Start TIMER + HCI_TIMER->INTENSET = TIMER_INTENSET_COMPARE1_Msk; + } + else + { + HCI_TIMER->INTENCLR = TIMER_INTENCLR_COMPARE1_Msk; + HCI_TIMER->TASKS_STOP = 1; // < Start TIMER + } +} + + +#else + +_static bool m_hci_timer_setup_flag = false; +_static uint32_t m_hci_timer_counter = 0; +_static uint32_t m_hci_timer_setup; + +static void hci_timeout_setup(uint32_t count) +{ + m_hci_timer_setup = count; + m_hci_timer_setup_flag = true; +} + + +static void hci_timeout_handler(void * p_context) +{ + + if (m_hci_timer_setup_flag) + { + m_hci_timer_setup_flag = false; + m_hci_timer_counter = m_hci_timer_setup; /* for 1 it will be always more than 1 tick - jitter is up to 1 tick */ + } + else if ( m_hci_timer_counter ) + { + m_hci_timer_counter--; + + if (m_hci_timer_counter == 0) + { + if (m_hci_timer_enabled_flag) + { + hci_signal_timeout_event(); + } + else + { + m_hci_timout_pending_flag = true; + } + } + } + return; +} + + +#endif + + +/**@brief Function for validating a received packet. + * + * @param[in] p_buffer Pointer to the packet data. + * @param[in] length Length of packet data in bytes. + * + * @return true if received packet is valid, false in other case. + */ +static bool is_rx_pkt_valid(const uint8_t * p_buffer, uint32_t length) +{ + // Executed packet filtering algorithm order: + // - verify packet overall length + // - verify data integrity bit set + // - verify reliable packet bit set + // - verify supported packet type + // - verify header checksum + // - verify payload length field + // - verify CRC + if (length <= PKT_HDR_SIZE) + { + return false; + } + + if (!(p_buffer[0] & DATA_INTEGRITY_MASK)) + { + return false; + } + + if (!(p_buffer[0] & RELIABLE_PKT_MASK)) + { + return false; + } + + if ((p_buffer[1] & 0x0Fu) != PKT_TYPE_VENDOR_SPECIFIC) + { + return false; + } + + const uint32_t expected_checksum = + ((p_buffer[0] + p_buffer[1] + p_buffer[2] + p_buffer[3])) & 0xFFu; + + if (expected_checksum != 0) + { + return false; + } + + const uint16_t crc_calculated = crc16_compute(p_buffer, (length - PKT_CRC_SIZE), NULL); + const uint16_t crc_received = uint16_decode(&p_buffer[length - PKT_CRC_SIZE]); + + if (crc_calculated != crc_received) + { + return false; + } + + return true; +} + + +/**@brief Function for getting the sequence number of the next reliable packet expected. + * + * @return sequence number of the next reliable packet expected. + */ +static __INLINE uint8_t packet_ack_get(void) +{ + return (uint8_t) m_packet_ack_number; +} + + +/**@brief Function for getting the sequence number of a reliable TX packet for which peer protocol + * entity acknowledgment is pending. + * + * @return sequence number of a reliable TX packet for which peer protocol entity acknowledgement + * is pending. + */ +static __INLINE uint8_t packet_seq_get(void) +{ + return m_packet_seq_number; +} + + +static __INLINE uint8_t packet_seq_nmbr_extract(const uint8_t * p_buffer) +{ + return (p_buffer[0] & 0x07u); +} + + +/**@brief Function for constructing 1st byte of the packet header of the packet to be transmitted. + * + * @return 1st byte of the packet header of the packet to be transmitted + */ +static __INLINE uint8_t tx_packet_byte_zero_construct(void) +{ + const uint32_t value = DATA_INTEGRITY_MASK | RELIABLE_PKT_MASK | + (packet_ack_get() << 3u) | packet_seq_get(); + + return (uint8_t) value; +} + + +/**@brief Function for calculating a packet header checksum. + * + * @param[in] p_hdr Pointer to the packet header. + * + * @return Calculated checksum. + */ +static __INLINE uint8_t header_checksum_calculate(const uint8_t * p_hdr) +{ + // @note: no pointer validation check needed as already checked by calling function. + uint32_t checksum; + + checksum = p_hdr[0]; + checksum += p_hdr[1]; + checksum += p_hdr[2]; + checksum &= 0xFFu; + checksum = (~checksum + 1u); + + return (uint8_t)checksum; +} + + +/**@brief Function for getting the expected ACK number. + * + * @return expected ACK number. + */ +static __INLINE uint8_t expected_ack_number_get(void) +{ + uint8_t seq_nmbr = packet_seq_get(); + + ++seq_nmbr; + seq_nmbr &= 0x07u; + + return seq_nmbr; +} + + +/**@brief Function for getting the expected ACK number. + * + * @return next expected ACK number. + */ + +static __INLINE uint8_t next_expected_ack_number_get(void) +{ + uint8_t seq_nmbr = expected_ack_number_get(); + + ++seq_nmbr; + seq_nmbr &= 0x07u; + + return seq_nmbr; +} + + +/**@brief Function for processing a received acknowledgement packet. + * + * Verifies does the received acknowledgement packet has the expected acknowledgement number and + * that the header checksum is correct. + * + * @param[in] p_buffer Pointer to the packet data. + * + * @return true if valid acknowledgement packet received. + */ + +static bool rx_ack_pkt_valid(const uint8_t * p_buffer) +{ + // @note: no pointer validation check needed as allready checked by calling function. + + // Verify header checksum. + const uint32_t expected_checksum = + ((p_buffer[0] + p_buffer[1] + p_buffer[2] + p_buffer[3])) & 0xFFu; + + if (expected_checksum != 0) + { + return false; + } + + const uint8_t ack_number = (p_buffer[0] >> 3u) & 0x07u; + + // Verify expected acknowledgment number. + return ( (ack_number == expected_ack_number_get()) || + (ack_number == next_expected_ack_number_get()) ); +} + + +/**@brief Function for decoding a packet type field. + * + * @param[in] p_buffer Pointer to the packet data. + * @param[in] length Length of packet data in bytes. + * + * @return Packet type field or INVALID_PKT_TYPE in case of decode error. + */ + +static uint32_t packet_type_decode(const uint8_t * p_buffer, uint32_t length) +{ + // @note: no pointer validation check needed as allready checked by calling function. + uint32_t return_value; + + if (length >= PKT_HDR_SIZE) + { + return_value = (p_buffer[1] & 0x0Fu); + } + else + { + return_value = INVALID_PKT_TYPE; + } + + return return_value; +} + +#ifdef HCI_LINK_CONTROL +/**@brief Function for decoding a link control packet. + * + * @param[in] p_buffer Pointer to the packet data. + * @param[in] length Length of packet data in bytes. + * + * @return Link Control Packet Type if decoding successful, HCI_LINK_CONTROL_PKT_INVALID otherwise. + */ +static uint16_t link_control_packet_decode(const uint8_t * p_buffer, uint32_t length) +{ + // @note: no pointer validation check needed as allready checked by calling function. + uint16_t packet_type = HCI_LINK_CONTROL_PKT_INVALID; + + // Executed link control packet filtering algorithm order: + // - verify packet overall length + // - verify data integrity bit cleared + // - verify reliable packet bit cleared + // - verify header checksum + // - verify payload: length and value + + if (length < HCI_PKT_SYNC_SIZE) + { + packet_type = HCI_LINK_CONTROL_PKT_INVALID; + } + + packet_type = p_buffer[PKT_HDR_SIZE] | (p_buffer[PKT_HDR_SIZE + 1] << 8u); + + if ((p_buffer[0] & DATA_INTEGRITY_MASK) || (p_buffer[0] & RELIABLE_PKT_MASK)) + { + packet_type = HCI_LINK_CONTROL_PKT_INVALID; + } + + const uint32_t expected_checksum = + ((p_buffer[0] + p_buffer[1] + p_buffer[2] + p_buffer[3])) & 0xFFu; + + if (expected_checksum != 0) + { + packet_type = HCI_LINK_CONTROL_PKT_INVALID; + } + + // This is a CONFIG or CONFIG_RSP packet + if ((packet_type == HCI_PKT_CONFIG) || (packet_type == HCI_PKT_CONFIG_RSP)) + { + if (length != HCI_PKT_CONFIG_SIZE) + { + packet_type = HCI_LINK_CONTROL_PKT_INVALID; + } + // Verify configuration field (0x11): + // - Sliding Window Size == 1, + // - OOF Flow Control == 0, + // - Data Integrity Check Type == 1, + // - Version Number == 0 + if (p_buffer[HCI_PKT_CONFIG_SIZE - 1] != HCI_CONFIG_FIELD) + { + packet_type = HCI_LINK_CONTROL_PKT_INVALID; + } + } + // This is a SYNC or SYNC_RSP packet + else if ((packet_type == HCI_PKT_SYNC) || (packet_type == HCI_PKT_SYNC_RSP)) + { + if (length != HCI_PKT_SYNC_SIZE) + { + packet_type = HCI_LINK_CONTROL_PKT_INVALID; + } + } + else + { + packet_type = HCI_LINK_CONTROL_PKT_INVALID; + } + + return packet_type; +} +#endif /* HCI_LINK_CONTROL */ + +/**@brief Function for writing an acknowledgment packet for transmission. + */ + +static void ack_transmit(void) +{ + uint32_t err_code; + // TX ACK packet format: + // - Unreliable Packet type + // - Payload Length set to 0 + // - Sequence Number set to 0 + // - Header checksum calculated + // - Acknowledge Number set correctly + m_tx_ack_packet[0] = (packet_ack_get() << 3u); + m_tx_ack_packet[1] = 0; + m_tx_ack_packet[2] = 0; + m_tx_ack_packet[3] = header_checksum_calculate(m_tx_ack_packet); + + ser_phy_hci_pkt_params_t pkt_header; + + pkt_header.p_buffer = m_tx_ack_packet; + pkt_header.num_of_bytes = PKT_HDR_SIZE; + DEBUG_EVT_SLIP_ACK_TX(0); + err_code = ser_phy_hci_slip_tx_pkt_send(&pkt_header, NULL, NULL); + ser_phy_hci_assert(err_code == NRF_SUCCESS); + + return; +} + + +static void ser_phy_event_callback(ser_phy_evt_t event) +{ + if (m_ser_phy_callback) + { + m_ser_phy_callback(event); + } + + return; +} + + +static void memory_request_callback(uint16_t size) +{ + ser_phy_evt_t event; + + DEBUG_EVT_HCI_PHY_EVT_BUF_REQUEST(0); + + event.evt_type = SER_PHY_EVT_RX_BUF_REQUEST; + event.evt_params.rx_buf_request.num_of_bytes = size; + ser_phy_event_callback(event); +} + + +static void packet_received_callback(uint8_t * pBuffer, uint16_t size) +{ + ser_phy_evt_t event; + + DEBUG_EVT_HCI_PHY_EVT_RX_PKT_RECEIVED(0); + + event.evt_type = SER_PHY_EVT_RX_PKT_RECEIVED; + event.evt_params.rx_pkt_received.num_of_bytes = size; + event.evt_params.rx_pkt_received.p_buffer = pBuffer; + ser_phy_event_callback(event); +} + + +static void packet_dropped_callback(void) +{ + ser_phy_evt_t event; + + DEBUG_EVT_HCI_PHY_EVT_RX_PKT_DROPPED(0); + + event.evt_type = SER_PHY_EVT_RX_PKT_DROPPED; + ser_phy_event_callback(event); +} + + +static void packet_transmitted_callback(void) +{ + ser_phy_evt_t event; + + DEBUG_EVT_HCI_PHY_EVT_TX_PKT_SENT(0); + + event.evt_type = SER_PHY_EVT_TX_PKT_SENT; + ser_phy_event_callback(event); +} + + +static void error_callback(void) +{ + ser_phy_evt_t event; + + DEBUG_EVT_HCI_PHY_EVT_TX_ERROR(0); + + event.evt_type = SER_PHY_EVT_HW_ERROR; + event.evt_params.hw_error.p_buffer = m_p_tx_payload; + ser_phy_event_callback(event); +} + + +static void hci_slip_event_handler(ser_phy_hci_slip_evt_t * p_event) +{ + hci_evt_t event; + uint32_t packet_type; + uint32_t err_code; + + if ( p_event->evt_type == SER_PHY_HCI_SLIP_EVT_PKT_SENT ) + { + NRF_LOG_DEBUG("EVT_PKT_SENT"); + + DEBUG_EVT_SLIP_PACKET_TXED(0); + event.evt_source = HCI_SLIP_EVT; + event.evt.ser_phy_slip_evt.evt_type = p_event->evt_type; +#ifndef HCI_LINK_CONTROL + hci_tx_event_handler(&event); +#else + if ((m_hci_mode == HCI_MODE_ACTIVE) && m_hci_other_side_active) + { + hci_tx_event_handler(&event); + } +#endif /*HCI_LINK_CONTROL*/ + } + else if ( p_event->evt_type == SER_PHY_HCI_SLIP_EVT_ACK_SENT ) + { + NRF_LOG_DEBUG("EVT_ACK_SENT"); + + DEBUG_EVT_SLIP_ACK_TXED(0); + event.evt_source = HCI_SLIP_EVT; + event.evt.ser_phy_slip_evt.evt_type = p_event->evt_type; +#ifndef HCI_LINK_CONTROL + hci_rx_event_handler(&event); +#else + if ((m_hci_mode == HCI_MODE_ACTIVE) && m_hci_other_side_active) + { + hci_rx_event_handler(&event); + } +#endif /* HCI_LINK_CONTROL */ + } + + else if ( p_event->evt_type == SER_PHY_HCI_SLIP_EVT_PKT_RECEIVED ) + { + event.evt_source = HCI_SLIP_EVT; + event.evt.ser_phy_slip_evt.evt_type = p_event->evt_type; + event.evt.ser_phy_slip_evt.evt_params.received_pkt.p_buffer = + p_event->evt_params.received_pkt.p_buffer; + event.evt.ser_phy_slip_evt.evt_params.received_pkt.num_of_bytes = + p_event->evt_params.received_pkt.num_of_bytes; + ser_phy_hci_assert(event.evt.ser_phy_slip_evt.evt_params.received_pkt.p_buffer != NULL); + ser_phy_hci_assert(event.evt.ser_phy_slip_evt.evt_params.received_pkt.num_of_bytes != 0); + packet_type = packet_type_decode( + event.evt.ser_phy_slip_evt.evt_params.received_pkt.p_buffer, + event.evt.ser_phy_slip_evt.evt_params.received_pkt.num_of_bytes); + + NRF_LOG_DEBUG("EVT_PKT_RECEIVED 0x%X/%u", packet_type, + p_event->evt_params.received_pkt.num_of_bytes); + + if (packet_type == PKT_TYPE_RESET) + { + NVIC_SystemReset(); + } + else if (packet_type == PKT_TYPE_ACK ) + { + DEBUG_EVT_SLIP_ACK_RXED(0); +#ifndef HCI_LINK_CONTROL + hci_tx_event_handler(&event); +#else + if ((m_hci_mode == HCI_MODE_ACTIVE) && m_hci_other_side_active) + { + hci_tx_event_handler(&event); + } + else + { + err_code = ser_phy_hci_slip_rx_buf_free( + event.evt.ser_phy_slip_evt.evt_params.received_pkt.p_buffer); + } +#endif /* HCI_LINK_CONTROL */ + } + else if ( packet_type == PKT_TYPE_VENDOR_SPECIFIC ) + { + if (is_rx_pkt_valid(event.evt.ser_phy_slip_evt.evt_params.received_pkt.p_buffer, + event.evt.ser_phy_slip_evt.evt_params.received_pkt.num_of_bytes)) + { + DEBUG_EVT_SLIP_PACKET_RXED(0); +#ifndef HCI_LINK_CONTROL + hci_rx_event_handler(&event); +#else + if ((m_hci_mode == HCI_MODE_ACTIVE) && m_hci_other_side_active) + { + hci_rx_event_handler(&event); + } + else + { + err_code = ser_phy_hci_slip_rx_buf_free( + event.evt.ser_phy_slip_evt.evt_params.received_pkt.p_buffer); + } +#endif /* HCI_LINK_CONTROL */ + } + else + { + err_code = ser_phy_hci_slip_rx_buf_free( + event.evt.ser_phy_slip_evt.evt_params.received_pkt.p_buffer); + ser_phy_hci_assert(err_code == NRF_SUCCESS); + /* throw assert when in debug mode*/ + DEBUG_EVT_SLIP_ERR_RXED(0); + } + } +#ifdef HCI_LINK_CONTROL + else if (packet_type == PKT_TYPE_LINK_CONTROL) + { + hci_link_control_event_handler(&event); + } +#endif /* HCI_LINK_CONTROL */ + else + { + err_code = ser_phy_hci_slip_rx_buf_free( + event.evt.ser_phy_slip_evt.evt_params.received_pkt.p_buffer); + ser_phy_hci_assert(err_code == NRF_SUCCESS); + /* throw assert when in debug mode*/ + DEBUG_EVT_SLIP_ERR_RXED(0); + } + } + else + { + NRF_LOG_DEBUG("EVT_HW_ERROR"); + } +} + + +static void hci_pkt_send(void) +{ + uint32_t err_code; + + m_tx_packet_header[0] = tx_packet_byte_zero_construct(); + uint16_t type_and_length_fields = ((m_tx_payload_length << 4u) | PKT_TYPE_VENDOR_SPECIFIC); + (void)uint16_encode(type_and_length_fields, &(m_tx_packet_header[1])); + m_tx_packet_header[3] = header_checksum_calculate(m_tx_packet_header); + uint16_t crc = crc16_compute(m_tx_packet_header, PKT_HDR_SIZE, NULL); + crc = crc16_compute(m_p_tx_payload, m_tx_payload_length, &crc); + (void)uint16_encode(crc, m_tx_packet_crc); + + ser_phy_hci_pkt_params_t pkt_header; + ser_phy_hci_pkt_params_t pkt_payload; + ser_phy_hci_pkt_params_t pkt_crc; + + pkt_header.p_buffer = m_tx_packet_header; + pkt_header.num_of_bytes = PKT_HDR_SIZE; + pkt_payload.p_buffer = m_p_tx_payload; + pkt_payload.num_of_bytes = m_tx_payload_length; + pkt_crc.p_buffer = m_tx_packet_crc; + pkt_crc.num_of_bytes = PKT_CRC_SIZE; + DEBUG_EVT_SLIP_PACKET_TX(0); + err_code = ser_phy_hci_slip_tx_pkt_send(&pkt_header, &pkt_payload, &pkt_crc); + ser_phy_hci_assert(err_code == NRF_SUCCESS); + + return; +} + +#ifdef HCI_LINK_CONTROL +static void hci_link_control_pkt_send(void) +{ + uint32_t err_code; + uint16_t link_control_payload_len = 0; + + m_tx_link_control_header[0] = 0x00u; // SEQ, ACK, DI and RP are set to 0 for link control + if (m_hci_link_control_next_pkt == HCI_PKT_SYNC) + { + link_control_payload_len = HCI_PKT_SYNC_SIZE - PKT_HDR_SIZE; + (void)uint16_encode(HCI_PKT_SYNC, m_tx_link_control_payload); + } + else if (m_hci_link_control_next_pkt == HCI_PKT_SYNC_RSP) + { + link_control_payload_len = HCI_PKT_SYNC_SIZE - PKT_HDR_SIZE; + (void)uint16_encode(HCI_PKT_SYNC_RSP, m_tx_link_control_payload); + } + else if (m_hci_link_control_next_pkt == HCI_PKT_CONFIG) + { + link_control_payload_len = HCI_PKT_CONFIG_SIZE - PKT_HDR_SIZE; + (void)uint16_encode(HCI_PKT_CONFIG, m_tx_link_control_payload); + m_tx_link_control_payload[2] = HCI_CONFIG_FIELD; + } + else if (m_hci_link_control_next_pkt == HCI_PKT_CONFIG_RSP) + { + link_control_payload_len = HCI_PKT_CONFIG_SIZE - PKT_HDR_SIZE; + (void)uint16_encode(HCI_PKT_CONFIG_RSP, m_tx_link_control_payload); + m_tx_link_control_payload[2] = HCI_CONFIG_FIELD; + } + uint16_t type_and_length_fields = ((link_control_payload_len << 4u) | PKT_TYPE_LINK_CONTROL); + (void)uint16_encode(type_and_length_fields, &(m_tx_link_control_header[1])); + m_tx_link_control_header[3] = header_checksum_calculate(m_tx_link_control_header); + + ser_phy_hci_pkt_params_t pkt_header; + ser_phy_hci_pkt_params_t pkt_payload; + ser_phy_hci_pkt_params_t pkt_crc; + + pkt_header.p_buffer = m_tx_link_control_header; + pkt_header.num_of_bytes = PKT_HDR_SIZE; + pkt_payload.p_buffer = m_tx_link_control_payload; + pkt_payload.num_of_bytes = link_control_payload_len; + pkt_crc.p_buffer = NULL; + pkt_crc.num_of_bytes = 0; + DEBUG_EVT_SLIP_PACKET_TX(0); + err_code = ser_phy_hci_slip_tx_pkt_send(&pkt_header, &pkt_payload, &pkt_crc); + ser_phy_hci_assert(err_code == NRF_SUCCESS); + + return; +} +#endif /* HCI_LINK_CONTROL */ + +static void hci_pkt_sent_upcall(void) +{ + m_packet_seq_number++; // incoming ACK is valid, increment SEQ + m_packet_seq_number &= 0x07u; + m_p_tx_payload = NULL; + packet_transmitted_callback(); + + return; +} + + +static void hci_release_ack_buffer(hci_evt_t * p_event) +{ + uint32_t err_code; + + err_code = ser_phy_hci_slip_rx_buf_free( + p_event->evt.ser_phy_slip_evt.evt_params.received_pkt.p_buffer); + ser_phy_hci_assert(err_code == NRF_SUCCESS); + + return; +} + + +static void hci_process_orphaned_ack(hci_evt_t * p_event) +{ + hci_release_ack_buffer(p_event); + return; +} + +/* main tx fsm */ +static void hci_tx_fsm_event_process(hci_evt_t * p_event) +{ + + switch (m_hci_tx_fsm_state) + { + case HCI_TX_STATE_SEND: + + if ((p_event->evt_source == HCI_SER_PHY_EVT) && + (p_event->evt.ser_phy_evt.evt_type == HCI_SER_PHY_TX_REQUEST)) + { + hci_pkt_send(); + hci_timeout_setup(0); + m_tx_retry_count = MAX_RETRY_COUNT; + m_hci_tx_fsm_state = HCI_TX_STATE_WAIT_FOR_FIRST_TX_END; + } + else if ((p_event->evt_source == HCI_SLIP_EVT) && + (p_event->evt.ser_phy_slip_evt.evt_type == SER_PHY_HCI_SLIP_EVT_PKT_RECEIVED)) + { + hci_process_orphaned_ack(p_event); + } + + break; + + case HCI_TX_STATE_WAIT_FOR_FIRST_TX_END: + + if ((p_event->evt_source == HCI_SLIP_EVT) && + (p_event->evt.ser_phy_slip_evt.evt_type == SER_PHY_HCI_SLIP_EVT_PKT_SENT)) + { + hci_timeout_setup(1); + m_hci_tx_fsm_state = HCI_TX_STATE_WAIT_FOR_ACK; + } + else if ((p_event->evt_source == HCI_SLIP_EVT) && + (p_event->evt.ser_phy_slip_evt.evt_type == SER_PHY_HCI_SLIP_EVT_PKT_RECEIVED)) + { + hci_process_orphaned_ack(p_event); + } + break; + + case HCI_TX_STATE_WAIT_FOR_ACK_OR_TX_END: + + if ((p_event->evt_source == HCI_SLIP_EVT) && + (p_event->evt.ser_phy_slip_evt.evt_type == SER_PHY_HCI_SLIP_EVT_PKT_SENT)) + { + hci_timeout_setup(1); + m_hci_tx_fsm_state = HCI_TX_STATE_WAIT_FOR_ACK; + } + else if ((p_event->evt_source == HCI_SLIP_EVT) && + (p_event->evt.ser_phy_slip_evt.evt_type == SER_PHY_HCI_SLIP_EVT_PKT_RECEIVED)) + { + if (rx_ack_pkt_valid(p_event->evt.ser_phy_slip_evt.evt_params.received_pkt.p_buffer)) + { + hci_timeout_setup(0); + m_hci_tx_fsm_state = HCI_TX_STATE_WAIT_FOR_TX_END; + } + hci_release_ack_buffer(p_event); + } + break; + + case HCI_TX_STATE_WAIT_FOR_ACK: + + if ((p_event->evt_source == HCI_SLIP_EVT) && + (p_event->evt.ser_phy_slip_evt.evt_type == SER_PHY_HCI_SLIP_EVT_PKT_RECEIVED)) + { + if (rx_ack_pkt_valid(p_event->evt.ser_phy_slip_evt.evt_params.received_pkt.p_buffer)) + { + hci_timeout_setup(0); + hci_pkt_sent_upcall(); + m_hci_tx_fsm_state = HCI_TX_STATE_SEND; + } + hci_release_ack_buffer(p_event); + } + else if (p_event->evt_source == HCI_TIMER_EVT) + { + m_tx_retry_count--; + // m_tx_retx_counter++; // global retransmissions counter + if (m_tx_retry_count) + { + hci_pkt_send(); + DEBUG_HCI_RETX(0); + m_hci_tx_fsm_state = HCI_TX_STATE_WAIT_FOR_ACK_OR_TX_END; + } + else + { + error_callback(); + m_hci_tx_fsm_state = HCI_TX_STATE_SEND; + } + } + break; + + case HCI_TX_STATE_WAIT_FOR_TX_END: + + if ((p_event->evt_source == HCI_SLIP_EVT) && + (p_event->evt.ser_phy_slip_evt.evt_type == SER_PHY_HCI_SLIP_EVT_PKT_SENT)) + { + hci_pkt_sent_upcall(); + m_hci_tx_fsm_state = HCI_TX_STATE_SEND; + } + else if ((p_event->evt_source == HCI_SLIP_EVT) && + (p_event->evt.ser_phy_slip_evt.evt_type == SER_PHY_HCI_SLIP_EVT_PKT_RECEIVED)) + { + hci_process_orphaned_ack(p_event); + } + + break; + +#ifdef HCI_LINK_CONTROL + case HCI_TX_STATE_DISABLE: + /* This case should not happen if HCI is in ACTIVE mode */ + if (m_hci_mode == HCI_MODE_ACTIVE) + { + ser_phy_hci_assert(false); + } + break; +#endif /* HCI_LINK_CONTROL */ + + default: + ser_phy_hci_assert(false); + break; + } +} + + +static void hci_mem_request(hci_evt_t * p_event) +{ + m_buffer_reqested_flag = true; + m_p_rx_packet = p_event->evt.ser_phy_slip_evt.evt_params.received_pkt.p_buffer; + m_rx_packet_length = p_event->evt.ser_phy_slip_evt.evt_params.received_pkt.num_of_bytes; + ser_phy_hci_assert(m_rx_packet_length > PKT_HDR_SIZE + PKT_CRC_SIZE); + memory_request_callback(m_rx_packet_length - PKT_HDR_SIZE - PKT_CRC_SIZE); + return; +} + + +static void hci_inc_ack() +{ + m_packet_ack_number++; + m_packet_ack_number &= 0x07u; +} + + +static void hci_rx_fsm_event_process(hci_evt_t * p_event) +{ + switch (m_hci_rx_fsm_state) + { + case HCI_RX_STATE_RECEIVE: + + if ((p_event->evt_source == HCI_SLIP_EVT) && + (p_event->evt.ser_phy_slip_evt.evt_type == SER_PHY_HCI_SLIP_EVT_PKT_RECEIVED)) + { + /* type and crc and check sum are validated by slip handler */ + uint8_t rx_seq_number = packet_seq_nmbr_extract( + p_event->evt.ser_phy_slip_evt.evt_params.received_pkt.p_buffer); + + if (packet_ack_get() == rx_seq_number) + { + hci_mem_request(p_event); + m_hci_rx_fsm_state = HCI_RX_STATE_WAIT_FOR_MEM; + } + else + { + // m_rx_drop_counter++; + m_hci_rx_fsm_state = HCI_RX_STATE_WAIT_FOR_SLIP_NACK_END; + (void) ser_phy_hci_slip_rx_buf_free(m_p_rx_packet); // and drop a packet + ack_transmit(); // send NACK with valid ACK + } + } + break; + + case HCI_RX_STATE_WAIT_FOR_MEM: + + if ((p_event->evt_source == HCI_SER_PHY_EVT) && + (p_event->evt.ser_phy_evt.evt_type == HCI_SER_PHY_RX_BUF_GRANTED)) + { + if (m_p_rx_buffer) + { + memcpy(m_p_rx_buffer, + m_p_rx_packet + PKT_HDR_SIZE, + m_rx_packet_length - PKT_HDR_SIZE - PKT_CRC_SIZE); + (void) ser_phy_hci_slip_rx_buf_free(m_p_rx_packet); + } + m_hci_rx_fsm_state = HCI_RX_STATE_WAIT_FOR_SLIP_ACK_END; + hci_inc_ack(); // SEQ was valid for good packet, we will send incremented SEQ as ACK + ack_transmit(); + } + + break; + + case HCI_RX_STATE_WAIT_FOR_SLIP_ACK_END: + + if ((p_event->evt_source == HCI_SLIP_EVT) && + (p_event->evt.ser_phy_slip_evt.evt_type == SER_PHY_HCI_SLIP_EVT_ACK_SENT)) + { + + if (m_p_rx_buffer) + { + packet_received_callback(m_p_rx_buffer, + m_rx_packet_length - PKT_HDR_SIZE - PKT_CRC_SIZE); + } + else + { + packet_dropped_callback(); + } + m_hci_rx_fsm_state = HCI_RX_STATE_RECEIVE; + } + else if ((p_event->evt_source == HCI_SLIP_EVT) && + (p_event->evt.ser_phy_slip_evt.evt_type == SER_PHY_HCI_SLIP_EVT_PKT_RECEIVED)) + { + (void) ser_phy_hci_slip_rx_buf_free(p_event->evt.ser_phy_slip_evt.evt_params.received_pkt.p_buffer); + } + break; + + case HCI_RX_STATE_WAIT_FOR_SLIP_NACK_END: + if ((p_event->evt_source == HCI_SLIP_EVT) && + (p_event->evt.ser_phy_slip_evt.evt_type == SER_PHY_HCI_SLIP_EVT_ACK_SENT)) + { + m_hci_rx_fsm_state = HCI_RX_STATE_RECEIVE; + } + else + { + (void) ser_phy_hci_slip_rx_buf_free(p_event->evt.ser_phy_slip_evt.evt_params.received_pkt.p_buffer); + } + break; + + +#ifdef HCI_LINK_CONTROL + case HCI_RX_STATE_DISABLE: + if (m_hci_mode == HCI_MODE_ACTIVE) + { + ser_phy_hci_assert(false); + } + break; +#endif /* HCI_LINK_CONTROL */ + + default: + ser_phy_hci_assert(false); + break; + } +} + + +/* this function might be entered only via hci_tx_event_handler */ +static void hci_tx_fsm(void) +{ + hci_evt_t event; + uint32_t err_code = NRF_SUCCESS; + + while (err_code == NRF_SUCCESS) + { + + CRITICAL_REGION_ENTER(); + err_code = nrf_queue_pop(&m_tx_evt_queue, &event); + + if (err_code != NRF_SUCCESS) + { + m_tx_fsm_idle_flag = true; + } + CRITICAL_REGION_EXIT(); + + if (err_code == NRF_SUCCESS) + { + hci_tx_fsm_event_process(&event); /* this is the only entry to the TX_FSM */ + } + } + return; +} + + +/* this function might be entered only via hci_rx_event_handler */ +static void hci_rx_fsm(void) +{ + hci_evt_t event; + uint32_t err_code = NRF_SUCCESS; + + while (err_code == NRF_SUCCESS) + { + CRITICAL_REGION_ENTER(); + err_code = nrf_queue_pop(&m_rx_evt_queue, &event); + + if (err_code != NRF_SUCCESS) + { + m_rx_fsm_idle_flag = true; + } + CRITICAL_REGION_EXIT(); + + if (err_code == NRF_SUCCESS) + { + hci_rx_fsm_event_process(&event); /* this is the only entry to the RX_FSM */ + } + } + return; +} + + +/* something might have been queued by API with disabled 'PHY-interrupts' */ +static void hci_tx_reschedule() +{ + bool tx_exec_flag = false; + uint32_t tx_queue_length; + + CRITICAL_REGION_ENTER(); + tx_queue_length = nrf_queue_utilization_get(&m_tx_evt_queue); + +#ifndef HCI_LINK_CONTROL + if (m_tx_fsm_idle_flag && m_hci_global_enable_flag && tx_queue_length) +#else + if (m_tx_fsm_idle_flag && m_hci_global_enable_flag && tx_queue_length && (m_hci_mode == HCI_MODE_ACTIVE)) +#endif /* HCI_LINK_CONTROL */ + { + tx_exec_flag = true; // FSM should be activated + m_tx_fsm_idle_flag = false; // FSM will be busy from now on till the queue is exhausted + } + CRITICAL_REGION_EXIT(); + + if (tx_exec_flag) + { + hci_tx_fsm(); + } + return; +} + + +/* entry to TX state machine, might be called asynchronously from different contexts */ +/* Puts event into the TX event queue and execute if FSM was idle */ +static void hci_tx_event_handler(hci_evt_t * p_event) +{ + bool tx_exec_flag = false; + uint32_t err_code; + + CRITICAL_REGION_ENTER(); + err_code = nrf_queue_push(&m_tx_evt_queue, p_event); + ser_phy_hci_assert(err_code == NRF_SUCCESS); + + // CRITICAL_REGION_ENTER(); + /* only one process can acquire tx_exec_flag */ + if (m_tx_fsm_idle_flag && m_hci_global_enable_flag) + { + tx_exec_flag = true; // FSM should be activated + m_tx_fsm_idle_flag = false; // FSM will be busy from now on till the queue is exhausted + } + CRITICAL_REGION_EXIT(); + + if (tx_exec_flag) + { + hci_tx_fsm(); + } + return; +} + + +/* Something might have been queued by API with disabled 'PHY-interrupts' */ +static void hci_rx_reschedule() +{ + bool rx_exec_flag = false; + uint32_t rx_queue_length; + + CRITICAL_REGION_ENTER(); + rx_queue_length = nrf_queue_utilization_get(&m_rx_evt_queue); + +#ifndef HCI_LINK_CONTROL + if (m_rx_fsm_idle_flag && m_hci_global_enable_flag && rx_queue_length) +#else + if (m_rx_fsm_idle_flag && m_hci_global_enable_flag && rx_queue_length && (m_hci_mode == HCI_MODE_ACTIVE)) +#endif /* HCI_LINK_CONTROL */ + { + rx_exec_flag = true; // FSM should be activated + m_rx_fsm_idle_flag = false; // FSM will be busy from now on till the queue is exhausted + } + CRITICAL_REGION_EXIT(); + + if (rx_exec_flag) + { + hci_rx_fsm(); + } + +} + + +/* Entry to RX state machine, might be called asynchronously from different contexts */ +/* Puts event into the RX event queue and execute if FSM was idle */ +static void hci_rx_event_handler(hci_evt_t * p_event) +{ + bool rx_exec_flag = false; + uint32_t err_code; + + CRITICAL_REGION_ENTER(); + err_code = nrf_queue_push(&m_rx_evt_queue, p_event); + ser_phy_hci_assert(err_code == NRF_SUCCESS); + + /* only one process can acquire rx_exec_flag */ + // CRITICAL_REGION_ENTER(); + if (m_rx_fsm_idle_flag && m_hci_global_enable_flag) + { + rx_exec_flag = true; // FSM should be activated + m_rx_fsm_idle_flag = false; // FSM will be busy from now on till the queue is exhausted + } + CRITICAL_REGION_EXIT(); + + if (rx_exec_flag) + { + hci_rx_fsm(); + } + + return; +} + +#ifdef HCI_LINK_CONTROL +/* Link control event handler - used only for Link Control packets */ +/* This handler will be called only in 2 cases: + - when SER_PHY_HCI_SLIP_EVT_PKT_RECEIVED event is received + - when HCI_TIMER_EVT event is reveived */ +static void hci_link_control_event_handler(hci_evt_t * p_event) +{ + uint16_t pkt_type = HCI_LINK_CONTROL_PKT_INVALID; + + switch (p_event->evt_source) + { + case HCI_SLIP_EVT: + pkt_type = link_control_packet_decode( + p_event->evt.ser_phy_slip_evt.evt_params.received_pkt.p_buffer, + p_event->evt.ser_phy_slip_evt.evt_params.received_pkt.num_of_bytes); + /* Perform HCI mode transition if needed */ + CRITICAL_REGION_ENTER(); + switch (pkt_type) + { + case HCI_PKT_SYNC: + m_hci_link_control_next_pkt = HCI_PKT_SYNC_RSP; + /* Restart HCI communication if it was in ACTIVE mode */ + if (m_hci_mode == HCI_MODE_ACTIVE) + { + m_hci_mode = HCI_MODE_UNINITIALIZED; + m_packet_ack_number = INITIAL_ACK_NUMBER_EXPECTED; + m_packet_seq_number = INITIAL_SEQ_NUMBER; + m_hci_tx_fsm_state = HCI_TX_STATE_DISABLE; + m_hci_rx_fsm_state = HCI_RX_STATE_DISABLE; + m_hci_other_side_active = false; + } + hci_link_control_pkt_send(); + hci_timeout_setup(HCI_LINK_CONTROL_TIMEOUT); // Need to trigger transmitting SYNC messages + break; + case HCI_PKT_SYNC_RSP: + if (m_hci_mode == HCI_MODE_UNINITIALIZED) + { + m_hci_mode = HCI_MODE_INITIALIZED; + m_hci_link_control_next_pkt = HCI_PKT_CONFIG; + } + break; + case HCI_PKT_CONFIG: + if (m_hci_mode != HCI_MODE_UNINITIALIZED) + { + m_hci_link_control_next_pkt = HCI_PKT_CONFIG_RSP; + hci_link_control_pkt_send(); + m_hci_other_side_active = true; + } + break; + case HCI_PKT_CONFIG_RSP: + if (m_hci_mode == HCI_MODE_INITIALIZED) + { + m_hci_mode = HCI_MODE_ACTIVE; + m_hci_tx_fsm_state = HCI_TX_STATE_SEND; + m_hci_rx_fsm_state = HCI_RX_STATE_RECEIVE; + } + break; + } + CRITICAL_REGION_EXIT(); + (void) ser_phy_hci_slip_rx_buf_free( + p_event->evt.ser_phy_slip_evt.evt_params.received_pkt.p_buffer); + /* Kick the state machine so it can start process BLE packets */ + if ((m_hci_mode == HCI_MODE_ACTIVE) && m_hci_other_side_active) + { + hci_tx_reschedule(); + hci_rx_reschedule(); + } + break; + + case HCI_TIMER_EVT: + /* Send one of the Link Control packets if in Unintialized or Initialized state */ + CRITICAL_REGION_ENTER(); + switch (m_hci_mode) + { + case HCI_MODE_UNINITIALIZED: + //send packet + m_hci_link_control_next_pkt = HCI_PKT_SYNC; + hci_link_control_pkt_send(); + hci_timeout_setup(HCI_LINK_CONTROL_TIMEOUT); + break; + case HCI_MODE_INITIALIZED: + m_hci_link_control_next_pkt = HCI_PKT_CONFIG; + hci_link_control_pkt_send(); + hci_timeout_setup(HCI_LINK_CONTROL_TIMEOUT); + break; + case HCI_MODE_ACTIVE: + case HCI_MODE_DISABLE: + default: + // No implementation needed + break; + } + CRITICAL_REGION_EXIT(); + break; + case HCI_SER_PHY_EVT: + default: + // No implementation needed + break; + } +} +#endif /* HCI_LINK_CONTROL */ + +/* ser_phy API function */ +void ser_phy_interrupts_enable(void) +{ + bool pending_timer_callback_flag = false; + + CRITICAL_REGION_ENTER(); + m_hci_timer_enabled_flag = true; + + if (m_hci_timout_pending_flag) + { + m_hci_timout_pending_flag = false; + pending_timer_callback_flag = true; + } + CRITICAL_REGION_EXIT(); + // this is a workaround - scheduled SER_PHY EVENTS + m_hci_global_enable_flag = true; + hci_tx_reschedule(); + hci_rx_reschedule(); + + if (pending_timer_callback_flag) + { + hci_signal_timeout_event(); + } + + return; +} + + +/* ser_phy API function */ +void ser_phy_interrupts_disable(void) +{ + CRITICAL_REGION_ENTER(); + m_hci_timer_enabled_flag = false; + // transport calls PHY API with ser_phy_interrupts_disabled + m_hci_global_enable_flag = false; + CRITICAL_REGION_EXIT(); +} + + +/* ser_phy API function */ +uint32_t ser_phy_rx_buf_set(uint8_t * p_buffer) +{ + uint32_t status = NRF_SUCCESS; + hci_evt_t event; + + if (m_buffer_reqested_flag) + { + m_buffer_reqested_flag = false; + m_p_rx_buffer = p_buffer; + event.evt_source = HCI_SER_PHY_EVT; + event.evt.ser_phy_evt.evt_type = HCI_SER_PHY_RX_BUF_GRANTED; + hci_rx_event_handler(&event); + } + else + { + status = NRF_ERROR_BUSY; + } + return status; +} + + +/* ser_phy API function */ +uint32_t ser_phy_tx_pkt_send(const uint8_t * p_buffer, uint16_t num_of_bytes) +{ + uint32_t status = NRF_SUCCESS; + hci_evt_t event; + + if ( p_buffer == NULL || num_of_bytes == 0) + { + return NRF_ERROR_NULL; + } + + if ( m_p_tx_payload == NULL) + { + m_tx_payload_length = num_of_bytes; + m_p_tx_payload = (uint8_t *)p_buffer; + DEBUG_EVT_TX_REQ(0); + event.evt_source = HCI_SER_PHY_EVT; + event.evt.ser_phy_evt.evt_type = HCI_SER_PHY_TX_REQUEST; + hci_tx_event_handler(&event); + } + else + { + status = NRF_ERROR_BUSY; + } + + return status; +} + + +static uint32_t hci_timer_init(void) +{ + uint32_t err_code = NRF_SUCCESS; + +#ifdef HCI_APP_TIMER + + err_code = app_timer_create(&m_app_timer_id, APP_TIMER_MODE_REPEATED, hci_timeout_handler); + + if (err_code != NRF_SUCCESS) + { + return NRF_ERROR_INTERNAL; + } + + err_code = app_timer_start(m_app_timer_id, RETRANSMISSION_TIMEOUT_IN_TICKS, NULL); + + if (err_code != NRF_SUCCESS) + { + return NRF_ERROR_INTERNAL; + } + +#else + + // Configure TIMER for compare[1] event + HCI_TIMER->PRESCALER = 9; + HCI_TIMER->MODE = TIMER_MODE_MODE_Timer; + HCI_TIMER->BITMODE = TIMER_BITMODE_BITMODE_16Bit; + + // Clear TIMER + HCI_TIMER->TASKS_CLEAR = 1; + + // Enable interrupt + HCI_TIMER->INTENCLR = 0xFFFFFFFF; + HCI_TIMER->INTENSET = TIMER_INTENSET_COMPARE1_Enabled << TIMER_INTENSET_COMPARE1_Pos; + + NVIC_ClearPendingIRQ(HCI_TIMER_IRQn); + NVIC_SetPriority(HCI_TIMER_IRQn, APP_IRQ_PRIORITY_HIGH); + NVIC_EnableIRQ(HCI_TIMER_IRQn); + +#endif + + return err_code; + +} + + +/* ser_phy API function */ +uint32_t ser_phy_open(ser_phy_events_handler_t events_handler) +{ + uint32_t err_code; + + if ((m_hci_tx_fsm_state != HCI_TX_STATE_DISABLE) || (m_hci_rx_fsm_state != HCI_RX_STATE_DISABLE)) + { + return NRF_ERROR_INVALID_STATE; + } + + if (events_handler == NULL) + { + return NRF_ERROR_NULL; + } + + err_code = hci_timer_init(); + + if (err_code != NRF_SUCCESS) + { + return NRF_ERROR_INTERNAL; + } + + nrf_queue_reset(&m_tx_evt_queue); + nrf_queue_reset(&m_rx_evt_queue); + + err_code = ser_phy_hci_slip_open(hci_slip_event_handler); + + if (err_code != NRF_SUCCESS) + { + return err_code; + } + + if (err_code == NRF_SUCCESS) + { + m_packet_ack_number = INITIAL_ACK_NUMBER_EXPECTED; + m_packet_seq_number = INITIAL_SEQ_NUMBER; + m_ser_phy_callback = events_handler; + +#ifndef HCI_LINK_CONTROL + m_hci_tx_fsm_state = HCI_TX_STATE_SEND; + m_hci_rx_fsm_state = HCI_RX_STATE_RECEIVE; +#else + hci_timeout_setup(HCI_LINK_CONTROL_TIMEOUT);// Trigger sending SYNC messages + m_hci_mode = HCI_MODE_UNINITIALIZED; + m_hci_other_side_active = false; +#endif /*HCI_LINK_CONTROL*/ + } + return err_code; +} + +static uint32_t hci_timer_close(void) +{ + uint32_t err_code = NRF_SUCCESS; + +#ifdef HCI_APP_TIMER + err_code = app_timer_stop(m_app_timer_id); + + if (err_code != NRF_SUCCESS) + { + return NRF_ERROR_INTERNAL; + } +#endif + + return err_code; +} + +/* ser_phy API function */ +void ser_phy_close(void) +{ + m_ser_phy_callback = NULL; + ser_phy_hci_slip_close(); + m_hci_tx_fsm_state = HCI_TX_STATE_DISABLE; + m_hci_rx_fsm_state = HCI_RX_STATE_DISABLE; + +#ifdef HCI_LINK_CONTROL + m_hci_mode = HCI_MODE_DISABLE; +#endif /* HCI_LINK_CONTROL */ + + uint32_t err_code = hci_timer_close(); + ser_phy_hci_assert(err_code == NRF_SUCCESS); +} + + diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_hci.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_hci.h new file mode 100644 index 0000000..c2993fd --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_hci.h @@ -0,0 +1,183 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +/** @file + * + * @defgroup ser_phy_hci HCI Serialization PHY + * @{ + * @ingroup ble_sdk_lib_serialization + * + * @brief HCI PHY layer for serialization. + * + * @details This file contains declarations of functions and definitions of data structures and + * identifiers (typedef enum) used as API of the serialization HCI PHY layer. + * + * + */ + +#ifndef SER_PHY_HCI_H__ +#define SER_PHY_HCI_H__ + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/**@brief Serialization PHY HCI module events types. */ +typedef enum +{ + SER_PHY_HCI_SLIP_EVT_PKT_SENT = 0, /**< An event indicating that packet has been transmitted. */ + SER_PHY_HCI_SLIP_EVT_ACK_SENT, /**< An event indicating that ack packet has been transmitted. */ + SER_PHY_HCI_SLIP_EVT_PKT_RECEIVED, /**< An event indicating that packet has been received. */ + SER_PHY_HCI_SLIP_EVT_HW_ERROR, /**< An event indicating a hardware error in PHY HCI module. */ + SER_PHY_HCI_SLIP_EVT_TYPE_MAX /**< Enumeration upper bound. */ +} ser_phy_hci_slip_evt_type_t; + +/**@brief Struct representing a PHY HCI packet. */ +typedef struct +{ + uint8_t * p_buffer; /**< Pointer to a buffer containing a packet. */ + uint16_t num_of_bytes; /**< Length of a packet in octets. */ +} ser_phy_hci_pkt_params_t; + + +/**@brief Struct containing parameters of event of type @ref SER_PHY_HCI_SLIP_EVT_HW_ERROR. */ +typedef struct +{ + uint32_t error_code; /**< Hardware error code - specific for a microcontroller. */ +} ser_phy_hci_evt_hw_error_params_t; + + +/**@brief Struct containing events from the Serialization PHY module. + * + * @note Some events do not have parameters, then the whole information is contained in the evt_type. + */ +typedef struct +{ + ser_phy_hci_slip_evt_type_t evt_type; /**< Type of an event. */ + union /**< Union alternative identified by evt_type in the enclosing struct. */ + { + /** Parameters of event of type @ref SER_PHY_HCI_SLIP_EVT_PKT_RECEIVED. */ + ser_phy_hci_pkt_params_t received_pkt; + /** Parameters of event of type @ref SER_PHY_HCI_SLIP_EVT_HW_ERROR. */ + ser_phy_hci_evt_hw_error_params_t hw_error; + } evt_params; +} ser_phy_hci_slip_evt_t; + + +/**@brief Type of generic callback function handler to be used by all PHY HCI events. + * + * @param[in] event Serialization PHY HCI module event. + */ +typedef void (*ser_phy_hci_slip_event_handler_t)(ser_phy_hci_slip_evt_t *p_event); + +/**@brief Function for opening and initializing a HCI SLIP PHY module. + * + * @note The function initializes hardware and internal module states and registers callback + * function to be used by all PHY HCI module events. + * + * @warning If the function has been already called, the function @ref ser_phy_hci_slip_close has to be + * called before ser_phy_hci_slip_open can be called again. + * + * @param[in] events_handler Generic callback function handler to be used by all PHY HCI module + * events. + * + * @retval NRF_SUCCESS Operation success. + * @retval NRF_ERROR_INVALID_STATE Operation failure. The function has been already called. + * To call it again, the function @ref ser_phy_hci_slip_close has to + * be called first. + * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_PARAM Operation failure. Hardware initialization parameters are not + * supported. + */ +uint32_t ser_phy_hci_slip_open(ser_phy_hci_slip_event_handler_t events_handler); + + +/**@brief A function for transmitting a HCI SLIP packet. + * + * @note The function adds a packet pointed by p_buffer parameter to a transmission queue and + * schedules generation of an event of type @ref SER_PHY_HCI_SLIP_EVT_PKT_SENT upon transmission + * completion. + * + * @param[in] p_header Pointer to ser_phy_hci_pkt_params_t structure representing packet header. + * @param[in] p_payload Pointer to ser_phy_hci_pkt_params_t structure representing packet payload. + * @param[in] p_crc Pointer to ser_phy_hci_pkt_params_t structure representing packet crc. + * + * @retval NRF_SUCCESS Operation success. Packet was added to the transmission queue + * and event will be sent upon transmission completion. + * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied in p_header parameter. + * NULL pointer is allowed for p_payload and p_crc parameters. + * @retval NRF_ERROR_INVALID_PARAM Operation failure. Number of bytes to be sent equals 0. + * @retval NRF_ERROR_BUSY Operation failure. Transmitting of a packet in progress. + */ +uint32_t ser_phy_hci_slip_tx_pkt_send(const ser_phy_hci_pkt_params_t * p_header, + const ser_phy_hci_pkt_params_t * p_payload, + const ser_phy_hci_pkt_params_t * p_crc); + + +/**@brief A function for freeing an RX buffer. + * + * @note The function has to be called as a response to event @ref SER_PHY_HCI_SLIP_EVT_PKT_RECEIVED + * when an RX packet has been processed. The function frees the RX buffer and therefore enables + * reception of next incoming data. + + * @param[in] p_buffer Pointer to an RX buffer which must be freed. + * + * @retval NRF_SUCCESS Operation success. + * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied. + * @retval NRF_ERROR_INVALID_STATE Operation failure. A buffer was already free. + */ +uint32_t ser_phy_hci_slip_rx_buf_free(uint8_t * p_buffer); + + +/**@brief A function for closing a PHY HCI module. + * + * @note The function disables hardware, resets internal module states, and unregisters the events + * callback function. + */ +void ser_phy_hci_slip_close(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* SER_PHY_HCI_H__ */ +/** @} */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_hci_slip.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_hci_slip.c new file mode 100644 index 0000000..4139bae --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_hci_slip.c @@ -0,0 +1,689 @@ +/** + * 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 "ser_phy_hci.h" +#include "ser_config.h" +#ifdef SER_CONNECTIVITY +#include "ser_phy_config_conn.h" +#else +#include "ser_phy_config_app.h" +#endif +#include "nrf_drv_uart.h" +#include "app_error.h" +#include "app_util_platform.h" + +#define APP_SLIP_END 0xC0 /**< SLIP code for identifying the beginning and end of a packet frame.. */ +#define APP_SLIP_ESC 0xDB /**< SLIP escape code. This code is used to specify that the following character is specially encoded. */ +#define APP_SLIP_ESC_END 0xDC /**< SLIP special code. When this code follows 0xDB, this character is interpreted as payload data 0xC0.. */ +#define APP_SLIP_ESC_ESC 0xDD /**< SLIP special code. When this code follows 0xDB, this character is interpreted as payload data 0xDB. */ + +#define HDR_SIZE 4 +#define CRC_SIZE 2 +#define PKT_SIZE (SER_HAL_TRANSPORT_MAX_PKT_SIZE + HDR_SIZE + CRC_SIZE) + +static const nrf_drv_uart_t m_uart = NRF_DRV_UART_INSTANCE(0); +static const nrf_drv_uart_config_t m_uart_config = { + .pseltxd = SER_PHY_UART_TX, + .pselrxd = SER_PHY_UART_RX, + .pselrts = SER_PHY_UART_RTS, + .pselcts = SER_PHY_UART_CTS, + .p_context = NULL, + .interrupt_priority = UART_IRQ_PRIORITY, +#if defined(UARTE_PRESENT) && defined(UART_PRESENT) + .use_easy_dma = true, +#endif + // These values are common for application and connectivity, they are + // defined in "ser_config.h". + .hwfc = SER_PHY_UART_FLOW_CTRL, + .parity = SER_PHY_UART_PARITY, + .baudrate = (nrf_uart_baudrate_t)SER_PHY_UART_BAUDRATE +}; + +typedef struct { + ser_phy_hci_pkt_params_t header; + ser_phy_hci_pkt_params_t payload; + ser_phy_hci_pkt_params_t crc; +} ser_phy_hci_slip_pkt_t; +static ser_phy_hci_slip_pkt_t m_tx_curr_packet; +static ser_phy_hci_slip_pkt_t m_tx_next_packet; + +static ser_phy_hci_slip_evt_t m_ser_phy_hci_slip_event; +static ser_phy_hci_slip_event_handler_t m_ser_phy_hci_slip_event_handler; /**< Event handler for upper layer */ + +static uint8_t m_tx_buf0[SER_PHY_HCI_SLIP_TX_BUF_SIZE]; +static uint8_t m_tx_buf1[SER_PHY_HCI_SLIP_TX_BUF_SIZE]; +static uint8_t * mp_tx_buf; +static uint8_t m_tx_bytes; +static enum { + PHASE_BEGIN, + PHASE_HEADER, + PHASE_PAYLOAD, + PHASE_CRC, + PHASE_ACK_END, + // The following three elements have to have consecutive values, + // 'tx_buf_fill()' relies on this. + PHASE_PACKET_END, + PHASE_PRE_IDLE = PHASE_PACKET_END + 1, + PHASE_IDLE = PHASE_PRE_IDLE + 1 +} volatile m_tx_phase; +static bool volatile m_tx_in_progress; +static bool volatile m_tx_pending; + +#define NO_EVENT SER_PHY_HCI_SLIP_EVT_TYPE_MAX +static ser_phy_hci_slip_evt_type_t m_tx_evt_type; +static ser_phy_hci_slip_evt_type_t m_tx_pending_evt_type; + +static uint8_t m_small_buffer[HDR_SIZE]; +static uint8_t m_big_buffer[PKT_SIZE]; + +static uint8_t * mp_small_buffer = NULL; +static uint8_t * mp_big_buffer = NULL; +static uint8_t * mp_buffer = NULL; + +static uint8_t m_rx_buf[1]; +static bool m_rx_escape; + + +// The function returns false to signal that no more bytes can be passed to be +// sent (put into the TX buffer) until UART transmission is done. +static bool tx_buf_put(uint8_t data_byte) +{ + ASSERT(m_tx_bytes < SER_PHY_HCI_SLIP_TX_BUF_SIZE); + + mp_tx_buf[m_tx_bytes] = data_byte; + ++m_tx_bytes; + + bool flush = false; + ser_phy_hci_slip_evt_type_t slip_evt_type = NO_EVENT; + if (m_tx_phase == PHASE_ACK_END) + { + // Send buffer, then signal that an acknowledge packet has been sent. + flush = true; + slip_evt_type = SER_PHY_HCI_SLIP_EVT_ACK_SENT; + } + else if (m_tx_phase == PHASE_PACKET_END) + { + // Send buffer, then signal that a packet with payload has been sent. + flush = true; + slip_evt_type = SER_PHY_HCI_SLIP_EVT_PKT_SENT; + } + else if (m_tx_bytes >= SER_PHY_HCI_SLIP_TX_BUF_SIZE) + { + // Send buffer (because it is filled up), but don't signal anything, + // since the packet sending is not complete yet. + flush = true; + } + + if (flush) + { + // If some TX transfer is being done at the moment, a new one cannot be + // started, it must be scheduled to be performed later. + if (m_tx_in_progress) + { + m_tx_pending_evt_type = slip_evt_type; + m_tx_pending = true; + // No more buffers available, can't continue filling. + return false; + } + + m_tx_in_progress = true; + m_tx_evt_type = slip_evt_type; + APP_ERROR_CHECK(nrf_drv_uart_tx(&m_uart, mp_tx_buf, m_tx_bytes)); + + // Switch to the second buffer. + mp_tx_buf = (mp_tx_buf == m_tx_buf0) ? m_tx_buf1 : m_tx_buf0; + m_tx_bytes = 0; + } + + return true; +} + +static void tx_buf_fill(void) +{ + static ser_phy_hci_pkt_params_t * mp_tx_data = NULL; + static uint32_t m_tx_index; + bool can_continue = true; + + do { + static uint8_t tx_escaped_data = 0; + + if (tx_escaped_data != 0) + { + can_continue = tx_buf_put(tx_escaped_data); + tx_escaped_data = 0; + } + else switch (m_tx_phase) + { + case PHASE_BEGIN: + can_continue = tx_buf_put(APP_SLIP_END); + mp_tx_data = &m_tx_curr_packet.header; + m_tx_index = 0; + m_tx_phase = PHASE_HEADER; + tx_escaped_data = 0; + break; + + case PHASE_ACK_END: + case PHASE_PACKET_END: + can_continue = tx_buf_put(APP_SLIP_END); + + // [this is needed for the '++m_tx_phase;' below] + m_tx_phase = PHASE_PACKET_END; + // no break, intentional fall-through + + case PHASE_PRE_IDLE: + // In PHASE_PRE_IDLE the sending process is almost finished, only + // the NRF_DRV_UART_EVT_TX_DONE event is needed before it can switch + // to PHASE_IDLE. But during this waiting a new packet may appear + // (i.e. 'ser_phy_hci_slip_tx_pkt_send()' may be called), hence + // the following pointer must be checked before switching the phase, + // just like right after writing whole packet to buffer (i.e. in + // PHASE_PACKET_END). Therefore, the following code is common for + // these two cases. + if (m_tx_next_packet.header.p_buffer != NULL) + { + m_tx_curr_packet = m_tx_next_packet; + m_tx_next_packet.header.p_buffer = NULL; + + m_tx_phase = PHASE_BEGIN; + break; + } + // Go to the next phase: + // PHASE_PACKET_END -> PHASE_PRE_IDLE + // PHASE_PRE_IDLE -> PHASE_IDLE + ++m_tx_phase; + return; + + default: + ASSERT(mp_tx_data->p_buffer != NULL); + uint8_t data = mp_tx_data->p_buffer[m_tx_index]; + ++m_tx_index; + + if (data == APP_SLIP_END) + { + data = APP_SLIP_ESC; + tx_escaped_data = APP_SLIP_ESC_END; + } + else if (data == APP_SLIP_ESC) + { + tx_escaped_data = APP_SLIP_ESC_ESC; + } + can_continue = tx_buf_put(data); + + if (m_tx_index >= mp_tx_data->num_of_bytes) + { + mp_tx_data->p_buffer = NULL; + + if (m_tx_phase == PHASE_HEADER) + { + if (m_tx_curr_packet.payload.p_buffer == NULL) + { + // No payload -> ACK packet. + m_tx_phase = PHASE_ACK_END; + } + else + { + mp_tx_data = &m_tx_curr_packet.payload; + m_tx_index = 0; + m_tx_phase = PHASE_PAYLOAD; + } + } + else if (m_tx_phase == PHASE_PAYLOAD) + { + if (m_tx_curr_packet.crc.p_buffer == NULL) + { + // Packet without CRC. + m_tx_phase = PHASE_PACKET_END; + } + else + { + mp_tx_data = &m_tx_curr_packet.crc; + m_tx_index = 0; + m_tx_phase = PHASE_CRC; + } + } + else + { + ASSERT(m_tx_phase == PHASE_CRC); + m_tx_phase = PHASE_PACKET_END; + } + } + break; + } + } while (can_continue); +} + +uint32_t ser_phy_hci_slip_tx_pkt_send(const ser_phy_hci_pkt_params_t * p_header, + const ser_phy_hci_pkt_params_t * p_payload, + const ser_phy_hci_pkt_params_t * p_crc) +{ + if (p_header == NULL) + { + return NRF_ERROR_NULL; + } + + CRITICAL_REGION_ENTER(); + + // If some packet is already transmitted, schedule this new one to be sent + // as next. A critical region is needed here to ensure that the transmission + // won't finish before the following assignments are done. + if (m_tx_phase != PHASE_IDLE) + { + m_tx_next_packet.header = *p_header; + + if (p_payload == NULL) + { + m_tx_next_packet.payload.p_buffer = NULL; + } + else + { + m_tx_next_packet.payload = *p_payload; + } + + if (p_crc == NULL) + { + m_tx_next_packet.crc.p_buffer = NULL; + } + else + { + m_tx_next_packet.crc = *p_crc; + } + } + else + { + m_tx_curr_packet.header = *p_header; + + if (p_payload == NULL) + { + m_tx_curr_packet.payload.p_buffer = NULL; + } + else + { + m_tx_curr_packet.payload = *p_payload; + } + + if (p_crc == NULL) + { + m_tx_curr_packet.crc.p_buffer = NULL; + } + else + { + m_tx_curr_packet.crc = *p_crc; + } + + m_tx_phase = PHASE_BEGIN; + tx_buf_fill(); + } + + CRITICAL_REGION_EXIT(); + + return NRF_SUCCESS; +} + +/* Function returns false when last byte in packet is detected.*/ +static bool slip_decode(uint8_t * p_received_byte) +{ + switch (*p_received_byte) + { + case APP_SLIP_END: + return false; + + case APP_SLIP_ESC: + m_rx_escape = true; + break; + + case APP_SLIP_ESC_END: + + if (m_rx_escape == true) + { + m_rx_escape = false; + *p_received_byte = APP_SLIP_END; + } + break; + + case APP_SLIP_ESC_ESC: + + if (m_rx_escape == true) + { + m_rx_escape = false; + *p_received_byte = APP_SLIP_ESC; + } + break; + + /* Normal character - decoding not needed*/ + default: + break; + } + + return true; +} + + +static void ser_phi_hci_rx_byte(uint8_t rx_byte) +{ + static bool rx_sync = false; + uint8_t received_byte = rx_byte; + static bool big_buff_in_use = false; + static uint32_t m_rx_index; + /* Test received byte for SLIP packet start: 0xC0*/ + if (!rx_sync) + { + if (received_byte == APP_SLIP_END) + { + m_rx_index = 0; + rx_sync = true; + } + return; + } + + /* Additional check needed in case rx_sync flag was set by end of previous packet*/ + if ((m_rx_index) == 0 && (received_byte == APP_SLIP_END)) + { + return; + } + + /* Check if small (ACK) buffer is available*/ + if ((mp_small_buffer != NULL) && (big_buff_in_use == false)) + { + if (m_rx_index == 0) + { + mp_buffer = mp_small_buffer; + } + + /* Check if switch between small and big buffer is needed*/ + if (m_rx_index == sizeof (m_small_buffer) && received_byte != APP_SLIP_END) + { + /* Check if big (PKT) buffer is available*/ + if (mp_big_buffer != NULL) + { + /* Switch to big buffer*/ + memcpy(m_big_buffer, m_small_buffer, sizeof (m_small_buffer)); + mp_buffer = m_big_buffer; + } + else + { + /* Small buffer is too small and big buffer not available - cannot continue reception*/ + rx_sync = false; + return; + } + } + + /* Check if big buffer is full */ + if ((m_rx_index >= PKT_SIZE) && (received_byte != APP_SLIP_END)) + { + /* Do not notify upper layer - the packet is too big and cannot be handled by slip */ + rx_sync = false; + return; + } + + /* Decode byte. Will return false when it is 0xC0 - end of packet*/ + if (slip_decode(&received_byte)) + { + /* Write Rx byte only if it is not escape char */ + if (!m_rx_escape) + { + mp_buffer[m_rx_index++] = received_byte; + } + } + else + { + /* Reset pointers to signalise buffers are locked waiting for upper layer */ + if (mp_buffer == mp_small_buffer) + { + mp_small_buffer = NULL; + } + else + { + mp_big_buffer = NULL; + } + /* Report packet reception end*/ + m_ser_phy_hci_slip_event.evt_type = + SER_PHY_HCI_SLIP_EVT_PKT_RECEIVED; + m_ser_phy_hci_slip_event.evt_params.received_pkt.p_buffer = mp_buffer; + m_ser_phy_hci_slip_event.evt_params.received_pkt.num_of_bytes = m_rx_index; + m_ser_phy_hci_slip_event_handler(&m_ser_phy_hci_slip_event); + + rx_sync = false; + } + } + else if (mp_big_buffer != NULL) + { + big_buff_in_use = true; + mp_buffer = mp_big_buffer; + + /* Check if big buffer is full */ + if ((m_rx_index >= PKT_SIZE) && (received_byte != APP_SLIP_END)) + { + /* Do not notify upper layer - the packet is too big and cannot be handled by slip */ + rx_sync = false; + return; + } + + /* Decode byte*/ + if (slip_decode(&received_byte)) + { + /* Write Rx byte only if it is not escape char */ + if (!m_rx_escape) + { + mp_buffer[m_rx_index++] = received_byte; + } + } + else + { + // Mark the big buffer as locked (it should be freed by the upper + // layer). + mp_big_buffer = NULL; + big_buff_in_use = false; + + /* Report packet reception end*/ + m_ser_phy_hci_slip_event.evt_type = + SER_PHY_HCI_SLIP_EVT_PKT_RECEIVED; + m_ser_phy_hci_slip_event.evt_params.received_pkt.p_buffer = mp_buffer; + m_ser_phy_hci_slip_event.evt_params.received_pkt.num_of_bytes = m_rx_index; + m_ser_phy_hci_slip_event_handler(&m_ser_phy_hci_slip_event); + + rx_sync = false; + } + } + else + { + /* Both buffers are not available - cannot continue reception*/ + rx_sync = false; + return; + } +} + + +uint32_t ser_phy_hci_slip_rx_buf_free(uint8_t * p_buffer) +{ + uint32_t err_code = NRF_SUCCESS; + + if (p_buffer == NULL) + { + return NRF_ERROR_NULL; + } + else if (p_buffer == m_small_buffer) + { + /* Free small buffer*/ + if (mp_small_buffer == NULL) + { + mp_small_buffer = m_small_buffer; + } + else + { + err_code = NRF_ERROR_INVALID_STATE; + } + } + else if (p_buffer == m_big_buffer) + { + /* Free big buffer*/ + if (mp_big_buffer == NULL) + { + mp_big_buffer = m_big_buffer; + } + else + { + err_code = NRF_ERROR_INVALID_STATE; + } + } + + return err_code; +} + + +static void uart_event_handler(nrf_drv_uart_event_t * p_event, + void * p_context) +{ + (void)p_context; + + switch (p_event->type) + { + case NRF_DRV_UART_EVT_ERROR: + // Process the error only if this is a parity or overrun error. + // Break and framing errors will always occur before the other + // side becomes active. + if (p_event->data.error.error_mask & + (NRF_UART_ERROR_PARITY_MASK | NRF_UART_ERROR_OVERRUN_MASK)) + { + // Pass error source to upper layer + m_ser_phy_hci_slip_event.evt_type = + SER_PHY_HCI_SLIP_EVT_HW_ERROR; + m_ser_phy_hci_slip_event.evt_params.hw_error.error_code = + p_event->data.error.error_mask; + m_ser_phy_hci_slip_event_handler(&m_ser_phy_hci_slip_event); + } + APP_ERROR_CHECK(nrf_drv_uart_rx(&m_uart, m_rx_buf, 1)); + break; + + case NRF_DRV_UART_EVT_TX_DONE: + // If there is a pending transfer (the second buffer is ready to + // be sent), start it immediately. + if (m_tx_pending) + { + APP_ERROR_CHECK(nrf_drv_uart_tx(&m_uart, mp_tx_buf, m_tx_bytes)); + + // Switch to the buffer that has just been sent completely + // and now can be filled again. + mp_tx_buf = (mp_tx_buf == m_tx_buf0) ? m_tx_buf1 : m_tx_buf0; + m_tx_bytes = 0; + + m_ser_phy_hci_slip_event.evt_type = m_tx_evt_type; + m_tx_evt_type = m_tx_pending_evt_type; + + m_tx_pending = false; + } + else + { + m_tx_in_progress = false; + m_ser_phy_hci_slip_event.evt_type = m_tx_evt_type; + } + // If needed, notify the upper layer that the packet transfer is + // complete (note that this notification may result in another + // packet send request, so everything must be cleaned up above). + if (m_ser_phy_hci_slip_event.evt_type != NO_EVENT) + { + m_ser_phy_hci_slip_event_handler(&m_ser_phy_hci_slip_event); + } + // And if the sending process is not yet finished, look what is + // to be done next. + if (m_tx_phase != PHASE_IDLE) + { + tx_buf_fill(); + } + break; + + case NRF_DRV_UART_EVT_RX_DONE: + { + uint8_t rx_byte = m_rx_buf[0]; + APP_ERROR_CHECK(nrf_drv_uart_rx(&m_uart, m_rx_buf, 1)); + ser_phi_hci_rx_byte(rx_byte); + } + break; + + default: + APP_ERROR_CHECK(NRF_ERROR_INTERNAL); + } +} + + +uint32_t ser_phy_hci_slip_open(ser_phy_hci_slip_event_handler_t events_handler) +{ + uint32_t err_code; + + if (events_handler == NULL) + { + return NRF_ERROR_NULL; + } + + // Check if function was not called before. + if (m_ser_phy_hci_slip_event_handler != NULL) + { + return NRF_ERROR_INVALID_STATE; + } + + m_ser_phy_hci_slip_event_handler = events_handler; + + err_code = nrf_drv_uart_init(&m_uart, &m_uart_config, uart_event_handler); + if (err_code != NRF_SUCCESS) + { + return NRF_ERROR_INVALID_PARAM; + } + + mp_tx_buf = m_tx_buf0; + m_tx_bytes = 0; + m_tx_phase = PHASE_IDLE; + m_tx_in_progress = false; + m_tx_pending = false; + + m_rx_escape = false; + mp_small_buffer = m_small_buffer; + mp_big_buffer = m_big_buffer; + + APP_ERROR_CHECK(nrf_drv_uart_rx(&m_uart, m_rx_buf, 1)); + + return NRF_SUCCESS; +} + + +void ser_phy_hci_slip_close(void) +{ + nrf_drv_uart_uninit(&m_uart); + m_ser_phy_hci_slip_event_handler = NULL; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_hci_slip_cdc.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_hci_slip_cdc.c new file mode 100644 index 0000000..99efac0 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_hci_slip_cdc.c @@ -0,0 +1,720 @@ +/** + * 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 "ser_phy_hci.h" +#include "ser_config.h" +#ifdef SER_CONNECTIVITY +#include "ser_phy_config_conn.h" +#else +#include "ser_phy_config_app.h" +#endif +#include "app_usbd_cdc_acm.h" +#include "nrf_drv_clock.h" +#include "app_error.h" +#include "app_util_platform.h" + +#define NRF_LOG_MODULE_NAME sphy_cdc +#include "nrf_log.h" +NRF_LOG_MODULE_REGISTER(); + +#define APP_SLIP_END 0xC0 /**< SLIP code for identifying the beginning and end of a packet frame.. */ +#define APP_SLIP_ESC 0xDB /**< SLIP escape code. This code is used to specify that the following character is specially encoded. */ +#define APP_SLIP_ESC_END 0xDC /**< SLIP special code. When this code follows 0xDB, this character is interpreted as payload data 0xC0.. */ +#define APP_SLIP_ESC_ESC 0xDD /**< SLIP special code. When this code follows 0xDB, this character is interpreted as payload data 0xDB. */ + +#define HDR_SIZE 4 +#define CRC_SIZE 2 +#define PKT_SIZE (SER_HAL_TRANSPORT_MAX_PKT_SIZE + HDR_SIZE + CRC_SIZE) + +static void cdc_acm_user_ev_handler(app_usbd_class_inst_t const * p_inst, + app_usbd_cdc_acm_user_event_t event); + +#define CDC_ACM_COMM_INTERFACE 0 +#define CDC_ACM_COMM_EPIN NRF_DRV_USBD_EPIN2 + +#define CDC_ACM_DATA_INTERFACE 1 +#define CDC_ACM_DATA_EPIN NRF_DRV_USBD_EPIN1 +#define CDC_ACM_DATA_EPOUT NRF_DRV_USBD_EPOUT1 + +APP_USBD_CDC_ACM_GLOBAL_DEF(m_app_cdc_acm, + cdc_acm_user_ev_handler, + CDC_ACM_COMM_INTERFACE, + CDC_ACM_DATA_INTERFACE, + CDC_ACM_COMM_EPIN, + CDC_ACM_DATA_EPIN, + CDC_ACM_DATA_EPOUT, + APP_USBD_CDC_COMM_PROTOCOL_NONE +); + +static bool volatile m_port_open; + +typedef struct { + ser_phy_hci_pkt_params_t header; + ser_phy_hci_pkt_params_t payload; + ser_phy_hci_pkt_params_t crc; +} ser_phy_hci_slip_pkt_t; +static ser_phy_hci_slip_pkt_t m_tx_curr_packet; +static ser_phy_hci_slip_pkt_t m_tx_next_packet; + +static ser_phy_hci_slip_evt_t m_ser_phy_hci_slip_event; +static ser_phy_hci_slip_event_handler_t m_ser_phy_hci_slip_event_handler; /**< Event handler for upper layer */ + +static uint8_t m_tx_buf0[NRF_DRV_USBD_EPSIZE]; +static uint8_t m_tx_buf1[NRF_DRV_USBD_EPSIZE]; +static uint8_t * mp_tx_buf; +static uint8_t m_tx_bytes; + +static enum { + PHASE_BEGIN, + PHASE_HEADER, + PHASE_PAYLOAD, + PHASE_CRC, + PHASE_ACK_END, + // The following three elements have to have consecutive values, + // 'tx_buf_fill()' relies on this. + PHASE_PACKET_END, + PHASE_PRE_IDLE = PHASE_PACKET_END + 1, + PHASE_IDLE = PHASE_PRE_IDLE + 1 +} volatile m_tx_phase; + +static bool volatile m_tx_in_progress; +static bool volatile m_tx_pending; + +#define NO_EVENT SER_PHY_HCI_SLIP_EVT_TYPE_MAX +static ser_phy_hci_slip_evt_type_t m_tx_evt_type; +static ser_phy_hci_slip_evt_type_t m_tx_pending_evt_type; + +static ser_phy_hci_pkt_params_t * mp_tx_data = NULL; +static uint32_t m_tx_index; + +static uint8_t m_small_buffer[HDR_SIZE]; +static uint8_t m_big_buffer[PKT_SIZE]; + +static uint8_t * mp_small_buffer = NULL; +static uint8_t * mp_big_buffer = NULL; +static uint8_t * mp_buffer = NULL; +static uint32_t m_rx_index; + +static uint8_t m_rx_byte; +static bool m_rx_escape; + + +// The function returns false to signal that no more bytes can be passed to be +// sent (put into the TX buffer) until UART transmission is done. +static bool tx_buf_put(uint8_t data_byte) +{ + ASSERT(m_tx_bytes < SER_PHY_HCI_SLIP_TX_BUF_SIZE); + mp_tx_buf[m_tx_bytes] = data_byte; + ++m_tx_bytes; + + bool flush = false; + ser_phy_hci_slip_evt_type_t slip_evt_type = NO_EVENT; + if (m_tx_phase == PHASE_ACK_END) + { + // Send buffer, then signal that an acknowledge packet has been sent. + flush = true; + slip_evt_type = SER_PHY_HCI_SLIP_EVT_ACK_SENT; + } + else if (m_tx_phase == PHASE_PACKET_END) + { + // Send buffer, then signal that a packet with payload has been sent. + flush = true; + slip_evt_type = SER_PHY_HCI_SLIP_EVT_PKT_SENT; + } + else if (m_tx_bytes >= SER_PHY_HCI_SLIP_TX_BUF_SIZE) + { + // Send buffer (because it is filled up), but don't signal anything, + // since the packet sending is not complete yet. + flush = true; + } + + if (flush) + { + // If some TX transfer is being done at the moment, a new one cannot be + // started, it must be scheduled to be performed later. + if (m_tx_in_progress) + { + m_tx_pending_evt_type = slip_evt_type; + m_tx_pending = true; + // No more buffers available, can't continue filling. + return false; + } + + if (m_port_open) + { + m_tx_in_progress = true; + m_tx_evt_type = slip_evt_type; + APP_ERROR_CHECK(app_usbd_cdc_acm_write(&m_app_cdc_acm, + mp_tx_buf, m_tx_bytes)); + } + + // Switch to the second buffer. + mp_tx_buf = (mp_tx_buf == m_tx_buf0) ? m_tx_buf1 : m_tx_buf0; + m_tx_bytes = 0; + } + + return true; +} + +static void tx_buf_fill(void) +{ + bool can_continue = true; + do { + static uint8_t tx_escaped_data = 0; + + if (tx_escaped_data != 0) + { + can_continue = tx_buf_put(tx_escaped_data); + tx_escaped_data = 0; + } + else switch (m_tx_phase) + { + case PHASE_BEGIN: + can_continue = tx_buf_put(APP_SLIP_END); + mp_tx_data = &m_tx_curr_packet.header; + m_tx_index = 0; + m_tx_phase = PHASE_HEADER; + tx_escaped_data = 0; + break; + + case PHASE_ACK_END: + case PHASE_PACKET_END: + can_continue = tx_buf_put(APP_SLIP_END); + + // [this is needed for the '++m_tx_phase;' below] + m_tx_phase = PHASE_PACKET_END; + // no break, intentional fall-through + + case PHASE_PRE_IDLE: + // In PHASE_PRE_IDLE the sending process is almost finished, only + // the NRF_DRV_UART_EVT_TX_DONE event is needed before it can switch + // to PHASE_IDLE. But during this waiting a new packet may appear + // (i.e. 'ser_phy_hci_slip_tx_pkt_send()' may be called), hence + // the following pointer must be checked before switching the phase, + // just like right after writing whole packet to buffer (i.e. in + // PHASE_PACKET_END). Therefore, the following code is common for + // these two cases. + if (m_tx_next_packet.header.p_buffer != NULL) + { + m_tx_curr_packet = m_tx_next_packet; + m_tx_next_packet.header.p_buffer = NULL; + + m_tx_phase = PHASE_BEGIN; + break; + } + // Go to the next phase: + // PHASE_PACKET_END -> PHASE_PRE_IDLE + // PHASE_PRE_IDLE -> PHASE_IDLE + ++m_tx_phase; + return; + + default: + ASSERT(mp_tx_data->p_buffer != NULL); + uint8_t data = mp_tx_data->p_buffer[m_tx_index]; + ++m_tx_index; + + if (data == APP_SLIP_END) + { + data = APP_SLIP_ESC; + tx_escaped_data = APP_SLIP_ESC_END; + } + else if (data == APP_SLIP_ESC) + { + tx_escaped_data = APP_SLIP_ESC_ESC; + } + can_continue = tx_buf_put(data); + + if (m_tx_index >= mp_tx_data->num_of_bytes) + { + mp_tx_data->p_buffer = NULL; + + if (m_tx_phase == PHASE_HEADER) + { + if (m_tx_curr_packet.payload.p_buffer == NULL) + { + // No payload -> ACK packet. + m_tx_phase = PHASE_ACK_END; + } + else + { + mp_tx_data = &m_tx_curr_packet.payload; + m_tx_index = 0; + m_tx_phase = PHASE_PAYLOAD; + } + } + else if (m_tx_phase == PHASE_PAYLOAD) + { + if (m_tx_curr_packet.crc.p_buffer == NULL) + { + // Packet without CRC. + m_tx_phase = PHASE_PACKET_END; + } + else + { + mp_tx_data = &m_tx_curr_packet.crc; + m_tx_index = 0; + m_tx_phase = PHASE_CRC; + } + } + else + { + ASSERT(m_tx_phase == PHASE_CRC); + m_tx_phase = PHASE_PACKET_END; + } + } + break; + } + } while (can_continue); +} + +uint32_t ser_phy_hci_slip_tx_pkt_send(const ser_phy_hci_pkt_params_t * p_header, + const ser_phy_hci_pkt_params_t * p_payload, + const ser_phy_hci_pkt_params_t * p_crc) +{ + if (p_header == NULL) + { + return NRF_ERROR_NULL; + } + + if (!m_port_open) + { + return NRF_SUCCESS; + } + + CRITICAL_REGION_ENTER(); + + // If some packet is already transmitted, schedule this new one to be sent + // as next. A critical region is needed here to ensure that the transmission + // won't finish before the following assignments are done. + if (m_tx_phase != PHASE_IDLE) + { + m_tx_next_packet.header = *p_header; + + if (p_payload == NULL) + { + m_tx_next_packet.payload.p_buffer = NULL; + } + else + { + m_tx_next_packet.payload = *p_payload; + } + + if (p_crc == NULL) + { + m_tx_next_packet.crc.p_buffer = NULL; + } + else + { + m_tx_next_packet.crc = *p_crc; + } + } + else + { + m_tx_curr_packet.header = *p_header; + + if (p_payload == NULL) + { + m_tx_curr_packet.payload.p_buffer = NULL; + } + else + { + m_tx_curr_packet.payload = *p_payload; + } + + if (p_crc == NULL) + { + m_tx_curr_packet.crc.p_buffer = NULL; + } + else + { + m_tx_curr_packet.crc = *p_crc; + } + + m_tx_phase = PHASE_BEGIN; + tx_buf_fill(); + } + + CRITICAL_REGION_EXIT(); + + return NRF_SUCCESS; +} + +/* Function returns false when last byte in packet is detected.*/ +static bool slip_decode(uint8_t * p_received_byte) +{ + switch (*p_received_byte) + { + case APP_SLIP_END: + return false; + + case APP_SLIP_ESC: + m_rx_escape = true; + break; + + case APP_SLIP_ESC_END: + + if (m_rx_escape == true) + { + m_rx_escape = false; + *p_received_byte = APP_SLIP_END; + } + break; + + case APP_SLIP_ESC_ESC: + + if (m_rx_escape == true) + { + m_rx_escape = false; + *p_received_byte = APP_SLIP_ESC; + } + break; + + /* Normal character - decoding not needed*/ + default: + break; + } + + return true; +} + + +static void ser_phi_hci_rx_byte(uint8_t rx_byte) +{ + static bool rx_sync = false; + uint8_t received_byte = rx_byte; + static bool big_buff_in_use = false; + + /* Test received byte for SLIP packet start: 0xC0*/ + if (!rx_sync) + { + if (received_byte == APP_SLIP_END) + { + m_rx_index = 0; + rx_sync = true; + } + return; + } + + /* Additional check needed in case rx_sync flag was set by end of previous packet*/ + if ((m_rx_index) == 0 && (received_byte == APP_SLIP_END)) + { + return; + } + + /* Check if small (ACK) buffer is available*/ + if ((mp_small_buffer != NULL) && (big_buff_in_use == false)) + { + if (m_rx_index == 0) + { + mp_buffer = mp_small_buffer; + } + + /* Check if switch between small and big buffer is needed*/ + if (m_rx_index == sizeof (m_small_buffer) /*NEW!!!*/ && received_byte != APP_SLIP_END) + { + /* Check if big (PKT) buffer is available*/ + if (mp_big_buffer != NULL) + { + /* Switch to big buffer*/ + memcpy(m_big_buffer, m_small_buffer, sizeof (m_small_buffer)); + mp_buffer = m_big_buffer; + } + else + { + /* Small buffer is too small and big buffer not available - cannot continue reception*/ + rx_sync = false; + return; + } + } + + /* Check if big buffer is full */ + if ((m_rx_index >= PKT_SIZE) && (received_byte != APP_SLIP_END)) + { + /* Do not notify upper layer - the packet is too big and cannot be handled by slip */ + rx_sync = false; + return; + } + + /* Decode byte. Will return false when it is 0xC0 - end of packet*/ + if (slip_decode(&received_byte)) + { + /* Write Rx byte only if it is not escape char */ + if (!m_rx_escape) + { + mp_buffer[m_rx_index++] = received_byte; + } + } + else + { + /* Reset pointers to signalise buffers are locked waiting for upper layer */ + if (mp_buffer == mp_small_buffer) + { + mp_small_buffer = NULL; + } + else + { + mp_big_buffer = NULL; + } + /* Report packet reception end*/ + m_ser_phy_hci_slip_event.evt_type = + SER_PHY_HCI_SLIP_EVT_PKT_RECEIVED; + m_ser_phy_hci_slip_event.evt_params.received_pkt.p_buffer = mp_buffer; + m_ser_phy_hci_slip_event.evt_params.received_pkt.num_of_bytes = m_rx_index; + m_ser_phy_hci_slip_event_handler(&m_ser_phy_hci_slip_event); + + rx_sync = false; + } + } + else if (mp_big_buffer != NULL) + { + big_buff_in_use = true; + mp_buffer = mp_big_buffer; + + /* Check if big buffer is full */ + if ((m_rx_index >= PKT_SIZE) && (received_byte != APP_SLIP_END)) + { + /* Do not notify upper layer - the packet is too big and cannot be handled by slip */ + rx_sync = false; + return; + } + + /* Decode byte*/ + if (slip_decode(&received_byte)) + { + /* Write Rx byte only if it is not escape char */ + if (!m_rx_escape) + { + mp_buffer[m_rx_index++] = received_byte; + } + } + else + { + // Mark the big buffer as locked (it should be freed by the upper + // layer). + mp_big_buffer = NULL; + big_buff_in_use = false; + + /* Report packet reception end*/ + m_ser_phy_hci_slip_event.evt_type = + SER_PHY_HCI_SLIP_EVT_PKT_RECEIVED; + m_ser_phy_hci_slip_event.evt_params.received_pkt.p_buffer = mp_buffer; + m_ser_phy_hci_slip_event.evt_params.received_pkt.num_of_bytes = m_rx_index; + m_ser_phy_hci_slip_event_handler(&m_ser_phy_hci_slip_event); + + rx_sync = false; + } + } + else + { + /* Both buffers are not available - cannot continue reception*/ + rx_sync = false; + return; + } +} + + +uint32_t ser_phy_hci_slip_rx_buf_free(uint8_t * p_buffer) +{ + uint32_t err_code = NRF_SUCCESS; + + if (p_buffer == NULL) + { + return NRF_ERROR_NULL; + } + else if (p_buffer == m_small_buffer) + { + /* Free small buffer*/ + if (mp_small_buffer == NULL) + { + mp_small_buffer = m_small_buffer; + } + else + { + err_code = NRF_ERROR_INVALID_STATE; + } + } + else if (p_buffer == m_big_buffer) + { + /* Free big buffer*/ + if (mp_big_buffer == NULL) + { + mp_big_buffer = m_big_buffer; + } + else + { + err_code = NRF_ERROR_INVALID_STATE; + } + } + + return err_code; +} + + +static void cdc_acm_user_ev_handler(app_usbd_class_inst_t const * p_inst, + app_usbd_cdc_acm_user_event_t event) +{ + app_usbd_cdc_acm_t const * p_cdc_acm = app_usbd_cdc_acm_class_get(p_inst); + + switch (event) + { + case APP_USBD_CDC_ACM_USER_EVT_PORT_OPEN: + NRF_LOG_DEBUG("EVT_PORT_OPEN"); + if (!m_port_open) + { + ret_code_t ret_code; + + m_port_open = true; + + do { + ret_code = app_usbd_cdc_acm_read(p_cdc_acm, &m_rx_byte, 1); + if (ret_code == NRF_SUCCESS) + { + ser_phi_hci_rx_byte(m_rx_byte); + } + else if (ret_code != NRF_ERROR_IO_PENDING) + { + APP_ERROR_CHECK(ret_code); + } + } while (ret_code == NRF_SUCCESS); + } + break; + + case APP_USBD_CDC_ACM_USER_EVT_PORT_CLOSE: + NRF_LOG_DEBUG("EVT_PORT_CLOSE"); + m_port_open = false; + break; + + case APP_USBD_CDC_ACM_USER_EVT_TX_DONE: + // If there is a pending transfer (the second buffer is ready to + // be sent), start it immediately. + if (m_tx_pending) + { + APP_ERROR_CHECK(app_usbd_cdc_acm_write(p_cdc_acm, + mp_tx_buf, m_tx_bytes)); + + // Switch to the buffer that has just been sent completely + // and now can be filled again. + mp_tx_buf = (mp_tx_buf == m_tx_buf0) ? m_tx_buf1 : m_tx_buf0; + m_tx_bytes = 0; + + m_ser_phy_hci_slip_event.evt_type = m_tx_evt_type; + m_tx_evt_type = m_tx_pending_evt_type; + + m_tx_pending = false; + } + else + { + m_tx_in_progress = false; + m_ser_phy_hci_slip_event.evt_type = m_tx_evt_type; + } + // If needed, notify the upper layer that the packet transfer is + // complete (note that this notification may result in another + // packet send request, so everything must be cleaned up above). + if (m_ser_phy_hci_slip_event.evt_type != NO_EVENT) + { + m_ser_phy_hci_slip_event_handler(&m_ser_phy_hci_slip_event); + } + // And if the sending process is not yet finished, look what is + // to be done next. + if (m_tx_phase != PHASE_IDLE) + { + tx_buf_fill(); + } + break; + + case APP_USBD_CDC_ACM_USER_EVT_RX_DONE: + { + ret_code_t ret_code; + do + { + ser_phi_hci_rx_byte(m_rx_byte); + + ret_code = app_usbd_cdc_acm_read(p_cdc_acm, &m_rx_byte, 1); + } while (ret_code == NRF_SUCCESS); + } + break; + + default: + break; + } +} + +uint32_t ser_phy_hci_slip_open(ser_phy_hci_slip_event_handler_t events_handler) +{ + if (events_handler == NULL) + { + return NRF_ERROR_NULL; + } + + // Check if function was not called before. + if (m_ser_phy_hci_slip_event_handler != NULL) + { + return NRF_ERROR_INVALID_STATE; + } + + ret_code_t ret = app_usbd_class_append( + app_usbd_cdc_acm_class_inst_get(&m_app_cdc_acm)); + if (ret != NRF_SUCCESS) + { + return ret; + } + + + m_ser_phy_hci_slip_event_handler = events_handler; + + mp_tx_buf = m_tx_buf0; + m_tx_bytes = 0; + m_tx_phase = PHASE_IDLE; + m_tx_in_progress = false; + m_tx_pending = false; + + m_rx_escape = false; + mp_small_buffer = m_small_buffer; + mp_big_buffer = m_big_buffer; + + return NRF_SUCCESS; +} + + +void ser_phy_hci_slip_close(void) +{ + m_ser_phy_hci_slip_event_handler = NULL; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_nohci.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_nohci.c new file mode 100644 index 0000000..4580086 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_nohci.c @@ -0,0 +1,382 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +/**@file + * + * @defgroup ser_phy_spi_phy_driver_slave ser_phy_nrf51_spi_slave.c + * @{ + * @ingroup ser_phy_spi_phy_driver_slave + * + * @brief SPI_RAW PHY slave driver. + */ + +#include <stddef.h> +#include <string.h> + +#include "app_error.h" +#include "app_util.h" +#include "app_util_platform.h" +#include "app_timer.h" +#include "ser_phy.h" +#include "ser_phy_hci.h" +#include "crc16.h" +#include "nrf_soc.h" + +#include "ser_phy_debug_comm.h" + +static bool m_flag_nohci_init = false; +static bool m_flag_expect_ack; +static bool m_flag_buffer_reqested = false; + +static uint16_t m_rx_packet_length; +static uint8_t * m_p_rx_packet; + +static uint16_t m_rx_pending_packet_length; +static uint8_t * m_p_rx_pending_packet; + +static uint16_t m_rx_allocated_packet_length; +static uint8_t * m_p_rx_allocated_packet; + +static uint8_t * m_p_tx_packet = NULL; +static uint16_t m_tx_packet_length; + +static ser_phy_events_handler_t m_ser_phy_callback = NULL; + +#define PKT_HDR_SIZE 4 /**< Packet header size in number of bytes. */ +#define PKT_CRC_SIZE 2 /**< Packet CRC size in number of bytes. */ + +static void ser_phy_nohci_assert(bool cond) +{ + APP_ERROR_CHECK_BOOL(cond); +} + + +static void ser_phy_event_callback(ser_phy_evt_t event) +{ + if (m_ser_phy_callback) + { + m_ser_phy_callback(event); + } +} + + +static void memory_request_callback(uint16_t size) +{ + ser_phy_evt_t event; + + DEBUG_EVT_HCI_PHY_EVT_BUF_REQUEST(0); + + event.evt_type = SER_PHY_EVT_RX_BUF_REQUEST; + event.evt_params.rx_buf_request.num_of_bytes = size; + ser_phy_event_callback(event); +} + + +static void packet_received_callback(uint8_t * pBuffer, uint16_t size) +{ + ser_phy_evt_t event; + + DEBUG_EVT_HCI_PHY_EVT_RX_PKT_RECEIVED(0); + + event.evt_type = SER_PHY_EVT_RX_PKT_RECEIVED; + event.evt_params.rx_pkt_received.num_of_bytes = size; + event.evt_params.rx_pkt_received.p_buffer = pBuffer; + ser_phy_event_callback(event); +} + + +static void packet_dropped_callback(void) +{ + ser_phy_evt_t event; + + DEBUG_EVT_HCI_PHY_EVT_RX_PKT_DROPPED(0); + + event.evt_type = SER_PHY_EVT_RX_PKT_DROPPED; + ser_phy_event_callback(event); +} + + +static void packet_transmitted_callback(void) +{ + ser_phy_evt_t event; + + DEBUG_EVT_HCI_PHY_EVT_TX_PKT_SENT(0); + + event.evt_type = SER_PHY_EVT_TX_PKT_SENT; + ser_phy_event_callback(event); +} + + +static void hci_slip_event_handler(ser_phy_hci_slip_evt_t * p_event) +{ + if ( p_event->evt_type == SER_PHY_HCI_SLIP_EVT_PKT_SENT ) + { + DEBUG_EVT_SLIP_PACKET_TXED(0); + + if (!m_flag_expect_ack) + { + m_p_tx_packet = NULL; + packet_transmitted_callback(); + } + else + { + ser_phy_nohci_assert(false); // packet was send as a ACK packet, callback should be with ACK_SENT + } + + } + else if ( p_event->evt_type == SER_PHY_HCI_SLIP_EVT_ACK_SENT ) + { + DEBUG_EVT_SLIP_ACK_TXED(0); + + if (m_flag_expect_ack) + { + m_p_tx_packet = NULL; + packet_transmitted_callback(); + } + else + { + ser_phy_nohci_assert(false); // packet was send as a normal packet, callback should be with PKT_SENT + } + + } + else if ( p_event->evt_type == SER_PHY_HCI_SLIP_EVT_PKT_RECEIVED ) + { + CRITICAL_REGION_ENTER(); + + if (m_p_rx_packet == NULL) + { + m_p_rx_packet = p_event->evt_params.received_pkt.p_buffer; + m_rx_packet_length = p_event->evt_params.received_pkt.num_of_bytes; + m_p_rx_allocated_packet = m_p_rx_packet; + m_rx_allocated_packet_length = m_rx_packet_length; + m_flag_buffer_reqested = true; + memory_request_callback(m_rx_allocated_packet_length); + } + else if (m_p_rx_pending_packet == NULL) + { + m_p_rx_pending_packet = p_event->evt_params.received_pkt.p_buffer; + m_rx_pending_packet_length = p_event->evt_params.received_pkt.num_of_bytes; + } + else + { + // both buffers are not released; this is fault + ser_phy_nohci_assert(false); + } + CRITICAL_REGION_EXIT(); + } + else + { + // no other callbacks are expected + ser_phy_nohci_assert(false); + } +} + + +/* ser_phy API function */ +void ser_phy_interrupts_enable(void) +{ + + NVIC_EnableIRQ(UART0_IRQn); + return; +} + + +/* ser_phy API function */ +void ser_phy_interrupts_disable(void) +{ + NVIC_DisableIRQ(UART0_IRQn); + return; +} + + +/* ser_phy API function */ +uint32_t ser_phy_rx_buf_set(uint8_t * p_buffer) +{ + uint32_t status = NRF_SUCCESS; + + if (m_flag_buffer_reqested) + { + m_flag_buffer_reqested = false; + + if (p_buffer) + { + memcpy(p_buffer, m_p_rx_allocated_packet, m_rx_allocated_packet_length); + packet_received_callback(p_buffer, m_rx_allocated_packet_length); + } + else + { + packet_dropped_callback(); + } + + CRITICAL_REGION_ENTER(); + + if (m_p_rx_allocated_packet == m_p_rx_packet && (m_p_rx_pending_packet == NULL)) + { + // packet is copied and there is no pending packet + (void) ser_phy_hci_slip_rx_buf_free(m_p_rx_packet); + m_p_rx_packet = NULL; + m_p_rx_allocated_packet = NULL; + } + else if (m_p_rx_allocated_packet == m_p_rx_packet && (m_p_rx_pending_packet != NULL)) + { + // there is a pending packet - request memory for it + m_p_rx_allocated_packet = m_p_rx_pending_packet; + m_rx_allocated_packet_length = m_rx_pending_packet_length; + m_flag_buffer_reqested = true; + } + else if (m_p_rx_allocated_packet == m_p_rx_pending_packet ) + { + // the pending packet was serviced - release both + m_p_rx_allocated_packet = NULL; + (void) ser_phy_hci_slip_rx_buf_free(m_p_rx_packet); + m_p_rx_packet = NULL; + (void) ser_phy_hci_slip_rx_buf_free(m_p_rx_pending_packet); + m_p_rx_pending_packet = NULL; + } + else + { + // no other calls are expected + ser_phy_nohci_assert(false); + } + CRITICAL_REGION_EXIT(); + + // request memory for a pending + if (m_p_rx_allocated_packet) + { + memory_request_callback(m_rx_allocated_packet_length); + } + } + else + { + status = NRF_ERROR_BUSY; + } + return status; +} + + +/* ser_phy API function */ +uint32_t ser_phy_tx_pkt_send(const uint8_t * p_buffer, uint16_t num_of_bytes) +{ + uint32_t status = NRF_SUCCESS; + uint32_t err_code; + + if ( p_buffer == NULL || num_of_bytes == 0) + { + return NRF_ERROR_NULL; + } + + if ( m_p_tx_packet == NULL) + { + m_tx_packet_length = num_of_bytes; + m_p_tx_packet = (uint8_t *)p_buffer; + + if (m_tx_packet_length <= PKT_HDR_SIZE + PKT_CRC_SIZE) + { + ser_phy_hci_pkt_params_t pkt; // all packets smaller than 6 goes as ACK + + m_flag_expect_ack = true; + pkt.p_buffer = (uint8_t *)m_p_tx_packet; + pkt.num_of_bytes = m_tx_packet_length; + DEBUG_EVT_SLIP_ACK_TX(0); + err_code = ser_phy_hci_slip_tx_pkt_send(&pkt, NULL, NULL); // this will look like ACK for slip + ser_phy_nohci_assert(err_code == NRF_SUCCESS); + } + else + { + ser_phy_hci_pkt_params_t header; // this is fake header - just first 4 bytes + ser_phy_hci_pkt_params_t crc; // this is fake header - just last 2 bytes + ser_phy_hci_pkt_params_t payload; // this is fake payload - all except for header and crc + + m_flag_expect_ack = false; + header.p_buffer = (uint8_t *)m_p_tx_packet; + header.num_of_bytes = PKT_HDR_SIZE; + crc.p_buffer = (uint8_t *)m_p_tx_packet + m_tx_packet_length - PKT_CRC_SIZE; + crc.num_of_bytes = PKT_CRC_SIZE; + payload.p_buffer = (uint8_t *)m_p_tx_packet + PKT_HDR_SIZE; + payload.num_of_bytes = m_tx_packet_length - PKT_HDR_SIZE - PKT_CRC_SIZE; + DEBUG_EVT_SLIP_PACKET_TX(0); + err_code = ser_phy_hci_slip_tx_pkt_send(&header, &payload, &crc); // this will look like normal packet for slip + ser_phy_nohci_assert(err_code == NRF_SUCCESS); + } + } + else + { + status = NRF_ERROR_BUSY; + } + + return status; +} + + +/* ser_phy API function */ +uint32_t ser_phy_open(ser_phy_events_handler_t events_handler) +{ + uint32_t err_code; + + if (m_flag_nohci_init) + { + return NRF_ERROR_INVALID_STATE; + } + + if (events_handler == NULL) + { + return NRF_ERROR_NULL; + } + err_code = ser_phy_hci_slip_open(hci_slip_event_handler); + + if (err_code != NRF_SUCCESS) + { + return err_code; + } + + m_ser_phy_callback = events_handler; + m_flag_nohci_init = true; + return NRF_SUCCESS; +} + + +/* ser_phy API function */ +void ser_phy_close(void) +{ + m_ser_phy_callback = NULL; + ser_phy_hci_slip_close(); + m_flag_nohci_init = false; +} + + diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_spi_5W_master.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_spi_5W_master.c new file mode 100644 index 0000000..ade86e5 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_spi_5W_master.c @@ -0,0 +1,823 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +/**@file + * + * @defgroup ser_phy_spi_5W_phy_driver_master ser_phy_nrf51_spi_5W_master.c + * @{ + * @ingroup ser_phy_spi_5W_phy_driver_master + * + * @brief SPI_5W_RAW PHY master driver. + */ + +#include <stdio.h> +#include "app_util.h" +#include "app_util_platform.h" +#include "boards.h" +#include "nrf_error.h" +#include "nrf_gpio.h" +#include "nrf_drv_gpiote.h" +#include "ser_config.h" +#include "ser_config_5W_app.h" +#include "ser_phy.h" +#include "ser_phy_config_app.h" +#include "spi_5W_master.h" +#include "ser_phy_debug_app.h" +#include "app_error.h" +#define notUSE_PendSV + +#ifdef USE_PendSV +#define SW_IRQn PendSV_IRQn +#define SW_IRQ_Handler() PendSV_Handler() +#define SET_Pend_SW_IRQ() SCB->ICSR = SCB->ICSR | SCB_ICSR_PENDSVSET_Msk //NVIC_SetPendingIRQ(PendSV_IRQn) - PendSV_IRQn is a negative - does not work with CMSIS +#else +#define SW_IRQn SWI3_IRQn +#define SW_IRQ_Handler() SWI3_IRQHandler() +#define SET_Pend_SW_IRQ() NVIC_SetPendingIRQ(SWI3_IRQn) +#endif + +#define SER_PHY_SPI_5W_MTU_SIZE SER_PHY_SPI_MTU_SIZE + +typedef enum +{ + SER_PHY_STATE_IDLE = 0, + SER_PHY_STATE_TX_HEADER, + SER_PHY_STATE_TX_WAIT_FOR_RDY, + SER_PHY_STATE_TX_PAYLOAD, + SER_PHY_STATE_RX_WAIT_FOR_RDY, + SER_PHY_STATE_TX_ZERO_HEADER, + SER_PHY_STATE_RX_HEADER, + SER_PHY_STATE_MEMORY_REQUEST, + SER_PHY_STATE_RX_PAYLOAD, + SER_PHY_STATE_DISABLED +} ser_phy_spi_master_state_t; + +typedef enum +{ + SER_PHY_EVT_GPIO_RDY = 0, + SER_PHY_EVT_GPIO_REQ, + SER_PHY_EVT_SPI_TRANSFER_DONE, + SER_PHY_EVT_TX_API_CALL, + SER_PHY_EVT_RX_API_CALL +} ser_phy_event_source_t; + +#define _static static + +_static uint8_t * mp_tx_buffer = NULL; +_static uint16_t m_tx_buf_len = 0; + +_static uint8_t * mp_rx_buffer = NULL; +_static uint16_t m_rx_buf_len = 0; +_static uint8_t m_recv_buffer[SER_PHY_SPI_5W_MTU_SIZE]; +_static uint8_t m_len_buffer[SER_PHY_HEADER_SIZE + 1] = { 0 }; //len is asymmetric for 5W, there is a 1 byte guard when receiving + +_static uint16_t m_tx_packet_length = 0; +_static uint16_t m_accumulated_tx_packet_length = 0; +_static uint16_t m_current_tx_packet_length = 0; + +_static uint16_t m_rx_packet_length = 0; +_static uint16_t m_accumulated_rx_packet_length = 0; +_static uint16_t m_current_rx_packet_length = 0; + +_static volatile bool m_pend_req_flag = 0; +_static volatile bool m_pend_rdy_flag = 0; +_static volatile bool m_pend_xfer_flag = 0; +_static volatile bool m_pend_rx_api_flag = 0; +_static volatile bool m_pend_tx_api_flag = 0; + +_static volatile bool m_slave_ready_flag = false; +_static volatile bool m_slave_request_flag = false; + + +_static ser_phy_events_handler_t m_callback_events_handler = NULL; +_static ser_phy_spi_master_state_t m_spi_master_state = SER_PHY_STATE_DISABLED; + +static void ser_phy_switch_state(ser_phy_event_source_t evt_src); + +static void spi_master_raw_assert(bool cond) +{ + APP_ERROR_CHECK_BOOL(cond); +} + +void SW_IRQ_Handler() +{ + if (m_pend_req_flag) + { + m_pend_req_flag = false; + DEBUG_EVT_SPI_MASTER_RAW_REQUEST(0); + ser_phy_switch_state(SER_PHY_EVT_GPIO_REQ); + } + + if (m_pend_rdy_flag) + { + m_pend_rdy_flag = false; + DEBUG_EVT_SPI_MASTER_RAW_READY(0); + ser_phy_switch_state(SER_PHY_EVT_GPIO_RDY); + } + + if (m_pend_xfer_flag) + { + m_pend_xfer_flag = false; + DEBUG_EVT_SPI_MASTER_RAW_XFER_DONE(0); + ser_phy_switch_state(SER_PHY_EVT_SPI_TRANSFER_DONE); + } + + if (m_pend_rx_api_flag) + { + m_pend_rx_api_flag = false; + DEBUG_EVT_SPI_MASTER_RAW_API_CALL(0); + ser_phy_switch_state(SER_PHY_EVT_RX_API_CALL); + } + + if (m_pend_tx_api_flag) + { + m_pend_tx_api_flag = false; + DEBUG_EVT_SPI_MASTER_RAW_API_CALL(0); + ser_phy_switch_state(SER_PHY_EVT_TX_API_CALL); + } + +} + +#ifndef _SPI_5W_ +static void ser_phy_spi_master_ready(nrf_drv_gpiote_pin_t pin, + nrf_gpiote_polarity_t action) +{ + if (nrf_gpio_pin_read(pin) == 0) + { + m_slave_ready_flag = true; + m_pend_rdy_flag = true; + } + else + { + m_slave_ready_flag = false; + } + + DEBUG_EVT_SPI_MASTER_RAW_READY_EDGE((uint32_t) !m_slave_ready_flag); + SET_Pend_SW_IRQ(); +} +#endif + +static void ser_phy_spi_master_request(nrf_drv_gpiote_pin_t pin, + nrf_gpiote_polarity_t action) +{ + if (nrf_gpio_pin_read(pin) == 0) + { + m_slave_request_flag = true; + m_pend_req_flag = true; + } + else + { + m_slave_request_flag = false; + } + + DEBUG_EVT_SPI_MASTER_RAW_REQUEST_EDGE((uint32_t) !m_slave_request_flag); + SET_Pend_SW_IRQ(); +} + +/* Send event SER_PHY_EVT_TX_PKT_SENT */ +static __INLINE void callback_packet_sent() +{ + ser_phy_evt_t event; + + event.evt_type = SER_PHY_EVT_TX_PKT_SENT; + m_callback_events_handler(event); +} + +/* Send event SER_PHY_EVT_RX_PKT_DROPPED */ +static __INLINE void callback_packet_dropped() +{ + ser_phy_evt_t event; + + event.evt_type = SER_PHY_EVT_RX_PKT_DROPPED; + m_callback_events_handler(event); +} + +/* Send event SER_PHY_EVT_RX_PKT_RECEIVED */ +static __INLINE void callback_packet_received() +{ + ser_phy_evt_t event; + + event.evt_type = SER_PHY_EVT_RX_PKT_RECEIVED; + event.evt_params.rx_pkt_received.p_buffer = mp_rx_buffer; + event.evt_params.rx_pkt_received.num_of_bytes = m_rx_buf_len; + m_callback_events_handler(event); +} + +/* Send event SER_PHY_EVT_RX_BUF_REQUEST */ +static __INLINE void callback_mem_request() +{ + ser_phy_evt_t event; + + event.evt_type = SER_PHY_EVT_RX_BUF_REQUEST; + event.evt_params.rx_buf_request.num_of_bytes = m_rx_buf_len; + m_callback_events_handler(event); +} + +static __INLINE void copy_buff(uint8_t * const p_dest, uint8_t const * const p_src, uint16_t len) +{ + uint16_t index; + + for (index = 0; index < len; index++) + { + p_dest[index] = p_src[index]; + } + return; +} + +static __INLINE void buffer_release(uint8_t * * const pp_buffer, uint16_t * const p_buf_len) +{ + *pp_buffer = NULL; + *p_buf_len = 0; +} + +static uint16_t compute_current_packet_length(const uint16_t packet_length, + const uint16_t accumulated_packet_length) +{ + uint16_t current_packet_length = packet_length - accumulated_packet_length; + + if (current_packet_length > SER_PHY_SPI_5W_MTU_SIZE) + { + current_packet_length = SER_PHY_SPI_5W_MTU_SIZE; + } + + return current_packet_length; +} + +static __INLINE uint32_t header_send(const uint16_t length) +{ + uint16_t buf_len_size = uint16_encode(length, m_len_buffer); + + return spi_master_send_recv(SER_PHY_SPI_MASTER, m_len_buffer, buf_len_size, NULL, 0); +} + +static __INLINE uint32_t frame_send() +{ + uint32_t err_code; + + m_current_tx_packet_length = compute_current_packet_length(m_tx_packet_length, + m_accumulated_tx_packet_length); + err_code = + spi_master_send_recv(SER_PHY_SPI_MASTER, + &mp_tx_buffer[m_accumulated_tx_packet_length], + m_current_tx_packet_length, + NULL, + 0); + m_accumulated_tx_packet_length += m_current_tx_packet_length; + return err_code; +} + +static __INLINE uint32_t header_get() +{ + return spi_master_send_recv(SER_PHY_SPI_MASTER, NULL, 0, m_len_buffer, SER_PHY_HEADER_SIZE + 1); //add 0 byte guard when receiving +} + +static __INLINE uint32_t frame_get() +{ + uint32_t err_code; + + m_current_rx_packet_length = compute_current_packet_length(m_rx_packet_length, + m_accumulated_rx_packet_length); + + if (m_current_rx_packet_length < SER_PHY_SPI_5W_MTU_SIZE) + { + m_current_rx_packet_length++; //take into account guard byte when receiving + } + err_code = spi_master_send_recv(SER_PHY_SPI_MASTER, + NULL, + 0, + m_recv_buffer, + m_current_rx_packet_length); + return err_code; +} + +/** + * \brief Master driver main state machine + * Executed only in the context of PendSV_Handler() + * For UML graph, please refer to SDK documentation +*/ + +static void ser_phy_switch_state(ser_phy_event_source_t evt_src) +{ + uint32_t err_code = NRF_SUCCESS; + static bool m_waitForReadyFlag = false; //local scheduling flag to defer RDY events + + switch (m_spi_master_state) + { + + case SER_PHY_STATE_IDLE: + + if (evt_src == SER_PHY_EVT_GPIO_REQ) + { + m_waitForReadyFlag = false; + + if (m_slave_ready_flag) + { + m_spi_master_state = SER_PHY_STATE_TX_ZERO_HEADER; + err_code = header_send(0); + } + else + { + m_spi_master_state = SER_PHY_STATE_RX_WAIT_FOR_RDY; + } + } + else if (evt_src == SER_PHY_EVT_TX_API_CALL) + { + spi_master_raw_assert(mp_tx_buffer != NULL); //api event with tx_buffer == NULL has no sense + m_waitForReadyFlag = false; + + if (m_slave_ready_flag) + { + m_spi_master_state = SER_PHY_STATE_TX_HEADER; + err_code = header_send(m_tx_buf_len); + } + else + { + m_spi_master_state = SER_PHY_STATE_TX_WAIT_FOR_RDY; + } + } + break; + + case SER_PHY_STATE_TX_WAIT_FOR_RDY: + + if (evt_src == SER_PHY_EVT_GPIO_RDY) + { + m_spi_master_state = SER_PHY_STATE_TX_HEADER; + err_code = header_send(m_tx_buf_len); + } + break; + + case SER_PHY_STATE_RX_WAIT_FOR_RDY: + + if (evt_src == SER_PHY_EVT_GPIO_RDY) + { + m_spi_master_state = SER_PHY_STATE_TX_ZERO_HEADER; + err_code = header_send(0); + + } + break; + + case SER_PHY_STATE_TX_HEADER: + + if (evt_src == SER_PHY_EVT_SPI_TRANSFER_DONE) + { + m_tx_packet_length = m_tx_buf_len; + m_accumulated_tx_packet_length = 0; + + if (m_slave_ready_flag) + { + m_spi_master_state = SER_PHY_STATE_TX_PAYLOAD; + err_code = frame_send(); + + } + else + { + m_waitForReadyFlag = true; + } + } + else if ((evt_src == SER_PHY_EVT_GPIO_RDY) && m_waitForReadyFlag) + { + m_waitForReadyFlag = false; + m_spi_master_state = SER_PHY_STATE_TX_PAYLOAD; + err_code = frame_send(); + } + + break; + + case SER_PHY_STATE_TX_PAYLOAD: + + if (evt_src == SER_PHY_EVT_SPI_TRANSFER_DONE) + { + if (m_accumulated_tx_packet_length < m_tx_packet_length) + { + if (m_slave_ready_flag) + { + err_code = frame_send(); + } + else + { + m_waitForReadyFlag = true; + } + } + else + { + spi_master_raw_assert(m_accumulated_tx_packet_length == m_tx_packet_length); + //Release TX buffer + buffer_release(&mp_tx_buffer, &m_tx_buf_len); + callback_packet_sent(); + + if ( m_slave_request_flag) + { + if (m_slave_ready_flag) + { + m_spi_master_state = SER_PHY_STATE_TX_ZERO_HEADER; + err_code = header_send(0); + } + else + { + m_spi_master_state = SER_PHY_STATE_RX_WAIT_FOR_RDY; + } + } + else + { + m_spi_master_state = SER_PHY_STATE_IDLE; //m_Tx_buffer is NULL - have to wait for API event + } + } + } + else if ((evt_src == SER_PHY_EVT_GPIO_RDY) && m_waitForReadyFlag ) + { + m_waitForReadyFlag = false; + err_code = frame_send(); + } + + break; + + case SER_PHY_STATE_TX_ZERO_HEADER: + + if (evt_src == SER_PHY_EVT_SPI_TRANSFER_DONE) + { + if (m_slave_ready_flag) + { + m_spi_master_state = SER_PHY_STATE_RX_HEADER; + err_code = header_get(); + } + else + { + m_waitForReadyFlag = true; + } + } + else if ( (evt_src == SER_PHY_EVT_GPIO_RDY) && m_waitForReadyFlag) + { + m_waitForReadyFlag = false; + m_spi_master_state = SER_PHY_STATE_RX_HEADER; + err_code = header_get(); + } + break; + + case SER_PHY_STATE_RX_HEADER: + + if (evt_src == SER_PHY_EVT_SPI_TRANSFER_DONE) + { + m_spi_master_state = SER_PHY_STATE_MEMORY_REQUEST; + m_rx_buf_len = uint16_decode(&(m_len_buffer[1])); //skip guard when receiving + m_rx_packet_length = m_rx_buf_len; + callback_mem_request(); + } + break; + + case SER_PHY_STATE_MEMORY_REQUEST: + + if (evt_src == SER_PHY_EVT_RX_API_CALL) + { + m_accumulated_rx_packet_length = 0; + + if (m_slave_ready_flag) + { + m_spi_master_state = SER_PHY_STATE_RX_PAYLOAD; + err_code = frame_get(); + } + else + { + m_waitForReadyFlag = true; + } + } + else if ((evt_src == SER_PHY_EVT_GPIO_RDY) && m_waitForReadyFlag) + { + m_waitForReadyFlag = false; + m_spi_master_state = SER_PHY_STATE_RX_PAYLOAD; + err_code = frame_get(); + } + break; + + case SER_PHY_STATE_RX_PAYLOAD: + + if (evt_src == SER_PHY_EVT_SPI_TRANSFER_DONE) + { + if (mp_rx_buffer) + { + copy_buff(&(mp_rx_buffer[m_accumulated_rx_packet_length]), + &(m_recv_buffer[1]), + m_current_rx_packet_length - 1); //skip guard byte when receiving + } + m_accumulated_rx_packet_length += (m_current_rx_packet_length - 1); + + if (m_accumulated_rx_packet_length < m_rx_packet_length) + { + if (m_slave_ready_flag) + { + err_code = frame_get(); + } + else + { + m_waitForReadyFlag = true; + } + } + else + { + spi_master_raw_assert(m_accumulated_rx_packet_length == m_rx_packet_length); + + if (mp_rx_buffer == NULL) + { + callback_packet_dropped(); + } + else + { + callback_packet_received(); + } + //Release RX buffer + buffer_release(&mp_rx_buffer, &m_rx_buf_len); + + if ((mp_tx_buffer != NULL)) //mp_tx_buffer !=NULL, this means that API_EVT was scheduled + { + if (m_slave_ready_flag ) + { + err_code = header_send(m_tx_buf_len); + m_spi_master_state = SER_PHY_STATE_TX_HEADER; + } + else + { + m_spi_master_state = SER_PHY_STATE_TX_WAIT_FOR_RDY; + } + } + else if (m_slave_request_flag) + { + if (m_slave_ready_flag) + { + m_spi_master_state = SER_PHY_STATE_TX_ZERO_HEADER; + err_code = header_send(0); + } + else + { + m_spi_master_state = SER_PHY_STATE_RX_WAIT_FOR_RDY; + } + } + else + { + m_spi_master_state = SER_PHY_STATE_IDLE; + } + } + } + else if ( evt_src == SER_PHY_EVT_GPIO_RDY && m_waitForReadyFlag) + { + m_waitForReadyFlag = false; + err_code = frame_get(); + } + + + break; + + default: + break; + } + + + if (err_code != NRF_SUCCESS) + { + (void)err_code; + } +} + +/* SPI master event handler */ +static void ser_phy_spi_master_event_handler(spi_master_evt_t spi_master_evt) +{ + switch (spi_master_evt.type) + { + case SPI_MASTER_EVT_TRANSFER_COMPLETED: + + /* Switch state */ + m_pend_xfer_flag = true; + SET_Pend_SW_IRQ(); + + break; + + default: + break; + } +} + +static void ser_phy_init_pendSV(void) +{ + NVIC_SetPriority(SW_IRQn, APP_IRQ_PRIORITY_MID); + NVIC_EnableIRQ(SW_IRQn); +} + +static void ser_phy_init_gpiote(void) +{ + if (!nrf_drv_gpiote_is_init()) + { + (void)nrf_drv_gpiote_init(); + } + NVIC_SetPriority(GPIOTE_IRQn, APP_IRQ_PRIORITY_HIGH); + + nrf_drv_gpiote_in_config_t config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true); + /* Enable pullup to ensure high state while connectivity device is reset */ + config.pull = NRF_GPIO_PIN_PULLUP; + (void)nrf_drv_gpiote_in_init(SER_PHY_SPI_MASTER_PIN_SLAVE_REQUEST, &config, + ser_phy_spi_master_request); + nrf_drv_gpiote_in_event_enable(SER_PHY_SPI_MASTER_PIN_SLAVE_REQUEST,true); + m_slave_request_flag = !(nrf_gpio_pin_read(SER_PHY_SPI_MASTER_PIN_SLAVE_REQUEST)); + +#ifdef _SPI_5W_ + m_slave_ready_flag = true; +#else + (void)nrf_drv_gpiote_in_init(SER_PHY_SPI_MASTER_PIN_SLAVE_READY, &config, + ser_phy_spi_master_ready); + nrf_drv_gpiote_in_event_enable(SER_PHY_SPI_MASTER_PIN_SLAVE_READY,true); + m_slave_ready_flag = !(nrf_gpio_pin_read(SER_PHY_SPI_MASTER_PIN_SLAVE_READY)); +#endif + + NVIC_ClearPendingIRQ(SW_IRQn); +} + +static void ser_phy_deinit_gpiote(void) +{ + nrf_drv_gpiote_in_uninit(SER_PHY_SPI_MASTER_PIN_SLAVE_REQUEST); +#ifndef _SPI_5W_ + nrf_drv_gpiote_in_uninit(SER_PHY_SPI_MASTER_PIN_SLAVE_READY); +#endif +} + +/* ser_phy API function */ +uint32_t ser_phy_tx_pkt_send(const uint8_t * p_buffer, uint16_t num_of_bytes) +{ + if (p_buffer == NULL) + { + return NRF_ERROR_NULL; + } + + if (num_of_bytes == 0) + { + return NRF_ERROR_INVALID_PARAM; + } + + if (mp_tx_buffer != NULL) + { + return NRF_ERROR_BUSY; + } + + //ser_phy_interrupts_disable(); + CRITICAL_REGION_ENTER(); + mp_tx_buffer = (uint8_t *)p_buffer; + m_tx_buf_len = num_of_bytes; + m_pend_tx_api_flag = true; + SET_Pend_SW_IRQ(); + //ser_phy_interrupts_enable(); + CRITICAL_REGION_EXIT(); + + return NRF_SUCCESS; +} + +/* ser_phy API function */ +uint32_t ser_phy_rx_buf_set(uint8_t * p_buffer) +{ + if (m_spi_master_state != SER_PHY_STATE_MEMORY_REQUEST) + { + return NRF_ERROR_INVALID_STATE; + } + + //ser_phy_interrupts_disable(); + CRITICAL_REGION_ENTER(); + mp_rx_buffer = p_buffer; + m_pend_rx_api_flag = true; + SET_Pend_SW_IRQ(); + //ser_phy_interrupts_enable(); + CRITICAL_REGION_EXIT(); + + return NRF_SUCCESS; +} + +/* ser_phy API function */ +uint32_t ser_phy_open(ser_phy_events_handler_t events_handler) +{ + + if (m_spi_master_state != SER_PHY_STATE_DISABLED) + { + return NRF_ERROR_INVALID_STATE; + } + + if (events_handler == NULL) + { + return NRF_ERROR_NULL; + } + + uint32_t err_code = NRF_SUCCESS; + m_spi_master_state = SER_PHY_STATE_IDLE; + m_callback_events_handler = events_handler; + ser_phy_init_gpiote(); + + /* Configure SPI Master driver */ + spi_master_config_t spi_master_config; + spi_master_config.SPI_Freq = SPI_FREQUENCY_FREQUENCY_M1; + spi_master_config.SPI_Pin_SCK = SER_PHY_SPI_MASTER_PIN_SCK; + spi_master_config.SPI_Pin_MISO = SER_PHY_SPI_MASTER_PIN_MISO; + spi_master_config.SPI_Pin_MOSI = SER_PHY_SPI_MASTER_PIN_MOSI; + spi_master_config.SPI_Pin_SS = SER_PHY_SPI_MASTER_PIN_SLAVE_SELECT; + spi_master_config.SPI_ORDER = SPI_CONFIG_ORDER_LsbFirst; + spi_master_config.SPI_CPOL = SPI_CONFIG_CPOL_ActiveHigh; + spi_master_config.SPI_CPHA = SPI_CONFIG_CPHA_Leading; + + err_code = spi_master_open(SER_PHY_SPI_MASTER, &spi_master_config); + + if (err_code != NRF_SUCCESS) + { + return err_code; + } +#ifdef _SPI_5W_ + spi_5W_master_evt_handler_reg(SER_PHY_SPI_MASTER, ser_phy_spi_master_event_handler); +#else + spi_master_evt_handler_reg(SER_PHY_SPI_MASTER, ser_phy_spi_master_event_handler); +#endif + ser_phy_init_pendSV(); + + return err_code; +} + +/* ser_phy API function */ +void ser_phy_close(void) +{ + m_spi_master_state = SER_PHY_STATE_DISABLED; + + m_callback_events_handler = NULL; + + buffer_release(&mp_tx_buffer, &m_tx_buf_len); + buffer_release(&mp_rx_buffer, &m_rx_buf_len); + m_tx_packet_length = 0; + m_accumulated_tx_packet_length = 0; + m_current_tx_packet_length = 0; + m_rx_packet_length = 0; + m_accumulated_rx_packet_length = 0; + m_current_rx_packet_length = 0; + ser_phy_deinit_gpiote(); + spi_master_close(SER_PHY_SPI_MASTER); +} + +/* ser_phy API function */ +void ser_phy_interrupts_enable(void) +{ + NVIC_EnableIRQ(SW_IRQn); +} + +/* ser_phy API function */ +void ser_phy_interrupts_disable(void) +{ + NVIC_DisableIRQ(SW_IRQn); +} + + +#ifdef SER_PHY_DEBUG_APP_ENABLE + +static spi_master_raw_callback_t m_spi_master_raw_evt_callback; + +void debug_evt(spi_master_raw_evt_type_t evt, uint32_t data) +{ + if (m_spi_master_raw_evt_callback) + { + spi_master_raw_evt_t e; + e.evt = evt; + e.data = data; + m_spi_master_raw_evt_callback(e); + } +} + +void debug_init(spi_master_raw_callback_t spi_master_raw_evt_callback) +{ + m_spi_master_raw_evt_callback = spi_master_raw_evt_callback; +} + +#endif +/** @} */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_spi_5W_slave.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_spi_5W_slave.c new file mode 100644 index 0000000..88588b4 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_spi_5W_slave.c @@ -0,0 +1,644 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +/**@file + * + * @defgroup ser_phy_spi_5W_phy_driver_slave ser_phy_nrf51_spi_5W_slave.c + * @{ + * @ingroup ser_phy_spi_5W_phy_driver_slave + * + * @brief SPI_5W_RAW PHY slave driver. + */ + + +#include <stddef.h> +#include <string.h> + + +#include "boards.h" +#include "nrf_drv_spis.h" +#include "ser_phy.h" +#include "ser_config.h" +#include "nrf_gpio.h" +#include "nrf_gpiote.h" +#include "nrf_soc.h" +#include "app_error.h" +#include "app_util.h" +#include "ser_phy_config_conn.h" +#include "ser_phy_debug_conn.h" +#include "app_error.h" + +#define _static static + +#define SER_PHY_SPI_5W_MTU_SIZE SER_PHY_SPI_MTU_SIZE + +#define SER_PHY_SPI_DEF_CHARACTER 0xFF //SPI default character. Character clocked out in case of an ignored transaction +#define SER_PHY_SPI_ORC_CHARACTER 0xFF //SPI over-read character. Character clocked out after an over-read of the transmit buffer + +static nrf_drv_spis_t m_spis = NRF_DRV_SPIS_INSTANCE(SER_PHY_SPI_SLAVE_INSTANCE); + +#define _SPI_5W_ + +//SPI raw peripheral device configuration data +typedef struct +{ + int32_t pin_req; //SPI /REQ pin. -1 for not using + int32_t pin_rdy; //SPI /RDY pin. -1 for not using + int32_t ppi_rdy_ch; //SPI /RDY ppi ready channel + int32_t gpiote_rdy_ch; //SPI /RDY pin ready channel +} spi_slave_raw_trasp_cfg_t; + +/**@brief States of the SPI transaction state machine. */ +typedef enum +{ + SPI_RAW_STATE_UNKNOWN, + SPI_RAW_STATE_SETUP_HEADER, + SPI_RAW_STATE_RX_HEADER, + SPI_RAW_STATE_MEM_REQUESTED, + SPI_RAW_STATE_RX_PAYLOAD, + SPI_RAW_STATE_TX_HEADER, + SPI_RAW_STATE_TX_PAYLOAD, +} trans_state_t; + +_static spi_slave_raw_trasp_cfg_t m_spi_slave_raw_config; + +_static uint16_t m_accumulated_rx_packet_length; +_static uint16_t m_rx_packet_length; +_static uint16_t m_current_rx_frame_length; + +_static uint16_t m_accumulated_tx_packet_length; +_static uint16_t m_tx_packet_length; +_static uint16_t m_current_tx_frame_length; + +_static uint8_t m_header_rx_buffer[SER_PHY_HEADER_SIZE + 1]; // + 1 for '0' guard in SPI_5W +_static uint8_t m_header_tx_buffer[SER_PHY_HEADER_SIZE + 1]; // + 1 for '0' guard in SPI_5W + +_static uint8_t m_tx_frame_buffer[SER_PHY_SPI_5W_MTU_SIZE]; +_static uint8_t m_rx_frame_buffer[SER_PHY_SPI_5W_MTU_SIZE]; +_static uint8_t m_zero_buff[SER_PHY_SPI_5W_MTU_SIZE] = { 0 }; //ROM'able declaration - all guard bytes + +_static uint8_t * volatile m_p_rx_buffer = NULL; +_static const uint8_t * volatile m_p_tx_buffer = NULL; + +_static bool m_trash_payload_flag; +_static bool m_buffer_reqested_flag; + +_static trans_state_t m_trans_state = SPI_RAW_STATE_UNKNOWN; +_static ser_phy_events_handler_t m_ser_phy_callback = NULL; + +static void spi_slave_raw_assert(bool cond) +{ + APP_ERROR_CHECK_BOOL(cond); +} + +static void callback_ser_phy_event(ser_phy_evt_t event) +{ + if (m_ser_phy_callback) + { + m_ser_phy_callback(event); + } + return; +} + +static void callback_memory_request(uint16_t size) +{ + ser_phy_evt_t event; + + event.evt_type = SER_PHY_EVT_RX_BUF_REQUEST; + event.evt_params.rx_buf_request.num_of_bytes = size; + callback_ser_phy_event(event); + return; + +} + +static void callback_packet_received(uint8_t * pBuffer, uint16_t size) +{ + ser_phy_evt_t event; + + event.evt_type = SER_PHY_EVT_RX_PKT_RECEIVED; + event.evt_params.rx_pkt_received.num_of_bytes = size; + event.evt_params.rx_pkt_received.p_buffer = pBuffer; + callback_ser_phy_event(event); + return; +} + +static void callback_packet_dropped() +{ + ser_phy_evt_t event; + + event.evt_type = SER_PHY_EVT_RX_PKT_DROPPED; + callback_ser_phy_event(event); + return; +} + +static void callback_packet_transmitted(void) +{ + ser_phy_evt_t event; + + event.evt_type = SER_PHY_EVT_TX_PKT_SENT; + callback_ser_phy_event(event); + return; +} + +static void copy_buff(uint8_t * const p_dest, uint8_t const * const p_src, uint16_t len) +{ + uint16_t index; + + for (index = 0; index < len; index++) + { + p_dest[index] = p_src[index]; + } + return; +} + +/* Function computes current packet length */ +static uint16_t compute_current_frame_length(const uint16_t packet_length, + const uint16_t accumulated_packet_length) +{ + uint16_t current_packet_length = packet_length - accumulated_packet_length; + + if (current_packet_length > SER_PHY_SPI_5W_MTU_SIZE) + { + current_packet_length = SER_PHY_SPI_5W_MTU_SIZE; + } + + return current_packet_length; +} + +static uint32_t header_get() +{ + uint32_t err_code; + + err_code = nrf_drv_spis_buffers_set(&m_spis, + (uint8_t *) m_zero_buff, + SER_PHY_HEADER_SIZE, + m_header_rx_buffer, + SER_PHY_HEADER_SIZE); + return err_code; +} + +static uint32_t frame_get() +{ + uint32_t err_code; + + m_current_rx_frame_length = compute_current_frame_length(m_rx_packet_length, + m_accumulated_rx_packet_length); + + if (!m_trash_payload_flag) + { + err_code = + nrf_drv_spis_buffers_set(&m_spis, + (uint8_t *) m_zero_buff, + m_current_rx_frame_length, + &(m_p_rx_buffer[m_accumulated_rx_packet_length]), + m_current_rx_frame_length); + } + else + { + err_code = nrf_drv_spis_buffers_set(&m_spis, + (uint8_t *) m_zero_buff, + m_current_rx_frame_length, + m_rx_frame_buffer, + m_current_rx_frame_length); + } + return err_code; +} + +static uint32_t header_send(uint16_t len) +{ + uint32_t err_code; + + m_header_tx_buffer[0] = (uint8_t) 0; //this is guard byte + (void)uint16_encode(len, &(m_header_tx_buffer[1])); + err_code = nrf_drv_spis_buffers_set(&m_spis, + m_header_tx_buffer, + SER_PHY_HEADER_SIZE + 1, + m_header_rx_buffer, + SER_PHY_HEADER_SIZE + 1); + return err_code; +} + +static uint32_t frame_send() +{ + uint32_t err_code; + + m_current_tx_frame_length = compute_current_frame_length(m_tx_packet_length, + m_accumulated_tx_packet_length); + + if (m_current_tx_frame_length == SER_PHY_SPI_5W_MTU_SIZE) + { + m_current_tx_frame_length -= 1; //extra space for guard byte must be taken into account for MTU + } + m_tx_frame_buffer[0] = 0; //guard byte + copy_buff(&(m_tx_frame_buffer[1]), + &(m_p_tx_buffer[m_accumulated_tx_packet_length]), + m_current_tx_frame_length); + err_code = nrf_drv_spis_buffers_set(&m_spis, + m_tx_frame_buffer, + m_current_tx_frame_length + 1, + m_rx_frame_buffer, + m_current_tx_frame_length + 1); + + return err_code; +} + +static void set_ready_line(void) +{ +#ifndef _SPI_5W_ + //toggle - this should go high - but toggle is unsafe + uint32_t rdy_task = nrf_drv_gpiote_out_task_addr_get(m_spi_slave_raw_config.gpiote_rdy_ch); + *(uint32_t *)rdy_task = 1; +#endif + return; +} + +static void set_request_line(void) +{ + //active low logic - set is 0 + nrf_gpio_pin_clear(m_spi_slave_raw_config.pin_req); + DEBUG_EVT_SPI_SLAVE_RAW_REQ_SET(0); + return; +} + +static void clear_request_line(void) +{ + //active low logic - clear is 1 + nrf_gpio_pin_set(m_spi_slave_raw_config.pin_req); + DEBUG_EVT_SPI_SLAVE_RAW_REQ_CLEARED(0); + return; +} + +/** + * \brief Slave driver main state machine + * For UML graph, please refer to SDK documentation +*/ +static void spi_slave_event_handle(nrf_drv_spis_event_t event) +{ + static uint32_t err_code = NRF_SUCCESS; + static uint16_t packetLength; + + switch (m_trans_state) + { + case SPI_RAW_STATE_SETUP_HEADER: + m_trans_state = SPI_RAW_STATE_RX_HEADER; + err_code = header_get(); + break; + + case SPI_RAW_STATE_RX_HEADER: + + if (event.evt_type == NRF_DRV_SPIS_BUFFERS_SET_DONE) + { + DEBUG_EVT_SPI_SLAVE_RAW_BUFFERS_SET(0); + set_ready_line(); + } + + if (event.evt_type == NRF_DRV_SPIS_XFER_DONE) + { + DEBUG_EVT_SPI_SLAVE_RAW_RX_XFER_DONE(event.rx_amount); + spi_slave_raw_assert(event.rx_amount == SER_PHY_HEADER_SIZE); + packetLength = uint16_decode(m_header_rx_buffer); + + if (packetLength != 0 ) + { + m_trans_state = SPI_RAW_STATE_MEM_REQUESTED; + m_buffer_reqested_flag = true; + m_rx_packet_length = packetLength; + callback_memory_request(packetLength); + } + else + { + if (m_p_tx_buffer) + { + clear_request_line(); + m_trans_state = SPI_RAW_STATE_TX_HEADER; + err_code = header_send(m_tx_packet_length); + } + else + { + //there is nothing to send - zero response facilitates pooling - but perhaps, it should be assert + err_code = header_send(0); + } + } + } + + break; + + case SPI_RAW_STATE_MEM_REQUESTED: + + if (event.evt_type == NRF_DRV_SPIS_EVT_TYPE_MAX) //This is API dummy event + { + m_buffer_reqested_flag = false; + m_trans_state = SPI_RAW_STATE_RX_PAYLOAD; + m_accumulated_rx_packet_length = 0; + err_code = frame_get(); + } + break; + + + case SPI_RAW_STATE_RX_PAYLOAD: + + if (event.evt_type == NRF_DRV_SPIS_BUFFERS_SET_DONE) + { + DEBUG_EVT_SPI_SLAVE_RAW_BUFFERS_SET(0); + set_ready_line(); + } + + if (event.evt_type == NRF_DRV_SPIS_XFER_DONE) + { + DEBUG_EVT_SPI_SLAVE_RAW_RX_XFER_DONE(event.rx_amount); + spi_slave_raw_assert(event.rx_amount == m_current_rx_frame_length); + m_accumulated_rx_packet_length += m_current_rx_frame_length; + + if (m_accumulated_rx_packet_length < m_rx_packet_length ) + { + err_code = frame_get(); + } + else + { + spi_slave_raw_assert(m_accumulated_rx_packet_length == m_rx_packet_length); + m_trans_state = SPI_RAW_STATE_RX_HEADER; + err_code = header_get(); + + if (!m_trash_payload_flag) + { + callback_packet_received(m_p_rx_buffer, m_accumulated_rx_packet_length); + } + else + { + callback_packet_dropped(); + } + } + } + break; + + case SPI_RAW_STATE_TX_HEADER: + + if (event.evt_type == NRF_DRV_SPIS_BUFFERS_SET_DONE) + { + DEBUG_EVT_SPI_SLAVE_RAW_BUFFERS_SET(0); + set_ready_line(); + } + + if (event.evt_type == NRF_DRV_SPIS_XFER_DONE) + { + DEBUG_EVT_SPI_SLAVE_RAW_TX_XFER_DONE(event.tx_amount); + spi_slave_raw_assert(event.tx_amount == SER_PHY_HEADER_SIZE + 1); + m_trans_state = SPI_RAW_STATE_TX_PAYLOAD; + m_accumulated_tx_packet_length = 0; + err_code = frame_send(); + } + + break; + + case SPI_RAW_STATE_TX_PAYLOAD: + + if (event.evt_type == NRF_DRV_SPIS_BUFFERS_SET_DONE) + { + DEBUG_EVT_SPI_SLAVE_RAW_BUFFERS_SET(0); + set_ready_line(); + } + + if (event.evt_type == NRF_DRV_SPIS_XFER_DONE) + { + DEBUG_EVT_SPI_SLAVE_RAW_TX_XFER_DONE(event.tx_amount); + spi_slave_raw_assert(event.tx_amount == m_current_tx_frame_length + 1); + m_accumulated_tx_packet_length += m_current_tx_frame_length; + + if ( m_accumulated_tx_packet_length < m_tx_packet_length ) + { + err_code = frame_send(); + } + else + { + spi_slave_raw_assert(m_accumulated_tx_packet_length == m_tx_packet_length); + //clear pointer before callback + m_p_tx_buffer = NULL; + callback_packet_transmitted(); + //spi slave TX transfer is possible only when RX is ready, so return to waiting for a header + m_trans_state = SPI_RAW_STATE_RX_HEADER; + err_code = header_get(); + } + } + break; + + default: + err_code = NRF_ERROR_INVALID_STATE; + break; + } + APP_ERROR_CHECK(err_code); +} + +#ifndef _SPI_5W_ +static void spi_slave_gpiote_init(void) +{ + if (!nrf_drv_gpiote_is_init()) + { + (void)nrf_drv_gpiote_init(); + } + nrf_drv_gpiote_out_config_t config = GPIOTE_CONFIG_OUT_TASK_TOGGLE(true); + (void)nrf_drv_gpiote_out_init(m_spi_slave_raw_config.gpiote_rdy_ch, &config); + return; +} + +static void spi_slave_ppi_init(void) +{ + uint32_t rdy_task = nrf_drv_gpiote_out_task_addr_get(m_spi_slave_raw_config.gpiote_rdy_ch); + //Configure PPI channel to clear /RDY line + NRF_PPI->CH[m_spi_slave_raw_config.ppi_rdy_ch].EEP = (uint32_t)(&NRF_SPIS1->EVENTS_END); + NRF_PPI->CH[m_spi_slave_raw_config.ppi_rdy_ch].TEP = rdy_task; + + //this works only for channels 0..15 - but soft device is using 8-15 anyway + NRF_PPI->CHEN |= (1 << m_spi_slave_raw_config.ppi_rdy_ch); + return; +} +#endif + +static void spi_slave_gpio_init(void) +{ + nrf_gpio_pin_set(m_spi_slave_raw_config.pin_req); + nrf_gpio_cfg_output(m_spi_slave_raw_config.pin_req); +#ifndef _SPI_5W_ + nrf_gpio_pin_set(m_spi_slave_raw_config.pin_rdy); + nrf_gpio_cfg_output(m_spi_slave_raw_config.pin_rdy); +#endif + return; +} + +/* ser_phy API function */ +void ser_phy_interrupts_enable(void) +{ + NVIC_EnableIRQ(nrfx_get_irq_number(m_spis.p_reg)); +} + +/* ser_phy API function */ +void ser_phy_interrupts_disable(void) +{ + NVIC_DisableIRQ(nrfx_get_irq_number(m_spis.p_reg)); +} + +/* ser_phy API function */ +uint32_t ser_phy_rx_buf_set(uint8_t * p_buffer) +{ + uint32_t status = NRF_SUCCESS; + nrf_drv_spis_event_t event; + + ser_phy_interrupts_disable(); + + if (m_buffer_reqested_flag && (m_trans_state == SPI_RAW_STATE_MEM_REQUESTED)) + { + m_p_rx_buffer = p_buffer; + + if (m_p_rx_buffer) + { + m_trash_payload_flag = false; + } + else + { + m_trash_payload_flag = true; + } + + event.evt_type = NRF_DRV_SPIS_EVT_TYPE_MAX; //force transition with dummy event + event.rx_amount = 0; + event.tx_amount = 0; + spi_slave_event_handle(event); + } + else + { + status = NRF_ERROR_BUSY; + } + ser_phy_interrupts_enable(); + + return status; +} + +/* ser_phy API function */ +uint32_t ser_phy_tx_pkt_send(const uint8_t * p_buffer, uint16_t num_of_bytes) +{ + uint32_t status = NRF_SUCCESS; + + if ( p_buffer == NULL || num_of_bytes == 0) + { + return NRF_ERROR_NULL; + } + + ser_phy_interrupts_disable(); + + if ( m_p_tx_buffer == NULL) + { + m_tx_packet_length = num_of_bytes; + m_p_tx_buffer = p_buffer; + set_request_line(); + } + else + { + status = NRF_ERROR_BUSY; + } + ser_phy_interrupts_enable(); + + return status; +} + +/* ser_phy API function */ +uint32_t ser_phy_open(ser_phy_events_handler_t events_handler) +{ + uint32_t err_code; + nrf_drv_spis_config_t spi_slave_config; + nrf_drv_spis_event_t event; + + if (m_trans_state != SPI_RAW_STATE_UNKNOWN) + { + return NRF_ERROR_INVALID_STATE; + } + + if (events_handler == NULL) + { + return NRF_ERROR_NULL; + } + + //one ppi channel and one gpiote channel are used to drive RDY line + m_spi_slave_raw_config.pin_req = SER_PHY_SPI_SLAVE_REQ_PIN; + m_spi_slave_raw_config.pin_rdy = SER_PHY_SPI_SLAVE_RDY_PIN; + m_spi_slave_raw_config.ppi_rdy_ch = SER_PHY_SPI_PPI_RDY_CH; + m_spi_slave_raw_config.gpiote_rdy_ch = SER_PHY_SPI_GPIOTE_RDY_CH; + + spi_slave_gpio_init(); +#ifndef _SPI_5W_ + spi_slave_gpiote_init(); + spi_slave_ppi_init(); +#endif + + spi_slave_config.miso_pin = SER_CON_SPIS_MISO_PIN; + spi_slave_config.mosi_pin = SER_CON_SPIS_MOSI_PIN; + spi_slave_config.sck_pin = SER_CON_SPIS_SCK_PIN; + spi_slave_config.csn_pin = SER_CON_SPIS_CSN_PIN; + spi_slave_config.mode = NRF_DRV_SPIS_MODE_0; + spi_slave_config.bit_order = NRF_DRV_SPIS_BIT_ORDER_LSB_FIRST; + spi_slave_config.def = SER_PHY_SPI_DEF_CHARACTER; + spi_slave_config.orc = SER_PHY_SPI_ORC_CHARACTER; + spi_slave_config.csn_pullup = NRF_GPIO_PIN_PULLUP; + spi_slave_config.irq_priority = APP_IRQ_PRIORITY_LOWEST; + + //keep /CS high when init + nrf_gpio_cfg_input(spi_slave_config.csn_pin, NRF_GPIO_PIN_PULLUP); + + err_code = nrf_drv_spis_init(&m_spis, &spi_slave_config, spi_slave_event_handle); + APP_ERROR_CHECK(err_code); + + if (err_code == NRF_SUCCESS) + { + m_ser_phy_callback = events_handler; + + m_trans_state = SPI_RAW_STATE_SETUP_HEADER; + event.evt_type = NRF_DRV_SPIS_EVT_TYPE_MAX; //force transition for dummy event + event.rx_amount = 0; + event.tx_amount = 0; + spi_slave_event_handle(event); + + } + + return err_code; +} + +/* ser_phy API function */ +void ser_phy_close(void) +{ + nrf_drv_spis_uninit(&m_spis); + m_ser_phy_callback = NULL; + m_trans_state = SPI_RAW_STATE_UNKNOWN; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_spi_master.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_spi_master.c new file mode 100644 index 0000000..6065446 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_spi_master.c @@ -0,0 +1,804 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +/**@file + * + * @defgroup ser_phy_spi_phy_driver_master ser_phy_nrf51_spi_master.c + * @{ + * @ingroup ser_phy_spi_phy_driver_master + * + * @brief SPI_RAW PHY master driver. + */ + +#include <stdio.h> +#include "nrf_drv_gpiote.h" +#include "nrf_drv_spi.h" +#include "ser_phy.h" +#include "ser_config.h" +#include "app_util.h" +#include "app_util_platform.h" +#include "app_error.h" +#include "nrf_error.h" +#include "nrf_gpio.h" +#include "nrf_gpiote.h" +#include "boards.h" +#include "app_error.h" +#include "ser_phy_config_app.h" +#include "ser_phy_debug_app.h" + +#define notUSE_PendSV + +#ifdef USE_PendSV + +#define SW_IRQn PendSV_IRQn +#define SW_IRQ_Handler() PendSV_Handler() +#define SET_Pend_SW_IRQ() SCB->ICSR = SCB->ICSR | SCB_ICSR_PENDSVSET_Msk //NVIC_SetPendingIRQ(PendSV_IRQn) - PendSV_IRQn is a negative - does not work with CMSIS + +#else + +#define SW_IRQn SWI3_IRQn +#define SW_IRQ_Handler() SWI3_IRQHandler() +#define SET_Pend_SW_IRQ() NVIC_SetPendingIRQ(SWI3_IRQn) +#endif /* USE_PendSV */ + +typedef enum +{ + SER_PHY_STATE_IDLE = 0, + SER_PHY_STATE_TX_HEADER, + SER_PHY_STATE_TX_WAIT_FOR_RDY, + SER_PHY_STATE_TX_PAYLOAD, + SER_PHY_STATE_RX_WAIT_FOR_RDY, + SER_PHY_STATE_TX_ZERO_HEADER, + SER_PHY_STATE_RX_HEADER, + SER_PHY_STATE_MEMORY_REQUEST, + SER_PHY_STATE_RX_PAYLOAD, + SER_PHY_STATE_DISABLED +} ser_phy_spi_master_state_t; + +typedef enum +{ + SER_PHY_EVT_GPIO_RDY = 0, + SER_PHY_EVT_GPIO_REQ, + SER_PHY_EVT_SPI_TRANSFER_DONE, + SER_PHY_EVT_TX_API_CALL, + SER_PHY_EVT_RX_API_CALL +} ser_phy_event_source_t; + +#define _static static + +_static uint8_t * mp_tx_buffer = NULL; +_static uint16_t m_tx_buf_len = 0; + +_static uint8_t * mp_rx_buffer = NULL; +_static uint16_t m_rx_buf_len = 0; +_static uint8_t m_frame_buffer[SER_PHY_SPI_MTU_SIZE]; +_static uint8_t m_header_buffer[SER_PHY_HEADER_SIZE] = { 0 }; + +_static uint16_t m_tx_packet_length = 0; +_static uint16_t m_accumulated_tx_packet_length = 0; +_static uint16_t m_current_tx_packet_length = 0; + +_static uint16_t m_rx_packet_length = 0; +_static uint16_t m_accumulated_rx_packet_length = 0; +_static uint16_t m_current_rx_packet_length = 0; + +_static volatile bool m_pend_req_flag = 0; +_static volatile bool m_pend_rdy_flag = 0; +_static volatile bool m_pend_xfer_flag = 0; +_static volatile bool m_pend_rx_api_flag = 0; +_static volatile bool m_pend_tx_api_flag = 0; + +_static volatile bool m_slave_ready_flag = false; +_static volatile bool m_slave_request_flag = false; + +_static ser_phy_events_handler_t m_callback_events_handler = NULL; +_static ser_phy_spi_master_state_t m_spi_master_state = SER_PHY_STATE_DISABLED; + +_static const nrf_drv_spi_t m_spi_master = SER_PHY_SPI_MASTER_INSTANCE; + +static void ser_phy_switch_state(ser_phy_event_source_t evt_src); + +static void spi_master_raw_assert(bool cond) +{ + APP_ERROR_CHECK_BOOL(cond); +} + +void SW_IRQ_Handler() +{ + if (m_pend_req_flag) + { + m_pend_req_flag = false; + DEBUG_EVT_SPI_MASTER_RAW_REQUEST(0); + ser_phy_switch_state(SER_PHY_EVT_GPIO_REQ); + } + + if (m_pend_rdy_flag) + { + m_pend_rdy_flag = false; + DEBUG_EVT_SPI_MASTER_RAW_READY(0); + ser_phy_switch_state(SER_PHY_EVT_GPIO_RDY); + } + + if (m_pend_xfer_flag) + { + m_pend_xfer_flag = false; + DEBUG_EVT_SPI_MASTER_RAW_XFER_DONE(0); + ser_phy_switch_state(SER_PHY_EVT_SPI_TRANSFER_DONE); + } + + if (m_pend_rx_api_flag) + { + m_pend_rx_api_flag = false; + DEBUG_EVT_SPI_MASTER_RAW_API_CALL(0); + ser_phy_switch_state(SER_PHY_EVT_RX_API_CALL); + } + + if (m_pend_tx_api_flag) + { + m_pend_tx_api_flag = false; + DEBUG_EVT_SPI_MASTER_RAW_API_CALL(0); + ser_phy_switch_state(SER_PHY_EVT_TX_API_CALL); + } +} + +static void ser_phy_spi_master_ready(nrf_drv_gpiote_pin_t pin, + nrf_gpiote_polarity_t action) +{ + if (nrf_gpio_pin_read(pin) == 0) + { + m_slave_ready_flag = true; + m_pend_rdy_flag = true; + } + else + { + m_slave_ready_flag = false; + } + + DEBUG_EVT_SPI_MASTER_RAW_READY_EDGE((uint32_t) !m_slave_ready_flag); + SET_Pend_SW_IRQ(); +} + +static void ser_phy_spi_master_request(nrf_drv_gpiote_pin_t pin, + nrf_gpiote_polarity_t action) +{ + if (nrf_gpio_pin_read(pin) == 0) + { + m_slave_request_flag = true; + m_pend_req_flag = true; + } + else + { + m_slave_request_flag = false; + } + + DEBUG_EVT_SPI_MASTER_RAW_REQUEST_EDGE((uint32_t) !m_slave_request_flag); + SET_Pend_SW_IRQ(); +} + +/* Send event SER_PHY_EVT_TX_PKT_SENT */ +static __INLINE void callback_packet_sent() +{ + ser_phy_evt_t event; + + DEBUG_EVT_SPI_MASTER_PHY_TX_PKT_SENT(0); + + event.evt_type = SER_PHY_EVT_TX_PKT_SENT; + m_callback_events_handler(event); +} + +/* Send event SER_PHY_EVT_RX_PKT_DROPPED */ +static __INLINE void callback_packet_dropped() +{ + ser_phy_evt_t event; + + DEBUG_EVT_SPI_MASTER_PHY_RX_PKT_DROPPED(0); + + event.evt_type = SER_PHY_EVT_RX_PKT_DROPPED; + m_callback_events_handler(event); +} + +/* Send event SER_PHY_EVT_RX_PKT_RECEIVED */ +static __INLINE void callback_packet_received() +{ + ser_phy_evt_t event; + + DEBUG_EVT_SPI_MASTER_PHY_RX_PKT_RECEIVED(0); + + event.evt_type = SER_PHY_EVT_RX_PKT_RECEIVED; + event.evt_params.rx_pkt_received.p_buffer = mp_rx_buffer; + event.evt_params.rx_pkt_received.num_of_bytes = m_rx_buf_len; + m_callback_events_handler(event); +} + +/* Send event SER_PHY_EVT_RX_BUF_REQUEST */ +static __INLINE void callback_mem_request() +{ + ser_phy_evt_t event; + + DEBUG_EVT_SPI_MASTER_PHY_BUF_REQUEST(0); + + event.evt_type = SER_PHY_EVT_RX_BUF_REQUEST; + event.evt_params.rx_buf_request.num_of_bytes = m_rx_buf_len; + m_callback_events_handler(event); +} + +/* Release buffer */ +static __INLINE void buffer_release(uint8_t * * const pp_buffer, + uint16_t * const p_buf_len) +{ + *pp_buffer = NULL; + *p_buf_len = 0; +} + +/* Function computes current packet length */ +static uint16_t compute_current_packet_length(const uint16_t packet_length, + const uint16_t accumulated_packet_length) +{ + uint16_t current_packet_length = packet_length - accumulated_packet_length; + + if (current_packet_length > SER_PHY_SPI_MTU_SIZE) + { + current_packet_length = SER_PHY_SPI_MTU_SIZE; + } + + return current_packet_length; +} + +static __INLINE uint32_t header_send(const uint16_t length) +{ + uint8_t buf_len_size = uint16_encode(length, m_header_buffer); + + return nrf_drv_spi_transfer(&m_spi_master, m_header_buffer, buf_len_size, NULL, 0); +} + + +static __INLINE uint32_t frame_send() +{ + uint32_t err_code; + + m_current_tx_packet_length = compute_current_packet_length(m_tx_packet_length, + m_accumulated_tx_packet_length); + err_code = + nrf_drv_spi_transfer(&m_spi_master, + &mp_tx_buffer[m_accumulated_tx_packet_length], + m_current_tx_packet_length, + NULL, + 0); + m_accumulated_tx_packet_length += m_current_tx_packet_length; + return err_code; +} + +static __INLINE uint32_t header_get() +{ + return nrf_drv_spi_transfer(&m_spi_master, NULL, 0, m_header_buffer, SER_PHY_HEADER_SIZE); +} + +static __INLINE uint32_t frame_get() +{ + uint32_t err_code; + + m_current_rx_packet_length = compute_current_packet_length(m_rx_packet_length, + m_accumulated_rx_packet_length); + + if (mp_rx_buffer) + { + err_code = nrf_drv_spi_transfer(&m_spi_master, + NULL, + 0, + &(mp_rx_buffer[m_accumulated_rx_packet_length]), + m_current_rx_packet_length); + } + else + { + err_code = nrf_drv_spi_transfer(&m_spi_master, + NULL, + 0, + m_frame_buffer, + m_current_rx_packet_length); + } + return err_code; +} + + +/** + * \brief Master driver main state machine + * Executed only in the context of PendSV_Handler() + * For UML graph, please refer to SDK documentation +*/ +static void ser_phy_switch_state(ser_phy_event_source_t evt_src) +{ + uint32_t err_code = NRF_SUCCESS; + static bool m_wait_for_ready_flag = false; //local scheduling flag to defer RDY events + + switch (m_spi_master_state) + { + + case SER_PHY_STATE_IDLE: + + if (evt_src == SER_PHY_EVT_GPIO_REQ) + { + m_wait_for_ready_flag = false; + + if (m_slave_ready_flag) + { + m_spi_master_state = SER_PHY_STATE_TX_ZERO_HEADER; + err_code = header_send(0); + } + else + { + m_spi_master_state = SER_PHY_STATE_RX_WAIT_FOR_RDY; + } + } + else if (evt_src == SER_PHY_EVT_TX_API_CALL) + { + spi_master_raw_assert(mp_tx_buffer != NULL); //api event with tx_buffer == NULL has no sense + m_wait_for_ready_flag = false; + + if (m_slave_ready_flag) + { + m_spi_master_state = SER_PHY_STATE_TX_HEADER; + err_code = header_send(m_tx_buf_len); + } + else + { + m_spi_master_state = SER_PHY_STATE_TX_WAIT_FOR_RDY; + } + } + break; + + case SER_PHY_STATE_TX_WAIT_FOR_RDY: + + if (evt_src == SER_PHY_EVT_GPIO_RDY) + { + m_spi_master_state = SER_PHY_STATE_TX_HEADER; + err_code = header_send(m_tx_buf_len); + } + break; + + case SER_PHY_STATE_RX_WAIT_FOR_RDY: + + if (evt_src == SER_PHY_EVT_GPIO_RDY) + { + m_spi_master_state = SER_PHY_STATE_TX_ZERO_HEADER; + err_code = header_send(0); + + } + break; + + case SER_PHY_STATE_TX_HEADER: + + if (evt_src == SER_PHY_EVT_SPI_TRANSFER_DONE) + { + m_tx_packet_length = m_tx_buf_len; + m_accumulated_tx_packet_length = 0; + + if (m_slave_ready_flag) + { + m_spi_master_state = SER_PHY_STATE_TX_PAYLOAD; + err_code = frame_send(); + + } + else + { + m_wait_for_ready_flag = true; + } + } + else if ((evt_src == SER_PHY_EVT_GPIO_RDY) && m_wait_for_ready_flag) + { + m_wait_for_ready_flag = false; + m_spi_master_state = SER_PHY_STATE_TX_PAYLOAD; + err_code = frame_send(); + } + + break; + + case SER_PHY_STATE_TX_PAYLOAD: + + if (evt_src == SER_PHY_EVT_SPI_TRANSFER_DONE) + { + if (m_accumulated_tx_packet_length < m_tx_packet_length) + { + if (m_slave_ready_flag) + { + err_code = frame_send(); + } + else + { + m_wait_for_ready_flag = true; + } + } + else + { + spi_master_raw_assert(m_accumulated_tx_packet_length == m_tx_packet_length); + buffer_release(&mp_tx_buffer, &m_tx_buf_len); + callback_packet_sent(); + if ( m_slave_request_flag) + { + if (m_slave_ready_flag) + { + m_spi_master_state = SER_PHY_STATE_TX_ZERO_HEADER; + err_code = header_send(0); + } + else + { + m_spi_master_state = SER_PHY_STATE_RX_WAIT_FOR_RDY; + } + } + else + { + m_spi_master_state = SER_PHY_STATE_IDLE; //m_Tx_buffer is NULL - have to wait for API event + } + } + } + else if ((evt_src == SER_PHY_EVT_GPIO_RDY) && m_wait_for_ready_flag ) + { + m_wait_for_ready_flag = false; + err_code = frame_send(); + } + + break; + + case SER_PHY_STATE_TX_ZERO_HEADER: + + if (evt_src == SER_PHY_EVT_SPI_TRANSFER_DONE) + { + if (m_slave_ready_flag) + { + m_spi_master_state = SER_PHY_STATE_RX_HEADER; + err_code = header_get(); + } + else + { + m_wait_for_ready_flag = true; + } + } + else if ( (evt_src == SER_PHY_EVT_GPIO_RDY) && m_wait_for_ready_flag) + { + m_wait_for_ready_flag = false; + m_spi_master_state = SER_PHY_STATE_RX_HEADER; + err_code = header_get(); + } + break; + + case SER_PHY_STATE_RX_HEADER: + + if (evt_src == SER_PHY_EVT_SPI_TRANSFER_DONE) + { + m_spi_master_state = SER_PHY_STATE_MEMORY_REQUEST; + m_rx_buf_len = uint16_decode(m_header_buffer); + m_rx_packet_length = m_rx_buf_len; + callback_mem_request(); + + } + break; + + case SER_PHY_STATE_MEMORY_REQUEST: + + if (evt_src == SER_PHY_EVT_RX_API_CALL) + { + m_accumulated_rx_packet_length = 0; + + if (m_slave_ready_flag) + { + m_spi_master_state = SER_PHY_STATE_RX_PAYLOAD; + err_code = frame_get(); + } + else + { + m_wait_for_ready_flag = true; + } + } + else if ((evt_src == SER_PHY_EVT_GPIO_RDY) && m_wait_for_ready_flag) + { + m_wait_for_ready_flag = false; + m_spi_master_state = SER_PHY_STATE_RX_PAYLOAD; + err_code = frame_get(); + } + break; + + case SER_PHY_STATE_RX_PAYLOAD: + + if (evt_src == SER_PHY_EVT_SPI_TRANSFER_DONE) + { + m_accumulated_rx_packet_length += m_current_rx_packet_length; + + if (m_accumulated_rx_packet_length < m_rx_packet_length) + { + if (m_slave_ready_flag) + { + err_code = frame_get(); + } + else + { + m_wait_for_ready_flag = true; + } + } + else + { + spi_master_raw_assert(m_accumulated_rx_packet_length == m_rx_packet_length); + + if (mp_rx_buffer == NULL) + { + callback_packet_dropped(); + } + else + { + callback_packet_received(); + } + buffer_release(&mp_rx_buffer, &m_rx_buf_len); + if (mp_tx_buffer != NULL) //mp_tx_buffer !=NULL, this means that API_EVT was scheduled + { + if (m_slave_ready_flag ) + { + err_code = header_send(m_tx_buf_len); + m_spi_master_state = SER_PHY_STATE_TX_HEADER; + } + else + { + m_spi_master_state = SER_PHY_STATE_TX_WAIT_FOR_RDY; + } + } + else if (m_slave_request_flag) + { + if (m_slave_ready_flag) + { + m_spi_master_state = SER_PHY_STATE_TX_ZERO_HEADER; + err_code = header_send(0); + } + else + { + m_spi_master_state = SER_PHY_STATE_RX_WAIT_FOR_RDY; + } + } + else + { + m_spi_master_state = SER_PHY_STATE_IDLE; + + } + } + + } + else if ( evt_src == SER_PHY_EVT_GPIO_RDY && m_wait_for_ready_flag) + { + m_wait_for_ready_flag = false; + err_code = frame_get(); + } + break; + + default: + break; + } + + if (err_code != NRF_SUCCESS) + { + (void)err_code; + } +} + +static void ser_phy_spi_master_event_handler(nrf_drv_spi_evt_t const * p_event, + void * p_context) +{ + switch (p_event->type) + { + case NRF_DRV_SPI_EVENT_DONE: + + /* Switch state */ + m_pend_xfer_flag = true; + SET_Pend_SW_IRQ(); + + break; + + default: + break; + } +} + +static void ser_phy_init_PendSV(void) +{ + NVIC_SetPriority(SW_IRQn, APP_IRQ_PRIORITY_MID); + NVIC_EnableIRQ(SW_IRQn); +} + +static ret_code_t ser_phy_init_gpiote(void) +{ + if (!nrf_drv_gpiote_is_init()) + { + (void)nrf_drv_gpiote_init(); + } + NVIC_SetPriority(GPIOTE_IRQn, APP_IRQ_PRIORITY_HIGH); + + nrf_drv_gpiote_in_config_t config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true); + /* Enable pullup to ensure high state while connectivity device is reset */ + config.pull = NRF_GPIO_PIN_PULLUP; + ret_code_t err_code = nrf_drv_gpiote_in_init(SER_PHY_SPI_MASTER_PIN_SLAVE_REQUEST, + &config, ser_phy_spi_master_request); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + nrf_drv_gpiote_in_event_enable(SER_PHY_SPI_MASTER_PIN_SLAVE_REQUEST,true); + + err_code = nrf_drv_gpiote_in_init(SER_PHY_SPI_MASTER_PIN_SLAVE_READY, + &config, ser_phy_spi_master_ready); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + nrf_drv_gpiote_in_event_enable(SER_PHY_SPI_MASTER_PIN_SLAVE_READY,true); + + m_slave_request_flag = !(nrf_gpio_pin_read(SER_PHY_SPI_MASTER_PIN_SLAVE_REQUEST)); + m_slave_ready_flag = !(nrf_gpio_pin_read(SER_PHY_SPI_MASTER_PIN_SLAVE_READY)); + + NVIC_ClearPendingIRQ(SW_IRQn); + + return NRF_SUCCESS; +} + +static void ser_phy_deinit_gpiote(void) +{ + nrf_drv_gpiote_in_uninit(SER_PHY_SPI_MASTER_PIN_SLAVE_REQUEST); + nrf_drv_gpiote_in_uninit(SER_PHY_SPI_MASTER_PIN_SLAVE_READY); +} + +/* ser_phy API function */ +uint32_t ser_phy_tx_pkt_send(const uint8_t * p_buffer, uint16_t num_of_bytes) +{ + if (p_buffer == NULL) + { + return NRF_ERROR_NULL; + } + + if (num_of_bytes == 0) + { + return NRF_ERROR_INVALID_PARAM; + } + + if (mp_tx_buffer != NULL) + { + return NRF_ERROR_BUSY; + } + + //ser_phy_interrupts_disable(); + CRITICAL_REGION_ENTER(); + mp_tx_buffer = (uint8_t *)p_buffer; + m_tx_buf_len = num_of_bytes; + m_pend_tx_api_flag = true; + SET_Pend_SW_IRQ(); + //ser_phy_interrupts_enable(); + CRITICAL_REGION_EXIT(); + + return NRF_SUCCESS; +} +/* ser_phy API function */ +uint32_t ser_phy_rx_buf_set(uint8_t * p_buffer) +{ + if (m_spi_master_state != SER_PHY_STATE_MEMORY_REQUEST) + { + return NRF_ERROR_INVALID_STATE; + } + + //ser_phy_interrupts_disable(); + CRITICAL_REGION_ENTER(); + mp_rx_buffer = p_buffer; + m_pend_rx_api_flag = true; + SET_Pend_SW_IRQ(); + //ser_phy_interrupts_enable(); + CRITICAL_REGION_EXIT(); + + return NRF_SUCCESS; +} + +/* ser_phy API function */ +uint32_t ser_phy_open(ser_phy_events_handler_t events_handler) +{ + if (m_spi_master_state != SER_PHY_STATE_DISABLED) + { + return NRF_ERROR_INVALID_STATE; + } + + if (events_handler == NULL) + { + return NRF_ERROR_NULL; + } + + uint32_t err_code = NRF_SUCCESS; + + m_spi_master_state = SER_PHY_STATE_IDLE; + m_callback_events_handler = events_handler; + nrf_drv_spi_config_t spi_master_config = { + .sck_pin = SER_PHY_SPI_MASTER_PIN_SCK, + .mosi_pin = SER_PHY_SPI_MASTER_PIN_MOSI, + .miso_pin = SER_PHY_SPI_MASTER_PIN_MISO, + .ss_pin = SER_PHY_SPI_MASTER_PIN_SLAVE_SELECT, + .irq_priority = APP_IRQ_PRIORITY_MID, + .orc = 0, + .frequency = SER_PHY_SPI_FREQUENCY, + .mode = NRF_DRV_SPI_MODE_0, + .bit_order = NRF_DRV_SPI_BIT_ORDER_LSB_FIRST, + }; + err_code = nrf_drv_spi_init(&m_spi_master, + &spi_master_config, + ser_phy_spi_master_event_handler, + NULL); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + + err_code = ser_phy_init_gpiote(); + ser_phy_init_PendSV(); + return err_code; +} + +/* ser_phy API function */ +void ser_phy_close(void) +{ + m_spi_master_state = SER_PHY_STATE_DISABLED; + + m_callback_events_handler = NULL; + + buffer_release(&mp_tx_buffer, &m_tx_buf_len); + buffer_release(&mp_rx_buffer, &m_rx_buf_len); + + m_tx_packet_length = 0; + m_accumulated_tx_packet_length = 0; + m_current_tx_packet_length = 0; + + m_rx_packet_length = 0; + m_accumulated_rx_packet_length = 0; + m_current_rx_packet_length = 0; + + ser_phy_deinit_gpiote(); + nrf_drv_spi_uninit(&m_spi_master); +} + +/* ser_phy API function */ +/* only PendSV may interact with ser_phy layer, other interrupts are internal */ +void ser_phy_interrupts_enable(void) +{ + NVIC_EnableIRQ(SW_IRQn); +} + +/* ser_phy API function */ +void ser_phy_interrupts_disable(void) +{ + NVIC_DisableIRQ(SW_IRQn); +} + +/** @} */ diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_spi_slave.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_spi_slave.c new file mode 100644 index 0000000..cde0250 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_spi_slave.c @@ -0,0 +1,613 @@ +/** + * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +/**@file + * + * @defgroup ser_phy_spi_phy_driver_slave ser_phy_nrf51_spi_slave.c + * @{ + * @ingroup ser_phy_spi_phy_driver_slave + * + * @brief SPI_RAW PHY slave driver. + */ + +#include <stddef.h> +#include <string.h> + +#include "app_error.h" +#include "app_util.h" +#include "boards.h" +#include "nrf_gpio.h" +#include "nrf_drv_gpiote.h" +#include "nrf_soc.h" +#include "nrf_drv_spis.h" +#include "ser_config.h" +#include "ser_phy.h" +#include "ser_phy_config_conn.h" +#include "ser_phy_debug_conn.h" + +#define SER_PHY_SPI_DEF_CHARACTER 0xFF //SPI default character. Character clocked out in case of an ignored transaction +#define SER_PHY_SPI_ORC_CHARACTER 0xFF //SPI over-read character. Character clocked out after an over-read of the transmit buffer + +static nrf_drv_spis_t m_spis = NRF_DRV_SPIS_INSTANCE(SER_PHY_SPI_SLAVE_INSTANCE); + +#ifdef NRF_SPIS0 +#define SPI_SLAVE_REG NRF_SPIS0 +#else +#define SPI_SLAVE_REG NRF_SPIS1 +#endif + +//SPI raw peripheral device configuration data +typedef struct +{ + int32_t pin_req; //SPI /REQ pin. -1 for not using + int32_t pin_rdy; //SPI /RDY pin. -1 for not using + int32_t ppi_rdy_ch; //SPI /RDY ppi ready channel + int32_t gpiote_rdy_ch; //SPI /RDY pin ready channel +} spi_slave_raw_trasp_cfg_t; + +/**@brief States of the SPI transaction state machine. */ +typedef enum +{ + SPI_RAW_STATE_UNKNOWN, + SPI_RAW_STATE_SETUP_HEADER, + SPI_RAW_STATE_RX_HEADER, + SPI_RAW_STATE_MEM_REQUESTED, + SPI_RAW_STATE_RX_PAYLOAD, + SPI_RAW_STATE_TX_HEADER, + SPI_RAW_STATE_TX_PAYLOAD, +} trans_state_t; + +#define _static static + +static spi_slave_raw_trasp_cfg_t m_spi_slave_raw_config; + +_static uint16_t m_accumulated_rx_packet_length; +_static uint16_t m_rx_packet_length; +_static uint16_t m_current_rx_frame_length; + +_static uint16_t m_accumulated_tx_packet_length; +_static uint16_t m_tx_packet_length; +_static uint16_t m_current_tx_frame_length; + +_static uint8_t m_header_rx_buffer[SER_PHY_HEADER_SIZE]; +_static uint8_t m_header_tx_buffer[SER_PHY_HEADER_SIZE]; + +_static uint8_t m_frame_buffer[SER_PHY_SPI_MTU_SIZE]; //trash storage +_static uint8_t m_zero_buffer[SER_PHY_SPI_MTU_SIZE] = { 0 }; //ROM'able declaration + +_static uint8_t * volatile m_p_rx_buffer = NULL; +_static const uint8_t * volatile m_p_tx_buffer = NULL; + +_static bool m_trash_payload_flag; +_static bool m_buffer_reqested_flag; + +_static trans_state_t m_trans_state = SPI_RAW_STATE_UNKNOWN; +_static ser_phy_events_handler_t m_ser_phy_callback = NULL; + +static void spi_slave_raw_assert(bool cond) +{ + APP_ERROR_CHECK_BOOL(cond); +} + +static void callback_ser_phy_event(ser_phy_evt_t event) +{ + if (m_ser_phy_callback) + { + m_ser_phy_callback(event); + } +} + +static void callback_memory_request(uint16_t size) +{ + ser_phy_evt_t event; + + DEBUG_EVT_SPI_SLAVE_PHY_BUF_REQUEST(0); + + event.evt_type = SER_PHY_EVT_RX_BUF_REQUEST; + event.evt_params.rx_buf_request.num_of_bytes = size; + callback_ser_phy_event(event); +} + +static void callback_packet_received(uint8_t * pBuffer, uint16_t size) +{ + ser_phy_evt_t event; + + DEBUG_EVT_SPI_SLAVE_PHY_PKT_RECEIVED(0); + + event.evt_type = SER_PHY_EVT_RX_PKT_RECEIVED; + event.evt_params.rx_pkt_received.num_of_bytes = size; + event.evt_params.rx_pkt_received.p_buffer = pBuffer; + callback_ser_phy_event(event); +} + +static void callback_packet_dropped() +{ + ser_phy_evt_t event; + + DEBUG_EVT_SPI_SLAVE_PHY_PKT_DROPPED(0); + + event.evt_type = SER_PHY_EVT_RX_PKT_DROPPED; + callback_ser_phy_event(event); +} + +static void callback_packet_transmitted(void) +{ + ser_phy_evt_t event; + + DEBUG_EVT_SPI_SLAVE_PHY_PKT_SENT(0); + + event.evt_type = SER_PHY_EVT_TX_PKT_SENT; + callback_ser_phy_event(event); +} + +/* Function computes current packet length */ +static uint16_t compute_current_frame_length(const uint16_t packet_length, + const uint16_t accumulated_packet_length) +{ + uint16_t current_packet_length = packet_length - accumulated_packet_length; + + if (current_packet_length > SER_PHY_SPI_MTU_SIZE) + { + current_packet_length = SER_PHY_SPI_MTU_SIZE; + } + + return current_packet_length; +} + +static uint32_t header_get() +{ + uint32_t err_code; + + err_code = nrf_drv_spis_buffers_set(&m_spis, + (uint8_t *) m_zero_buffer, + SER_PHY_HEADER_SIZE, + m_header_rx_buffer, + SER_PHY_HEADER_SIZE); + return err_code; +} + +static uint32_t frame_get() +{ + uint32_t err_code; + + m_current_rx_frame_length = compute_current_frame_length(m_rx_packet_length, + m_accumulated_rx_packet_length); + + if (!m_trash_payload_flag) + { + err_code = + nrf_drv_spis_buffers_set(&m_spis, + (uint8_t *) m_zero_buffer, + m_current_rx_frame_length, + &(m_p_rx_buffer[m_accumulated_rx_packet_length]), + m_current_rx_frame_length); + } + else + { + err_code = nrf_drv_spis_buffers_set(&m_spis, + (uint8_t *) m_zero_buffer, + m_current_rx_frame_length, + m_frame_buffer, + m_current_rx_frame_length); + } + return err_code; +} + +static uint32_t header_send(uint16_t len) +{ + uint32_t err_code; + + (void) uint16_encode(len, m_header_tx_buffer); + err_code = + nrf_drv_spis_buffers_set(&m_spis, + m_header_tx_buffer, + sizeof (m_header_tx_buffer), + m_header_rx_buffer, + sizeof (m_header_tx_buffer)); + return err_code; +} + +static uint32_t frame_send() +{ + uint32_t err_code; + + m_current_tx_frame_length = compute_current_frame_length(m_tx_packet_length, + m_accumulated_tx_packet_length); + err_code = + nrf_drv_spis_buffers_set(&m_spis, + (uint8_t *) &(m_p_tx_buffer[m_accumulated_tx_packet_length]), + m_current_tx_frame_length, + m_frame_buffer, + m_current_tx_frame_length); + return err_code; +} + +static void set_ready_line(void) +{ + //toggle - this should go high - but toggle is unsafe + uint32_t rdy_task = nrf_drv_gpiote_out_task_addr_get(m_spi_slave_raw_config.pin_rdy); + *(uint32_t *)rdy_task = 1; + return; +} + +static void set_request_line(void) +{ + //active low logic - set is 0 + nrf_gpio_pin_clear(m_spi_slave_raw_config.pin_req); + DEBUG_EVT_SPI_SLAVE_RAW_REQ_SET(0); +} + +static void clear_request_line(void) +{ + //active low logic - clear is 1 + nrf_gpio_pin_set(m_spi_slave_raw_config.pin_req); + DEBUG_EVT_SPI_SLAVE_RAW_REQ_SET(0); +} + +/** + * \brief Slave driver main state machine + * For UML graph, please refer to SDK documentation +*/ +static void spi_slave_event_handle(nrf_drv_spis_event_t event) +{ + uint32_t err_code = NRF_SUCCESS; + static uint16_t packetLength; + + switch (m_trans_state) + { + case SPI_RAW_STATE_SETUP_HEADER: + m_trans_state = SPI_RAW_STATE_RX_HEADER; + err_code = header_get(); + break; + + case SPI_RAW_STATE_RX_HEADER: + + if (event.evt_type == NRF_DRV_SPIS_BUFFERS_SET_DONE) + { + DEBUG_EVT_SPI_SLAVE_RAW_BUFFERS_SET(0); + set_ready_line(); + } + + if (event.evt_type == NRF_DRV_SPIS_XFER_DONE) + { + DEBUG_EVT_SPI_SLAVE_RAW_RX_XFER_DONE(event.rx_amount); + spi_slave_raw_assert(event.rx_amount == SER_PHY_HEADER_SIZE); + packetLength = uint16_decode(m_header_rx_buffer); + + if (packetLength != 0 ) + { + m_trans_state = SPI_RAW_STATE_MEM_REQUESTED; + m_buffer_reqested_flag = true; + m_rx_packet_length = packetLength; + callback_memory_request(packetLength); + } + else + { + if (m_p_tx_buffer) + { + clear_request_line(); + m_trans_state = SPI_RAW_STATE_TX_HEADER; + err_code = header_send(m_tx_packet_length); + } + else + { + //there is nothing to send - zero response facilitates pooling - but perhaps, it should be assert + err_code = header_send(0); + } + } + } + + break; + + case SPI_RAW_STATE_MEM_REQUESTED: + + if (event.evt_type == NRF_DRV_SPIS_EVT_TYPE_MAX) //This is API dummy event + { + m_buffer_reqested_flag = false; + m_trans_state = SPI_RAW_STATE_RX_PAYLOAD; + m_accumulated_rx_packet_length = 0; + err_code = frame_get(); + } + break; + + case SPI_RAW_STATE_RX_PAYLOAD: + + if (event.evt_type == NRF_DRV_SPIS_BUFFERS_SET_DONE) + { + DEBUG_EVT_SPI_SLAVE_RAW_BUFFERS_SET(0); + set_ready_line(); + } + + if (event.evt_type == NRF_DRV_SPIS_XFER_DONE) + { + DEBUG_EVT_SPI_SLAVE_RAW_RX_XFER_DONE(event.rx_amount); + spi_slave_raw_assert(event.rx_amount == m_current_rx_frame_length); + m_accumulated_rx_packet_length += m_current_rx_frame_length; + + if (m_accumulated_rx_packet_length < m_rx_packet_length ) + { + err_code = frame_get(); + } + else + { + spi_slave_raw_assert(m_accumulated_rx_packet_length == m_rx_packet_length); + m_trans_state = SPI_RAW_STATE_RX_HEADER; + err_code = header_get(); + + if (!m_trash_payload_flag) + { + callback_packet_received(m_p_rx_buffer, m_accumulated_rx_packet_length); + } + else + { + callback_packet_dropped(); + } + } + } + break; + + case SPI_RAW_STATE_TX_HEADER: + + if (event.evt_type == NRF_DRV_SPIS_BUFFERS_SET_DONE) + { + DEBUG_EVT_SPI_SLAVE_RAW_BUFFERS_SET(0); + set_ready_line(); + } + + if (event.evt_type == NRF_DRV_SPIS_XFER_DONE) + { + DEBUG_EVT_SPI_SLAVE_RAW_TX_XFER_DONE(event.tx_amount); + spi_slave_raw_assert(event.tx_amount == SER_PHY_HEADER_SIZE); + m_trans_state = SPI_RAW_STATE_TX_PAYLOAD; + m_accumulated_tx_packet_length = 0; + err_code = frame_send(); + } + + break; + + case SPI_RAW_STATE_TX_PAYLOAD: + + if (event.evt_type == NRF_DRV_SPIS_BUFFERS_SET_DONE) + { + DEBUG_EVT_SPI_SLAVE_RAW_BUFFERS_SET(0); + set_ready_line(); + } + + if (event.evt_type == NRF_DRV_SPIS_XFER_DONE) + { + DEBUG_EVT_SPI_SLAVE_RAW_TX_XFER_DONE(event.tx_amount); + spi_slave_raw_assert(event.tx_amount == m_current_tx_frame_length); + m_accumulated_tx_packet_length += m_current_tx_frame_length; + + if ( m_accumulated_tx_packet_length < m_tx_packet_length ) + { + err_code = frame_send(); + } + else + { + spi_slave_raw_assert(m_accumulated_tx_packet_length == m_tx_packet_length); + //clear pointer before callback + m_p_tx_buffer = NULL; + callback_packet_transmitted(); + //spi slave TX transfer is possible only when RX is ready, so return to waiting for a header + m_trans_state = SPI_RAW_STATE_RX_HEADER; + err_code = header_get(); + } + } + break; + + default: + err_code = NRF_ERROR_INVALID_STATE; + break; + } + APP_ERROR_CHECK(err_code); +} + +static void spi_slave_gpiote_init(void) +{ + if (!nrf_drv_gpiote_is_init()) + { + (void)nrf_drv_gpiote_init(); + } + nrf_drv_gpiote_out_config_t config = GPIOTE_CONFIG_OUT_TASK_TOGGLE(true); + (void) nrf_drv_gpiote_out_init(m_spi_slave_raw_config.pin_rdy, &config); + (void) nrf_drv_gpiote_out_task_enable(m_spi_slave_raw_config.pin_rdy); + return; +} + +static void spi_slave_ppi_init(void) +{ + uint32_t rdy_task = nrf_drv_gpiote_out_task_addr_get(m_spi_slave_raw_config.pin_rdy); + //Configure PPI channel to clear /RDY line + NRF_PPI->CH[m_spi_slave_raw_config.ppi_rdy_ch].EEP = (uint32_t)(&SPI_SLAVE_REG->EVENTS_END); + NRF_PPI->CH[m_spi_slave_raw_config.ppi_rdy_ch].TEP = rdy_task; + + //this works only for channels 0..15 - but soft device is using 8-15 anyway + NRF_PPI->CHEN |= (1 << m_spi_slave_raw_config.ppi_rdy_ch); + return; +} + +static void spi_slave_gpio_init(void) +{ + nrf_gpio_pin_set(m_spi_slave_raw_config.pin_req); + nrf_gpio_cfg_output(m_spi_slave_raw_config.pin_req); + nrf_gpio_pin_set(m_spi_slave_raw_config.pin_rdy); + nrf_gpio_cfg_output(m_spi_slave_raw_config.pin_rdy); +} + +/* ser_phy API function */ +void ser_phy_interrupts_enable(void) +{ + (void)sd_nvic_EnableIRQ(nrfx_get_irq_number(m_spis.p_reg)); +} + +/* ser_phy API function */ +void ser_phy_interrupts_disable(void) +{ + (void)sd_nvic_DisableIRQ(nrfx_get_irq_number(m_spis.p_reg)); +} + +/* ser_phy API function */ +uint32_t ser_phy_rx_buf_set(uint8_t * p_buffer) +{ + uint32_t status = NRF_SUCCESS; + nrf_drv_spis_event_t event; + + ser_phy_interrupts_disable(); + + if (m_buffer_reqested_flag && (m_trans_state == SPI_RAW_STATE_MEM_REQUESTED)) + { + m_p_rx_buffer = p_buffer; + + if (m_p_rx_buffer) + { + m_trash_payload_flag = false; + } + else + { + m_trash_payload_flag = true; + } + event.evt_type = NRF_DRV_SPIS_EVT_TYPE_MAX; //force transition with dummy event + event.rx_amount = 0; + event.tx_amount = 0; + spi_slave_event_handle(event); + } + else + { + status = NRF_ERROR_BUSY; + } + ser_phy_interrupts_enable(); + + return status; +} + +/* ser_phy API function */ +uint32_t ser_phy_tx_pkt_send(const uint8_t * p_buffer, uint16_t num_of_bytes) +{ + uint32_t status = NRF_SUCCESS; + + if ( p_buffer == NULL || num_of_bytes == 0) + { + return NRF_ERROR_NULL; + } + + ser_phy_interrupts_disable(); + + if ( m_p_tx_buffer == NULL) + { + m_tx_packet_length = num_of_bytes; + m_p_tx_buffer = p_buffer; + set_request_line(); + } + else + { + status = NRF_ERROR_BUSY; + } + ser_phy_interrupts_enable(); + + return status; +} + +/* ser_phy API function */ +uint32_t ser_phy_open(ser_phy_events_handler_t events_handler) +{ + uint32_t err_code; + nrf_drv_spis_config_t spi_slave_config; + nrf_drv_spis_event_t event; + + if (m_trans_state != SPI_RAW_STATE_UNKNOWN) + { + return NRF_ERROR_INVALID_STATE; + } + + if (events_handler == NULL) + { + return NRF_ERROR_NULL; + } + + //one ppi channel and one gpiote channel are used to drive RDY line + m_spi_slave_raw_config.pin_req = SER_PHY_SPI_SLAVE_REQ_PIN; + m_spi_slave_raw_config.pin_rdy = SER_PHY_SPI_SLAVE_RDY_PIN; + m_spi_slave_raw_config.ppi_rdy_ch = SER_PHY_SPI_PPI_RDY_CH; + m_spi_slave_raw_config.gpiote_rdy_ch = SER_PHY_SPI_GPIOTE_RDY_CH; + + spi_slave_gpio_init(); + spi_slave_gpiote_init(); + spi_slave_ppi_init(); + + spi_slave_config.miso_pin = SER_PHY_SPI_SLAVE_MISO_PIN; + spi_slave_config.mosi_pin = SER_PHY_SPI_SLAVE_MOSI_PIN; + spi_slave_config.sck_pin = SER_PHY_SPI_SLAVE_SCK_PIN; + spi_slave_config.csn_pin = SER_PHY_SPI_SLAVE_SS_PIN; + spi_slave_config.mode = NRF_DRV_SPIS_MODE_0; + spi_slave_config.bit_order = NRF_DRV_SPIS_BIT_ORDER_LSB_FIRST; + spi_slave_config.def = SER_PHY_SPI_DEF_CHARACTER; + spi_slave_config.orc = SER_PHY_SPI_ORC_CHARACTER; + spi_slave_config.irq_priority = APP_IRQ_PRIORITY_LOWEST; + spi_slave_config.miso_drive = NRF_DRV_SPIS_DEFAULT_MISO_DRIVE; + //use /CS pullup because state of the line might be undefined when master redefines PIO lines + spi_slave_config.csn_pullup = NRF_GPIO_PIN_PULLUP; + + //keep /CS high when init + nrf_gpio_cfg_input(spi_slave_config.csn_pin, NRF_GPIO_PIN_PULLUP); + + err_code = nrf_drv_spis_init(&m_spis, &spi_slave_config, spi_slave_event_handle); + APP_ERROR_CHECK(err_code); + + if (err_code == NRF_SUCCESS) + { + m_ser_phy_callback = events_handler; + + m_trans_state = SPI_RAW_STATE_SETUP_HEADER; + event.evt_type = NRF_DRV_SPIS_EVT_TYPE_MAX; //force transition for dummy event + event.rx_amount = 0; + event.tx_amount = 0; + spi_slave_event_handle(event); + + } + return err_code; +} + +/* ser_phy API function */ +void ser_phy_close(void) +{ + nrf_drv_spis_uninit(&m_spis); + m_ser_phy_callback = NULL; + m_trans_state = SPI_RAW_STATE_UNKNOWN; +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_uart.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_uart.c new file mode 100644 index 0000000..d690ac7 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy/ser_phy_uart.c @@ -0,0 +1,357 @@ +/** + * 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 "ser_phy.h" +#include "ser_config.h" +#ifdef SER_CONNECTIVITY + #include "ser_phy_config_conn.h" +#else + #include "ser_phy_config_app.h" +#endif +#include "nrf_drv_uart.h" +#include "app_error.h" +#include "app_util.h" +#include "app_util_platform.h" + +#define UART_TRANSFER_MAX 255 + +#if defined(UARTE_PRESENT) && !defined(UART_PRESENT) +#define SER_UART_IRQ UARTE0_IRQn +#else +#define SER_UART_IRQ UART0_IRQn +#endif + +static const nrf_drv_uart_t m_uart = NRF_DRV_UART_INSTANCE(0); +static const nrf_drv_uart_config_t m_uart_config = { + .pseltxd = SER_PHY_UART_TX, + .pselrxd = SER_PHY_UART_RX, + .pselrts = SER_PHY_UART_RTS, + .pselcts = SER_PHY_UART_CTS, + .p_context = NULL, + .interrupt_priority = UART_IRQ_PRIORITY, +#if defined(UARTE_PRESENT) && defined(UART_PRESENT) + .use_easy_dma = true, +#endif + // These values are common for application and connectivity, they are + // defined in "ser_config.h". + .hwfc = SER_PHY_UART_FLOW_CTRL, + .parity = SER_PHY_UART_PARITY, + .baudrate = (nrf_uart_baudrate_t)SER_PHY_UART_BAUDRATE +}; + +static bool volatile m_tx_in_progress; +static uint8_t m_tx_header_buf[SER_PHY_HEADER_SIZE]; +static uint16_t m_bytes_to_transmit; +static uint8_t const * mp_tx_buffer; + +static uint8_t m_rx_header_buf[SER_PHY_HEADER_SIZE]; +static uint16_t m_bytes_to_receive; +static uint8_t m_rx_drop_buf[1]; + +static ser_phy_events_handler_t m_ser_phy_event_handler; +static ser_phy_evt_t m_ser_phy_rx_event; + + +static void packet_sent_callback(void) +{ + static ser_phy_evt_t const event = { + .evt_type = SER_PHY_EVT_TX_PKT_SENT, + }; + m_ser_phy_event_handler(event); +} + +static void buffer_request_callback(uint16_t num_of_bytes) +{ + m_ser_phy_rx_event.evt_type = SER_PHY_EVT_RX_BUF_REQUEST; + m_ser_phy_rx_event.evt_params.rx_buf_request.num_of_bytes = num_of_bytes; + m_ser_phy_event_handler(m_ser_phy_rx_event); +} + +static void packet_received_callback(void) +{ + m_ser_phy_event_handler(m_ser_phy_rx_event); +} + +static void packet_dropped_callback(void) +{ + static ser_phy_evt_t const event = { + .evt_type = SER_PHY_EVT_RX_PKT_DROPPED, + }; + m_ser_phy_event_handler(event); +} + +static void hardware_error_callback(uint32_t hw_error) +{ + ser_phy_evt_t event = { + .evt_type = SER_PHY_EVT_HW_ERROR, + .evt_params.hw_error.error_code = hw_error, + }; + m_ser_phy_event_handler(event); +} + +static void packet_rx_start(void) +{ + APP_ERROR_CHECK(nrf_drv_uart_rx(&m_uart, m_rx_header_buf, + SER_PHY_HEADER_SIZE)); +} + +static void packet_byte_drop(void) +{ + APP_ERROR_CHECK(nrf_drv_uart_rx(&m_uart, m_rx_drop_buf, 1)); +} + +static void uart_event_handler(nrf_drv_uart_event_t * p_event, + void * p_context) +{ + (void)p_context; + + switch (p_event->type) + { + case NRF_DRV_UART_EVT_ERROR: + // Process the error only if this is a parity or overrun error. + // Break and framing errors will always occur before the other + // side becomes active. + if (p_event->data.error.error_mask & + (NRF_UART_ERROR_PARITY_MASK | NRF_UART_ERROR_OVERRUN_MASK)) + { + // Pass error source to upper layer. + hardware_error_callback(p_event->data.error.error_mask); + } + + packet_rx_start(); + break; + + case NRF_DRV_UART_EVT_TX_DONE: + if (p_event->data.rxtx.p_data == m_tx_header_buf) + { +#if (SER_HAL_TRANSPORT_TX_MAX_PKT_SIZE > UART_TRANSFER_MAX) + if (m_bytes_to_transmit > UART_TRANSFER_MAX) + { + APP_ERROR_CHECK(nrf_drv_uart_tx(&m_uart, mp_tx_buffer, + UART_TRANSFER_MAX)); + } + else +#endif // (SER_HAL_TRANSPORT_TX_MAX_PKT_SIZE > UART_TRANSFER_MAX) + { + APP_ERROR_CHECK(nrf_drv_uart_tx(&m_uart, mp_tx_buffer, + m_bytes_to_transmit)); + } + } + else + { +#if (SER_HAL_TRANSPORT_TX_MAX_PKT_SIZE > UART_TRANSFER_MAX) + ASSERT(p_event->data.rxtx.bytes <= m_bytes_to_transmit); + m_bytes_to_transmit -= p_event->data.rxtx.bytes; + if (m_bytes_to_transmit != 0) + { + APP_ERROR_CHECK(nrf_drv_uart_tx(&m_uart, + p_event->data.rxtx.p_data + p_event->data.rxtx.bytes, + m_bytes_to_transmit < UART_TRANSFER_MAX ? + m_bytes_to_transmit : UART_TRANSFER_MAX)); + } + else +#endif // (SER_HAL_TRANSPORT_TX_MAX_PKT_SIZE > UART_TRANSFER_MAX) + { + m_tx_in_progress = false; + packet_sent_callback(); + } + } + break; + + case NRF_DRV_UART_EVT_RX_DONE: + if (p_event->data.rxtx.p_data == m_rx_header_buf) + { + m_bytes_to_receive = uint16_decode(m_rx_header_buf); + buffer_request_callback(m_bytes_to_receive); + } + else if (p_event->data.rxtx.p_data == m_rx_drop_buf) + { + --m_bytes_to_receive; + if (m_bytes_to_receive != 0) + { + packet_byte_drop(); + } + else + { + packet_dropped_callback(); + + packet_rx_start(); + } + } + else + { +#if (SER_HAL_TRANSPORT_RX_MAX_PKT_SIZE > UART_TRANSFER_MAX) + ASSERT(p_event->data.rxtx.bytes <= m_bytes_to_receive); + m_bytes_to_receive -= p_event->data.rxtx.bytes; + if (m_bytes_to_receive != 0) + { + APP_ERROR_CHECK(nrf_drv_uart_rx(&m_uart, + p_event->data.rxtx.p_data + p_event->data.rxtx.bytes, + m_bytes_to_receive < UART_TRANSFER_MAX ? + m_bytes_to_receive : UART_TRANSFER_MAX)); + } + else +#endif // (SER_HAL_TRANSPORT_RX_MAX_PKT_SIZE > UART_TRANSFER_MAX) + { + packet_received_callback(); + + packet_rx_start(); + } + } + break; + + default: + APP_ERROR_CHECK(NRF_ERROR_INTERNAL); + } +} + +/** API FUNCTIONS */ + +uint32_t ser_phy_open(ser_phy_events_handler_t events_handler) +{ + uint32_t err_code; + + if (events_handler == NULL) + { + return NRF_ERROR_NULL; + } + + // Check if function was not called before. + if (m_ser_phy_event_handler != NULL) + { + return NRF_ERROR_INVALID_STATE; + } + + err_code = nrf_drv_uart_init(&m_uart, &m_uart_config, uart_event_handler); + if (err_code != NRF_SUCCESS) + { + return NRF_ERROR_INVALID_PARAM; + } + + m_ser_phy_event_handler = events_handler; + + packet_rx_start(); + + return err_code; +} + +uint32_t ser_phy_tx_pkt_send(const uint8_t * p_buffer, uint16_t num_of_bytes) +{ + if (p_buffer == NULL) + { + return NRF_ERROR_NULL; + } + else if (num_of_bytes == 0) + { + return NRF_ERROR_INVALID_PARAM; + } + + bool busy; + + CRITICAL_REGION_ENTER(); + busy = m_tx_in_progress; + m_tx_in_progress = true; + CRITICAL_REGION_EXIT(); + + if (busy) + { + return NRF_ERROR_BUSY; + } + + (void)uint16_encode(num_of_bytes, m_tx_header_buf); + mp_tx_buffer = p_buffer; + m_bytes_to_transmit = num_of_bytes; + APP_ERROR_CHECK(nrf_drv_uart_tx(&m_uart, m_tx_header_buf, + SER_PHY_HEADER_SIZE)); + + return NRF_SUCCESS; +} + + +uint32_t ser_phy_rx_buf_set(uint8_t * p_buffer) +{ + + if (m_ser_phy_rx_event.evt_type != SER_PHY_EVT_RX_BUF_REQUEST) + { + return NRF_ERROR_INVALID_STATE; + } + + m_ser_phy_rx_event.evt_type = SER_PHY_EVT_RX_PKT_RECEIVED; + m_ser_phy_rx_event.evt_params.rx_pkt_received.p_buffer = p_buffer; + m_ser_phy_rx_event.evt_params.rx_pkt_received.num_of_bytes = + m_bytes_to_receive; + + // If there is not enough memory to receive the packet (no buffer was + // provided), drop its data byte by byte (using an internal 1-byte buffer). + if (p_buffer == NULL) + { + packet_byte_drop(); + } +#if (SER_HAL_TRANSPORT_RX_MAX_PKT_SIZE > UART_TRANSFER_MAX) + else if (m_bytes_to_receive > UART_TRANSFER_MAX) + { + APP_ERROR_CHECK(nrf_drv_uart_rx(&m_uart, p_buffer, UART_TRANSFER_MAX)); + } +#endif // (SER_HAL_TRANSPORT_RX_MAX_PKT_SIZE > UART_TRANSFER_MAX) + else + { + APP_ERROR_CHECK(nrf_drv_uart_rx(&m_uart, p_buffer, m_bytes_to_receive)); + } + + return NRF_SUCCESS; +} + + +void ser_phy_close(void) +{ + nrf_drv_uart_uninit(&m_uart); + m_ser_phy_event_handler = NULL; +} + + +void ser_phy_interrupts_enable(void) +{ + NVIC_EnableIRQ(SER_UART_IRQ); +} + + +void ser_phy_interrupts_disable(void) +{ + NVIC_DisableIRQ(SER_UART_IRQ); +} diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy_debug_comm.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy_debug_comm.h new file mode 100644 index 0000000..4ec0697 --- /dev/null +++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/serialization/common/transport/ser_phy_debug_comm.h @@ -0,0 +1,203 @@ +/** + * 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 SER_PHY_DEBUG_COMM_H__ +#define SER_PHY_DEBUG_COMM_H__ + +#ifndef SER_PHY_HCI_DEBUG_ENABLE + +// empty definitions here +#define DEBUG_EVT_HCI_PHY_EVT_TX_PKT_SENT(data) +#define DEBUG_EVT_HCI_PHY_EVT_BUF_REQUEST(data) +#define DEBUG_EVT_HCI_PHY_EVT_RX_PKT_RECEIVED(data) +#define DEBUG_EVT_HCI_PHY_EVT_RX_PKT_DROPPED(data) +#define DEBUG_EVT_HCI_PHY_EVT_TX_ERROR(data) +#define DEBUG_EVT_SLIP_PACKET_TX(data) +#define DEBUG_EVT_SLIP_ACK_TX(data) +#define DEBUG_EVT_SLIP_PACKET_TXED(data) +#define DEBUG_EVT_SLIP_ACK_TXED(data) +#define DEBUG_EVT_SLIP_PACKET_RXED(data) +#define DEBUG_EVT_SLIP_ACK_RXED(data) +#define DEBUG_EVT_SLIP_ERR_RXED(data) +#define DEBUG_EVT_TIMEOUT(data) +#define DEBUG_HCI_RETX(data) +#define DEBUG_EVT_MAIN_BUSY(data) +#define DEBUG_EVT_TX_REQ(data) + +#else +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +//Low level hardware events +typedef enum +{ + HCI_PHY_EVT_TX_PKT_SENT, + HCI_PHY_EVT_BUF_REQUEST, + HCI_PHY_EVT_RX_PKT_RECEIVED, + HCI_PHY_EVT_RX_PKT_DROPPED, + HCI_PHY_EVT_TX_ERROR, + HCI_SLIP_EVT_PACKET_TX, + HCI_SLIP_EVT_ACK_TX, + HCI_SLIP_EVT_PACKET_TXED, + HCI_SLIP_EVT_ACK_TXED, + HCI_SLIP_EVT_PACKET_RXED, + HCI_SLIP_EVT_ACK_RXED, + HCI_SLIP_EVT_ERR_RXED, + HCI_TIMER_EVT_TIMEOUT, + HCI_RETX, + HCI_MAIN_BUSY, + HCI_TX_REQ, + HCI_PHY_EVT_MAX +} hci_dbg_evt_type_t; + + +//Low level hardware event definition +typedef struct +{ + hci_dbg_evt_type_t evt; + uint32_t data; +} hci_dbg_evt_t; + +typedef void (*hci_dbg_event_handler_t)(hci_dbg_evt_t event); + +void debug_init(hci_dbg_event_handler_t evt_callback); + +void debug_evt(hci_dbg_evt_type_t evt, uint32_t data); + + +#define DEBUG_EVT(event_type, data) \ +do { \ + debug_evt(event_type, data); \ +} while (0); + + +#define DEBUG_EVT_HCI_PHY_EVT_TX_PKT_SENT(data) \ +do { \ + DEBUG_EVT(HCI_PHY_EVT_TX_PKT_SENT, data); \ +} while (0); + + +#define DEBUG_EVT_HCI_PHY_EVT_BUF_REQUEST(data) \ +do { \ + DEBUG_EVT(HCI_PHY_EVT_BUF_REQUEST, data); \ +} while (0); + + +#define DEBUG_EVT_HCI_PHY_EVT_RX_PKT_RECEIVED(data) \ +do { \ + DEBUG_EVT(HCI_PHY_EVT_RX_PKT_RECEIVED, data); \ +} while (0); + + +#define DEBUG_EVT_HCI_PHY_EVT_RX_PKT_DROPPED(data) \ +do { \ + DEBUG_EVT(HCI_PHY_EVT_RX_PKT_DROPPED, data); \ +} while (0); + +#define DEBUG_EVT_HCI_PHY_EVT_TX_ERROR(data) \ +do { \ + DEBUG_EVT(HCI_PHY_EVT_TX_ERROR, data); \ +} while (0); + +#define DEBUG_EVT_SLIP_PACKET_TX(data) \ +do { \ + DEBUG_EVT(HCI_SLIP_EVT_PACKET_TX, data); \ +} while (0); + +#define DEBUG_EVT_SLIP_ACK_TX(data) \ +do { \ + DEBUG_EVT(HCI_SLIP_EVT_ACK_TX, data); \ +} while (0); + +#define DEBUG_EVT_SLIP_PACKET_TXED(data) \ +do { \ + DEBUG_EVT(HCI_SLIP_EVT_PACKET_TXED, data); \ +} while (0); + +#define DEBUG_EVT_SLIP_ACK_TXED(data) \ +do { \ + DEBUG_EVT(HCI_SLIP_EVT_ACK_TXED, data); \ +} while (0); + +#define DEBUG_EVT_SLIP_PACKET_RXED(data) \ +do { \ + DEBUG_EVT(HCI_SLIP_EVT_PACKET_RXED, data); \ +} while (0); + +#define DEBUG_EVT_SLIP_ACK_RXED(data) \ +do { \ + DEBUG_EVT(HCI_SLIP_EVT_ACK_RXED, data); \ +} while (0); + +#define DEBUG_EVT_SLIP_ERR_RXED(data) \ +do { \ + DEBUG_EVT(HCI_SLIP_EVT_ERR_RXED, data); \ +} while (0); + +#define DEBUG_EVT_TIMEOUT(data) \ +do { \ + DEBUG_EVT(HCI_TIMER_EVT_TIMEOUT, data); \ +} while (0); + +#define DEBUG_HCI_RETX(data) \ +do { \ + DEBUG_EVT(HCI_RETX, data); \ +} while (0); + +#define DEBUG_EVT_MAIN_BUSY(data) \ +do { \ + DEBUG_EVT(HCI_MAIN_BUSY, data); \ +} while (0); + +#define DEBUG_EVT_TX_REQ(data) \ +do { \ + DEBUG_EVT(HCI_TX_REQ, data); \ +} while (0); + +#endif // SER_PHY_HCI_DEBUG_ENABLE + + +#ifdef __cplusplus +} +#endif + +#endif // SER_PHY_DEBUG_COMM_H__ 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__ */ + +/** @} */ + |