bonding with devices which use random BLE addresses

anthony
Posts: 8
Joined: Tue Mar 31, 2020 6:37 pm

bonding with devices which use random BLE addresses

Postby anthony » Tue Mar 31, 2020 6:48 pm

Hi,

I am using the WROVER-B dev kit and I'm trying to get my application to bond with various devices.
The initial bonding works fine (linux, android, ios).
The problem comes when I try to reconnect with ios and android.
Android manages to connect fine the second time, but in the logs I can see that the bonding operation was repeated, and it was not recognized as the previously bonded device.
With ios the second connection just fails until you manually remove the bond from within ios.
I can see that the mac address is different each time an android or ios device connects, and my understanding is that this is normal, and these addresses should be translated using the key information stored during bonding.
What I don't understand is why this isn't working. I assume this is something that should work automatically, or is there some callback I need to implement?

I am using the NIMBle bluetooth backend.
Here is the configuration:

Code: Select all

       ble_hs_cfg.sync_cb = ble_periph_on_sync;
       ble_hs_cfg.store_status_cb = ble_store_status_cb;
       ble_hs_cfg.sm_io_cap = BLE_SM_IO_CAP_NO_IO;
       ble_hs_cfg.sm_sc = 1;
       ble_hs_cfg.sm_bonding = 1;
       ble_hs_cfg.sm_mitm = 1;
       ble_hs_cfg.sm_our_key_dist = BLE_SM_PAIR_KEY_DIST_ENC;
       ble_hs_cfg.sm_their_key_dist = BLE_SM_PAIR_KEY_DIST_ENC;
Any help or hints would be appreciated.

abansal22
Posts: 105
Joined: Wed Apr 22, 2020 8:24 am

Re: bonding with devices which use random BLE addresses

Postby abansal22 » Thu Apr 23, 2020 6:25 am

Please let me know which application you are using on android and ios. Similar thing happens to me when I was trying to connect the my nrfconnect app on android ans esp32 which works as a server. What I was trying to do is to pair the devices from app itself. But after much time i figured out that, I have to pair devices by going to android settings > bluetooth>Pair device. After that my both devices connect properly. If I delete the bond information, then I have to repeat the whole process again.

anthony
Posts: 8
Joined: Tue Mar 31, 2020 6:37 pm

Re: bonding with devices which use random BLE addresses

Postby anthony » Thu Apr 23, 2020 2:46 pm

Hi abansal22,

Thanks for your reply. I have tried with several applications. "LightBlue", and a custom application written by someone in our company based on react-native-ble. Can you confirm that you are using the Nimble BLE backend and not bluedroid on ESP32? I did the pairing both automatically, and manually via the android settings. By the way, did you ever test with iPhone as well?

abansal22
Posts: 105
Joined: Wed Apr 22, 2020 8:24 am

Re: bonding with devices which use random BLE addresses

Postby abansal22 » Fri Apr 24, 2020 7:23 am

Hi Anthony,

I was using the bluedroid on esp32. No I haven't tested on iPhone. One crucial piece of information actually I was using the esp-idf(ver 4.0 ). When I was using the arduino which is on ver 3.2.3, failed to do properly.

anthony
Posts: 8
Joined: Tue Mar 31, 2020 6:37 pm

Re: bonding with devices which use random BLE addresses

Postby anthony » Fri Apr 24, 2020 12:22 pm

Hi abansal22,

I'm using the same version of esp-idf. I think it might just be the Nimble backend.

abansal22
Posts: 105
Joined: Wed Apr 22, 2020 8:24 am

Re: bonding with devices which use random BLE addresses

Postby abansal22 » Fri Apr 24, 2020 4:08 pm

Hello,

I might help, could you provide the log details in nrf connect android app. I could match with mine, maybe it can provide any help.
Thanks

chegewara
Posts: 2378
Joined: Wed Jun 14, 2017 9:00 pm

Re: bonding with devices which use random BLE addresses

Postby chegewara » Fri Apr 24, 2020 5:12 pm


anthony
Posts: 8
Joined: Tue Mar 31, 2020 6:37 pm

Re: bonding with devices which use random BLE addresses

Postby anthony » Sat Apr 25, 2020 8:21 am

Hi chegewara,

That seems to describe almost exactly my situation. I think for my use case it should be okay to enable RPA for the device itself, so I'll give that a try. Thanks for the link.

abansal22: I'll the approach above first

ESP_Prasad
Posts: 18
Joined: Tue Nov 12, 2019 7:46 am

Re: bonding with devices which use random BLE addresses

Postby ESP_Prasad » Tue Apr 28, 2020 10:16 am

@anthony Please take a look at this issue: https://github.com/espressif/esp-nimble/issues/8 and see if it resolves your problem.
If you are looking to use RPA feature, please refer to following points:
  • own_addr_type needs to be set to BLE_ADDR_RANDOM.
  • ble_hs_pvcy_rpa_config() should be called in after BLE Host stack starts and NimBLE host and ESP controller are synced i.e. in bleprph_on_sync.
  • Enable IRK distribution from both ends i.e.

    Code: Select all

    ble_hs_cfg.sm_our_key_dist = BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID;
    ble_hs_cfg.sm_their_key_dist = BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID;
    
Please let me know if it resolves your issue.

anthony
Posts: 8
Joined: Tue Mar 31, 2020 6:37 pm

Re: bonding with devices which use random BLE addresses

Postby anthony » Thu Apr 30, 2020 10:11 am

@ESP_Prasad thanks for your response. I will try that and let you know the results.

Edit:
I've got it working with your suggestions. The important point was to replace

Code: Select all

ble_hs_util_ensure_addr(0)
with

Code: Select all

ble_hs_pvcy_rpa_config(1)
and then set the key exchange flags correctly. Thank you so much, and thanks to everyone else for responding as well.

Who is online

Users browsing this forum: No registered users and 141 guests