初始版本

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

View File

@@ -0,0 +1,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