Kevin Kadooka / mbed-dev

Fork of mbed-dev by mbed official

Committer:
<>
Date:
Fri Oct 28 11:17:30 2016 +0100
Revision:
149:156823d33999
Parent:
targets/hal/TARGET_NORDIC/TARGET_NRF5/sdk/ble/peer_manager/gatt_cache_manager.h@144:ef7eb2e8f9f7
This updates the lib to the mbed lib v128

NOTE: This release includes a restructuring of the file and directory locations and thus some
include paths in your code may need updating accordingly.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 144:ef7eb2e8f9f7 1 /*
<> 144:ef7eb2e8f9f7 2 * Copyright (c) 2015 Nordic Semiconductor ASA
<> 144:ef7eb2e8f9f7 3 * All rights reserved.
<> 144:ef7eb2e8f9f7 4 *
<> 144:ef7eb2e8f9f7 5 * Redistribution and use in source and binary forms, with or without modification,
<> 144:ef7eb2e8f9f7 6 * are permitted provided that the following conditions are met:
<> 144:ef7eb2e8f9f7 7 *
<> 144:ef7eb2e8f9f7 8 * 1. Redistributions of source code must retain the above copyright notice, this list
<> 144:ef7eb2e8f9f7 9 * of conditions and the following disclaimer.
<> 144:ef7eb2e8f9f7 10 *
<> 144:ef7eb2e8f9f7 11 * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA
<> 144:ef7eb2e8f9f7 12 * integrated circuit in a product or a software update for such product, must reproduce
<> 144:ef7eb2e8f9f7 13 * the above copyright notice, this list of conditions and the following disclaimer in
<> 144:ef7eb2e8f9f7 14 * the documentation and/or other materials provided with the distribution.
<> 144:ef7eb2e8f9f7 15 *
<> 144:ef7eb2e8f9f7 16 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be
<> 144:ef7eb2e8f9f7 17 * used to endorse or promote products derived from this software without specific prior
<> 144:ef7eb2e8f9f7 18 * written permission.
<> 144:ef7eb2e8f9f7 19 *
<> 144:ef7eb2e8f9f7 20 * 4. This software, with or without modification, must only be used with a
<> 144:ef7eb2e8f9f7 21 * Nordic Semiconductor ASA integrated circuit.
<> 144:ef7eb2e8f9f7 22 *
<> 144:ef7eb2e8f9f7 23 * 5. Any software provided in binary or object form under this license must not be reverse
<> 144:ef7eb2e8f9f7 24 * engineered, decompiled, modified and/or disassembled.
<> 144:ef7eb2e8f9f7 25 *
<> 144:ef7eb2e8f9f7 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
<> 144:ef7eb2e8f9f7 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
<> 144:ef7eb2e8f9f7 28 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
<> 144:ef7eb2e8f9f7 29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
<> 144:ef7eb2e8f9f7 30 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
<> 144:ef7eb2e8f9f7 31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
<> 144:ef7eb2e8f9f7 32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
<> 144:ef7eb2e8f9f7 33 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
<> 144:ef7eb2e8f9f7 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
<> 144:ef7eb2e8f9f7 35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<> 144:ef7eb2e8f9f7 36 *
<> 144:ef7eb2e8f9f7 37 */
<> 144:ef7eb2e8f9f7 38
<> 144:ef7eb2e8f9f7 39
<> 144:ef7eb2e8f9f7 40
<> 144:ef7eb2e8f9f7 41 #ifndef GATT_CACHE_MANAGER_H__
<> 144:ef7eb2e8f9f7 42 #define GATT_CACHE_MANAGER_H__
<> 144:ef7eb2e8f9f7 43
<> 144:ef7eb2e8f9f7 44 #include <stdint.h>
<> 144:ef7eb2e8f9f7 45 #include "sdk_errors.h"
<> 144:ef7eb2e8f9f7 46 #include "nrf_ble.h"
<> 144:ef7eb2e8f9f7 47 #include "nrf_ble_gap.h"
<> 144:ef7eb2e8f9f7 48 #include "peer_manager_types.h"
<> 144:ef7eb2e8f9f7 49
<> 144:ef7eb2e8f9f7 50
<> 144:ef7eb2e8f9f7 51
<> 144:ef7eb2e8f9f7 52 /**
<> 144:ef7eb2e8f9f7 53 * @cond NO_DOXYGEN
<> 144:ef7eb2e8f9f7 54 * @defgroup gatt_cache_manager GATT Cache Manager
<> 144:ef7eb2e8f9f7 55 * @ingroup peer_manager
<> 144:ef7eb2e8f9f7 56 * @{
<> 144:ef7eb2e8f9f7 57 * @brief An internal module of @ref peer_manager. A module for managing persistent storing of GATT
<> 144:ef7eb2e8f9f7 58 * attributes.
<> 144:ef7eb2e8f9f7 59 */
<> 144:ef7eb2e8f9f7 60
<> 144:ef7eb2e8f9f7 61
<> 144:ef7eb2e8f9f7 62 /**@brief Events that can come from the GATT Cache Manager module.
<> 144:ef7eb2e8f9f7 63 */
<> 144:ef7eb2e8f9f7 64 typedef enum
<> 144:ef7eb2e8f9f7 65 {
<> 144:ef7eb2e8f9f7 66 GCM_EVT_LOCAL_DB_CACHE_STORED, /**< The persistent cache for the local database has been updated with provided values, for one peer. */
<> 144:ef7eb2e8f9f7 67 GCM_EVT_LOCAL_DB_CACHE_UPDATED, /**< The persistent cache for the local database has been updated with values from the SoftDevice, for one peer. */
<> 144:ef7eb2e8f9f7 68 GCM_EVT_LOCAL_DB_CACHE_APPLIED, /**< The SoftDevice has been given local database values from the persistent cache, for one peer. */
<> 144:ef7eb2e8f9f7 69 GCM_EVT_ERROR_LOCAL_DB_CACHE_APPLY, /**< The stored local database values for a peer were rejected by the SoftDevice, which means the database has changed. */
<> 144:ef7eb2e8f9f7 70 GCM_EVT_REMOTE_DB_CACHE_UPDATED, /**< The persistent cache for the remote database has been updated with provided values, for one peer. */
<> 144:ef7eb2e8f9f7 71 GCM_EVT_SERVICE_CHANGED_IND_SENT, /**< A service changed indication has been sent to a peer. */
<> 144:ef7eb2e8f9f7 72 GCM_EVT_SERVICE_CHANGED_IND_CONFIRMED, /**< A sent service changed indication has been confirmed by a peer. */
<> 144:ef7eb2e8f9f7 73 GCM_EVT_ERROR_DATA_SIZE, /**< An operation failed because the write buffer of the Peer Database module was not large enough. This is a fatal error. */
<> 144:ef7eb2e8f9f7 74 GCM_EVT_ERROR_STORAGE_FULL, /**< An operation failed because there was no available storage room in persistent storage. Please free up room, and the operation will automatically continue. */
<> 144:ef7eb2e8f9f7 75 GCM_EVT_ERROR_UNEXPECTED, /**< An operation failed with an unexpected error. The error is provided. This is possibly a fatal error. */
<> 144:ef7eb2e8f9f7 76 } gcm_evt_id_t;
<> 144:ef7eb2e8f9f7 77
<> 144:ef7eb2e8f9f7 78
<> 144:ef7eb2e8f9f7 79 /**@brief A structure meant to be used for event parameters for multiple event types.
<> 144:ef7eb2e8f9f7 80 */
<> 144:ef7eb2e8f9f7 81 typedef struct
<> 144:ef7eb2e8f9f7 82 {
<> 144:ef7eb2e8f9f7 83 uint16_t conn_handle; /**< The connection handle. Likely the connection handle an event pertains to. */
<> 144:ef7eb2e8f9f7 84 } gcm_evt_param_conn_handle_t;
<> 144:ef7eb2e8f9f7 85
<> 144:ef7eb2e8f9f7 86
<> 144:ef7eb2e8f9f7 87 /**@brief Structure containing an event from the GCM module.
<> 144:ef7eb2e8f9f7 88 */
<> 144:ef7eb2e8f9f7 89 typedef struct
<> 144:ef7eb2e8f9f7 90 {
<> 144:ef7eb2e8f9f7 91 gcm_evt_id_t evt_id; /**< The type of event this is. */
<> 144:ef7eb2e8f9f7 92 pm_peer_id_t peer_id; /**< The peer ID this event pertains to. */
<> 144:ef7eb2e8f9f7 93 union
<> 144:ef7eb2e8f9f7 94 {
<> 144:ef7eb2e8f9f7 95 gcm_evt_param_conn_handle_t local_db_cache_updated;
<> 144:ef7eb2e8f9f7 96 gcm_evt_param_conn_handle_t local_db_cache_applied;
<> 144:ef7eb2e8f9f7 97 gcm_evt_param_conn_handle_t error_local_db_cache_apply;
<> 144:ef7eb2e8f9f7 98 gcm_evt_param_conn_handle_t service_changed_ind_sent;
<> 144:ef7eb2e8f9f7 99 gcm_evt_param_conn_handle_t service_changed_ind_confirmed;
<> 144:ef7eb2e8f9f7 100 gcm_evt_param_conn_handle_t error_data_size;
<> 144:ef7eb2e8f9f7 101 gcm_evt_param_conn_handle_t error_no_mem;
<> 144:ef7eb2e8f9f7 102 struct
<> 144:ef7eb2e8f9f7 103 {
<> 144:ef7eb2e8f9f7 104 uint16_t conn_handle; /**< The handle of the connection the event pertains to. */
<> 144:ef7eb2e8f9f7 105 ret_code_t error; /**< The unexpected error that occurred. */
<> 144:ef7eb2e8f9f7 106 } error_unexpected;
<> 144:ef7eb2e8f9f7 107 } params; /**< Event specific parameters. Chosen based on evt_id. */
<> 144:ef7eb2e8f9f7 108 } gcm_evt_t;
<> 144:ef7eb2e8f9f7 109
<> 144:ef7eb2e8f9f7 110 /**@brief Event handler for events from the GATT Cache Manager module.
<> 144:ef7eb2e8f9f7 111 *
<> 144:ef7eb2e8f9f7 112 * @param[in] event The event that has happened.
<> 144:ef7eb2e8f9f7 113 * @param[in] peer The id of the peer the event pertains to.
<> 144:ef7eb2e8f9f7 114 * @param[in] flags The data the event pertains to.
<> 144:ef7eb2e8f9f7 115 */
<> 144:ef7eb2e8f9f7 116 typedef void (*gcm_evt_handler_t)(gcm_evt_t const * p_event);
<> 144:ef7eb2e8f9f7 117
<> 144:ef7eb2e8f9f7 118
<> 144:ef7eb2e8f9f7 119 /**@brief Function for initializing the GATT Cache Manager module.
<> 144:ef7eb2e8f9f7 120 *
<> 144:ef7eb2e8f9f7 121 * @param[in] evt_handler Callback for events from the GATT Cache Manager module.
<> 144:ef7eb2e8f9f7 122 *
<> 144:ef7eb2e8f9f7 123 * @retval NRF_SUCCESS Initialization was successful.
<> 144:ef7eb2e8f9f7 124 * @retval NRF_ERROR_NULL evt_handler was NULL.
<> 144:ef7eb2e8f9f7 125 */
<> 144:ef7eb2e8f9f7 126 ret_code_t gcm_init(gcm_evt_handler_t evt_handler);
<> 144:ef7eb2e8f9f7 127
<> 144:ef7eb2e8f9f7 128
<> 144:ef7eb2e8f9f7 129 /**@brief Function for dispatching SoftDevice events to the GATT Cache Manager module.
<> 144:ef7eb2e8f9f7 130 *
<> 144:ef7eb2e8f9f7 131 * @param[in] p_ble_evt The SoftDevice event.
<> 144:ef7eb2e8f9f7 132 */
<> 144:ef7eb2e8f9f7 133 void gcm_ble_evt_handler(ble_evt_t * p_ble_evt);
<> 144:ef7eb2e8f9f7 134
<> 144:ef7eb2e8f9f7 135
<> 144:ef7eb2e8f9f7 136
<> 144:ef7eb2e8f9f7 137 /**@brief Function for storing a discovered remote database persistently.
<> 144:ef7eb2e8f9f7 138 *
<> 144:ef7eb2e8f9f7 139 * @param[in] peer_id Peer to store the database for.
<> 144:ef7eb2e8f9f7 140 * @param[in] p_remote_db Database values to store as an array. Can be NULL if n_services is 0.
<> 144:ef7eb2e8f9f7 141 * @param[in] n_services Number of services in p_remote_db array. If 0, values are cleared.
<> 144:ef7eb2e8f9f7 142 *
<> 144:ef7eb2e8f9f7 143 * @retval NRF_SUCCESS Store procedure successfully started.
<> 144:ef7eb2e8f9f7 144 * @retval NRF_ERROR_NOT_FOUND The peer id is invalid or unallocated.
<> 144:ef7eb2e8f9f7 145 * @retval NRF_ERROR_INVALID_STATE Module is not initialized.
<> 144:ef7eb2e8f9f7 146 */
<> 144:ef7eb2e8f9f7 147 ret_code_t gcm_remote_db_store(pm_peer_id_t peer_id,
<> 144:ef7eb2e8f9f7 148 ble_gatt_db_srv_t * p_remote_db,
<> 144:ef7eb2e8f9f7 149 uint32_t n_services);
<> 144:ef7eb2e8f9f7 150
<> 144:ef7eb2e8f9f7 151
<> 144:ef7eb2e8f9f7 152 /**@brief Function for retrieving a persistently stored remote database.
<> 144:ef7eb2e8f9f7 153 *
<> 144:ef7eb2e8f9f7 154 * @param[in] peer_id Peer to retrieve data for.
<> 144:ef7eb2e8f9f7 155 * @param[out] p_remote_db If p_n_services was large enough: Copied database values.
<> 144:ef7eb2e8f9f7 156 * @param[inout] p_n_services In: Size of provided p_remote_db array. Out: Size of data in flash.
<> 144:ef7eb2e8f9f7 157 *
<> 144:ef7eb2e8f9f7 158 * @note p_n_services is always updated with the size of the data to be retrieved. The data is only
<> 144:ef7eb2e8f9f7 159 * copied if p_remote_db is large enough (p_n_services is large enough initially).
<> 144:ef7eb2e8f9f7 160 *
<> 144:ef7eb2e8f9f7 161 * @retval NRF_SUCCESS Data retrieved successfully.
<> 144:ef7eb2e8f9f7 162 * @retval NRF_ERROR_NOT_FOUND The peer ID is invalid or unallocated.
<> 144:ef7eb2e8f9f7 163 * @retval NRF_ERROR_NULL p_remote_db is NULL.
<> 144:ef7eb2e8f9f7 164 * @retval NRF_ERROR_INVALID_STATE Module is not initialized.
<> 144:ef7eb2e8f9f7 165 */
<> 144:ef7eb2e8f9f7 166 ret_code_t gcm_remote_db_retrieve(pm_peer_id_t peer_id,
<> 144:ef7eb2e8f9f7 167 ble_gatt_db_srv_t * p_remote_db,
<> 144:ef7eb2e8f9f7 168 uint32_t * p_n_services);
<> 144:ef7eb2e8f9f7 169
<> 144:ef7eb2e8f9f7 170
<> 144:ef7eb2e8f9f7 171 /**@brief Function for triggering local GATT database data to be stored persistently. Values are
<> 144:ef7eb2e8f9f7 172 * retrieved from SoftDevice and written to persistent storage.
<> 144:ef7eb2e8f9f7 173 *
<> 144:ef7eb2e8f9f7 174 * @note This function is only needed when you want to override the regular functionality of the
<> 144:ef7eb2e8f9f7 175 * module, e.g. to immediately store to flash instead of waiting for the native logic to
<> 144:ef7eb2e8f9f7 176 * perform the update.
<> 144:ef7eb2e8f9f7 177 *
<> 144:ef7eb2e8f9f7 178 * @param[in] conn_handle Connection handle to perform update on.
<> 144:ef7eb2e8f9f7 179 *
<> 144:ef7eb2e8f9f7 180 * @retval NRF_SUCCESS Store operation started.
<> 144:ef7eb2e8f9f7 181 * @retval BLE_ERROR_INVALID_CONN_HANDLE conn_handle does not refer to an active, bonded connection.
<> 144:ef7eb2e8f9f7 182 * @retval NRF_ERROR_DATA_SIZE Write buffer not large enough. Call will never work with
<> 144:ef7eb2e8f9f7 183 * this GATT database.
<> 144:ef7eb2e8f9f7 184 * @retval NRF_ERROR_NO_MEM No room in persistent_storage. Free up space; the
<> 144:ef7eb2e8f9f7 185 * operation will be automatically reattempted after the
<> 144:ef7eb2e8f9f7 186 * next compression procedure
<> 144:ef7eb2e8f9f7 187 * @retval NRF_ERROR_INVALID_STATE Module is not initialized.
<> 144:ef7eb2e8f9f7 188 */
<> 144:ef7eb2e8f9f7 189 ret_code_t gcm_local_db_cache_update(uint16_t conn_handle);
<> 144:ef7eb2e8f9f7 190
<> 144:ef7eb2e8f9f7 191
<> 144:ef7eb2e8f9f7 192 /**@brief Function for setting new values in the local database cache.
<> 144:ef7eb2e8f9f7 193 *
<> 144:ef7eb2e8f9f7 194 * @note If the peer is connected, the values will also be applied immediately to the connection.
<> 144:ef7eb2e8f9f7 195 * @note This function is only needed when you want to override the regular functionality of the
<> 144:ef7eb2e8f9f7 196 * module.
<> 144:ef7eb2e8f9f7 197 * @note The data in the pointer must be available until the GCM_EVT_LOCAL_DB_CACHE_SET event is
<> 144:ef7eb2e8f9f7 198 * received.
<> 144:ef7eb2e8f9f7 199 *
<> 144:ef7eb2e8f9f7 200 * @param[in] peer_id Peer to set values for.
<> 144:ef7eb2e8f9f7 201 * @param[in] p_local_db Database values to apply. If NULL, the values will instead be cleared.
<> 144:ef7eb2e8f9f7 202 *
<> 144:ef7eb2e8f9f7 203 * @retval NRF_SUCCESS Operation started, and values were applied (if connected).
<> 144:ef7eb2e8f9f7 204 * @retval NRF_ERROR_NOT_FOUND The peer ID was invalid or unallocated.
<> 144:ef7eb2e8f9f7 205 * @retval NRF_ERROR_INVALID_STATE Module is not initialized.
<> 144:ef7eb2e8f9f7 206 */
<> 144:ef7eb2e8f9f7 207 ret_code_t gcm_local_db_cache_set(pm_peer_id_t peer_id, pm_peer_data_local_gatt_db_t * p_local_db);
<> 144:ef7eb2e8f9f7 208
<> 144:ef7eb2e8f9f7 209
<> 144:ef7eb2e8f9f7 210 /**@brief Function for retrieving values in the local database cache.
<> 144:ef7eb2e8f9f7 211 *
<> 144:ef7eb2e8f9f7 212 * @note This function is not needed for regular operation of the module.
<> 144:ef7eb2e8f9f7 213 *
<> 144:ef7eb2e8f9f7 214 * @param[in] peer_id Peer to get values for.
<> 144:ef7eb2e8f9f7 215 * @param[out] p_local_db Database values.
<> 144:ef7eb2e8f9f7 216 *
<> 144:ef7eb2e8f9f7 217 * @retval NRF_SUCCESS Values retrieved successfully.
<> 144:ef7eb2e8f9f7 218 * @retval NRF_ERROR_NOT_FOUND The peer ID was invalid or unallocated.
<> 144:ef7eb2e8f9f7 219 * @retval NRF_ERROR_NULL p_local_db was NULL.
<> 144:ef7eb2e8f9f7 220 * @retval NRF_ERROR_INVALID_STATE Module is not initialized.
<> 144:ef7eb2e8f9f7 221 */
<> 144:ef7eb2e8f9f7 222 ret_code_t gcm_local_db_cache_get(pm_peer_id_t peer_id, pm_peer_data_local_gatt_db_t * p_local_db);
<> 144:ef7eb2e8f9f7 223
<> 144:ef7eb2e8f9f7 224
<> 144:ef7eb2e8f9f7 225 /**@brief Function for manually informing that the local database has changed.
<> 144:ef7eb2e8f9f7 226 *
<> 144:ef7eb2e8f9f7 227 * @details This causes a service changed notification to be sent to all bonded peers that
<> 144:ef7eb2e8f9f7 228 * subscribe to it.
<> 144:ef7eb2e8f9f7 229 */
<> 144:ef7eb2e8f9f7 230 void gcm_local_database_has_changed(void);
<> 144:ef7eb2e8f9f7 231
<> 144:ef7eb2e8f9f7 232 /** @}
<> 144:ef7eb2e8f9f7 233 * @endcond
<> 144:ef7eb2e8f9f7 234 */
<> 144:ef7eb2e8f9f7 235
<> 144:ef7eb2e8f9f7 236 #endif /* GATT_CACHE_MANAGER_H__ */