nRF51 SDK - S110 SoftDevice
|
When BLE DFU Service support is added to an application that uses the Device Manager, it is possible to transfer bonding information from the application to the bootloader. This information is required to reconnect to bonded devices and share the encryption keys. If no bonding information is available, the connection is re-established using directed advertising.
Bonding information consists of the peer address, the Identity Resolving Key (IRK), and the Long Term Key (LTK) of the connected peer.
If you include the file dfu_app_handler.c
in your application, bonding information is automatically shared, and either directed advertising or whitelist advertising is used to re-establish the secure connection between the devices. Whitelist advertising is only used if the device has a Resolvable Private Address (RPA) instead of a static address. In this case, the Identity Resolving Key (IRK) of only this device is added to the whitelist. So, in both cases, the device will connect only to the device that triggered the DFU mode. If the peer does not reconnect to the device, the system resets and loads the installed application again.
The following figure shows the process of reconnecting to a bonded device:
In bootloader mode, the device is advertising with the same address as in application mode if the application supports Service Changed indications. Otherwise, changes to the application cannot be indicated, and therefore the device must advertise as a new device. This is accomplished by the device advertising with the address increased by 1.
In the application, the keys that are needed to re-establish the secure connection are retrieved from the Device Manager using the function dm_distributed_keys_get. They are then passed from the application to the bootloader. The following code from dfu_app_handler.c
shows how to implement bond sharing:
The dfu_ble_svc_set_peer_data function performs a supervisor call (SVC) to the bootloader to pass the bonding information. For the bootloader to receive the information, the application's SVCs must be forwarded correctly. To do so, call sd_softdevice_vector_table_base_set with NRF_UICR->BOOTLOADERADDR as argument.
To receive the bonding information, the bootloader must implement an SVC handler. If it does not, the system will end in the default SVC handler (which is an infinite loop) when the application tries to call dfu_ble_svc_set_peer_data.