Pinned to some recent date

Committer:
Simon Cooksey
Date:
Thu Nov 17 16:43:53 2016 +0000
Revision:
0:fb7af294d5d9
Initial commit

Who changed what in which revision?

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