|
|
| Gap * | GetGap () |
| | Access the underlying GAP instance.
|
| |
| const Gap * | GetGap () const |
| | Access the underlying GAP instance (const).
|
| |
| SecurityManager * | GetSecurityManager () |
| | Access the underlying Security Manager instance.
|
| |
| const SecurityManager * | GetSecurityManager () const |
| | Access the underlying Security Manager instance (const).
|
| |
| SecurityManager * | EnableSecurityManager (const SecurityManager::SecurityParameters ¶ms) |
| | Enable and access the Security Manager instance.
|
| |
| AttributeServer * | EnableAttributeServer (const void *context) |
| | Enable and access the Attribute Server instance.
|
| |
|
| AttributeServer * | GetAttributeServer () |
| | Access the Attribute Server instance.
|
| |
| const AttributeServer * | GetAttributeServer () const |
| | Access the Attribute Server instance (const).
|
| |
|
| void | SetOnBleStackOnCallback (std::function< void()> handler) |
| | Register BLE stack-on callback (HCI_STATE_WORKING).
|
| |
| void | SetOnBleStackOnCallback (void(*handler)()) |
| | Register BLE stack-on callback from a function pointer.
|
| |
| template<typename T > |
| void | SetOnBleStackOnCallback (T *object, void(T::*method)()) |
| | Register BLE stack-on callback from an object/member function.
|
| |
| template<typename T > |
| void | SetOnBleStackOnCallback (const T *object, void(T::*method)() const) |
| | Register BLE stack-on callback from a const object/member function.
|
| |
| void | SetOnBleStackOffCallback (std::function< void()> handler) |
| | Register BLE stack-off callback (non-working state).
|
| |
| void | SetOnBleStackOffCallback (void(*handler)()) |
| | Register BLE stack-off callback from a function pointer.
|
| |
| template<typename T > |
| void | SetOnBleStackOffCallback (T *object, void(T::*method)()) |
| | Register BLE stack-off callback from an object/member function.
|
| |
| template<typename T > |
| void | SetOnBleStackOffCallback (const T *object, void(T::*method)() const) |
| | Register BLE stack-off callback from a const object/member function.
|
| |
|
| BleError | TurnOn () |
| | Power on the BLE stack and controller.
|
| |
| void | TurnOff () |
| | Power off the BLE stack and controller.
|
| |
| bool | IsTurnedOn () const |
| | Check whether BLE stack is marked as working.
|
| |
|
| void | SetDeviceName (const std::string &name) |
| | Set the GAP device name.
|
| |
| void | SetAdvertisementFlags (uint8_t flags) |
| | Set the advertising flags (e.g., general discoverable).
|
| |
| void | AddGapEventHandler (const Gap::EventHandler &handler) |
| | Add a GAP event handler.
|
| |
| void | RemoveGapEventHandler (const Gap::EventHandler &handler) |
| | Remove a GAP event handler.
|
| |
| void | ClearGapEventHandlers () |
| | Remove all GAP event handlers.
|
| |
| void | SetRandomAddress (const BleAddress &address) |
| | Set the random device address.
|
| |
| void | SetAdvertisingParameters (const Gap::AdvertisementParameters ¶ms) |
| | Set advertising parameters.
|
| |
| void | SetAdvertisingData (const uint8_t *data, size_t size) |
| | Set raw advertising data.
|
| |
| void | SetAdvertisingData (const std::vector< uint8_t > &data) |
| | Set advertising data from a vector.
|
| |
| void | SetAdvertisingData (const AdvertisementDataBuilder &data_builder) |
| | Set advertising data from a builder.
|
| |
| void | SetAdvertisingData () |
| | Set advertising data from the current builder state.
|
| |
| void | SetScanResponseData (uint8_t length, const uint8_t *data) |
| | Set scan response data.
|
| |
| void | EnableAdvertising (bool enabled) |
| | Enable or disable advertising.
|
| |
| void | StartAdvertising () |
| | Start advertising.
|
| |
| void | StopAdvertising () |
| | Stop advertising.
|
| |
| bool | IsAdvertisingEnabled () const |
| | Check whether advertising is enabled.
|
| |
| bool | IsConnected () const |
| | Check whether a GAP connection is active.
|
| |
| BleError | RequestConnectionParameterUpdate (ConnectionHandle con_handle, const Gap::PreferredConnectionParameters ¶ms) |
| | Request a connection parameter update.
|
| |
| BleError | UpdateConnectionParameters (ConnectionHandle con_handle, const Gap::PreferredConnectionParameters ¶ms) |
| | Apply new connection parameters.
|
| |
| BleError | ReadRssi (ConnectionHandle con_handle) |
| | Read RSSI for an active connection.
|
| |
| BleError | Disconnect (ConnectionHandle con_handle) |
| | Disconnect an active connection.
|
| |
| AdvertisementDataBuilder & | GetAdvertisementDataBuilder () |
| | Access the advertising data builder.
|
| |
| const AdvertisementDataBuilder & | GetAdvertisementDataBuilder () const |
| | Access the advertising data builder (const).
|
| |
|
| void | AddSecurityEventHandler (const SecurityManager::EventHandler &handler) |
| | Add a Security Manager event handler.
|
| |
| bool | RemoveSecurityEventHandler (const SecurityManager::EventHandler &handler) |
| | Remove a Security Manager event handler.
|
| |
| void | AddSecurityEventHandler (const SecurityManager::EventHandler *handler) |
| | Add a Security Manager event handler pointer.
|
| |
| bool | RemoveSecurityEventHandler (const SecurityManager::EventHandler *handler) |
| | Remove a Security Manager event handler pointer.
|
| |
| void | ClearSecurityEventHandlers () |
| | Remove all Security Manager event handlers.
|
| |
| BleError | ConfigureSecurity (const SecurityManager::SecurityParameters ¶ms) |
| | Configure the Security Manager parameters.
|
| |
| BleError | SetSecurityIoCapability (SecurityManager::IoCapability capability) |
| | Set Security Manager IO capability.
|
| |
| BleError | SetSecurityAuthenticationRequirements (SecurityManager::AuthenticationRequirement auth) |
| | Set Security Manager authentication requirements.
|
| |
| BleError | SetSecurityKeySizeRange (uint8_t min_key_size, uint8_t max_key_size) |
| | Set Security Manager encryption key size range.
|
| |
| BleError | SetSecurityBondable (bool bondable) |
| | Enable or disable bonding in the Security Manager.
|
| |
| BleError | SetSecuritySecureConnectionsOnly (bool enabled) |
| | Enable or disable Secure Connections only mode.
|
| |
| BleError | ConfirmJustWorks (ConnectionHandle con_handle) |
| | Confirm "Just Works" pairing.
|
| |
| BleError | ConfirmNumericComparison (ConnectionHandle con_handle, bool accept) |
| | Confirm numeric comparison pairing.
|
| |
| BleError | ProvidePasskey (ConnectionHandle con_handle, uint32_t passkey) |
| | Provide passkey for keyboard input role.
|
| |
| BleError | RequestPairing (ConnectionHandle con_handle) |
| | Request pairing with the peer device.
|
| |
| BleError | SetAuthorization (ConnectionHandle con_handle, SecurityManager::AuthorizationResult result) |
| | Provide an authorization decision.
|
| |
|
| virtual BleError | DispatchBleHciPacket (uint8_t packet_type, uint8_t channel, const uint8_t *packet_data, uint16_t packet_data_size) |
| | Dispatch raw HCI packets to GAP/AttributeServer/SecurityManager.
|
| |
| | NonCopyable (const NonCopyable &)=delete |
| |
| NonCopyable & | operator= (const NonCopyable &)=delete |
| |
| | NonCopyable (NonCopyable &&)=default |
| |
| NonCopyable & | operator= (NonCopyable &&)=default |
| |
| | NonMovable (const NonMovable &)=default |
| |
| NonMovable & | operator= (const NonMovable &)=default |
| |
| | NonMovable (NonMovable &&)=delete |
| |
| NonMovable & | operator= (NonMovable &&)=delete |
| |
Singleton entry point for BLE configuration and events.
This class is the primary facade for BLE stack initialization, configuration, and event routing. It aggregates references to other singleton components (GAP, AttributeServer, SecurityManager) and coordinates their lifecycle.
Singleton Composition
The BLE stack is represented by several singletons:
Gap manages advertising, connections, and GAP-level events.
AttributeServer parses the ATT database and routes GATT operations.
SecurityManager configures pairing and handles security events.
Ble owns pointers to these instances and ensures they are enabled in the correct order. This keeps a single, global view of BLE state in the system.
Context Pointer (Platform-Specific)
EnableAttributeServer(const void* context) accepts a platform-specific context pointer. On Pico W, this is the compiled ATT database blob (att_db.h/att_db.c) generated by BTstack. The context is cached so the ATT database remains valid for the lifetime of the server.
This allows Ble to remain platform-agnostic while the platform layer interprets the context appropriately.
Profile Databases (ATT/GATT)
BLE profiles are represented as an ATT/GATT database (services, characteristics, and descriptors). On the Pico W, this database is required by the Pico BTstack stack and is generated outside of this library (e.g., by the BTstack tooling that produces att_db.h/att_db.c). The database is passed into EnableAttributeServer() as the context pointer. The AttributeServer parses this database into Service and Characteristic objects for routing and event callbacks.
The database blob is treated as immutable and must remain valid for the lifetime of the server because many static attributes reference data inside that blob.
Typical Workflow
- Configure security (optional):
- Enable Attribute Server:
- Call
EnableAttributeServer(att_db) with the compiled ATT database.
- Register handlers:
- Install attribute/characteristic handlers.
- Register SecurityManager event handlers if needed.
- Do this after
EnableAttributeServer() (so characteristics exist), and before TurnOn() or before initiating any connections.
- Register GAP event handlers immediately after obtaining the
Gap instance, also before TurnOn(), so early connection/state events are not missed.
Handler Registration Timing
TurnOn/TurnOff Callbacks
SetOnBleStackOnCallback() is invoked when the stack transitions to HCI_STATE_WORKING after TurnOn() succeeds. This is the earliest safe moment to start advertising or initiating connections.
SetOnBleStackOffCallback() is invoked when the stack leaves the working state (e.g., controller power-off or reset). Use it to stop application activity that depends on an active controller.
- Turn on BLE:
- Call
TurnOn() to initialize the stack and power on the controller.
- Dispatch events:
Example
ble->EnableSecurityManager(params);
ble->EnableAttributeServer(att_db);
ble->TurnOn();
static Ble * GetInstance(bool enable_hci_logging=false)
Get the singleton instance.
@ kMitmProtection
Require MITM protection.
@ kNoInputNoOutput
Device has no input and no output.
Cached security configuration parameters.
Definition security_manager.hpp:284
IoCapability io_capability
IO capability used to select pairing method.
Definition security_manager.hpp:288
AuthenticationRequirement authentication
Authentication requirement bitfield.
Definition security_manager.hpp:292
BLE Standard Concepts (High-Level)
- GAP handles discovery, advertising, and connections.
- GATT/ATT define services, characteristics, and attribute access.
- SM (Security Manager) handles pairing, authentication, and encryption.
Ble sits above these roles and routes HCI events to the appropriate subsystem based on their responsibility.
Raspberry Pi Pico (BTstack) Port
On Pico W, the platform implementation in libs/elec_c7222/ble/platform/rpi_pico/:
- Initializes L2CAP and SM as needed.
- Registers BTstack HCI event handlers.
- Powers on the controller via
hci_power_control(HCI_POWER_ON).
- Routes HCI events into GAP, AttributeServer, and SecurityManager.
- Updates the AttributeServer security cache on
GAP_EVENT_SECURITY_LEVEL.
The DumpAttributeServerContext() helper can dump the ATT database using BTstack when HCI logging is enabled.