cvb

Fork of nrf51-sdk by Lancaster University

Committer:
Jonathan Austin
Date:
Wed Apr 06 23:55:04 2016 +0100
Revision:
0:bc2961fa1ef0
Synchronized with git rev 90647e3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jonathan Austin 0:bc2961fa1ef0 1 /*
Jonathan Austin 0:bc2961fa1ef0 2 * Copyright (c) Nordic Semiconductor ASA
Jonathan Austin 0:bc2961fa1ef0 3 * All rights reserved.
Jonathan Austin 0:bc2961fa1ef0 4 *
Jonathan Austin 0:bc2961fa1ef0 5 * Redistribution and use in source and binary forms, with or without modification,
Jonathan Austin 0:bc2961fa1ef0 6 * are permitted provided that the following conditions are met:
Jonathan Austin 0:bc2961fa1ef0 7 *
Jonathan Austin 0:bc2961fa1ef0 8 * 1. Redistributions of source code must retain the above copyright notice, this
Jonathan Austin 0:bc2961fa1ef0 9 * list of conditions and the following disclaimer.
Jonathan Austin 0:bc2961fa1ef0 10 *
Jonathan Austin 0:bc2961fa1ef0 11 * 2. Redistributions in binary form must reproduce the above copyright notice, this
Jonathan Austin 0:bc2961fa1ef0 12 * list of conditions and the following disclaimer in the documentation and/or
Jonathan Austin 0:bc2961fa1ef0 13 * other materials provided with the distribution.
Jonathan Austin 0:bc2961fa1ef0 14 *
Jonathan Austin 0:bc2961fa1ef0 15 * 3. Neither the name of Nordic Semiconductor ASA nor the names of other
Jonathan Austin 0:bc2961fa1ef0 16 * contributors to this software may be used to endorse or promote products
Jonathan Austin 0:bc2961fa1ef0 17 * derived from this software without specific prior written permission.
Jonathan Austin 0:bc2961fa1ef0 18 *
Jonathan Austin 0:bc2961fa1ef0 19 *
Jonathan Austin 0:bc2961fa1ef0 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
Jonathan Austin 0:bc2961fa1ef0 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Jonathan Austin 0:bc2961fa1ef0 22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Jonathan Austin 0:bc2961fa1ef0 23 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
Jonathan Austin 0:bc2961fa1ef0 24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Jonathan Austin 0:bc2961fa1ef0 25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Jonathan Austin 0:bc2961fa1ef0 26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
Jonathan Austin 0:bc2961fa1ef0 27 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Jonathan Austin 0:bc2961fa1ef0 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Jonathan Austin 0:bc2961fa1ef0 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Jonathan Austin 0:bc2961fa1ef0 30 *
Jonathan Austin 0:bc2961fa1ef0 31 */
Jonathan Austin 0:bc2961fa1ef0 32
Jonathan Austin 0:bc2961fa1ef0 33 /** @file
Jonathan Austin 0:bc2961fa1ef0 34 *
Jonathan Austin 0:bc2961fa1ef0 35 * @defgroup ble_sdk_lib_conn_params Connection Parameters Negotiation
Jonathan Austin 0:bc2961fa1ef0 36 * @{
Jonathan Austin 0:bc2961fa1ef0 37 * @ingroup ble_sdk_lib
Jonathan Austin 0:bc2961fa1ef0 38 * @brief Module for initiating and executing a connection parameters negotiation procedure.
Jonathan Austin 0:bc2961fa1ef0 39 */
Jonathan Austin 0:bc2961fa1ef0 40
Jonathan Austin 0:bc2961fa1ef0 41 #ifndef BLE_CONN_PARAMS_H__
Jonathan Austin 0:bc2961fa1ef0 42 #define BLE_CONN_PARAMS_H__
Jonathan Austin 0:bc2961fa1ef0 43
Jonathan Austin 0:bc2961fa1ef0 44 #include <stdint.h>
Jonathan Austin 0:bc2961fa1ef0 45 #include "ble.h"
Jonathan Austin 0:bc2961fa1ef0 46 #include "ble_srv_common.h"
Jonathan Austin 0:bc2961fa1ef0 47
Jonathan Austin 0:bc2961fa1ef0 48 /**@brief Connection Parameters Module event type. */
Jonathan Austin 0:bc2961fa1ef0 49 typedef enum
Jonathan Austin 0:bc2961fa1ef0 50 {
Jonathan Austin 0:bc2961fa1ef0 51 BLE_CONN_PARAMS_EVT_FAILED , /**< Negotiation procedure failed. */
Jonathan Austin 0:bc2961fa1ef0 52 BLE_CONN_PARAMS_EVT_SUCCEEDED /**< Negotiation procedure succeeded. */
Jonathan Austin 0:bc2961fa1ef0 53 } ble_conn_params_evt_type_t;
Jonathan Austin 0:bc2961fa1ef0 54
Jonathan Austin 0:bc2961fa1ef0 55 /**@brief Connection Parameters Module event. */
Jonathan Austin 0:bc2961fa1ef0 56 typedef struct
Jonathan Austin 0:bc2961fa1ef0 57 {
Jonathan Austin 0:bc2961fa1ef0 58 ble_conn_params_evt_type_t evt_type; /**< Type of event. */
Jonathan Austin 0:bc2961fa1ef0 59 } ble_conn_params_evt_t;
Jonathan Austin 0:bc2961fa1ef0 60
Jonathan Austin 0:bc2961fa1ef0 61 /**@brief Connection Parameters Module event handler type. */
Jonathan Austin 0:bc2961fa1ef0 62 typedef void (*ble_conn_params_evt_handler_t) (ble_conn_params_evt_t * p_evt);
Jonathan Austin 0:bc2961fa1ef0 63
Jonathan Austin 0:bc2961fa1ef0 64 /**@brief Connection Parameters Module init structure. This contains all options and data needed for
Jonathan Austin 0:bc2961fa1ef0 65 * initialization of the connection parameters negotiation module. */
Jonathan Austin 0:bc2961fa1ef0 66 typedef struct
Jonathan Austin 0:bc2961fa1ef0 67 {
Jonathan Austin 0:bc2961fa1ef0 68 ble_gap_conn_params_t * p_conn_params; /**< Pointer to the connection parameters desired by the application. When calling ble_conn_params_init, if this parameter is set to NULL, the connection parameters will be fetched from host. */
Jonathan Austin 0:bc2961fa1ef0 69 uint32_t first_conn_params_update_delay; /**< Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (in number of timer ticks). */
Jonathan Austin 0:bc2961fa1ef0 70 uint32_t next_conn_params_update_delay; /**< Time between each call to sd_ble_gap_conn_param_update after the first (in number of timer ticks). Recommended value 30 seconds as per BLUETOOTH SPECIFICATION Version 4.0. */
Jonathan Austin 0:bc2961fa1ef0 71 uint8_t max_conn_params_update_count; /**< Number of attempts before giving up the negotiation. */
Jonathan Austin 0:bc2961fa1ef0 72 uint16_t start_on_notify_cccd_handle; /**< If procedure is to be started when notification is started, set this to the handle of the corresponding CCCD. Set to BLE_GATT_HANDLE_INVALID if procedure is to be started on connect event. */
Jonathan Austin 0:bc2961fa1ef0 73 bool disconnect_on_fail; /**< Set to TRUE if a failed connection parameters update shall cause an automatic disconnection, set to FALSE otherwise. */
Jonathan Austin 0:bc2961fa1ef0 74 ble_conn_params_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Connection Parameters. */
Jonathan Austin 0:bc2961fa1ef0 75 ble_srv_error_handler_t error_handler; /**< Function to be called in case of an error. */
Jonathan Austin 0:bc2961fa1ef0 76 } ble_conn_params_init_t;
Jonathan Austin 0:bc2961fa1ef0 77
Jonathan Austin 0:bc2961fa1ef0 78
Jonathan Austin 0:bc2961fa1ef0 79 /**@brief Function for initializing the Connection Parameters module.
Jonathan Austin 0:bc2961fa1ef0 80 *
Jonathan Austin 0:bc2961fa1ef0 81 * @note If the negotiation procedure should be triggered when notification/indication of
Jonathan Austin 0:bc2961fa1ef0 82 * any characteristic is enabled by the peer, then this function must be called after
Jonathan Austin 0:bc2961fa1ef0 83 * having initialized the services.
Jonathan Austin 0:bc2961fa1ef0 84 *
Jonathan Austin 0:bc2961fa1ef0 85 * @param[in] p_init This contains information needed to initialize this module.
Jonathan Austin 0:bc2961fa1ef0 86 *
Jonathan Austin 0:bc2961fa1ef0 87 * @return NRF_SUCCESS on successful initialization, otherwise an error code.
Jonathan Austin 0:bc2961fa1ef0 88 */
Jonathan Austin 0:bc2961fa1ef0 89 uint32_t ble_conn_params_init(const ble_conn_params_init_t * p_init);
Jonathan Austin 0:bc2961fa1ef0 90
Jonathan Austin 0:bc2961fa1ef0 91 /**@brief Function for stopping the Connection Parameters module.
Jonathan Austin 0:bc2961fa1ef0 92 *
Jonathan Austin 0:bc2961fa1ef0 93 * @details This function is intended to be used by the application to clean up the connection
Jonathan Austin 0:bc2961fa1ef0 94 * parameters update module. This will stop the connection parameters update timer if
Jonathan Austin 0:bc2961fa1ef0 95 * running, thereby preventing any impending connection parameters update procedure. This
Jonathan Austin 0:bc2961fa1ef0 96 * function must be called by the application when it needs to clean itself up (for
Jonathan Austin 0:bc2961fa1ef0 97 * example, before disabling the bluetooth SoftDevice) so that an unwanted timer expiry
Jonathan Austin 0:bc2961fa1ef0 98 * event can be avoided.
Jonathan Austin 0:bc2961fa1ef0 99 *
Jonathan Austin 0:bc2961fa1ef0 100 * @return NRF_SUCCESS on successful initialization, otherwise an error code.
Jonathan Austin 0:bc2961fa1ef0 101 */
Jonathan Austin 0:bc2961fa1ef0 102 uint32_t ble_conn_params_stop(void);
Jonathan Austin 0:bc2961fa1ef0 103
Jonathan Austin 0:bc2961fa1ef0 104 /**@brief Function for changing the current connection parameters to a new set.
Jonathan Austin 0:bc2961fa1ef0 105 *
Jonathan Austin 0:bc2961fa1ef0 106 * @details Use this function to change the connection parameters to a new set of parameter
Jonathan Austin 0:bc2961fa1ef0 107 * (ie different from the ones given at init of the module).
Jonathan Austin 0:bc2961fa1ef0 108 * This function is usefull for scenario where most of the time the application
Jonathan Austin 0:bc2961fa1ef0 109 * needs a relatively big connection interval, and just sometimes, for a temporary
Jonathan Austin 0:bc2961fa1ef0 110 * period requires shorter connection interval, for example to transfer a higher
Jonathan Austin 0:bc2961fa1ef0 111 * amount of data.
Jonathan Austin 0:bc2961fa1ef0 112 * If the given parameters does not match the current connection's parameters
Jonathan Austin 0:bc2961fa1ef0 113 * this function initiates a new negotiation.
Jonathan Austin 0:bc2961fa1ef0 114 *
Jonathan Austin 0:bc2961fa1ef0 115 * @param[in] new_params This contains the new connections parameters to setup.
Jonathan Austin 0:bc2961fa1ef0 116 *
Jonathan Austin 0:bc2961fa1ef0 117 * @return NRF_SUCCESS on successful initialization, otherwise an error code.
Jonathan Austin 0:bc2961fa1ef0 118 */
Jonathan Austin 0:bc2961fa1ef0 119 uint32_t ble_conn_params_change_conn_params(ble_gap_conn_params_t *new_params);
Jonathan Austin 0:bc2961fa1ef0 120
Jonathan Austin 0:bc2961fa1ef0 121 /**@brief Function for handling the Application's BLE Stack events.
Jonathan Austin 0:bc2961fa1ef0 122 *
Jonathan Austin 0:bc2961fa1ef0 123 * @details Handles all events from the BLE stack that are of interest to this module.
Jonathan Austin 0:bc2961fa1ef0 124 *
Jonathan Austin 0:bc2961fa1ef0 125 * @param[in] p_ble_evt The event received from the BLE stack.
Jonathan Austin 0:bc2961fa1ef0 126 */
Jonathan Austin 0:bc2961fa1ef0 127 void ble_conn_params_on_ble_evt(ble_evt_t * p_ble_evt);
Jonathan Austin 0:bc2961fa1ef0 128
Jonathan Austin 0:bc2961fa1ef0 129 #endif // BLE_CONN_PARAMS_H__
Jonathan Austin 0:bc2961fa1ef0 130
Jonathan Austin 0:bc2961fa1ef0 131 /** @} */