Abstract away BLE-capable radio transceivers or SOCs. More...
#include <BLE.h>
Data Structures | |
struct | InitializationCompleteCallbackContext |
Initialization complete event. More... | |
struct | OnEventsToProcessCallbackContext |
Events to process event. More... | |
Public Types | |
typedef unsigned | InstanceID_t |
Opaque type used to store the ID of a BLE instance. More... | |
typedef FunctionPointerWithContext< OnEventsToProcessCallbackContext * > | OnEventsToProcessCallback_t |
Events to process event handler. More... | |
typedef void(* | InitializationCompleteCallback_t) (InitializationCompleteCallbackContext *context) |
Initialization complete event handler. More... | |
Public Member Functions | |
InstanceID_t | getInstanceID (void) const |
Fetch the ID of a BLE instance. More... | |
void | onEventsToProcess (const OnEventsToProcessCallback_t &on_event_cb) |
Register a callback called when the BLE stack has pending work. More... | |
void | processEvents () |
Process ALL pending events living in the BLE stack and return once all events have been consumed. More... | |
ble_error_t | init (InitializationCompleteCallback_t completion_cb=NULL) |
Initialize the BLE controller/stack. More... | |
template<typename T > | |
ble_error_t | init (T *object, void(T::*completion_cb)(InitializationCompleteCallbackContext *context)) |
Initialize the BLE controller/stack. More... | |
bool | hasInitialized (void) const |
Indicate if the BLE instance has been initialized. More... | |
ble_error_t | shutdown (void) |
Shut down the underlying stack, and reset state of this BLE instance. More... | |
const char * | getVersion (void) |
This call allows the application to get the BLE stack version information. More... | |
Gap & | gap () |
Accessor to Gap. More... | |
const Gap & | gap () const |
A const alternative to gap(). More... | |
GattServer & | gattServer () |
Accessor to GattServer. More... | |
const GattServer & | gattServer () const |
A const alternative to gattServer(). More... | |
GattClient & | gattClient () |
Accessors to GattClient. More... | |
const GattClient & | gattClient () const |
A const alternative to gattClient(). More... | |
SecurityManager & | securityManager () |
Accessors to SecurityManager. More... | |
const SecurityManager & | securityManager () const |
A const alternative to securityManager(). More... | |
BLE (InstanceID_t instanceID=DEFAULT_INSTANCE) | |
Constructor for a handle to a BLE instance (the BLE stack). More... | |
void | waitForEvent (void) |
Yield control to the BLE stack or to other tasks waiting for events. More... | |
ble_error_t | setAddress (BLEProtocol::AddressType_t type, const BLEProtocol::AddressBytes_t address) |
Set the BTLE MAC address and type. More... | |
ble_error_t | getAddress (BLEProtocol::AddressType_t *typeP, BLEProtocol::AddressBytes_t address) |
Fetch the Bluetooth Low Energy MAC address and type. More... | |
void | setAdvertisingType (GapAdvertisingParams::AdvertisingType advType) |
Set the GAP advertising mode to use for this device. More... | |
void | setAdvertisingInterval (uint16_t interval) |
Set the advertising interval. More... | |
uint16_t | getMinAdvertisingInterval (void) const |
Get the minimum advertising interval in milliseconds, which can be used for connectable advertising types. More... | |
uint16_t | getMinNonConnectableAdvertisingInterval (void) const |
Get the minimum advertising interval in milliseconds, which can be used for nonconnectable advertising type. More... | |
uint16_t | getMaxAdvertisingInterval (void) const |
Get the maximum advertising interval in milliseconds. More... | |
void | setAdvertisingTimeout (uint16_t timeout) |
Set the advertising duration. More... | |
void | setAdvertisingParams (const GapAdvertisingParams &advParams) |
Set up a particular, user-constructed set of advertisement parameters for the underlying stack. More... | |
const GapAdvertisingParams & | getAdvertisingParams (void) const |
Get the current advertising parameters. More... | |
ble_error_t | accumulateAdvertisingPayload (uint8_t flags) |
Accumulate an AD structure in the advertising payload. More... | |
ble_error_t | accumulateAdvertisingPayload (GapAdvertisingData::Appearance app) |
Accumulate an AD structure in the advertising payload. More... | |
ble_error_t | accumulateAdvertisingPayloadTxPower (int8_t power) |
Accumulate an AD structure in the advertising payload. More... | |
ble_error_t | accumulateAdvertisingPayload (GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len) |
Accumulate a variable length byte-stream as an AD structure in the advertising payload. More... | |
ble_error_t | setAdvertisingData (const GapAdvertisingData &advData) |
Set up a particular, user-constructed advertisement payload for the underlying stack. More... | |
const GapAdvertisingData & | getAdvertisingData (void) const |
Get a reference to the current advertising payload. More... | |
void | clearAdvertisingPayload (void) |
Reset any advertising payload prepared from prior calls to accumulateAdvertisingPayload(). More... | |
ble_error_t | setAdvertisingPayload (void) |
Dynamically reset the accumulated advertising payload and scanResponse. More... | |
ble_error_t | accumulateScanResponse (GapAdvertisingData::DataType type, const uint8_t *data, uint8_t len) |
Accumulate a variable length byte-stream as an AD structure in the scanResponse payload. More... | |
void | clearScanResponse (void) |
Reset any scan response prepared from prior calls to accumulateScanResponse(). More... | |
ble_error_t | startAdvertising (void) |
Start advertising. More... | |
ble_error_t | stopAdvertising (void) |
Stop advertising. More... | |
ble_error_t | setScanParams (uint16_t interval=GapScanningParams::SCAN_INTERVAL_MAX, uint16_t window=GapScanningParams::SCAN_WINDOW_MAX, uint16_t timeout=0, bool activeScanning=false) |
Set up parameters for GAP scanning (observer mode). More... | |
ble_error_t | setScanInterval (uint16_t interval) |
Set up the scanInterval parameter for GAP scanning (observer mode). More... | |
ble_error_t | setScanWindow (uint16_t window) |
Set up the scanWindow parameter for GAP scanning (observer mode). More... | |
ble_error_t | setScanTimeout (uint16_t timeout) |
Set up parameters for GAP scanning (observer mode). More... | |
void | setActiveScan (bool activeScanning) |
Set up parameters for GAP scanning (observer mode). More... | |
ble_error_t | startScan (void(*callback)(const Gap::AdvertisementCallbackParams_t *params)) |
Start scanning (Observer Procedure) based on the parameters currently in effect. More... | |
template<typename T > | |
ble_error_t | startScan (T *object, void(T::*memberCallback)(const Gap::AdvertisementCallbackParams_t *params)) |
Start the scanning procedure. More... | |
ble_error_t | stopScan (void) |
Stop scanning. More... | |
ble_error_t | connect (const BLEProtocol::AddressBytes_t peerAddr, BLEProtocol::AddressType_t peerAddrType=BLEProtocol::AddressType::RANDOM_STATIC, const Gap::ConnectionParams_t *connectionParams=NULL, const GapScanningParams *scanParams=NULL) |
Create a connection (GAP Link Establishment). More... | |
ble_error_t | disconnect (Gap::Handle_t connectionHandle, Gap::DisconnectionReason_t reason) |
This call initiates the disconnection procedure, and its completion is communicated to the application with an invocation of the onDisconnection callback. More... | |
ble_error_t | disconnect (Gap::DisconnectionReason_t reason) |
This call initiates the disconnection procedure, and its completion is communicated to the application with an invocation of the onDisconnection callback. More... | |
Gap::GapState_t | getGapState (void) const |
Returns the current Gap state of the device using a bitmask that describes whether the device is advertising or connected. More... | |
ble_error_t | getPreferredConnectionParams (Gap::ConnectionParams_t *params) |
Get the GAP peripheral's preferred connection parameters. More... | |
ble_error_t | setPreferredConnectionParams (const Gap::ConnectionParams_t *params) |
Set the GAP peripheral's preferred connection parameters. More... | |
ble_error_t | updateConnectionParams (Gap::Handle_t handle, const Gap::ConnectionParams_t *params) |
Update connection parameters while in the peripheral role. More... | |
ble_error_t | setDeviceName (const uint8_t *deviceName) |
Set the device name characteristic in the Gap service. More... | |
ble_error_t | getDeviceName (uint8_t *deviceName, unsigned *lengthP) |
Get the value of the device name characteristic in the Gap service. More... | |
ble_error_t | setAppearance (GapAdvertisingData::Appearance appearance) |
Set the appearance characteristic in the Gap service. More... | |
ble_error_t | getAppearance (GapAdvertisingData::Appearance *appearanceP) |
Get the appearance characteristic in the Gap service. More... | |
ble_error_t | setTxPower (int8_t txPower) |
Set the radio's transmit power. More... | |
void | getPermittedTxPowerValues (const int8_t **valueArrayPP, size_t *countP) |
Query the underlying stack for permitted arguments for setTxPower(). More... | |
ble_error_t | addService (GattService &service) |
Add a service declaration to the local server ATT table. More... | |
ble_error_t | readCharacteristicValue (GattAttribute::Handle_t attributeHandle, uint8_t *buffer, uint16_t *lengthP) |
Read the value of a characteristic from the local GattServer. More... | |
ble_error_t | readCharacteristicValue (Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t *buffer, uint16_t *lengthP) |
Read the value of a characteristic from the local GattServer. More... | |
ble_error_t | updateCharacteristicValue (GattAttribute::Handle_t attributeHandle, const uint8_t *value, uint16_t size, bool localOnly=false) |
Update the value of a characteristic on the local GattServer. More... | |
ble_error_t | updateCharacteristicValue (Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, const uint8_t *value, uint16_t size, bool localOnly=false) |
Update the value of a characteristic on the local GattServer. More... | |
ble_error_t | initializeSecurity (bool enableBonding=true, bool requireMITM=true, SecurityManager::SecurityIOCapabilities_t iocaps=SecurityManager::IO_CAPS_NONE, const SecurityManager::Passkey_t passkey=NULL) |
Enable the BLE stack's Security Manager. More... | |
ble_error_t | getLinkSecurity (Gap::Handle_t connectionHandle, SecurityManager::LinkSecurityStatus_t *securityStatusP) |
Get the security status of a connection. More... | |
ble_error_t | purgeAllBondingState (void) |
Delete all peer device context and all related bonding information from the database within the security manager. More... | |
void | onTimeout (Gap::TimeoutEventCallback_t timeoutCallback) |
Set up a callback for timeout events. More... | |
void | onConnection (Gap::ConnectionEventCallback_t connectionCallback) |
Set up a callback for connection events. More... | |
void | onDisconnection (Gap::DisconnectionEventCallback_t disconnectionCallback) |
Append to a chain of callbacks to be invoked upon GAP disconnection. More... | |
template<typename T > | |
void | onDisconnection (T *tptr, void(T::*mptr)(const Gap::DisconnectionCallbackParams_t *)) |
The same as onDisconnection() but allows an object reference and member function to be added to the chain of callbacks. More... | |
void | onRadioNotification (void(*callback)(bool)) |
Radio Notification is a feature that enables ACTIVE and INACTIVE (nACTIVE) signals from the stack. More... | |
void | onDataSent (void(*callback)(unsigned count)) |
Add a callback for the GATT event DATA_SENT (which is triggered when updates are sent out by GATT in the form of notifications). More... | |
template<typename T > | |
void | onDataSent (T *objPtr, void(T::*memberPtr)(unsigned count)) |
The same as onDataSent() but allows an object reference and member function to be added to the chain of callbacks. More... | |
void | onDataWritten (void(*callback)(const GattWriteCallbackParams *eventDataP)) |
Set up a callback for when an attribute has its value updated by or at the connected peer. More... | |
template<typename T > | |
void | onDataWritten (T *objPtr, void(T::*memberPtr)(const GattWriteCallbackParams *context)) |
The same as onDataWritten() but allows an object reference and member function to be added to the chain of callbacks. More... | |
ble_error_t | onDataRead (void(*callback)(const GattReadCallbackParams *eventDataP)) |
Set up a callback to be invoked on the peripheral when an attribute is being read by a remote client. More... | |
template<typename T > | |
ble_error_t | onDataRead (T *objPtr, void(T::*memberPtr)(const GattReadCallbackParams *context)) |
The same as onDataRead() but allows an object reference and member function to be added to the chain of callbacks. More... | |
void | onUpdatesEnabled (GattServer::EventCallback_t callback) |
Set up a callback for when notifications or indications are enabled for a characteristic on the local GattServer. More... | |
void | onUpdatesDisabled (GattServer::EventCallback_t callback) |
Set up a callback for when notifications or indications are disabled for a characteristic on the local GattServer. More... | |
void | onConfirmationReceived (GattServer::EventCallback_t callback) |
Set up a callback for when the GATT server receives a response for an indication event sent previously. More... | |
void | onSecuritySetupInitiated (SecurityManager::SecuritySetupInitiatedCallback_t callback) |
Set up a callback for when the security setup procedure (key generation and exchange) for a link has started. More... | |
void | onSecuritySetupCompleted (SecurityManager::SecuritySetupCompletedCallback_t callback) |
Set up a callback for when the security setup procedure (key generation and exchange) for a link has completed. More... | |
void | onLinkSecured (SecurityManager::LinkSecuredCallback_t callback) |
Set up a callback for when a link with the peer is secured. More... | |
void | onSecurityContextStored (SecurityManager::HandleSpecificEvent_t callback) |
Set up a callback for successful bonding, meaning that link-specific security context is stored persistently for a peer device. More... | |
void | onPasskeyDisplay (SecurityManager::PasskeyDisplayCallback_t callback) |
Set up a callback for when the passkey needs to be displayed on a peripheral with DISPLAY capability. More... | |
Static Public Member Functions | |
static BLE & | Instance (InstanceID_t id=DEFAULT_INSTANCE) |
Get a reference to the BLE singleton corresponding to a given interface. More... | |
static const char * | errorToString (ble_error_t error) |
Translate error code into a printable string. More... | |
Static Public Attributes | |
static const InstanceID_t | DEFAULT_INSTANCE = 0 |
The value of the BLE::InstanceID_t for the default BLE instance. More... | |
static const InstanceID_t | NUM_INSTANCES = 1 |
The number of permitted BLE instances for the application. More... | |
Abstract away BLE-capable radio transceivers or SOCs.
Instances of this class have three responsibilities:
The user should not create BLE instances directly but rather access to the singleton(s) holding the BLE interfaces present in the system by using the static function Instance().
Next, the signal handling/process mechanism should be set up. By design, Mbed BLE does not impose to the user an event handling/processing mechanism; however, it exposes APIs, which allows an application to compose its own:
It is common to bind BLE event mechanism with Mbed EventQueue:
Once the event processing mechanism is in place, the Bluetooth subsystem can be initialized with the init() function. That function accepts in input a callback, which will be invoked once the initialization process has finished.
typedef void(* InitializationCompleteCallback_t) (InitializationCompleteCallbackContext *context) |
typedef unsigned InstanceID_t |
BLE | ( | InstanceID_t | instanceID = DEFAULT_INSTANCE | ) |
Constructor for a handle to a BLE instance (the BLE stack).
BLE handles are thin wrappers around a transport object (that is, ptr. to BLEInstanceBase).
[in] | instanceID | BLE Instance ID to get. |
It is better to create BLE objects as singletons accessed through the Instance() method. If multiple BLE handles are constructed for the same interface (using this constructor), they share the same underlying transport object.
ble_error_t accumulateAdvertisingPayload | ( | uint8_t | flags | ) |
Accumulate an AD structure in the advertising payload.
Please note that the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used as an additional 31 bytes if the advertising payload is too small.
[in] | flags | The flags to add. Please refer to GapAdvertisingData::Flags for valid flags. Multiple flags may be specified in combination. |
ble_error_t accumulateAdvertisingPayload | ( | GapAdvertisingData::Appearance | app | ) |
Accumulate an AD structure in the advertising payload.
Please note that the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used as an additional 31 bytes if the advertising payload is too small.
[in] | app | The appearance of the peripheral. |
ble_error_t accumulateAdvertisingPayload | ( | GapAdvertisingData::DataType | type, |
const uint8_t * | data, | ||
uint8_t | len | ||
) |
Accumulate a variable length byte-stream as an AD structure in the advertising payload.
Please note that the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used as an additional 31 bytes if the advertising payload is too small.
type | The type that describes the variable length data. |
data | Data bytes. |
len | Data length. |
ble_error_t accumulateAdvertisingPayloadTxPower | ( | int8_t | power | ) |
Accumulate an AD structure in the advertising payload.
Please note that the payload is limited to 31 bytes. The SCAN_RESPONSE message may be used as an additional 31 bytes if the advertising payload is too small.
[in] | power | The max transmit power to be used by the controller. This is only a hint. |
ble_error_t accumulateScanResponse | ( | GapAdvertisingData::DataType | type, |
const uint8_t * | data, | ||
uint8_t | len | ||
) |
Accumulate a variable length byte-stream as an AD structure in the scanResponse payload.
[in] | type | The type that describes the variable length data. |
[in] | data | Data bytes. |
[in] | len | Data length. |
ble_error_t addService | ( | GattService & | service | ) |
Add a service declaration to the local server ATT table.
Also add the characteristics contained within.
[in] | service | The service to be added; attribute handle of services, characteristic and characteristic descriptors are updated by the process. |
void clearAdvertisingPayload | ( | void | ) |
Reset any advertising payload prepared from prior calls to accumulateAdvertisingPayload().
This automatically propagates the re- initialized advertising payload to the underlying stack.
void clearScanResponse | ( | void | ) |
Reset any scan response prepared from prior calls to accumulateScanResponse().
ble_error_t connect | ( | const BLEProtocol::AddressBytes_t | peerAddr, |
BLEProtocol::AddressType_t | peerAddrType = BLEProtocol::AddressType::RANDOM_STATIC , |
||
const Gap::ConnectionParams_t * | connectionParams = NULL , |
||
const GapScanningParams * | scanParams = NULL |
||
) |
Create a connection (GAP Link Establishment).
peerAddr | 48-bit address, LSB format. |
peerAddrType | Address type of the peer. |
connectionParams | Connection parameters. |
scanParams | Parameters to use while scanning for the peer. |
ble_error_t disconnect | ( | Gap::Handle_t | connectionHandle, |
Gap::DisconnectionReason_t | reason | ||
) |
This call initiates the disconnection procedure, and its completion is communicated to the application with an invocation of the onDisconnection callback.
[in] | connectionHandle | |
[in] | reason | The reason for disconnection; sent back to the peer. |
ble_error_t disconnect | ( | Gap::DisconnectionReason_t | reason | ) |
This call initiates the disconnection procedure, and its completion is communicated to the application with an invocation of the onDisconnection callback.
reason | The reason for disconnection; sent back to the peer. |
|
static |
Translate error code into a printable string.
[in] | error | Error code returned by BLE functions. |
Gap& gap | ( | ) |
const Gap& gap | ( | ) | const |
GattClient& gattClient | ( | ) |
Accessors to GattClient.
All GattClient related functionality requires going through this accessor.
const GattClient& gattClient | ( | ) | const |
A const alternative to gattClient().
GattServer& gattServer | ( | ) |
Accessor to GattServer.
All GattServer related functionality requires going through this accessor.
const GattServer& gattServer | ( | ) | const |
A const alternative to gattServer().
ble_error_t getAddress | ( | BLEProtocol::AddressType_t * | typeP, |
BLEProtocol::AddressBytes_t | address | ||
) |
Fetch the Bluetooth Low Energy MAC address and type.
[out] | typeP | Type of the current address set. |
[out] | address | Value of the current address. |
const GapAdvertisingData& getAdvertisingData | ( | void | ) | const |
Get a reference to the current advertising payload.
const GapAdvertisingParams& getAdvertisingParams | ( | void | ) | const |
Get the current advertising parameters.
ble_error_t getAppearance | ( | GapAdvertisingData::Appearance * | appearanceP | ) |
Get the appearance characteristic in the Gap service.
[out] | appearanceP | The new value for the device-appearance. |
ble_error_t getDeviceName | ( | uint8_t * | deviceName, |
unsigned * | lengthP | ||
) |
Get the value of the device name characteristic in the Gap service.
[out] | deviceName | Pointer to an empty buffer where the UTF-8 non NULL- terminated string will be placed. Set this value to NULL to obtain the deviceName-length from the 'length' parameter. |
[in,out] | lengthP | (on input) Length of the buffer pointed to by deviceName; (on output) the complete device name length (without the null terminator). |
Gap::GapState_t getGapState | ( | void | ) | const |
Returns the current Gap state of the device using a bitmask that describes whether the device is advertising or connected.
InstanceID_t getInstanceID | ( | void | ) | const |
ble_error_t getLinkSecurity | ( | Gap::Handle_t | connectionHandle, |
SecurityManager::LinkSecurityStatus_t * | securityStatusP | ||
) |
Get the security status of a connection.
[in] | connectionHandle | Handle to identify the connection. |
[out] | securityStatusP | Security status. |
uint16_t getMaxAdvertisingInterval | ( | void | ) | const |
Get the maximum advertising interval in milliseconds.
uint16_t getMinAdvertisingInterval | ( | void | ) | const |
Get the minimum advertising interval in milliseconds, which can be used for connectable advertising types.
uint16_t getMinNonConnectableAdvertisingInterval | ( | void | ) | const |
Get the minimum advertising interval in milliseconds, which can be used for nonconnectable advertising type.
void getPermittedTxPowerValues | ( | const int8_t ** | valueArrayPP, |
size_t * | countP | ||
) |
Query the underlying stack for permitted arguments for setTxPower().
[out] | valueArrayPP | Out parameter to receive the immutable array of Tx values. |
[out] | countP | Out parameter to receive the array's size. |
ble_error_t getPreferredConnectionParams | ( | Gap::ConnectionParams_t * | params | ) |
Get the GAP peripheral's preferred connection parameters.
These are the defaults that the peripheral would like to have in a connection. The choice of the connection parameters is eventually up to the central.
[out] | params | The structure where the parameters will be stored. The caller owns memory for this. |
const char* getVersion | ( | void | ) |
bool hasInitialized | ( | void | ) | const |
ble_error_t init | ( | InitializationCompleteCallback_t | completion_cb = NULL | ) |
Initialize the BLE controller/stack.
init() hands control to the underlying BLE module to accomplish initialization. This initialization may tacitly depend on other hardware setup (such as clocks or power-modes) that happens early on during system startup. It may not be safe to call init() from a global static context where ordering is compiler-specific and can't be guaranteed - it is safe to call BLE::init() from within main().
[in] | completion_cb | A callback for when initialization completes for a BLE instance. This is an optional parameter; if no callback is set up, the application can still determine the status of initialization using BLE::hasInitialized() (see below). |
ble_error_t init | ( | T * | object, |
void(T::*)(InitializationCompleteCallbackContext *context) | completion_cb | ||
) |
Initialize the BLE controller/stack.
This is an alternate declaration for init(). This one takes an <Object, member> pair as its callback target.
[in] | object | Object, which will be used to invoke the completion callback. |
[in] | completion_cb | Member function pointer, which will be invoked when initialization is complete. |
ble_error_t initializeSecurity | ( | bool | enableBonding = true , |
bool | requireMITM = true , |
||
SecurityManager::SecurityIOCapabilities_t | iocaps = SecurityManager::IO_CAPS_NONE , |
||
const SecurityManager::Passkey_t | passkey = NULL |
||
) |
Enable the BLE stack's Security Manager.
The Security Manager implements the cryptographic algorithms and protocol exchanges that allow two devices to securely exchange data and privately detect each other. Calling this API is a prerequisite for encryption and pairing (bonding).
[in] | enableBonding | Allow for bonding. |
[in] | requireMITM | Require protection against man-in-the-middle attacks. |
[in] | iocaps | To specify the I/O capabilities of this peripheral, such as availability of a display or keyboard, to support out-of-band exchanges of security data. |
[in] | passkey | To specify a static passkey. |
|
static |
Get a reference to the BLE singleton corresponding to a given interface.
There is a static array of BLE singletons.
[in] | id | BLE Instance ID to get. |
void onConfirmationReceived | ( | GattServer::EventCallback_t | callback | ) |
Set up a callback for when the GATT server receives a response for an indication event sent previously.
[in] | callback | Event handler being registered. |
void onConnection | ( | Gap::ConnectionEventCallback_t | connectionCallback | ) |
Set up a callback for connection events.
Refer to Gap::ConnectionEventCallback_t.
[in] | connectionCallback | Event handler being registered. |
ble_error_t onDataRead | ( | void(*)(const GattReadCallbackParams *eventDataP) | callback | ) |
Set up a callback to be invoked on the peripheral when an attribute is being read by a remote client.
[in] | callback | Event handler being registered. |
ble_error_t onDataRead | ( | T * | objPtr, |
void(T::*)(const GattReadCallbackParams *context) | memberPtr | ||
) |
The same as onDataRead() but allows an object reference and member function to be added to the chain of callbacks.
[in] | objPtr | Pointer to the instance that is used to invoke the event handler (memberPtr ). |
[in] | memberPtr | Event handler being registered. It is a member function. |
void onDataSent | ( | void(*)(unsigned count) | callback | ) |
Add a callback for the GATT event DATA_SENT (which is triggered when updates are sent out by GATT in the form of notifications).
[in] | callback | Event handler being registered. |
void onDataSent | ( | T * | objPtr, |
void(T::*)(unsigned count) | memberPtr | ||
) |
The same as onDataSent() but allows an object reference and member function to be added to the chain of callbacks.
[in] | objPtr | Pointer to the instance that is used to invoke the event handler. |
[in] | memberPtr | Event handler being registered. It is a member function. |
void onDataWritten | ( | void(*)(const GattWriteCallbackParams *eventDataP) | callback | ) |
Set up a callback for when an attribute has its value updated by or at the connected peer.
For a peripheral, this callback is triggered when the local GATT server has an attribute updated by a write command from the peer. For a Central, this callback is triggered when a response is received for a write request.
[in] | callback | The event handler being registered. |
void onDataWritten | ( | T * | objPtr, |
void(T::*)(const GattWriteCallbackParams *context) | memberPtr | ||
) |
The same as onDataWritten() but allows an object reference and member function to be added to the chain of callbacks.
[in] | objPtr | Pointer to the instance that is used to invoke the event handler (memberPtr ). |
[in] | memberPtr | Event handler being registered. It is a member function. |
void onDisconnection | ( | Gap::DisconnectionEventCallback_t | disconnectionCallback | ) |
Append to a chain of callbacks to be invoked upon GAP disconnection.
[in] | disconnectionCallback | Event handler being registered. |
void onDisconnection | ( | T * | tptr, |
void(T::*)(const Gap::DisconnectionCallbackParams_t *) | mptr | ||
) |
The same as onDisconnection() but allows an object reference and member function to be added to the chain of callbacks.
[in] | tptr | Instance used to invoke mptr. |
[in] | mptr | Event handler being registered. |
void onEventsToProcess | ( | const OnEventsToProcessCallback_t & | on_event_cb | ) |
Register a callback called when the BLE stack has pending work.
By registering a callback, application code can know when event processing has to be scheduled.
on_event_cb | Callback invoked when there are new events to process. |
void onLinkSecured | ( | SecurityManager::LinkSecuredCallback_t | callback | ) |
Set up a callback for when a link with the peer is secured.
For bonded devices, subsequent reconnections with a bonded peer will result only in this callback when the link is secured, and setup procedures will not occur unless the bonding information is either lost or deleted on either or both sides. The callback is passed in a SecurityManager::SecurityMode_t according to the level of security in effect for the secured link.
[in] | callback | Event handler being registered. |
void onPasskeyDisplay | ( | SecurityManager::PasskeyDisplayCallback_t | callback | ) |
Set up a callback for when the passkey needs to be displayed on a peripheral with DISPLAY capability.
This happens when security is configured to prevent man-in-the-middle attacks, and the peers need to exchange a passkey (or PIN) to authenticate the connection attempt.
[in] | callback | Event handler being registered. |
void onRadioNotification | ( | void(*)(bool) | callback | ) |
Radio Notification is a feature that enables ACTIVE and INACTIVE (nACTIVE) signals from the stack.
These notify the application when the radio is in use. The signal is sent using software interrupt.
The ACTIVE signal is sent before the radio event starts. The nACTIVE signal is sent at the end of the radio event. These signals can be used by the application programmer to synchronize application logic with radio activity. For example, the ACTIVE signal can be used to shut off external devices to manage peak current drawn during periods when the radio is on, or to trigger sensor data collection for transmission in the radio event.
callback | The application handler to be invoked in response to a radio ACTIVE/INACTIVE event. |
void onSecurityContextStored | ( | SecurityManager::HandleSpecificEvent_t | callback | ) |
Set up a callback for successful bonding, meaning that link-specific security context is stored persistently for a peer device.
[in] | callback | Event handler being registered. |
void onSecuritySetupCompleted | ( | SecurityManager::SecuritySetupCompletedCallback_t | callback | ) |
Set up a callback for when the security setup procedure (key generation and exchange) for a link has completed.
This will be skipped for bonded devices. The callback is passed in the success/failure status of the security setup procedure.
[in] | callback | Event handler being registered. |
void onSecuritySetupInitiated | ( | SecurityManager::SecuritySetupInitiatedCallback_t | callback | ) |
Set up a callback for when the security setup procedure (key generation and exchange) for a link has started.
This will be skipped for bonded devices. The callback is passed in parameters received from the peer's security request: bool allowBonding, bool requireMITM and SecurityIOCapabilities_t.
[in] | callback | Event handler being registered. |
void onTimeout | ( | Gap::TimeoutEventCallback_t | timeoutCallback | ) |
Set up a callback for timeout events.
Refer to Gap::TimeoutSource_t for possible event types.
[in] | timeoutCallback | Event handler being registered. |
void onUpdatesDisabled | ( | GattServer::EventCallback_t | callback | ) |
Set up a callback for when notifications or indications are disabled for a characteristic on the local GattServer.
[in] | callback | Event handler being registered. |
void onUpdatesEnabled | ( | GattServer::EventCallback_t | callback | ) |
Set up a callback for when notifications or indications are enabled for a characteristic on the local GattServer.
[in] | callback | Event handler being registered. |
void processEvents | ( | ) |
Process ALL pending events living in the BLE stack and return once all events have been consumed.
ble_error_t purgeAllBondingState | ( | void | ) |
Delete all peer device context and all related bonding information from the database within the security manager.
BLE_ERROR_NONE | On success; else returns an error code indicating the reason for the failure. |
BLE_ERROR_INVALID_STATE | If the API is called without module initialization or application registration. |
ble_error_t readCharacteristicValue | ( | GattAttribute::Handle_t | attributeHandle, |
uint8_t * | buffer, | ||
uint16_t * | lengthP | ||
) |
Read the value of a characteristic from the local GattServer.
[in] | attributeHandle | Attribute handle for the value attribute of the characteristic. |
[out] | buffer | A buffer to hold the value being read. |
[in,out] | lengthP | Length of the buffer being supplied. If the attribute value is longer than the size of the supplied buffer, this variable will return the total attribute value length (excluding offset). The application may use this information to allocate a suitable buffer size. |
ble_error_t readCharacteristicValue | ( | Gap::Handle_t | connectionHandle, |
GattAttribute::Handle_t | attributeHandle, | ||
uint8_t * | buffer, | ||
uint16_t * | lengthP | ||
) |
Read the value of a characteristic from the local GattServer.
[in] | connectionHandle | Connection Handle. |
[in] | attributeHandle | Attribute handle for the value attribute of the characteristic. |
[out] | buffer | A buffer to hold the value being read. |
[in,out] | lengthP | Length of the buffer being supplied. If the attribute value is longer than the size of the supplied buffer, this variable will return the total attribute value length (excluding offset). The application may use this information to allocate a suitable buffer size. |
SecurityManager& securityManager | ( | ) |
Accessors to SecurityManager.
All SecurityManager-related functionality requires going through this accessor.
const SecurityManager& securityManager | ( | ) | const |
A const alternative to securityManager().
void setActiveScan | ( | bool | activeScanning | ) |
Set up parameters for GAP scanning (observer mode).
[in] | activeScanning | Set to True if active-scanning is required. This is used to fetch the scan response from a peer if possible. |
Once the scanning parameters have been configured, scanning can be enabled by using startScan().
ble_error_t setAddress | ( | BLEProtocol::AddressType_t | type, |
const BLEProtocol::AddressBytes_t | address | ||
) |
Set the BTLE MAC address and type.
[in] | type | Type of the address to set. |
[in] | address | Value of the address to set. It is ordered in little endian. |
ble_error_t setAdvertisingData | ( | const GapAdvertisingData & | advData | ) |
Set up a particular, user-constructed advertisement payload for the underlying stack.
It would be uncommon for this API to be used directly; there are other APIs to build an advertisement payload (see above).
[in] | advData | Advertising data to set. |
void setAdvertisingInterval | ( | uint16_t | interval | ) |
Set the advertising interval.
[in] | interval | Advertising interval in units of milliseconds. Advertising is disabled if interval is 0. If interval is smaller than the minimum supported value, then the minimum supported value is used instead. This minimum value can be discovered using getMinAdvertisingInterval(). |
This field must be set to 0 if connectionMode is equal to ADV_CONNECTABLE_DIRECTED.
void setAdvertisingParams | ( | const GapAdvertisingParams & | advParams | ) |
Set up a particular, user-constructed set of advertisement parameters for the underlying stack.
It would be uncommon for this API to be used directly; there are other APIs to tweak advertisement parameters individually (see above).
[in] | advParams | The new advertising parameters. |
ble_error_t setAdvertisingPayload | ( | void | ) |
Dynamically reset the accumulated advertising payload and scanResponse.
The application must clear and re- accumulate a new advertising payload (and scanResponse) before using this API.
void setAdvertisingTimeout | ( | uint16_t | timeout | ) |
Set the advertising duration.
A timeout event is genenerated once the advertising period expired.
[in] | timeout | Advertising timeout (in seconds) between 0x1 and 0x3FFF (1 and 16383). Use 0 to disable the advertising timeout. |
void setAdvertisingType | ( | GapAdvertisingParams::AdvertisingType | advType | ) |
Set the GAP advertising mode to use for this device.
[in] | advType | New type of advertising to use. |
ble_error_t setAppearance | ( | GapAdvertisingData::Appearance | appearance | ) |
Set the appearance characteristic in the Gap service.
[in] | appearance | The new value for the device-appearance. |
ble_error_t setDeviceName | ( | const uint8_t * | deviceName | ) |
Set the device name characteristic in the Gap service.
[in] | deviceName | The new value for the device-name. This is a UTF-8 encoded, NULL-terminated string. |
ble_error_t setPreferredConnectionParams | ( | const Gap::ConnectionParams_t * | params | ) |
Set the GAP peripheral's preferred connection parameters.
These are the defaults that the peripheral would like to have in a connection. The choice of the connection parameters is eventually up to the central.
[in] | params | The structure containing the desired parameters. |
ble_error_t setScanInterval | ( | uint16_t | interval | ) |
Set up the scanInterval parameter for GAP scanning (observer mode).
[in] | interval | Scan interval (in milliseconds) [valid values lie between 2.5ms and 10.24s]. |
The scanning window divided by the interval determines the duty cycle for scanning. For example, if the interval is 100ms and the window is 10ms, then the controller will scan for 10 percent of the time. It is possible to have the interval and window set to the same value. In this case, scanning is continuous, with a change of scanning frequency once every interval.
Once the scanning parameters have been configured, scanning can be enabled by using startScan().
ble_error_t setScanParams | ( | uint16_t | interval = GapScanningParams::SCAN_INTERVAL_MAX , |
uint16_t | window = GapScanningParams::SCAN_WINDOW_MAX , |
||
uint16_t | timeout = 0 , |
||
bool | activeScanning = false |
||
) |
Set up parameters for GAP scanning (observer mode).
[in] | interval | Scan interval (in milliseconds) [valid values lie between 2.5ms and 10.24s]. |
[in] | window | Scan Window (in milliseconds) [valid values lie between 2.5ms and 10.24s]. |
[in] | timeout | Scan timeout (in seconds) between 0x0001 and 0xFFFF; 0x0000 disables timeout. |
[in] | activeScanning | Set to True if active-scanning is required. This is used to fetch the scan response from a peer if possible. |
The scanning window divided by the interval determines the duty cycle for scanning. For example, if the interval is 100ms and the window is 10ms, then the controller will scan for 10 percent of the time. It is possible to have the interval and window set to the same value. In this case, scanning is continuous, with a change of scanning frequency once every interval.
Once the scanning parameters have been configured, scanning can be enabled by using startScan().
ble_error_t setScanTimeout | ( | uint16_t | timeout | ) |
Set up parameters for GAP scanning (observer mode).
[in] | timeout | Scan timeout (in seconds) between 0x0001 and 0xFFFF; 0x0000 disables timeout. |
The scanning window divided by the interval determines the duty cycle for scanning. For example, if the interval is 100ms and the window is 10ms, then the controller will scan for 10 percent of the time. It is possible to have the interval and window set to the same value. In this case, scanning is continuous, with a change of scanning frequency once every interval.
Once the scanning parameters have been configured, scanning can be enabled by using startScan().
ble_error_t setScanWindow | ( | uint16_t | window | ) |
Set up the scanWindow parameter for GAP scanning (observer mode).
[in] | window | Scan Window (in milliseconds) [valid values lie between 2.5ms and 10.24s]. |
The scanning window divided by the interval determines the duty cycle for scanning. For example, if the interval is 100ms and the window is 10ms, then the controller will scan for 10 percent of the time. It is possible to have the interval and window set to the same value. In this case, scanning is continuous, with a change of scanning frequency once every interval.
Once the scanning parameters have been configured, scanning can be enabled by using startScan().
ble_error_t setTxPower | ( | int8_t | txPower | ) |
Set the radio's transmit power.
[in] | txPower | Radio transmit power in dBm. |
ble_error_t shutdown | ( | void | ) |
Shut down the underlying stack, and reset state of this BLE instance.
ble_error_t startAdvertising | ( | void | ) |
Start advertising.
ble_error_t startScan | ( | void(*)(const Gap::AdvertisementCallbackParams_t *params) | callback | ) |
Start scanning (Observer Procedure) based on the parameters currently in effect.
[in] | callback | The application-specific callback to be invoked upon receiving every advertisement report. This can be passed in as NULL, in which case scanning may not be enabled at all. |
ble_error_t startScan | ( | T * | object, |
void(T::*)(const Gap::AdvertisementCallbackParams_t *params) | memberCallback | ||
) |
Start the scanning procedure.
Packets received during the scan procedure are forwarded to the scan packet handler passed as argument to this function.
[in] | object | Instance used to invoke callbackMember . |
[in] | memberCallback | Advertisement packet event handler. Upon reception of an advertising packet, the packet is forwarded to callback invoked from object . |
ble_error_t stopAdvertising | ( | void | ) |
Stop advertising.
ble_error_t stopScan | ( | void | ) |
Stop scanning.
The current scanning parameters remain in effect.
ble_error_t updateCharacteristicValue | ( | GattAttribute::Handle_t | attributeHandle, |
const uint8_t * | value, | ||
uint16_t | size, | ||
bool | localOnly = false |
||
) |
Update the value of a characteristic on the local GattServer.
[in] | attributeHandle | Handle for the value attribute of the characteristic. |
[in] | value | A pointer to a buffer holding the new value. |
[in] | size | Size of the new value (in bytes). |
[in] | localOnly | Should this update be kept on the local GattServer regardless of the state of the notify/indicate flag in the CCCD for this characteristic? If set to true, no notification or indication is generated. |
ble_error_t updateCharacteristicValue | ( | Gap::Handle_t | connectionHandle, |
GattAttribute::Handle_t | attributeHandle, | ||
const uint8_t * | value, | ||
uint16_t | size, | ||
bool | localOnly = false |
||
) |
Update the value of a characteristic on the local GattServer.
A version of the above, with a connection handle parameter to allow updates for connection-specific multivalued attributes (such as the CCCDs).
[in] | connectionHandle | Connection Handle. |
[in] | attributeHandle | Handle for the value attribute of the Characteristic. |
[in] | value | A pointer to a buffer holding the new value. |
[in] | size | Size of the new value (in bytes). |
[in] | localOnly | Should this update be kept on the local GattServer regardless of the state of the notify/indicate flag in the CCCD for this Characteristic? If set to true, no notification or indication is generated. |
ble_error_t updateConnectionParams | ( | Gap::Handle_t | handle, |
const Gap::ConnectionParams_t * | params | ||
) |
Update connection parameters while in the peripheral role.
In the peripheral role, this will send the corresponding L2CAP request to the connected peer and wait for the central to perform the procedure.
[in] | handle | Connection Handle |
[in] | params | Pointer to desired connection parameters. If NULL is provided on a peripheral role, the parameters in the PPCP characteristic of the GAP service will be used instead. |
void waitForEvent | ( | void | ) |
Yield control to the BLE stack or to other tasks waiting for events.
This is a sleep function that returns when there is an application-specific interrupt. This is not interchangeable with WFE() considering that the MCU might wake up several times to service the stack before returning control to the caller.
|
static |
The value of the BLE::InstanceID_t for the default BLE instance.
|
static |