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

Device manager: How to identify between already bonded phones with new phones?

Hi, I am developing a firmware using nrf51822xxaa s130 SDK 10.0. I am using device manager to exchange the security keys and storing the bond information. For my project, I need the firmware to connect to the phone that is already paired with the device (before power cycle of the device). In other words, I should be able to identify if the app has already bonded with me before or not. Also, I need to identify if this is the first time the app is bonding with me. [I remember I saw an event which would occur only the very first time when a device and app would bond and that event would not occur in the subsequent connects (because it is already bonded before). I cant remember which event is that.] The project is in its final stages and at this stage we cannot afford to make a transition to SDK 11.0 or later versions: please consider this. Please help. Thanks.

Parents
  • Hi Nordicdev,

    You can have a look at the device_manager.h and look for "Link Status Events", you can find the list of event regarding security process. You can also have a look here to see what happens under the hood between the softdevice and device manager.

    Basically you receive DM_EVT_LINK_SECURED after the link is encrypted (regardless it's a new central or not)

    You receive DM_EVT_SECURITY_SETUP if there is a bonding request

    You receive DM_EVT_SECURITY_SETUP_COMPLETE if it's a new bond or a refreshed bond (master require the new keys to be exchanged, rarely happens)

    If you want something more than that, you may need to look into the device manager code to extract information about if the central is bonded or not (check BLE_GAP_EVT_CONNECTED event in dm_ble_evt_handler() ).

  • I have finally worked it out. For iOS, we cant rely on the "device_instance_find" which is used in "BLE_GAP_EVT_CONNECTED" under "dm_ble_evt_handler". This is because, in iOS, "The iPhone will change its public Bluetooth address every now and then, and only paired devices will have the correct key to resolve that public address and recognize the iPhone." reference: stackoverflow.com/.../ios-bluetooth-le-unable-to-connect-using-stored-pairing-data. So, the peer addr given by iOS in the on_connected event is actually fake. Used the following method that works for both iOS and Android: How to find if nRF and phone are bonding for the first time? As suggested by HungBai, if the events "DM_EVT_SECURITY_SETUP" and "DM_EVT_SECURITY_SETUP_COMPLETE" happen, that means, the app and nrf51 are bonding for the very first time. These events are not fired upon subsequent connects (as the security keys are already exchanged and both the nrf51 and the app remember the exchanged security keys). How to find if nRF51 and phone have already bonded before? If the "m_service_context_apply" returns success (under the event BLE_GAP_EVT_CONN_SEC_UPDATE), then, it means that the nRF51 and app have successfully bonded. Thanks, Hung Bai for shedding the light!

Reply
  • I have finally worked it out. For iOS, we cant rely on the "device_instance_find" which is used in "BLE_GAP_EVT_CONNECTED" under "dm_ble_evt_handler". This is because, in iOS, "The iPhone will change its public Bluetooth address every now and then, and only paired devices will have the correct key to resolve that public address and recognize the iPhone." reference: stackoverflow.com/.../ios-bluetooth-le-unable-to-connect-using-stored-pairing-data. So, the peer addr given by iOS in the on_connected event is actually fake. Used the following method that works for both iOS and Android: How to find if nRF and phone are bonding for the first time? As suggested by HungBai, if the events "DM_EVT_SECURITY_SETUP" and "DM_EVT_SECURITY_SETUP_COMPLETE" happen, that means, the app and nrf51 are bonding for the very first time. These events are not fired upon subsequent connects (as the security keys are already exchanged and both the nrf51 and the app remember the exchanged security keys). How to find if nRF51 and phone have already bonded before? If the "m_service_context_apply" returns success (under the event BLE_GAP_EVT_CONN_SEC_UPDATE), then, it means that the nRF51 and app have successfully bonded. Thanks, Hung Bai for shedding the light!

Children
No Data
Related