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:
Thu Nov 08 11:45:42 2018 +0000
Revision:
171:3a7713b1edbc
Parent:
TARGET_NRF51_DK/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/ble/peer_manager/peer_manager_types.h@169:a7c7b631e539
mbed library. Release version 164

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 146:22da6e220af6 1 /*
AnnaBridge 146:22da6e220af6 2 * Copyright (c) 2015 Nordic Semiconductor ASA
AnnaBridge 146:22da6e220af6 3 * All rights reserved.
AnnaBridge 146:22da6e220af6 4 *
AnnaBridge 146:22da6e220af6 5 * Redistribution and use in source and binary forms, with or without modification,
AnnaBridge 146:22da6e220af6 6 * are permitted provided that the following conditions are met:
AnnaBridge 146:22da6e220af6 7 *
AnnaBridge 146:22da6e220af6 8 * 1. Redistributions of source code must retain the above copyright notice, this list
AnnaBridge 146:22da6e220af6 9 * of conditions and the following disclaimer.
AnnaBridge 146:22da6e220af6 10 *
AnnaBridge 146:22da6e220af6 11 * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA
AnnaBridge 146:22da6e220af6 12 * integrated circuit in a product or a software update for such product, must reproduce
AnnaBridge 146:22da6e220af6 13 * the above copyright notice, this list of conditions and the following disclaimer in
AnnaBridge 146:22da6e220af6 14 * the documentation and/or other materials provided with the distribution.
AnnaBridge 146:22da6e220af6 15 *
AnnaBridge 146:22da6e220af6 16 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be
AnnaBridge 146:22da6e220af6 17 * used to endorse or promote products derived from this software without specific prior
AnnaBridge 146:22da6e220af6 18 * written permission.
AnnaBridge 146:22da6e220af6 19 *
AnnaBridge 146:22da6e220af6 20 * 4. This software, with or without modification, must only be used with a
AnnaBridge 146:22da6e220af6 21 * Nordic Semiconductor ASA integrated circuit.
AnnaBridge 146:22da6e220af6 22 *
AnnaBridge 146:22da6e220af6 23 * 5. Any software provided in binary or object form under this license must not be reverse
AnnaBridge 146:22da6e220af6 24 * engineered, decompiled, modified and/or disassembled.
AnnaBridge 146:22da6e220af6 25 *
AnnaBridge 146:22da6e220af6 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
AnnaBridge 146:22da6e220af6 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
AnnaBridge 146:22da6e220af6 28 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
AnnaBridge 146:22da6e220af6 29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
AnnaBridge 146:22da6e220af6 30 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
AnnaBridge 146:22da6e220af6 31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
AnnaBridge 146:22da6e220af6 32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
AnnaBridge 146:22da6e220af6 33 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
AnnaBridge 146:22da6e220af6 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
AnnaBridge 146:22da6e220af6 35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
AnnaBridge 146:22da6e220af6 36 *
AnnaBridge 146:22da6e220af6 37 */
AnnaBridge 146:22da6e220af6 38
AnnaBridge 146:22da6e220af6 39
AnnaBridge 146:22da6e220af6 40
AnnaBridge 146:22da6e220af6 41 /**
AnnaBridge 146:22da6e220af6 42 * @file peer_manager_types.h
AnnaBridge 146:22da6e220af6 43 *
AnnaBridge 146:22da6e220af6 44 * @addtogroup peer_manager
AnnaBridge 146:22da6e220af6 45 * @{
AnnaBridge 146:22da6e220af6 46 */
AnnaBridge 146:22da6e220af6 47
AnnaBridge 146:22da6e220af6 48 #ifndef PEER_MANAGER_TYPES_H__
AnnaBridge 146:22da6e220af6 49 #define PEER_MANAGER_TYPES_H__
AnnaBridge 146:22da6e220af6 50
AnnaBridge 146:22da6e220af6 51 #include <stdint.h>
AnnaBridge 146:22da6e220af6 52 #include <stdbool.h>
AnnaBridge 146:22da6e220af6 53 #include <stddef.h>
AnnaBridge 146:22da6e220af6 54 #include "nrf.h"
AnnaBridge 146:22da6e220af6 55 #include "nrf_ble_gap.h"
AnnaBridge 146:22da6e220af6 56 #include "nrf_ble_hci.h"
AnnaBridge 146:22da6e220af6 57 #include "app_util.h"
AnnaBridge 146:22da6e220af6 58 #include "app_util_platform.h"
AnnaBridge 146:22da6e220af6 59 #include "ble_gatt_db.h"
AnnaBridge 146:22da6e220af6 60
AnnaBridge 146:22da6e220af6 61
AnnaBridge 146:22da6e220af6 62 /**@brief Handle to uniquely identify a peer for which we have persistently stored data.
AnnaBridge 146:22da6e220af6 63 */
AnnaBridge 146:22da6e220af6 64 typedef uint16_t pm_peer_id_t;
AnnaBridge 146:22da6e220af6 65
AnnaBridge 146:22da6e220af6 66 /**@brief Type that is used for write prepares (used to reserve space in flash).
AnnaBridge 146:22da6e220af6 67 */
AnnaBridge 146:22da6e220af6 68 typedef uint32_t pm_prepare_token_t;
AnnaBridge 146:22da6e220af6 69
AnnaBridge 146:22da6e220af6 70 /**@brief Type that is used to hold a reference to a stored item in flash.
AnnaBridge 146:22da6e220af6 71 */
AnnaBridge 146:22da6e220af6 72 typedef uint32_t pm_store_token_t;
AnnaBridge 146:22da6e220af6 73
AnnaBridge 146:22da6e220af6 74 /**@brief Errors from security procedures in Peer Manager.
AnnaBridge 146:22da6e220af6 75 *
AnnaBridge 146:22da6e220af6 76 * @details Possible values are defined in @ref PM_SEC_ERRORS and @ref BLE_GAP_SEC_STATUS.
AnnaBridge 146:22da6e220af6 77 */
AnnaBridge 146:22da6e220af6 78 typedef uint16_t pm_sec_error_code_t;
AnnaBridge 146:22da6e220af6 79
AnnaBridge 146:22da6e220af6 80
AnnaBridge 146:22da6e220af6 81 //lint -emacro(516,PM_LOCAL_DB_LEN_OVERHEAD_BYTES)
AnnaBridge 146:22da6e220af6 82
AnnaBridge 146:22da6e220af6 83 #define PM_PEER_ID_INVALID 0xFFFF /**< @brief Invalid value for @ref pm_peer_id_t. */
AnnaBridge 146:22da6e220af6 84 #define PM_STORE_TOKEN_INVALID 0 /**< @brief Invalid value for store token. */
AnnaBridge 146:22da6e220af6 85 #define PM_PEER_ID_N_AVAILABLE_IDS 256 /**< @brief The number of available peer IDs. */
AnnaBridge 146:22da6e220af6 86 #define PM_LOCAL_DB_LEN_OVERHEAD_BYTES offsetof(pm_peer_data_local_gatt_db_t, data) /**< @brief The static-length part of the local GATT data struct. */
AnnaBridge 146:22da6e220af6 87
AnnaBridge 146:22da6e220af6 88
AnnaBridge 146:22da6e220af6 89 #define PM_CONN_SEC_ERROR_BASE 0x1000 /**< @brief The base for Peer Manager defined errors. See @ref PM_SEC_ERRORS and @ref pm_sec_error_code_t. */
AnnaBridge 146:22da6e220af6 90
AnnaBridge 146:22da6e220af6 91
AnnaBridge 146:22da6e220af6 92 /**@defgroup PM_SEC_ERRORS Peer Manager defined security errors
AnnaBridge 146:22da6e220af6 93 *
AnnaBridge 146:22da6e220af6 94 * @details The first 256 numbers in this range correspond to the status codes in
AnnaBridge 146:22da6e220af6 95 * @ref BLE_HCI_STATUS_CODES.
AnnaBridge 146:22da6e220af6 96 * @{ */
AnnaBridge 146:22da6e220af6 97 #define PM_CONN_SEC_ERROR_PIN_OR_KEY_MISSING (PM_CONN_SEC_ERROR_BASE + 0x06) /**< @brief Encryption failed because the peripheral has lost the LTK for this bond. See also @ref BLE_HCI_STATUS_CODE_PIN_OR_KEY_MISSING and Table 3.7 ("Pairing Failed Reason Codes") in the Bluetooth Core Specification 4.2, section 3.H.3.5.5 (@linkBLEcore). */
AnnaBridge 146:22da6e220af6 98 #define PM_CONN_SEC_ERROR_MIC_FAILURE (PM_CONN_SEC_ERROR_BASE + 0x3D) /**< @brief Encryption ended with disconnection because of mismatching keys or a stray packet during a procedure. See the SoftDevice GAP Message Sequence Charts on encryption (@linkBLEMSCgap), the Bluetooth Core Specification 4.2, sections 6.B.5.1.3.1 and 3.H.3.5.5 (@linkBLEcore), and @ref BLE_HCI_CONN_TERMINATED_DUE_TO_MIC_FAILURE. */
AnnaBridge 146:22da6e220af6 99 #define PM_CONN_SEC_ERROR_DISCONNECT (PM_CONN_SEC_ERROR_BASE + 0x100) /**< @brief Pairing or encryption did not finish before the link disconnected for an unrelated reason. */
AnnaBridge 146:22da6e220af6 100 #define PM_CONN_SEC_ERROR_SMP_TIMEOUT (PM_CONN_SEC_ERROR_BASE + 0x101) /**< @brief Pairing/bonding could not start because an SMP time-out has already happened on this link. This means that no more pairing or bonding can happen on this link. To be able to pair or bond, the link must be disconnected and then reconnected. See Bluetooth Core Specification 4.2 section 3.H.3.4 (@linkBLEcore). */
AnnaBridge 146:22da6e220af6 101 /** @} */
AnnaBridge 146:22da6e220af6 102
AnnaBridge 146:22da6e220af6 103
AnnaBridge 146:22da6e220af6 104
AnnaBridge 146:22da6e220af6 105 /**@defgroup PM_PEER_ID_VERSIONS All versions of Peer IDs.
AnnaBridge 146:22da6e220af6 106 * @brief The data ID for each iteration of the data formats in flash.
AnnaBridge 146:22da6e220af6 107 * @details Each time the format (in flash) of a piece of peer data changes, the data ID will also
AnnaBridge 146:22da6e220af6 108 * be updated. This list of defines is a record of each data ID that has ever existed, and
AnnaBridge 146:22da6e220af6 109 * code that caters to legacy formats can find the relevant IDs here.
AnnaBridge 146:22da6e220af6 110 * @{ */
AnnaBridge 146:22da6e220af6 111 #define PM_PEER_DATA_ID_FIRST_VX 0 /**< @brief The smallest data ID. */
AnnaBridge 146:22da6e220af6 112 #define PM_PEER_DATA_ID_BONDING_V1 0 /**< @brief The data ID of the first version of bonding data. */
AnnaBridge 146:22da6e220af6 113 #define PM_PEER_DATA_ID_BONDING_V2 7 /**< @brief The data ID of the second version of bonding data. */
AnnaBridge 146:22da6e220af6 114 #define PM_PEER_DATA_ID_SERVICE_CHANGED_PENDING_V1 1 /**< @brief The data ID of the first version of the service changed pending flag. */
AnnaBridge 146:22da6e220af6 115 #define PM_PEER_DATA_ID_GATT_LOCAL_V1 2 /**< @brief The data ID of the first version of local GATT data. */
AnnaBridge 146:22da6e220af6 116 #define PM_PEER_DATA_ID_GATT_LOCAL_V2 8 /**< @brief The data ID of the second version of local GATT data. */
AnnaBridge 146:22da6e220af6 117 #define PM_PEER_DATA_ID_GATT_REMOTE_V1 3 /**< @brief The data ID of the first version of remote GATT data. */
AnnaBridge 146:22da6e220af6 118 #define PM_PEER_DATA_ID_APPLICATION_V1 4 /**< @brief The data ID of the first version of application data. */
AnnaBridge 146:22da6e220af6 119 #define PM_PEER_DATA_ID_GATT_REMOTE_V2 5 /**< @brief The data ID of the second version of remote GATT data. */
AnnaBridge 146:22da6e220af6 120 #define PM_PEER_DATA_ID_PEER_RANK_V1 6 /**< @brief The data ID of the first version of the rank. */
AnnaBridge 146:22da6e220af6 121 #define PM_PEER_DATA_ID_LAST_VX 9 /**< @brief The data ID after the last valid one. */
AnnaBridge 146:22da6e220af6 122 #define PM_PEER_DATA_ID_INVALID_VX 0xFF /**< @brief A data ID guaranteed to be invalid. */
AnnaBridge 146:22da6e220af6 123 /**@}*/
AnnaBridge 146:22da6e220af6 124
AnnaBridge 146:22da6e220af6 125
AnnaBridge 146:22da6e220af6 126 /**@brief The different types of data associated with a peer.
AnnaBridge 146:22da6e220af6 127 */
AnnaBridge 146:22da6e220af6 128 typedef enum
AnnaBridge 146:22da6e220af6 129 {
AnnaBridge 146:22da6e220af6 130 PM_PEER_DATA_ID_FIRST = PM_PEER_DATA_ID_FIRST_VX, /**< @brief The smallest data ID. */
AnnaBridge 146:22da6e220af6 131 PM_PEER_DATA_ID_BONDING = PM_PEER_DATA_ID_BONDING_V2, /**< @brief The data ID for bonding data. See @ref pm_peer_data_bonding_t. */
AnnaBridge 146:22da6e220af6 132 PM_PEER_DATA_ID_SERVICE_CHANGED_PENDING = PM_PEER_DATA_ID_SERVICE_CHANGED_PENDING_V1, /**< @brief The data ID for service changed state. */
AnnaBridge 146:22da6e220af6 133 PM_PEER_DATA_ID_GATT_LOCAL = PM_PEER_DATA_ID_GATT_LOCAL_V2, /**< @brief The data ID for local GATT data (sys attributes). See @ref pm_peer_data_local_gatt_db_t. */
AnnaBridge 146:22da6e220af6 134 PM_PEER_DATA_ID_GATT_REMOTE = PM_PEER_DATA_ID_GATT_REMOTE_V2, /**< @brief The data ID for remote GATT data. */
AnnaBridge 146:22da6e220af6 135 PM_PEER_DATA_ID_PEER_RANK = PM_PEER_DATA_ID_PEER_RANK_V1, /**< @brief The data ID for peer rank. See @ref pm_peer_rank_highest. */
AnnaBridge 146:22da6e220af6 136 PM_PEER_DATA_ID_APPLICATION = PM_PEER_DATA_ID_APPLICATION_V1, /**< @brief The data ID for application data. */
AnnaBridge 146:22da6e220af6 137 PM_PEER_DATA_ID_LAST = PM_PEER_DATA_ID_LAST_VX, /**< @brief One more than the highest data ID. */
AnnaBridge 146:22da6e220af6 138 PM_PEER_DATA_ID_INVALID = PM_PEER_DATA_ID_INVALID_VX, /**< @brief A data ID guaranteed to be invalid. */
AnnaBridge 146:22da6e220af6 139 } pm_peer_data_id_t;
AnnaBridge 146:22da6e220af6 140
AnnaBridge 146:22da6e220af6 141
AnnaBridge 146:22da6e220af6 142 /**@brief Different procedures that can lead to an encrypted link.
AnnaBridge 146:22da6e220af6 143 */
AnnaBridge 146:22da6e220af6 144 typedef enum
AnnaBridge 146:22da6e220af6 145 {
AnnaBridge 146:22da6e220af6 146 PM_LINK_SECURED_PROCEDURE_ENCRYPTION, /**< @brief Using an LTK that was shared during a previous bonding procedure to encrypt the link. */
AnnaBridge 146:22da6e220af6 147 PM_LINK_SECURED_PROCEDURE_BONDING, /**< @brief A pairing procedure, followed by a bonding procedure. */
AnnaBridge 146:22da6e220af6 148 PM_LINK_SECURED_PROCEDURE_PAIRING, /**< @brief A pairing procedure with no bonding. */
AnnaBridge 146:22da6e220af6 149 } pm_conn_sec_procedure_t;
AnnaBridge 146:22da6e220af6 150
AnnaBridge 146:22da6e220af6 151
AnnaBridge 146:22da6e220af6 152 /**@brief Configuration of a security procedure.
AnnaBridge 146:22da6e220af6 153 */
AnnaBridge 146:22da6e220af6 154 typedef struct
AnnaBridge 146:22da6e220af6 155 {
AnnaBridge 146:22da6e220af6 156 bool allow_repairing; /** @brief Whether to allow the peer to pair if it wants to, but is already bonded. If this is false, the procedure is rejected, and no more events are sent. Default: false. */
AnnaBridge 146:22da6e220af6 157 } pm_conn_sec_config_t;
AnnaBridge 146:22da6e220af6 158
AnnaBridge 146:22da6e220af6 159
AnnaBridge 146:22da6e220af6 160 /**@brief Data associated with a bond to a peer.
AnnaBridge 146:22da6e220af6 161 */
AnnaBridge 146:22da6e220af6 162 typedef struct
AnnaBridge 146:22da6e220af6 163 {
AnnaBridge 146:22da6e220af6 164 uint8_t own_role; /**< @brief The role of the local device during bonding. */
AnnaBridge 146:22da6e220af6 165 ble_gap_id_key_t peer_id; /**< @brief The peer's peer address and identity resolution key. */
AnnaBridge 146:22da6e220af6 166 ble_gap_enc_key_t peer_ltk; /**< @brief The peer's long-term encryption key. */
AnnaBridge 146:22da6e220af6 167 ble_gap_enc_key_t own_ltk; /**< @brief Locally generated long-term encryption key, distributed to the peer. */
AnnaBridge 146:22da6e220af6 168 } pm_peer_data_bonding_t;
AnnaBridge 146:22da6e220af6 169
AnnaBridge 146:22da6e220af6 170
AnnaBridge 146:22da6e220af6 171
AnnaBridge 146:22da6e220af6 172 /**@brief Data on a local GATT database.
AnnaBridge 146:22da6e220af6 173 */
AnnaBridge 146:22da6e220af6 174 typedef struct
AnnaBridge 146:22da6e220af6 175 {
AnnaBridge 146:22da6e220af6 176 uint32_t flags; /**< @brief Flags that describe the database attributes. */
AnnaBridge 146:22da6e220af6 177 uint16_t len; /**< @brief Size of the attribute array. */
AnnaBridge 146:22da6e220af6 178
AnnaBridge 146:22da6e220af6 179 #ifdef __ICCARM__ //IAR dosen't support "flexible array member" in c++ compilation
AnnaBridge 146:22da6e220af6 180 uint8_t data[1]; /**< @brief Array to hold the database attributes. */
AnnaBridge 146:22da6e220af6 181 #else
AnnaBridge 146:22da6e220af6 182 uint8_t data[]; /**< @brief Array to hold the database attributes. */
AnnaBridge 146:22da6e220af6 183 #endif
AnnaBridge 146:22da6e220af6 184 } pm_peer_data_local_gatt_db_t;
AnnaBridge 146:22da6e220af6 185
AnnaBridge 146:22da6e220af6 186
AnnaBridge 146:22da6e220af6 187 /**@brief Macro to check whether a data type is valid, thus one of the valid enum values.
AnnaBridge 146:22da6e220af6 188 *
AnnaBridge 146:22da6e220af6 189 * @param[in] data_id The data type to check.
AnnaBridge 146:22da6e220af6 190 */
AnnaBridge 146:22da6e220af6 191 #define PM_PEER_DATA_ID_IS_VALID(data_id) \
AnnaBridge 146:22da6e220af6 192 ( ((data_id) == PM_PEER_DATA_ID_BONDING) \
AnnaBridge 146:22da6e220af6 193 || ((data_id) == PM_PEER_DATA_ID_SERVICE_CHANGED_PENDING)\
AnnaBridge 146:22da6e220af6 194 || ((data_id) == PM_PEER_DATA_ID_GATT_LOCAL) \
AnnaBridge 146:22da6e220af6 195 || ((data_id) == PM_PEER_DATA_ID_GATT_REMOTE) \
AnnaBridge 146:22da6e220af6 196 || ((data_id) == PM_PEER_DATA_ID_PEER_RANK) \
AnnaBridge 146:22da6e220af6 197 || ((data_id) == PM_PEER_DATA_ID_APPLICATION))
AnnaBridge 146:22da6e220af6 198
AnnaBridge 146:22da6e220af6 199
AnnaBridge 146:22da6e220af6 200 /** @} */
AnnaBridge 146:22da6e220af6 201
AnnaBridge 146:22da6e220af6 202 #endif /* PEER_MANAGER_TYPES_H__ */