The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Wed Feb 20 20:53:29 2019 +0000
Revision:
172:65be27845400
Parent:
171:3a7713b1edbc
mbed library release version 165

Who changed what in which revision?

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