19#ifndef BLE_SECURITY_MANAGER_H_
20#define BLE_SECURITY_MANAGER_H_
24#include "ble/common/BLETypes.h"
25#include "ble/common/blecommon.h"
26#include "ble/common/CallChainOfFunctionPointersWithContext.h"
30#if !defined(DOXYGEN_ONLY)
194 SECURITY_MODE_NO_ACCESS,
250#if BLE_ROLE_PERIPHERAL
265 (void)connectionHandle;
279 (void)connectionHandle;
295 bool address_is_public) {
296 (void)connectionHandle;
298 (void)address_is_public;
331 (void)connectionHandle;
349#if BLE_PASSKEY_DISPLAY_REVERSED_DIGITS_DEPRECATION
350 MBED_DEPRECATED_SINCE(
"mbed-os-6.8.0",
"This returns the passkey in reverse order. Please set the config option ble.ble-passkey-display-reversed-digits-deprecation in your mbed_app.json override section to false. This will then return the passkey in the correct order.")
353 (void)connectionHandle;
357#if BLE_FEATURE_SECURE_CONNECTIONS
372 (void)connectionHandle;
387 (void)connectionHandle;
390#if BLE_FEATURE_SECURE_CONNECTIONS
402 (void)connectionHandle;
416 (void)connectionHandle;
454#if BLE_FEATURE_SIGNING
465 (void)connectionHandle;
506 bool enableBonding =
true,
507 bool requireMITM =
true,
511 const char *dbFilepath =
nullptr
613#if BLE_ROLE_PERIPHERAL
667#if BLE_FEATURE_SECURE_CONNECTIONS
738#if BLE_FEATURE_SIGNING
873#if BLE_FEATURE_SECURE_CONNECTIONS
897#if BLE_FEATURE_SECURE_CONNECTIONS
922#if BLE_FEATURE_SECURE_CONNECTIONS
940#if BLE_FEATURE_SIGNING
961#if BLE_FEATURE_PRIVACY
970 uint16_t timeout_in_seconds
992 template <
typename T>
1016#if !defined(DOXYGEN_ONLY)
1027 impl::SecurityManager *impl;
Function like object hosting a list of FunctionPointerWithContext.
Function like object adapter over freestanding and member functions.
The stack will use these functions to signal events to the application, subclass to override handlers...
virtual void whitelistFromBondTable(::ble::whitelist_t *whitelist)
Deliver the requested whitelist to the application.
virtual void linkEncryptionResult(ble::connection_handle_t connectionHandle, ble::link_encryption_t result)
Triggered by change of encryption state on a link.
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.
virtual void passkeyDisplay(ble::connection_handle_t connectionHandle, const Passkey_t passkey)
Triggered during pairing based on IO capabilities of devices.
virtual void signingKey(ble::connection_handle_t connectionHandle, const ble::csrk_t *csrk, bool authenticated)
Deliver the signing key to the application.
virtual void pairingResult(ble::connection_handle_t connectionHandle, SecurityCompletionStatus_t result)
Indicate to the application that pairing has completed.
virtual void passkeyRequest(ble::connection_handle_t connectionHandle)
Indicate to the application that a passkey is required.
virtual void keypressNotification(ble::connection_handle_t connectionHandle, ble::Keypress_t keypress)
Notify the application that a key was pressed by the peer during passkey entry.
virtual void confirmationRequest(ble::connection_handle_t connectionHandle)
Indicate to the application that a confirmation is required.
~EventHandler()=default
Prevent polymorphic deletion and avoid unnecessary virtual destructor as the SecurityManager class wi...
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 through another commu...
virtual void pairingRequest(ble::connection_handle_t connectionHandle)
Called when a pairing request is received.
virtual void legacyPairingOobRequest(ble::connection_handle_t connectionHandle)
Indicate to the application it needs to return legacy pairing OOB to the stack using legacyPairingOob...
virtual void peerIdentity(ble::connection_handle_t connectionHandle, const address_t *peer_address, bool address_is_public)
Indicate that a peer address has been saved by the security manager or if we are bonded to the peer t...
SecurityManagerShutdownCallbackChain_t & onShutdown()
Provide access to the callchain of shutdown event callbacks.
ble_error_t purgeAllBondingState()
Delete all peer device context and all related bonding information from the database within the secur...
ble_error_t requestAuthentication(ble::connection_handle_t connectionHandle)
Request that the link be authenticated (keys with MITM protection).
ble_error_t generateWhitelistFromBondTable(::ble::whitelist_t *whitelist) const
Create a list of addresses from all peers in the bond table and generate an event which returns it as...
static const unsigned PASSKEY_LEN
Declaration of type containing a passkey to be used during pairing.
ble_error_t preserveBondingStateOnReset(bool enable)
Normally all bonding information is lost when device is reset, this requests that the stack attempts ...
ble_error_t passkeyEntered(ble::connection_handle_t connectionHandle, Passkey_t passkey)
Supply the stack with the user entered passkey.
ble_error_t writeBondingStateToPersistentStorage()
Some or all of bonding information may be stored in memory while in use.
void onShutdown(const SecurityManagerShutdownCallback_t &callback)
Setup a callback to be invoked to notify the user application that the SecurityManager instance is ab...
ble_error_t setPairingRequestAuthorisation(bool required=true)
Tell the stack whether the application needs to authorise pairing requests or should they be automati...
ble_error_t cancelPairingRequest(ble::connection_handle_t connectionHandle)
Reject pairing request if the local device is the slave or cancel an outstanding pairing request if m...
ble_error_t setDatabaseFilepath(const char *dbFilepath=nullptr)
Change the file used for the security database.
ble_error_t getSigningKey(ble::connection_handle_t connectionHandle, bool authenticated)
Retrieves a signing key through a signingKey event.
ble_error_t setEncryptionKeyRequirements(uint8_t minimumByteSize, uint8_t maximumByteSize)
Set the requirements for encryption key size.
ble_error_t setLinkSecurity(ble::connection_handle_t connectionHandle, SecurityMode_t securityMode)
Set the security mode on a connection.
SecurityIOCapabilities_t
Input/output capability of the device and application.
@ IO_CAPS_KEYBOARD_ONLY
Keyboard only.
@ IO_CAPS_KEYBOARD_DISPLAY
Keyboard and display.
@ IO_CAPS_NONE
No I/O capabilities.
@ IO_CAPS_DISPLAY_ONLY
Display only.
@ IO_CAPS_DISPLAY_YESNO
Display and yes/no entry.
SecurityCompletionStatus_t
Result of security requests.
@ SEC_STATUS_PDU_INVALID
Invalid PDU received.
@ SEC_STATUS_AUTH_REQ
Authentication requirements not met.
@ SEC_STATUS_OOB_NOT_AVAILABLE
Out of Band Key not available.
@ SEC_STATUS_REPEATED_ATTEMPTS
Too little time elapsed since last attempt.
@ SEC_STATUS_ENC_KEY_SIZE
Encryption key size.
@ SEC_STATUS_SUCCESS
Procedure completed with success.
@ SEC_STATUS_SMP_CMD_UNSUPPORTED
Unsupported SMP command.
@ SEC_STATUS_UNSPECIFIED
Unspecified reason.
@ SEC_STATUS_TIMEOUT
Procedure timed out.
@ SEC_STATUS_DHKEY_CHECK_FAILED
DHKey received doesn’t match locally calculated one.
@ SEC_STATUS_PASSKEY_ENTRY_FAILED
Passkey entry failed (user cancelled or other).
@ SEC_STATUS_PAIRING_NOT_SUPP
Pairing not supported.
@ SEC_STATUS_INVALID_PARAMS
Invalid parameters.
@ SEC_STATUS_CONFIRM_VALUE
Confirm value failed.
@ SEC_STATUS_COMPARISON_FAILED
Values in the numeric comparison protocol do not match.
ble_error_t setLinkEncryption(ble::connection_handle_t connectionHandle, ble::link_encryption_t encryption)
Enabled or disable encryption on the link.
ble_error_t confirmationEntered(ble::connection_handle_t connectionHandle, bool confirmation)
Report to the stack if the passkey matches or not.
ble_error_t reset()
Notify all registered onShutdown callbacks that the SecurityManager is about to be shutdown and clear...
ble_error_t acceptPairingRequest(ble::connection_handle_t connectionHandle)
Accept the pairing request.
ble_error_t allowLegacyPairing(bool allow=true)
Allow or disallow the use of legacy pairing in case the application only wants to force the use of Se...
SecurityMode_t
level of security required from the link by the application
@ SECURITY_MODE_SIGNED_NO_MITM
Require signing or encryption, but no MITM protection.
@ SECURITY_MODE_ENCRYPTION_OPEN_LINK
Require no protection, open link.
@ SECURITY_MODE_SIGNED_WITH_MITM
Require signing or encryption, and MITM protection.
@ SECURITY_MODE_ENCRYPTION_WITH_MITM
Require encryption and MITM protection.
@ SECURITY_MODE_ENCRYPTION_NO_MITM
Require encryption, but no MITM protection.
ble_error_t setKeypressNotification(bool enabled=true)
Set whether or not we want to send and receive keypress notifications during passkey entry.
ble_error_t legacyPairingOobReceived(const ble::address_t *address, const ble::oob_tk_t *tk)
Supply the stack with the OOB data for legacy connections.
ble_error_t enableSigning(ble::connection_handle_t connectionHandle, bool enabled=true)
Request generation and exchange of signing keys so that packet signing can be utilised on this connec...
ble_error_t sendKeypressNotification(ble::connection_handle_t connectionHandle, ble::Keypress_t keypress)
Send a notification to the peer that the user pressed a key on the local device.
ble_error_t init(bool enableBonding=true, bool requireMITM=true, SecurityIOCapabilities_t iocaps=IO_CAPS_NONE, const Passkey_t passkey=nullptr, bool signing=true, const char *dbFilepath=nullptr)
Enable the BLE stack's Security Manager.
ble_error_t generateOOB(const ble::address_t *address)
Generate OOB data with the given address.
ble_error_t setIoCapability(SecurityIOCapabilities_t iocaps)
Set the IO capability of the local device.
ble_error_t getPeerIdentity(ble::connection_handle_t connectionHandle)
Retrieve identity address for the peer on the given connection.
ble_error_t setPrivateAddressTimeout(uint16_t timeout_in_seconds)
Sets how often the address is rotated when privacy is enabled.
ble_error_t requestPairing(ble::connection_handle_t connectionHandle)
Request pairing with the peer.
ble_error_t setDisplayPasskey(const Passkey_t passkey)
Set the passkey that is displayed on the local device instead of using a randomly generated one.
ble_error_t getEncryptionKeySize(connection_handle_t connectionHandle, uint8_t *size)
Get encryption key size for given connection.
ble_error_t getSecureConnectionsSupport(bool *enabled)
Check if the Secure Connections feature is supported by the stack and controller.
ble_error_t oobReceived(const ble::address_t *address, const ble::oob_lesc_value_t *random, const ble::oob_confirm_t *confirm)
Supply the stack with the OOB data for secure connections.
ble_error_t setOOBDataUsage(ble::connection_handle_t connectionHandle, bool useOOB, bool OOBProvidesMITM=true)
Enable OOB data usage during paring.
uint8_t Passkey_t[PASSKEY_LEN]
6-digit passkey in ASCII ('0'-'9' digits only).
void setSecurityManagerEventHandler(EventHandler *handler)
Assign the event handler implementation that will be used by the stack to signal events back to the a...
ble_error_t getLinkEncryption(ble::connection_handle_t connectionHandle, ble::link_encryption_t *encryption)
Current state of encryption on the link.
ble_error_t setHintFutureRoleReversal(bool enable=true)
Give a hint to the stack that the master/slave role might change in the future.
ble_error_t
Error codes for the BLE API.
Entry namespace for all BLE API definitions.
Keypress_t
events sent and received when passkey is being entered
uintptr_t connection_handle_t
Opaque reference to a connection.
Model fixed size array values.
Type that describes link's encryption state.
Representation of a whitelist of addresses.