Jonathan Austin / nRF51822

Dependents:   microbit_rubber_ducky microbit_mouse_BLE microbit_mouse_BLE_daybreak_version microbit_presenter

Fork of nRF51822 by Nordic Semiconductor

Committer:
vcoubard
Date:
Mon Jan 11 10:29:13 2016 +0000
Revision:
607:e98331f1d6b5
Child:
608:d9f8ffc6fc07
Import nordic sdk from https://github.com/ARMmbed/nrf51-sdk.git#a0faa63aae1f6351ac36cd70f28ce037d6f4ae11

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vcoubard 607:e98331f1d6b5 1 /*
vcoubard 607:e98331f1d6b5 2 * Copyright (c) Nordic Semiconductor ASA
vcoubard 607:e98331f1d6b5 3 * All rights reserved.
vcoubard 607:e98331f1d6b5 4 *
vcoubard 607:e98331f1d6b5 5 * Redistribution and use in source and binary forms, with or without modification,
vcoubard 607:e98331f1d6b5 6 * are permitted provided that the following conditions are met:
vcoubard 607:e98331f1d6b5 7 *
vcoubard 607:e98331f1d6b5 8 * 1. Redistributions of source code must retain the above copyright notice, this
vcoubard 607:e98331f1d6b5 9 * list of conditions and the following disclaimer.
vcoubard 607:e98331f1d6b5 10 *
vcoubard 607:e98331f1d6b5 11 * 2. Redistributions in binary form must reproduce the above copyright notice, this
vcoubard 607:e98331f1d6b5 12 * list of conditions and the following disclaimer in the documentation and/or
vcoubard 607:e98331f1d6b5 13 * other materials provided with the distribution.
vcoubard 607:e98331f1d6b5 14 *
vcoubard 607:e98331f1d6b5 15 * 3. Neither the name of Nordic Semiconductor ASA nor the names of other
vcoubard 607:e98331f1d6b5 16 * contributors to this software may be used to endorse or promote products
vcoubard 607:e98331f1d6b5 17 * derived from this software without specific prior written permission.
vcoubard 607:e98331f1d6b5 18 *
vcoubard 607:e98331f1d6b5 19 *
vcoubard 607:e98331f1d6b5 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
vcoubard 607:e98331f1d6b5 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
vcoubard 607:e98331f1d6b5 22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
vcoubard 607:e98331f1d6b5 23 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
vcoubard 607:e98331f1d6b5 24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
vcoubard 607:e98331f1d6b5 25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
vcoubard 607:e98331f1d6b5 26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
vcoubard 607:e98331f1d6b5 27 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
vcoubard 607:e98331f1d6b5 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
vcoubard 607:e98331f1d6b5 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
vcoubard 607:e98331f1d6b5 30 *
vcoubard 607:e98331f1d6b5 31 */
vcoubard 607:e98331f1d6b5 32
vcoubard 607:e98331f1d6b5 33 #ifndef PEER_ID_MANAGER_H__
vcoubard 607:e98331f1d6b5 34 #define PEER_ID_MANAGER_H__
vcoubard 607:e98331f1d6b5 35
vcoubard 607:e98331f1d6b5 36 #include "stdint.h"
vcoubard 607:e98331f1d6b5 37 #include "sdk_errors.h"
vcoubard 607:e98331f1d6b5 38 #include "ble.h"
vcoubard 607:e98331f1d6b5 39 #include "ble_gap.h"
vcoubard 607:e98331f1d6b5 40 #include "peer_manager_types.h"
vcoubard 607:e98331f1d6b5 41
vcoubard 607:e98331f1d6b5 42
vcoubard 607:e98331f1d6b5 43 /**
vcoubard 607:e98331f1d6b5 44 * @defgroup id_manager ID Manager
vcoubard 607:e98331f1d6b5 45 * @ingroup peer_manager
vcoubard 607:e98331f1d6b5 46 * @{
vcoubard 607:e98331f1d6b5 47 * @brief An internal module of @ref peer_manager. A module for keeping track of peer identities
vcoubard 607:e98331f1d6b5 48 * (IRK and peer address).
vcoubard 607:e98331f1d6b5 49 */
vcoubard 607:e98331f1d6b5 50
vcoubard 607:e98331f1d6b5 51
vcoubard 607:e98331f1d6b5 52 /**@brief Events that can come from the ID Manager module.
vcoubard 607:e98331f1d6b5 53 */
vcoubard 607:e98331f1d6b5 54 typedef enum
vcoubard 607:e98331f1d6b5 55 {
vcoubard 607:e98331f1d6b5 56 IM_EVT_DUPLICATE_ID, /**< The ID Manager module has detected that two stored peers represent the same peer. */
vcoubard 607:e98331f1d6b5 57 IM_EVT_BONDED_PEER_CONNECTED, /**< A connected peer has been identified as one of the bonded peers. This can happen immediately on connection, or at a later time. */
vcoubard 607:e98331f1d6b5 58 } im_evt_id_t;
vcoubard 607:e98331f1d6b5 59
vcoubard 607:e98331f1d6b5 60
vcoubard 607:e98331f1d6b5 61 typedef struct
vcoubard 607:e98331f1d6b5 62 {
vcoubard 607:e98331f1d6b5 63 im_evt_id_t evt_id;
vcoubard 607:e98331f1d6b5 64 uint16_t conn_handle;
vcoubard 607:e98331f1d6b5 65 union
vcoubard 607:e98331f1d6b5 66 {
vcoubard 607:e98331f1d6b5 67 struct
vcoubard 607:e98331f1d6b5 68 {
vcoubard 607:e98331f1d6b5 69 pm_peer_id_t peer_id_1;
vcoubard 607:e98331f1d6b5 70 pm_peer_id_t peer_id_2;
vcoubard 607:e98331f1d6b5 71 } duplicate_id;
vcoubard 607:e98331f1d6b5 72 } params;
vcoubard 607:e98331f1d6b5 73 } im_evt_t;
vcoubard 607:e98331f1d6b5 74
vcoubard 607:e98331f1d6b5 75
vcoubard 607:e98331f1d6b5 76 /**@brief Event handler for events from the ID Manager module.
vcoubard 607:e98331f1d6b5 77 *
vcoubard 607:e98331f1d6b5 78 * @param[in] p_event The event that has happened.
vcoubard 607:e98331f1d6b5 79 */
vcoubard 607:e98331f1d6b5 80 typedef void (*im_evt_handler_t)(im_evt_t const * p_event);
vcoubard 607:e98331f1d6b5 81
vcoubard 607:e98331f1d6b5 82 /**@brief Function for registering for events from the ID Manager module.
vcoubard 607:e98331f1d6b5 83 *
vcoubard 607:e98331f1d6b5 84 * @note This will also initialize the module if needed.
vcoubard 607:e98331f1d6b5 85 *
vcoubard 607:e98331f1d6b5 86 * @param[in] evt_handler Callback for events from the ID Manager module.
vcoubard 607:e98331f1d6b5 87 *
vcoubard 607:e98331f1d6b5 88 * @retval NRF_SUCCESS Registration was successful.
vcoubard 607:e98331f1d6b5 89 * @retval NRF_ERROR_NO_MEM No more registrations possible.
vcoubard 607:e98331f1d6b5 90 * @retval NRF_ERROR_NULL evt_handler was NULL.
vcoubard 607:e98331f1d6b5 91 */
vcoubard 607:e98331f1d6b5 92 ret_code_t im_register(im_evt_handler_t evt_handler);
vcoubard 607:e98331f1d6b5 93
vcoubard 607:e98331f1d6b5 94
vcoubard 607:e98331f1d6b5 95 /**@brief Function for dispatching SoftDevice events to the ID Manager module.
vcoubard 607:e98331f1d6b5 96 *
vcoubard 607:e98331f1d6b5 97 * @param[in] p_ble_evt The SoftDevice event.
vcoubard 607:e98331f1d6b5 98 */
vcoubard 607:e98331f1d6b5 99 void im_ble_evt_handler(ble_evt_t * p_ble_evt);
vcoubard 607:e98331f1d6b5 100
vcoubard 607:e98331f1d6b5 101
vcoubard 607:e98331f1d6b5 102 /**@brief Function for getting the corresponding peer ID from a connection handle.
vcoubard 607:e98331f1d6b5 103 *
vcoubard 607:e98331f1d6b5 104 * @param[in] conn_handle The connection handle.
vcoubard 607:e98331f1d6b5 105 *
vcoubard 607:e98331f1d6b5 106 * @return The corresponding peer ID, or @ref PM_PEER_ID_INVALID if none could be resolved.
vcoubard 607:e98331f1d6b5 107 */
vcoubard 607:e98331f1d6b5 108 pm_peer_id_t im_peer_id_get_by_conn_handle(uint16_t conn_handle);
vcoubard 607:e98331f1d6b5 109
vcoubard 607:e98331f1d6b5 110
vcoubard 607:e98331f1d6b5 111 /**@brief Function for getting the corresponding peer ID from a master ID (EDIV and rand).
vcoubard 607:e98331f1d6b5 112 *
vcoubard 607:e98331f1d6b5 113 * @param[in] p_master_id The master ID.
vcoubard 607:e98331f1d6b5 114 *
vcoubard 607:e98331f1d6b5 115 * @return The corresponding peer ID, or @ref PM_PEER_ID_INVALID if none could be resolved.
vcoubard 607:e98331f1d6b5 116 */
vcoubard 607:e98331f1d6b5 117 pm_peer_id_t im_peer_id_get_by_master_id(ble_gap_master_id_t * p_master_id);
vcoubard 607:e98331f1d6b5 118
vcoubard 607:e98331f1d6b5 119
vcoubard 607:e98331f1d6b5 120 /**@brief Function for getting the corresponding peer ID from an IRK match index, see @ref
vcoubard 607:e98331f1d6b5 121 * ble_gap_evt_connected_t.
vcoubard 607:e98331f1d6b5 122 *
vcoubard 607:e98331f1d6b5 123 * @param[in] irk_match_idx The IRK match index.
vcoubard 607:e98331f1d6b5 124 *
vcoubard 607:e98331f1d6b5 125 * @return The corresponding peer ID, or @ref PM_PEER_ID_INVALID if none could be resolved.
vcoubard 607:e98331f1d6b5 126 */
vcoubard 607:e98331f1d6b5 127 pm_peer_id_t im_peer_id_get_by_irk_match_idx(uint8_t irk_match_idx);
vcoubard 607:e98331f1d6b5 128
vcoubard 607:e98331f1d6b5 129
vcoubard 607:e98331f1d6b5 130 /**@brief Function for getting the corresponding connection handle from a peer ID.
vcoubard 607:e98331f1d6b5 131 *
vcoubard 607:e98331f1d6b5 132 * @param[in] peer_id The peer ID.
vcoubard 607:e98331f1d6b5 133 *
vcoubard 607:e98331f1d6b5 134 * @return The corresponding connection handle, or @ref BLE_CONN_HANDLE_INVALID if none could be
vcoubard 607:e98331f1d6b5 135 * resolved.
vcoubard 607:e98331f1d6b5 136 */
vcoubard 607:e98331f1d6b5 137 uint16_t im_conn_handle_get(pm_peer_id_t peer_id);
vcoubard 607:e98331f1d6b5 138
vcoubard 607:e98331f1d6b5 139
vcoubard 607:e98331f1d6b5 140 /**@brief Function for getting the BLE address used by the peer when connecting.
vcoubard 607:e98331f1d6b5 141 *
vcoubard 607:e98331f1d6b5 142 * @param[in] conn_handle The connection handle.
vcoubard 607:e98331f1d6b5 143 * @param[out] p_ble_addr The BLE address used by the peer when the connection specified by
vcoubard 607:e98331f1d6b5 144 * conn_handle was established.
vcoubard 607:e98331f1d6b5 145 *
vcoubard 607:e98331f1d6b5 146 * @retval NRF_SUCCESS The address was found and copied.
vcoubard 607:e98331f1d6b5 147 * @retval NRF_ERROR_INVALID_STATE Module not initialized.
vcoubard 607:e98331f1d6b5 148 * @retval BLE_ERROR_CONN_HANDLE_INVALID conn_handle does not refer to an active connection.
vcoubard 607:e98331f1d6b5 149 * @retval NRF_ERROR_NULL p_ble_addr was NULL.
vcoubard 607:e98331f1d6b5 150 */
vcoubard 607:e98331f1d6b5 151 ret_code_t im_ble_addr_get(uint16_t conn_handle, ble_gap_addr_t * p_ble_addr);
vcoubard 607:e98331f1d6b5 152
vcoubard 607:e98331f1d6b5 153
vcoubard 607:e98331f1d6b5 154 /**@brief Function for checking whether a master ID is valid or invalid
vcoubard 607:e98331f1d6b5 155 *
vcoubard 607:e98331f1d6b5 156 * @param[in] p_master_id The master ID.
vcoubard 607:e98331f1d6b5 157 *
vcoubard 607:e98331f1d6b5 158 * @retval true The master id is valid.
vcoubard 607:e98331f1d6b5 159 * @retval true The master id is invalid (i.e. all zeros).
vcoubard 607:e98331f1d6b5 160 */
vcoubard 607:e98331f1d6b5 161 bool im_master_id_is_valid(ble_gap_master_id_t const * p_master_id);
vcoubard 607:e98331f1d6b5 162
vcoubard 607:e98331f1d6b5 163
vcoubard 607:e98331f1d6b5 164 /**@brief Function for reporting that a new peer ID has been allocated for a specified connection.
vcoubard 607:e98331f1d6b5 165 *
vcoubard 607:e98331f1d6b5 166 * @param[in] conn_handle The connection.
vcoubard 607:e98331f1d6b5 167 * @param[in] peer_id The new peer ID.
vcoubard 607:e98331f1d6b5 168 */
vcoubard 607:e98331f1d6b5 169 void im_new_peer_id(uint16_t conn_handle, pm_peer_id_t peer_id);
vcoubard 607:e98331f1d6b5 170
vcoubard 607:e98331f1d6b5 171
vcoubard 607:e98331f1d6b5 172 /**
vcoubard 607:e98331f1d6b5 173 * @brief Function for informing this module of what whitelist will be used.
vcoubard 607:e98331f1d6b5 174 *
vcoubard 607:e98331f1d6b5 175 * @details This function is meant to be used when the app wants to use a custom whitelist.
vcoubard 607:e98331f1d6b5 176 * When using peer manager, this function must be used if a custom whitelist is used.
vcoubard 607:e98331f1d6b5 177 *
vcoubard 607:e98331f1d6b5 178 * @note When using a whitelist, always use the whitelist created/set by the most recent
vcoubard 607:e98331f1d6b5 179 * call to @ref im_wlist_create or to this function, whichever happened most recently.
vcoubard 607:e98331f1d6b5 180 * @note Do not call this function while scanning with another whitelist.
vcoubard 607:e98331f1d6b5 181 * @note Do not add any irks to the whitelist that are not present in the bonding data of a peer in
vcoubard 607:e98331f1d6b5 182 * the peer database.
vcoubard 607:e98331f1d6b5 183 *
vcoubard 607:e98331f1d6b5 184 * @param[in] p_whitelist The whitelist.
vcoubard 607:e98331f1d6b5 185 *
vcoubard 607:e98331f1d6b5 186 * @retval NRF_SUCCESS Whitelist successfully set.
vcoubard 607:e98331f1d6b5 187 * @retval NRF_ERROR_NULL p_whitelist was NULL.
vcoubard 607:e98331f1d6b5 188 * @retval NRF_ERROR_NOT_FOUND One or more of the whitelists irks was not found in the peer_database.
vcoubard 607:e98331f1d6b5 189 */
vcoubard 607:e98331f1d6b5 190 ret_code_t im_wlist_set(ble_gap_whitelist_t * p_whitelist);
vcoubard 607:e98331f1d6b5 191
vcoubard 607:e98331f1d6b5 192
vcoubard 607:e98331f1d6b5 193 /**
vcoubard 607:e98331f1d6b5 194 * @brief Function for constructing a whitelist for use when advertising.
vcoubard 607:e98331f1d6b5 195 *
vcoubard 607:e98331f1d6b5 196 * @note When advertising with whitelist, always use the whitelist created/set by the most recent
vcoubard 607:e98331f1d6b5 197 * call to this function or to @ref im_wlist_set, whichever happened most recently.
vcoubard 607:e98331f1d6b5 198 * @note Do not call this function while advertising with another whitelist.
vcoubard 607:e98331f1d6b5 199 *
vcoubard 607:e98331f1d6b5 200 * @param[in] p_peer_ids The ids of the peers to be added to the whitelist.
vcoubard 607:e98331f1d6b5 201 * @param[in] n_peer_ids The number of peer ids in p_peer_ids.
vcoubard 607:e98331f1d6b5 202 * @param[in,out] p_whitelist The constructed whitelist. Note that p_adv_whitelist->pp_addrs
vcoubard 607:e98331f1d6b5 203 * must be NULL or point to an array with size @ref
vcoubard 607:e98331f1d6b5 204 * BLE_GAP_WHITELIST_ADDR_MAX_COUNT and p_adv_whitelist->pp_irks
vcoubard 607:e98331f1d6b5 205 * must be NULL or point to an array with size @ref
vcoubard 607:e98331f1d6b5 206 * BLE_GAP_WHITELIST_IRK_MAX_COUNT.
vcoubard 607:e98331f1d6b5 207 *
vcoubard 607:e98331f1d6b5 208 * @retval NRF_SUCCESS Whitelist successfully created.
vcoubard 607:e98331f1d6b5 209 * @retval NRF_ERROR_NULL p_whitelist was NULL.
vcoubard 607:e98331f1d6b5 210 */
vcoubard 607:e98331f1d6b5 211 ret_code_t im_wlist_create(pm_peer_id_t * p_peer_ids,
vcoubard 607:e98331f1d6b5 212 uint8_t n_peer_ids,
vcoubard 607:e98331f1d6b5 213 ble_gap_whitelist_t * p_whitelist);
vcoubard 607:e98331f1d6b5 214
vcoubard 607:e98331f1d6b5 215 /**
vcoubard 607:e98331f1d6b5 216 * @brief Function for resolving a resolvable address with an identity resolution key (IRK).
vcoubard 607:e98331f1d6b5 217 *
vcoubard 607:e98331f1d6b5 218 * @details This function will use the ECB peripheral to resolve a resolvable address.
vcoubard 607:e98331f1d6b5 219 * This can be used to resolve the identity of a device distributing a random
vcoubard 607:e98331f1d6b5 220 * resolvable address based on any IRKs you have received earlier. If an address is
vcoubard 607:e98331f1d6b5 221 * resolved by an IRK, the device disributing the address must also know the IRK.
vcoubard 607:e98331f1d6b5 222 *
vcoubard 607:e98331f1d6b5 223 * @param[in] p_addr A random resolvable address.
vcoubard 607:e98331f1d6b5 224 * @param[in] p_irk An identity resolution key (IRK).
vcoubard 607:e98331f1d6b5 225 *
vcoubard 607:e98331f1d6b5 226 * @retval true The irk used matched the one used to create the address.
vcoubard 607:e98331f1d6b5 227 * @retval false The irk used did not match the one used to create the address, or an argument was
vcoubard 607:e98331f1d6b5 228 * NULL.
vcoubard 607:e98331f1d6b5 229 */
vcoubard 607:e98331f1d6b5 230 bool im_address_resolve(ble_gap_addr_t const * p_addr, ble_gap_irk_t const * p_irk);
vcoubard 607:e98331f1d6b5 231
vcoubard 607:e98331f1d6b5 232 /** @} */
vcoubard 607:e98331f1d6b5 233
vcoubard 607:e98331f1d6b5 234 #endif /* PEER_ID_MANAGER_H__ */