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!

Parents
  • 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!

  • If one of the devices are out of range and/or turned OFF, then there will a disconnect, until the peer again is in-range or turned ON, then there will be re-connect. I assume that you first see an issue on the re-connect?

    Kenneth

  • If one of the devices are out of range and/or turned OFF, then there will a disconnect, until the peer again is in-range or turned ON, then there will be re-connect. I assume that you first see an issue on the re-connect?


    No, I should have been more clear. The short version is

    1) Phone and one device are bonded/connected
    2) device is turned off and never turned on again (so no more traffic)
    [At this point the Phone still has the bond, and can reconnect if the device is turned on again (which it never is, but we tested]
    3) Phone is rebooted, once it has started again the bond is gone

    It is also worth noting that this bug does not happen if one uses nrf connect to trigger bonding by writing to one of the attributes. Only if it is done by our app



    Can you try to comment out CONFIG_BT_TINYCRYPT_ECC and possible add CONFIG_BT_ECC=n. I guess I should try this myself first.


    That fails to compile due to smp requiring them, I didn't investigate further than the compilation error. So there may be a workaround

    subsys/bluetooth/host/libsubsys__bluetooth__host.a(smp.c.obj): in function `bt_smp_init':
    /home/censored/.local/opt/ncs/zephyr/subsys/bluetooth/host/smp.c:5564: undefined reference to `bt_pub_key_gen'

  • I assume that you first see an issue on the re-connect?

    As I said before, disconnect/reconnect works just fine. No errors triggered.

    So before rebooting the phone, I tried disconnect/reconnect dozens of times and it just worked fine. The reconnection always happened successfully.

    When the phone is rebooted then the bond is removed and that is the issue that the device is not bonded anymore (not present anymore int bonded devices list on Android side).

    If one of the devices are out of range and/or turned OFF

    The issue happens even when is just one device connected.

  • Thanks for the clarification.

    I don't think this is caused by FW side, I think it is the app side, though it's not something we have seen before. Are you able to modify back the FW to make it work with the app, and possible narrow down the cause that way?

    Kenneth

  • I don't think this is caused by FW side, I think it is the app side,

    That has been my conclusion as well

    . Are you able to modify back the FW to make it work with the app,

    Yes, and no. The bug seems to have started happening when we switched from 'numerical comparison'- to 'just works' bonding. Switching back stops it, but requires a different build of the app

    Two things that may be relevant:

    * In my limited testing, the bug does not occur in android when using the nrf connect app to trigger bonding by writing to an attribute that requires bonding, even with 'just works'

    * My understanding is that the bug does not occur if my colleague calls 'startDiscovery' on the android side before initiating 'just works' bonding

Reply
  • I don't think this is caused by FW side, I think it is the app side,

    That has been my conclusion as well

    . Are you able to modify back the FW to make it work with the app,

    Yes, and no. The bug seems to have started happening when we switched from 'numerical comparison'- to 'just works' bonding. Switching back stops it, but requires a different build of the app

    Two things that may be relevant:

    * In my limited testing, the bug does not occur in android when using the nrf connect app to trigger bonding by writing to an attribute that requires bonding, even with 'just works'

    * My understanding is that the bug does not occur if my colleague calls 'startDiscovery' on the android side before initiating 'just works' bonding

Children
No Data
Related