"Just works" Level 2 security

Hi, I am not even sure its the correct place to ask this questions, but ill try. First of all, I don't have a lot of knowledge about firmware. We lost our firmware developer before he was done implementing security for our BLE devices. Everything is working as it should. But we miss an encrypted connection (level 2 security) to our GATT services. And our device doesn't have a display, so I've tried to implement a "Just works" pairing process. I've looked at many different samples and I've ended up with an implementation that almost works as intended. But I have 1 issue I can't seem to solve (and it seems to be only on android).

If I connect(first time), I get asked to pair. And this goes smooth. All the GATT services are running. No problem! But if I disconnect, and then reconnect, then it really struggles to setup the GATT connection again. Eventually it succeeds, sometimes it takes 2-3 reconnects attempts. Sometimes it takes between 5-10 mins before it succeeds.

This is the error from our mobile app. "Device '00000000-0000-0000-0000-fd0debeda8ca' disconnected while writing descriptor with 00002902-0000-1000-8000-00805f9b34fb"

I'm not using a devkit (I flash via Bluetooth) so I cant really show any logs. But here are some code samples of the implementation and config.

Please let me know if I need to provide you more.

We use nrf connect 2.2.0 SDK.

Hope you can help us Slight smile

Best regards Pelle.

  • Here is a video showing the issue (again this seems to only be on android phones)

  • Hi,

    Which mobile phone (type and Android version) do you use? Which device do you use on the other side?

    Have you tried using nRF Connect for Mobile application instead of Device Manager?

    Which other devices have you tried apart from mentioned Android device?

    Best regards,
    Dejan

  • I have tried with a Huawei p30 pro android 10 and a Xiaomi android 11. If I disable all the security, then there is no issue.

    I tested with an iphone 10. With no issues.

    It's a custom device we use to gather emg data.

    The example in my video was just to show the issue, the same happens when we pair through our Xamarin app. Or use the nrf connect application.

  • I tried to remove the bt_conn_set_security() and decorate my gatt services like this:

    BT_GATT_SERVICE_DEFINE(ble_data_service,
    BT_GATT_PRIMARY_SERVICE(&ble_data_service_uuid),
    BT_GATT_CHARACTERISTIC(&ble_data_char_uuid.uuid, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, BT_GATT_PERM_READ_ENCRYPT, ble_data_char_read, NULL, &ads1298_adv_data),
    BT_GATT_CCC(ccc_cfg_changed, BT_GATT_PERM_WRITE_ENCRYPT), );

    This also prompts the user for a pairing the first time and successfully start reading data, but after a reconnect it keeps getting disconnected, and after a lot of tries it succeeds.

  • Hi,

    You could try to avoid bonding with Android. 
    Additionally, you could try to use nRF sniffer to identify what might be wrong.

    Best regards,
    Dejan

Related