This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

The nRF52 bonded device is automatically unbonded when the Android phone is rebooted.

Hello!

I am developing an application which is connecting to an nRF52 board using the Android-BLE-Library implemented by Nordic
The application is doing the following:

  1. Perform an LE scan using Google's recommended Android stock class, which is BluetoothLeScanner, to scan for the board -> as a result the nRF52 board is found by the BluetoothLeScanner
  2. The app is sending a connect request to the nRF52 board -> as a result it successfully connects
  3. Then the application performs a write with response request to a characterisc which require bonding - in my case I am performing a write request to enable the indications on a secure characteristic
  4. Since it is a secure writing, and the board is requesting bonding, the Android framework will automaticaly initiate the bonding - no code required on the Android app side to perform the bond -> as a result the bond succedes and then I get the write response back that the write completed successfully
  5. I check the bonded devices list in the Android Bluetooth setting screen and the nRF52 board is listed
  6. I reboot the phone. When the phone is rebooted I check again the Bluetooth settings screen and the nRF board is still listed

The FW team did the following changes in one monolithic commit, on the FW side:

  • in prj.conf file the following line was added: CONFIG_BT_PRIVACY=y
  • for the secure characteristics, in the BT_GATT_CHARACTERISTIC(...) the 3rd parameter was changed from BT_GATT_PERM_WRITE_AUTHEN into BT_GATT_PERM_WRITE_ENCRYPT for writing and from BT_GATT_PERM_READ_AUTHEN into BT_GATT_PERM_READ_ENCRYPT for reading
  • the initial two steps bonding with numerical confirmation was changed into one step just-works bonding
  • and some othere changes which I couldn't figure out what those means

Now it comes the problem. After these changes all the steps above where successfull except step 6 - after rebooting, the device was not listed anymore in the bonded devices list in Bluetooth settings screen. So before rebooting the device was listed, after rebooting the device was automatically unbonded.

Is it possible that any of the changes the FW team did could lead to this behaviour?
Is it possible that I am doing something wrong on the app side?

Thank you!

  • I forgot to mention that the bond removal issue was tested and reproduced on the following phones:

    • Google Pixel 2 & Pixel 4 running Android 11
    • Oneplus 5 running Android 10
    • Doro 8080 running Android 9
    • Google Nexus 5X running Android 8.0

    Minimum Android supported version in the Android app is set to Android 8 (SDK 26).

    I am using version 2.2.4 version of the Android-BLE-Library from Nordic.

  • My colleague from FW side managed to narrow down the change which is reproducing the issue:

    from

    static struct bt_conn_auth_cb conn_auth_callbacks = {
    .passkey_display = auth_passkey_display,
    .passkey_entry = NULL,
    .passkey_confirm = passkey_confirm,
    .cancel = auth_cancel,
    .pairing_confirm = pairing_confirm,
    .pairing_complete = pairing_complete,
    .pairing_failed = pairing_failed,
    .bond_deleted = bond_deleted
    };

    into

    static struct bt_conn_auth_cb conn_auth_callbacks = {
    .passkey_display = NULL,
    .passkey_entry = NULL,
    .passkey_confirm = NULL,
    .cancel = auth_cancel,
    .pairing_confirm = pairing_confirm,
    .pairing_complete = pairing_complete,
    .pairing_failed = pairing_failed,
    .bond_deleted = bond_deleted
    };

    I also noticed on the Android app side: after connecting and just before sending any request to the device, if the app code runs a remote device discovery (using the function bluetoothAdapter.startDiscovery()) until the nRF52 board is discovered, then the problem is not reproducing anymore.

    Is the discovery required for the bond to be strong and not removed after phone reboots? Is the application missing something else?

    Is the FW implementation missing anything triggering the need of running a discovery to make the bond stronger?

    Thank you!

  • Hi,

    I think we might need an on air sniffer log here to find the problem. Maybe you can do that with nRF sniffer tool if you have an nRF52-DK you can use for sniffer. Some other questions while waiting for your sniffer log

    1. Does the problem also occur if you disconnect and reconnect the peripheral before step 6?

    2. I have been working on this problem in a different case, I want to find out if your issue is related. To confirm please comment out the line bt_conn_set_security() that is found in bt_gatt_connected() in gatt.c and repeat your setup. Please do this test first.

    Edit: Do make sure you re-bond after doing the change in step 2.

    Best regards,
    Kenneth

  • Hi Kenneth,

    Does the problem also occur if you disconnect and reconnect the peripheral before step 6?

    Before rebooting the phone, the connection is stable. The app reconnects every time with no problems.

    I have been working on this problem in a different case, I want to find out if your issue is related.

    That post is for one of our issues. One of my colleagues from the FW team posted it and my colleague said that the fix Nordic suggested is already integrated in the FW code. This issue doesn't trigger any error while connecting or while bonding as the issue in the link. So it is not the same issue.

    To confirm please comment out the line bt_conn_set_security() that is found in bt_gatt_connected() in gatt.c and repeat your setup. Please do this test first.

    My FW colleague told me this code is also already in.

    think we might need an on air sniffer log here to find the problem. Maybe you can do that with nRF sniffer tool if you have an nRF52-DK you can use for sniffer.

    I will ask my FW colleagues to take the sniffer log and attach it to this ticket.

    Thank you!


  • Here is the log. The perephrials address is ce:d1:0e:8b:17:66

    The exact steps performed were:

    1. Peripheral was erased using nrfjprog --ereaseall
    2. Peripheral was flashed with firmware and power cycled
    3. Made sure the peripheral was not listed under "previously connected devices" in android
    4. Rebooted the phone
    5. After the phone is rebooted turn OFF and then turn ON Bluetooth on the phone (may not be required, but it appears the bug happens more reliably with this step)
    6. Installed the android application from scratch and made sure its data was erased
    7. On-boarded the peripheral - it was on-boarded successfully
    8. Turned OFF the peripheral, it was disconnected from the phone
    9. Rebooted the phone while the peripheral was still turned OFF

    Expected Result: peripheral should still be bonded

    Actual Result: peripheral was not bonded

    1. Does the problem also occur if you disconnect and reconnect the peripheral before step 6?

    When turning off/on the Bluetooth on the phone between steps 7 and 8 above:
    Sometimes the peripheral disappears immediately, that is without a rebootbugtriggnorpa.pcapng

    Sometimes the peripheral remains, and in those cases it remained after steps 8 and 9 were performed (peripheral turned off/ phone rebooted)

    When the phone is rebooted without turning off/on bluetooth between steps 7 and 8, it seems the peripheral always disappears.

Related