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.
TARGET_TY51822R3/TOOLCHAIN_IAR/security_manager.h@172:65be27845400, 2019-02-20 (annotated)
- 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?
User | Revision | Line number | New 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 SECURITY_MANAGER_H__ |
AnnaBridge | 143:86740a56073b | 42 | #define SECURITY_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 | #include "security_dispatcher.h" |
AnnaBridge | 143:86740a56073b | 50 | |
AnnaBridge | 143:86740a56073b | 51 | |
AnnaBridge | 143:86740a56073b | 52 | /** |
AnnaBridge | 143:86740a56073b | 53 | * @cond NO_DOXYGEN |
AnnaBridge | 143:86740a56073b | 54 | * @defgroup security_manager Security 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 streamlining pairing, bonding, and |
AnnaBridge | 143:86740a56073b | 58 | * encryption, including flash storage of shared data. |
AnnaBridge | 143:86740a56073b | 59 | */ |
AnnaBridge | 143:86740a56073b | 60 | |
AnnaBridge | 143:86740a56073b | 61 | |
AnnaBridge | 143:86740a56073b | 62 | /**@brief Events that can come from the Security Manager module. |
AnnaBridge | 143:86740a56073b | 63 | */ |
AnnaBridge | 143:86740a56073b | 64 | typedef enum |
AnnaBridge | 143:86740a56073b | 65 | { |
AnnaBridge | 143:86740a56073b | 66 | // SM_EVT_PARAMS_REQ = SMD_EVT_PARAMS_REQ, /**< Parameters are required for a pairing procedure on the specified connection. The user must provide them using @ref sm_sec_params_set or @ref sm_sec_params_reply (only this procedure, currently unimplemented). */ |
AnnaBridge | 143:86740a56073b | 67 | SM_EVT_SLAVE_SECURITY_REQ = SMD_EVT_SLAVE_SECURITY_REQ, /**< The peer (peripheral) has requested link encryption, which has been enabled. */ |
AnnaBridge | 143:86740a56073b | 68 | SM_EVT_SEC_PROCEDURE_START = SMD_EVT_SEC_PROCEDURE_START, /**< A security procedure has started. */ |
AnnaBridge | 143:86740a56073b | 69 | SM_EVT_PAIRING_SUCCESS = SMD_EVT_PAIRING_SUCCESS, /**< A pairing procedure (and bonding if applicable) has completed with success. */ |
AnnaBridge | 143:86740a56073b | 70 | SM_EVT_PAIRING_FAIL = SMD_EVT_PAIRING_FAIL, /**< A pairing procedure has failed which means no encryption and no bond could be established. */ |
AnnaBridge | 143:86740a56073b | 71 | SM_EVT_LINK_ENCRYPTION_UPDATE = SMD_EVT_LINK_ENCRYPTION_UPDATE, /**< The security level of the link has been updated. The link is encrypted. */ |
AnnaBridge | 143:86740a56073b | 72 | SM_EVT_LINK_ENCRYPTION_FAILED = SMD_EVT_LINK_ENCRYPTION_FAILED, /**< An attempt to start encryption on an unencrypted link failed because the peripheral did not have the correct keys. If the peer is the peripheral, the force_repairing flag should be set when reattempting @ref sm_link_secure. */ |
AnnaBridge | 143:86740a56073b | 73 | SM_EVT_BONDING_INFO_STORED = SMD_EVT_BONDING_INFO_STORED, /**< Information exchanged during bonding with a peer has been stored persistently. */ |
AnnaBridge | 143:86740a56073b | 74 | SM_EVT_ERROR_BONDING_INFO = SMD_EVT_ERROR_BONDING_INFO, /**< Information exchanged during bonding with a peer could not be stored persistently, because of an unexpected error. */ |
AnnaBridge | 143:86740a56073b | 75 | SM_EVT_ERROR_UNEXPECTED = SMD_EVT_ERROR_UNEXPECTED, /**< An operation failed with an unexpected error. The error is provided. This is possibly a fatal error. */ |
AnnaBridge | 143:86740a56073b | 76 | SM_EVT_ERROR_NO_MEM /*= SMD_EVT_ERROR_NO_MEM*/, /**< An operation failed because there was no available storage room in persistent storage. Please free up room and the operation will automatically continue after the next compression. */ |
AnnaBridge | 143:86740a56073b | 77 | SM_EVT_ERROR_SMP_TIMEOUT, /**< An operation failed because there has been an SMP timeout on the link, which entails that no more security operations can be performed on it. */ |
AnnaBridge | 143:86740a56073b | 78 | SM_EVT_CONN_SEC_CONFIG_REQ, /**< The peer (central) has requested pairing, but a bond already exists with that peer. Reply by calling @ref sm_conn_sec_config_reply before the event handler returns. If no reply is sent, a default is used. */ |
AnnaBridge | 143:86740a56073b | 79 | } sm_evt_id_t; |
AnnaBridge | 143:86740a56073b | 80 | |
AnnaBridge | 143:86740a56073b | 81 | |
AnnaBridge | 143:86740a56073b | 82 | typedef struct |
AnnaBridge | 143:86740a56073b | 83 | { |
AnnaBridge | 143:86740a56073b | 84 | sm_evt_id_t evt_id; |
AnnaBridge | 143:86740a56073b | 85 | uint16_t conn_handle; |
AnnaBridge | 143:86740a56073b | 86 | smd_evt_params_t params; |
AnnaBridge | 143:86740a56073b | 87 | } sm_evt_t; |
AnnaBridge | 143:86740a56073b | 88 | |
AnnaBridge | 143:86740a56073b | 89 | |
AnnaBridge | 143:86740a56073b | 90 | |
AnnaBridge | 143:86740a56073b | 91 | /**@brief Event handler for events from the Security Manager module. |
AnnaBridge | 143:86740a56073b | 92 | * |
AnnaBridge | 143:86740a56073b | 93 | * @param[in] event The event that has happened. |
AnnaBridge | 143:86740a56073b | 94 | * @param[in] conn_handle The connection handle the event pertains to. |
AnnaBridge | 143:86740a56073b | 95 | */ |
AnnaBridge | 143:86740a56073b | 96 | typedef void (*sm_evt_handler_t)(sm_evt_t const * p_event); |
AnnaBridge | 143:86740a56073b | 97 | |
AnnaBridge | 143:86740a56073b | 98 | |
AnnaBridge | 143:86740a56073b | 99 | /**@brief Function for registering with the Security Manager module. This function also |
AnnaBridge | 143:86740a56073b | 100 | * initializes the module if uninitialized. |
AnnaBridge | 143:86740a56073b | 101 | * |
AnnaBridge | 143:86740a56073b | 102 | * @param[in] evt_handler Callback for events from the Security Manager module. |
AnnaBridge | 143:86740a56073b | 103 | * |
AnnaBridge | 143:86740a56073b | 104 | * @retval NRF_SUCCESS Registration was successful. |
AnnaBridge | 143:86740a56073b | 105 | * @retval NRF_ERROR_NO_MEM No more registrations possible. |
AnnaBridge | 143:86740a56073b | 106 | * @retval NRF_ERROR_NULL evt_handler was NULL. |
AnnaBridge | 143:86740a56073b | 107 | * @retval NRF_ERROR_INTERNAL An unexpected error occurred. |
AnnaBridge | 143:86740a56073b | 108 | */ |
AnnaBridge | 143:86740a56073b | 109 | ret_code_t sm_register(sm_evt_handler_t evt_handler); |
AnnaBridge | 143:86740a56073b | 110 | |
AnnaBridge | 143:86740a56073b | 111 | |
AnnaBridge | 143:86740a56073b | 112 | /**@brief Function for dispatching SoftDevice events to the Security Manager module. |
AnnaBridge | 143:86740a56073b | 113 | * |
AnnaBridge | 143:86740a56073b | 114 | * @param[in] ble_evt The SoftDevice event. |
AnnaBridge | 143:86740a56073b | 115 | */ |
AnnaBridge | 143:86740a56073b | 116 | void sm_ble_evt_handler(ble_evt_t * ble_evt); |
AnnaBridge | 143:86740a56073b | 117 | |
AnnaBridge | 143:86740a56073b | 118 | |
AnnaBridge | 143:86740a56073b | 119 | /**@brief Function for providing pairing and bonding parameters to use for pairing procedures. |
AnnaBridge | 143:86740a56073b | 120 | * |
AnnaBridge | 143:86740a56073b | 121 | * @details Until this is called, all bonding procedures initiated by the peer will be rejected. |
AnnaBridge | 143:86740a56073b | 122 | * This function can be called multiple times, even with NULL p_sec_params, in which case |
AnnaBridge | 143:86740a56073b | 123 | * it will go back to rejecting all procedures. |
AnnaBridge | 143:86740a56073b | 124 | * |
AnnaBridge | 143:86740a56073b | 125 | * @param[in] p_sec_params The security parameters to use for this link. Can be NULL to reject |
AnnaBridge | 143:86740a56073b | 126 | * all pairing procedures. |
AnnaBridge | 143:86740a56073b | 127 | * |
AnnaBridge | 143:86740a56073b | 128 | * @retval NRF_SUCCESS Success. |
AnnaBridge | 143:86740a56073b | 129 | * @retval NRF_ERROR_INVALID_PARAM Invalid combination of parameters. |
AnnaBridge | 143:86740a56073b | 130 | * @retval NRF_ERROR_INVALID_STATE Module is not initialized. |
AnnaBridge | 143:86740a56073b | 131 | */ |
AnnaBridge | 143:86740a56073b | 132 | ret_code_t sm_sec_params_set(ble_gap_sec_params_t * p_sec_params); |
AnnaBridge | 143:86740a56073b | 133 | |
AnnaBridge | 143:86740a56073b | 134 | |
AnnaBridge | 143:86740a56073b | 135 | /**@brief Function for providing security configuration for a link. |
AnnaBridge | 143:86740a56073b | 136 | * |
AnnaBridge | 143:86740a56073b | 137 | * @details This function is optional, and must be called in reply to a @ref |
AnnaBridge | 143:86740a56073b | 138 | * SM_EVT_CONN_SEC_CONFIG_REQ event, before the Peer Manager event handler returns. If it |
AnnaBridge | 143:86740a56073b | 139 | * is not called in time, a default configuration is used. See @ref pm_conn_sec_config_t |
AnnaBridge | 143:86740a56073b | 140 | * for the value of the default. |
AnnaBridge | 143:86740a56073b | 141 | * |
AnnaBridge | 143:86740a56073b | 142 | * @param[in] conn_handle The connection to set the configuration for. |
AnnaBridge | 143:86740a56073b | 143 | * @param[in] p_conn_sec_config The configuration. |
AnnaBridge | 143:86740a56073b | 144 | */ |
AnnaBridge | 143:86740a56073b | 145 | void sm_conn_sec_config_reply(uint16_t conn_handle, pm_conn_sec_config_t * p_conn_sec_config); |
AnnaBridge | 143:86740a56073b | 146 | |
AnnaBridge | 143:86740a56073b | 147 | |
AnnaBridge | 143:86740a56073b | 148 | /**@brief Experimental function for specifying the public key to use for LESC operations. |
AnnaBridge | 143:86740a56073b | 149 | * |
AnnaBridge | 143:86740a56073b | 150 | * @details This function can be called multiple times. The specified public key will be used for |
AnnaBridge | 143:86740a56073b | 151 | * all subsequent LESC (LE Secure Connections) operations until the next time this function |
AnnaBridge | 143:86740a56073b | 152 | * is called. |
AnnaBridge | 143:86740a56073b | 153 | * |
AnnaBridge | 143:86740a56073b | 154 | * @note The key must continue to reside in application memory as it is not copied by Peer Manager. |
AnnaBridge | 143:86740a56073b | 155 | * |
AnnaBridge | 143:86740a56073b | 156 | * @param[in] p_public_key The public key to use for all subsequent LESC operations. |
AnnaBridge | 143:86740a56073b | 157 | * |
AnnaBridge | 143:86740a56073b | 158 | * @retval NRF_SUCCESS Pairing initiated successfully. |
AnnaBridge | 143:86740a56073b | 159 | * @retval NRF_ERROR_INVALID_STATE Peer Manager is not initialized. |
AnnaBridge | 143:86740a56073b | 160 | */ |
AnnaBridge | 143:86740a56073b | 161 | ret_code_t sm_lesc_public_key_set(ble_gap_lesc_p256_pk_t * p_public_key); |
AnnaBridge | 143:86740a56073b | 162 | |
AnnaBridge | 143:86740a56073b | 163 | |
AnnaBridge | 143:86740a56073b | 164 | /**@brief Function for providing pairing and bonding parameters to use for the current pairing |
AnnaBridge | 143:86740a56073b | 165 | * procedure on a connection. |
AnnaBridge | 143:86740a56073b | 166 | * |
AnnaBridge | 143:86740a56073b | 167 | * @warning This function is not yet implemented. |
AnnaBridge | 143:86740a56073b | 168 | * |
AnnaBridge | 143:86740a56073b | 169 | * @note If this function returns an @ref NRF_ERROR_NULL, @ref NRF_ERROR_INVALID_PARAM, @ref |
AnnaBridge | 143:86740a56073b | 170 | * BLE_ERROR_INVALID_CONN_HANDLE, or @ref NRF_ERROR_NO_MEM, this function can be called again |
AnnaBridge | 143:86740a56073b | 171 | * after corrective action. |
AnnaBridge | 143:86740a56073b | 172 | * |
AnnaBridge | 143:86740a56073b | 173 | * @note To reject a request, call this function with NULL p_sec_params. |
AnnaBridge | 143:86740a56073b | 174 | * |
AnnaBridge | 143:86740a56073b | 175 | * @param[in] conn_handle The connection handle of the connection the pairing is happening on. |
AnnaBridge | 143:86740a56073b | 176 | * @param[in] p_sec_params The security parameters to use for this link. |
AnnaBridge | 143:86740a56073b | 177 | * |
AnnaBridge | 143:86740a56073b | 178 | * @retval NRF_SUCCESS Success. |
AnnaBridge | 143:86740a56073b | 179 | * @retval NRF_ERROR_INVALID_STATE Module is not initialized, or no parameters have been |
AnnaBridge | 143:86740a56073b | 180 | * requested on that conn_handle, or this error originates |
AnnaBridge | 143:86740a56073b | 181 | * from the SoftDevice. |
AnnaBridge | 143:86740a56073b | 182 | * @retval NRF_ERROR_INVALID_PARAM Invalid combination of parameters (not including conn_handle). |
AnnaBridge | 143:86740a56073b | 183 | * @retval NRF_ERROR_TIMEOUT There has been an SMP timeout, so no more SMP operations |
AnnaBridge | 143:86740a56073b | 184 | * can be performed on this link. |
AnnaBridge | 143:86740a56073b | 185 | * @retval BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle. |
AnnaBridge | 143:86740a56073b | 186 | * @retval NRF_ERROR_NO_MEM No more room in flash. Fix and reattempt later. |
AnnaBridge | 143:86740a56073b | 187 | * @retval NRF_ERROR_BUSY No write buffer. Reattempt later. |
AnnaBridge | 143:86740a56073b | 188 | */ |
AnnaBridge | 143:86740a56073b | 189 | ret_code_t sm_sec_params_reply(uint16_t conn_handle, ble_gap_sec_params_t * p_sec_params); |
AnnaBridge | 143:86740a56073b | 190 | |
AnnaBridge | 143:86740a56073b | 191 | |
AnnaBridge | 143:86740a56073b | 192 | /**@brief Function for initiating security on the link, with the specified parameters. |
AnnaBridge | 143:86740a56073b | 193 | * |
AnnaBridge | 143:86740a56073b | 194 | * @note If the connection is a peripheral connection, this will send a security request to the |
AnnaBridge | 143:86740a56073b | 195 | * master, but the master is not obligated to initiate pairing or encryption in response. |
AnnaBridge | 143:86740a56073b | 196 | * @note If the connection is a central connection and a key is available, the parameters will be |
AnnaBridge | 143:86740a56073b | 197 | * used to determine whether to re-pair or to encrypt using the existing key. If no key is |
AnnaBridge | 143:86740a56073b | 198 | * available, pairing will be started. |
AnnaBridge | 143:86740a56073b | 199 | * |
AnnaBridge | 143:86740a56073b | 200 | * @param[in] conn_handle Handle of the connection to initiate pairing on. |
AnnaBridge | 143:86740a56073b | 201 | * @param[in] force_repairing Whether to force a pairing procedure to happen regardless of whether |
AnnaBridge | 143:86740a56073b | 202 | * an encryption key already exists. This argument is only relevant for |
AnnaBridge | 143:86740a56073b | 203 | * the central role. Recommended value: false |
AnnaBridge | 143:86740a56073b | 204 | * |
AnnaBridge | 143:86740a56073b | 205 | * @retval NRF_SUCCESS Success. |
AnnaBridge | 143:86740a56073b | 206 | * @retval NRF_ERROR_TIMEOUT There has been an SMP timeout, so no more SMP operations |
AnnaBridge | 143:86740a56073b | 207 | * can be performed on this link. |
AnnaBridge | 143:86740a56073b | 208 | * @retval BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle. |
AnnaBridge | 143:86740a56073b | 209 | * @retval NRF_ERROR_NOT_FOUND Security parameters have not been set. |
AnnaBridge | 143:86740a56073b | 210 | * @retval NRF_ERROR_INVALID_STATE Module is not initialized. |
AnnaBridge | 143:86740a56073b | 211 | * @retval NRF_ERROR_INTERNAL An unexpected error occurred. |
AnnaBridge | 143:86740a56073b | 212 | */ |
AnnaBridge | 143:86740a56073b | 213 | ret_code_t sm_link_secure(uint16_t conn_handle, bool force_repairing); |
AnnaBridge | 143:86740a56073b | 214 | |
AnnaBridge | 143:86740a56073b | 215 | /** @} |
AnnaBridge | 143:86740a56073b | 216 | * @endcond |
AnnaBridge | 143:86740a56073b | 217 | */ |
AnnaBridge | 143:86740a56073b | 218 | |
AnnaBridge | 143:86740a56073b | 219 | #endif /* SECURITY_MANAGER_H__ */ |