Nicolas Borla / Mbed OS BBR_1Ebene
Committer:
borlanic
Date:
Mon May 14 11:29:06 2018 +0000
Revision:
0:fbdae7e6d805
BBR

Who changed what in which revision?

UserRevisionLine numberNew contents of line
borlanic 0:fbdae7e6d805 1 /*
borlanic 0:fbdae7e6d805 2 * Copyright (c) 2015 Nordic Semiconductor ASA
borlanic 0:fbdae7e6d805 3 * All rights reserved.
borlanic 0:fbdae7e6d805 4 *
borlanic 0:fbdae7e6d805 5 * Redistribution and use in source and binary forms, with or without modification,
borlanic 0:fbdae7e6d805 6 * are permitted provided that the following conditions are met:
borlanic 0:fbdae7e6d805 7 *
borlanic 0:fbdae7e6d805 8 * 1. Redistributions of source code must retain the above copyright notice, this list
borlanic 0:fbdae7e6d805 9 * of conditions and the following disclaimer.
borlanic 0:fbdae7e6d805 10 *
borlanic 0:fbdae7e6d805 11 * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA
borlanic 0:fbdae7e6d805 12 * integrated circuit in a product or a software update for such product, must reproduce
borlanic 0:fbdae7e6d805 13 * the above copyright notice, this list of conditions and the following disclaimer in
borlanic 0:fbdae7e6d805 14 * the documentation and/or other materials provided with the distribution.
borlanic 0:fbdae7e6d805 15 *
borlanic 0:fbdae7e6d805 16 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be
borlanic 0:fbdae7e6d805 17 * used to endorse or promote products derived from this software without specific prior
borlanic 0:fbdae7e6d805 18 * written permission.
borlanic 0:fbdae7e6d805 19 *
borlanic 0:fbdae7e6d805 20 * 4. This software, with or without modification, must only be used with a
borlanic 0:fbdae7e6d805 21 * Nordic Semiconductor ASA integrated circuit.
borlanic 0:fbdae7e6d805 22 *
borlanic 0:fbdae7e6d805 23 * 5. Any software provided in binary or object form under this license must not be reverse
borlanic 0:fbdae7e6d805 24 * engineered, decompiled, modified and/or disassembled.
borlanic 0:fbdae7e6d805 25 *
borlanic 0:fbdae7e6d805 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
borlanic 0:fbdae7e6d805 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
borlanic 0:fbdae7e6d805 28 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
borlanic 0:fbdae7e6d805 29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
borlanic 0:fbdae7e6d805 30 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
borlanic 0:fbdae7e6d805 31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
borlanic 0:fbdae7e6d805 32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
borlanic 0:fbdae7e6d805 33 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
borlanic 0:fbdae7e6d805 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
borlanic 0:fbdae7e6d805 35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
borlanic 0:fbdae7e6d805 36 *
borlanic 0:fbdae7e6d805 37 */
borlanic 0:fbdae7e6d805 38
borlanic 0:fbdae7e6d805 39
borlanic 0:fbdae7e6d805 40
borlanic 0:fbdae7e6d805 41 #ifndef GATTS_CACHE_MANAGER_H__
borlanic 0:fbdae7e6d805 42 #define GATTS_CACHE_MANAGER_H__
borlanic 0:fbdae7e6d805 43
borlanic 0:fbdae7e6d805 44 #include <stdint.h>
borlanic 0:fbdae7e6d805 45 #include "sdk_errors.h"
borlanic 0:fbdae7e6d805 46 #include "nrf_ble.h"
borlanic 0:fbdae7e6d805 47 #include "nrf_ble_gap.h"
borlanic 0:fbdae7e6d805 48 #include "peer_manager_types.h"
borlanic 0:fbdae7e6d805 49
borlanic 0:fbdae7e6d805 50
borlanic 0:fbdae7e6d805 51
borlanic 0:fbdae7e6d805 52 /**
borlanic 0:fbdae7e6d805 53 * @cond NO_DOXYGEN
borlanic 0:fbdae7e6d805 54 * @defgroup gatts_cache_manager GATT Server Cache Manager
borlanic 0:fbdae7e6d805 55 * @ingroup peer_manager
borlanic 0:fbdae7e6d805 56 * @{
borlanic 0:fbdae7e6d805 57 * @brief An internal module of @ref peer_manager. A module for managing persistent storing of GATT
borlanic 0:fbdae7e6d805 58 * attributes pertaining to the GATT server role of the local device.
borlanic 0:fbdae7e6d805 59 */
borlanic 0:fbdae7e6d805 60
borlanic 0:fbdae7e6d805 61
borlanic 0:fbdae7e6d805 62 /**@brief Events that can come from the GATT Server Cache Manager module.
borlanic 0:fbdae7e6d805 63 */
borlanic 0:fbdae7e6d805 64 typedef enum
borlanic 0:fbdae7e6d805 65 {
borlanic 0:fbdae7e6d805 66 GSCM_EVT_LOCAL_DB_CACHE_STORED, /**< The persistent cache for the local database has been updated with provided values, for one peer. */
borlanic 0:fbdae7e6d805 67 GSCM_EVT_LOCAL_DB_CACHE_UPDATED, /**< The persistent cache for the local database has been updated with values from the SoftDevice, for one peer. */
borlanic 0:fbdae7e6d805 68 GSCM_EVT_SC_STATE_STORED, /**< The service changed pending flag in persistent storage has been updated, for one peer. */
borlanic 0:fbdae7e6d805 69 } gscm_evt_id_t;
borlanic 0:fbdae7e6d805 70
borlanic 0:fbdae7e6d805 71
borlanic 0:fbdae7e6d805 72 /**@brief Structure containing an event from the GSCM module.
borlanic 0:fbdae7e6d805 73 */
borlanic 0:fbdae7e6d805 74 typedef struct
borlanic 0:fbdae7e6d805 75 {
borlanic 0:fbdae7e6d805 76 gscm_evt_id_t evt_id; /**< The type of event this is. */
borlanic 0:fbdae7e6d805 77 pm_peer_id_t peer_id; /**< The peer ID this event pertains to. */
borlanic 0:fbdae7e6d805 78 union
borlanic 0:fbdae7e6d805 79 {
borlanic 0:fbdae7e6d805 80 struct
borlanic 0:fbdae7e6d805 81 {
borlanic 0:fbdae7e6d805 82 uint16_t conn_handle; /**< The connection this event pertains to. */
borlanic 0:fbdae7e6d805 83 } local_db_cache_updated;
borlanic 0:fbdae7e6d805 84 struct
borlanic 0:fbdae7e6d805 85 {
borlanic 0:fbdae7e6d805 86 bool state; /**< The newly stored state of the Service Changed pending flag. */
borlanic 0:fbdae7e6d805 87 } sc_state_stored;
borlanic 0:fbdae7e6d805 88 } params; /**< Event parameters specific to certain event types. */
borlanic 0:fbdae7e6d805 89 } gscm_evt_t;
borlanic 0:fbdae7e6d805 90
borlanic 0:fbdae7e6d805 91 /**@brief Event handler for events from the GATT Server Cache Manager module.
borlanic 0:fbdae7e6d805 92 *
borlanic 0:fbdae7e6d805 93 * @param[in] event The event that has happened.
borlanic 0:fbdae7e6d805 94 * @param[in] peer The id of the peer the event pertains to.
borlanic 0:fbdae7e6d805 95 * @param[in] flags The data the event pertains to.
borlanic 0:fbdae7e6d805 96 */
borlanic 0:fbdae7e6d805 97 typedef void (*gscm_evt_handler_t)(gscm_evt_t const * p_event);
borlanic 0:fbdae7e6d805 98
borlanic 0:fbdae7e6d805 99
borlanic 0:fbdae7e6d805 100 /**@brief Function for initializing the GATT Server Cache Manager module.
borlanic 0:fbdae7e6d805 101 *
borlanic 0:fbdae7e6d805 102 * @param[in] evt_handler Callback for events from the GATT Server Cache Manager module.
borlanic 0:fbdae7e6d805 103 *
borlanic 0:fbdae7e6d805 104 * @retval NRF_SUCCESS Initialization was successful.
borlanic 0:fbdae7e6d805 105 * @retval NRF_ERROR_NULL evt_handler was NULL.
borlanic 0:fbdae7e6d805 106 */
borlanic 0:fbdae7e6d805 107 ret_code_t gscm_init(gscm_evt_handler_t evt_handler);
borlanic 0:fbdae7e6d805 108
borlanic 0:fbdae7e6d805 109
borlanic 0:fbdae7e6d805 110 /**@brief Function for triggering local GATT database data to be stored persistently. Values are
borlanic 0:fbdae7e6d805 111 * retrieved from the SoftDevice and written to persistent storage.
borlanic 0:fbdae7e6d805 112 *
borlanic 0:fbdae7e6d805 113 * @param[in] conn_handle Connection handle to perform update on.
borlanic 0:fbdae7e6d805 114 *
borlanic 0:fbdae7e6d805 115 * @retval NRF_SUCCESS Store operation started.
borlanic 0:fbdae7e6d805 116 * @retval BLE_ERROR_INVALID_CONN_HANDLE conn_handle does not refer to an active connection with a
borlanic 0:fbdae7e6d805 117 * bonded peer.
borlanic 0:fbdae7e6d805 118 * @retval NRF_ERROR_BUSY Unable to perform operation at this time. Reattempt later.
borlanic 0:fbdae7e6d805 119 * @retval NRF_ERROR_DATA_SIZE Write buffer not large enough. Call will never work with
borlanic 0:fbdae7e6d805 120 * this GATT database.
borlanic 0:fbdae7e6d805 121 * @retval NRF_ERROR_NO_MEM No room in persistent_storage. Free up space; the
borlanic 0:fbdae7e6d805 122 * operation will be automatically reattempted after the
borlanic 0:fbdae7e6d805 123 * next compression procedure
borlanic 0:fbdae7e6d805 124 * @retval NRF_ERROR_INVALID_STATE Module is not initialized.
borlanic 0:fbdae7e6d805 125 */
borlanic 0:fbdae7e6d805 126 ret_code_t gscm_local_db_cache_update(uint16_t conn_handle);
borlanic 0:fbdae7e6d805 127
borlanic 0:fbdae7e6d805 128
borlanic 0:fbdae7e6d805 129 /**@brief Function for applying stored local GATT database data to the SoftDevice. Values are
borlanic 0:fbdae7e6d805 130 * retrieved from persistent storage and given to the SoftDevice.
borlanic 0:fbdae7e6d805 131 *
borlanic 0:fbdae7e6d805 132 * @param[in] conn_handle Connection handle to apply values to.
borlanic 0:fbdae7e6d805 133 *
borlanic 0:fbdae7e6d805 134 * @retval NRF_SUCCESS Store operation started.
borlanic 0:fbdae7e6d805 135 * @retval BLE_ERROR_INVALID_CONN_HANDLE conn_handle does not refer to an active connection with a
borlanic 0:fbdae7e6d805 136 * bonded peer.
borlanic 0:fbdae7e6d805 137 * @retval NRF_ERROR_INVALID_DATA The stored data was rejected by the SoftDevice, which
borlanic 0:fbdae7e6d805 138 * probably means that the local database has changed. The
borlanic 0:fbdae7e6d805 139 * system part of the sys_attributes was attempted applied,
borlanic 0:fbdae7e6d805 140 * so service changed indications can be sent to subscribers.
borlanic 0:fbdae7e6d805 141 * @retval NRF_ERROR_BUSY Unable to perform operation at this time. Reattempt later.
borlanic 0:fbdae7e6d805 142 * @retval NRF_ERROR_INVALID_STATE Module is not initialized.
borlanic 0:fbdae7e6d805 143 * @return An unexpected return value from an internal function call.
borlanic 0:fbdae7e6d805 144 */
borlanic 0:fbdae7e6d805 145 ret_code_t gscm_local_db_cache_apply(uint16_t conn_handle);
borlanic 0:fbdae7e6d805 146
borlanic 0:fbdae7e6d805 147
borlanic 0:fbdae7e6d805 148 /**@brief Function for setting new values in the local database cache.
borlanic 0:fbdae7e6d805 149 *
borlanic 0:fbdae7e6d805 150 * @note If the peer is connected, the values will also be applied immediately to the connection.
borlanic 0:fbdae7e6d805 151 * @note The data in the pointer must be available until the GSCM_EVT_LOCAL_DB_STORED event is
borlanic 0:fbdae7e6d805 152 * received.
borlanic 0:fbdae7e6d805 153 *
borlanic 0:fbdae7e6d805 154 * @param[in] peer_id Peer to set values for.
borlanic 0:fbdae7e6d805 155 * @param[in] p_local_db Database values to apply. If NULL, the values will instead be cleared.
borlanic 0:fbdae7e6d805 156 *
borlanic 0:fbdae7e6d805 157 * @retval NRF_SUCCESS Operation started, and values were applied (if connected).
borlanic 0:fbdae7e6d805 158 * @retval NRF_ERROR_NOT_FOUND The peer ID was invalid or unallocated.
borlanic 0:fbdae7e6d805 159 * @retval NRF_ERROR_INVALID_STATE Module is not initialized.
borlanic 0:fbdae7e6d805 160 * @return An unexpected return value from an internal function call.
borlanic 0:fbdae7e6d805 161 */
borlanic 0:fbdae7e6d805 162 ret_code_t gscm_local_db_cache_set(pm_peer_id_t peer_id, pm_peer_data_local_gatt_db_t * p_local_db);
borlanic 0:fbdae7e6d805 163
borlanic 0:fbdae7e6d805 164
borlanic 0:fbdae7e6d805 165 /**@brief Function for retrieving values in the local database cache.
borlanic 0:fbdae7e6d805 166 *
borlanic 0:fbdae7e6d805 167 * @param[in] peer_id Peer to get values for.
borlanic 0:fbdae7e6d805 168 * @param[inout] p_local_db Where to store the data. The length field needs to reflect the
borlanic 0:fbdae7e6d805 169 * available buffer space. On a successful read, the length field is
borlanic 0:fbdae7e6d805 170 * updated to match the length of the read data.
borlanic 0:fbdae7e6d805 171 *
borlanic 0:fbdae7e6d805 172 * @retval NRF_SUCCESS Values retrieved successfully.
borlanic 0:fbdae7e6d805 173 * @retval NRF_ERROR_NOT_FOUND The peer ID was invalid or unallocated.
borlanic 0:fbdae7e6d805 174 * @retval NRF_ERROR_NULL p_local_db was NULL.
borlanic 0:fbdae7e6d805 175 * @retval NRF_ERROR_INVALID_STATE Module is not initialized.
borlanic 0:fbdae7e6d805 176 */
borlanic 0:fbdae7e6d805 177 ret_code_t gscm_local_db_cache_get(pm_peer_id_t peer_id, pm_peer_data_local_gatt_db_t * p_local_db);
borlanic 0:fbdae7e6d805 178
borlanic 0:fbdae7e6d805 179
borlanic 0:fbdae7e6d805 180 /**@brief Function for storing the fact that the local database has changed, for all currently
borlanic 0:fbdae7e6d805 181 * bonded peers.
borlanic 0:fbdae7e6d805 182 *
borlanic 0:fbdae7e6d805 183 * @note This will cause a later call to @ref gscm_service_changed_ind_needed to return true for
borlanic 0:fbdae7e6d805 184 * a connection with a currently bonded peer.
borlanic 0:fbdae7e6d805 185 */
borlanic 0:fbdae7e6d805 186 void gscm_local_database_has_changed(void);
borlanic 0:fbdae7e6d805 187
borlanic 0:fbdae7e6d805 188
borlanic 0:fbdae7e6d805 189 /**@brief Function for checking if a service changed indication should be sent.
borlanic 0:fbdae7e6d805 190 *
borlanic 0:fbdae7e6d805 191 * @param[in] conn_handle The connection to check.
borlanic 0:fbdae7e6d805 192 *
borlanic 0:fbdae7e6d805 193 * @return true if a service changed indication should be sent, false if not.
borlanic 0:fbdae7e6d805 194 */
borlanic 0:fbdae7e6d805 195 bool gscm_service_changed_ind_needed(uint16_t conn_handle);
borlanic 0:fbdae7e6d805 196
borlanic 0:fbdae7e6d805 197
borlanic 0:fbdae7e6d805 198 /**@brief Function for sending a service changed indication to a connected peer.
borlanic 0:fbdae7e6d805 199 *
borlanic 0:fbdae7e6d805 200 * @param[in] conn_handle The connection to send the indication on.
borlanic 0:fbdae7e6d805 201 *
borlanic 0:fbdae7e6d805 202 * @retval NRF_SUCCESS Indication sent or not needed.
borlanic 0:fbdae7e6d805 203 * @retval BLE_ERROR_INVALID_CONN_HANDLE conn_handle does not refer to an active connection.
borlanic 0:fbdae7e6d805 204 * @retval NRF_ERROR_BUSY Unable to send indication at this time. Reattempt later.
borlanic 0:fbdae7e6d805 205 * @retval BLE_ERROR_GATTS_SYS_ATTR_MISSING Information missing. Apply local cache, then reattempt.
borlanic 0:fbdae7e6d805 206 * @retval NRF_ERROR_INVALID_PARAM From @ref sd_ble_gatts_service_changed. Unexpected.
borlanic 0:fbdae7e6d805 207 * @retval NRF_ERROR_NOT_SUPPORTED Service changed characteristic is not present.
borlanic 0:fbdae7e6d805 208 * @retval NRF_ERROR_INVALID_STATE Service changed cannot be indicated to this peer
borlanic 0:fbdae7e6d805 209 * because the peer has not subscribed to it.
borlanic 0:fbdae7e6d805 210 */
borlanic 0:fbdae7e6d805 211 ret_code_t gscm_service_changed_ind_send(uint16_t conn_handle);
borlanic 0:fbdae7e6d805 212
borlanic 0:fbdae7e6d805 213
borlanic 0:fbdae7e6d805 214 /**@brief Function for specifying that a peer has been made aware of the latest local database
borlanic 0:fbdae7e6d805 215 * change.
borlanic 0:fbdae7e6d805 216 *
borlanic 0:fbdae7e6d805 217 * @note After calling this, a later call to @ref gscm_service_changed_ind_needed will to return
borlanic 0:fbdae7e6d805 218 * false for this peer unless @ref gscm_local_database_has_changed is called again.
borlanic 0:fbdae7e6d805 219 *
borlanic 0:fbdae7e6d805 220 * @param[in] peer_id The connection to send the indication on.
borlanic 0:fbdae7e6d805 221 */
borlanic 0:fbdae7e6d805 222 void gscm_db_change_notification_done(pm_peer_id_t peer_id);
borlanic 0:fbdae7e6d805 223
borlanic 0:fbdae7e6d805 224 /** @}
borlanic 0:fbdae7e6d805 225 * @endcond
borlanic 0:fbdae7e6d805 226 */
borlanic 0:fbdae7e6d805 227
borlanic 0:fbdae7e6d805 228 #endif /* GATTS_CACHE_MANAGER_H__ */