17 #ifndef SECURITY_MANAGER_H_    18 #define SECURITY_MANAGER_H_    22 #include "ble/common/StaticInterface.h"    23 #include "ble/blecommon.h"    24 #include "ble/BLETypes.h"    26 #include "CallChainOfFunctionPointersWithContext.h"    27 #include "BleImplementationForward.h"    29 #if !defined(DOXYGEN_ONLY)   187 #if !defined(DOXYGEN_ONLY)   188 template <
class Impl>
   189 class SecurityManager : 
public StaticInterface<Impl, SecurityManager> {
   208         SECURITY_MODE_NO_ACCESS,
   229         IO_CAPS_DISPLAY_ONLY = 0x00,     
   230         IO_CAPS_DISPLAY_YESNO = 0x01,    
   231         IO_CAPS_KEYBOARD_ONLY = 0x02,    
   233         IO_CAPS_KEYBOARD_DISPLAY = 0x04, 
   238         SEC_STATUS_SUCCESS              = 0x00,  
   239         SEC_STATUS_TIMEOUT              = 0x01,  
   240         SEC_STATUS_PDU_INVALID          = 0x02,  
   241         SEC_STATUS_PASSKEY_ENTRY_FAILED = 0x81,  
   242         SEC_STATUS_OOB_NOT_AVAILABLE    = 0x82,  
   243         SEC_STATUS_AUTH_REQ             = 0x83,  
   244         SEC_STATUS_CONFIRM_VALUE        = 0x84,  
   245         SEC_STATUS_PAIRING_NOT_SUPP     = 0x85,  
   246         SEC_STATUS_ENC_KEY_SIZE         = 0x86,  
   247         SEC_STATUS_SMP_CMD_UNSUPPORTED  = 0x87,  
   248         SEC_STATUS_UNSPECIFIED          = 0x88,  
   249         SEC_STATUS_REPEATED_ATTEMPTS    = 0x89,  
   250         SEC_STATUS_INVALID_PARAMS       = 0x8A,  
   251         SEC_STATUS_DHKEY_CHECK_FAILED   = 0x8B,  
   252         SEC_STATUS_COMPARISON_FAILED    = 0x8C,  
   260     static const unsigned PASSKEY_LEN = 6;
   261     typedef uint8_t Passkey_t[PASSKEY_LEN]; 
   270     typedef void (*LinkSecuredCallback_t)(ble::connection_handle_t connectionHandle, 
SecurityMode_t securityMode);
   271     typedef void (*PasskeyDisplayCallback_t)(ble::connection_handle_t connectionHandle, 
const Passkey_t passkey);
   292             (void)connectionHandle;
   302             (void)connectionHandle;
   330             (void)connectionHandle;
   345             (void)connectionHandle;
   359             (void)connectionHandle;
   369             (void)connectionHandle;
   379             (void)connectionHandle;
   389             (void)connectionHandle;
   432             (void)connectionHandle;
   466         bool                     enableBonding = 
true,
   467         bool                     requireMITM   = 
true,
   469         const Passkey_t          passkey       = NULL,
   471         const char              *dbFilepath    = NULL
   485     ble_error_t setDatabaseFilepath(
const char *dbFilepath = NULL);
   509     ble_error_t preserveBondingStateOnReset(
bool enable);
   550     ble_error_t requestPairing(ble::connection_handle_t connectionHandle);
   559     ble_error_t acceptPairingRequest(ble::connection_handle_t connectionHandle);
   568     ble_error_t cancelPairingRequest(ble::connection_handle_t connectionHandle);
   580     ble_error_t setPairingRequestAuthorisation(
bool required = 
true);
   602     ble_error_t getSecureConnectionsSupport(
bool *enabled);
   623     ble_error_t setDisplayPasskey(
const Passkey_t passkey);
   645     ble_error_t setKeypressNotification(
bool enabled = 
true);
   647 #if BLE_FEATURE_SIGNING   658     ble_error_t enableSigning(ble::connection_handle_t connectionHandle, 
bool enabled = 
true);
   659 #endif // BLE_FEATURE_SIGNING   668     ble_error_t setHintFutureRoleReversal(
bool enable = 
true);
   701     ble_error_t setEncryptionKeyRequirements(uint8_t minimumByteSize, uint8_t maximumByteSize);
   714     ble_error_t requestAuthentication(ble::connection_handle_t connectionHandle);
   760     ble_error_t setOOBDataUsage(ble::connection_handle_t connectionHandle, 
bool useOOB, 
bool OOBProvidesMITM = 
true);
   769     ble_error_t confirmationEntered(ble::connection_handle_t connectionHandle, 
bool confirmation);
   778     ble_error_t passkeyEntered(ble::connection_handle_t connectionHandle, Passkey_t passkey);
   788     ble_error_t sendKeypressNotification(ble::connection_handle_t connectionHandle, 
Keypress_t keypress);
   825     ble_error_t getSigningKey(ble::connection_handle_t connectionHandle, 
bool authenticated);
   844         shutdownCallChain.add(callback);
   846     template <
typename T>
   847     void onShutdown(T *objPtr, 
void (T::*memberPtr)(
const SecurityManager *)) {
   848         shutdownCallChain.add(objPtr, memberPtr);
   859         return shutdownCallChain;
   870             eventHandler = handler;
   872             eventHandler = &defaultEventHandler;
   878         eventHandler = &defaultEventHandler;
   913         ble_error_t err = getLinkEncryption(connectionHandle, &encryption);
   918         switch (encryption.
value()) {
   920                 *securityStatus = NOT_ENCRYPTED;
   923                 *securityStatus = ENCRYPTION_IN_PROGRESS;
   928                 *securityStatus = ENCRYPTED;
   933                 *securityStatus = NOT_ENCRYPTED;
   946         defaultEventHandler.securitySetupInitiatedCallback = 
callback;
   955         defaultEventHandler.securitySetupCompletedCallback = 
callback;
   967         defaultEventHandler.linkSecuredCallback = 
callback;
   976         defaultEventHandler.securityContextStoredCallback = 
callback;
   984         defaultEventHandler.passkeyDisplayCallback = 
callback;
   991         if (defaultEventHandler.securitySetupInitiatedCallback) {
   992             defaultEventHandler.securitySetupInitiatedCallback(connectionHandle, allowBonding, requireMITM, iocaps);
   997         eventHandler->pairingResult(connectionHandle, status);
  1001         if (securityMode == SECURITY_MODE_ENCRYPTION_NO_MITM) {
  1009         if (defaultEventHandler.securityContextStoredCallback) {
  1010             defaultEventHandler.securityContextStoredCallback(connectionHandle);
  1015         eventHandler->passkeyDisplay(connectionHandle, passkey);
  1028         const Passkey_t passkey,
  1030         const char *dbFilepath
  1033     ble_error_t setDatabaseFilepath_(
const char *dbFilepath);
  1035     ble_error_t preserveBondingStateOnReset_(
bool enable);
  1044         ble::connection_handle_t connectionHandle
  1048         ble::connection_handle_t connectionHandle
  1052         ble::connection_handle_t connectionHandle
  1061     ble_error_t getSecureConnectionsSupport_(
bool *enabled);
  1065     ble_error_t setDisplayPasskey_(
const Passkey_t passkey);
  1068         ble::connection_handle_t connectionHandle,
  1072     ble_error_t setKeypressNotification_(
bool enabled);
  1075         ble::connection_handle_t connectionHandle,
  1079     ble_error_t setHintFutureRoleReversal_(
bool enable);
  1082         ble::connection_handle_t connectionHandle,
  1087         ble::connection_handle_t connectionHandle,
  1092         uint8_t minimumByteSize,
  1093         uint8_t maximumByteSize
  1097         ble::connection_handle_t connectionHandle
  1103         ble::connection_handle_t connectionHandle,
  1105         bool OOBProvidesMITM
  1109         ble::connection_handle_t connectionHandle,
  1114         ble::connection_handle_t connectionHandle,
  1119         ble::connection_handle_t connectionHandle,
  1135         ble::connection_handle_t connectionHandle,
  1146         LegacyEventHandler() :
  1147             securitySetupInitiatedCallback(),
  1148             securitySetupCompletedCallback(),
  1149             linkSecuredCallback(),
  1150             securityContextStoredCallback(),
  1151             passkeyDisplayCallback() { };
  1154             if (securitySetupCompletedCallback) {
  1155                 securitySetupCompletedCallback(connectionHandle, result);
  1159         virtual void linkEncryptionResult(ble::connection_handle_t connectionHandle, 
ble::link_encryption_t result) {
  1160             if (linkSecuredCallback) {
  1163                     securityMode = SECURITY_MODE_ENCRYPTION_NO_MITM;
  1168                     securityMode = SECURITY_MODE_ENCRYPTION_WITH_MITM;
  1170                     securityMode = SECURITY_MODE_ENCRYPTION_OPEN_LINK;
  1172                 linkSecuredCallback(connectionHandle, securityMode);
  1176         virtual void passkeyDisplay(ble::connection_handle_t connectionHandle, 
const Passkey_t passkey) {
  1177             if (passkeyDisplayCallback) {
  1178                 passkeyDisplayCallback(connectionHandle, passkey);
  1182         SecuritySetupInitiatedCallback_t securitySetupInitiatedCallback;
  1183         SecuritySetupCompletedCallback_t securitySetupCompletedCallback;
  1184         LinkSecuredCallback_t            linkSecuredCallback;
  1185         HandleSpecificEvent_t            securityContextStoredCallback;
  1186         PasskeyDisplayCallback_t         passkeyDisplayCallback;
  1190     SecurityManagerShutdownCallbackChain_t shutdownCallChain;
  1194     LegacyEventHandler defaultEventHandler;
  1198 #if !defined(DOXYGEN_ONLY)  1202 using ble::impl::SecurityManager;
 virtual void confirmationRequest(ble::connection_handle_t connectionHandle)
Indicate to the application that a confirmation is required. 
virtual void keypressNotification(ble::connection_handle_t connectionHandle, SecurityManager::Keypress_t keypress)
Notify the application that a key was pressed by the peer during passkey entry. 
virtual void passkeyRequest(ble::connection_handle_t connectionHandle)
Indicate to the application that a passkey is required. 
SecurityCompletionStatus_t
Result of security requests. 
virtual void passkeyDisplay(ble::connection_handle_t connectionHandle, const SecurityManager::Passkey_t passkey)
Display the given passkey on the local device. 
The link is secure and authenticated. 
void onShutdown(const SecurityManagerShutdownCallback_t &callback)
Setup a callback to be invoked to notify the user application that the SecurityManager instance is ab...
uintptr_t connection_handle_t
Opaque reference to a connection. 
uint8_t Passkey_t[PASSKEY_LEN]
6-digit passkey in ASCII ('0'-'9' digits only). 
The link is secure and authenticated with a secure connection key. 
SecurityManagerShutdownCallbackChain_t & onShutdown()
Provide access to the callchain of shutdown event callbacks. 
virtual void pairingResult(ble::connection_handle_t connectionHandle, SecurityCompletionStatus_t result)
Indicate to the application that pairing has completed. 
virtual void linkEncryptionResult(ble::connection_handle_t connectionHandle, ble::link_encryption_t result)
Inform the device of the encryption state of a given link. 
void processPasskeyDisplayEvent(ble::connection_handle_t connectionHandle, const Passkey_t passkey)
Model fixed size array values. 
Keypress_t
events sent and received when passkey is being entered 
void processLinkSecuredEvent(ble::connection_handle_t connectionHandle, SecurityMode_t securityMode)
SecurityIOCapabilities_t
Input/output capability of the device and application. 
Require signing or encryption, but no MITM protection. 
LayoutType value() const 
Explicit access to the inner value of the SafeEnum instance. 
ble_error_t getLinkSecurity(ble::connection_handle_t connectionHandle, LinkSecurityStatus_t *securityStatus)
virtual void legacyPairingOobGenerated(const ble::address_t *address, const ble::oob_tk_t *temporaryKey)
Indicate that the application needs to send legacy pairing OOB data to the peer. 
Require signing or encryption, and MITM protection. 
void onLinkSecured(LinkSecuredCallback_t callback)
Link security is being established. 
virtual void signingKey(ble::connection_handle_t connectionHandle, const ble::csrk_t *csrk, bool authenticated)
Deliver the signing key to the application. 
Require encryption, but no MITM protection. 
Type that describes link's encryption state. 
void processSecuritySetupInitiatedEvent(ble::connection_handle_t connectionHandle, bool allowBonding, bool requireMITM, SecurityIOCapabilities_t iocaps)
SecurityMode_t
level of security required from the link by the application 
Link security is being established. 
virtual void oobGenerated(const ble::address_t *address, const ble::oob_lesc_value_t *random, const ble::oob_confirm_t *confirm)
Indicate that the application needs to send secure connections OOB data to the peer. 
void setSecurityManagerEventHandler(EventHandler *handler)
Assign the event handler implementation that will be used by the stack to signal events back to the a...
virtual void legacyPairingOobRequest(ble::connection_handle_t connectionHandle)
Indicate to the application it needs to return legacy pairing OOB to the stack. 
void processSecurityContextStoredEvent(ble::connection_handle_t connectionHandle)
void onSecuritySetupInitiated(SecuritySetupInitiatedCallback_t callback)
virtual void pairingRequest(ble::connection_handle_t connectionHandle)
Request application to accept or reject pairing. 
Require encryption and MITM protection. 
Require no protection, open link. 
Representation of a whitelist of addresses. 
virtual void whitelistFromBondTable(::Gap::Whitelist_t *whitelist)
Deliver the requested whitelist to the application. 
void onSecuritySetupCompleted(SecuritySetupCompletedCallback_t callback)
void onPasskeyDisplay(PasskeyDisplayCallback_t callback)
void processSecuritySetupCompletedEvent(ble::connection_handle_t connectionHandle, SecurityCompletionStatus_t status)
void onSecurityContextStored(HandleSpecificEvent_t callback)
Entry namespace for all BLE API definitions. 
LinkSecurityStatus_t
Defines possible security status or states. 
The stack will use these functions to signal events to the application, subclass to override handlers...
ble_error_t
Error codes for the BLE API.