|
CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
|
#include <IBluetoothController.h>
Classes | |
| struct | DiscoveredCharacteristic |
| struct | DiscoveredService |
Public Types | |
| using | ListenerToken = uint16_t |
| using | PasskeyCallback = std::function<void(uint32_t passkey)> |
| using | AuthCompleteCallback = std::function<void(bool success)> |
| using | NumericComparisonCallback = std::function<void(uint16_t connHandle, uint32_t passkey)> |
| using | EncChangeCallback = std::function<void(uint16_t connHandle, int status)> |
| using | ConnectionCallback = std::function<void(uint16_t connHandle)> |
| using | DisconnectionCallback = std::function<void(uint16_t connHandle, int reason)> |
| using | ServiceDiscoveryCallback |
| using | CharacteristicReadCallback |
| using | NotificationCallback |
| using | WriteCompleteCallback |
Public Member Functions | |
| virtual | ~IBluetoothController ()=default |
| virtual bool | enable ()=0 |
| virtual void | disable ()=0 |
| virtual bool | isEnabled () const=0 |
| virtual bool | getMacAddress (uint8_t *mac) const=0 |
| virtual void | setDeviceName (const char *name)=0 |
| virtual const char * | getDeviceName () const=0 |
| virtual bool | isConnected () const=0 |
| virtual void | disconnect ()=0 |
| virtual int8_t | getRssi () const=0 |
| virtual bool | getConnectedDeviceName (char *buf, size_t bufLen) const |
| virtual uint8_t | getBondedDeviceCount () const |
| virtual uint8_t | getBondedDevices (BleBondInfo *out, uint8_t maxCount) const |
| virtual void | startAdvertising () |
| virtual void | stopAdvertising () |
| virtual bool | isAdvertising () const |
| virtual bool | addAdvertisingUuid (const BleUuid &uuid) |
| virtual void | removeAdvertisingUuid (const BleUuid &uuid) |
| virtual bool | setAdvertisingManufacturerData (uint16_t companyId, const uint8_t *data, uint16_t len) |
| virtual void | clearAdvertisingManufacturerData () |
| virtual void | setAppearance (uint16_t appearance) |
| virtual bool | startScan (uint32_t durationMs=5000, bool keepAdvertising=false) |
| virtual void | stopScan () |
| virtual bool | isScanComplete () const |
| virtual uint8_t | getScanResults (BleScanResult *results, uint8_t maxResults) |
| virtual void | setPasskeyCallback (PasskeyCallback cb) |
| virtual void | setAuthCompleteCallback (AuthCompleteCallback cb) |
| virtual ListenerToken | addNumericComparisonCallback (NumericComparisonCallback cb) |
| virtual void | removeNumericComparisonCallback (ListenerToken token) |
| virtual void | setNumericComparisonCallback (NumericComparisonCallback cb) |
| virtual void | respondToNumericComparison (uint16_t connHandle, bool accept) |
| virtual ListenerToken | addEncryptionChangeCallback (EncChangeCallback cb) |
| virtual void | removeEncryptionChangeCallback (ListenerToken token) |
| virtual bool | initiateSecurity (uint16_t connHandle) |
| virtual bool | getPeerIdAddr (uint16_t connHandle, uint8_t addr[6], uint8_t *addrType) const |
| virtual ListenerToken | addConnectionCallback (ConnectionCallback cb) |
| virtual ListenerToken | addDisconnectionCallback (DisconnectionCallback cb) |
| virtual void | removeConnectionCallback (ListenerToken token) |
| virtual void | removeDisconnectionCallback (ListenerToken token) |
| virtual void | clearAllBonds () |
| virtual void | forgetBond (const uint8_t addr[6], uint8_t addrType) |
| virtual bool | registerGattService (const GattServiceDef &service, bool pluginReserved=false) |
| virtual bool | unregisterGattService (const BleUuid &serviceUuid) |
| virtual bool | sendNotification (uint16_t connHandle, uint16_t attrHandle, const uint8_t *data, uint16_t len) |
| virtual bool | sendIndication (uint16_t connHandle, uint16_t attrHandle, const uint8_t *data, uint16_t len) |
| virtual uint16_t | getMtu () const |
| virtual bool | connect (const uint8_t *addr, uint8_t addrType=0) |
| virtual void | cancelConnect () |
| virtual bool | discoverServiceByUuid (uint16_t connHandle, const BleUuid &uuid) |
| virtual bool | writeCharacteristic (uint16_t connHandle, uint16_t attrHandle, const uint8_t *data, uint16_t len, bool withResponse=true) |
| virtual bool | readCharacteristic (uint16_t connHandle, uint16_t attrHandle) |
| virtual bool | enableNotifications (uint16_t connHandle, uint16_t cccdHandle) |
| virtual void | disconnectHandle (uint16_t connHandle) |
| virtual ListenerToken | addServiceDiscoveryCallback (ServiceDiscoveryCallback cb) |
| virtual ListenerToken | addCharacteristicReadCallback (CharacteristicReadCallback cb) |
| virtual ListenerToken | addNotificationCallback (NotificationCallback cb) |
| virtual ListenerToken | addWriteCompleteCallback (WriteCompleteCallback cb) |
| virtual void | removeServiceDiscoveryCallback (ListenerToken token) |
| virtual void | removeCharacteristicReadCallback (ListenerToken token) |
| virtual void | removeNotificationCallback (ListenerToken token) |
| virtual void | removeWriteCompleteCallback (ListenerToken token) |
| virtual void | setServiceDiscoveryCallback (ServiceDiscoveryCallback cb) |
| virtual void | setCharacteristicReadCallback (CharacteristicReadCallback cb) |
| virtual void | setNotificationCallback (NotificationCallback cb) |
| virtual void | setWriteCompleteCallback (WriteCompleteCallback cb) |
| virtual uint16_t | getConnectionHandle () const |
| Public Member Functions inherited from cdc::core::IService | |
| virtual | ~IService ()=default |
| virtual bool | init ()=0 |
| virtual bool | start ()=0 |
| virtual void | stop ()=0 |
| virtual ServiceState | getState () const =0 |
| virtual const char * | getName () const =0 |
Static Public Attributes | |
| static constexpr ListenerToken | INVALID_LISTENER = 0xFFFF |
| static constexpr uint8_t | MAX_REGISTERED_SERVICES = 7 |
| static constexpr uint8_t | MAX_CHARS_PER_SERVICE = 6 |
| static constexpr uint8_t | MAX_BONDED_DEVICES = 5 |
| static constexpr uint8_t | MAX_SCAN_RESULTS = 64 |
Bluetooth Controller Interface Handles BLE stack initialization, power control, scanning and advertising
Definition at line 144 of file IBluetoothController.h.
| using cdc::hal::IBluetoothController::AuthCompleteCallback = std::function<void(bool success)> |
Definition at line 343 of file IBluetoothController.h.
Called when characteristic read completes
Definition at line 650 of file IBluetoothController.h.
| using cdc::hal::IBluetoothController::ConnectionCallback = std::function<void(uint16_t connHandle)> |
Definition at line 434 of file IBluetoothController.h.
| using cdc::hal::IBluetoothController::DisconnectionCallback = std::function<void(uint16_t connHandle, int reason)> |
Definition at line 435 of file IBluetoothController.h.
| using cdc::hal::IBluetoothController::EncChangeCallback = std::function<void(uint16_t connHandle, int status)> |
Called when link encryption is established or fails on a connection. status == 0 means the link is now encrypted.
Definition at line 397 of file IBluetoothController.h.
| using cdc::hal::IBluetoothController::ListenerToken = uint16_t |
Opaque listener token returned by add*Callback() methods. Pass to the matching remove*Callback() to unregister.
Definition at line 152 of file IBluetoothController.h.
Called when notification/indication received from remote device
Definition at line 657 of file IBluetoothController.h.
| using cdc::hal::IBluetoothController::NumericComparisonCallback = std::function<void(uint16_t connHandle, uint32_t passkey)> |
Numeric comparison callback for secure pairing. Called when a connecting device requires confirmation. Display the passkey and let the user accept/reject.
Definition at line 360 of file IBluetoothController.h.
| using cdc::hal::IBluetoothController::PasskeyCallback = std::function<void(uint32_t passkey)> |
Definition at line 342 of file IBluetoothController.h.
Called when service discovery completes.
| connHandle | Connection handle |
| service | Discovered service (null if discovery failed) |
| complete | true when discovery is finished |
Definition at line 643 of file IBluetoothController.h.
Called when write to remote characteristic completes
Definition at line 664 of file IBluetoothController.h.
|
virtualdefault |
|
inlinevirtual |
Register a service UUID to include in advertising scan response. Enables remote devices to discover services before connecting.
| uuid | Service UUID to advertise |
Definition at line 269 of file IBluetoothController.h.
|
inlinevirtual |
Definition at line 676 of file IBluetoothController.h.
|
inlinevirtual |
Register a callback for device connection events. Multiple callbacks are supported (up to 4).
Definition at line 442 of file IBluetoothController.h.
|
inlinevirtual |
Register a callback for device disconnection events. Multiple callbacks are supported (up to 4).
Definition at line 449 of file IBluetoothController.h.
|
inlinevirtual |
Register a callback for encryption-change events (multi-listener).
Definition at line 403 of file IBluetoothController.h.
|
inlinevirtual |
Definition at line 679 of file IBluetoothController.h.
|
inlinevirtual |
Register a numeric-comparison pairing callback. Multiple listeners are supported. Only the first listener that calls respondToNumericComparison() will succeed; later responses are no-ops.
Definition at line 368 of file IBluetoothController.h.
|
inlinevirtual |
Multi-listener registration for GATT client events. Each module should call removeXxx() in its deinit to avoid stale callbacks.
Definition at line 673 of file IBluetoothController.h.
|
inlinevirtual |
Definition at line 682 of file IBluetoothController.h.
|
inlinevirtual |
Cancel an in-progress connection attempt started via connect(). No-op if no connection is pending.
Definition at line 558 of file IBluetoothController.h.
|
inlinevirtual |
Clear manufacturer data from advertising
Definition at line 294 of file IBluetoothController.h.
|
inlinevirtual |
Erase all bonded peer information from the bond store.
Definition at line 466 of file IBluetoothController.h.
|
inlinevirtual |
Connect to a peripheral device
| addr | BLE address (6 bytes) |
| addrType | Address type (0=public, 1=random) |
Definition at line 549 of file IBluetoothController.h.
|
pure virtual |
Disable Bluetooth (shutdown BLE stack to save power)
|
pure virtual |
Disconnect current connection if any
|
inlinevirtual |
Disconnect a specific connection (central or peripheral)
| connHandle | Connection handle to disconnect |
Definition at line 614 of file IBluetoothController.h.
|
inlinevirtual |
Discover a specific service by UUID on connected device. Results delivered via ServiceDiscoveryCallback with discovered characteristics.
| connHandle | Connection handle |
| uuid | Service UUID to discover |
Definition at line 567 of file IBluetoothController.h.
|
pure virtual |
Enable Bluetooth (initialize BLE stack)
|
inlinevirtual |
Enable notifications on a remote characteristic
| connHandle | Connection handle |
| cccdHandle | CCCD handle (usually attrHandle + 1) |
Definition at line 605 of file IBluetoothController.h.
|
inlinevirtual |
Forget (unpair) a single bonded peer by identity address. Used for ephemeral pairings that should not persist.
| addr | 6-byte identity address |
| addrType | Address type (0=public, 1=random) |
Definition at line 474 of file IBluetoothController.h.
|
inlinevirtual |
Get number of bonded (paired) devices
Definition at line 233 of file IBluetoothController.h.
|
inlinevirtual |
Enumerate bonded (paired) peers into a caller-provided buffer.
| out | Output array of BleBondInfo |
| maxCount | Capacity of the output array |
Definition at line 241 of file IBluetoothController.h.
|
inlinevirtual |
Get connected device name
| buf | Output buffer |
| bufLen | Buffer size |
Definition at line 222 of file IBluetoothController.h.
|
inlinevirtual |
Get connection handle for current peripheral connection
Definition at line 704 of file IBluetoothController.h.
|
pure virtual |
Get device name
|
pure virtual |
Get current Bluetooth MAC address
| mac | Output buffer (6 bytes) |
|
inlinevirtual |
Get negotiated MTU for current connection (payload size)
Definition at line 539 of file IBluetoothController.h.
|
inlinevirtual |
Resolve the identity address of a connected peer.
| connHandle | Connection handle |
| addr | Output 6-byte address |
| addrType | Output address type (0=public, 1=random) |
Definition at line 428 of file IBluetoothController.h.
|
pure virtual |
Get RSSI of connected device
|
inlinevirtual |
Get scan results
| results | Output array |
| maxResults | Maximum results to return |
Definition at line 338 of file IBluetoothController.h.
|
inlinevirtual |
Initiate link encryption / pairing as central on an existing connection. Triggers the configured pairing flow (e.g. numeric comparison). Used to upgrade a connection to an encrypted link on demand.
| connHandle | Connection handle |
Definition at line 419 of file IBluetoothController.h.
|
inlinevirtual |
Check if currently advertising
Definition at line 261 of file IBluetoothController.h.
|
pure virtual |
Check if a device is currently connected
|
pure virtual |
Check if Bluetooth is currently enabled
|
inlinevirtual |
Check if scan is complete
Definition at line 330 of file IBluetoothController.h.
|
inlinevirtual |
Read a characteristic from remote device
| connHandle | Connection handle |
| attrHandle | Attribute handle |
Definition at line 594 of file IBluetoothController.h.
|
inlinevirtual |
Register a GATT service with characteristics. Service definitions are translated to stack-native format internally. Must be called after enable() and before advertising.
| service | Service definition (struct must remain valid until unregistered) |
| pluginReserved | true to allocate from the slot reserved for plugins; false (system modules) to allocate from the system pool |
Definition at line 489 of file IBluetoothController.h.
|
inlinevirtual |
Remove a service UUID from advertising scan response.
| uuid | Service UUID to remove |
Definition at line 275 of file IBluetoothController.h.
|
inlinevirtual |
Definition at line 687 of file IBluetoothController.h.
|
inlinevirtual |
Unregister a previously added connection callback.
Definition at line 454 of file IBluetoothController.h.
|
inlinevirtual |
Unregister a previously added disconnection callback.
Definition at line 459 of file IBluetoothController.h.
|
inlinevirtual |
Unregister a previously added encryption-change callback.
Definition at line 410 of file IBluetoothController.h.
|
inlinevirtual |
Definition at line 688 of file IBluetoothController.h.
|
inlinevirtual |
Unregister a numeric-comparison callback previously added via add*().
Definition at line 376 of file IBluetoothController.h.
|
inlinevirtual |
Definition at line 686 of file IBluetoothController.h.
|
inlinevirtual |
Definition at line 689 of file IBluetoothController.h.
|
inlinevirtual |
Respond to a numeric comparison pairing request
| connHandle | Connection handle from the callback |
| accept | true to accept, false to reject |
Definition at line 389 of file IBluetoothController.h.
|
inlinevirtual |
Send indication on a characteristic (with acknowledgment)
| connHandle | Connection handle |
| attrHandle | Attribute handle |
| data | Data to send |
| len | Data length |
Definition at line 529 of file IBluetoothController.h.
|
inlinevirtual |
Send notification on a characteristic
| connHandle | Connection handle (0xFFFF for all connections) |
| attrHandle | Attribute handle of the characteristic |
| data | Data to send |
| len | Data length |
Definition at line 515 of file IBluetoothController.h.
|
inlinevirtual |
Set manufacturer-specific data in advertising scan response. Used for module-specific broadcast data (e.g., vCard minicard).
| companyId | Bluetooth company ID (0xFFFF for testing) |
| data | Payload data |
| len | Payload length (max ~27 bytes) |
Definition at line 285 of file IBluetoothController.h.
|
inlinevirtual |
Set the GAP Appearance value advertised in the primary PDU. Lets HOGP hosts categorize the device (e.g. 0x03C1 = HID Keyboard).
| appearance | Appearance value, or 0 to advertise none |
Definition at line 301 of file IBluetoothController.h.
|
inlinevirtual |
Set callback for authentication completion
Definition at line 353 of file IBluetoothController.h.
|
inlinevirtual |
Definition at line 696 of file IBluetoothController.h.
|
pure virtual |
Set device name for BLE advertising
| name | Device name (null-terminated) |
|
inlinevirtual |
Definition at line 697 of file IBluetoothController.h.
|
inlinevirtual |
Legacy single-listener setter retained for source compatibility. Equivalent to calling addNumericComparisonCallback() on a freshly cleared list.
Definition at line 382 of file IBluetoothController.h.
|
inlinevirtual |
Set callback for passkey display during pairing
Definition at line 348 of file IBluetoothController.h.
|
inlinevirtual |
Legacy single-listener setters retained for source compatibility. Equivalent to clearing all listeners and then add*Callback(cb).
Definition at line 695 of file IBluetoothController.h.
|
inlinevirtual |
Definition at line 698 of file IBluetoothController.h.
|
inlinevirtual |
Start BLE advertising
Definition at line 251 of file IBluetoothController.h.
|
inlinevirtual |
Start BLE scan
| durationMs | Scan duration in milliseconds; 0 scans continuously until stopScan(). |
| keepAdvertising | If true, advertising keeps running during the scan (Peripheral + Observer multi-role) instead of being stopped. |
Definition at line 318 of file IBluetoothController.h.
|
inlinevirtual |
Stop BLE advertising
Definition at line 256 of file IBluetoothController.h.
|
inlinevirtual |
Stop ongoing scan
Definition at line 325 of file IBluetoothController.h.
|
inlinevirtual |
Unregister a previously registered GATT service by its service UUID and rebuild the GATT database. Intended for dynamically (un)loaded owners such as plugins.
| serviceUuid | UUID of the service to remove |
Definition at line 502 of file IBluetoothController.h.
|
inlinevirtual |
Write to a characteristic on remote device
| connHandle | Connection handle |
| attrHandle | Attribute handle |
| data | Data to write |
| len | Data length |
| withResponse | true for write with response |
Definition at line 581 of file IBluetoothController.h.
|
staticconstexpr |
Definition at line 153 of file IBluetoothController.h.
Referenced by cdc::mod_2fa::ble_chalresp_deinit().
|
staticconstexpr |
Maximum number of bonded peers retained/returned. Single source of truth for both the controller's bond store and any caller-side buffers.
Definition at line 228 of file IBluetoothController.h.
|
staticconstexpr |
Definition at line 158 of file IBluetoothController.h.
|
staticconstexpr |
Definition at line 157 of file IBluetoothController.h.
|
staticconstexpr |
Maximum number of scan results retained/returned. Single source of truth for both the controller's result buffer and any caller-side buffers.
Definition at line 309 of file IBluetoothController.h.