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