Includes library modifications to allow access to AIN_4 (AIN_0 / 5)

Committer:
bryantaylor
Date:
Tue Sep 20 21:26:12 2016 +0000
Revision:
0:eafc3fd41f75
hackathon

Who changed what in which revision?

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