Bluetooth LE state module¶
Use the Bluetooth LE state module to:
Enable Bluetooth (
bt_enable()
).Handle Zephyr connection callbacks (
bt_conn_cb
).Handle Zephyr authenticated pairing callbacks (
bt_conn_auth_cb
).Propagate information about the connection state and parameters by using Event Manager events.
Module events¶
Source Module |
Input Event |
This Module |
Output Event |
Sink Module |
---|---|---|---|---|
|
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Note
See the Overview: Firmware architecture for more information about the event-based communication in the nRF Desktop application and about how to read this table.
Configuration¶
The module requires the basic Bluetooth configuration, as described in Bluetooth in nRF Desktop.
You can use the option CONFIG_DESKTOP_BLE_ENABLE_PASSKEY
to enable pairing based on passkey for increased security.
Make sure to enable and configure the Passkey module if you decide to use this option.
Implementation details¶
The Bluetooth LE state module module is used by both Bluetooth Peripheral and Bluetooth Central devices.
Connection state change¶
The module propagates information about the connection state changes using ble_peer_event
, where ble_peer_event.id
is a pointer to the connection object, and ble_peer_event.state
is the connection state.
The connection state can be set to one of the following values:
PEER_STATE_CONNECTED
- successfully connected to the remote peer.PEER_STATE_CONN_FAILED
- failed to connect the remote peer.PEER_STATE_SECURED
- set the connection security at least to level 2 (encryption and no authentication).PEER_STATE_DISCONNECTED
- disconnected from the remote peer.
Connection parameters change¶
The module submits a ble_peer_conn_params_event
to inform other application modules about the following:
Connection parameter update request.
Connection parameter update.
The connection parameter update request is rejected in the Zephyr’s callback.
The Bluetooth LE connection parameters module updates the connection parameters on ble_peer_conn_params_event
.
Connection references¶
The Bluetooth LE state module keeps references to bt_conn
objects to ensure that they remain valid when other application modules access them.
When a new connection is established, the module calls bt_conn_ref()
to increase the object reference counter.
After ble_peer_event
regarding disconnection or connection failure is received by all other application modules, the Bluetooth LE state module unreferences the bt_conn
object by using bt_conn_unref()
.
For Bluetooth Peripheral, the Bluetooth LE state module is used to request the connection security level 2. If the connection security level 2 is not established, the peripheral device disconnects.
Passkey enabled¶
If you set the CONFIG_DESKTOP_BLE_ENABLE_PASSKEY
option, the Bluetooth LE state module registers the set of authenticated pairing callbacks (bt_conn_auth_cb
).
The callbacks can be used to achieve higher security levels.
The passkey input is handled in the Passkey module.
Warning
By default, Zephyr’s Bluetooth Peripheral demands the security level 3 in case the passkey authentication is enabled.
If the nRF Desktop dongle is unable to achieve the security level 3, it will be unable to connect with the peripheral.
Disable the CONFIG_BT_SMP_ENFORCE_MITM
option to allow the dongle to connect without the authentication.
SoftDevice Link Layer¶
If Nordic Semiconductor’s SoftDevice Bluetooth LE Link Layer is selected (CONFIG_BT_LL_SOFTDEVICE
) and the CONFIG_DESKTOP_BLE_USE_LLPM
option is enabled, the module sends a Bluetooth HCI command to enable the LLPM when Bluetooth is ready.
The Bluetooth LE state module also sets the TX power for connections, because Zephyr’s Kconfig options related to selecting the default TX power are not used by this Link Layer.