|
ELEC-C7222
Libraries for ELEC C7222 Course Work
|
Manages BLE security configuration and pairing-related events. More...
#include <security_manager.hpp>


Classes | |
| struct | EventHandler |
| Security Manager event callback interface. More... | |
| struct | SecurityParameters |
| Cached security configuration parameters. More... | |
Public Types | |
| enum class | EventId : uint8_t { kJustWorksRequest , kNumericComparisonRequest , kPasskeyDisplay , kPasskeyInput , kPairingComplete , kReencryptionComplete , kAuthorizationRequest , kAuthorizationResult } |
| Security-related event identifiers. More... | |
| enum class | IoCapability : uint8_t { kDisplayOnly , kDisplayYesNo , kKeyboardOnly , kNoInputNoOutput , kKeyboardDisplay } |
| Local device IO capabilities used during pairing. More... | |
| enum class | AuthenticationRequirement : uint8_t { kNone = 0 , kBonding = 1u << 0 , kMitmProtection = 1u << 1 , kSecureConnections = 1u << 2 , kKeypressNotifications = 1u << 3 } |
| Authentication requirement flags. More... | |
| enum class | PairingStatus : uint8_t { kSuccess = 0x00 , kFailed = 0x01 , kTimeout = 0x02 , kUnsupported = 0x03 , kUnknown = 0xFF } |
| Pairing outcome classification. More... | |
| enum class | AuthorizationResult : uint8_t { kDenied = 0 , kGranted = 1 } |
| Authorization decision. More... | |
| enum class | FixedPasskeyRole : uint8_t { kNone = 0 , kDisplay = 1 , kKeyboard = 2 } |
| Role used for fixed passkey configuration. More... | |
| enum class | GattClientSecurityLevel : uint8_t { kLevel0 = 0 , kLevel1 = 1 , kLevel2 = 2 , kLevel3 = 3 , kLevel4 = 4 } |
| Required security level for the BTstack GATT client. More... | |
Public Member Functions | |
| BleError | Configure (const SecurityParameters ¶ms) |
| Apply a full configuration object at once. | |
| BleError | SetIoCapability (IoCapability capability) |
| Set the local IO capability. | |
| BleError | SetAuthenticationRequirements (AuthenticationRequirement auth) |
| Set authentication requirement bitfield. | |
| BleError | SetEncryptionKeySizeRange (uint8_t min_key_size, uint8_t max_key_size) |
| Set minimum and maximum encryption key sizes. | |
| BleError | SetBondable (bool bondable) |
| Enable or disable bonding. | |
| BleError | SetSecureConnectionsOnly (bool enabled) |
| Enable or disable Secure Connections only mode. | |
| BleError | SetGattClientRequiredSecurityLevel (GattClientSecurityLevel level) |
| Set required security level for GATT client operations. | |
| BleError | SetFixedPasskeyDisplay (uint32_t passkey) |
| Configure fixed passkey for display role. | |
| BleError | SetFixedPasskeyKeyboard (uint32_t passkey) |
| Configure fixed passkey for keyboard role. | |
| BleError | ClearFixedPasskey () |
| Clear fixed passkey configuration. | |
| SecurityParameters | GetSecurityParameters () const |
| Get the cached security parameters. | |
| bool | IsConfigured () const |
| Check whether security has been explicitly configured by the application. | |
| bool | IsApplied () const |
| Check whether the configuration has been applied to the platform stack. | |
| bool | ValidateConfiguration (bool authentication_required, bool authorization_required, bool encryption_required) const |
| Validate that the current configuration can satisfy requirements. | |
| void | AddEventHandler (const EventHandler &handler) |
| Add an event handler (stored as a pointer). | |
| bool | RemoveEventHandler (const EventHandler &handler) |
| Remove an event handler. | |
| void | AddEventHandler (const EventHandler *handler) |
| Add an event handler pointer (no ownership). | |
| bool | RemoveEventHandler (const EventHandler *handler) |
| Remove an event handler pointer. | |
| void | ClearEventHandlers () |
| Remove all registered event handlers. | |
| size_t | GetEventHandlerCount () const |
| Get the number of registered event handlers. | |
| BleError | ConfirmJustWorks (ConnectionHandle con_handle) |
| Confirm a "Just Works" pairing request. | |
| BleError | ConfirmNumericComparison (ConnectionHandle con_handle, bool accept) |
| Accept or reject a numeric comparison pairing request. | |
| BleError | ProvidePasskey (ConnectionHandle con_handle, uint32_t passkey) |
| Provide a passkey for keyboard input role. | |
| BleError | RequestPairing (ConnectionHandle con_handle) |
| Initiate pairing as a client or server. | |
| BleError | SetAuthorization (ConnectionHandle con_handle, AuthorizationResult result) |
| Provide an authorization decision for the given connection. | |
| BleError | DispatchBleHciPacket (uint8_t packet_type, const uint8_t *packet, uint16_t size) |
| Dispatch a raw HCI packet into the security event pipeline. | |
Public Member Functions inherited from c7222::NonCopyable | |
| NonCopyable (const NonCopyable &)=delete | |
| NonCopyable & | operator= (const NonCopyable &)=delete |
| NonCopyable (NonCopyable &&)=default | |
| NonCopyable & | operator= (NonCopyable &&)=default |
Public Member Functions inherited from c7222::NonMovable | |
| NonMovable (const NonMovable &)=default | |
| NonMovable & | operator= (const NonMovable &)=default |
| NonMovable (NonMovable &&)=delete | |
| NonMovable & | operator= (NonMovable &&)=delete |
Static Public Member Functions | |
| static SecurityManager * | GetInstance () |
| Get the singleton instance. | |
Additional Inherited Members | |
Protected Member Functions inherited from c7222::NonCopyableNonMovable | |
| NonCopyableNonMovable ()=default | |
| ~NonCopyableNonMovable ()=default | |
Protected Member Functions inherited from c7222::NonCopyable | |
| NonCopyable ()=default | |
| ~NonCopyable ()=default | |
Protected Member Functions inherited from c7222::NonMovable | |
| NonMovable ()=default | |
| ~NonMovable ()=default | |
Manages BLE security configuration and pairing-related events.
This class provides a platform-agnostic interface for configuring security requirements before connections are established (IO capabilities, pairing flags, key sizes, and GATT client requirements) and for handling pairing and authorization events at runtime.
Configure security before enabling the stack or accepting connections:
The BLE layer will apply the configuration when SecurityManager is enabled.
Implement EventHandler and register it to receive pairing prompts and authorization callbacks. Event payloads are only valid during the call.
Use ValidateConfiguration(authentication_required, authorization_required,
encryption_required) to ensure the current configuration can satisfy the security requirements of your GATT database.
The Pico W/RP2040 implementation lives in libs/elec_c7222/ble/security_manager/platform/rpi_pico/. The platform layer applies configuration via BTstack APIs and dispatches SM events to the handlers registered on this class. It also performs platform-specific validation in ValidateConfiguration() based on the BTstack configuration and available key storage backend.
|
strong |
Authentication requirement flags.
These are modeled as a bitfield so they can be combined with |.
|
strong |
|
strong |
Security-related event identifiers.
|
strong |
|
strong |
Required security level for the BTstack GATT client.
This maps to BTstack's gap_security_level_t used by gatt_client_set_required_security_level(level).
|
strong |
Local device IO capabilities used during pairing.
|
strong |
| void c7222::SecurityManager::AddEventHandler | ( | const EventHandler & | handler | ) |
Add an event handler (stored as a pointer).

| void c7222::SecurityManager::AddEventHandler | ( | const EventHandler * | handler | ) |
Add an event handler pointer (no ownership).
| void c7222::SecurityManager::ClearEventHandlers | ( | ) |
Remove all registered event handlers.

| BleError c7222::SecurityManager::ClearFixedPasskey | ( | ) |
Clear fixed passkey configuration.
| BleError c7222::SecurityManager::Configure | ( | const SecurityParameters & | params | ) |
Apply a full configuration object at once.
Marks the SecurityManager as configured; the BLE layer applies the settings to the platform when security is enabled.

| BleError c7222::SecurityManager::ConfirmJustWorks | ( | ConnectionHandle | con_handle | ) |
Confirm a "Just Works" pairing request.

| BleError c7222::SecurityManager::ConfirmNumericComparison | ( | ConnectionHandle | con_handle, |
| bool | accept | ||
| ) |
Accept or reject a numeric comparison pairing request.

| BleError c7222::SecurityManager::DispatchBleHciPacket | ( | uint8_t | packet_type, |
| const uint8_t * | packet, | ||
| uint16_t | size | ||
| ) |
Dispatch a raw HCI packet into the security event pipeline.
|
inline |
Get the number of registered event handlers.
|
static |
Get the singleton instance.
|
inline |
Get the cached security parameters.
|
inline |
Check whether the configuration has been applied to the platform stack.
This becomes true after a successful ApplyConfiguration() call.
|
inline |
Check whether security has been explicitly configured by the application.
This becomes true after any configuration setter (or Configure()) is called.
| BleError c7222::SecurityManager::ProvidePasskey | ( | ConnectionHandle | con_handle, |
| uint32_t | passkey | ||
| ) |
Provide a passkey for keyboard input role.

| bool c7222::SecurityManager::RemoveEventHandler | ( | const EventHandler & | handler | ) |
Remove an event handler.

| bool c7222::SecurityManager::RemoveEventHandler | ( | const EventHandler * | handler | ) |
Remove an event handler pointer.
| BleError c7222::SecurityManager::RequestPairing | ( | ConnectionHandle | con_handle | ) |
Initiate pairing as a client or server.

| BleError c7222::SecurityManager::SetAuthenticationRequirements | ( | AuthenticationRequirement | auth | ) |
Set authentication requirement bitfield.

| BleError c7222::SecurityManager::SetAuthorization | ( | ConnectionHandle | con_handle, |
| AuthorizationResult | result | ||
| ) |
Provide an authorization decision for the given connection.

| BleError c7222::SecurityManager::SetBondable | ( | bool | bondable | ) |
Enable or disable bonding.

| BleError c7222::SecurityManager::SetEncryptionKeySizeRange | ( | uint8_t | min_key_size, |
| uint8_t | max_key_size | ||
| ) |
Set minimum and maximum encryption key sizes.

| BleError c7222::SecurityManager::SetFixedPasskeyDisplay | ( | uint32_t | passkey | ) |
Configure fixed passkey for display role.
| BleError c7222::SecurityManager::SetFixedPasskeyKeyboard | ( | uint32_t | passkey | ) |
Configure fixed passkey for keyboard role.
| BleError c7222::SecurityManager::SetGattClientRequiredSecurityLevel | ( | GattClientSecurityLevel | level | ) |
Set required security level for GATT client operations.
| BleError c7222::SecurityManager::SetIoCapability | ( | IoCapability | capability | ) |
Set the local IO capability.

| BleError c7222::SecurityManager::SetSecureConnectionsOnly | ( | bool | enabled | ) |
Enable or disable Secure Connections only mode.

| bool c7222::SecurityManager::ValidateConfiguration | ( | bool | authentication_required, |
| bool | authorization_required, | ||
| bool | encryption_required | ||
| ) | const |
Validate that the current configuration can satisfy requirements.
This check is platform-dependent and should be called before enabling BLE when the GATT database requires specific security guarantees.