初始版本

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

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,793 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef _CONN_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

View File

@@ -0,0 +1,84 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,89 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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;
}

View File

@@ -0,0 +1,78 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,79 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,84 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,71 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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;
}

View File

@@ -0,0 +1,89 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,73 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,97 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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;
}

View File

@@ -0,0 +1,89 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,78 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,78 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,89 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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;
}

View File

@@ -0,0 +1,78 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,89 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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;
}

View File

@@ -0,0 +1,78 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,83 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,78 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,89 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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;
}

View File

@@ -0,0 +1,73 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,107 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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;
}

View File

@@ -0,0 +1,101 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,88 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,96 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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;
}

View File

@@ -0,0 +1,84 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,79 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,88 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,55 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,75 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,114 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "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;
}

View File

@@ -0,0 +1,74 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __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

View File

@@ -0,0 +1,70 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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;
}

View File

@@ -0,0 +1,72 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __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

View File

@@ -0,0 +1,84 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,84 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,73 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,71 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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;
}

View File

@@ -0,0 +1,73 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,79 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,83 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,73 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,78 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,78 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,55 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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);
}

View File

@@ -0,0 +1,71 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "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;
}

View File

@@ -0,0 +1,83 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef _CONN_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

View File

@@ -0,0 +1,421 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "ble_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) || (NRF_SD_BLE_API_VERSION == 3))
#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 = &params;
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);
#ifndef UNIT_TEST
sd_err_code = nrf_sdh_ble_enable(p_params, &app_ram_base);
#else
sd_err_code = NRF_SUCCESS;
#endif
#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);
(void)app_ram_base;
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

View File

@@ -0,0 +1,242 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#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

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,820 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef _CONN_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
/** @} */

View File

@@ -0,0 +1,389 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "ble_gattc_conn.h"
#include "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 = &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;
}

View File

@@ -0,0 +1,259 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef _CONN_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

View File

@@ -0,0 +1,517 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "ble_gatts_conn.h"
#include "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;
}

View File

@@ -0,0 +1,314 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef _CONN_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

View File

@@ -0,0 +1,260 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "ble_l2cap_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 = &params;
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

View File

@@ -0,0 +1,206 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef _CONN_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

View File

@@ -0,0 +1,558 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "ble_conn.h"
#include "ble_serialization.h"
#include "cond_field_serialization.h"
#include "ble_struct_serialization.h"
#include "ble_gap_struct_serialization.h"
#include "ble_gatt_struct_serialization.h"
#include "ble_gattc_struct_serialization.h"
#include "ble_gatts_struct_serialization.h"
#include "ble_l2cap_struct_serialization.h"
#include "app_util.h"
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
uint32_t ble_enable_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_enable_params_t * * const pp_ble_enable_params)
{
SER_REQ_DEC_BEGIN(SD_BLE_ENABLE);
SER_PULL_COND(pp_ble_enable_params, ble_enable_params_t_dec);
SER_REQ_DEC_END;
}
#else
uint32_t ble_enable_req_dec(uint8_t const * const p_buf,
uint32_t packet_len)
{
SER_REQ_DEC_BEGIN(SD_BLE_ENABLE);
SER_REQ_DEC_END;
}
#endif
uint32_t ble_enable_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_ENABLE);
}
uint32_t ble_opt_get_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint32_t * const p_opt_id,
ble_opt_t **const pp_opt )
{
SER_REQ_DEC_BEGIN(SD_BLE_OPT_GET);
SER_ASSERT_NOT_NULL(p_opt_id);
SER_ASSERT_NOT_NULL(pp_opt);
SER_ASSERT_NOT_NULL(*pp_opt);
SER_PULL_uint32(p_opt_id);
SER_PULL_COND(pp_opt, NULL);
SER_REQ_DEC_END;
}
uint32_t ble_opt_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint32_t opt_id,
ble_opt_t const * const p_opt)
{
SER_RSP_ENC_BEGIN(SD_BLE_OPT_GET);
SER_ASSERT_NOT_NULL(p_opt);
SER_PUSH_uint32(&opt_id);
field_encoder_handler_t fp_encoder = NULL;
void const * p_struct = NULL;
switch (opt_id)
{
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
case BLE_COMMON_OPT_CONN_BW:
fp_encoder = ble_common_opt_conn_bw_t_enc;
p_struct = &p_opt->common_opt.conn_bw;
break;
#endif
case BLE_COMMON_OPT_PA_LNA:
fp_encoder = ble_common_opt_pa_lna_t_enc;
p_struct = &p_opt->common_opt.pa_lna;
break;
case BLE_COMMON_OPT_CONN_EVT_EXT:
fp_encoder = ble_common_opt_conn_evt_ext_t_enc;
p_struct = &p_opt->common_opt.conn_evt_ext;
break;
case BLE_GAP_OPT_CH_MAP:
fp_encoder = ble_gap_opt_ch_map_t_enc;
p_struct = &p_opt->gap_opt.ch_map;
break;
case BLE_GAP_OPT_LOCAL_CONN_LATENCY:
fp_encoder = ble_gap_opt_local_conn_latency_t_enc;
p_struct = &p_opt->gap_opt.local_conn_latency;
break;
case BLE_GAP_OPT_PASSKEY:
fp_encoder = ble_gap_opt_passkey_t_enc;
p_struct = &p_opt->gap_opt.passkey;
break;
case BLE_GAP_OPT_AUTH_PAYLOAD_TIMEOUT:
fp_encoder = ble_gap_opt_auth_payload_timeout_t_enc;
p_struct = &p_opt->gap_opt.auth_payload_timeout;
break;
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
case BLE_GAP_OPT_EXT_LEN:
fp_encoder = ble_gap_opt_ext_len_t_enc;
p_struct = &p_opt->gap_opt.ext_len;
break;
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 6
case BLE_GAP_OPT_SCAN_REQ_REPORT:
fp_encoder = ble_gap_opt_scan_req_report_t_enc;
p_struct = &p_opt->gap_opt.scan_req_report;
break;
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
case BLE_GAP_OPT_COMPAT_MODE:
fp_encoder = ble_gap_opt_compat_mode_t_enc;
p_struct = &p_opt->gap_opt.compat_mode;
break;
#else
#ifndef S112
case BLE_GAP_OPT_COMPAT_MODE_1:
fp_encoder = ble_gap_opt_compat_mode_1_t_enc;
p_struct = &p_opt->gap_opt.compat_mode_1;
break;
#endif
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION == 4
case BLE_GAP_OPT_COMPAT_MODE_2:
fp_encoder = ble_gap_opt_compat_mode_2_t_enc;
p_struct = &p_opt->gap_opt.compat_mode_2;
break;
#endif
default:
SER_ASSERT(NRF_ERROR_INVALID_PARAM, NRF_ERROR_INVALID_PARAM);
break;
}
SER_PUSH_FIELD(p_struct, fp_encoder);
SER_RSP_ENC_END;
}
uint32_t ble_opt_set_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint32_t * const p_opt_id,
ble_opt_t **const pp_opt )
{
SER_REQ_DEC_BEGIN(SD_BLE_OPT_SET);
SER_ASSERT_NOT_NULL(p_opt_id);
SER_ASSERT_NOT_NULL(pp_opt);
SER_ASSERT_NOT_NULL(*pp_opt);
SER_PULL_uint32(p_opt_id);
SER_PULL_COND(pp_opt, NULL);
if (*pp_opt)
{
field_decoder_handler_t fp_decoder = NULL;
void * p_struct = NULL;
switch (*p_opt_id)
{
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
case BLE_COMMON_OPT_CONN_BW:
fp_decoder = ble_common_opt_conn_bw_t_dec;
p_struct = &((*pp_opt)->common_opt.conn_bw);
break;
#endif
case BLE_COMMON_OPT_PA_LNA:
fp_decoder = ble_common_opt_pa_lna_t_dec;
p_struct = &((*pp_opt)->common_opt.pa_lna);
break;
case BLE_COMMON_OPT_CONN_EVT_EXT:
fp_decoder = ble_common_opt_conn_evt_ext_t_dec;
p_struct = &((*pp_opt)->common_opt.conn_evt_ext);
break;
case BLE_GAP_OPT_CH_MAP:
fp_decoder = ble_gap_opt_ch_map_t_dec;
p_struct = &((*pp_opt)->gap_opt.ch_map);
break;
case BLE_GAP_OPT_LOCAL_CONN_LATENCY:
fp_decoder = ble_gap_opt_local_conn_latency_t_dec;
p_struct = &((*pp_opt)->gap_opt.local_conn_latency);
break;
case BLE_GAP_OPT_PASSKEY:
fp_decoder = ble_gap_opt_passkey_t_dec;
p_struct = &((*pp_opt)->gap_opt.passkey);
break;
case BLE_GAP_OPT_AUTH_PAYLOAD_TIMEOUT:
fp_decoder = ble_gap_opt_auth_payload_timeout_t_dec;
p_struct = &((*pp_opt)->gap_opt.auth_payload_timeout);
break;
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
case BLE_GAP_OPT_EXT_LEN:
fp_decoder = ble_gap_opt_ext_len_t_dec;
p_struct = &((*pp_opt)->gap_opt.ext_len);
break;
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 6
case BLE_GAP_OPT_SCAN_REQ_REPORT:
fp_decoder = ble_gap_opt_scan_req_report_t_dec;
p_struct = &((*pp_opt)->gap_opt.scan_req_report);
break;
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
case BLE_GAP_OPT_COMPAT_MODE:
fp_decoder = ble_gap_opt_compat_mode_t_dec;
p_struct = &((*pp_opt)->gap_opt.compat_mode);
break;
#else
#ifndef S112
case BLE_GAP_OPT_COMPAT_MODE_1:
fp_decoder = ble_gap_opt_compat_mode_1_t_dec;
p_struct = &((*pp_opt)->gap_opt.compat_mode_1);
break;
#endif
case BLE_GAP_OPT_SLAVE_LATENCY_DISABLE:
fp_decoder = ble_gap_opt_slave_latency_disable_t_dec;
p_struct = &((*pp_opt)->gap_opt.slave_latency_disable);
break;
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION == 4
case BLE_GAP_OPT_COMPAT_MODE_2:
fp_decoder = ble_gap_opt_compat_mode_2_t_dec;
p_struct = &((*pp_opt)->gap_opt.compat_mode_2);
break;
#endif
default:
SER_ASSERT(NRF_ERROR_INVALID_PARAM,NRF_ERROR_INVALID_PARAM);
break;
}
SER_PULL_FIELD(p_struct, fp_decoder);
}
SER_REQ_DEC_END;
}
uint32_t ble_opt_set_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_OPT_SET);
}
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
uint32_t ble_tx_packet_count_get_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
uint8_t * * const pp_count)
{
SER_REQ_DEC_BEGIN(SD_BLE_TX_PACKET_COUNT_GET);
SER_PULL_uint16(p_conn_handle);
SER_PULL_COND(pp_count, NULL);
SER_REQ_DEC_END;
}
uint32_t ble_tx_packet_count_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint8_t const * const p_count)
{
SER_RSP_ENC_BEGIN(SD_BLE_TX_PACKET_COUNT_GET);
SER_PUSH_COND(p_count, uint8_t_enc);
SER_RSP_ENC_END;
}
#endif
uint32_t ble_user_mem_reply_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_conn_handle,
ble_user_mem_block_t * * const pp_mem_block)
{
SER_REQ_DEC_BEGIN(SD_BLE_USER_MEM_REPLY);
SER_ASSERT_NOT_NULL(p_conn_handle);
SER_ASSERT_NOT_NULL(pp_mem_block);
SER_ASSERT_NOT_NULL(*pp_mem_block);
SER_PULL_uint16(p_conn_handle);
SER_PULL_COND(pp_mem_block, ble_user_mem_block_t_dec);
SER_REQ_DEC_END;
}
uint32_t ble_user_mem_reply_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_USER_MEM_REPLY);
}
uint32_t ble_uuid_decode_req_dec(uint8_t const * const p_buf,
uint32_t const packet_len,
uint8_t * p_uuid_le_len,
uint8_t * * const pp_uuid_le,
ble_uuid_t * * const pp_uuid)
{
SER_REQ_DEC_BEGIN(SD_BLE_UUID_DECODE);
SER_PULL_len8data(pp_uuid_le, p_uuid_le_len);
SER_PULL_COND(pp_uuid, NULL);
SER_REQ_DEC_END;
}
uint32_t ble_uuid_decode_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
ble_uuid_t const * const p_uuid)
{
SER_RSP_ENC_BEGIN(SD_BLE_UUID_DECODE);
SER_PUSH_COND(p_uuid, ble_uuid_t_enc);
SER_RSP_ENC_END;
}
uint32_t ble_uuid_encode_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
ble_uuid_t * * const pp_uuid,
uint8_t * * const pp_uuid_le_len,
uint8_t * * const pp_uuid_le)
{
SER_REQ_DEC_BEGIN(SD_BLE_UUID_ENCODE);
SER_ASSERT_NOT_NULL(pp_uuid);
SER_ASSERT_NOT_NULL(pp_uuid_le_len);
SER_ASSERT_NOT_NULL(pp_uuid_le);
SER_ASSERT_NOT_NULL(*pp_uuid);
SER_ASSERT_NOT_NULL(*pp_uuid_le_len);
SER_ASSERT_NOT_NULL(*pp_uuid_le);
SER_PULL_COND(pp_uuid, ble_uuid_t_dec);
SER_PULL_COND(pp_uuid_le_len, NULL);
SER_PULL_COND(pp_uuid_le, NULL);
SER_REQ_DEC_END;
}
uint32_t ble_uuid_encode_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint8_t uuid_le_len,
uint8_t const * const p_uuid_le)
{
SER_RSP_ENC_BEGIN(SD_BLE_UUID_ENCODE);
SER_PUSH_uint8(&uuid_le_len);
if (p_uuid_le != NULL)
{
SER_PUSH_uint8array(p_uuid_le, uuid_le_len);
}
SER_RSP_ENC_END;
}
uint32_t ble_uuid_vs_add_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
ble_uuid128_t * * const pp_uuid,
uint8_t * * const pp_uuid_type)
{
SER_REQ_DEC_BEGIN(SD_BLE_UUID_VS_ADD);
SER_ASSERT_NOT_NULL(pp_uuid);
SER_ASSERT_NOT_NULL(pp_uuid_type);
SER_ASSERT_NOT_NULL(*pp_uuid);
SER_ASSERT_NOT_NULL(*pp_uuid_type);
SER_PULL_COND(pp_uuid, ble_uuid128_t_dec);
SER_PULL_COND(pp_uuid_type, NULL);
SER_REQ_DEC_END;
}
uint32_t ble_uuid_vs_add_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint8_t const * const p_uuid_type)
{
SER_RSP_ENC_BEGIN(SD_BLE_UUID_VS_ADD);
SER_PUSH_COND(p_uuid_type, uint8_t_enc);
SER_RSP_ENC_END;
}
uint32_t ble_version_get_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
ble_version_t * * const pp_version)
{
SER_REQ_DEC_BEGIN(SD_BLE_VERSION_GET);
SER_ASSERT_NOT_NULL(pp_version);
SER_ASSERT_NOT_NULL(*pp_version);
SER_PULL_COND(pp_version, NULL);
SER_REQ_DEC_END;
}
uint32_t ble_version_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
ble_version_t const * const p_version)
{
SER_RSP_ENC_BEGIN(SD_BLE_VERSION_GET);
SER_PUSH_FIELD(p_version, ble_version_t_enc);
SER_RSP_ENC_END;
}
uint32_t ble_opt_id_pre_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint32_t * const p_opt_id)
{
SER_REQ_DEC_BEGIN(SD_BLE_OPT_SET);
SER_ASSERT_NOT_NULL(p_opt_id);
SER_PULL_uint32(p_opt_id);
// Pre-decoding; do not check if the whole packet was processed.
return NRF_SUCCESS;
}
#if NRF_SD_BLE_API_VERSION >= 4
uint32_t ble_cfg_set_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * p_cfg_id,
ble_cfg_t * * const pp_cfg)
{
SER_REQ_DEC_BEGIN(SD_BLE_CFG_SET);
SER_PULL_uint32(p_cfg_id);
SER_PULL_COND(pp_cfg, NULL);
if (*pp_cfg)
{
field_decoder_handler_t fp_decoder = NULL;
void * p_struct = NULL;
switch (*p_cfg_id)
{
case BLE_CONN_CFG_GAP:
fp_decoder = ble_gap_conn_cfg_t_dec;
p_struct = &((*pp_cfg)->conn_cfg.params.gap_conn_cfg);
break;
case BLE_CONN_CFG_GATTC:
fp_decoder = ble_gattc_conn_cfg_t_dec;
p_struct = &((*pp_cfg)->conn_cfg.params.gattc_conn_cfg);
break;
case BLE_CONN_CFG_GATTS:
fp_decoder = ble_gatts_conn_cfg_t_dec;
p_struct = &((*pp_cfg)->conn_cfg.params.gatts_conn_cfg);
break;
case BLE_CONN_CFG_GATT:
fp_decoder = ble_gatt_conn_cfg_t_dec;
p_struct = &((*pp_cfg)->conn_cfg.params.gatt_conn_cfg);
break;
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION >= 5 && !defined(S112)
case BLE_CONN_CFG_L2CAP:
fp_decoder = ble_l2cap_conn_cfg_t_dec;
p_struct = &((*pp_cfg)->conn_cfg.params.l2cap_conn_cfg);
break;
#endif
case BLE_COMMON_CFG_VS_UUID:
fp_decoder = ble_common_cfg_vs_uuid_t_dec;
p_struct = &((*pp_cfg)->common_cfg.vs_uuid_cfg);
break;
case BLE_GAP_CFG_ROLE_COUNT:
fp_decoder = ble_gap_cfg_role_count_t_dec;
p_struct = &((*pp_cfg)->gap_cfg.role_count_cfg);
break;
case BLE_GAP_CFG_DEVICE_NAME:
fp_decoder = ble_gap_cfg_device_name_t_dec;
p_struct = &((*pp_cfg)->gap_cfg.device_name_cfg);
break;
case BLE_GATTS_CFG_SERVICE_CHANGED:
fp_decoder = ble_gatts_cfg_service_changed_t_dec;
p_struct = &((*pp_cfg)->gatts_cfg.service_changed);
break;
case BLE_GATTS_CFG_ATTR_TAB_SIZE:
fp_decoder = ble_gatts_cfg_attr_tab_size_t_dec;
p_struct = &((*pp_cfg)->gatts_cfg.attr_tab_size);
break;
default:
SER_ASSERT(NRF_ERROR_INVALID_PARAM,NRF_ERROR_INVALID_PARAM);
break;
}
if (*p_cfg_id >= BLE_CONN_CFG_BASE && *p_cfg_id <= BLE_CONN_CFG_GATT)
{
SER_PULL_uint8(&(*pp_cfg)->conn_cfg.conn_cfg_tag);
}
SER_PULL_FIELD(p_struct, fp_decoder);
}
SER_REQ_DEC_END;
}
uint32_t ble_cfg_set_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_CFG_SET);
}
#endif

View File

@@ -0,0 +1,521 @@
/**
* Copyright (c) 2013 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef BLE_CONN_H__
#define BLE_CONN_H__
/**
* @addtogroup ser_conn_s130_codecs Connectivity codecs for S132 and S140
* @ingroup ser_codecs_conn
*/
/**@file
*
* @defgroup ble_conn Connectivity command request decoders and command response encoders
* @{
* @ingroup ser_conn_s130_codecs
*
* @brief Connectivity command request decoders and command response encoders.
*/
#include "ble.h"
#ifdef __cplusplus
extern "C" {
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
/**@brief Decodes @ref sd_ble_tx_packet_count_get command request.
*
* @sa @ref ble_tx_packet_count_get_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_conn_handle Pointer to connection handle.
* @param[out] pp_count Pointer to pointer to location for count.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_tx_packet_count_get_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
uint8_t * * const pp_count);
/**@brief Encodes @ref sd_ble_tx_packet_count_get command response.
*
* @sa @ref ble_tx_packet_count_get_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_count Pointer to count value.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_tx_packet_count_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint8_t const * const p_count);
#endif
/**@brief Event encoding dispatcher.
*
* The event encoding dispatcher will route the event packet to the correct encoder which in turn
* encodes the contents of the event and updates the \p p_buf buffer.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
* @retval NRF_ERROR_NOT_SUPPORTED Event encoder is not implemented.
*/
uint32_t ble_event_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_version_get command request.
*
* @sa @ref ble_version_get_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] pp_version Pointer to pointer to @ref ble_version_t address.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_version_get_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
ble_version_t * * const pp_version);
/**@brief Encodes @ref sd_ble_version_get command response.
*
* @sa @ref ble_version_get_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_version Pointer to @ref ble_version_t address.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_version_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
ble_version_t const * const p_version);
/**@brief Decodes @ref sd_ble_opt_get command request.
*
* @sa @ref ble_opt_get_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_opt_id Pointer to pointer to @ref ble_version_t address.
* @param[out] pp_opt Pointer to pointer to @ref ble_opt_t address.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_opt_get_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint32_t * const p_opt_id,
ble_opt_t **const pp_opt );
/**@brief Encodes @ref sd_ble_opt_get command response.
*
* @sa @ref ble_opt_get_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] opt_id identifies type of ble_opt_t union
* @param[in] p_opt Pointer to @ref ble_opt_t union.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_opt_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint32_t opt_id,
ble_opt_t const * const p_opt);
/**@brief Decodes @ref sd_ble_opt_set command request.
*
* @sa @ref ble_opt_set_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_opt_id Pointer to @ref ble_opt_t union type identifier.
* @param[out] pp_opt Pointer to pointer to @ref ble_opt_t union.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_opt_set_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint32_t * const p_opt_id,
ble_opt_t **const pp_opt );
/**@brief Encodes @ref sd_ble_opt_set command response.
*
* @sa @ref ble_opt_set_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_opt_set_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_uuid_encode command request.
*
* @sa @ref ble_uuid_encode_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] pp_uuid Pointer to pointer to @ref ble_uuid_t structure.
* @param[out] pp_uuid_le_len Pointer to pointer to the length of encoded UUID.
* @param[out] pp_uuid_le Pointer to pointer to buffer where encoded UUID will be stored.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_uuid_encode_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
ble_uuid_t * * const pp_uuid,
uint8_t * * const pp_uuid_le_len,
uint8_t * * const pp_uuid_le);
/**@brief Encodes @ref sd_ble_uuid_encode command response.
*
* @sa @ref ble_uuid_encode_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] uuid_le_len Length of the encoded UUID.
* @param[in] p_uuid_le Pointer to the buffer with encoded UUID.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_uuid_encode_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint8_t uuid_le_len,
uint8_t const * const p_uuid_le);
/**@brief Decodes @ref sd_ble_uuid_decode command request.
*
* @sa @ref ble_uuid_decode_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_uuid_le_len Pointer to the length of encoded UUID.
* @param[out] pp_uuid_le Pointer to pointer to buffer where encoded UUID will be stored.
* @param[out] pp_uuid Pointer to pointer to @ref ble_uuid_t structure.
* \c It will be set to NULL if p_uuid is not present in the packet.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_uuid_decode_req_dec(uint8_t const * const p_buf,
uint32_t const packet_len,
uint8_t * p_uuid_le_len,
uint8_t * * const pp_uuid_le,
ble_uuid_t * * const pp_uuid);
/**@brief Encodes @ref sd_ble_uuid_decode command response.
*
* @sa @ref ble_uuid_decode_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_uuid Pointer to the buffer with encoded UUID.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_uuid_decode_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
ble_uuid_t const * const p_uuid);
/**@brief Decodes @ref sd_ble_uuid_vs_add command request.
*
* @sa @ref ble_uuid_vs_add_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] pp_uuid Pointer to pointer to UUID.
* \c It will be set to NULL if p_uuid is not present in the packet.
* @param[out] pp_uuid_type Pointer to pointer to UUID type.
* \c It will be set to NULL if p_uuid_type is not present in the packet.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_uuid_vs_add_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
ble_uuid128_t * * const pp_uuid,
uint8_t * * const pp_uuid_type);
/**@brief Encodes @ref sd_ble_uuid_vs_add command response.
*
* @sa @ref ble_uuid_vs_add_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_uuid_type Pointer to the UUID type.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_uuid_vs_add_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint8_t const * const p_uuid_type);
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
/**@brief Decodes @ref sd_ble_enable command request.
*
* @sa @ref ble_enable_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] pp_ble_enable_params Pointer to pointer to ble_enable_params_t.
* \c It will be set to NULL if p_ble_enable_params is not present in the packet.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_enable_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
ble_enable_params_t * * const pp_ble_enable_params);
#else
/**@brief Decodes @ref sd_ble_enable command request.
*
* @sa @ref ble_enable_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_enable_req_dec(uint8_t const * const p_buf,
uint32_t packet_len);
#endif
/**@brief Encodes @ref sd_ble_enable command response.
*
* @sa @ref ble_enable_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_enable_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Pre-decodes opt_id of @ref ble_opt_t for middleware.
*
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] packet_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in,out] p_opt_id Pointer to opt_id which identifies type of @ref ble_opt_t union.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_opt_id_pre_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint32_t * const p_opt_id);
/**@brief Decodes @ref sd_ble_user_mem_reply command request.
*
* @sa @ref ble_user_mem_reply_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[in] p_conn_handle Pointer to Connection Handle.
* @param[in,out] pp_block Pointer to pointer to ble_user_mem_block_t.
* \c It will be set to NULL if p_block is not present in the packet.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_user_mem_reply_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_conn_handle,
ble_user_mem_block_t * * const pp_block);
/**@brief Encodes @ref sd_ble_user_mem_reply command response.
*
* @sa @ref ble_user_mem_reply_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_user_mem_reply_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#if NRF_SD_BLE_API_VERSION >= 4
/**@brief Decodes @ref sd_ble_cfg_set command request.
*
* @sa @ref ble_cfg_set_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[in] p_cfg_id Pointer to ConfigurationId.
* @param[in,out] pp_cfg Pointer to pointer to configuration struct.
* \c It will be set to NULL if p_block is not present in the packet.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_cfg_set_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint32_t * p_cfg_id,
ble_cfg_t * * const pp_cfg);
/**@brief Encodes @ref sd_ble_cfg_set command response.
*
* @sa @ref ble_cfg_set_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_cfg_set_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#endif
/** @} */
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,308 @@
/**
* Copyright (c) 2013 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "ble_conn.h"
#include "ble_evt_conn.h"
#include "ble_gap_evt_conn.h"
#include "ble_gattc_evt_conn.h"
#include "ble_gatts_evt_conn.h"
#include "ble_l2cap_evt_conn.h"
#include "ble_serialization.h"
#include "app_util.h"
#include "nrf_log.h"
#include "ser_dbg_sd_str.h"
uint32_t ble_event_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
uint32_t ret_val = NRF_SUCCESS;
SER_ASSERT_NOT_NULL(p_buf);
SER_ASSERT_NOT_NULL(p_buf_len);
SER_ASSERT_NOT_NULL(p_event);
NRF_LOG_DEBUG("event:%s", ser_dbg_sd_evt_str_get(p_event->header.evt_id));
switch (p_event->header.evt_id)
{
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
case BLE_EVT_TX_COMPLETE:
ret_val = ble_evt_tx_complete_enc(p_event, event_len, p_buf, p_buf_len);
break;
#endif
case BLE_EVT_USER_MEM_RELEASE:
ret_val = ble_evt_user_mem_release_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_EVT_USER_MEM_REQUEST:
ret_val = ble_evt_user_mem_request_enc(p_event, event_len, p_buf, p_buf_len);
break;
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
case BLE_EVT_DATA_LENGTH_CHANGED:
ret_val = ble_evt_data_length_changed_enc(p_event, event_len, p_buf, p_buf_len);
break;
#endif
case BLE_GAP_EVT_CONN_PARAM_UPDATE:
ret_val = ble_gap_evt_conn_param_update_enc(p_event, event_len, p_buf, p_buf_len);
break;
#ifndef S112
case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST:
ret_val = ble_gap_evt_conn_param_update_request_enc(p_event, event_len, p_buf, p_buf_len);
break;
#endif //!S112
case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
ret_val = ble_gap_evt_sec_params_request_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GAP_EVT_SEC_INFO_REQUEST:
ret_val = ble_gap_evt_sec_info_request_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GAP_EVT_AUTH_STATUS:
ret_val = ble_gap_evt_auth_status_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GAP_EVT_PASSKEY_DISPLAY:
ret_val = ble_gap_evt_passkey_display_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GAP_EVT_AUTH_KEY_REQUEST:
ret_val = ble_gap_evt_auth_key_request_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GAP_EVT_CONN_SEC_UPDATE:
ret_val = ble_gap_evt_conn_sec_update_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GAP_EVT_RSSI_CHANGED:
ret_val = ble_gap_evt_rssi_changed_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GAP_EVT_TIMEOUT:
ret_val = ble_gap_evt_timeout_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GAP_EVT_DISCONNECTED:
ret_val = ble_gap_evt_disconnected_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GAP_EVT_CONNECTED:
ret_val = ble_gap_evt_connected_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GAP_EVT_SEC_REQUEST:
ret_val = ble_gap_evt_sec_request_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GAP_EVT_KEY_PRESSED:
ret_val = ble_gap_evt_key_pressed_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GAP_EVT_LESC_DHKEY_REQUEST:
ret_val = ble_gap_evt_lesc_dhkey_request_enc(p_event, event_len, p_buf, p_buf_len);
break;
#if NRF_SD_BLE_API_VERSION >= 5
case BLE_GAP_EVT_PHY_UPDATE:
ret_val = ble_gap_evt_phy_update_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
ret_val = ble_gap_evt_phy_update_request_enc(p_event, event_len, p_buf, p_buf_len);
break;
#endif
#if NRF_SD_BLE_API_VERSION >= 6
#ifndef S112
case BLE_GAP_EVT_QOS_CHANNEL_SURVEY_REPORT:
ret_val = ble_gap_evt_qos_channel_survey_report_enc(p_event, event_len, p_buf, p_buf_len);
break;
#endif
case BLE_GAP_EVT_ADV_SET_TERMINATED:
ret_val = ble_gap_evt_adv_set_terminated_enc(p_event, event_len, p_buf, p_buf_len);
break;
#endif
#if NRF_SD_BLE_API_VERSION >= 4 && !defined(S112)
case BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST:
ret_val = ble_gap_evt_data_length_update_request_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GAP_EVT_DATA_LENGTH_UPDATE:
ret_val = ble_gap_evt_data_length_update_enc(p_event, event_len, p_buf, p_buf_len);
break;
#endif //NRF_SD_BLE_API_VERSION >= 4 && !defined(S112)
case BLE_GATTC_EVT_CHAR_DISC_RSP:
ret_val = ble_gattc_evt_char_disc_rsp_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTC_EVT_DESC_DISC_RSP:
ret_val = ble_gattc_evt_desc_disc_rsp_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP:
ret_val = ble_gattc_evt_char_val_by_uuid_read_rsp_enc(p_event,
event_len,
p_buf,
p_buf_len);
break;
case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP:
ret_val = ble_gattc_evt_prim_srvc_disc_rsp_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTC_EVT_HVX:
ret_val = ble_gattc_evt_hvx_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTC_EVT_READ_RSP:
ret_val = ble_gattc_evt_read_rsp_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTC_EVT_TIMEOUT:
ret_val = ble_gattc_evt_timeout_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTC_EVT_WRITE_RSP:
ret_val = ble_gattc_evt_write_rsp_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTC_EVT_REL_DISC_RSP:
ret_val = ble_gattc_evt_rel_disc_rsp_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTC_EVT_CHAR_VALS_READ_RSP:
ret_val = ble_gattc_evt_char_vals_read_rsp_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTC_EVT_ATTR_INFO_DISC_RSP:
ret_val = ble_gattc_evt_attr_info_disc_rsp_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTC_EVT_EXCHANGE_MTU_RSP:
ret_val = ble_gattc_evt_exchange_mtu_rsp_enc(p_event, event_len, p_buf, p_buf_len);
break;
#if NRF_SD_BLE_API_VERSION >= 4
case BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE:
ret_val = ble_gattc_evt_write_cmd_tx_complete_enc(p_event, event_len, p_buf, p_buf_len);
break;
#endif
case BLE_GATTS_EVT_HVC:
ret_val = ble_gatts_evt_hvc_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTS_EVT_TIMEOUT:
ret_val = ble_gatts_evt_timeout_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTS_EVT_SC_CONFIRM:
ret_val = ble_gatts_evt_sc_confirm_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTS_EVT_WRITE:
ret_val = ble_gatts_evt_write_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
ret_val = ble_gatts_evt_rw_authorize_request_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTS_EVT_SYS_ATTR_MISSING:
ret_val = ble_gatts_evt_sys_attr_missing_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST:
ret_val = ble_gatts_evt_exchange_mtu_request_enc(p_event, event_len, p_buf, p_buf_len);
break;
#if NRF_SD_BLE_API_VERSION >= 4
case BLE_GATTS_EVT_HVN_TX_COMPLETE:
ret_val = ble_gatts_evt_hvn_tx_complete_enc(p_event, event_len, p_buf, p_buf_len);
break;
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
case BLE_L2CAP_EVT_RX:
ret_val = ble_l2cap_evt_rx_enc(p_event, event_len, p_buf, p_buf_len);
break;
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION >= 5 && !defined(S112)
case BLE_L2CAP_EVT_CH_SETUP_REQUEST:
ret_val = ble_l2cap_evt_ch_setup_request_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_L2CAP_EVT_CH_SETUP_REFUSED:
ret_val = ble_l2cap_evt_ch_setup_refused_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_L2CAP_EVT_CH_SETUP:
ret_val = ble_l2cap_evt_ch_setup_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_L2CAP_EVT_CH_RELEASED:
ret_val = ble_l2cap_evt_ch_released_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_L2CAP_EVT_CH_SDU_BUF_RELEASED:
ret_val = ble_l2cap_evt_ch_sdu_buf_released_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_L2CAP_EVT_CH_CREDIT:
ret_val = ble_l2cap_evt_ch_credit_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_L2CAP_EVT_CH_RX:
ret_val = ble_l2cap_evt_ch_rx_enc(p_event, event_len, p_buf, p_buf_len);
break;
case BLE_L2CAP_EVT_CH_TX:
ret_val = ble_l2cap_evt_ch_tx_enc(p_event, event_len, p_buf, p_buf_len);
break;
#endif //defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION >= 5 && !defined(S112)
#ifndef S112
case BLE_GAP_EVT_ADV_REPORT:
ret_val = ble_gap_evt_adv_report_enc(p_event, event_len, p_buf, p_buf_len);
break;
#endif //!S112
case BLE_GAP_EVT_SCAN_REQ_REPORT:
ret_val = ble_gap_evt_scan_req_report_enc(p_event, event_len, p_buf, p_buf_len);
break;
default:
ret_val = NRF_ERROR_NOT_SUPPORTED;
*p_buf_len = 0;
break;
}
return ret_val;
}

View File

@@ -0,0 +1,108 @@
/**
* Copyright (c) 2013 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "ble_evt_conn.h"
#include <string.h>
#include "ble_serialization.h"
#include "ble_struct_serialization.h"
#include "app_util.h"
#include "conn_ble_user_mem.h"
uint32_t ble_evt_user_mem_release_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_EVT_USER_MEM_RELEASE);
SER_PUSH_uint16(&p_event->evt.common_evt.conn_handle);
SER_PUSH_uint8(&p_event->evt.common_evt.params.user_mem_release.type);
SER_PUSH_uint16(&p_event->evt.common_evt.params.user_mem_release.mem_block.len);
SER_PUSH_COND(p_event->evt.common_evt.params.user_mem_release.mem_block.p_mem, NULL);
// Now user memory context can be released
err_code = conn_ble_user_mem_context_destroy(p_event->evt.common_evt.conn_handle);
SER_ASSERT(err_code == NRF_SUCCESS, err_code);
SER_EVT_ENC_END;
}
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
uint32_t ble_evt_tx_complete_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_EVT_TX_COMPLETE);
SER_PUSH_uint16(&p_event->evt.common_evt.conn_handle);
SER_PUSH_uint8(&p_event->evt.common_evt.params.tx_complete.count);
SER_EVT_ENC_END;
}
#endif
uint32_t ble_evt_user_mem_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_EVT_USER_MEM_REQUEST);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_uint8(&p_event->evt.common_evt.params.user_mem_request.type);
SER_EVT_ENC_END;
}
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
uint32_t ble_evt_data_length_changed_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_EVT_DATA_LENGTH_CHANGED);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.common_evt.params.data_length_changed, ble_evt_data_length_changed_t_enc);
SER_EVT_ENC_END;
}
#endif

View File

@@ -0,0 +1,138 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef BLE_EVT_CONN_H__
#define BLE_EVT_CONN_H__
/**@file
*
* @defgroup ble_evt_conn Connectivity event encoders
* @{
* @ingroup ser_conn_s130_codecs
*
* @brief Connectivity event encoders.
*/
#include "ble.h"
#ifdef __cplusplus
extern "C" {
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
/**
* @brief Encodes ble_evt_tx_complete event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that will be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_evt_tx_complete_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#endif
/**
* @brief Encodes ble_evt_user_mem_release event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_evt_user_mem_release_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_evt_user_mem_request event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that will be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_evt_user_mem_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
/**
* @brief Encodes ble_evt_data_length_changed event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that will be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_evt_data_length_changed_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#endif
/** @} */
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,412 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "ble.h"
#include "ble_gap_evt_conn.h"
#include <string.h>
#include "ble_serialization.h"
#include "cond_field_serialization.h"
#include "ble_gap_struct_serialization.h"
#include "ble_struct_serialization.h"
#include "conn_ble_gap_sec_keys.h"
#include "app_util.h"
extern ser_ble_gap_conn_keyset_t m_conn_keys_table[];
#ifndef S112
uint32_t ble_gap_evt_adv_report_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_ADV_REPORT);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.adv_report, ble_gap_evt_adv_report_t_enc);
#if NRF_SD_BLE_API_VERSION > 5
conn_ble_gap_scan_data_unset(false);
#endif
SER_EVT_ENC_END;
}
#endif //!S112
uint32_t ble_gap_evt_auth_key_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_AUTH_KEY_REQUEST);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_uint8(&p_event->evt.gap_evt.params.auth_key_request.key_type);
SER_EVT_ENC_END;
}
uint32_t ble_gap_evt_auth_status_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_AUTH_STATUS);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.auth_status, ble_gap_evt_auth_status_t_enc);
// keyset is an extension of standard event data - used to synchronize keys at application
uint32_t conn_index;
err_code = conn_ble_gap_sec_context_find(p_event->evt.gap_evt.conn_handle, &conn_index);
if (err_code == NRF_SUCCESS)
{
SER_PUSH_FIELD(&(m_conn_keys_table[conn_index].keyset), ble_gap_sec_keyset_t_enc);
err_code = conn_ble_gap_sec_context_destroy(p_event->evt.gap_evt.conn_handle);
SER_ASSERT(err_code == NRF_SUCCESS, err_code);
}
else
{
err_code = NRF_SUCCESS;
}
SER_EVT_ENC_END;
}
uint32_t ble_gap_evt_conn_param_update_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_CONN_PARAM_UPDATE);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.conn_param_update, ble_gap_evt_conn_param_update_t_enc);
SER_EVT_ENC_END;
}
#ifndef S112
uint32_t ble_gap_evt_conn_param_update_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.conn_param_update_request,
ble_gap_evt_conn_param_update_request_t_enc);
SER_EVT_ENC_END;
}
#endif //!S112
uint32_t ble_gap_evt_conn_sec_update_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_CONN_SEC_UPDATE);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.conn_sec_update, ble_gap_evt_conn_sec_update_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gap_evt_connected_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_CONNECTED);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.connected, ble_gap_evt_connected_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gap_evt_disconnected_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_DISCONNECTED);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.disconnected, ble_gap_evt_disconnected_t_enc);
// If disconnected and context is not yet destroyed, destroy it now
uint32_t conn_index;
err_code = conn_ble_gap_sec_context_find(p_event->evt.gap_evt.conn_handle, &conn_index);
if (err_code == NRF_SUCCESS)
{
err_code = conn_ble_gap_sec_context_destroy(p_event->evt.gap_evt.conn_handle);
SER_ASSERT(err_code == NRF_SUCCESS, err_code);
}
err_code = NRF_SUCCESS;
SER_EVT_ENC_END;
}
uint32_t ble_gap_evt_key_pressed_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_KEY_PRESSED);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_uint8(&p_event->evt.gap_evt.params.key_pressed.kp_not);
SER_EVT_ENC_END;
}
uint32_t ble_gap_evt_lesc_dhkey_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_LESC_DHKEY_REQUEST);
uint8_t ser_data = p_event->evt.gap_evt.params.lesc_dhkey_request.oobd_req & 0x01;
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_COND(p_event->evt.gap_evt.params.lesc_dhkey_request.p_pk_peer, ble_gap_lesc_p256_pk_t_enc);
SER_PUSH_uint8(&ser_data);
SER_EVT_ENC_END;
}
#define PASSKEY_LEN sizeof (p_event->evt.gap_evt.params.passkey_display.passkey)
uint32_t ble_gap_evt_passkey_display_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_PASSKEY_DISPLAY);
uint8_t ser_data = p_event->evt.gap_evt.params.passkey_display.match_request & 0x01;
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_uint8array(p_event->evt.gap_evt.params.passkey_display.passkey, BLE_GAP_PASSKEY_LEN);
SER_PUSH_uint8(&ser_data);
SER_EVT_ENC_END;
}
uint32_t ble_gap_evt_rssi_changed_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_RSSI_CHANGED);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_int8(&p_event->evt.gap_evt.params.rssi_changed.rssi);
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5
SER_PUSH_uint8(&p_event->evt.gap_evt.params.rssi_changed.ch_index);
#endif
SER_EVT_ENC_END;
}
uint32_t ble_gap_evt_scan_req_report_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_SCAN_REQ_REPORT);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5
SER_PUSH_uint8(&p_event->evt.gap_evt.params.scan_req_report.adv_handle);
#endif
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.scan_req_report.peer_addr, ble_gap_addr_t_enc);
SER_PUSH_int8(&p_event->evt.gap_evt.params.scan_req_report.rssi);
SER_EVT_ENC_END;
}
uint32_t ble_gap_evt_sec_info_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_SEC_INFO_REQUEST);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.sec_info_request, ble_gap_evt_sec_info_request_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gap_evt_sec_params_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_SEC_PARAMS_REQUEST);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.sec_params_request, ble_gap_evt_sec_params_request_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gap_evt_sec_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_SEC_REQUEST);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.sec_request, ble_gap_evt_sec_request_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gap_evt_timeout_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_TIMEOUT);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_uint8(&p_event->evt.gap_evt.params.timeout.src);
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5 && !defined(S112)
if (p_event->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_SCAN)
{
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.timeout.params.adv_report_buffer, ble_data_t_enc);
}
#endif
SER_EVT_ENC_END;
}
#if NRF_SD_BLE_API_VERSION >= 5
uint32_t ble_gap_evt_phy_update_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_PHY_UPDATE);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_uint8(&p_event->evt.gap_evt.params.phy_update.status);
SER_PUSH_uint8(&p_event->evt.gap_evt.params.phy_update.tx_phy);
SER_PUSH_uint8(&p_event->evt.gap_evt.params.phy_update.rx_phy);
SER_EVT_ENC_END;
}
uint32_t ble_gap_evt_phy_update_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_PHY_UPDATE_REQUEST);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.phy_update_request, ble_gap_phys_t_enc);
SER_EVT_ENC_END;
}
#endif
#if NRF_SD_BLE_API_VERSION >= 4 && !defined(S112)
uint32_t ble_gap_evt_data_length_update_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.data_length_update_request.peer_params, ble_gap_data_length_params_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gap_evt_data_length_update_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_DATA_LENGTH_UPDATE);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.data_length_update.effective_params, ble_gap_data_length_params_t_enc);
SER_EVT_ENC_END;
}
#endif // NRF_SD_BLE_API_VERSION >= 4 && !defined(S112)
#if NRF_SD_BLE_API_VERSION > 5
uint32_t ble_gap_evt_adv_set_terminated_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_ADV_SET_TERMINATED);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gap_evt.params.adv_set_terminated, ble_gap_evt_adv_set_terminated_t_enc);
SER_EVT_ENC_END;
}
#ifndef S112
uint32_t ble_gap_evt_qos_channel_survey_report_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GAP_EVT_QOS_CHANNEL_SURVEY_REPORT);
SER_PUSH_uint16(&p_event->evt.gap_evt.conn_handle);
SER_PUSH_uint8array((uint8_t *)p_event->evt.gap_evt.params.qos_channel_survey_report.channel_energy,
BLE_GAP_CHANNEL_COUNT);
SER_EVT_ENC_END;
}
#endif //!S112
#endif//NRF_SD_BLE_API_VERSION > 5

View File

@@ -0,0 +1,483 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef BLE_GAP_EVT_CONN_H__
#define BLE_GAP_EVT_CONN_H__
/**@file
*
* @defgroup ble_gap_evt_conn GAP Connectivity event encoders
* @{
* @ingroup ser_conn_s130_codecs
*
* @brief GAP Connectivity event encoders.
*/
#include "ble.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Encodes ble_gap_evt_auth_key_request event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_auth_key_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_auth_status event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_auth_status_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_conn_param_update event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_conn_param_update_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_conn_sec_update event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_conn_sec_update_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_connected event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_connected_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_disconnected event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_disconnected_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_passkey_display event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_passkey_display_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_rssi_changed event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_rssi_changed_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_sec_info_request event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_sec_info_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_sec_params_request event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_sec_params_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_timeout event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_timeout_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_sec_request event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_sec_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_conn_param_update_request event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_conn_param_update_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_adv_report event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_adv_report_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_scan_req_report event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_scan_req_report_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_key_pressed event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_key_pressed_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_lesc_dhkey_request event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_lesc_dhkey_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#if NRF_SD_BLE_API_VERSION >= 5
/**
* @brief Encodes ble_gap_evt_phy_update event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_phy_update_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_phy_update_request event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_phy_update_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#endif
#if NRF_SD_BLE_API_VERSION >= 4
/**
* @brief Encodes ble_gap_evt_data_length_update_request event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_data_length_update_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gap_evt_data_length_update event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_data_length_update_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#endif
#if NRF_SD_BLE_API_VERSION >= 6
/**
* @brief Encodes ble_gap_evt_adv_set_terminated event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_adv_set_terminated_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#ifndef S112
/**
* @brief Encodes ble_gap_evt_qos_channel_survey_report event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gap_evt_qos_channel_survey_report_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#endif //!S112
#endif //NRF_SD_BLE_API_VERSION >= 6
/** @} */
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,299 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "ble_gattc_conn.h"
#include "ble_serialization.h"
#include "ble_struct_serialization.h"
#include "ble_gattc_struct_serialization.h"
#include "cond_field_serialization.h"
#include "app_util.h"
#include <string.h>
uint32_t ble_gattc_attr_info_discover_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
ble_gattc_handle_range_t * * const pp_handle_range)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTC_ATTR_INFO_DISCOVER);
SER_ASSERT_NOT_NULL(p_conn_handle);
SER_ASSERT_NOT_NULL(pp_handle_range);
SER_ASSERT_NOT_NULL(*pp_handle_range);
SER_PULL_uint16(p_conn_handle);
SER_PULL_COND(pp_handle_range, ble_gattc_handle_range_t_dec);
SER_REQ_DEC_END;
}
uint32_t ble_gattc_attr_info_discover_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_ATTR_INFO_DISCOVER);
}
uint32_t ble_gattc_char_value_by_uuid_read_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
ble_uuid_t * * const pp_uuid,
ble_gattc_handle_range_t * * const
pp_handle_range)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ);
SER_ASSERT_NOT_NULL(p_conn_handle);
SER_ASSERT_NOT_NULL(pp_uuid);
SER_ASSERT_NOT_NULL(*pp_uuid);
SER_ASSERT_NOT_NULL(pp_handle_range);
SER_ASSERT_NOT_NULL(*pp_handle_range);
SER_PULL_uint16(p_conn_handle);
SER_PULL_COND(pp_uuid, ble_uuid_t_dec);
SER_PULL_COND(pp_handle_range, ble_gattc_handle_range_t_dec);
SER_REQ_DEC_END;
}
uint32_t ble_gattc_char_value_by_uuid_read_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ);
}
uint32_t ble_gattc_char_values_read_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
uint16_t * * const pp_handles,
uint16_t * const p_handle_count)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTC_CHAR_VALUES_READ);
SER_ASSERT_NOT_NULL(p_conn_handle);
SER_ASSERT_NOT_NULL(pp_handles);
SER_ASSERT_NOT_NULL(*pp_handles);
SER_ASSERT_NOT_NULL(p_handle_count);
SER_PULL_uint16(p_conn_handle);
SER_PULL_len16data16(pp_handles, p_handle_count);
SER_REQ_DEC_END;
}
uint32_t ble_gattc_char_values_read_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_CHAR_VALUES_READ);
}
uint32_t ble_gattc_characteristics_discover_req_dec(
uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
ble_gattc_handle_range_t * * const pp_handle_range)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTC_CHARACTERISTICS_DISCOVER);
SER_PULL_uint16(p_conn_handle);
SER_PULL_COND(pp_handle_range, ble_gattc_handle_range_t_dec);
SER_REQ_DEC_END;
}
uint32_t ble_gattc_characteristics_discover_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_CHARACTERISTICS_DISCOVER);
}
uint32_t ble_gattc_descriptors_discover_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
ble_gattc_handle_range_t * * const pp_handle_range)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTC_DESCRIPTORS_DISCOVER);
SER_PULL_uint16(p_conn_handle);
SER_PULL_COND(pp_handle_range, ble_gattc_handle_range_t_dec);
SER_REQ_DEC_END;
}
uint32_t ble_gattc_descriptors_discover_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_DESCRIPTORS_DISCOVER);
}
uint32_t ble_gattc_hv_confirm_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_conn_handle,
uint16_t * const p_handle)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTC_HV_CONFIRM);
SER_PULL_uint16(p_conn_handle);
SER_PULL_uint16(p_handle);
SER_REQ_DEC_END;
}
uint32_t ble_gattc_hv_confirm_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_HV_CONFIRM);
}
uint32_t ble_gattc_primary_services_discover_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
uint16_t * const p_start_handle,
ble_uuid_t * * const pp_srvc_uuid)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER);
SER_PULL_uint16(p_conn_handle);
SER_PULL_uint16(p_start_handle);
SER_PULL_COND(pp_srvc_uuid, ble_uuid_t_dec);
SER_REQ_DEC_END;
}
uint32_t ble_gattc_primary_services_discover_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER);
}
uint32_t ble_gattc_read_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
uint16_t * const p_handle,
uint16_t * const p_offset)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTC_READ);
SER_PULL_uint16(p_conn_handle);
SER_PULL_uint16(p_handle);
SER_PULL_uint16(p_offset);
SER_REQ_DEC_END;
}
uint32_t ble_gattc_read_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_READ);
}
uint32_t ble_gattc_relationships_discover_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
ble_gattc_handle_range_t * * const pp_handle_range)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTC_RELATIONSHIPS_DISCOVER);
SER_PULL_uint16(p_conn_handle);
SER_PULL_COND(pp_handle_range, ble_gattc_handle_range_t_dec);
SER_REQ_DEC_END;
}
uint32_t ble_gattc_relationships_discover_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_RELATIONSHIPS_DISCOVER);
}
uint32_t ble_gattc_write_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
ble_gattc_write_params_t * * const pp_write_params)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTC_WRITE);
SER_PULL_uint16(p_conn_handle);
SER_PULL_COND(pp_write_params, ble_gattc_write_params_t_dec);
SER_REQ_DEC_END;
}
uint32_t ble_gattc_write_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_WRITE);
}
uint32_t ble_gattc_exchange_mtu_request_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
uint16_t * const p_client_rx_mtu)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTC_EXCHANGE_MTU_REQUEST);
SER_PULL_uint16(p_conn_handle);
SER_PULL_uint16(p_client_rx_mtu);
SER_REQ_DEC_END;
}
uint32_t ble_gattc_exchange_mtu_request_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTC_EXCHANGE_MTU_REQUEST);
}

View File

@@ -0,0 +1,481 @@
/**
* Copyright (c) 2013 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef BLE_GATTC_CONN_H__
#define BLE_GATTC_CONN_H__
/**@file
*
* @defgroup ble_gatc_conn GATTC connectivity command request decoders and command response encoders
* @{
* @ingroup ser_conn_s130_codecs
*
* @brief GATTC Connectivity command request decoders and command response encoders
*/
#include "ble_gattc.h"
#include "ble.h"
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Decodes @ref sd_ble_gattc_characteristics_discover command request.
*
* @sa @ref ble_gattc_characteristics_discover_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_conn_handle Pointer to connection handle.
* @param[out] pp_handle_range Pointer to pointer to handle range.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_DATA Decoding failure. Invalid value for handle range field present.
*/
uint32_t ble_gattc_characteristics_discover_req_dec
(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
ble_gattc_handle_range_t * * const pp_handle_range);
/**@brief Encodes @ref sd_ble_gattc_characteristics_discover command response.
*
* @sa @ref ble_gattc_characteristics_discover_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[in] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_characteristics_discover_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_gattc_descriptors_discover command request.
*
* @sa @ref ble_gattc_descriptors_discover_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_conn_handle Pointer to connection handle.
* @param[out] pp_handle_range Pointer to pointer to handle range.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_DATA Decoding failure. Invalid value for handle range field present.
*/
uint32_t ble_gattc_descriptors_discover_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
ble_gattc_handle_range_t * * const pp_handle_range);
/**@brief Encodes @ref sd_ble_gattc_descriptors_discover command response.
*
* @sa @ref ble_gattc_descriptors_discover_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[in] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_descriptors_discover_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_gattc_relationships_discover command request.
*
* @sa @ref ble_gattc_relationships_discover_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_conn_handle Pointer to connection handle.
* @param[out] pp_handle_range Pointer to pointer to handle range.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_DATA Decoding failure. Invalid value for handle range field present.
*/
uint32_t ble_gattc_relationships_discover_req_dec
(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
ble_gattc_handle_range_t * * const pp_handle_range);
/**@brief Encodes @ref sd_ble_gattc_relationships_discover command response.
*
* @sa @ref ble_gattc_relationships_discover_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[in] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_relationships_discover_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_gattc_primary_services_discover command request.
*
* @sa @ref ble_gattc_primary_services_discover_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_conn_handle Pointer to connection handle.
* @param[out] p_start_handle Pointer to start handle.
* @param[out] pp_srvc_uuid Pointer to pointer to service uuid.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_DATA Decoding failure. Invalid value for uuid field present.
*/
uint32_t ble_gattc_primary_services_discover_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
uint16_t * const p_start_handle,
ble_uuid_t * * const pp_srvc_uuid);
/**@brief Encodes @ref sd_ble_gattc_primary_services_discover command response.
*
* @sa @ref ble_gattc_primary_services_discover_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[in] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_primary_services_discover_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_gattc_read command request.
*
* @sa @ref ble_gattc_read_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_conn_handle Pointer to connection handle.
* @param[out] p_handle Pointer to handle.
* @param[out] p_offset Pointer to offset.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_read_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
uint16_t * const p_handle,
uint16_t * const p_offset);
/**@brief Encodes @ref sd_ble_gattc_read command response.
*
* @sa @ref ble_gattc_read_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[in] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_read_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_gattc_char_values_read command request.
*
* @sa @ref ble_gattc_char_values_read_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_conn_handle Pointer to connection handle.
* @param[out] pp_handles Pointer to pointer to handle table.
* @param[out] p_handle_count Pointer to handle handle table count.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_char_values_read_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
uint16_t * * const pp_handles,
uint16_t * const p_handle_count);
/**@brief Encodes @ref sd_ble_gattc_char_values_read command response.
*
* @sa @ref ble_gattc_char_values_read_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[in] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_char_values_read_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_gattc_write command request.
*
* @sa @ref ble_gattc_write_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_conn_handle Pointer to connection handle.
* @param[out] pp_write_params Pointer to pointer to write parameters.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_write_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
ble_gattc_write_params_t * * const pp_write_params);
/**@brief Encodes @ref sd_ble_gattc_write command response.
*
* @sa @ref ble_gattc_write_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[in] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_write_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_gattc_hv_confirm command request.
*
* @sa @ref ble_gattc_hv_confirm_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command response packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_conn_handle Pointer to connection handle.
* @param[out] p_handle Pointer to handle of the attribute in the indication.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_hv_confirm_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_conn_handle,
uint16_t * const p_handle);
/**@brief Encodes @ref sd_ble_gattc_hv_confirm command response.
*
* @sa @ref ble_gattc_hv_confirm_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[in] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_hv_confirm_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_gattc_char_value_by_uuid_read command request.
*
* @sa @ref ble_gattc_char_value_by_uuid_read_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of request packet.
* @param[out] p_conn_handle Pointer to connection handle of the connection.
* @param[out] pp_uuid Pointer to pointer to a characteristic value UUID to read.
* @param[out] pp_handle_range Pointer to pointer to the range of handles to perform this
* procedure on.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_DATA Decoding failure. Invalid operation type.
*/
uint32_t ble_gattc_char_value_by_uuid_read_req_dec
(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
ble_uuid_t * * const pp_uuid,
ble_gattc_handle_range_t * * const pp_handle_range);
/**@brief Encodes @ref sd_ble_gattc_char_value_by_uuid_read command response.
*
* @sa @ref ble_gattc_char_value_by_uuid_read_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[in] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_char_value_by_uuid_read_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_gattc_attr_info_discover command request.
*
* @sa @ref ble_gattc_attr_info_discover_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] buf_len Length (in bytes) of request packet.
* @param[out] p_conn_handle Pointer to connection handle of the connection.
* @param[out] pp_handle_range Pointer to pointer to the range of handles.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_DATA Decoding failure. Invalid operation type.
*/
uint32_t ble_gattc_attr_info_discover_req_dec(uint8_t const * const p_buf,
uint16_t buf_len,
uint16_t * const p_conn_handle,
ble_gattc_handle_range_t * * const pp_handle_range);
/**@brief Encodes @ref sd_ble_gattc_attr_info_discover command response.
*
* @sa @ref ble_gattc_attr_info_discover_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[in] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_attr_info_discover_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_gattc_exchange_mtu_request command request.
*
* @sa @ref ble_gattc_exchange_mtu_request_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of request packet.
* @param[out] p_conn_handle Pointer to connection handle of the connection.
* @param[out] p_client_rx_mtu Pointer to Client RX MTU size.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_DATA Decoding failure. Invalid operation type.
*/
uint32_t ble_gattc_exchange_mtu_request_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
uint16_t * const p_client_rx_mtu);
/**@brief Encodes @ref sd_ble_gattc_exchange_mtu_request command response.
*
* @sa @ref ble_gattc_exchange_mtu_request_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[in] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_exchange_mtu_request_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/** @} */
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,253 @@
/**
* Copyright (c) 2016 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "ble_gattc_evt_conn.h"
#include "ble_serialization.h"
#include "ble_gattc_struct_serialization.h"
#include "app_util.h"
#include <string.h>
uint32_t ble_gattc_evt_attr_info_disc_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_ATTR_INFO_DISC_RSP);
SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.attr_info_disc_rsp,
ble_gattc_evt_attr_info_disc_rsp_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gattc_evt_char_disc_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_CHAR_DISC_RSP);
SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.char_disc_rsp,
ble_gattc_evt_char_disc_rsp_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gattc_evt_char_val_by_uuid_read_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP);
SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.char_val_by_uuid_read_rsp,
ble_gattc_evt_char_val_by_uuid_read_rsp_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gattc_evt_char_vals_read_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_CHAR_VALS_READ_RSP);
SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.char_vals_read_rsp,
ble_gattc_evt_char_vals_read_rsp_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gattc_evt_desc_disc_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_DESC_DISC_RSP);
SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.desc_disc_rsp,
ble_gattc_evt_desc_disc_rsp_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gattc_evt_hvx_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_HVX);
SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.hvx, ble_gattc_evt_hvx_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gattc_evt_prim_srvc_disc_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP);
SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.prim_srvc_disc_rsp,
ble_gattc_evt_prim_srvc_disc_rsp_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gattc_evt_read_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_READ_RSP);
SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.read_rsp,
ble_gattc_evt_read_rsp_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gattc_evt_rel_disc_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_REL_DISC_RSP);
SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.rel_disc_rsp,
ble_gattc_evt_rel_disc_rsp_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gattc_evt_timeout_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_TIMEOUT);
SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.timeout,
ble_gattc_evt_timeout_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gattc_evt_write_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_WRITE_RSP);
SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.write_rsp,
ble_gattc_evt_write_rsp_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gattc_evt_exchange_mtu_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_EXCHANGE_MTU_RSP);
SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PUSH_FIELD(&p_event->evt.gattc_evt.params.exchange_mtu_rsp,
ble_gattc_evt_exchange_mtu_rsp_t_enc);
SER_EVT_ENC_END;
}
#if NRF_SD_BLE_API_VERSION >= 4
uint32_t ble_gattc_evt_write_cmd_tx_complete_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE);
SER_PUSH_uint16(&p_event->evt.gattc_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.gattc_evt.gatt_status);
SER_PUSH_uint16(&p_event->evt.gattc_evt.error_handle);
SER_PUSH_uint8(&p_event->evt.gattc_evt.params.write_cmd_tx_complete.count);
SER_EVT_ENC_END;
}
#endif

View File

@@ -0,0 +1,300 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef BLE_GATTC_EVT_CONN_H__
#define BLE_GATTC_EVT_CONN_H__
/**@file
*
* @defgroup ble_gattc_evt_conn GATTC Connectivity event encoders
* @{
* @ingroup ser_conn_s130_codecs
*
* @brief GATTC Connectivity event encoders.
*/
#include "ble.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Encodes ble_gattc_evt_char_disc_rsp event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_evt_char_disc_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gattc_evt_char_val_by_uuid_read_rsp event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_evt_char_val_by_uuid_read_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gattc_evt_char_vals_read_rsp event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_evt_char_vals_read_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gattc_evt_desc_disc_rsp event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_evt_desc_disc_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gattc_evt_hvx event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_evt_hvx_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gattc_evt_prim_srvc_disc_rsp event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_evt_prim_srvc_disc_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gattc_evt_read_rsp event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_evt_read_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gattc_evt_rel_disc_rsp event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_evt_rel_disc_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gattc_evt_timeout event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_evt_timeout_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gattc_evt_write_rsp event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_evt_write_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gattc_evt_attr_info_disc_rsp event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_evt_attr_info_disc_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes ble_gattc_evt_exchange_mtu_rsp event.
*
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_evt_exchange_mtu_rsp_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#if NRF_SD_BLE_API_VERSION >= 4
/**
* @brief Encodes @ref BLE_gattc_EVT_WRITE_CMD_TX_COMPLETE event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gattc_evt_write_cmd_tx_complete_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#endif
/** @} */
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,421 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "ble_gatts_conn.h"
#include <string.h>
#include "ble_serialization.h"
#include "ble_struct_serialization.h"
#include "ble_gatts_struct_serialization.h"
#include "app_util.h"
#include "cond_field_serialization.h"
uint32_t ble_gatts_attr_get_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * p_handle,
ble_uuid_t * * pp_uuid,
ble_gatts_attr_md_t * * pp_md)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTS_ATTR_GET);
SER_PULL_uint16(p_handle);
SER_PULL_COND(pp_uuid, NULL);
SER_PULL_COND(pp_md, NULL);
SER_REQ_DEC_END;
}
uint32_t ble_gatts_attr_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
ble_uuid_t * p_uuid,
ble_gatts_attr_md_t * p_md)
{
SER_RSP_ENC_BEGIN(SD_BLE_GATTS_ATTR_GET);
SER_PUSH_COND(p_uuid, ble_uuid_t_enc);
SER_PUSH_COND(p_md, ble_gatts_attr_md_t_enc);
SER_RSP_ENC_END;
}
uint32_t ble_gatts_characteristic_add_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * p_service_handle,
ble_gatts_char_md_t * * const pp_char_md,
ble_gatts_attr_t * * const pp_attr_char_value,
ble_gatts_char_handles_t * * const pp_handles)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTS_CHARACTERISTIC_ADD);
SER_PULL_uint16(p_service_handle);
SER_PULL_COND(pp_char_md, ble_gatts_char_md_t_dec);
SER_PULL_COND(pp_attr_char_value, ble_gatts_attr_t_dec);
SER_PULL_COND(pp_handles, NULL);
SER_REQ_DEC_END;
}
uint32_t ble_gatts_characteristic_add_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
ble_gatts_char_handles_t const * const p_handles)
{
SER_RSP_ENC_BEGIN(SD_BLE_GATTS_CHARACTERISTIC_ADD);
SER_PUSH_COND(p_handles, ble_gatts_char_handles_t_enc);
SER_RSP_ENC_END;
}
uint32_t ble_gatts_descriptor_add_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_char_handle,
ble_gatts_attr_t * * const pp_attr,
uint16_t * * const pp_handle)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTS_DESCRIPTOR_ADD);
SER_PULL_uint16(p_char_handle);
SER_PULL_COND(pp_attr, ble_gatts_attr_t_dec);
SER_PULL_COND(pp_handle, NULL);
SER_REQ_DEC_END;
}
uint32_t ble_gatts_descriptor_add_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint16_t * p_handle)
{
SER_RSP_ENC_BEGIN(SD_BLE_GATTS_DESCRIPTOR_ADD);
SER_PUSH_COND(p_handle,uint16_t_enc);
SER_RSP_ENC_END;
}
uint32_t ble_gatts_hvx_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_conn_handle,
ble_gatts_hvx_params_t * * const pp_hvx_params)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTS_HVX);
SER_PULL_uint16(p_conn_handle);
SER_PULL_COND(pp_hvx_params, ble_gatts_hvx_params_t_dec);
SER_REQ_DEC_END;
}
uint32_t ble_gatts_hvx_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint16_t const * const p_bytes_written)
{
SER_RSP_ENC_BEGIN(SD_BLE_GATTS_HVX);
SER_PUSH_COND(p_bytes_written, uint16_t_enc);
SER_RSP_ENC_END;
}
uint32_t ble_gatts_include_add_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_service_handle,
uint16_t * const p_inc_srvc_handle,
uint16_t * * const pp_include_handle)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTS_INCLUDE_ADD);
SER_PULL_uint16(p_service_handle);
SER_PULL_uint16(p_inc_srvc_handle);
SER_PULL_COND(pp_include_handle, NULL);
SER_REQ_DEC_END;
}
uint32_t ble_gatts_include_add_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint16_t const * const p_include_handle)
{
SER_RSP_ENC_BEGIN(SD_BLE_GATTS_INCLUDE_ADD);
SER_PUSH_COND(p_include_handle, uint16_t_enc);
SER_RSP_ENC_END;
}
uint32_t ble_gatts_initial_user_handle_get_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * * pp_handle)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTS_INITIAL_USER_HANDLE_GET);
SER_PULL_COND(pp_handle, NULL);
SER_REQ_DEC_END;
}
uint32_t ble_gatts_initial_user_handle_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint16_t * p_handle)
{
SER_RSP_ENC_BEGIN(SD_BLE_GATTS_INITIAL_USER_HANDLE_GET);
SER_PUSH_COND(p_handle, uint16_t_enc);
SER_RSP_ENC_END;
}
uint32_t ble_gatts_rw_authorize_reply_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * p_conn_handle,
ble_gatts_rw_authorize_reply_params_t * * const pp_reply_params)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTS_RW_AUTHORIZE_REPLY);
SER_PULL_uint16(p_conn_handle);
SER_PULL_COND(pp_reply_params, ble_gatts_rw_authorize_reply_params_t_dec);
SER_REQ_DEC_END;
}
uint32_t ble_gatts_rw_authorize_reply_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTS_RW_AUTHORIZE_REPLY);
}
uint32_t ble_gatts_service_add_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint8_t * const p_type,
ble_uuid_t * * const pp_uuid,
uint16_t * * const pp_handle)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTS_SERVICE_ADD);
SER_PULL_uint8(p_type);
SER_PULL_COND(pp_uuid, ble_uuid_t_dec);
SER_PULL_COND(pp_handle, NULL);
SER_REQ_DEC_END;
}
uint32_t ble_gatts_service_add_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint16_t const * const p_handle)
{
SER_RSP_ENC_BEGIN(SD_BLE_GATTS_SERVICE_ADD);
SER_PUSH_COND(p_handle, uint16_t_enc);
//SER_PUSH_uint16(p_handle);
SER_RSP_ENC_END;
}
uint32_t ble_gatts_service_changed_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * p_conn_handle,
uint16_t * p_start_handle,
uint16_t * p_end_handle)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTS_SERVICE_CHANGED);
SER_PULL_uint16(p_conn_handle);
SER_PULL_uint16(p_start_handle);
SER_PULL_uint16(p_end_handle);
SER_REQ_DEC_END;
}
uint32_t ble_gatts_service_changed_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTS_SERVICE_CHANGED);
}
uint32_t ble_gatts_sys_attr_get_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_conn_handle,
uint8_t * * const pp_sys_attr_data,
uint16_t * * const pp_sys_attr_data_len,
uint32_t * const p_flags)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTS_SYS_ATTR_GET);
SER_PULL_uint16(p_conn_handle);
SER_PULL_COND(pp_sys_attr_data_len, uint16_t_dec);
SER_PULL_COND(pp_sys_attr_data, NULL);
SER_PULL_uint32(p_flags);
SER_REQ_DEC_END;
}
uint32_t ble_gatts_sys_attr_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint8_t const * const p_sys_attr_data,
uint16_t const * const p_sys_attr_data_len)
{
SER_RSP_ENC_BEGIN(SD_BLE_GATTS_SYS_ATTR_GET);
SER_PUSH_COND(p_sys_attr_data_len, uint16_t_enc);
if (p_sys_attr_data_len)
{
SER_PUSH_buf(p_sys_attr_data, *p_sys_attr_data_len);
}
SER_RSP_ENC_END;
}
uint32_t ble_gatts_sys_attr_set_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_conn_handle,
uint8_t * * const pp_sys_attr_data,
uint16_t * const p_sys_attr_data_len,
uint32_t * const p_flags)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTS_SYS_ATTR_SET);
SER_PULL_uint16(p_conn_handle);
SER_PULL_len16data(pp_sys_attr_data, p_sys_attr_data_len);
SER_PULL_uint32(p_flags);
SER_REQ_DEC_END;
}
uint32_t ble_gatts_sys_attr_set_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTS_SYS_ATTR_SET);
}
uint32_t ble_gatts_value_get_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
uint16_t * const p_handle,
ble_gatts_value_t * * const pp_value)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTS_VALUE_GET);
SER_PULL_uint16(p_conn_handle);
SER_PULL_uint16(p_handle);
//Special case: skip the data.
SER_PULL_COND(pp_value, NULL);
if (*pp_value)
{
SER_PULL_uint16(&(*pp_value)->offset);
SER_PULL_uint16(&(*pp_value)->len);
SER_PULL_COND(&(*pp_value)->p_value, NULL);
}
SER_REQ_DEC_END;
}
uint32_t ble_gatts_value_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
ble_gatts_value_t * const p_value)
{
SER_RSP_ENC_BEGIN(SD_BLE_GATTS_VALUE_GET);
SER_PUSH_COND(p_value, ble_gatts_value_t_enc);
SER_RSP_ENC_END;
}
uint32_t ble_gatts_value_set_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * p_conn_handle,
uint16_t * p_handle,
ble_gatts_value_t * * const pp_value)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTS_VALUE_SET);
SER_PULL_uint16(p_conn_handle);
SER_PULL_uint16(p_handle);
SER_PULL_COND(pp_value, ble_gatts_value_t_dec);
SER_REQ_DEC_END;
}
uint32_t ble_gatts_value_set_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
ble_gatts_value_t * p_value)
{
SER_RSP_ENC_BEGIN(SD_BLE_GATTS_VALUE_SET);
SER_PUSH_COND(p_value, ble_gatts_value_t_enc);
SER_RSP_ENC_END;
}
uint32_t ble_gatts_exchange_mtu_reply_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
uint16_t * const p_server_rx_mtu)
{
SER_REQ_DEC_BEGIN(SD_BLE_GATTS_EXCHANGE_MTU_REPLY);
SER_PULL_uint16(p_conn_handle);
SER_PULL_uint16(p_server_rx_mtu);
SER_REQ_DEC_END;
}
uint32_t ble_gatts_exchange_mtu_reply_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_GATTS_EXCHANGE_MTU_REPLY);
}

View File

@@ -0,0 +1,634 @@
/**
* Copyright (c) 2013 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef BLE_GATTS_CONN_H__
#define BLE_GATTS_CONN_H__
/**@file
*
* @defgroup ble_gatts_conn GATTS Connectivity command request decoders and command response encoders
* @{
* @ingroup ser_conn_s130_codecs
*
* @brief GATTS Connectivity command request decoders and command response encoders.
*/
#include "ble_gatts.h"
#include "ble.h"
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Decodes @ref sd_ble_gatts_value_get command request.
*
* @sa @ref ble_gatts_value_get_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of request packet.
* @param[out] p_conn_handle Pointer to the connection_handle.
* @param[out] p_handle Pointer to the attribute_handle.
* @param[out] pp_value Pointer to pointer to the Attribute Value structure.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_value_get_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
uint16_t * const p_handle,
ble_gatts_value_t * * const pp_value);
/**@brief Encodes @ref sd_ble_gatts_value_get command response.
*
* @sa @ref ble_gatts_value_get_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_value Pointer to Attribute Value structure.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_value_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
ble_gatts_value_t * const p_value);
/**@brief Decodes @ref sd_ble_gatts_characteristic_add command request.
*
* @sa @ref ble_gatts_characteristic_add_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of request packet.
* @param[out] p_service_handle Pointer to the service_handle.
* @param[out] constpp_char_md Pointer to pointer to the location where Characteristic metadata
* will be decoded.
* @param[out] pp_attr_char_value Pointer to pointer to the location where GATT Attribute will be
* decoded.
* @param[out] pp_handles Pointer to pointer to the location where Characteristic definition
* handles will be decoded.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_characteristic_add_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * p_service_handle,
ble_gatts_char_md_t * * constpp_char_md,
ble_gatts_attr_t * * const pp_attr_char_value,
ble_gatts_char_handles_t * * const pp_handles);
/**@brief Encodes @ref ble_gatts_sys_attr_get_rsp_enc command response.
*
* @sa @ref ble_gatts_sys_attr_get_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_handles Pointer to handle struct to be encoded.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_characteristic_add_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
ble_gatts_char_handles_t const * const p_handles);
/**@brief Decodes @ref sd_ble_gatts_include_add command request.
*
* @sa @ref ble_gatts_include_add_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of request packet.
* @param[out] p_service_handle Pointer to the service_handle.
* @param[out] p_inc_srvc_handle Pointer to the handle of the included service.
* @param[out] pp_include_handle Pointer to Pointer to 16-bit word where the assigned handle will be stored.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_include_add_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_service_handle,
uint16_t * const p_inc_srvc_handle,
uint16_t * * const pp_include_handle);
/**@brief Encodes @ref ble_gatts_include_add_rsp_enc command response.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_include_handle Pointer to a 16-bit word where the assigned handle was stored.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_include_add_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint16_t const * const p_include_handle);
/**@brief Decodes @ref sd_ble_gatts_service_add command request.
*
* @sa @ref ble_gatts_service_add_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of request packet.
* @param[out] p_type Pointer to the service type.
* @param[out] pp_uuid Pointer to pointer to service UUID.
* @param[out] pp_handle Pointer to pointer to a 16-bit word where the assigned handle will be stored.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_service_add_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint8_t * const p_type,
ble_uuid_t * * const pp_uuid,
uint16_t * * const pp_handle);
/**@brief Encodes @ref ble_gatts_service_add_rsp_enc command response.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_handle Pointer to a 16-bit word where the assigned handle was stored.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_service_add_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint16_t const * const p_handle);
/**@brief Decodes @ref ble_gatts_sys_attr_get_req_dec command request.
*
* @sa @ref ble_gatts_sys_attr_get_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_conn_handle Pointer to connectiton handle.
* @param[out] pp_sys_attr_data Pointer to pointer to buffer where system attributes data will be filled in.
* @param[out] pp_sys_attr_data_len Pointer to pointer to variable which contains size of buffer for system attributes.
* @param[out] p_flags Pointer to additional optional flags.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_gatts_sys_attr_get_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_conn_handle,
uint8_t * * const pp_sys_attr_data,
uint16_t * * const pp_sys_attr_data_len,
uint32_t * const p_flags);
/**@brief Encodes @ref ble_gatts_sys_attr_get_rsp_enc command response.
*
* @sa @ref ble_gatts_sys_attr_get_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_sys_attr_data Pointer to buffer where system attributes data are stored.
* @param[in] p_sys_attr_data_len Pointer to variable which contains size of buffer for system attributes.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_sys_attr_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint8_t const * const p_sys_attr_data,
uint16_t const * const p_sys_attr_data_len);
/**@brief Decodes @ref sd_ble_gatts_value_set command request.
*
* @sa @ref ble_gatts_value_set_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_conn_handle Pointer to connection handle.
* @param[out] p_handle Pointer to attribute handle.
* @param[out] pp_value Pointer to pointer to attribute value structure.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_gatts_value_set_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * p_conn_handle,
uint16_t * p_handle,
ble_gatts_value_t * * const pp_value);
/**@brief Encodes @ref sd_ble_gatts_value_set command response.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[in] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in, out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_value \c in: size of value returned when value was written with success
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_value_set_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
ble_gatts_value_t * p_value);
/**@brief Decodes @ref sd_ble_gatts_sys_attr_set command request.
*
* @sa @ref ble_gatts_sys_attr_set_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of request packet.
* @param[out] p_conn_handle Pointer to the buffer raw data to be placed in advertisement packet.
* @param[out] pp_sys_attr_data Pointer to pointer to system attribute data.
* @param[out] p_sys_attr_data_len Pointer to data length for system attribute data.
* @param[out] p_flags Pointer to additional optional flags.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_sys_attr_set_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_conn_handle,
uint8_t * * const pp_sys_attr_data,
uint16_t * const p_sys_attr_data_len,
uint32_t * const p_flags);
/**@brief Encodes @ref sd_ble_gatts_sys_attr_set command response.
*
* @sa @ref ble_gatts_sys_attr_set_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_sys_attr_set_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref ble_gatts_hvx_req_dec command request.
*
* @sa @ref ble_gatts_hvx_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of request packet.
* @param[out] p_conn_handle Pointer to the buffer raw data to be placed in advertisement packet.
* @param[out] pp_hvx_params Pointer to an HVx parameters structure.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_hvx_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_conn_handle,
ble_gatts_hvx_params_t * * const pp_hvx_params);
/**@brief Encodes @ref ble_gatts_hvx_rsp_enc command response.
*
* @sa @ref ble_gatts_hvx_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_bytes_written Pointer to number of bytes written.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_hvx_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint16_t const * const p_bytes_written);
/**@brief Decodes @ref sd_ble_gatts_descriptor_add command request.
*
* @sa @ref ble_gatts_descriptor_add_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of request packet.
* @param[out] p_char_handle Pointer to buffer where characteristic handle will be.
returned.
* @param[out] pp_attr Pointer to pointer to an attribute structure.
* @param[out] pp_handle Pointer to pointer to descriptor handle.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_descriptor_add_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * const p_char_handle,
ble_gatts_attr_t * * const pp_attr,
uint16_t * * const pp_handle);
/**@brief Encodes @ref sd_ble_gatts_descriptor_add command response.
*
* @sa @ref ble_gatts_descriptor_add_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_handle Pointer to descriptor handle value.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_descriptor_add_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint16_t * p_handle);
/**@brief Decodes @ref sd_ble_gatts_rw_authorize_reply command request.
*
* @sa @ref ble_gatts_rw_authorize_reply_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_conn_handle Pointer to connection handle.
* @param[out] pp_reply_params Pointer to pointer to \ref ble_gatts_rw_authorize_reply_params_t .
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_gatts_rw_authorize_reply_req_dec(
uint8_t const * const p_buf,
uint32_t
packet_len,
uint16_t *
p_conn_handle,
ble_gatts_rw_authorize_reply_params_t * * const
pp_reply_params);
/**@brief Encodes @ref sd_ble_gatts_rw_authorize_reply command response.
*
* @sa @ref ble_gatts_rw_authorize_reply_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_rw_authorize_reply_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_gatts_service_changed command request.
*
* @sa @ref ble_gatts_service_changed_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_conn_handle Pointer to connection handle.
* @param[out] p_start_handle Pointer to start handle.
* @param[out] p_end_handle Pointer to end handle.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_gatts_service_changed_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * p_conn_handle,
uint16_t * p_start_handle,
uint16_t * p_end_handle);
/**@brief Encodes @ref sd_ble_gatts_service_changed command response.
*
* @sa @ref ble_gatts_service_changed_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_service_changed_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref ble_gatts_attr_get_req_dec command request.
*
* @sa @ref ble_gatts_attr_get_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_handle Pointer to handle.
* @param[out] pp_uuid Pointer to pointer to location for decoded uuid structure.
* @param[out] pp_md Pointer to pointer to location for md structure.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_gatts_attr_get_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * p_handle,
ble_uuid_t * * pp_uuid,
ble_gatts_attr_md_t * * pp_md);
/**@brief Encodes @ref ble_gatts_attr_get_rsp_enc command response.
*
* @sa @ref ble_gatts_attr_get_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_uuid Pointer to structure to be encoded.
* @param[in] p_md Pointer to structure to be encoded.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_attr_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
ble_uuid_t * p_uuid,
ble_gatts_attr_md_t * p_md);
/**@brief Decodes @ref ble_gatts_initial_user_handle_get_req_dec command request.
*
* @sa @ref ble_gatts_initial_user_handle_get_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] pp_handle Pointer to pointer to handle.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_gatts_initial_user_handle_get_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
uint16_t * * pp_handle);
/**@brief Encodes @ref ble_gatts_initial_user_handle_get_rsp_enc command response.
*
* @sa @ref ble_gatts_initial_user_handle_get_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_handle Pointer to handle to be encoded.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_initial_user_handle_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint16_t * p_handle);
/**@brief Decodes @ref sd_ble_gatts_rw_authorize_reply command request.
*
* @ref ble_gatts_exchange_mtu_reply_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] packet_len Length (in bytes) of response packet.
* @param[out] p_conn_handle Pointer to connection handle.
* @param[out] p_server_rx_mtu Pointer to Server RX MTU size.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_gatts_exchange_mtu_reply_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * const p_conn_handle,
uint16_t * const p_server_rx_mtu);
/**@brief Encodes @ref sd_ble_gatts_rw_authorize_reply command response.
*
* @ref ble_gatts_exchange_mtu_reply_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_exchange_mtu_reply_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/** @} */
#ifdef __cplusplus
}
#endif
#endif //BLE_GATTS_CONN_H__

View File

@@ -0,0 +1,178 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "ble_gatts_evt_conn.h"
#include "ble_serialization.h"
#include "ble_gatts_struct_serialization.h"
#include "conn_ble_user_mem.h"
#include "app_util.h"
extern sercon_ble_user_mem_t m_conn_user_mem_table[];
uint32_t ble_gatts_evt_rw_authorize_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST);
SER_PUSH_uint16(&p_event->evt.gatts_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gatts_evt.params.authorize_request, ble_gatts_evt_rw_authorize_request_t_enc);
if ((p_event->evt.gatts_evt.params.authorize_request.type == BLE_GATTS_AUTHORIZE_TYPE_WRITE) &&
((p_event->evt.gatts_evt.params.authorize_request.request.write.op == BLE_GATTS_OP_EXEC_WRITE_REQ_NOW) ||
(p_event->evt.gatts_evt.params.authorize_request.request.write.op == BLE_GATTS_OP_PREP_WRITE_REQ)))
{
uint32_t conn_index;
if (conn_ble_user_mem_context_find(p_event->evt.gatts_evt.conn_handle, &conn_index) != NRF_ERROR_NOT_FOUND)
{
err_code = len16data_enc(m_conn_user_mem_table[conn_index].mem_block.p_mem, m_conn_user_mem_table[conn_index].mem_block.len, p_buf, *p_buf_len, &index);
SER_ASSERT(err_code == NRF_SUCCESS, err_code);
}
}
SER_EVT_ENC_END;
}
uint32_t ble_gatts_evt_hvc_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTS_EVT_HVC);
SER_PUSH_uint16(&p_event->evt.gatts_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gatts_evt.params.hvc, ble_gatts_evt_hvc_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gatts_evt_sc_confirm_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTS_EVT_SC_CONFIRM);
SER_PUSH_uint16(&p_event->evt.gatts_evt.conn_handle);
SER_EVT_ENC_END;
}
uint32_t ble_gatts_evt_sys_attr_missing_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTS_EVT_SYS_ATTR_MISSING);
SER_PUSH_uint16(&p_event->evt.gatts_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gatts_evt.params.sys_attr_missing, ble_gatts_evt_sys_attr_missing_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gatts_evt_timeout_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTS_EVT_TIMEOUT);
SER_PUSH_uint16(&p_event->evt.gatts_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gatts_evt.params.timeout, ble_gatts_evt_timeout_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_gatts_evt_write_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTS_EVT_WRITE);
SER_PUSH_uint16(&p_event->evt.gatts_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gatts_evt.params.write, ble_gatts_evt_write_t_enc);
if ((p_event->evt.gatts_evt.params.write.op == BLE_GATTS_OP_WRITE_REQ) || (p_event->evt.gatts_evt.params.write.op == BLE_GATTS_OP_EXEC_WRITE_REQ_NOW))
{
uint32_t conn_index;
if (conn_ble_user_mem_context_find(p_event->evt.gatts_evt.conn_handle, &conn_index) != NRF_ERROR_NOT_FOUND)
{
SER_PUSH_len16data(m_conn_user_mem_table[conn_index].mem_block.p_mem, m_conn_user_mem_table[conn_index].mem_block.len);
}
}
SER_EVT_ENC_END;
}
uint32_t ble_gatts_evt_exchange_mtu_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST);
SER_PUSH_uint16(&p_event->evt.gatts_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.gatts_evt.params.exchange_mtu_request, ble_gatts_evt_exchange_mtu_request_t_enc);
SER_EVT_ENC_END;
}
#if NRF_SD_BLE_API_VERSION >= 4
uint32_t ble_gatts_evt_hvn_tx_complete_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_GATTS_EVT_HVN_TX_COMPLETE);
SER_PUSH_uint16(&p_event->evt.gatts_evt.conn_handle);
SER_PUSH_uint8(&p_event->evt.gatts_evt.params.hvn_tx_complete.count);
SER_EVT_ENC_END;
}
#endif

View File

@@ -0,0 +1,208 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef BLE_GATTS_EVT_CONN_H__
#define BLE_GATTS_EVT_CONN_H__
/**@file
*
* @defgroup ble_gatts_evt_conn GATTS Connectivity event encoders
* @{
* @ingroup ser_conn_s130_codecs
*
* @brief GATTS Connectivity event encoders.
*/
#include "ble.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Encodes @ref BLE_GATTS_EVT_HVC event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_evt_hvc_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes @ref BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_evt_rw_authorize_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes @ref BLE_GATTS_EVT_SC_CONFIRM event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_evt_sc_confirm_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes @ref BLE_GATTS_EVT_SYS_ATTR_MISSING event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_evt_sys_attr_missing_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes @ref BLE_GATTS_EVT_TIMEOUT event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_evt_timeout_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes @ref BLE_GATTS_EVT_WRITE event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_evt_write_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**
* @brief Encodes @ref BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_evt_exchange_mtu_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#if NRF_SD_BLE_API_VERSION >= 4
/**
* @brief Encodes @ref BLE_GATTS_EVT_HVN_TX_COMPLETE event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_gatts_evt_hvn_tx_complete_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#endif
/** @} */
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,323 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <stdlib.h>
#include <string.h>
#include "ble_l2cap_conn.h"
#include "ble_serialization.h"
#include "ble_struct_serialization.h"
#include "ble_l2cap_struct_serialization.h"
#include "cond_field_serialization.h"
#include "conn_ble_l2cap_sdu_pool.h"
#include "app_util.h"
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
uint32_t ble_l2cap_cid_register_req_dec(uint8_t const * const p_buf,
uint32_t buf_len,
uint16_t * p_cid)
{
uint32_t index = 0;
uint32_t err_code = NRF_SUCCESS;
SER_ASSERT_NOT_NULL(p_cid);
SER_ASSERT_NOT_NULL(p_buf);
SER_ASSERT_LENGTH_EQ(3, buf_len);
SER_ASSERT(p_buf[index] == SD_BLE_L2CAP_CID_REGISTER, NRF_ERROR_INVALID_PARAM);
index++;
err_code = uint16_t_dec(p_buf, buf_len, &index, p_cid);
SER_ASSERT(err_code == NRF_SUCCESS, err_code);
SER_ASSERT_LENGTH_EQ(index, buf_len);
return err_code;
}
uint32_t ble_l2cap_cid_register_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
return ser_ble_cmd_rsp_status_code_enc(SD_BLE_L2CAP_CID_REGISTER, return_code,
p_buf, p_buf_len);
}
uint32_t ble_l2cap_cid_unregister_req_dec(uint8_t const * const p_buf,
uint32_t buf_len,
uint16_t * p_cid)
{
uint32_t index = 0;
uint32_t err_code = NRF_SUCCESS;
SER_ASSERT_NOT_NULL(p_cid);
SER_ASSERT_NOT_NULL(p_buf);
SER_ASSERT_LENGTH_EQ(3, buf_len);
SER_ASSERT(p_buf[index] == SD_BLE_L2CAP_CID_UNREGISTER, NRF_ERROR_INVALID_PARAM);
index++;
err_code = uint16_t_dec(p_buf, buf_len, &index, p_cid);
SER_ASSERT(err_code == NRF_SUCCESS, err_code);
SER_ASSERT_LENGTH_EQ(index, buf_len);
return err_code;
}
uint32_t ble_l2cap_cid_unregister_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
return ser_ble_cmd_rsp_status_code_enc(SD_BLE_L2CAP_CID_UNREGISTER, return_code,
p_buf, p_buf_len);
}
uint32_t ble_l2cap_tx_req_dec(uint8_t const * const p_buf,
uint32_t const buf_len,
uint16_t * p_conn_handle,
ble_l2cap_header_t * * const pp_l2cap_header,
uint8_t const * * pp_data)
{
SER_ASSERT_NOT_NULL(p_buf);
SER_ASSERT_NOT_NULL(p_conn_handle);
SER_ASSERT_NOT_NULL(pp_l2cap_header);
SER_ASSERT_NOT_NULL(*pp_l2cap_header);
SER_ASSERT_NOT_NULL(pp_data);
//SER_ASSERT_NOT_NULL(*pp_data);
uint32_t err_code = NRF_SUCCESS;
uint32_t index = SER_CMD_DATA_POS;
err_code = uint16_t_dec(p_buf, buf_len, &index, p_conn_handle);
SER_ASSERT(err_code == NRF_SUCCESS, err_code);
err_code = cond_field_dec(p_buf, buf_len, &index, (void * *)pp_l2cap_header,
ble_l2cap_header_t_dec);
SER_ASSERT(err_code == NRF_SUCCESS, err_code);
if (*pp_l2cap_header != NULL)
{
*pp_data = p_buf + index + 1;
index += 1 + (*pp_l2cap_header)->len;
}
else
{
*pp_data = NULL;
index++;
}
SER_ASSERT_LENGTH_EQ(index, buf_len);
return err_code;
}
uint32_t ble_l2cap_tx_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
return ser_ble_cmd_rsp_status_code_enc(SD_BLE_L2CAP_TX, return_code,
p_buf, p_buf_len);
}
#endif
#if NRF_SD_BLE_API_VERSION >= 5
uint32_t ble_l2cap_ch_setup_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * p_conn_handle,
uint16_t * * pp_local_cid,
ble_l2cap_ch_setup_params_t * * const pp_params)
{
SER_REQ_DEC_BEGIN(SD_BLE_L2CAP_CH_SETUP);
SER_PULL_uint16(p_conn_handle);
SER_PULL_COND(pp_local_cid, uint16_t_dec);
SER_PULL_COND(pp_params, ble_l2cap_ch_setup_params_t_dec);
if (*pp_params && (*pp_params)->rx_params.sdu_buf.p_data)
{
SER_ASSERT_LENGTH_LEQ((*pp_params)->rx_params.sdu_buf.len, CONN_BLE_L2CAP_SDU_MAX_BUFFER_SIZE);
uint8_t * p_data = conn_ble_l2cap_sdu_pool_alloc((*pp_params)->rx_params.sdu_buf.len,
(uint32_t)((*pp_params)->rx_params.sdu_buf.p_data));
(*pp_params)->rx_params.sdu_buf.p_data = p_data;
}
SER_REQ_DEC_END;
}
uint32_t ble_l2cap_ch_setup_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint16_t * p_local_cid)
{
SER_RSP_ENC_BEGIN(SD_BLE_L2CAP_CH_SETUP);
SER_PUSH_COND(p_local_cid, uint16_t_enc);
SER_RSP_ENC_END;
}
uint32_t ble_l2cap_ch_release_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * p_conn_handle,
uint16_t * p_local_cid)
{
SER_REQ_DEC_BEGIN(SD_BLE_L2CAP_CH_RELEASE);
SER_PULL_uint16(p_conn_handle);
SER_PULL_uint16(p_local_cid);
SER_REQ_DEC_END;
}
uint32_t ble_l2cap_ch_release_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_L2CAP_CH_RELEASE);
}
uint32_t ble_l2cap_ch_rx_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * p_conn_handle,
uint16_t * p_local_cid,
ble_data_t * * pp_sdu_buf)
{
SER_REQ_DEC_BEGIN(SD_BLE_L2CAP_CH_RX);
SER_PULL_uint16(p_conn_handle);
SER_PULL_uint16(p_local_cid);
uint8_t * p_tmp = (uint8_t *)1;
SER_PULL_COND(&p_tmp, NULL);
if (p_tmp)
{
SER_PULL_uint16((uint16_t*)&(*pp_sdu_buf)->len);
uint32_t addr;
SER_PULL_uint32(&addr);
SER_ASSERT_LENGTH_LEQ((*pp_sdu_buf)->len, CONN_BLE_L2CAP_SDU_MAX_BUFFER_SIZE);
uint8_t * p_data = conn_ble_l2cap_sdu_pool_alloc((*pp_sdu_buf)->len, addr);
(*pp_sdu_buf)->p_data = p_data;
}
else
{
*pp_sdu_buf = NULL;
}
SER_REQ_DEC_END;
}
uint32_t ble_l2cap_ch_rx_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_L2CAP_CH_RX);
}
uint32_t ble_l2cap_ch_tx_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * p_conn_handle,
uint16_t * p_local_cid,
ble_data_t * * const pp_sdu_buf)
{
SER_REQ_DEC_BEGIN(SD_BLE_L2CAP_CH_TX);
SER_PULL_uint16(p_conn_handle);
SER_PULL_uint16(p_local_cid);
uint8_t * p_tmp = (uint8_t *)1;
SER_PULL_COND(&p_tmp, NULL);
if (p_tmp)
{
uint32_t id;
uint16_t len;
SER_PULL_uint32(&id);
SER_PULL_uint16(&len);
SER_ASSERT_LENGTH_LEQ(len, CONN_BLE_L2CAP_SDU_MAX_BUFFER_SIZE);
uint8_t * p_data = conn_ble_l2cap_sdu_pool_alloc(len, id);
if (p_data)
{
SER_PULL_buf(&p_data, len, len);
}
(*pp_sdu_buf)->p_data = p_data;
(*pp_sdu_buf)->len = len;
}
else
{
*pp_sdu_buf = NULL;
}
SER_REQ_DEC_END;
}
uint32_t ble_l2cap_ch_tx_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_RSP_ENC_RESULT_ONLY(SD_BLE_L2CAP_CH_TX);
}
uint32_t ble_l2cap_ch_flow_control_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * p_conn_handle,
uint16_t * p_local_cid,
uint16_t * p_credits,
uint16_t * * pp_credits)
{
SER_REQ_DEC_BEGIN(SD_BLE_L2CAP_CH_FLOW_CONTROL);
SER_PULL_uint16(p_conn_handle);
SER_PULL_uint16(p_local_cid);
SER_PULL_uint16(p_credits);
SER_PULL_COND(pp_credits, NULL);
SER_REQ_DEC_END;
}
uint32_t ble_l2cap_ch_flow_control_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint16_t const * const p_credits)
{
SER_RSP_ENC_BEGIN(SD_BLE_L2CAP_CH_FLOW_CONTROL);
SER_PUSH_COND(p_credits, uint16_t_enc);
SER_RSP_ENC_END;
}
#endif //NRF_SD_BLE_API_VERSION >= 5

View File

@@ -0,0 +1,384 @@
/**
* Copyright (c) 2011 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/**@file
*
* @defgroup ble_l2cap_conn L2CAP Connectivity command request decoders and command response encoders
* @{
* @ingroup ser_conn_s130_codecs
*
* @brief L2CAP Connectivity command request decoders and command response encoders.
*/
#ifndef BLE_L2CAP_CONN_H__
#define BLE_L2CAP_CONN_H__
#include "ble.h"
#include "ble_types.h"
#include "ble_ranges.h"
#include "ble_err.h"
#include "ble_l2cap.h"
#ifdef __cplusplus
extern "C" {
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
/**@brief Decodes @ref sd_ble_l2cap_cid_register command request.
*
* @sa @ref ble_l2cap_cid_register_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] buf_len Length (in bytes) of response packet.
* @param[in] p_cid Pointer to L2CAP CID.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_l2cap_cid_register_req_dec(uint8_t const * const p_buf,
uint32_t buf_len,
uint16_t * p_cid);
/**@brief Encodes @ref sd_ble_l2cap_cid_register command response.
*
* @sa @ref ble_l2cap_cid_register_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_l2cap_cid_register_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_l2cap_cid_unregister command request.
*
* @sa @ref ble_l2cap_cid_unregister_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] buf_len Length (in bytes) of response packet.
* @param[in] p_cid Pointer to L2CAP CID.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_l2cap_cid_unregister_req_dec(uint8_t const * const p_buf,
uint32_t buf_len,
uint16_t * p_cid);
/**@brief Encodes @ref sd_ble_l2cap_cid_unregister command response.
*
* @sa @ref ble_l2cap_cid_unregister_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_l2cap_cid_unregister_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_l2cap_tx command request.
*
* @sa @ref ble_l2cap_tx_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] buf_len Length (in bytes) of response packet.
* @param[in] p_conn_handle Pointer to connection handle.
* @param[in] pp_l2cap_header Pointer to pointer to L2CAP header.
* @param[in] pp_data Pointer to pointer L2CAP data.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_l2cap_tx_req_dec(uint8_t const * const p_buf,
uint32_t const buf_len,
uint16_t * p_conn_handle,
ble_l2cap_header_t * * const pp_l2cap_header,
uint8_t const * * pp_data);
/**@brief Encodes @ref sd_ble_l2cap_tx command response.
*
* @sa @ref ble_l2cap_tx_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_l2cap_tx_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION >= 5
/**@brief Decodes @ref sd_ble_l2cap_ch_setup command request.
*
* @sa @ref ble_l2cap_ch_setup_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] buf_len Length (in bytes) of response packet.
* @param[in] p_conn_handle Pointer to connection handle.
* @param[in, out] pp_local_cid Pointer to pointer to local cid.
* @param[in, out] pp_params Pointer to pointer to params.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_l2cap_ch_setup_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * p_conn_handle,
uint16_t * * pp_local_cid,
ble_l2cap_ch_setup_params_t * * const pp_params);
/**@brief Encodes @ref sd_ble_l2cap_ch_setup command response.
*
* @sa @ref ble_l2cap_ch_setup_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[p_local_cid Pointer to local cid.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_l2cap_ch_setup_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint16_t * p_local_cid);
/**@brief Decodes @ref sd_ble_l2cap_ch_release command request.
*
* @sa @ref ble_l2cap_ch_release_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] buf_len Length (in bytes) of response packet.
* @param[in] p_conn_handle Pointer to connection handle.
* @param[in] p_local_cid Pointer to local cid.
* @param[in] pp_data Pointer to pointer L2CAP data.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_l2cap_ch_release_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * p_conn_handle,
uint16_t * p_local_cid);
/**@brief Encodes @ref sd_ble_l2cap_ch_releasecommand response.
*
* @sa @ref ble_l2cap_ch_release_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_l2cap_ch_release_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_l2cap_ch_rx command request.
*
* @sa @ref ble_l2cap_ch_rx_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] buf_len Length (in bytes) of response packet.
* @param[in] p_conn_handle Pointer to connection handle.
* @param[in] p_local_cid Pointer to local cid.
* @param[in] pp_sdu_buf Pointer to pointer to SDU buf.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_l2cap_ch_rx_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * p_conn_handle,
uint16_t * p_local_cid,
ble_data_t * * pp_sdu_buf);
/**@brief Encodes @ref sd_ble_l2cap_ch_rx command response.
*
* @sa @ref ble_l2cap_ch_rx_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_l2cap_ch_rx_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_l2cap_ch_tx command request.
*
* @sa @ref ble_l2cap_ch_tx_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] buf_len Length (in bytes) of response packet.
* @param[in] p_conn_handle Pointer to connection handle.
* @param[in] p_local_cid Pointer to local cid.
* @param[in] pp_sdu_buf Pointer to pointer to SDU buf.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_l2cap_ch_tx_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * p_conn_handle,
uint16_t * p_local_cid,
ble_data_t * * const pp_sdu_buf);
/**@brief Encodes @ref sd_ble_l2cap_ch_tx command response.
*
* @sa @ref ble_l2cap_ch_tx_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_l2cap_ch_tx_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/**@brief Decodes @ref sd_ble_l2cap_ch_flow_control command request.
*
* @sa @ref ble_l2cap_ch_flow_control_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to beginning of command request packet.
* @param[in] buf_len Length (in bytes) of response packet.
* @param[in] p_conn_handle Pointer to connection handle.
* @param[in] p_local_cid Pointer to local cid.
* @param[in] p_credits Pointer to credits.
* @param[in,out] pp_credits Pointer to pointer to credits.
*
* @retval NRF_SUCCESS Decoding success.
* @retval NRF_ERROR_NULL Decoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
* @retval NRF_ERROR_INVALID_PARAM Decoding failure. Invalid operation type.
*/
uint32_t ble_l2cap_ch_flow_control_req_dec(uint8_t const * const p_buf,
uint16_t packet_len,
uint16_t * p_conn_handle,
uint16_t * p_local_cid,
uint16_t * p_credits,
uint16_t * * pp_credits);
/**@brief Encodes @ref sd_ble_l2cap_ch_flow_control command response.
*
* @sa @ref ble_l2cap_ch_flow_control_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_credits Pointer to credits.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_l2cap_ch_flow_control_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
uint16_t const * const p_credits);
#endif
#ifdef __cplusplus
}
#endif
#endif //BLE_L2CAP_CONN_H__
/**
@}
*/

View File

@@ -0,0 +1,199 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "ble_l2cap_evt_conn.h"
#include <string.h>
#include "ble_serialization.h"
#include "ble_struct_serialization.h"
#include "ble_l2cap_struct_serialization.h"
#include "app_util.h"
#include "conn_ble_l2cap_sdu_pool.h"
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION < 4
uint32_t ble_l2cap_evt_rx_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_L2CAP_EVT_RX);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.conn_handle);
SER_PUSH_FIELD(&p_event->evt.l2cap_evt.params.rx, ble_l2cap_evt_rx_t_enc);
SER_EVT_ENC_END;
}
#endif
#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION >= 5
uint32_t ble_l2cap_evt_ch_setup_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_L2CAP_EVT_CH_SETUP_REQUEST);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.local_cid);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.params.ch_setup_request.le_psm);
SER_PUSH_FIELD(&p_event->evt.l2cap_evt.params.ch_setup_request.tx_params, ble_l2cap_ch_tx_params_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_l2cap_evt_ch_setup_refused_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_L2CAP_EVT_CH_SETUP_REFUSED);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.local_cid);
SER_PUSH_uint8(&p_event->evt.l2cap_evt.params.ch_setup_refused.source);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.params.ch_setup_refused.status);
SER_EVT_ENC_END;
}
uint32_t ble_l2cap_evt_ch_setup_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_L2CAP_EVT_CH_SETUP);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.local_cid);
SER_PUSH_FIELD(&p_event->evt.l2cap_evt.params.ch_setup.tx_params, ble_l2cap_ch_tx_params_t_enc);
SER_EVT_ENC_END;
}
uint32_t ble_l2cap_evt_ch_released_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_L2CAP_EVT_CH_RELEASED);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.local_cid);
SER_EVT_ENC_END;
}
uint32_t ble_l2cap_evt_ch_sdu_buf_released_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_L2CAP_EVT_CH_SDU_BUF_RELEASED);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.local_cid);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.params.ch_sdu_buf_released.sdu_buf.len);
uint32_t * p_data = (uint32_t *)p_event->evt.l2cap_evt.params.ch_sdu_buf_released.sdu_buf.p_data;
if (p_data)
{
uint32_t id = *(p_data - 1);
conn_ble_l2cap_sdu_pool_free(p_data);
SER_PUSH_uint32(&id);
}
SER_EVT_ENC_END;
}
uint32_t ble_l2cap_evt_ch_credit_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_L2CAP_EVT_CH_CREDIT);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.local_cid);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.params.credit.credits);
SER_EVT_ENC_END;
}
uint32_t ble_l2cap_evt_ch_rx_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_L2CAP_EVT_CH_RX);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.local_cid);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.params.rx.sdu_len);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.params.rx.sdu_buf.len);
uint32_t * p_data = (uint32_t *)p_event->evt.l2cap_evt.params.rx.sdu_buf.p_data;
uint32_t id = *(p_data - 1);
SER_PUSH_uint32(&id);
SER_PUSH_buf(p_event->evt.l2cap_evt.params.rx.sdu_buf.p_data, p_event->evt.l2cap_evt.params.rx.sdu_buf.len);
conn_ble_l2cap_sdu_pool_free(p_data);
SER_EVT_ENC_END;
}
uint32_t ble_l2cap_evt_ch_tx_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len)
{
SER_EVT_ENC_BEGIN(BLE_L2CAP_EVT_CH_TX);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.conn_handle);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.local_cid);
SER_PUSH_uint16(&p_event->evt.l2cap_evt.params.tx.sdu_buf.len);
uint32_t * p_data = (uint32_t *)p_event->evt.l2cap_evt.params.tx.sdu_buf.p_data;
if (p_data)
{
uint32_t id = *(p_data - 1);
conn_ble_l2cap_sdu_pool_free(p_data);
SER_PUSH_uint32(&id);
}
SER_EVT_ENC_END;
}
#endif

View File

@@ -0,0 +1,121 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef BLE_L2CAP_EVT_CONN_H__
#define BLE_L2CAP_EVT_CONN_H__
/**@file
*
* @defgroup ble_l2cap_evt_conn L2CAP Connectivity event encoders
* @{
* @ingroup ser_conn_s130_codecs
*
* @brief L2CAP Connectivity event encoders.
*/
#include "ble.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Encodes ble_l2cap_evt_rx event.
*
* @param[in] p_event Pointer to the \ref ble_evt_t buffer that shall be encoded.
* @param[in] event_len Size (in bytes) of \p p_event buffer.
* @param[out] p_buf Pointer to the beginning of a buffer for encoded event packet.
* @param[in,out] p_buf_len \c in: Size (in bytes) of \p p_buf buffer.
* \c out: Length of encoded contents in \p p_buf.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ble_l2cap_evt_rx_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
uint32_t ble_l2cap_evt_ch_setup_request_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
uint32_t ble_l2cap_evt_ch_setup_refused_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
uint32_t ble_l2cap_evt_ch_setup_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
uint32_t ble_l2cap_evt_ch_released_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
uint32_t ble_l2cap_evt_ch_sdu_buf_released_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
uint32_t ble_l2cap_evt_ch_credit_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
uint32_t ble_l2cap_evt_ch_rx_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
uint32_t ble_l2cap_evt_ch_tx_enc(ble_evt_t const * const p_event,
uint32_t event_len,
uint8_t * const p_buf,
uint32_t * const p_buf_len);
/** @} */
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,202 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "conn_ble_gap_sec_keys.h"
#include "ser_config.h"
#include "nrf_error.h"
#include "nordic_common.h"
#include <stddef.h>
ser_ble_gap_conn_keyset_t m_conn_keys_table[SER_MAX_CONNECTIONS];
#if NRF_SD_BLE_API_VERSION >= 6
typedef struct
{
uint32_t id;
uint8_t ble_data[SER_MAX_ADV_DATA];
} ble_data_item_t;
ble_data_item_t m_ble_data_pool[8];
static uint8_t * mp_scan_data;
#endif
void conn_ble_gap_sec_keys_init(void)
{
uint32_t i;
for (i = 0; i < SER_MAX_CONNECTIONS; i++)
{
m_conn_keys_table[i].conn_active = 0;
}
#if NRF_SD_BLE_API_VERSION >= 6
for (i = 0; i < 8; i++)
{
m_ble_data_pool[i].id = 0;
}
#endif
}
uint32_t conn_ble_gap_sec_context_create(uint32_t *p_index)
{
uint32_t err_code = NRF_ERROR_NO_MEM;
uint32_t i;
for (i=0; i<SER_MAX_CONNECTIONS; i++ )
{
if ( ! m_conn_keys_table[i].conn_active )
{
m_conn_keys_table[i].conn_active = 1;
*p_index = i;
err_code = NRF_SUCCESS;
break;
}
}
return err_code;
}
uint32_t conn_ble_gap_sec_context_destroy(uint16_t conn_handle)
{
uint32_t err_code = NRF_ERROR_NOT_FOUND;
uint32_t i;
for (i=0; i<SER_MAX_CONNECTIONS; i++ )
{
if ( m_conn_keys_table[i].conn_handle == conn_handle )
{
m_conn_keys_table[i].conn_active = 0;
err_code = NRF_SUCCESS;
break;
}
}
return err_code;
}
uint32_t conn_ble_gap_sec_context_find(uint16_t conn_handle, uint32_t *p_index)
{
uint32_t err_code = NRF_ERROR_NOT_FOUND;
uint32_t i;
for (i=0; i<SER_MAX_CONNECTIONS; i++ )
{
if ( (m_conn_keys_table[i].conn_handle == conn_handle) && (m_conn_keys_table[i].conn_active == 1) )
{
*p_index = i;
err_code = NRF_SUCCESS;
break;
}
}
return err_code;
}
#if NRF_SD_BLE_API_VERSION >= 6
uint8_t * conn_ble_gap_ble_data_buf_alloc(uint32_t id)
{
uint32_t i;
if (id == 0)
{
return NULL;
}
/* First find if given id already allocated the buffer. */
for (i = 0; i < ARRAY_SIZE(m_ble_data_pool); i++)
{
if (m_ble_data_pool[i].id == id)
{
return m_ble_data_pool[i].ble_data;
}
}
for (i = 0; i < ARRAY_SIZE(m_ble_data_pool); i++)
{
if (m_ble_data_pool[i].id == 0)
{
m_ble_data_pool[i].id = id;
return m_ble_data_pool[i].ble_data;
}
}
return NULL;
}
uint32_t conn_ble_gap_ble_data_buf_free(uint8_t * p_data)
{
uint32_t i;
if (p_data == NULL)
{
return 0;
}
/* First find if given id already allocated the buffer. */
for (i = 0; i < ARRAY_SIZE(m_ble_data_pool); i++)
{
if (m_ble_data_pool[i].ble_data == p_data)
{
uint32_t id = m_ble_data_pool[i].id;
m_ble_data_pool[i].id = 0;
return id;
}
}
return 0;
}
void conn_ble_gap_scan_data_set(uint8_t * p_scan_data)
{
mp_scan_data = p_scan_data;
}
void conn_ble_gap_scan_data_unset(bool free)
{
if (mp_scan_data)
{
if (free)
{
(void)conn_ble_gap_ble_data_buf_free(mp_scan_data);
}
mp_scan_data = NULL;
}
}
#endif

View File

@@ -0,0 +1,131 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef _CONN_BLE_GAP_SEC_KEYS_H
#define _CONN_BLE_GAP_SEC_KEYS_H
/**@file
*
* @defgroup conn_ble_gap_sec_keys GAP Functions for managing memory for security keys on connectivity device
* @{
* @ingroup ser_conn_s130_codecs
*
* @brief GAP Connectivity auxiliary functions for providing static memory required by the SoftDevice. This memory is used to store GAP security keys.
*/
#include "ble_gap.h"
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/**@brief GAP connection - keyset mapping structure.
*
* @note This structure is used to map keysets to connection instances, and will be stored in a static table.
*/
typedef struct
{
uint16_t conn_handle; /**< Connection handle. */
uint8_t conn_active; /**< Indication that keys for this connection are used by the SoftDevice. 0: keys used; 1: keys not used. */
ble_gap_sec_keyset_t keyset; /**< Keyset structure, see @ref ble_gap_sec_keyset_t. */
ble_gap_enc_key_t enc_key_own; /**< Own Encryption Key, see @ref ble_gap_enc_key_t. */
ble_gap_id_key_t id_key_own; /**< Own Identity Key, see @ref ble_gap_id_key_t. */
ble_gap_sign_info_t sign_key_own; /**< Own Signing Information, see @ref ble_gap_sign_info_t. */
ble_gap_lesc_p256_pk_t pk_own; /**< Own Public key, see @ref ble_gap_lesc_p256_pk_t. */
ble_gap_enc_key_t enc_key_peer; /**< Peer Encryption Key, see @ref ble_gap_enc_key_t. */
ble_gap_id_key_t id_key_peer; /**< Peer Identity Key, see @ref ble_gap_id_key_t. */
ble_gap_sign_info_t sign_key_peer; /**< Peer Signing Information, see @ref ble_gap_sign_info_t. */
ble_gap_lesc_p256_pk_t pk_peer; /**< Peer Public key, see @ref ble_gap_lesc_p256_pk_t. */
} ser_ble_gap_conn_keyset_t;
/**@brief Initializes buffer pool. */
void conn_ble_gap_sec_keys_init(void);
/**@brief Allocates instance in m_conn_keys_table[] for storage of encryption keys.
*
* @param[out] p_index Pointer to the index of allocated instance.
*
* @retval NRF_SUCCESS Success.
* @retval NRF_ERROR_NO_MEM No free instance available.
*/
uint32_t conn_ble_gap_sec_context_create(uint32_t *p_index);
/**@brief Releases the instance identified by a connection handle.
*
* @param[in] conn_handle conn_handle
*
* @retval NRF_SUCCESS Context released.
* @retval NRF_ERROR_NOT_FOUND Instance with conn_handle not found.
*/
uint32_t conn_ble_gap_sec_context_destroy(uint16_t conn_handle);
/**@brief Finds index of the instance identified by a connection handle in m_conn_keys_table[].
*
* @param[in] conn_handle conn_handle
*
* @param[out] p_index Pointer to the index of entry in the context table corresponding to the given conn_handle.
*
* @retval NRF_SUCCESS Context table entry found.
* @retval NRF_ERROR_NOT_FOUND Instance with the conn_handle not found.
*/
uint32_t conn_ble_gap_sec_context_find(uint16_t conn_handle, uint32_t *p_index);
/** @} */
/** @brief Function allocates data from the pool.
*
* @param id ID used for buffer identification. If buffer with given ID is already allocated the pointer to that buffer is returned.
* @return Allocated buffer of NULL.
*/
uint8_t * conn_ble_gap_ble_data_buf_alloc(uint32_t id);
/** @brief Function for freeing the buffer.
* @param p_data Buffer to be freed.
*/
uint32_t conn_ble_gap_ble_data_buf_free(uint8_t * p_data);
void conn_ble_gap_scan_data_set(uint8_t * p_scan_data);
void conn_ble_gap_scan_data_unset(bool free);
#ifdef __cplusplus
}
#endif
#endif //_CONN_BLE_GAP_SEC_KEYS_H

View File

@@ -0,0 +1,84 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "conn_ble_l2cap_sdu_pool.h"
#include "app_util.h"
#include "nrf_balloc.h"
#define MAX_NUM_OF_BUFFERS 8
#define ID_SIZE 4
#define TOTAL_BUF_SIZE (CONN_BLE_L2CAP_SDU_MAX_BUFFER_SIZE+ID_SIZE)
NRF_BALLOC_DEF(m_pool, TOTAL_BUF_SIZE, MAX_NUM_OF_BUFFERS);
void conn_ble_l2cap_sdu_pool_init(void)
{
(void)nrf_balloc_init(&m_pool);
}
uint8_t * conn_ble_l2cap_sdu_pool_alloc(uint16_t length, uint32_t id)
{
if (length > CONN_BLE_L2CAP_SDU_MAX_BUFFER_SIZE)
{
return NULL;
}
uint32_t * p_buf = nrf_balloc_alloc(&m_pool);
*p_buf = id;
p_buf++;
return (uint8_t *)p_buf;
}
uint32_t conn_ble_l2cap_sdu_pool_id_get(void * p_data)
{
uint32_t * p_buf = (uint32_t *)p_data;
p_buf--;
return *p_buf;
}
void conn_ble_l2cap_sdu_pool_free(void * p_data)
{
uint32_t * p_buf = (uint32_t *)p_data;
p_buf--;
nrf_balloc_free(&m_pool, p_buf);
}

View File

@@ -0,0 +1,53 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef CONN_BLE_L2CAP_SDU_POOL_H
#define CONN_BLE_L2CAP_SDU_POOL_H
#include <stdint.h>
#define CONN_BLE_L2CAP_SDU_MAX_BUFFER_SIZE 124
void conn_ble_l2cap_sdu_pool_init(void);
uint8_t * conn_ble_l2cap_sdu_pool_alloc(uint16_t length, uint32_t id);
uint32_t conn_ble_l2cap_sdu_pool_id_get(void * p_data);
void conn_ble_l2cap_sdu_pool_free(void * p_data);
#endif //CONN_BLE_L2CAP_SDU_POOL_H

View File

@@ -0,0 +1,115 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "conn_ble_user_mem.h"
#include "ser_config.h"
#include "nrf_error.h"
#include <stddef.h>
sercon_ble_user_mem_t m_conn_user_mem_table[SER_MAX_CONNECTIONS];
void conn_ble_user_mem_init(void)
{
uint32_t i;
for (i=0; i<SER_MAX_CONNECTIONS; i++ )
{
m_conn_user_mem_table[i].conn_active = 0;
}
}
uint32_t conn_ble_user_mem_context_create(uint32_t *p_index)
{
uint32_t err_code = NRF_ERROR_NO_MEM;
uint32_t i;
for (i=0; i<SER_MAX_CONNECTIONS; i++ )
{
if ( ! m_conn_user_mem_table[i].conn_active )
{
m_conn_user_mem_table[i].conn_active = 1;
m_conn_user_mem_table[i].mem_block.p_mem = m_conn_user_mem_table[i].mem_table;
*p_index = i;
err_code = NRF_SUCCESS;
break;
}
}
return err_code;
}
uint32_t conn_ble_user_mem_context_destroy(uint16_t conn_handle)
{
uint32_t err_code = NRF_ERROR_NOT_FOUND;
uint32_t i;
for (i=0; i<SER_MAX_CONNECTIONS; i++ )
{
if ( m_conn_user_mem_table[i].conn_handle == conn_handle )
{
m_conn_user_mem_table[i].conn_active = 0;
m_conn_user_mem_table[i].mem_block.p_mem = NULL;
err_code = NRF_SUCCESS;
break;
}
}
return err_code;
}
uint32_t conn_ble_user_mem_context_find(uint16_t conn_handle, uint32_t *p_index)
{
uint32_t err_code = NRF_ERROR_NOT_FOUND;
uint32_t i;
for (i=0; i<SER_MAX_CONNECTIONS; i++ )
{
if ( (m_conn_user_mem_table[i].conn_handle == conn_handle) && (m_conn_user_mem_table[i].conn_active == 1) )
{
*p_index = i;
err_code = NRF_SUCCESS;
break;
}
}
return err_code;
}

View File

@@ -0,0 +1,111 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef _CONN_BLE_USER_MEM_H
#define _CONN_BLE_USER_MEM_H
/**@file
*
* @defgroup conn_ble_user_mem Functions for managing memory for user memory request on connectivity device.
* @{
* @ingroup ser_conn_s130_codecs
*
* @brief Connectivity auxiliary functions for providing static memory required by the SoftDevice.
*/
#include "ble.h"
#include "ser_config.h"
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Connection - user memory mapping structure.
*
* @note This structure is used to map keysets to connection instances, and will be stored in a static table.
*/
//lint -esym(452,ser_ble_user_mem_t)
typedef struct
{
uint16_t conn_handle; /**< Connection handle.*/
uint8_t conn_active; /**< Indication that user memory for this connection is used by the SoftDevice. 0: memory used; 1: memory not used. */
ble_user_mem_block_t mem_block; /**< User memory block structure, see @ref ble_user_mem_block_t. */
uint8_t mem_table[64]; /**< Memory table. */
} sercon_ble_user_mem_t;
/**@brief Initializes buffer pool. */
void conn_ble_user_mem_init(void);
/**@brief Allocates instance in m_user_mem_table[] for storage.
*
* @param[out] p_index Pointer to the index of allocated instance.
*
* @retval NRF_SUCCESS Success.
* @retval NRF_ERROR_NO_MEM No free instance available.
*/
uint32_t conn_ble_user_mem_context_create(uint32_t *p_index);
/**@brief Releases the instance identified by a connection handle.
*
* @param[in] conn_handle conn_handle
*
* @retval NRF_SUCCESS Context released.
* @retval NRF_ERROR_NOT_FOUND Instance with the conn_handle not found.
*/
uint32_t conn_ble_user_mem_context_destroy(uint16_t conn_handle);
/**@brief Finds index of the instance identified by a connection handle in m_user_mem_table[].
*
* @param[in] conn_handle conn_handle
*
* @param[out] p_index Pointer to the index of entry in the context table corresponding to the given conn_handle.
*
* @retval NRF_SUCCESS Context table entry found.
* @retval NRF_ERROR_NOT_FOUND Instance with the conn_handle not found.
*/
uint32_t conn_ble_user_mem_context_find(uint16_t conn_handle, uint32_t *p_index);
/** @} */
#ifdef __cplusplus
}
#endif
#endif //_CONN_BLE_USER_MEM_H

View File

@@ -0,0 +1,89 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "nrf_soc.h"
#include "nrf_soc_conn.h"
#include "nrf_error.h"
#include "ble_serialization.h"
#include "cond_field_serialization.h"
#include "nrf_soc_struct_serialization.h"
uint32_t ecb_block_encrypt_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
nrf_ecb_hal_data_t * * const pp_ecb_data)
{
SER_REQ_DEC_BEGIN(SD_ECB_BLOCK_ENCRYPT);
SER_PULL_COND(pp_ecb_data, nrf_ecb_hal_data_t_in_dec);
SER_REQ_DEC_END;
}
uint32_t ecb_block_encrypt_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
nrf_ecb_hal_data_t * const p_ecb_data)
{
SER_RSP_ENC_BEGIN(SD_ECB_BLOCK_ENCRYPT);
SER_PUSH_COND(p_ecb_data, nrf_ecb_hal_data_t_out_enc);
SER_RSP_ENC_END;
}
uint32_t power_system_off_req_dec(uint8_t const * const p_buf,
uint16_t packet_len)
{
SER_REQ_DEC_BEGIN(SD_POWER_SYSTEM_OFF);
SER_REQ_DEC_END;
}
uint32_t temp_get_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
int32_t * * const pp_temp)
{
SER_REQ_DEC_BEGIN(SD_TEMP_GET);
SER_PULL_COND(pp_temp, NULL);
SER_REQ_DEC_END;
}
uint32_t temp_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
int32_t * const p_temp)
{
SER_RSP_ENC_BEGIN(SD_TEMP_GET);
SER_PUSH_COND(p_temp, uint32_t_enc);
SER_RSP_ENC_END;
}

View File

@@ -0,0 +1,148 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef NRF_SOC_CONN_H__
#define NRF_SOC_CONN_H__
/**@file
*
* @defgroup soc_conn SOC Connectivity command request decoders and command response encoders
* @{
* @ingroup ser_conn_s130_codecs
*
* @brief SOC Connectivity command request decoders and command response encoders.
*/
#include "nrf_soc.h"
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Decodes @ref sd_power_system_off command request.
*
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in] packet_len Length (in bytes) of request packet.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_PARAM Encoding failure. Incorrect parameter.
*/
uint32_t power_system_off_req_dec(uint8_t const * const p_buf, uint16_t packet_len);
/**@brief Decodes @ref sd_temp_get command request.
*
* @sa @ref temp_get_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in] packet_len Length (in bytes) of request packet.
* @param[out] pp_temp Pointer to pointer to result of temperature measurement.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_PARAM Encoding failure. Incorrect parameter.
*/
uint32_t temp_get_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
int32_t * * const pp_temp);
/**@brief Encodes @ref sd_temp_get command response.
*
* @sa @ref temp_get_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_temp Pointer to result of temperature measurement.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t temp_get_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
int32_t * const p_temp);
/**@brief Decodes @ref sd_ecb_block_encrypt command request.
*
* @sa @ref ecb_block_encrypt_rsp_enc for response encoding.
*
* @param[in] p_buf Pointer to buffer where encoded data command will be returned.
* @param[in] packet_len Length (in bytes) of request packet.
* @param[out] pp_ecb_data Pointer to pointer to ECB data.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied
* @retval NRF_ERROR_INVALID_PARAM Encoding failure. Incorrect parameter.
*/
uint32_t ecb_block_encrypt_req_dec(uint8_t const * const p_buf,
uint32_t packet_len,
nrf_ecb_hal_data_t * * const pp_ecb_data);
/**@brief Encodes @ref sd_ecb_block_encrypt command response.
*
* @sa @ref ecb_block_encrypt_req_dec for request decoding.
*
* @param[in] return_code Return code indicating if command was successful or not.
* @param[out] p_buf Pointer to buffer where encoded data command response will be
* returned.
* @param[in,out] p_buf_len \c in: size of \p p_buf buffer.
* \c out: Length of encoded command response packet.
* @param[in] p_ecb_data Pointer to ECB data.
*
* @retval NRF_SUCCESS Encoding success.
* @retval NRF_ERROR_NULL Encoding failure. NULL pointer supplied.
* @retval NRF_ERROR_INVALID_LENGTH Encoding failure. Incorrect buffer length.
*/
uint32_t ecb_block_encrypt_rsp_enc(uint32_t return_code,
uint8_t * const p_buf,
uint32_t * const p_buf_len,
nrf_ecb_hal_data_t * const p_ecb_data);
/** @} */
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,113 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef BLE_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__

View File

@@ -0,0 +1,83 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "ble_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;
}

View File

@@ -0,0 +1,107 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <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;
}

View File

@@ -0,0 +1,88 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef _CONN_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

View File

@@ -0,0 +1,224 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "conn_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)
};

View File

@@ -0,0 +1,114 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "nrf_soc_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;
}

View File

@@ -0,0 +1,118 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef CONN_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

View File

@@ -0,0 +1,242 @@
/**
* Copyright (c) 2012 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/**
@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;
#if defined(NRF_DRV_UART_WITH_UARTE) && defined(NRF_DRV_UART_WITH_UART)
//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 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(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);
}
}
}
/// @}

View File

@@ -0,0 +1,59 @@
/**
* Copyright (c) 2013 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef 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__

View File

@@ -0,0 +1,138 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#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;
}

View File

@@ -0,0 +1,89 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/**
* @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__ */
/** @} */

View File

@@ -0,0 +1,126 @@
/**
* Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#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);
}
}

Some files were not shown because too many files have changed in this diff Show More