mbed-os

Dependents:   cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more

Committer:
be_bryan
Date:
Mon Dec 11 17:54:04 2017 +0000
Revision:
0:b74591d5ab33
motor ++

Who changed what in which revision?

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