fka mod
Fork of BLE_API by
ble/SecurityManager.h@1128:8b07ab5a696d, 2016-01-12 (annotated)
- Committer:
- vcoubard
- Date:
- Tue Jan 12 19:47:51 2016 +0000
- Revision:
- 1128:8b07ab5a696d
- Parent:
- 1127:0f8fed8cda0d
- Child:
- 1129:85ee56c4f469
Synchronized with git rev 17e37360
Author: Vincent Coubard
Merge pull request #161 from ARMmbed/develop
merge branch develop (v2.4.0)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vcoubard | 1126:08db6549adef | 1 | /* mbed Microcontroller Library |
vcoubard | 1126:08db6549adef | 2 | * Copyright (c) 2006-2015 ARM Limited |
vcoubard | 1126:08db6549adef | 3 | * |
vcoubard | 1126:08db6549adef | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
vcoubard | 1126:08db6549adef | 5 | * you may not use this file except in compliance with the License. |
vcoubard | 1126:08db6549adef | 6 | * You may obtain a copy of the License at |
vcoubard | 1126:08db6549adef | 7 | * |
vcoubard | 1126:08db6549adef | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
vcoubard | 1126:08db6549adef | 9 | * |
vcoubard | 1126:08db6549adef | 10 | * Unless required by applicable law or agreed to in writing, software |
vcoubard | 1126:08db6549adef | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
vcoubard | 1126:08db6549adef | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
vcoubard | 1126:08db6549adef | 13 | * See the License for the specific language governing permissions and |
vcoubard | 1126:08db6549adef | 14 | * limitations under the License. |
vcoubard | 1126:08db6549adef | 15 | */ |
vcoubard | 1126:08db6549adef | 16 | |
vcoubard | 1126:08db6549adef | 17 | #ifndef __SECURITY_MANAGER_H__ |
vcoubard | 1126:08db6549adef | 18 | #define __SECURITY_MANAGER_H__ |
vcoubard | 1126:08db6549adef | 19 | |
vcoubard | 1126:08db6549adef | 20 | #include <stdint.h> |
vcoubard | 1126:08db6549adef | 21 | |
vcoubard | 1126:08db6549adef | 22 | #include "Gap.h" |
vcoubard | 1126:08db6549adef | 23 | #include "CallChainOfFunctionPointersWithContext.h" |
vcoubard | 1126:08db6549adef | 24 | |
vcoubard | 1126:08db6549adef | 25 | class SecurityManager { |
vcoubard | 1126:08db6549adef | 26 | public: |
vcoubard | 1126:08db6549adef | 27 | enum SecurityMode_t { |
vcoubard | 1126:08db6549adef | 28 | SECURITY_MODE_NO_ACCESS, |
vcoubard | 1126:08db6549adef | 29 | SECURITY_MODE_ENCRYPTION_OPEN_LINK, /**< Require no protection, open link. */ |
vcoubard | 1126:08db6549adef | 30 | SECURITY_MODE_ENCRYPTION_NO_MITM, /**< Require encryption, but no MITM protection. */ |
vcoubard | 1126:08db6549adef | 31 | SECURITY_MODE_ENCRYPTION_WITH_MITM, /**< Require encryption and MITM protection. */ |
vcoubard | 1126:08db6549adef | 32 | SECURITY_MODE_SIGNED_NO_MITM, /**< Require signing or encryption, but no MITM protection. */ |
vcoubard | 1126:08db6549adef | 33 | SECURITY_MODE_SIGNED_WITH_MITM, /**< Require signing or encryption, and MITM protection. */ |
vcoubard | 1126:08db6549adef | 34 | }; |
vcoubard | 1126:08db6549adef | 35 | |
vcoubard | 1126:08db6549adef | 36 | /** |
vcoubard | 1126:08db6549adef | 37 | * @brief Defines possible security status or states. |
vcoubard | 1126:08db6549adef | 38 | * |
vcoubard | 1126:08db6549adef | 39 | * @details Defines possible security status or states of a link when requested by getLinkSecurity(). |
vcoubard | 1126:08db6549adef | 40 | */ |
vcoubard | 1126:08db6549adef | 41 | enum LinkSecurityStatus_t { |
vcoubard | 1126:08db6549adef | 42 | NOT_ENCRYPTED, /**< The link is not secured. */ |
vcoubard | 1126:08db6549adef | 43 | ENCRYPTION_IN_PROGRESS, /**< Link security is being established.*/ |
vcoubard | 1126:08db6549adef | 44 | ENCRYPTED /**< The link is secure.*/ |
vcoubard | 1126:08db6549adef | 45 | }; |
vcoubard | 1126:08db6549adef | 46 | |
vcoubard | 1126:08db6549adef | 47 | enum SecurityIOCapabilities_t { |
vcoubard | 1126:08db6549adef | 48 | IO_CAPS_DISPLAY_ONLY = 0x00, /**< Display only. */ |
vcoubard | 1126:08db6549adef | 49 | IO_CAPS_DISPLAY_YESNO = 0x01, /**< Display and yes/no entry. */ |
vcoubard | 1126:08db6549adef | 50 | IO_CAPS_KEYBOARD_ONLY = 0x02, /**< Keyboard only. */ |
vcoubard | 1126:08db6549adef | 51 | IO_CAPS_NONE = 0x03, /**< No I/O capabilities. */ |
vcoubard | 1126:08db6549adef | 52 | IO_CAPS_KEYBOARD_DISPLAY = 0x04, /**< Keyboard and display. */ |
vcoubard | 1126:08db6549adef | 53 | }; |
vcoubard | 1126:08db6549adef | 54 | |
vcoubard | 1126:08db6549adef | 55 | enum SecurityCompletionStatus_t { |
vcoubard | 1126:08db6549adef | 56 | SEC_STATUS_SUCCESS = 0x00, /**< Procedure completed with success. */ |
vcoubard | 1126:08db6549adef | 57 | SEC_STATUS_TIMEOUT = 0x01, /**< Procedure timed out. */ |
vcoubard | 1126:08db6549adef | 58 | SEC_STATUS_PDU_INVALID = 0x02, /**< Invalid PDU received. */ |
vcoubard | 1126:08db6549adef | 59 | SEC_STATUS_PASSKEY_ENTRY_FAILED = 0x81, /**< Passkey entry failed (user canceled or other). */ |
vcoubard | 1126:08db6549adef | 60 | SEC_STATUS_OOB_NOT_AVAILABLE = 0x82, /**< Out of Band Key not available. */ |
vcoubard | 1126:08db6549adef | 61 | SEC_STATUS_AUTH_REQ = 0x83, /**< Authentication requirements not met. */ |
vcoubard | 1126:08db6549adef | 62 | SEC_STATUS_CONFIRM_VALUE = 0x84, /**< Confirm value failed. */ |
vcoubard | 1126:08db6549adef | 63 | SEC_STATUS_PAIRING_NOT_SUPP = 0x85, /**< Pairing not supported. */ |
vcoubard | 1126:08db6549adef | 64 | SEC_STATUS_ENC_KEY_SIZE = 0x86, /**< Encryption key size. */ |
vcoubard | 1126:08db6549adef | 65 | SEC_STATUS_SMP_CMD_UNSUPPORTED = 0x87, /**< Unsupported SMP command. */ |
vcoubard | 1126:08db6549adef | 66 | SEC_STATUS_UNSPECIFIED = 0x88, /**< Unspecified reason. */ |
vcoubard | 1126:08db6549adef | 67 | SEC_STATUS_REPEATED_ATTEMPTS = 0x89, /**< Too little time elapsed since last attempt. */ |
vcoubard | 1126:08db6549adef | 68 | SEC_STATUS_INVALID_PARAMS = 0x8A, /**< Invalid parameters. */ |
vcoubard | 1126:08db6549adef | 69 | }; |
vcoubard | 1126:08db6549adef | 70 | |
vcoubard | 1126:08db6549adef | 71 | /** |
vcoubard | 1126:08db6549adef | 72 | * Declaration of type containing a passkey to be used during pairing. This |
vcoubard | 1126:08db6549adef | 73 | * is passed into initializeSecurity() to specify a pre-programmed passkey |
vcoubard | 1126:08db6549adef | 74 | * for authentication instead of generating a random one. |
vcoubard | 1126:08db6549adef | 75 | */ |
vcoubard | 1126:08db6549adef | 76 | static const unsigned PASSKEY_LEN = 6; |
vcoubard | 1126:08db6549adef | 77 | typedef uint8_t Passkey_t[PASSKEY_LEN]; /**< 6-digit passkey in ASCII ('0'-'9' digits only). */ |
vcoubard | 1126:08db6549adef | 78 | |
vcoubard | 1126:08db6549adef | 79 | public: |
vcoubard | 1126:08db6549adef | 80 | typedef void (*HandleSpecificEvent_t)(Gap::Handle_t handle); |
vcoubard | 1126:08db6549adef | 81 | typedef void (*SecuritySetupInitiatedCallback_t)(Gap::Handle_t, bool allowBonding, bool requireMITM, SecurityIOCapabilities_t iocaps); |
vcoubard | 1126:08db6549adef | 82 | typedef void (*SecuritySetupCompletedCallback_t)(Gap::Handle_t, SecurityCompletionStatus_t status); |
vcoubard | 1126:08db6549adef | 83 | typedef void (*LinkSecuredCallback_t)(Gap::Handle_t handle, SecurityMode_t securityMode); |
vcoubard | 1126:08db6549adef | 84 | typedef void (*PasskeyDisplayCallback_t)(Gap::Handle_t handle, const Passkey_t passkey); |
vcoubard | 1126:08db6549adef | 85 | |
vcoubard | 1126:08db6549adef | 86 | typedef FunctionPointerWithContext<const SecurityManager *> SecurityManagerShutdownCallback_t; |
vcoubard | 1126:08db6549adef | 87 | typedef CallChainOfFunctionPointersWithContext<const SecurityManager *> SecurityManagerShutdownCallbackChain_t; |
vcoubard | 1126:08db6549adef | 88 | |
vcoubard | 1126:08db6549adef | 89 | /* |
vcoubard | 1126:08db6549adef | 90 | * The following functions are meant to be overridden in the platform-specific sub-class. |
vcoubard | 1126:08db6549adef | 91 | */ |
vcoubard | 1126:08db6549adef | 92 | public: |
vcoubard | 1126:08db6549adef | 93 | /** |
vcoubard | 1126:08db6549adef | 94 | * Enable the BLE stack's Security Manager. The Security Manager implements |
vcoubard | 1126:08db6549adef | 95 | * the actual cryptographic algorithms and protocol exchanges that allow two |
vcoubard | 1126:08db6549adef | 96 | * devices to securely exchange data and privately detect each other. |
vcoubard | 1126:08db6549adef | 97 | * Calling this API is a prerequisite for encryption and pairing (bonding). |
vcoubard | 1126:08db6549adef | 98 | * |
vcoubard | 1126:08db6549adef | 99 | * @param[in] enableBonding Allow for bonding. |
vcoubard | 1126:08db6549adef | 100 | * @param[in] requireMITM Require protection for man-in-the-middle attacks. |
vcoubard | 1126:08db6549adef | 101 | * @param[in] iocaps To specify the I/O capabilities of this peripheral, |
vcoubard | 1126:08db6549adef | 102 | * such as availability of a display or keyboard, to |
vcoubard | 1126:08db6549adef | 103 | * support out-of-band exchanges of security data. |
vcoubard | 1126:08db6549adef | 104 | * @param[in] passkey To specify a static passkey. |
vcoubard | 1126:08db6549adef | 105 | * |
vcoubard | 1126:08db6549adef | 106 | * @return BLE_ERROR_NONE on success. |
vcoubard | 1126:08db6549adef | 107 | */ |
vcoubard | 1126:08db6549adef | 108 | virtual ble_error_t init(bool enableBonding = true, |
vcoubard | 1126:08db6549adef | 109 | bool requireMITM = true, |
vcoubard | 1126:08db6549adef | 110 | SecurityIOCapabilities_t iocaps = IO_CAPS_NONE, |
vcoubard | 1126:08db6549adef | 111 | const Passkey_t passkey = NULL) { |
vcoubard | 1126:08db6549adef | 112 | /* Avoid compiler warnings about unused variables. */ |
vcoubard | 1126:08db6549adef | 113 | (void)enableBonding; |
vcoubard | 1126:08db6549adef | 114 | (void)requireMITM; |
vcoubard | 1126:08db6549adef | 115 | (void)iocaps; |
vcoubard | 1126:08db6549adef | 116 | (void)passkey; |
vcoubard | 1126:08db6549adef | 117 | |
vcoubard | 1126:08db6549adef | 118 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if security is supported. */ |
vcoubard | 1126:08db6549adef | 119 | } |
vcoubard | 1126:08db6549adef | 120 | |
vcoubard | 1126:08db6549adef | 121 | /** |
vcoubard | 1126:08db6549adef | 122 | * Get the security status of a connection. |
vcoubard | 1126:08db6549adef | 123 | * |
vcoubard | 1126:08db6549adef | 124 | * @param[in] connectionHandle Handle to identify the connection. |
vcoubard | 1126:08db6549adef | 125 | * @param[out] securityStatusP Security status. |
vcoubard | 1126:08db6549adef | 126 | * |
vcoubard | 1126:08db6549adef | 127 | * @return BLE_ERROR_NONE or appropriate error code indicating the failure reason. |
vcoubard | 1126:08db6549adef | 128 | */ |
vcoubard | 1126:08db6549adef | 129 | virtual ble_error_t getLinkSecurity(Gap::Handle_t connectionHandle, LinkSecurityStatus_t *securityStatusP) { |
vcoubard | 1126:08db6549adef | 130 | /* Avoid compiler warnings about unused variables. */ |
vcoubard | 1126:08db6549adef | 131 | (void)connectionHandle; |
vcoubard | 1126:08db6549adef | 132 | (void)securityStatusP; |
vcoubard | 1126:08db6549adef | 133 | |
vcoubard | 1126:08db6549adef | 134 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if security is supported. */ |
vcoubard | 1126:08db6549adef | 135 | } |
vcoubard | 1126:08db6549adef | 136 | |
vcoubard | 1126:08db6549adef | 137 | /** |
vcoubard | 1126:08db6549adef | 138 | * Set the security mode on a connection. Useful for elevating the security mode |
vcoubard | 1126:08db6549adef | 139 | * once certain conditions are met, e.g., a particular service is found. |
vcoubard | 1126:08db6549adef | 140 | * |
vcoubard | 1126:08db6549adef | 141 | * @param[in] connectionHandle Handle to identify the connection. |
vcoubard | 1126:08db6549adef | 142 | * @param[in] securityMode Requested security mode. |
vcoubard | 1126:08db6549adef | 143 | * |
vcoubard | 1126:08db6549adef | 144 | * @return BLE_ERROR_NONE or appropriate error code indicating the failure reason. |
vcoubard | 1126:08db6549adef | 145 | */ |
vcoubard | 1126:08db6549adef | 146 | virtual ble_error_t setLinkSecurity(Gap::Handle_t connectionHandle, SecurityMode_t securityMode) { |
vcoubard | 1126:08db6549adef | 147 | /* Avoid compiler warnings about unused variables. */ |
vcoubard | 1126:08db6549adef | 148 | (void)connectionHandle; |
vcoubard | 1126:08db6549adef | 149 | (void)securityMode; |
vcoubard | 1126:08db6549adef | 150 | |
vcoubard | 1126:08db6549adef | 151 | return BLE_ERROR_NOT_IMPLEMENTED; |
vcoubard | 1126:08db6549adef | 152 | } |
vcoubard | 1126:08db6549adef | 153 | |
vcoubard | 1126:08db6549adef | 154 | /** |
vcoubard | 1126:08db6549adef | 155 | * Delete all peer device context and all related bonding information from |
vcoubard | 1126:08db6549adef | 156 | * the database within the security manager. |
vcoubard | 1126:08db6549adef | 157 | * |
vcoubard | 1126:08db6549adef | 158 | * @retval BLE_ERROR_NONE On success, else an error code indicating reason for failure. |
vcoubard | 1126:08db6549adef | 159 | * @retval BLE_ERROR_INVALID_STATE If the API is called without module initialization or |
vcoubard | 1126:08db6549adef | 160 | * application registration. |
vcoubard | 1126:08db6549adef | 161 | */ |
vcoubard | 1126:08db6549adef | 162 | virtual ble_error_t purgeAllBondingState(void) { |
vcoubard | 1126:08db6549adef | 163 | return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if security is supported. */ |
vcoubard | 1126:08db6549adef | 164 | } |
vcoubard | 1126:08db6549adef | 165 | |
vcoubard | 1126:08db6549adef | 166 | /* Event callback handlers. */ |
vcoubard | 1126:08db6549adef | 167 | public: |
vcoubard | 1126:08db6549adef | 168 | /** |
vcoubard | 1126:08db6549adef | 169 | * Setup a callback to be invoked to notify the user application that the |
vcoubard | 1126:08db6549adef | 170 | * SecurityManager instance is about to shutdown (possibly as a result of a call |
vcoubard | 1126:08db6549adef | 171 | * to BLE::shutdown()). |
vcoubard | 1126:08db6549adef | 172 | * |
vcoubard | 1126:08db6549adef | 173 | * @Note: It is possible to chain together multiple onShutdown callbacks |
vcoubard | 1126:08db6549adef | 174 | * (potentially from different modules of an application) to be notified |
vcoubard | 1126:08db6549adef | 175 | * before the SecurityManager is shutdown. |
vcoubard | 1126:08db6549adef | 176 | * |
vcoubard | 1126:08db6549adef | 177 | * @Note: It is also possible to set up a callback into a member function of |
vcoubard | 1126:08db6549adef | 178 | * some object. |
vcoubard | 1126:08db6549adef | 179 | * |
vcoubard | 1126:08db6549adef | 180 | * @Note It is possible to unregister a callback using onShutdown().detach(callback) |
vcoubard | 1126:08db6549adef | 181 | */ |
vcoubard | 1126:08db6549adef | 182 | void onShutdown(const SecurityManagerShutdownCallback_t& callback) { |
vcoubard | 1126:08db6549adef | 183 | shutdownCallChain.add(callback); |
vcoubard | 1126:08db6549adef | 184 | } |
vcoubard | 1126:08db6549adef | 185 | template <typename T> |
vcoubard | 1126:08db6549adef | 186 | void onShutdown(T *objPtr, void (T::*memberPtr)(void)) { |
vcoubard | 1126:08db6549adef | 187 | shutdownCallChain.add(objPtr, memberPtr); |
vcoubard | 1126:08db6549adef | 188 | } |
vcoubard | 1126:08db6549adef | 189 | |
vcoubard | 1126:08db6549adef | 190 | /** |
vcoubard | 1126:08db6549adef | 191 | * @brief provide access to the callchain of shutdown event callbacks |
vcoubard | 1126:08db6549adef | 192 | * It is possible to register callbacks using onShutdown().add(callback); |
vcoubard | 1126:08db6549adef | 193 | * It is possible to unregister callbacks using onShutdown().detach(callback) |
vcoubard | 1126:08db6549adef | 194 | * @return The shutdown event callbacks chain |
vcoubard | 1126:08db6549adef | 195 | */ |
vcoubard | 1126:08db6549adef | 196 | SecurityManagerShutdownCallbackChain_t& onShutdown() { |
vcoubard | 1126:08db6549adef | 197 | return shutdownCallChain; |
vcoubard | 1126:08db6549adef | 198 | } |
vcoubard | 1126:08db6549adef | 199 | |
vcoubard | 1126:08db6549adef | 200 | /** |
vcoubard | 1126:08db6549adef | 201 | * To indicate that a security procedure for the link has started. |
vcoubard | 1126:08db6549adef | 202 | */ |
vcoubard | 1126:08db6549adef | 203 | virtual void onSecuritySetupInitiated(SecuritySetupInitiatedCallback_t callback) {securitySetupInitiatedCallback = callback;} |
vcoubard | 1126:08db6549adef | 204 | |
vcoubard | 1126:08db6549adef | 205 | /** |
vcoubard | 1126:08db6549adef | 206 | * To indicate that the security procedure for the link has completed. |
vcoubard | 1126:08db6549adef | 207 | */ |
vcoubard | 1126:08db6549adef | 208 | virtual void onSecuritySetupCompleted(SecuritySetupCompletedCallback_t callback) {securitySetupCompletedCallback = callback;} |
vcoubard | 1126:08db6549adef | 209 | |
vcoubard | 1126:08db6549adef | 210 | /** |
vcoubard | 1126:08db6549adef | 211 | * To indicate that the link with the peer is secured. For bonded devices, |
vcoubard | 1126:08db6549adef | 212 | * subsequent reconnections with a bonded peer will result only in this callback |
vcoubard | 1126:08db6549adef | 213 | * when the link is secured; setup procedures will not occur (unless the |
vcoubard | 1126:08db6549adef | 214 | * bonding information is either lost or deleted on either or both sides). |
vcoubard | 1126:08db6549adef | 215 | */ |
vcoubard | 1126:08db6549adef | 216 | virtual void onLinkSecured(LinkSecuredCallback_t callback) {linkSecuredCallback = callback;} |
vcoubard | 1126:08db6549adef | 217 | |
vcoubard | 1126:08db6549adef | 218 | /** |
vcoubard | 1126:08db6549adef | 219 | * To indicate that device context is stored persistently. |
vcoubard | 1126:08db6549adef | 220 | */ |
vcoubard | 1126:08db6549adef | 221 | virtual void onSecurityContextStored(HandleSpecificEvent_t callback) {securityContextStoredCallback = callback;} |
vcoubard | 1126:08db6549adef | 222 | |
vcoubard | 1126:08db6549adef | 223 | /** |
vcoubard | 1126:08db6549adef | 224 | * To set the callback for when the passkey needs to be displayed on a peripheral with DISPLAY capability. |
vcoubard | 1126:08db6549adef | 225 | */ |
vcoubard | 1126:08db6549adef | 226 | virtual void onPasskeyDisplay(PasskeyDisplayCallback_t callback) {passkeyDisplayCallback = callback;} |
vcoubard | 1126:08db6549adef | 227 | |
vcoubard | 1126:08db6549adef | 228 | /* Entry points for the underlying stack to report events back to the user. */ |
vcoubard | 1126:08db6549adef | 229 | public: |
vcoubard | 1126:08db6549adef | 230 | void processSecuritySetupInitiatedEvent(Gap::Handle_t handle, bool allowBonding, bool requireMITM, SecurityIOCapabilities_t iocaps) { |
vcoubard | 1126:08db6549adef | 231 | if (securitySetupInitiatedCallback) { |
vcoubard | 1126:08db6549adef | 232 | securitySetupInitiatedCallback(handle, allowBonding, requireMITM, iocaps); |
vcoubard | 1126:08db6549adef | 233 | } |
vcoubard | 1126:08db6549adef | 234 | } |
vcoubard | 1126:08db6549adef | 235 | |
vcoubard | 1126:08db6549adef | 236 | void processSecuritySetupCompletedEvent(Gap::Handle_t handle, SecurityCompletionStatus_t status) { |
vcoubard | 1126:08db6549adef | 237 | if (securitySetupCompletedCallback) { |
vcoubard | 1126:08db6549adef | 238 | securitySetupCompletedCallback(handle, status); |
vcoubard | 1126:08db6549adef | 239 | } |
vcoubard | 1126:08db6549adef | 240 | } |
vcoubard | 1126:08db6549adef | 241 | |
vcoubard | 1126:08db6549adef | 242 | void processLinkSecuredEvent(Gap::Handle_t handle, SecurityMode_t securityMode) { |
vcoubard | 1126:08db6549adef | 243 | if (linkSecuredCallback) { |
vcoubard | 1126:08db6549adef | 244 | linkSecuredCallback(handle, securityMode); |
vcoubard | 1126:08db6549adef | 245 | } |
vcoubard | 1126:08db6549adef | 246 | } |
vcoubard | 1126:08db6549adef | 247 | |
vcoubard | 1126:08db6549adef | 248 | void processSecurityContextStoredEvent(Gap::Handle_t handle) { |
vcoubard | 1126:08db6549adef | 249 | if (securityContextStoredCallback) { |
vcoubard | 1126:08db6549adef | 250 | securityContextStoredCallback(handle); |
vcoubard | 1126:08db6549adef | 251 | } |
vcoubard | 1126:08db6549adef | 252 | } |
vcoubard | 1126:08db6549adef | 253 | |
vcoubard | 1126:08db6549adef | 254 | void processPasskeyDisplayEvent(Gap::Handle_t handle, const Passkey_t passkey) { |
vcoubard | 1126:08db6549adef | 255 | if (passkeyDisplayCallback) { |
vcoubard | 1126:08db6549adef | 256 | passkeyDisplayCallback(handle, passkey); |
vcoubard | 1126:08db6549adef | 257 | } |
vcoubard | 1126:08db6549adef | 258 | } |
vcoubard | 1126:08db6549adef | 259 | |
vcoubard | 1126:08db6549adef | 260 | protected: |
vcoubard | 1126:08db6549adef | 261 | SecurityManager() : |
vcoubard | 1126:08db6549adef | 262 | securitySetupInitiatedCallback(), |
vcoubard | 1126:08db6549adef | 263 | securitySetupCompletedCallback(), |
vcoubard | 1126:08db6549adef | 264 | linkSecuredCallback(), |
vcoubard | 1126:08db6549adef | 265 | securityContextStoredCallback(), |
vcoubard | 1126:08db6549adef | 266 | passkeyDisplayCallback() { |
vcoubard | 1126:08db6549adef | 267 | /* empty */ |
vcoubard | 1126:08db6549adef | 268 | } |
vcoubard | 1126:08db6549adef | 269 | |
vcoubard | 1126:08db6549adef | 270 | public: |
vcoubard | 1126:08db6549adef | 271 | /** |
vcoubard | 1126:08db6549adef | 272 | * Notify all registered onShutdown callbacks that the SecurityManager is |
vcoubard | 1126:08db6549adef | 273 | * about to be shutdown and clear all SecurityManager state of the |
vcoubard | 1126:08db6549adef | 274 | * associated object. |
vcoubard | 1126:08db6549adef | 275 | * |
vcoubard | 1126:08db6549adef | 276 | * This function is meant to be overridden in the platform-specific |
vcoubard | 1126:08db6549adef | 277 | * sub-class. Nevertheless, the sub-class is only expected to reset its |
vcoubard | 1126:08db6549adef | 278 | * state and not the data held in SecurityManager members. This shall be |
vcoubard | 1126:08db6549adef | 279 | * achieved by a call to SecurityManager::reset() from the sub-class' |
vcoubard | 1126:08db6549adef | 280 | * reset() implementation. |
vcoubard | 1126:08db6549adef | 281 | * |
vcoubard | 1126:08db6549adef | 282 | * @return BLE_ERROR_NONE on success. |
vcoubard | 1126:08db6549adef | 283 | */ |
vcoubard | 1126:08db6549adef | 284 | virtual ble_error_t reset(void) { |
vcoubard | 1126:08db6549adef | 285 | /* Notify that the instance is about to shutdown */ |
vcoubard | 1126:08db6549adef | 286 | shutdownCallChain.call(this); |
vcoubard | 1126:08db6549adef | 287 | shutdownCallChain.clear(); |
vcoubard | 1126:08db6549adef | 288 | |
vcoubard | 1126:08db6549adef | 289 | securitySetupInitiatedCallback = NULL; |
vcoubard | 1126:08db6549adef | 290 | securitySetupCompletedCallback = NULL; |
vcoubard | 1126:08db6549adef | 291 | linkSecuredCallback = NULL; |
vcoubard | 1126:08db6549adef | 292 | securityContextStoredCallback = NULL; |
vcoubard | 1126:08db6549adef | 293 | passkeyDisplayCallback = NULL; |
vcoubard | 1126:08db6549adef | 294 | |
vcoubard | 1126:08db6549adef | 295 | return BLE_ERROR_NONE; |
vcoubard | 1126:08db6549adef | 296 | } |
vcoubard | 1126:08db6549adef | 297 | |
vcoubard | 1126:08db6549adef | 298 | protected: |
vcoubard | 1126:08db6549adef | 299 | SecuritySetupInitiatedCallback_t securitySetupInitiatedCallback; |
vcoubard | 1126:08db6549adef | 300 | SecuritySetupCompletedCallback_t securitySetupCompletedCallback; |
vcoubard | 1126:08db6549adef | 301 | LinkSecuredCallback_t linkSecuredCallback; |
vcoubard | 1126:08db6549adef | 302 | HandleSpecificEvent_t securityContextStoredCallback; |
vcoubard | 1126:08db6549adef | 303 | PasskeyDisplayCallback_t passkeyDisplayCallback; |
vcoubard | 1126:08db6549adef | 304 | |
vcoubard | 1126:08db6549adef | 305 | private: |
vcoubard | 1126:08db6549adef | 306 | SecurityManagerShutdownCallbackChain_t shutdownCallChain; |
vcoubard | 1126:08db6549adef | 307 | }; |
vcoubard | 1126:08db6549adef | 308 | |
rgrover1 | 716:11b41f651697 | 309 | #endif /*__SECURITY_MANAGER_H__*/ |